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 band hwmode
47 hwmode
="${hwmode##11}"
56 wireless_setup_failed
"INVALID_CHANNEL"
63 if [ "$channel" -gt 14 ]; then
92 eval "drv_$1_$2 \"$interface\""
98 json_set_namespace wdev old_cb
100 json_set_namespace
$old_cb
104 while [ -n "$1" ]; do
105 eval "$1() { _wdev_msg_call _$1 \"\$@\"; }"
110 _wdev_notify_init
() {
116 json_add_int
"command" "$command"
117 json_add_string
"device" "$__netifd_device"
118 [ -n "$name" -a -n "$value" ] && json_add_string
"$name" "$value"
119 json_add_object
"data"
126 ubus
$options call network.wireless notify
"$(json_dump)"
129 _wdev_add_variables
() {
130 while [ -n "$1" ]; do
134 [[ "$var" = "$val" ]] && continue
136 json_add_string
"$var" "$val"
140 _wireless_add_vif
() {
141 local name
="$1"; shift
142 local ifname
="$1"; shift
144 _wdev_notify_init
$CMD_SET_DATA "interface" "$name"
145 json_add_string
"ifname" "$ifname"
146 _wdev_add_variables
"$@"
150 _wireless_add_vlan
() {
151 local name
="$1"; shift
152 local ifname
="$1"; shift
154 _wdev_notify_init
$CMD_SET_DATA "vlan" "$name"
155 json_add_string
"ifname" "$ifname"
156 _wdev_add_variables
"$@"
161 _wdev_notify_init
$CMD_UP
165 _wireless_set_data
() {
166 _wdev_notify_init
$CMD_SET_DATA
167 _wdev_add_variables
"$@"
171 _wireless_add_process
() {
172 _wdev_notify_init
$CMD_PROCESS_ADD
174 [ -L "$exe" ] && exe
="$(readlink -f "$exe")"
175 json_add_int pid
"$1"
176 json_add_string exe
"$exe"
177 [ -n "$3" ] && json_add_boolean required
1
178 [ -n "$4" ] && json_add_boolean keep
1
179 exe2
="$(readlink -f /proc/$1/exe)"
180 [ "$exe" != "$exe2" ] && echo "WARNING (wireless_add_process): executable path $exe does not match process $1 path ($exe2)"
184 _wireless_process_kill_all
() {
185 _wdev_notify_init
$CMD_PROCESS_KILL_ALL
186 [ -n "$1" ] && json_add_int signal
"$1"
190 _wireless_set_retry
() {
191 _wdev_notify_init
$CMD_SET_RETRY
192 json_add_int retry
"$1"
201 wireless_add_process \
202 wireless_process_kill_all \
205 wireless_vif_parse_encryption
() {
206 json_get_vars encryption
207 set_default encryption none
213 if [ "$hwmode" = "ad" ]; then
219 # WPA3 enterprise requires the GCMP-256 cipher (technically also CCMP and GCMP are possible
220 # but many clients/devices do not support that)
221 case "$encryption" in
222 wpa3-mixed
*) wpa_cipher
="${wpa_cipher} GCMP-256";;
223 wpa3
*) wpa_cipher
="GCMP-256";;
226 case "$encryption" in
227 *tkip
+aes|
*tkip
+ccmp|
*aes
+tkip|
*ccmp
+tkip
) wpa_cipher
="CCMP TKIP";;
228 *ccmp256
) wpa_cipher
="CCMP-256";;
229 *aes|
*ccmp
) wpa_cipher
="CCMP";;
230 *tkip
) wpa_cipher
="TKIP";;
231 *gcmp256
) wpa_cipher
="GCMP-256";;
232 *gcmp
) wpa_cipher
="GCMP";;
235 # 802.11n requires CCMP for WPA
236 [ "$enable_ht:$wpa_cipher" = "1:TKIP" ] && wpa_cipher
="CCMP TKIP"
239 # psk-mixed/tkip => WPA1+2 PSK, TKIP
240 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
241 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
243 case "$encryption" in
244 wpa2
*|wpa3
*|
*psk2
*|psk3
*|sae
*|owe
*)
247 wpa
*mixed
*|
*psk
*mixed
*)
258 wpa_pairwise
="$wpa_cipher"
260 case "$encryption" in
270 psk3-mixed
*|sae-mixed
*)
284 case "$encryption" in
296 case "$encryption" in
303 _wireless_set_brsnoop_isolation
() {
304 local multicast_to_unicast
="$1"
307 json_get_vars isolate proxy_arp
309 [ ${isolate:-0} -gt 0 -o -z "$network_bridge" ] && return
310 [ ${multicast_to_unicast:-1} -gt 0 -o ${proxy_arp:-0} -gt 0 ] && json_add_boolean isolate
1
313 for_each_interface
() {
314 local _w_types
="$1"; shift
315 local _w_ifaces _w_iface
319 local multicast_to_unicast
321 json_get_keys _w_ifaces interfaces
322 json_select interfaces
323 for _w_iface
in $_w_ifaces; do
324 json_select
"$_w_iface"
325 if [ -n "$_w_types" ]; then
326 json_get_var network_bridge bridge
327 json_get_var network_ifname bridge-ifname
328 json_get_var multicast_to_unicast multicast_to_unicast
330 _wireless_set_brsnoop_isolation
"$multicast_to_unicast"
331 json_get_var _w_type mode
333 _w_types
=" $_w_types "
334 [[ "${_w_types%$_w_type*}" = "$_w_types" ]] && {
346 local _w_vlans _w_vlan
348 json_get_keys _w_vlans vlans
350 for _w_vlan
in $_w_vlans; do
351 json_select
"$_w_vlan"
363 json_get_keys _w_stas stas
365 for _w_sta
in $_w_stas; do
366 json_select
"$_w_sta"
375 _wdev_common_device_config
() {
376 config_add_string channel hwmode band htmode noscan
379 _wdev_common_iface_config
() {
380 config_add_string mode ssid encryption
'key:wpakey'
383 _wdev_common_vlan_config
() {
384 config_add_string name vid iface
387 _wdev_common_station_config
() {
388 config_add_string mac key vid iface
391 init_wireless_driver
() {
398 eval "drv_$1_cleanup"
401 json_add_string name
"$1"
403 json_add_array device
404 _wdev_common_device_config
405 eval "drv_$1_init_device_config"
409 _wdev_common_iface_config
410 eval "drv_$1_init_iface_config"
414 _wdev_common_vlan_config
415 eval "drv_$1_init_vlan_config"
418 json_add_array station
419 _wdev_common_station_config
420 eval "drv_$1_init_station_config"
427 interface
="$1"; shift
429 export __netifd_device
="$interface"
432 [[ "$name" == "$1" ]] ||
return 0
433 _wdev_handler
"$1" "$cmd"