File: test-wireless-ap

package info (click to toggle)
guessnet 0.42-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,000 kB
  • ctags: 1,252
  • sloc: cpp: 5,001; sh: 1,194; makefile: 133; perl: 118
file content (101 lines) | stat: -rwxr-xr-x 2,558 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Need bash because we use ${.../...}
#
# test-wireless-ap
#
# Usage:
#   test-wireless-ap [--timeout=TIMEOUT] IFACE [AP_MAC_ADDRESS] [IWCONFIG_ARG]...
#
# This tests whether the wireless card can associate to an access
# point using the given iwconfig argument pairs
#     essid ESSID
#     key 123456
# and so on.
#
# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
#
# History
# May 2005: Bugs fixed by Christoph Biedl and Thomas Hood
# Nov 2003: Modified by Thomas Hood and Klaus Wacker
# July 2003: Modified by Thomas Hood to support Aironet cards
# June 2003: Modified by John Fettig <jfettig@uiuc.edu>
# Jan 2003:  Derived from testssid by Andrew McMillan <awm@debian.org>
#            Written by Thomas Hood <jdthood@yahoo.co.uk>

set -o errexit   # -e
set -o noglob    # -f

MYNAME="$(basename $0)"
PATH=/sbin:/bin

ESSID=""
MAC_ADDRESS=""

report_err() { echo "${MYNAME}: Error: $*" >&2 ; }

do_sleep() { LANG=C sleep "$@" ; }

is_ethernet_mac()
{
	[ "$1" ] && [ ! "${1/[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]/}" ]
}

# Set ESSID to string following 'essid' in the array of function arguments
extract_ESSID()
{
	while [ "$1" ] ; do
		[ "$1" = "essid" ] && { ESSID="$2" ; return 0 ; }
		shift
	done
}

TIMEOUT=3
case "$1" in
	--timeout) TIMEOUT="$2" ; shift 2 ;;
	--timeout=*) TIMEOUT="${1#--timeout=}" ; shift ;;
esac

IFACE="$1"
shift
[ "$IFACE" ] || { report_err "Interface not specified.  Exiting." ; exit 1 ; }

if is_ethernet_mac "$1" ; then
	MAC_ADDRESS="$1"
	shift
fi

extract_ESSID "$@"

[ "$1" ] && iwconfig "$IFACE" "$@"
ifconfig "$IFACE" up

for (( TIMELEFT="$TIMEOUT" ; TIMELEFT > 0 ; TIMELEFT-- )) ; do
	FAILED=0
	if [ "$ESSID" ] ; then
		# Check that interface ESSID is what we are looking for
		ACTUAL_ESSID="$(iwgetid $IFACE)"
		ACTUAL_ESSID="${ACTUAL_ESSID#*ESSID:}"
		ACTUAL_ESSID="${ACTUAL_ESSID# }"
		ACTUAL_ESSID="${ACTUAL_ESSID#\"}"
		ACTUAL_ESSID="${ACTUAL_ESSID%\"}"
		[ "$ACTUAL_ESSID" = "$ESSID" ] || FAILED=1
	fi
	if [ "$FAILED" = 0 ] && [ "$MAC_ADDRESS" ] ; then
		# Check that access point MAC address is what we are looking for
		ACTUAL_MAC_ADDRESS="$(iwgetid $IFACE --ap --scheme)"
		case "$ACTUAL_MAC_ADDRESS" in
		  "FF:FF:FF:FF:FF:FF"|"ff:ff:ff:ff:ff:ff"|"44:44:44:44:44:44"|"00:00:00:00:00:00")
			ACTUAL_MAC_ADDRESS=""
			;;
		esac
		[ "$ACTUAL_MAC_ADDRESS" = "$MAC_ADDRESS" ] || FAILED=1
	fi
	if [ "$FAILED" = 0 ] ; then
		ifconfig "$IFACE" down
		exit 0
	fi
	do_sleep 1
done
# Out of time
ifconfig "$IFACE" down
exit 1