2007-04-05 16:48:42 +05:30
|
|
|
# Copyright 2004-2007 Gentoo Foundation
|
2007-11-14 20:52:04 +05:30
|
|
|
# Copyright 2007 Roy Marples
|
|
|
|
# All rights reserved
|
|
|
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-13 03:07:59 +05:30
|
|
|
_config_vars="$_config_vars ssid mode associate_timeout preferred_aps blacklist_aps"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
iwconfig_depend() {
|
2007-10-25 14:41:18 +05:30
|
|
|
program /sbin/ifconfig
|
|
|
|
after plug
|
|
|
|
before interface
|
|
|
|
provide wireless
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_get_wep_status() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local status="disabled"
|
|
|
|
local mode=$(LC_ALL=C ifconfig "${IFACE}" \
|
|
|
|
| sed -n -e 's/^[[:space:]]*authmode \([^ ]*\) privacy ON .*/\1/p')
|
|
|
|
if [ -n "${mode}" ] ; then
|
|
|
|
status="enabled - ${mode}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "(WEP ${status})"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_iwconfig_get() {
|
2007-10-25 14:41:18 +05:30
|
|
|
LC_ALL=C ifconfig "${IFACE}" | \
|
|
|
|
sed -n -e "s/^[[:space:]]*ssid \(.*\) channel \([0-9]*\) bssid \(..:..:..:..:..:..\)\$/\\$1/p"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_get_ssid() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local ssid="$(_iwconfig_get 1)"
|
|
|
|
# If the ssid has a space then it's wrapped in quotes.
|
|
|
|
# This is a problem if the real ssid has a quote at the start or the end :/
|
|
|
|
ssid=${ssid#\"}
|
|
|
|
ssid=${ssid%\"}
|
|
|
|
echo "${ssid}"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_get_ap_mac_address() {
|
2007-10-25 14:41:18 +05:30
|
|
|
_iwconfig_get 3
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_get_channel() {
|
2007-10-25 14:41:18 +05:30
|
|
|
_iwconfig_get 2
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_report() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local m="connected to"
|
|
|
|
local ssid="$(_get_ssid)"
|
|
|
|
local mac="$(_get_ap_mac_address "${iface}")"
|
|
|
|
[ -n "${mac}" ] && mac=" at ${mac}"
|
|
|
|
local wep_status="$(iwconfig_get_wep_status "${iface}")"
|
|
|
|
local channel="$(_get_channel)"
|
|
|
|
[ -n "${channel}" ] && channel="on channel ${channel} "
|
|
|
|
|
|
|
|
eindent
|
|
|
|
einfo "${IFACE} ${m} \"${ssid}\"${mac}"
|
|
|
|
einfo "${channel}${wep_status}"
|
|
|
|
eoutdent
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_get_wep_key() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local mac="$1" key=
|
|
|
|
[ -n "${mac}" ] && mac="$(echo "${mac}" | sed -e 's/://g')"
|
|
|
|
eval key=\$mac_key_${mac}
|
|
|
|
[ -z "${key}" ] && eval key=\$key_${SSIDVAR}
|
|
|
|
echo "${key:--}"
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_user_config() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local conf=
|
|
|
|
eval set -- \$ifconfig_${SSIDVAR}
|
|
|
|
for conf in "$@" ; do
|
|
|
|
ifconfig "${IFACE}" ${conf}
|
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_set_mode() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local x= opt= unopt="hostap adhoc"
|
|
|
|
case "$1" in
|
|
|
|
master|hostap) unopt="adhoc" opt="hostap" ;;
|
|
|
|
ad-hoc|adhoc) unopt="hostap" opt="adhoc" ;;
|
|
|
|
esac
|
|
|
|
for x in ${unopt} ; do
|
|
|
|
ifconfig "${IFACE}" -mediaopt ${x}
|
|
|
|
done
|
|
|
|
for x in ${opt} ; do
|
|
|
|
ifconfig "${IFACE}" mediaopt ${x}
|
|
|
|
done
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_setup_specific() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local mode="${1:-master}" channel=
|
|
|
|
if [ -z "${SSID}" ]; then
|
|
|
|
eerror "${IFACE} requires an SSID to be set to operate in ${mode} mode"
|
|
|
|
eerror "adjust the ssid_${IFVAR} setting in /etc/conf.d/net"
|
|
|
|
return 1
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
iwconfig_set_mode "${mode}" || return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
SSIDVAR=$(_shell_var "${SSID}")
|
|
|
|
local key=$(iwconfig_get_wep_key)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
# Now set the key
|
|
|
|
ifconfig "${IFACE}" wepkey "${key}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
ifconfig "${IFACE}" ssid "${SSID}" || return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
eval channel=\$channel_${IFVAR}
|
|
|
|
# We default the channel to 3
|
|
|
|
ifconfig "${IFACE}" channel "${channel:-3}" || return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
iwconfig_user_config
|
|
|
|
iwconfig_report "${iface}"
|
|
|
|
return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_associate() {
|
2007-10-25 14:41:18 +05:30
|
|
|
local mac="$1" channel="$2" caps="$3"
|
|
|
|
local mode= w="(WEP Disabled)" key=
|
|
|
|
|
|
|
|
SSIDVAR=$(_shell_var "${SSID}")
|
|
|
|
key=$(iwconfig_get_wep_key "${mac}")
|
|
|
|
case "${caps}" in
|
|
|
|
[EI]P*)
|
|
|
|
if [ "${key}" = "-" ] ; then
|
|
|
|
ewarn "WEP key is not set for \"${SSID}\"; not connecting"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"") ;;
|
|
|
|
*)
|
|
|
|
if [ "${key}" != "-" ] ; then
|
|
|
|
key="-"
|
|
|
|
ewarn "\"${SSID}\" is not WEP enabled; ignoring setting"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Set mode accordingly
|
|
|
|
case "${caps}" in
|
|
|
|
*E*)
|
2007-04-05 16:48:42 +05:30
|
|
|
mode="managed"
|
2007-10-25 14:41:18 +05:30
|
|
|
if LC_ALL=C ifconfig "${IFACE}" | \
|
|
|
|
grep -q "^[[:space:]]*media: .*adhoc" ; then
|
|
|
|
ifconfig "${IFACE}" down -mediaopt adhoc up
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*I*)
|
|
|
|
mode="adhoc"
|
|
|
|
if ! LC_ALL=C ifconfig "${IFACE}" | \
|
|
|
|
grep -q "^[[:space:]]*media: .*adhoc" ; then
|
|
|
|
ifconfig "${IFACE}" down mediaopt adhoc up
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if LC_ALL=C ifconfig "${IFACE}" \
|
|
|
|
| grep -q "^[[:space:]]*media: .*adhoc" ; then
|
|
|
|
mode="adhoc"
|
|
|
|
else
|
|
|
|
mode="managed"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "${key}" = "-" ] ; then
|
|
|
|
ifconfig "${IFACE}" wepmode off
|
|
|
|
else
|
|
|
|
ifconfig "${IFACE}" wepmode on
|
|
|
|
ifconfig "${IFACE}" deftxkey 1
|
|
|
|
w=$(iwconfig_get_wep_status)
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
ebegin "Connecting to \"${SSID}\" in ${mode} mode ${w}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
if ! ifconfig "${IFACE}" wepkey "${key}" ; then
|
|
|
|
eerror "Invalid WEP key ${key}"
|
|
|
|
return 1
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
ifconfig "${IFACE}" ssid "${SSID}" || return 1
|
|
|
|
iwconfig_user_config
|
|
|
|
|
|
|
|
if [ "${SSID}" != "any" ] && type preassociate >/dev/null 2>/dev/null ; then
|
|
|
|
veinfo "Running preassociate function"
|
|
|
|
veindent
|
|
|
|
( preassociate )
|
|
|
|
local e=$?
|
|
|
|
veoutdent
|
|
|
|
if [ ${e} -eq 0 ] ; then
|
|
|
|
veend 1 "preassociate \"${SSID}\" on ${IFACE} failed"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
local timeout= i=0
|
|
|
|
eval timeout=\$associate_timeout_${IFVAR}
|
|
|
|
timeout=${timeout:-10}
|
|
|
|
|
|
|
|
[ ${timeout} -eq 0 ] \
|
|
|
|
&& vewarn "WARNING: infinite timeout set for association on ${IFACE}"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
_has_carrier && break
|
|
|
|
sleep 1
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
[ ${timeout} -eq 0 ] && continue
|
|
|
|
i=$((${i} + 1))
|
|
|
|
[ ${i} -ge ${timeout} ] && { eend 1; return 1; }
|
|
|
|
done
|
|
|
|
|
|
|
|
_has_carrier || { eend 1; return 1; }
|
|
|
|
eend 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
if [ "${SSID}" = "any" ]; then
|
|
|
|
SSID="$(_get_ssid)"
|
|
|
|
iwconfig_associate
|
|
|
|
return $?
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
iwconfig_report
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-25 14:41:18 +05:30
|
|
|
if type postassociate >/dev/null 2>/dev/null ; then
|
|
|
|
veinfo "Running postassociate function"
|
|
|
|
veindent
|
|
|
|
( postassociate )
|
|
|
|
veoutdent
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_scan() {
|
|
|
|
local x= i=0 scan= quality=
|
|
|
|
einfo "Scanning for access points"
|
|
|
|
eindent
|
|
|
|
|
|
|
|
scan="$(LC_ALL=C ifconfig -v "${IFACE}" list scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")"
|
2007-04-10 18:11:38 +05:30
|
|
|
while [ ${i} -lt 3 -a -z "${scan}" ] ; do
|
2007-10-25 14:41:18 +05:30
|
|
|
scan="${scan}${scan:+ }$(LC_ALL=C ifconfig -v "${IFACE}" scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")"
|
|
|
|
i=$((${i} + 1))
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
2007-10-25 14:41:18 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
APS=-1
|
|
|
|
eval set -- ${scan}
|
|
|
|
for line in "$@" ; do
|
2007-10-25 14:41:18 +05:30
|
|
|
APS=$((${APS} + 1))
|
|
|
|
set -- ${line}
|
|
|
|
while true ; do
|
|
|
|
case "$1" in
|
|
|
|
*:*:*:*:*:*) break ;;
|
|
|
|
esac
|
|
|
|
eval SSID_${APS}="\"\${SSID_${APS}}\${SSID_${APS}:+ }$1\""
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
eval MAC_${APS}="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
|
|
|
eval CHAN_${APS}="$2"
|
|
|
|
quality=${4%:*}
|
|
|
|
shift ; shift ; shift ; shift ; shift
|
|
|
|
eval CAPS_${APS}="\"$*\""
|
|
|
|
|
|
|
|
# Add 1000 for managed nodes as we prefer them to adhoc
|
|
|
|
set -- $*
|
2007-04-05 16:48:42 +05:30
|
|
|
case "$1" in
|
2007-10-25 14:41:18 +05:30
|
|
|
*E*) eval QUAL_${APS}=$((${quality} + 1000)) ;;
|
|
|
|
*) eval QUAL_${APS}=\$quality ;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "${MAC_0}" ]; then
|
|
|
|
ewarn "no access points found"
|
|
|
|
eoutdent
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Sort based on quality
|
|
|
|
local i=0 k=1 a= b= x= t=
|
|
|
|
while [ ${i} -lt ${APS} ] ; do
|
2007-10-25 14:41:18 +05:30
|
|
|
k=$((${i} + 1))
|
|
|
|
while [ ${k} -le ${APS} ] ; do
|
|
|
|
eval a=\$QUALITY_${i}
|
|
|
|
[ -z "${a}" ] && break
|
|
|
|
eval b=\$QUALITY_${k}
|
|
|
|
if [ -n "${b}" -a "${a}" -lt "${b}" ] ; then
|
|
|
|
for x in MAC SSID CHAN QUALITY CAPS ; do
|
|
|
|
eval t=\$${x}_${i}
|
|
|
|
eval ${x}_${i}=\$${x}_${k}
|
|
|
|
eval ${x}_${k}=\$t
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
k=$((${k} + 1))
|
|
|
|
done
|
|
|
|
i=$((${i} + 1))
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
|
|
|
|
# Strip any duplicates
|
|
|
|
local i=0 k=1 a= b=
|
|
|
|
while [ ${i} -lt ${APS} ] ; do
|
2007-10-25 14:41:18 +05:30
|
|
|
k=$((${i} + 1))
|
|
|
|
while [ ${k} -le ${APS} ] ; do
|
|
|
|
eval a=\$MAC_${i}
|
|
|
|
eval b=\$MAC_${k}
|
|
|
|
if [ "${a}" = "${b}" ] ; then
|
|
|
|
eval a=\$QUALITY_${i}
|
|
|
|
eval b=\$QUALITY_${k}
|
|
|
|
if [ -n "${a}" -a -n "${b}" ] ; then
|
|
|
|
if [ ${a} -ge ${b} ] ; then
|
|
|
|
unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k}
|
|
|
|
else
|
|
|
|
unset MAC_${i} SSID_${i} CHAN_${i} QUALITY_${i} CAPS_${i}
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k}
|
|
|
|
fi
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2007-10-25 14:41:18 +05:30
|
|
|
k=$((${k} + 1))
|
|
|
|
done
|
|
|
|
i=$((${i} + 1))
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
|
2007-11-14 23:53:59 +05:30
|
|
|
local i=0 e= m= s=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
while [ ${i} -le ${APS} ] ; do
|
|
|
|
eval x=\$MAC_${i}
|
|
|
|
if [ -z "${x}" ] ; then
|
2007-10-25 14:41:18 +05:30
|
|
|
i=$((${i} + 1))
|
|
|
|
continue
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
eval m=\$MODE_${i}
|
|
|
|
[ -n "${m}" ] && m=", ${m}"
|
|
|
|
eval s=\$SSID_${i}
|
|
|
|
eval q=\$QUALITY_${i}
|
|
|
|
eval e=\$CAPS_${i}
|
|
|
|
case "${e}" in
|
2007-10-25 14:41:18 +05:30
|
|
|
[EI]P*) e=", encrypted" ;;
|
|
|
|
*) e="" ;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
if [ -z "${s}" ] ; then
|
|
|
|
einfo "Found ${x}${m}${e}"
|
|
|
|
else
|
|
|
|
einfo "Found \"${s}\" at ${x}${m}${e}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
x="$(echo "${x}" | sed -e 's/://g')"
|
|
|
|
eval x=\$mac_ssid_${x}
|
|
|
|
if [ -n "${x}" ] ; then
|
|
|
|
eval SSID_${i}=\$x
|
|
|
|
s=${x}
|
|
|
|
eindent
|
|
|
|
einfo "mapping to \"${x}\""
|
|
|
|
eoutdent
|
|
|
|
fi
|
|
|
|
|
2007-11-14 23:53:59 +05:30
|
|
|
eval set -- $(_flatten_array "blacklist_aps_${IFVAR}")
|
|
|
|
[ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps")
|
|
|
|
for x in "$@"; do
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ "${x}" = "${s}" ] ; then
|
|
|
|
ewarn "${s} has been blacklisted - not connecting"
|
|
|
|
unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
i=$((${i} + 1))
|
|
|
|
done
|
|
|
|
eoutdent
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_force_preferred() {
|
2007-11-14 23:53:59 +05:30
|
|
|
eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
|
|
|
|
[ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
|
|
|
|
[ $# = 0 ] && return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
ewarn "Trying to force preferred in case they are hidden"
|
2007-11-14 23:53:59 +05:30
|
|
|
local ssid=
|
|
|
|
for ssid in "$@"; do
|
2007-04-05 16:48:42 +05:30
|
|
|
local found_AP=false i=0 e=
|
2007-05-13 03:07:59 +05:30
|
|
|
while [ ${i} -le ${APS:--1} ] ; do
|
2007-04-05 16:48:42 +05:30
|
|
|
eval e=\$SSID_${i}
|
|
|
|
if [ "${e}" = "${ssid}" ] ; then
|
|
|
|
found_AP=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
i=$((${i} + 1))
|
|
|
|
done
|
|
|
|
if ! ${found_AP} ; then
|
2007-05-13 03:07:59 +05:30
|
|
|
SSID=${ssid}
|
2007-04-05 16:48:42 +05:30
|
|
|
iwconfig_associate && return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
ewarn "Failed to associate with any preferred access points on ${IFACE}"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_connect_preferred() {
|
2007-11-14 23:53:59 +05:30
|
|
|
eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
|
|
|
|
[ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
|
|
|
|
[ $# = 0 ] && return 1
|
2007-05-13 03:07:59 +05:30
|
|
|
|
2007-11-14 23:53:59 +05:30
|
|
|
local ssid= i=0 mode= mac= caps= freq= chan=
|
|
|
|
for ssid in "$@"; do
|
2007-04-05 16:48:42 +05:30
|
|
|
while [ ${i} -le ${APS} ] ; do
|
|
|
|
eval e=\$SSID_${i}
|
2007-05-13 03:07:59 +05:30
|
|
|
if [ "${e}" = "${ssid}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
SSID=${e}
|
|
|
|
eval mac=\$MAC_${i}
|
|
|
|
eval caps=\$CAPS_${i}
|
|
|
|
eval freq=\$FREQ_${i}
|
|
|
|
eval chan=\$CHAN_${i}
|
|
|
|
iwconfig_associate "${mac}" \
|
|
|
|
"${chan}" "${caps}" && return 0
|
|
|
|
fi
|
|
|
|
i=$((${i} + 1))
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_connect_not_preferred() {
|
2007-05-13 03:07:59 +05:30
|
|
|
local ssid= i=0 mode= mac= caps= freq= chan= pref=
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
while [ ${i} -le ${APS} ] ; do
|
|
|
|
eval e=\$SSID_${i}
|
|
|
|
if [ -z "${e}" ] ; then
|
2007-10-25 14:41:18 +05:30
|
|
|
i=$((${i} + 1))
|
|
|
|
continue
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
2007-11-14 23:53:59 +05:30
|
|
|
eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
|
|
|
|
[ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
|
2007-04-05 16:48:42 +05:30
|
|
|
pref=false
|
2007-11-14 23:53:59 +05:30
|
|
|
for ssid in "$@"; do
|
2007-05-13 03:07:59 +05:30
|
|
|
if [ "${e}" = "${ssid}" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
pref=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! ${pref} ; then
|
|
|
|
SSID=${e}
|
|
|
|
eval mac=\$MAC_${i}
|
|
|
|
eval caps=\$CAPS_${i}
|
|
|
|
eval freq=\$FREQ_${i}
|
|
|
|
eval chan=\$CHAN_${i}
|
|
|
|
iwconfig_associate "${mac}" \
|
2007-10-25 14:41:18 +05:30
|
|
|
"${chan}" "${caps}" && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
i=$((${i} + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_defaults() {
|
|
|
|
# Set some defaults
|
|
|
|
#ifconfig "${iface}" txpower 100 2>/dev/null
|
|
|
|
ifconfig "${IFACE}" bssid -
|
|
|
|
ifconfig "${IFACE}" ssid -
|
2007-04-10 18:11:38 +05:30
|
|
|
ifconfig "${IFACE}" wepkey 1:- wepkey 2:- wepkey 3:- wepkey 4:-
|
2007-04-05 16:48:42 +05:30
|
|
|
ifconfig "${IFACE}" authmode open
|
|
|
|
ifconfig "${IFACE}" -mediaopt adhoc
|
|
|
|
ifconfig "${IFACE}" -mediaopt hostap
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_configure() {
|
|
|
|
local x APS
|
|
|
|
eval SSID=\$ssid_${IFVAR}
|
|
|
|
|
|
|
|
# Setup ad-hoc mode?
|
|
|
|
eval x=\$mode_${IFVAR}
|
|
|
|
x=${x:-managed}
|
|
|
|
case "${x}" in
|
2007-10-25 14:41:18 +05:30
|
|
|
ad-hoc|adhoc|hostap|master) iwconfig_setup_specific "${x}" ;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
|
2007-05-16 12:03:25 +05:30
|
|
|
if [ "${x}" != "managed" -a "${x}" != "auto" -a "${x}" != "ad-hoc" -a "${x}" != "adhoc" -a ${x} != "master" ] ; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "Only managed, ad-hoc, master and auto modes are supported"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-10-25 12:11:29 +05:30
|
|
|
# Has an SSID been forced?
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ -n "${SSID}" ]; then
|
|
|
|
iwconfig_set_mode "${x}"
|
|
|
|
iwconfig_associate && return 0
|
|
|
|
[ "${SSID}" = "any" ] && iwconfig_force_preferred && return 0
|
|
|
|
|
|
|
|
eval SSID=\$adhoc_ssid_${IFVAR}
|
|
|
|
if [ -n "${SSID}" ]; then
|
|
|
|
iwconfig_setup_specific adhoc
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Are we forcing preferred only?
|
|
|
|
eval x=\$associate_order_${IFVAR}
|
|
|
|
[ -n "${x}" ] && associate_order=${x}
|
|
|
|
associate_order=${associate_order:-any}
|
|
|
|
if [ "${associate_order}" = "forcepreferredonly" ]; then
|
|
|
|
iwconfig_force_preferred && return 0
|
|
|
|
else
|
|
|
|
iwconfig_scan || return 1
|
|
|
|
iwconfig_connect_preferred && return 0
|
|
|
|
[ "${associate_order}" = "forcepreferred" ] || \
|
|
|
|
[ "${associate_order}" = "forceany" ] && \
|
|
|
|
iwconfig_force_preferred && return 0
|
|
|
|
[ "${associate_order}" = "any" ] || \
|
|
|
|
[ "${associate_order}" = "forceany" ] && \
|
|
|
|
iwconfig_connect_not_preferred && return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
e="associate with"
|
|
|
|
[ -z "${MAC_0}" ] && e="find"
|
|
|
|
[ "${preferred_aps}" = "force" ] || \
|
|
|
|
[ "${preferred_aps}" = "forceonly" ] && \
|
|
|
|
e="force"
|
|
|
|
e="Couldn't ${e} any access points on ${IFACE}"
|
|
|
|
|
|
|
|
eval SSID=\$adhoc_ssid_${IFVAR}
|
|
|
|
if [ -n "${SSID}" ]; then
|
|
|
|
ewarn "${e}"
|
|
|
|
iwconfig_setup_specific adhoc
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
eerror "${e}"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_pre_start() {
|
|
|
|
# We don't configure wireless if we're being called from
|
|
|
|
# the background
|
|
|
|
${IN_BACKGROUND} && return 0
|
|
|
|
|
|
|
|
save_options "SSID" ""
|
|
|
|
_exists || return 0
|
|
|
|
|
|
|
|
if ! _is_wireless ; then
|
|
|
|
veinfo "${IFACE} is not wireless"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
iwconfig_defaults
|
|
|
|
iwconfig_user_config
|
2007-10-25 14:41:18 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
# Set the base metric to be 2000
|
|
|
|
metric=2000
|
|
|
|
|
|
|
|
einfo "Configuring wireless network for ${IFACE}"
|
|
|
|
|
|
|
|
if iwconfig_configure ; then
|
2007-10-25 12:11:29 +05:30
|
|
|
save_options "SSID" "${SSID}"
|
2007-04-05 16:48:42 +05:30
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
eerror "Failed to configure wireless for ${IFACE}"
|
|
|
|
iwconfig_defaults
|
|
|
|
#iwconfig "${IFACE}" txpower 0 2>/dev/null
|
|
|
|
unset SSID SSIDVAR
|
|
|
|
_down
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
iwconfig_post_stop() {
|
|
|
|
${IN_BACKGROUND} && return 0
|
|
|
|
_is_wireless || return 0
|
|
|
|
iwconfig_defaults
|
|
|
|
#iwconfig "${IFACE}" txpower 0 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# vim: set ts=4
|