diff options
author | James Rayner <james@archlinux.org> | 2008-12-18 06:33:31 +0100 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2008-12-18 06:33:31 +0100 |
commit | 164df2fdcc8ac4286c7f8f04f1e7c9004ade6960 (patch) | |
tree | 50e56f8711d4c7e9db7981c3c6282a994213acca /src/wireless | |
parent | 300cd2c73b599c2a58463ce75e1aa2cb19ac2414 (diff) | |
download | netctl-164df2fdcc8ac4286c7f8f04f1e7c9004ade6960.tar.gz netctl-164df2fdcc8ac4286c7f8f04f1e7c9004ade6960.tar.xz |
fix libify
Diffstat (limited to 'src/wireless')
-rw-r--r-- | src/wireless | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/wireless b/src/wireless new file mode 100644 index 0000000..405b86b --- /dev/null +++ b/src/wireless @@ -0,0 +1,61 @@ +# Uses wireless_tools, to check for association to a network. +# wep_check interface [timeout] +wep_check() +{ + INTERFACE=$1; TIMEOUT=$2 + + [[ -z "$TIMEOUT" ]] && TIMEOUT=15 + let timeout=0 + while [[ $timeout -ne $TIMEOUT ]]; do + bssid=`iwgetid $INTERFACE -ra` + [[ ! "$bssid" = "00:00:00:00:00:00" ]] && return 0 + sleep 1 + let timeout++ + done + + err_append "Wireless association failed" + return 1 +} + +# Check if a particular network is within range +# find_essid interface essid +find_essid() +{ + INTERFACE=$1; ESSID=$2; RETRIES=5 + try=0; + while [[ $try -ne $RETRIES ]]; do + if iwlist $INTERFACE scan|sed "s/ESSID://g"|grep -q "\"$ESSID\""; then + return 0 # network found + fi + sleep 1 + let try++ + done + return 1 +} + +# Return a filename containing a list of network ESSID's found. +# list_networks interface +list_networks() +{ + # 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 "$1" ]] && return 1 + essids=$(mktemp /tmp/essid.XXXXX) + + let try=0; + RETRIES=6; + while [[ $try -ne $RETRIES ]]; do + iwlist $1 scan 2> /dev/null|grep ESSID|sed 's/.*ESSID:"\([^"]\+\)".*/\1/' > $essids + sleep 0.5; let try++ + done + sort -u $essids -o $essids + + # File of 0 length, ie. no ssid's. + if [[ ! -s $essids ]]; then + return 1 + fi + + echo $essids + return 0 +} |