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
162 [ -L "$exe" ] && exe="$(readlink -f "$exe")"
163 json_add_int pid "$1"
164 json_add_string exe "$exe"
165 [ -n "$3" ] && json_add_boolean required 1
166 exe2="$(readlink -f /proc/$pid/exe)"
167 [ "$exe" = "$exe2" ] && echo "WARNING (wireless_add_process): executable path $exe does not match process $1 path ($exe2)"
171 _wireless_process_kill_all() {
172 _wdev_notify_init $CMD_PROCESS_KILL_ALL
173 [ -n "$1" ] && json_add_int signal "$1"
177 _wireless_set_retry() {
178 _wdev_notify_init $CMD_SET_RETRY
179 json_add_int retry "$1"
187 wireless_add_process \
188 wireless_process_kill_all \
191 wireless_vif_parse_encryption() {
192 json_get_vars encryption
193 set_default encryption none
199 case "$encryption" in
200 *tkip+aes|*tkip+ccmp|*aes+tkip|*ccmp+tkip) wpa_pairwise="CCMP TKIP";;
201 *aes|*ccmp) wpa_pairwise="CCMP";;
202 *tkip) wpa_pairwise="TKIP";;
205 # 802.11n requires CCMP for WPA
206 [ "$enable_ht:$wpa_pairwise" = "1:TKIP" ] && wpa_pairwise="CCMP TKIP"
209 # psk-mixed/tkip => WPA1+2 PSK, TKIP
210 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
211 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
213 case "$encryption" in
229 case "$encryption" in
238 case "$encryption" in
253 json_get_var _w_type mode
256 json_get_var network_bridge bridge
259 for_each_interface() {
260 local _w_types="$1"; shift
261 local _w_ifaces _w_iface
265 json_get_keys _w_ifaces interfaces
266 json_select interfaces
267 for _w_iface in $_w_ifaces; do
268 json_select "$_w_iface"
269 if [ -n "$_w_types" ]; then
273 _w_types=" $_w_types "
274 [[ "${_w_types%$_w_type*}" = "$_w_types" ]] && {
285 _wdev_common_device_config() {
286 config_add_string channel hwmode htmode
289 _wdev_common_iface_config() {
290 config_add_string mode ssid encryption key
293 init_wireless_driver() {
300 eval "drv_$1_cleanup"
303 json_add_string name "$1"
305 json_add_array device
306 _wdev_common_device_config
307 eval "drv_$1_init_device_config"
311 _wdev_common_iface_config
312 eval "drv_$1_init_iface_config"
319 interface="$1"; shift
321 export __netifd_device="$interface"
324 [[ "$name" == "$1" ]] || return 0
325 _wdev_handler "$1" "$cmd"