2011-04-26 12:26:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (c) 2003-2009 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
2013-02-21 23:51:49 +01:00
|
|
|
# Copyright (c) 2003-2009,2013 by Davide Madrisan <davide.madrisan@gmail.com>
|
2011-04-26 12:26:24 +02:00
|
|
|
|
|
|
|
# Only meant to be called from ifup.
|
|
|
|
|
2013-02-21 23:51:49 +01:00
|
|
|
# Configure wireless network device options.
|
|
|
|
# Valid variables:
|
|
|
|
# WIRELESS_ESSID
|
|
|
|
# WIRELESS_MODE
|
|
|
|
# WIRELESS_ENCMODE:
|
|
|
|
# WIRELESS_NWID
|
|
|
|
# WIRELESS_CHANNEL
|
|
|
|
# WIRELESS_FREQUENCY
|
|
|
|
# WIRELESS_AP
|
|
|
|
# WIRELESS_FREQ
|
|
|
|
# WIRELESS_RATE
|
|
|
|
# WIRELESS_ENC
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
unset WIRELESS_OPTS WIRELESS_OPTS2
|
|
|
|
|
|
|
|
if [ "$WIRELESS_ESSID" ]; then
|
2013-02-21 23:51:49 +01:00
|
|
|
tmpfile=`tempfile 2>/dev/null`
|
|
|
|
tmpfile1=`tempfile 2>/dev/null`
|
2011-04-26 12:26:24 +02:00
|
|
|
|
|
|
|
if [ "$tmpfile" ]; then
|
|
|
|
ifconfig ${DEVICE} up
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
unset vname found_essid
|
2013-02-21 23:51:49 +01:00
|
|
|
# Note: iwlist scan essid option does not work with all drivers
|
|
|
|
# (see man iwlist) so we split cell information below
|
2011-04-26 12:26:24 +02:00
|
|
|
iwlist ${DEVICE} scan essid $WIRELESS_ESSID > $tmpfile
|
2013-02-21 23:51:49 +01:00
|
|
|
|
|
|
|
# Note: sometimes iwlist scan fails with "Device or resource busy",
|
|
|
|
# so we try again
|
|
|
|
[ -s $tmpfile ] ||
|
|
|
|
{ ifconfig ${DEVICE} down
|
2011-04-26 12:26:24 +02:00
|
|
|
ifconfig ${DEVICE} up
|
2013-02-21 23:51:49 +01:00
|
|
|
iwlist ${DEVICE} scan essid $WIRELESS_ESSID > $tmpfile; }
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
cat $tmpfile | \
|
|
|
|
while read line; do
|
|
|
|
if [ "${line:0:5}" = "Cell " ]; then
|
|
|
|
[ "$found_essid" ] && break || > $tmpfile1
|
|
|
|
fi
|
|
|
|
echo $line >> $tmpfile1
|
|
|
|
[ "$line" = "ESSID:\"$WIRELESS_ESSID\"" ] && found_essid=1
|
|
|
|
done
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
> $tmpfile
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
cat $tmpfile1 | \
|
|
|
|
while read line; do
|
|
|
|
vname=${line/:*}
|
|
|
|
if [ "${line:0:4}" = "Cell" ]; then
|
|
|
|
vname="${line/* }"
|
|
|
|
vval=${line/*Address:}
|
|
|
|
vname="Address"
|
|
|
|
elif [ "${line/Unknown:}" != "$line" ]; then
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
vname=${line/:*}
|
|
|
|
vname=`echo ${vname} | tr ' ' _`
|
|
|
|
vname=${vname/_(1)}
|
|
|
|
vval=${line/*:}
|
|
|
|
fi
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
vname=WIRELESS_AUTO_${vname/* }
|
|
|
|
vval=${vval/ }
|
|
|
|
vval=\"${vval/GHz*}\"
|
2013-02-21 23:51:49 +01:00
|
|
|
|
|
|
|
if [ "$vname" = "WIRELESS_AUTO_Mode" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_Channel" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_Address" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_Frequency" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_IE" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_Group_Cipher" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_Pairwise_Ciphers" -o \
|
|
|
|
"$vname" = "WIRELESS_AUTO_Authentication_Suites" ]; then
|
2011-04-26 12:26:24 +02:00
|
|
|
echo $vname=$vval >> $tmpfile
|
|
|
|
fi
|
|
|
|
done
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
. $tmpfile
|
|
|
|
else
|
2013-02-21 23:51:49 +01:00
|
|
|
echo "\
|
|
|
|
Warning: unable to create temporary file; skipping wireless autodetection"
|
2011-04-26 12:26:24 +02:00
|
|
|
fi
|
2013-02-21 23:51:49 +01:00
|
|
|
rm -f $tmpfile $tmpfile1
|
2011-04-26 12:26:24 +02:00
|
|
|
fi
|
|
|
|
|
2013-02-21 23:51:49 +01:00
|
|
|
[ "$WIRELESS_ENCMODE" ] || WIRELESS_ENCMODE="open"
|
|
|
|
|
|
|
|
[ "$WIRELESS_MODE" ] && WIRELESS_OPTS="$WIRELESS_OPTS mode $WIRELESS_MODE"
|
|
|
|
[ "$WIRELESS_ESSID" ] && WIRELESS_OPTS="$WIRELESS_OPTS essid $WIRELESS_ESSID"
|
|
|
|
[ "$WIRELESS_NWID" ] && WIRELESS_OPTS="$WIRELESS_OPTS nwid $WIRELESS_NWID"
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
if [ "$WIRELESS_CHANNEL" ]; then
|
|
|
|
WIRELESS_OPTS="$WIRELESS_OPTS channel $WIRELESS_CHANNEL"
|
|
|
|
elif [ "$WIRELESS_AUTO_Channel" ]; then
|
|
|
|
WIRELESS_OPTS="$WIRELESS_OPTS channel $WIRELESS_AUTO_Channel"
|
|
|
|
fi
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
if [ "$WIRELESS_FREQUENCY" ]; then
|
|
|
|
WIRELESS_OPTS="$WIRELESS_OPTS freq $WIRELESS_FREQUENCY"
|
|
|
|
elif [ "$WIRELESS_AUTO_Frequency" ]; then
|
|
|
|
WIRELESS_OPTS="$WIRELESS_OPTS freq ${WIRELESS_AUTO_Frequency}G"
|
|
|
|
fi
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
if [ "$WIRELESS_AP" ]; then
|
|
|
|
WIRELESS_OPTS2="$WIRELESS_OPTS2 ap $WIRELESS_AP"
|
|
|
|
elif [ "$WIRELESS_AUTO_Address" ]; then
|
|
|
|
WIRELESS_OPTS2="$WIRELESS_OPTS2 ap $WIRELESS_AUTO_Address"
|
|
|
|
fi
|
2013-02-21 23:51:49 +01:00
|
|
|
|
|
|
|
[ "$WIRELESS_FREQ" ] && WIRELESS_OPTS2="$WIRELESS_OPTS2 freq $WIRELESS_FREQ"
|
|
|
|
[ "$WIRELESS_RATE" ] && WIRELESS_OPTS2="$WIRELESS_OPTS2 rate $WIRELESS_RATE"
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
# Note: WIRELESS_ENC must appear as the last option
|
2013-02-21 23:51:49 +01:00
|
|
|
[ "$WIRELESS_ENC" -a "${WIRELESS_AUTO_IE:0:3}" != "WPA" ] &&
|
2011-04-26 12:26:24 +02:00
|
|
|
WIRELESS_OPTS="$WIRELESS_OPTS key $WIRELESS_ENCMODE $WIRELESS_ENC"
|
|
|
|
|
|
|
|
if [ "$WIRELESS_ESSID" -o "$WIRELESS_ENC" ]; then
|
|
|
|
echo -n "Setting wireless options for ${DEVICE}: "
|
2013-02-21 23:51:49 +01:00
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
ifconfig ${DEVICE} down
|
|
|
|
iwconfig ${DEVICE} $WIRELESS_OPTS
|
2013-02-21 23:51:49 +01:00
|
|
|
[ "$WIRELESS_OPTS2" ] && iwconfig ${DEVICE} $WIRELESS_OPTS2
|
|
|
|
|
2011-04-26 12:26:24 +02:00
|
|
|
evaluate_retval
|
|
|
|
echo
|
|
|
|
|
2013-02-21 23:51:49 +01:00
|
|
|
if [ "${WIRELESS_AUTO_IE:0:3}" = "WPA" -a ! -e /var/run/wpa_supplicant/${DEVICE} ]; then
|
|
|
|
echo -n "Setting WPA options for ${DEVICE}: "
|
|
|
|
|
|
|
|
[ "$WIRELESS_AUTO_Authentication_Suites" ] ||
|
|
|
|
WIRELESS_AUTO_Authentication_Suites=PSK
|
|
|
|
|
|
|
|
[ "$WIRELESS_AUTO_Pairwise_Ciphers" ] ||
|
|
|
|
WIRELESS_AUTO_Pairwise_Ciphers=TKIP
|
|
|
|
|
|
|
|
[ "$WIRELESS_AUTO_Group_Cipher" ] ||
|
|
|
|
WIRELESS_AUTO_Group_Cipher=TKIP
|
|
|
|
|
|
|
|
if [ "${WIRELESS_ENC:0:2}" = "s:" ]; then
|
|
|
|
WPA_PSK=\"${WIRELESS_ENC/s:}\"
|
|
|
|
else
|
|
|
|
WPA_PSK=${WIRELESS_ENC}
|
|
|
|
fi
|
|
|
|
|
|
|
|
tmpfile1=`tempfile 2>/dev/null`
|
|
|
|
cat >> $tmpfile1 << _EOF
|
2011-04-26 12:26:24 +02:00
|
|
|
ctrl_interface=/var/run/wpa_supplicant
|
|
|
|
network={
|
|
|
|
scan_ssid=0
|
|
|
|
ssid="$WIRELESS_ESSID"
|
|
|
|
proto=WPA
|
|
|
|
key_mgmt=WPA-$WIRELESS_AUTO_Authentication_Suites
|
|
|
|
pairwise=$WIRELESS_AUTO_Pairwise_Ciphers
|
|
|
|
group=$WIRELESS_AUTO_Group_Cipher
|
|
|
|
psk=$WPA_PSK
|
|
|
|
}
|
|
|
|
_EOF
|
2013-02-21 23:51:49 +01:00
|
|
|
wpa_supplicant -Dwext -i${DEVICE} -c $tmpfile1 -B
|
|
|
|
|
|
|
|
evaluate_retval
|
|
|
|
echo
|
|
|
|
|
|
|
|
rm -f $tmpfile1
|
2011-04-26 12:26:24 +02:00
|
|
|
fi
|
|
|
|
fi
|