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
() {
114 json_add_int
"command" "$command"
115 json_add_string
"device" "$__netifd_device"
116 [ -n "$interface" ] && json_add_string
"interface" "$interface"
117 json_add_object
"data"
124 ubus
$options call network.wireless notify
"$(json_dump)"
127 _wdev_add_variables
() {
128 while [ -n "$1" ]; do
132 [[ "$var" = "$val" ]] && continue
134 json_add_string
"$var" "$val"
138 _wireless_add_vif
() {
139 local name
="$1"; shift
140 local ifname
="$1"; shift
142 _wdev_notify_init
$CMD_SET_DATA "$name"
143 json_add_string
"ifname" "$ifname"
144 _wdev_add_variables
"$@"
149 _wdev_notify_init
$CMD_UP
153 _wireless_set_data
() {
154 _wdev_notify_init
$CMD_SET_DATA
155 _wdev_add_variables
"$@"
159 _wireless_add_process
() {
160 _wdev_notify_init
$CMD_PROCESS_ADD
161 json_add_int pid
"$1"
162 json_add_string exe
"$2"
163 [ -n "$3" ] && json_add_boolean required
1
167 _wireless_process_kill_all
() {
168 _wdev_notify_init
$CMD_PROCESS_KILL_ALL
169 [ -n "$1" ] && json_add_int signal
"$1"
173 _wireless_set_retry
() {
174 _wdev_notify_init
$CMD_SET_RETRY
175 json_add_int retry
"$1"
183 wireless_add_process \
184 wireless_process_kill_all \
187 wireless_vif_parse_encryption
() {
188 json_get_vars encryption
189 set_default encryption none
195 case "$encryption" in
196 *tkip
+aes|
*tkip
+ccmp|
*aes
+tkip|
*ccmp
+tkip
) wpa_pairwise
="CCMP TKIP";;
197 *aes|
*ccmp
) wpa_pairwise
="CCMP";;
198 *tkip
) wpa_pairwise
="TKIP";;
201 # 802.11n requires CCMP for WPA
202 [ "$enable_ht:$wpa_pairwise" = "1:TKIP" ] && wpa_pairwise
="CCMP TKIP"
205 # psk-mixed/tkip => WPA1+2 PSK, TKIP
206 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
207 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
209 case "$encryption" in
225 case "$encryption" in
234 case "$encryption" in
249 json_get_var _w_type mode
252 json_get_var network_bridge bridge
255 for_each_interface
() {
256 local _w_types
="$1"; shift
257 local _w_ifaces _w_iface
261 json_get_keys _w_ifaces interfaces
262 json_select interfaces
263 for _w_iface
in $_w_ifaces; do
264 json_select
"$_w_iface"
265 if [ -n "$_w_types" ]; then
269 _w_types
=" $_w_types "
270 [[ "${_w_types%$_w_type*}" = "$_w_types" ]] && {
281 _wdev_common_device_config
() {
282 config_add_string channel hwmode
285 _wdev_common_iface_config
() {
286 config_add_string mode ssid encryption key
289 init_wireless_driver
() {
297 json_add_string name
"$1"
299 json_add_array device
300 _wdev_common_device_config
301 eval "drv_$1_init_device_config"
305 _wdev_common_iface_config
306 eval "drv_$1_init_iface_config"
313 interface
="$1"; shift
315 export __netifd_device
="$interface"
318 [[ "$name" == "$1" ]] ||
return 0
319 _wdev_handler
"$1" "$cmd"