From 13393d42c895b5f5b8853bafdb17c8b6d69e65bb Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sun, 19 Jun 2011 17:13:53 +0200 Subject: 8021x: add wpa_supplicant equivalents for find_essid(), find_ap() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Oudompheng --- src/8021x | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/8021x b/src/8021x index 551b4b0..0584040 100644 --- a/src/8021x +++ b/src/8021x @@ -50,6 +50,55 @@ stop_wpa() fi } +wpa_find_essid() { + # usage: wpa_find_essid $INTERFACE $ESSID + # look for existence of a given essid. Assumes wpa_supplicant is + # running + result=$(wpa_supplicant_scan_and_find "$1" 5 "$2") + ret=$? + echo $result + report_debug wpa_find_essid "\"$result\"" + return $ret +} + +wpa_find_ap() { + # usage: wpa_find_essid $INTERFACE $ESSID + # look for existence of a given essid. Assumes wpa_supplicant is + # running + bssid=${2,,} # set to lowercase + result=$(wpa_supplicant_scan_and_find "$1" 1 "$bssid") + ret=$? + echo $result + report_debug wpa_find_ap "\"$result\"" + return $ret +} + +wpa_supplicant_scan_and_find() { + #usage: wpa_supplicant_scan_and_find $INTERFACE $FIELD $ITEM + # field = 1 for bssid, 5 for essid + # item = string to lookup + local INTERFACE="$1" FIELD="$2" ITEM="$3" RETRIES=5 try scan_ok + scan_ok=0 + $WPA_CLI -i "$INTERFACE" scan &> /dev/null + for ((try=0; try < $RETRIES; try++)); do + local found + sleep 2 + found=$($WPA_CLI -i "$INTERFACE" scan_results | tail -n+2 | cut -f ${FIELD} | grep -F -x -m 1 "${ITEM}") + (( $? == 0 )) && scan_ok=1 + + # ITEM has been found, echo it + if [[ -n "$found" ]]; then + echo "$found" + return 0 + fi + $WPA_CLI -i "$INTERFACE" scan &> /dev/null + done + if (( $scan_ok != 1 )); then + report_debug wpa_supplicant_scan_and_find "unable to retrieve scan results" + fi + return 1 +} + # Return a filename containing a list of network APs and ESSIDs found (sorted by decreasing signal strength) # list_networks interface list_networks() { @@ -156,5 +205,5 @@ make_wpa_config() { fi } -# vim: ft=sh ts=4 et sw=4: +# vim: ft=sh ts=4 et sw=4 tw=0: -- cgit v1.2.3-24-g4f1b