2 # Copyright (C) 2006 OpenWrt.org
5 .
/usr
/share
/libubox
/jshn.sh
9 Usage: $0 [config|down|reload|status]
10 enables (default), disables or configures devices not yet configured.
20 [ -n "$2" ] && json_add_string device
"$2"
21 ubus call network.wireless
"$1" "$(json_dump)"
29 config_get cfg
"$vif" network
35 config_get ifname
"$vif" ifname
37 cfg
="$(find_config "$ifname")"
39 [ -z "$cfg" ] && return 0
46 [ -z "$cfg" ] && return 0
52 config_get iftype
"$cfg" type
53 [ "$iftype" = bridge
] && config_get
"$cfg" ifname
54 prepare_interface_bridge
"$cfg"
63 echo -n "$key" |
grep -qE "[^a-fA-F0-9]" && hex
=0
64 [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
65 [ "${#key}" -eq 26 -a $hex -eq 1 ] ||
{
66 [ "${key:0:2}" = "s:" ] && key
="${key#s:}"
67 key
="$(echo -n "$key" | hexdump -ve '1/1 "%02x
" ""')"
75 local hwmode hwmode_11n
77 config_get channel
"$device" channel
78 config_get hwmode
"$device" hwmode
85 hwmode_11n
="${hwmode##11n}"
88 default
) hwmode_11n
="$default"
90 config_set
"$device" hwmode_11n
"$hwmode_11n"
94 if [ "${channel:-0}" -gt 0 ]; then
95 if [ "${channel:-0}" -gt 14 ]; then
105 config_set
"$device" hwmode
"$hwmode"
109 for device
in ${2:-$DEVICES}; do (
110 config_get disabled
"$device" disabled
111 [ "$disabled" = "1" ] && {
112 echo "'$device' is disabled"
115 config_get iftype
"$device" type
116 if eval "type ${1}_$iftype" 2>/dev
/null
>/dev
/null
; then
117 eval "scan_$iftype '$device'"
118 eval "${1}_$iftype '$device'" ||
echo "$device($iftype): ${1} failed"
119 elif [ ! -f /lib
/netifd
/wireless
/$iftype.sh
]; then
120 echo "$device($iftype): Interface type not supported"
127 [ enable = "$1" ] && {
128 _wifi_updown disable
"$2"
129 ubus_wifi_cmd
"$cmd" "$2"
133 ubus_wifi_cmd
"$cmd" "$2"
137 wifi_reload_legacy
() {
138 _wifi_updown
"disable" "$1"
140 _wifi_updown
"enable" "$1"
144 ubus call network reload
149 [ ! -f /etc
/config
/wireless
] && touch /etc
/config
/wireless
151 for driver
in $DRIVERS; do (
152 if eval "type detect_$driver" 2>/dev
/null
>/dev
/null
; then
153 eval "detect_$driver" ||
echo "$driver: Detect failed" >&2
155 echo "$driver: Hardware detection not supported" >&2
165 [ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev
/null
166 [ -z "$config" ] ||
{
169 for config
in $config; do
170 setup_interface
"$iface" "$config" "" "$vifmac"
178 uci_set_state wireless
"$cfg" up
1
179 uci_set_state wireless
"$cfg" ifname
"$ifname"
184 local vifs vif vifstr
186 [ -f "/var/run/wifi-${cfg}.pid" ] &&
187 kill "$(cat "/var
/run
/wifi-
${cfg}.pid
")" 2>/dev
/null
188 uci_revert_state wireless
"$cfg"
189 config_get vifs
"$cfg" vifs
191 uci_revert_state wireless
"$vif"
205 append DEVICES
"$section"
206 config_set
"$section" vifs
""
207 config_set
"$section" ht_capab
""
212 config_get TYPE
"$CONFIG_SECTION" TYPE
215 config_get device
"$CONFIG_SECTION" device
216 config_get vifs
"$device" vifs
217 append vifs
"$CONFIG_SECTION"
218 config_set
"$device" vifs
"$vifs"
222 config_load
"${cfgfile:-wireless}"
231 down
) wifi_updown
"disable" "$2";;
233 config
) wifi_config
;;
234 status
) ubus_wifi_cmd
"status" "$2";;
235 reload
) wifi_reload
"$2";;
236 reload_legacy
) wifi_reload_legacy
"$2";;
238 *) ubus call network reload
; wifi_updown
"enable" "$2";;