2 # Copyright (C) 2006 OpenWrt.org
5 .
/usr
/share
/libubox
/jshn.sh
9 Usage: $0 [config|up|down|reconf|reload|status|isup]
10 enables (default), disables or configures devices not yet configured.
20 [ -n "$dev" ] && json_add_string device
"$dev"
21 ubus call network.wireless
"$cmd" "$(json_dump)"
27 json_load
"$(ubus_wifi_cmd "status
" "$dev")"
30 for device
in $devices; do
33 [ $up -eq 0 ] && return 1
45 config_get cfg
"$vif" network
51 config_get ifname
"$vif" ifname
53 cfg
="$(find_config "$ifname")"
55 [ -z "$cfg" ] && return 0
62 [ -z "$cfg" ] && return 0
68 config_get iftype
"$cfg" type
69 [ "$iftype" = bridge
] && config_get
"$cfg" ifname
70 prepare_interface_bridge
"$cfg"
79 echo -n "$key" |
grep -qE "[^a-fA-F0-9]" && hex
=0
80 [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
81 [ "${#key}" -eq 26 -a $hex -eq 1 ] ||
{
82 [ "${key:0:2}" = "s:" ] && key
="${key#s:}"
83 key
="$(echo -n "$key" | hexdump -ve '1/1 "%02x
" ""')"
91 local hwmode hwmode_11n
93 config_get channel
"$device" channel
94 config_get hwmode
"$device" hwmode
102 hwmode_11n
="${hwmode##11n}"
103 case "$hwmode_11n" in
105 default
) hwmode_11n
="$default"
107 config_set
"$device" hwmode_11n
"$hwmode_11n"
111 if [ "${channel:-0}" -gt 0 ]; then
112 if [ "${channel:-0}" -gt 14 ]; then
122 config_set
"$device" hwmode
"$hwmode"
126 for device
in ${2:-$DEVICES}; do (
127 config_get disabled
"$device" disabled
128 [ "$disabled" = "1" ] && {
129 echo "'$device' is disabled"
132 config_get iftype
"$device" type
133 if eval "type ${1}_$iftype" 2>/dev
/null
>/dev
/null
; then
134 eval "scan_$iftype '$device'"
135 eval "${1}_$iftype '$device'" ||
echo "$device($iftype): ${1} failed"
136 elif [ ! -f /lib
/netifd
/wireless
/$iftype.sh
]; then
137 echo "$device($iftype): Interface type not supported"
144 [ enable = "$1" ] && {
145 _wifi_updown disable
"$2"
146 ubus_wifi_cmd
"$cmd" "$2"
147 ubus call network reload
151 [ reconf
= "$1" ] && {
152 ubus call network reload
156 ubus_wifi_cmd
"$cmd" "$2"
160 wifi_reload_legacy
() {
161 _wifi_updown
"disable" "$1"
163 _wifi_updown
"enable" "$1"
167 ubus call network reload
171 wifi_detect_notice
() {
172 >&2 echo "WARNING: Wifi detect is deprecated. Use wifi config instead"
173 >&2 echo "For more information, see commit 5f8f8a366136a07df661e31decce2458357c167a"
178 [ ! -f /etc
/config
/wireless
] && touch /etc
/config
/wireless
180 for driver
in $DRIVERS; do (
181 if eval "type detect_$driver" 2>/dev
/null
>/dev
/null
; then
182 eval "detect_$driver" ||
echo "$driver: Detect failed" >&2
184 echo "$driver: Hardware detection not supported" >&2
194 [ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev
/null
195 [ -z "$config" ] ||
{
198 for config
in $config; do
199 setup_interface
"$iface" "$config" "" "$vifmac"
207 uci_set_state wireless
"$cfg" up
1
208 uci_set_state wireless
"$cfg" ifname
"$ifname"
213 local vifs vif vifstr
215 [ -f "/var/run/wifi-${cfg}.pid" ] &&
216 kill "$(cat "/var
/run
/wifi-
${cfg}.pid
")" 2>/dev
/null
217 uci_revert_state wireless
"$cfg"
218 config_get vifs
"$cfg" vifs
220 uci_revert_state wireless
"$vif"
234 append DEVICES
"$section"
235 config_set
"$section" vifs
""
236 config_set
"$section" ht_capab
""
241 config_get TYPE
"$CONFIG_SECTION" TYPE
244 config_get device
"$CONFIG_SECTION" device
245 config_get vifs
"$device" vifs
246 append vifs
"$CONFIG_SECTION"
247 config_set
"$device" vifs
"$vifs"
251 config_load
"${cfgfile:-wireless}"
260 down
) wifi_updown
"disable" "$2";;
261 detect
) wifi_detect_notice
;;
262 config
) wifi_config
;;
263 status
) ubus_wifi_cmd
"status" "$2";;
264 isup
) wifi_isup
"$2"; exit $?
;;
265 reload
) wifi_reload
"$2";;
266 reload_legacy
) wifi_reload_legacy
"$2";;
268 reconf
) wifi_updown
"reconf" "$2";;
269 ''|up
) wifi_updown
"enable" "$2";;