2 # Copyright (C) 2006 OpenWrt.org
8 Usage: $0 [down|detect]
9 enables (default), disables or detects a wifi configuration.
19 config_get cfg
"$vif" network
25 config_get ifname
"$vif" ifname
27 cfg
="$(find_config "$ifname")"
29 [ -z "$cfg" ] && return 0
36 [ -z "$cfg" ] && return 0
41 config_get iftype
"$cfg" type
42 [ "$iftype" = bridge
] && config_get
"$cfg" ifname
49 echo -n "$key" |
grep -qE "[^a-fA-F0-9]" && hex
=0
50 [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
51 [ "${#key}" -eq 26 -a $hex -eq 1 ] ||
{
52 [ "${key:0:2}" = "s:" ] && key
="${key#s:}"
53 key
="$(echo -n "$key" | hexdump -ve '1/1 "%02x
" ""')"
61 local hwmode hwmode_11n
63 config_get channel
"$device" channel
64 config_get hwmode
"$device" hwmode
71 hwmode_11n
="${hwmode##11n}"
74 default
) hwmode_11n
="$default"
76 config_set
"$device" hwmode_11n
"$hwmode_11n"
80 if [ "${channel:-0}" -gt 0 ]; then
81 if [ "${channel:-0}" -gt 14 ]; then
91 config_set
"$device" hwmode
"$hwmode"
95 [ enable = "$1" ] && {
96 wifi_updown disable
"$2"
99 for device
in ${2:-$DEVICES}; do (
100 config_get disabled
"$device" disabled
101 [ 1 == "$disabled" ] && {
102 echo "'$device' is disabled"
105 config_get iftype
"$device" type
106 if eval "type ${1}_$iftype" 2>/dev
/null
>/dev
/null
; then
107 eval "scan_$iftype '$device'"
108 eval "${1}_$iftype '$device'" ||
echo "$device($iftype): ${1} failed"
110 echo "$device($iftype): Interface type not supported"
116 for driver
in ${2:-$DRIVERS}; do (
117 if eval "type detect_$driver" 2>/dev
/null
>/dev
/null
; then
118 eval "detect_$driver" ||
echo "$driver: Detect failed" >&2
120 echo "$driver: Hardware detection not supported" >&2
130 [ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev
/null
133 setup_interface
"$iface" "$config" "" "$vifmac"
139 uci_set_state wireless
"$cfg" up
1
140 uci_set_state wireless
"$cfg" ifname
"$ifname"
145 local vifs vif vifstr
147 [ -f "/var/run/wifi-${cfg}.pid" ] &&
148 kill "$(cat "/var
/run
/wifi-
${cfg}.pid
")" 2>/dev
/null
149 uci_revert_state wireless
"$cfg"
150 config_get vifs
"$cfg" vifs
152 uci_revert_state wireless
"$vif"
166 append DEVICES
"$section"
167 config_set
"$section" vifs
""
168 config_set
"$section" ht_capab
""
173 config_get TYPE
"$CONFIG_SECTION" TYPE
176 config_get device
"$CONFIG_SECTION" device
177 config_get vifs
"$device" vifs
178 append vifs
"$CONFIG_SECTION"
179 config_set
"$device" vifs
"$vifs"
183 config_load
"${cfgfile:-wireless}"
192 down
) wifi_updown
"disable" "$2";;
193 detect
) wifi_detect
"$2";;
195 *) wifi_updown
"enable" "$2";;