diff options
author | Rémy Oudompheng <remy@archlinux.org> | 2011-06-19 17:13:53 +0200 |
---|---|---|
committer | Rémy Oudompheng <remy@archlinux.org> | 2011-06-19 18:49:26 +0200 |
commit | 13393d42c895b5f5b8853bafdb17c8b6d69e65bb (patch) | |
tree | 4d97acac7c4325ee1d56f27ffffa5611ee2ae008 /src | |
parent | 877ef579f1f87bbd0b37bf768cf635fe4ed407f5 (diff) | |
download | netctl-13393d42c895b5f5b8853bafdb17c8b6d69e65bb.tar.gz netctl-13393d42c895b5f5b8853bafdb17c8b6d69e65bb.tar.xz |
8021x: add wpa_supplicant equivalents for find_essid(), find_ap()
Signed-off-by: Rémy Oudompheng <remy@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/8021x | 51 |
1 files changed, 50 insertions, 1 deletions
@@ -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: |