2006-06-25 15:42:53 +00:00
|
|
|
#!/bin/sh
|
2006-06-27 00:36:13 +00:00
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
|
2006-06-25 15:42:53 +00:00
|
|
|
. /etc/functions.sh
|
|
|
|
|
2006-11-11 12:57:23 +00: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-04 23:11:47 +00:00
|
|
|
config_get ifname "$vif" ifname
|
2006-11-11 12:57:23 +00: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 05:31:21 +00:00
|
|
|
[ "$iftype" = bridge ] && config_get "$cfg" ifname
|
2006-11-11 12:57:23 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
2007-03-16 13:56:36 +00:00
|
|
|
wifi_updown() {
|
2007-07-20 16:11:46 +00:00
|
|
|
[ enable = "$1" ] && wifi_updown disable "$2"
|
2006-10-15 15:27:34 +00:00
|
|
|
for device in ${2:-$DEVICES}; do (
|
2007-03-16 13:56:36 +00:00
|
|
|
config_get disabled "$device" disabled
|
2007-06-15 16:07:09 +00:00
|
|
|
[ 1 == "$disabled" ] && {
|
2007-03-16 13:56:36 +00:00
|
|
|
echo "'$device' is disabled"
|
|
|
|
set disable
|
|
|
|
}
|
2006-10-15 15:27:34 +00:00
|
|
|
config_get iftype "$device" type
|
2007-03-16 13:56:36 +00:00
|
|
|
if eval "type ${1}_$iftype" 2>/dev/null >/dev/null; then
|
2006-10-15 15:27:34 +00:00
|
|
|
eval "scan_$iftype '$device'"
|
2007-03-16 13:56:36 +00:00
|
|
|
eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed"
|
2006-10-15 15:27:34 +00: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"
|
|
|
|
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
setup_interface "$1" "$2"
|
|
|
|
)}
|
|
|
|
|
2007-07-22 18:32:47 +00:00
|
|
|
set_wifi_up() {
|
|
|
|
local cfg="$1"
|
|
|
|
local ifname="$2"
|
|
|
|
uci set "/var/state/wireless.${cfg}.up=1"
|
|
|
|
uci set "/var/state/wireless.${cfg}.ifname=$ifname"
|
|
|
|
}
|
|
|
|
|
|
|
|
set_wifi_down() {
|
|
|
|
local cfg="$1"
|
|
|
|
local vifs vif vifstr
|
2007-07-22 18:46:57 +00:00
|
|
|
[ -f /var/state/wireless ] || return
|
|
|
|
|
2007-07-22 18:32:47 +00:00
|
|
|
config_get vifs "$cfg" vifs
|
|
|
|
for vif in $vifs; do
|
|
|
|
append vifstr "$vif" "|"
|
|
|
|
done
|
|
|
|
FILE="/var/state/wireless.$$"
|
|
|
|
grep -vE "^config_set '($vifstr)' " /var/state/wireless > "$FILE"
|
|
|
|
mv "$FILE" /var/state/wireless
|
|
|
|
}
|
|
|
|
|
2007-03-24 13:42:53 +00:00
|
|
|
scan_wifi() {
|
|
|
|
local cfgfile="$1"
|
|
|
|
config_cb() {
|
|
|
|
config_get TYPE "$CONFIG_SECTION" TYPE
|
|
|
|
case "$TYPE" in
|
|
|
|
wifi-device)
|
|
|
|
append DEVICES "$CONFIG_SECTION"
|
|
|
|
;;
|
|
|
|
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 15:42:53 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 15:27:34 +00:00
|
|
|
DEVICES=
|
|
|
|
DRIVERS=
|
2006-09-24 13:32:18 +00:00
|
|
|
include /lib/wifi
|
2007-03-24 13:42:53 +00:00
|
|
|
scan_wifi
|
2006-06-25 15:42:53 +00:00
|
|
|
|
2006-10-15 15:27:34 +00:00
|
|
|
case "$1" in
|
2007-03-16 13:56:36 +00:00
|
|
|
down) wifi_updown "disable" "$2";;
|
2006-10-15 15:27:34 +00:00
|
|
|
detect) wifi_detect "$2";;
|
2007-03-16 13:56:36 +00:00
|
|
|
*) wifi_updown "enable" "$2";;
|
2006-10-15 15:27:34 +00:00
|
|
|
esac
|