6
6
# configuration file(s) should be copied into the
7
7
# /etc/mandos/network-hooks.d directory.
9
# Copyright © 2012 Teddy Hogeborn
10
# Copyright © 2012 Björn Påhlsson
9
12
# Copying and distribution of this file, with or without modification,
10
13
# are permitted in any medium without royalty provided the copyright
11
14
# notice and this notice are preserved. This file is offered as-is,
21
24
CONFIG="$MANDOSNETHOOKDIR/wireless.conf"
27
grep -liFe "$1" /sys/class/net/*/address \
28
| sed -e 's,.*/\([^/]*\)/[^/]*,\1,'
24
32
if [ -e "$CONFIG" ]; then
30
interfaces="`env|sed -n -e 's/^\(MODULE\|IPADDRS\|ROUTES\|WPA_DRIVER\)_\([^=]*\)=.*/\2/p' \"$CONFIG\" |sort -u`"
38
ifkeys=`env | sed -n -e 's/^ADDRESS_\([^=]*\)=.*/\1/p' "$CONFIG" \
32
41
# Exit if DEVICE is set and is not any of the wireless interfaces
33
42
if [ -n "$DEVICE" ]; then
35
for IF in $interfaces; do
36
if [ "$IF" = "$DEVICE" ]; then
44
for KEY in $ifkeys; do
45
ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
46
INTERFACE=`addrtoif "$ADDRESS"`
47
if [ "$INTERFACE" = "$DEVICE" ]; then
67
78
mkdir -m u=rwx,go= -p "$CTRLDIR"
68
79
"$wpa_supplicant" -B -g "$CTRL" -p "$CTRLDIR" $WPAS_OPTIONS
69
for INTERFACE in $interfaces; do
70
DRIVER=`eval 'echo "$WPA_DRIVER_'"$INTERFACE"\"`
71
DELAY=`eval 'echo "$DELAY_'"$INTERFACE"\"`
80
for KEY in $ifkeys; do
81
ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
82
INTERFACE=`addrtoif "$ADDRESS"`
83
DRIVER=`eval 'echo "$WPA_DRIVER_'"$KEY"\"`
84
IFDELAY=`eval 'echo "$DELAY_'"$KEY"\"`
72
85
"$wpa_cli" -g "$CTRL" interface_add "$INTERFACE" "" \
73
86
"${DRIVER:-wext}" "$CTRLDIR" > /dev/null \
75
NETWORK=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" add_network`
76
eval wpa_interface_"$INTERFACE"
88
NETWORK=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" \
90
eval wpa_interface_"$KEY"
77
91
"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" enable_network \
78
92
"$NETWORK" | sed -e '/^OK$/d'
79
( sleep "${DELAY:-$DELAY}" || : ) &
93
sleep "${IFDELAY:-$DELAY}" &
82
kill -0 $sleep || break
83
STATE=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" status | sed -n -e 's/^wpa_state=//p'`
96
kill -0 $sleep 2>/dev/null || break
97
STATE=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" \
98
status | sed -n -e 's/^wpa_state=//p'`
84
99
if [ "$STATE" = COMPLETED ]; then
101
kill -0 $sleep 2>/dev/null || break 2
102
UP=`cat /sys/class/net/"$INTERFACE"/operstate`
103
if [ "$UP" = up ]; then
104
kill $sleep 2>/dev/null
91
IPADDRS=`eval 'echo "$IPADDRS_'"$INTERFACE"\"`
113
IPADDRS=`eval 'echo "$IPADDRS_'"$KEY"\"`
92
114
if [ -n "$IPADDRS" ]; then
93
115
if [ "$IPADDRS" = dhcp ]; then
94
116
ipconfig -c dhcp -d "$INTERFACE" || :
111
133
"$wpa_cli" -g "$CTRL" terminate 2>&1 | sed -e '/^OK$/d'
112
for INTERFACE in $interfaces; do
134
for KEY in $ifkeys; do
135
ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
136
INTERFACE=`addrtoif "$ADDRESS"`
113
137
"$ip" addr show scope global permanent dev "$INTERFACE" \
114
138
| while read type addr rest; do