summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src-wireless/netcfg-auto-wireless3
-rw-r--r--src/wireless47
2 files changed, 21 insertions, 29 deletions
diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless
index bbee281..fb076eb 100644
--- a/src-wireless/netcfg-auto-wireless
+++ b/src-wireless/netcfg-auto-wireless
@@ -11,11 +11,10 @@ wifi_auto()
{
local interface="$1"
report_try "Scanning for networks"
-
set_interface up "$interface" # uses iproute methods---is it there any value to providing option to use ifconfig?
networks="$(list_networks $interface)"
- if [[ ! "$networks" ]]; then
+ if [[ -z $networks ]]; then
set_interface forcedown "$interface"
exit_fail "- No networks available."
fi
diff --git a/src/wireless b/src/wireless
index 2c9e681..81a8408 100644
--- a/src/wireless
+++ b/src/wireless
@@ -93,34 +93,27 @@ list_networks()
[[ -z "$INTERFACE" ]] && return 1
essids=$(mktemp /tmp/essid.XXXXXXXX)
-# # James suggested using this, but it requires wpa_supplicant to be running
-# wpa_cli -i "$INTERFACE" scan 2>/dev/null || { rm $essids; return 1; }
-# sleep 0.5
-# wpa_cli -i "$INTERFACE" scan_results > $essids 2>/dev/null || { rm $essids; return 1; }
- {
- while [[ "$try" -lt "$RETRIES" ]]; do
- sleep 0.5
- let try++
- # iwlist "$INTERFACE" scan 2> /dev/null | fgrep "ESSID" | sed 's/.*ESSID:"\([^"]\+\)".*/\1/' > $essids
- res=$(iwlist "$INTERFACE" scan 2> /dev/null)
- [[ -z "$res" ]] && continue
- scanned=1
- # we only bother with at most 5 successful scans
- if (( try < RETRIES-4 )); then try=$((RETRIES-4)); fi
- echo "$res" | sed -r '1d; $ { H; ba }; 2 { h; d }; /^\s+Cell /! { H; d }; :a; x; s/\n/ /g'
- done
- } \
- | sed -rne 's/.*Address: ([[:xdigit:]:]+).*ESSID:"([^"]*)".*Quality=([0-9]+).*/\1\t\3\t\1\t\2/p' \
- -e 's/.*Address: ([[:xdigit:]:]+).*Quality=([0-9]+).*ESSID:"([^"]*)".*/\1\t\2\t\1\t\3/p' \
- | sort -k1 -k2nr | uniq -w17 \
- | sort -k2nr \
- | cut -f3- > "$essids"
- # 1. make tab-separated fields: ap, signal-strength, ap, essid (easiest way to use uniq and cut here requires ap twice)
- # 2. eliminate duplicate aps (keeping strongest signal)
- # 3. sort entire list by decreasing signal
- # 4. then return tab-separated fields: ap, essid (ap needs to come first so that read can assume format is <word> <rest of line>)
-
+ 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 -f1,5 > "$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