2006-06-25 15:42:53 +00:00
|
|
|
#!/bin/sh
|
2006-06-27 00:36:13 +00:00
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
|
2012-06-05 16:04:23 +00:00
|
|
|
. /lib/functions.sh
|
2013-12-02 16:41:03 +00:00
|
|
|
. /usr/share/libubox/jshn.sh
|
2006-06-25 15:42:53 +00:00
|
|
|
|
2010-12-05 11:22:56 +00:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
2013-12-02 16:41:03 +00:00
|
|
|
Usage: $0 [down|detect|reload|status]
|
2010-12-05 11:22:56 +00:00
|
|
|
enables (default), disables or detects a wifi configuration.
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-12-02 16:41:03 +00:00
|
|
|
ubus_wifi_cmd() {
|
|
|
|
local cmd="$1"
|
|
|
|
local dev="$2"
|
|
|
|
|
|
|
|
json_init
|
|
|
|
[ -n "$2" ] && json_add_string device "$2"
|
|
|
|
ubus call network.wireless "$1" "$(json_dump)"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2012-06-26 15:25:33 +00:00
|
|
|
for cfg in $cfg; do
|
|
|
|
config_get iftype "$cfg" type
|
|
|
|
[ "$iftype" = bridge ] && config_get "$cfg" ifname
|
|
|
|
prepare_interface_bridge "$cfg"
|
|
|
|
return $?
|
|
|
|
done
|
2006-11-11 12:57:23 +00:00
|
|
|
)}
|
|
|
|
|
2010-01-13 18:39:44 +00: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:}"
|
2013-12-09 11:30:14 +00:00
|
|
|
key="$(echo -n "$key" | hexdump -ve '1/1 "%02x" ""')"
|
2010-01-13 18:39:44 +00:00
|
|
|
}
|
|
|
|
echo "$key"
|
|
|
|
}
|
|
|
|
|
2009-03-27 21:14:59 +00: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 20:16:01 +00:00
|
|
|
11bg) hwmode=bg;;
|
2009-03-27 21:14:59 +00:00
|
|
|
11a) hwmode=a;;
|
|
|
|
11b) hwmode=b;;
|
|
|
|
11g) hwmode=g;;
|
|
|
|
11n*)
|
|
|
|
hwmode_11n="${hwmode##11n}"
|
2010-01-24 14:27:27 +00:00
|
|
|
case "$hwmode_11n" in
|
2009-03-27 21:14:59 +00:00
|
|
|
a|g) ;;
|
|
|
|
default) hwmode_11n="$default"
|
|
|
|
esac
|
|
|
|
config_set "$device" hwmode_11n "$hwmode_11n"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
hwmode=
|
2013-12-09 11:30:14 +00:00
|
|
|
if [ "${channel:-0}" -gt 0 ]; then
|
2009-03-27 21:14:59 +00:00
|
|
|
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 12:57:23 +00:00
|
|
|
|
2013-12-02 16:41:03 +00:00
|
|
|
_wifi_updown() {
|
2006-10-15 15:27:34 +00:00
|
|
|
for device in ${2:-$DEVICES}; do (
|
2007-08-04 11:30:40 +00:00
|
|
|
config_get disabled "$device" disabled
|
2014-10-14 12:21:11 +00:00
|
|
|
[ "$disabled" = "1" ] && {
|
2007-08-04 11:30:40 +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"
|
2013-12-02 16:41:03 +00:00
|
|
|
elif [ ! -f /lib/netifd/wireless/$iftype.sh ]; then
|
2006-10-15 15:27:34 +00:00
|
|
|
echo "$device($iftype): Interface type not supported"
|
|
|
|
fi
|
|
|
|
); done
|
|
|
|
}
|
|
|
|
|
2013-12-02 16:41:03 +00:00
|
|
|
wifi_updown() {
|
|
|
|
cmd=down
|
|
|
|
[ enable = "$1" ] && {
|
|
|
|
_wifi_updown disable "$2"
|
2013-12-02 16:53:27 +00:00
|
|
|
ubus_wifi_cmd "$cmd" "$2"
|
2013-12-02 16:41:03 +00:00
|
|
|
scan_wifi
|
|
|
|
cmd=up
|
|
|
|
}
|
|
|
|
ubus_wifi_cmd "$cmd" "$2"
|
|
|
|
_wifi_updown "$@"
|
|
|
|
}
|
|
|
|
|
2013-12-02 16:53:24 +00:00
|
|
|
wifi_reload_legacy() {
|
2013-12-02 16:41:03 +00:00
|
|
|
_wifi_updown "disable" "$1"
|
|
|
|
scan_wifi
|
|
|
|
_wifi_updown "enable" "$1"
|
|
|
|
}
|
|
|
|
|
2013-12-02 16:53:24 +00:00
|
|
|
wifi_reload() {
|
|
|
|
ubus call network reload
|
|
|
|
wifi_reload_legacy
|
|
|
|
}
|
|
|
|
|
base-files, mac80211, broadcom-wl: wifi detection and configuration
Currently, the wifi detection script is executed as part of
the (early) boot process. Pluggable wifi USB devices, which
are inserted at a later time are not automatically
detected and therefore they don't show up in LuCI.
A user has to deal with wifi detection manually, or restart
the router.
However, the current "sleep 1" window - which the boot
process waits for wifi devices to "settle down" - is too
short to detect wifi devices for some routers anyway.
For example, this can happen with USB WLAN devices on the
WNDR4700. This is because the usb controller needs to load
its firmware from UBI and initialize, before it can operate.
The issue can be seen on a BT HomeHub 5A as well as soon as
the caldata are on an ubi volume. This is because the ath9k
card has to be initialized by owl-loader first. Which has to
wait for the firmware extraction script to retrieve the pci
initialization values inside the caldata.
This patch moves the wifi configuration to hotplug scripts.
For mac80211, the wifi configuration will now automatically
run any time a "ieee80211" device is added. Likewise
broadcom-wl's script checks for new "net" devices which
have the "wl$NUMBER" moniker.
Issues with spawning multiple interface configuration - in
case the detection script is run concurrently - have been
resolved by using a named section for the initial
configuration. Concurrent configuration scripts will now
simply overwrite the same existing configuration.
A workaround which preserves the "sleep 1" window for just
the first boot has been added. This allows the existing
brcm47xx boot and mvebu uci-default scripts to correctly
setup the initial mac addresses and regulatory domain.
And finally, the patch renames the "wifi detect" into
"wifi config". As the script no longer produces any output
that has to be redirected or appended to the configuration
file.
Thanks to Martin Blumenstingl for helping with the implementation
and testing of the patch.
Acked-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Mathias Kresin <dev@kresin.me>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-10-17 13:59:14 +00:00
|
|
|
wifi_config() {
|
2016-10-17 13:59:12 +00:00
|
|
|
[ ! -f /etc/config/wireless ] && touch /etc/config/wireless
|
|
|
|
|
2016-09-29 17:55:33 +00:00
|
|
|
for driver in $DRIVERS; do (
|
2006-10-15 15:27:34 +00:00
|
|
|
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 19:13:15 +00:00
|
|
|
local vifmac="$3"
|
2006-10-15 15:27:34 +00:00
|
|
|
|
2008-10-23 01:07:35 +00:00
|
|
|
[ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev/null
|
2011-11-08 14:42:58 +00:00
|
|
|
[ -z "$config" ] || {
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
2012-06-26 15:25:33 +00:00
|
|
|
for config in $config; do
|
|
|
|
setup_interface "$iface" "$config" "" "$vifmac"
|
|
|
|
done
|
2011-11-08 14:42:58 +00:00
|
|
|
}
|
2006-10-15 15:27:34 +00:00
|
|
|
)}
|
|
|
|
|
2007-07-22 18:32:47 +00:00
|
|
|
set_wifi_up() {
|
|
|
|
local cfg="$1"
|
|
|
|
local ifname="$2"
|
2008-02-03 06:48:15 +00:00
|
|
|
uci_set_state wireless "$cfg" up 1
|
|
|
|
uci_set_state wireless "$cfg" ifname "$ifname"
|
2007-07-22 18:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_wifi_down() {
|
|
|
|
local cfg="$1"
|
|
|
|
local vifs vif vifstr
|
2007-07-22 18:46:57 +00:00
|
|
|
|
2008-10-29 17:26:49 +00:00
|
|
|
[ -f "/var/run/wifi-${cfg}.pid" ] &&
|
2010-02-02 02:19:10 +00:00
|
|
|
kill "$(cat "/var/run/wifi-${cfg}.pid")" 2>/dev/null
|
2008-02-03 06:48:15 +00:00
|
|
|
uci_revert_state wireless "$cfg"
|
2007-07-22 18:32:47 +00:00
|
|
|
config_get vifs "$cfg" vifs
|
|
|
|
for vif in $vifs; do
|
2008-02-03 06:48:15 +00:00
|
|
|
uci_revert_state wireless "$vif"
|
2007-07-22 18:32:47 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2007-03-24 13:42:53 +00:00
|
|
|
scan_wifi() {
|
|
|
|
local cfgfile="$1"
|
2010-02-02 02:19:10 +00:00
|
|
|
DEVICES=
|
2007-03-24 13:42:53 +00:00
|
|
|
config_cb() {
|
2010-07-08 18:36:12 +00:00
|
|
|
local type="$1"
|
|
|
|
local section="$2"
|
|
|
|
|
|
|
|
# section start
|
|
|
|
case "$type" in
|
2007-03-24 13:42:53 +00:00
|
|
|
wifi-device)
|
2010-07-08 18:36:12 +00:00
|
|
|
append DEVICES "$section"
|
|
|
|
config_set "$section" vifs ""
|
|
|
|
config_set "$section" ht_capab ""
|
2007-03-24 13:42:53 +00:00
|
|
|
;;
|
2010-07-08 18:36:12 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
# section end
|
|
|
|
config_get TYPE "$CONFIG_SECTION" TYPE
|
|
|
|
case "$TYPE" in
|
2007-03-24 13:42:53 +00:00
|
|
|
wifi-iface)
|
|
|
|
config_get device "$CONFIG_SECTION" device
|
2013-12-09 11:30:14 +00:00
|
|
|
config_get vifs "$device" vifs
|
2007-03-24 13:42:53 +00:00
|
|
|
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";;
|
base-files, mac80211, broadcom-wl: wifi detection and configuration
Currently, the wifi detection script is executed as part of
the (early) boot process. Pluggable wifi USB devices, which
are inserted at a later time are not automatically
detected and therefore they don't show up in LuCI.
A user has to deal with wifi detection manually, or restart
the router.
However, the current "sleep 1" window - which the boot
process waits for wifi devices to "settle down" - is too
short to detect wifi devices for some routers anyway.
For example, this can happen with USB WLAN devices on the
WNDR4700. This is because the usb controller needs to load
its firmware from UBI and initialize, before it can operate.
The issue can be seen on a BT HomeHub 5A as well as soon as
the caldata are on an ubi volume. This is because the ath9k
card has to be initialized by owl-loader first. Which has to
wait for the firmware extraction script to retrieve the pci
initialization values inside the caldata.
This patch moves the wifi configuration to hotplug scripts.
For mac80211, the wifi configuration will now automatically
run any time a "ieee80211" device is added. Likewise
broadcom-wl's script checks for new "net" devices which
have the "wl$NUMBER" moniker.
Issues with spawning multiple interface configuration - in
case the detection script is run concurrently - have been
resolved by using a named section for the initial
configuration. Concurrent configuration scripts will now
simply overwrite the same existing configuration.
A workaround which preserves the "sleep 1" window for just
the first boot has been added. This allows the existing
brcm47xx boot and mvebu uci-default scripts to correctly
setup the initial mac addresses and regulatory domain.
And finally, the patch renames the "wifi detect" into
"wifi config". As the script no longer produces any output
that has to be redirected or appended to the configuration
file.
Thanks to Martin Blumenstingl for helping with the implementation
and testing of the patch.
Acked-by: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Mathias Kresin <dev@kresin.me>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-10-17 13:59:14 +00:00
|
|
|
detect) ;;
|
|
|
|
config) wifi_config ;;
|
2013-12-02 16:41:03 +00:00
|
|
|
status) ubus_wifi_cmd "status" "$2";;
|
|
|
|
reload) wifi_reload "$2";;
|
2013-12-02 16:53:24 +00:00
|
|
|
reload_legacy) wifi_reload_legacy "$2";;
|
2010-12-05 11:22:56 +00:00
|
|
|
--help|help) usage;;
|
2013-12-11 19:48:19 +00:00
|
|
|
*) ubus call network reload; wifi_updown "enable" "$2";;
|
2006-10-15 15:27:34 +00:00
|
|
|
esac
|