1 NETIFD_MAIN_DIR
="${NETIFD_MAIN_DIR:-/lib/netifd}"
3 .
/usr
/share
/libubox
/jshn.sh
4 .
$NETIFD_MAIN_DIR/utils.sh
16 wireless_setup_vif_failed
() {
18 echo "Interface $_w_iface setup failed: $error"
21 wireless_setup_failed
() {
24 echo "Device setup failed: $error"
32 echo -n "$key" |
grep -qE "[^a-fA-F0-9]" && hex
=0
33 [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
34 [ "${#key}" -eq 26 -a $hex -eq 1 ] ||
{
35 [ "${key:0:2}" = "s:" ] && key
="${key#s:}"
36 key
="$(echo -n "$key" | hexdump -ve '1/1 "%02x
" ""')"
41 _wdev_prepare_channel
() {
42 json_get_vars channel hwmode
47 hwmode
="${hwmode##11}"
48 hwmode_n
="${hwmode##n}"
57 wireless_setup_failed
"INVALID_CHANNEL"
61 [[ "$hwmode_n" = "$hwmode" ]] ||
{
75 if [ "$channel" -gt 14 ]; then
91 eval "drv_$1_$2 \"$interface\""
97 json_set_namespace wdev old_cb
99 json_set_namespace
$old_cb
103 while [ -n "$1" ]; do
104 eval "$1() { _wdev_msg_call _$1 \"\$@\"; }"
109 _wdev_notify_init
() {
115 json_add_int
"command" "$command"
116 json_add_string
"device" "$__netifd_device"
117 [ -n "$name" -a -n "$value" ] && json_add_string
"$name" "$value"
118 json_add_object
"data"
125 ubus
$options call network.wireless notify
"$(json_dump)"
128 _wdev_add_variables
() {
129 while [ -n "$1" ]; do
133 [[ "$var" = "$val" ]] && continue
135 json_add_string
"$var" "$val"
139 _wireless_add_vif
() {
140 local name
="$1"; shift
141 local ifname
="$1"; shift
143 _wdev_notify_init
$CMD_SET_DATA "interface" "$name"
144 json_add_string
"ifname" "$ifname"
145 _wdev_add_variables
"$@"
149 _wireless_add_vlan
() {
150 local name
="$1"; shift
151 local ifname
="$1"; shift
153 _wdev_notify_init
$CMD_SET_DATA "vlan" "$name"
154 json_add_string
"ifname" "$ifname"
155 _wdev_add_variables
"$@"
160 _wdev_notify_init
$CMD_UP
164 _wireless_set_data
() {
165 _wdev_notify_init
$CMD_SET_DATA
166 _wdev_add_variables
"$@"
170 _wireless_add_process
() {
171 _wdev_notify_init
$CMD_PROCESS_ADD
173 [ -L "$exe" ] && exe
="$(readlink -f "$exe")"
174 json_add_int pid
"$1"
175 json_add_string exe
"$exe"
176 [ -n "$3" ] && json_add_boolean required
1
177 [ -n "$4" ] && json_add_boolean keep
1
178 exe2
="$(readlink -f /proc/$1/exe)"
179 [ "$exe" != "$exe2" ] && echo "WARNING (wireless_add_process): executable path $exe does not match process $1 path ($exe2)"
183 _wireless_process_kill_all
() {
184 _wdev_notify_init
$CMD_PROCESS_KILL_ALL
185 [ -n "$1" ] && json_add_int signal
"$1"
189 _wireless_set_retry
() {
190 _wdev_notify_init
$CMD_SET_RETRY
191 json_add_int retry
"$1"
200 wireless_add_process \
201 wireless_process_kill_all \
204 wireless_vif_parse_encryption
() {
205 json_get_vars encryption
206 set_default encryption none
212 case "$encryption" in
213 *tkip
+aes|
*tkip
+ccmp|
*aes
+tkip|
*ccmp
+tkip
) wpa_cipher
="CCMP TKIP";;
214 *aes|
*ccmp
) wpa_cipher
="CCMP";;
215 *tkip
) wpa_cipher
="TKIP";;
216 *gcmp
) wpa_cipher
="GCMP";;
219 # 802.11n requires CCMP for WPA
220 [ "$enable_ht:$wpa_cipher" = "1:TKIP" ] && wpa_cipher
="CCMP TKIP"
223 # psk-mixed/tkip => WPA1+2 PSK, TKIP
224 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
225 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
227 case "$encryption" in
228 wpa2
*|wpa3
*|
*psk2
*|psk3
*|sae
*|owe
*)
231 wpa
*mixed
*|
*psk
*mixed
*)
242 wpa_pairwise
="$wpa_cipher"
244 case "$encryption" in
254 psk3-mixed
*|sae-mixed
*)
268 case "$encryption" in
280 case "$encryption" in
287 _wireless_set_brsnoop_isolation
() {
288 local multicast_to_unicast
="$1"
291 json_get_var isolate isolate
293 [ ${isolate:-0} -gt 0 -o -z "$network_bridge" ] && return
294 [ ${multicast_to_unicast:-1} -gt 0 ] && json_add_boolean isolate
1
297 for_each_interface
() {
298 local _w_types
="$1"; shift
299 local _w_ifaces _w_iface
303 local multicast_to_unicast
305 json_get_keys _w_ifaces interfaces
306 json_select interfaces
307 for _w_iface
in $_w_ifaces; do
308 json_select
"$_w_iface"
309 if [ -n "$_w_types" ]; then
310 json_get_var network_bridge bridge
311 json_get_var multicast_to_unicast multicast_to_unicast
313 _wireless_set_brsnoop_isolation
"$multicast_to_unicast"
314 json_get_var _w_type mode
316 _w_types
=" $_w_types "
317 [[ "${_w_types%$_w_type*}" = "$_w_types" ]] && {
329 local _w_vlans _w_vlan
331 json_get_keys _w_vlans vlans
333 for _w_vlan
in $_w_vlans; do
334 json_select
"$_w_vlan"
346 json_get_keys _w_stas stas
348 for _w_sta
in $_w_stas; do
349 json_select
"$_w_sta"
358 _wdev_common_device_config
() {
359 config_add_string channel hwmode htmode noscan
362 _wdev_common_iface_config
() {
363 config_add_string mode ssid encryption
'key:wpakey'
366 _wdev_common_vlan_config
() {
367 config_add_string name vid iface
370 _wdev_common_station_config
() {
371 config_add_string mac key vid iface
374 init_wireless_driver
() {
381 eval "drv_$1_cleanup"
384 json_add_string name
"$1"
386 json_add_array device
387 _wdev_common_device_config
388 eval "drv_$1_init_device_config"
392 _wdev_common_iface_config
393 eval "drv_$1_init_iface_config"
397 _wdev_common_vlan_config
398 eval "drv_$1_init_vlan_config"
401 json_add_array station
402 _wdev_common_station_config
403 eval "drv_$1_init_station_config"
410 interface
="$1"; shift
412 export __netifd_device
="$interface"
415 [[ "$name" == "$1" ]] ||
return 0
416 _wdev_handler
"$1" "$cmd"