2006-06-25 18:42:53 +03:00
|
|
|
#!/bin/sh
|
2006-06-27 03:36:13 +03:00
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
|
2012-06-05 19:04:23 +03:00
|
|
|
. /lib/functions.sh
|
2006-06-25 18:42:53 +03:00
|
|
|
|
2010-12-05 13:22:56 +02:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
Usage: $0 [down|detect]
|
|
|
|
enables (default), disables or detects a wifi configuration.
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2006-11-11 14:57:23 +02:00
|
|
|
find_net_config() {(
|
|
|
|
local vif="$1"
|
|
|
|
local cfg
|
|
|
|
local ifname
|
|
|
|
|
|
|
|
config_get cfg "$vif" network
|
|
|
|
|
|
|
|
[ -z "$cfg" ] && {
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
|
2006-12-05 01:11:47 +02:00
|
|
|
config_get ifname "$vif" ifname
|
2006-11-11 14:57:23 +02:00
|
|
|
|
|
|
|
cfg="$(find_config "$ifname")"
|
|
|
|
}
|
|
|
|
[ -z "$cfg" ] && return 0
|
|
|
|
echo "$cfg"
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
bridge_interface() {(
|
|
|
|
local cfg="$1"
|
|
|
|
[ -z "$cfg" ] && return 0
|
|
|
|
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
|
|
|
|
config_get iftype "$cfg" type
|
2006-11-17 07:31:21 +02:00
|
|
|
[ "$iftype" = bridge ] && config_get "$cfg" ifname
|
2011-11-04 03:05:12 +02:00
|
|
|
prepare_interface_bridge "$cfg"
|
2006-11-11 14:57:23 +02:00
|
|
|
)}
|
|
|
|
|
2010-01-13 20:39:44 +02:00
|
|
|
prepare_key_wep() {
|
|
|
|
local key="$1"
|
|
|
|
local hex=1
|
|
|
|
|
|
|
|
echo -n "$key" | grep -qE "[^a-fA-F0-9]" && hex=0
|
|
|
|
[ "${#key}" -eq 10 -a $hex -eq 1 ] || \
|
|
|
|
[ "${#key}" -eq 26 -a $hex -eq 1 ] || {
|
|
|
|
[ "${key:0:2}" = "s:" ] && key="${key#s:}"
|
|
|
|
key="$(echo -n "$key" | hexdump -ve '1/1 "%02x" ""')"
|
|
|
|
}
|
|
|
|
echo "$key"
|
|
|
|
}
|
|
|
|
|
2009-03-27 23:14:59 +02:00
|
|
|
wifi_fixup_hwmode() {
|
|
|
|
local device="$1"
|
|
|
|
local default="$2"
|
|
|
|
local hwmode hwmode_11n
|
|
|
|
|
|
|
|
config_get channel "$device" channel
|
|
|
|
config_get hwmode "$device" hwmode
|
|
|
|
case "$hwmode" in
|
2009-04-09 23:16:01 +03:00
|
|
|
11bg) hwmode=bg;;
|
2009-03-27 23:14:59 +02:00
|
|
|
11a) hwmode=a;;
|
|
|
|
11b) hwmode=b;;
|
|
|
|
11g) hwmode=g;;
|
|
|
|
11n*)
|
|
|
|
hwmode_11n="${hwmode##11n}"
|
2010-01-24 16:27:27 +02:00
|
|
|
case "$hwmode_11n" in
|
2009-03-27 23:14:59 +02:00
|
|
|
a|g) ;;
|
|
|
|
default) hwmode_11n="$default"
|
|
|
|
esac
|
|
|
|
config_set "$device" hwmode_11n "$hwmode_11n"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
hwmode=
|
|
|
|
if [ "${channel:-0}" -gt 0 ]; then
|
|
|
|
if [ "${channel:-0}" -gt 14 ]; then
|
|
|
|
hwmode=a
|
|
|
|
else
|
|
|
|
hwmode=g
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
hwmode="$default"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
config_set "$device" hwmode "$hwmode"
|
|
|
|
}
|
2006-11-11 14:57:23 +02:00
|
|
|
|
2007-03-16 15:56:36 +02:00
|
|
|
wifi_updown() {
|
2010-02-02 04:19:10 +02:00
|
|
|
[ enable = "$1" ] && {
|
|
|
|
wifi_updown disable "$2"
|
|
|
|
scan_wifi
|
|
|
|
}
|
2006-10-15 18:27:34 +03:00
|
|
|
for device in ${2:-$DEVICES}; do (
|
2007-08-04 14:30:40 +03:00
|
|
|
config_get disabled "$device" disabled
|
|
|
|
[ 1 == "$disabled" ] && {
|
|
|
|
echo "'$device' is disabled"
|
|
|
|
set disable
|
|
|
|
}
|
2006-10-15 18:27:34 +03:00
|
|
|
config_get iftype "$device" type
|
2007-03-16 15:56:36 +02:00
|
|
|
if eval "type ${1}_$iftype" 2>/dev/null >/dev/null; then
|
2006-10-15 18:27:34 +03:00
|
|
|
eval "scan_$iftype '$device'"
|
2007-03-16 15:56:36 +02:00
|
|
|
eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed"
|
2006-10-15 18:27:34 +03:00
|
|
|
else
|
|
|
|
echo "$device($iftype): Interface type not supported"
|
|
|
|
fi
|
|
|
|
); done
|
|
|
|
}
|
|
|
|
|
|
|
|
wifi_detect() {
|
|
|
|
for driver in ${2:-$DRIVERS}; do (
|
|
|
|
if eval "type detect_$driver" 2>/dev/null >/dev/null; then
|
|
|
|
eval "detect_$driver" || echo "$driver: Detect failed" >&2
|
|
|
|
else
|
|
|
|
echo "$driver: Hardware detection not supported" >&2
|
|
|
|
fi
|
|
|
|
); done
|
|
|
|
}
|
|
|
|
|
|
|
|
start_net() {(
|
|
|
|
local iface="$1"
|
|
|
|
local config="$2"
|
2009-03-25 21:13:15 +02:00
|
|
|
local vifmac="$3"
|
2006-10-15 18:27:34 +03:00
|
|
|
|
2008-10-23 04:07:35 +03:00
|
|
|
[ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev/null
|
2011-11-08 16:42:58 +02:00
|
|
|
[ -z "$config" ] || {
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
setup_interface "$iface" "$config" "" "$vifmac"
|
|
|
|
}
|
2006-10-15 18:27:34 +03:00
|
|
|
)}
|
|
|
|
|
2007-07-22 21:32:47 +03:00
|
|
|
set_wifi_up() {
|
|
|
|
local cfg="$1"
|
|
|
|
local ifname="$2"
|
2008-02-03 08:48:15 +02:00
|
|
|
uci_set_state wireless "$cfg" up 1
|
|
|
|
uci_set_state wireless "$cfg" ifname "$ifname"
|
2007-07-22 21:32:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
set_wifi_down() {
|
|
|
|
local cfg="$1"
|
|
|
|
local vifs vif vifstr
|
2007-07-22 21:46:57 +03:00
|
|
|
|
2008-10-29 19:26:49 +02:00
|
|
|
[ -f "/var/run/wifi-${cfg}.pid" ] &&
|
2010-02-02 04:19:10 +02:00
|
|
|
kill "$(cat "/var/run/wifi-${cfg}.pid")" 2>/dev/null
|
2008-02-03 08:48:15 +02:00
|
|
|
uci_revert_state wireless "$cfg"
|
2007-07-22 21:32:47 +03:00
|
|
|
config_get vifs "$cfg" vifs
|
|
|
|
for vif in $vifs; do
|
2008-02-03 08:48:15 +02:00
|
|
|
uci_revert_state wireless "$vif"
|
2007-07-22 21:32:47 +03:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2007-03-24 15:42:53 +02:00
|
|
|
scan_wifi() {
|
|
|
|
local cfgfile="$1"
|
2010-02-02 04:19:10 +02:00
|
|
|
DEVICES=
|
2007-03-24 15:42:53 +02:00
|
|
|
config_cb() {
|
2010-07-08 21:36:12 +03:00
|
|
|
local type="$1"
|
|
|
|
local section="$2"
|
|
|
|
|
|
|
|
# section start
|
|
|
|
case "$type" in
|
2007-03-24 15:42:53 +02:00
|
|
|
wifi-device)
|
2010-07-08 21:36:12 +03:00
|
|
|
append DEVICES "$section"
|
|
|
|
config_set "$section" vifs ""
|
|
|
|
config_set "$section" ht_capab ""
|
2007-03-24 15:42:53 +02:00
|
|
|
;;
|
2010-07-08 21:36:12 +03:00
|
|
|
esac
|
|
|
|
|
|
|
|
# section end
|
|
|
|
config_get TYPE "$CONFIG_SECTION" TYPE
|
|
|
|
case "$TYPE" in
|
2007-03-24 15:42:53 +02:00
|
|
|
wifi-iface)
|
|
|
|
config_get device "$CONFIG_SECTION" device
|
|
|
|
config_get vifs "$device" vifs
|
|
|
|
append vifs "$CONFIG_SECTION"
|
|
|
|
config_set "$device" vifs "$vifs"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
config_load "${cfgfile:-wireless}"
|
2006-06-25 18:42:53 +03:00
|
|
|
}
|
|
|
|
|
2006-10-15 18:27:34 +03:00
|
|
|
DEVICES=
|
|
|
|
DRIVERS=
|
2006-09-24 16:32:18 +03:00
|
|
|
include /lib/wifi
|
2007-03-24 15:42:53 +02:00
|
|
|
scan_wifi
|
2006-06-25 18:42:53 +03:00
|
|
|
|
2006-10-15 18:27:34 +03:00
|
|
|
case "$1" in
|
2007-03-16 15:56:36 +02:00
|
|
|
down) wifi_updown "disable" "$2";;
|
2006-10-15 18:27:34 +03:00
|
|
|
detect) wifi_detect "$2";;
|
2010-12-05 13:22:56 +02:00
|
|
|
--help|help) usage;;
|
2007-03-16 15:56:36 +02:00
|
|
|
*) wifi_updown "enable" "$2";;
|
2006-10-15 18:27:34 +03:00
|
|
|
esac
|