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