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() {
20 wireless_setup_failed() {
30 echo -n "$key" | grep -qE "[^a-fA-F0-9]" && hex=0
31 [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
32 [ "${#key}" -eq 26 -a $hex -eq 1 ] || {
33 [ "${key:0:2}" = "s:" ] && key="${key#s:}"
34 key="$(echo -n "$key" | hexdump -ve '1/1 "%02x" ""')"
39 _wdev_prepare_channel() {
40 json_get_vars channel hwmode
45 hwmode="${hwmode##11}"
46 hwmode_n="${hwmode##n}"
55 wireless_setup_failed "INVALID_CHANNEL"
59 [[ "$hwmode_n" = "$hwmode" ]] && {
73 if [ "$channel" -gt 14 ]; then
89 eval "drv_$1_$2 \"$interface\""
95 json_set_namespace wdev old_cb
97 json_set_namespace $old_cb
101 while [ -n "$1" ]; do
102 eval "$1() { _wdev_msg_call _$1 \"\$@\"; }"
107 _wdev_notify_init() {
112 json_add_int "command" "$command"
113 json_add_string "device" "$__netifd_device"
114 [ -n "$interface" ] && json_add_string "interface" "$interface"
115 json_add_object "data"
122 ubus $options call network.wireless notify "$(json_dump)"
125 _wdev_add_variables() {
126 while [ -n "$1" ]; do
130 [[ "$var" = "$val" ]] && continue
132 json_add_string "$var" "$val"
136 _wireless_add_vif() {
137 local name="$1"; shift
138 local ifname="$1"; shift
140 _wdev_notify_init $CMD_SET_DATA "$name"
141 json_add_string "ifname" "$ifname"
142 _wdev_add_variables "$@"
147 _wdev_notify_init $CMD_UP
151 _wireless_set_data() {
152 _wdev_notify_init $CMD_SET_DATA
153 _wdev_add_variables "$@"
157 _wireless_add_process() {
158 _wdev_notify_init $CMD_PROCESS_ADD
159 json_add_int pid "$1"
160 json_add_string exe "$2"
161 [ -n "$3" ] && json_add_boolean required 1
165 _wireless_process_kill_all() {
166 _wdev_notify_init $CMD_PROCESS_KILL_ALL
167 [ -n "$1" ] && json_add_int signal "$1"
171 _wireless_set_retry() {
172 _wdev_notify_init $CMD_SET_RETRY
173 json_add_int retry "$1"
181 wireless_add_process \
182 wireless_process_kill_all \
185 wireless_vif_parse_encryption() {
186 json_get_vars encryption
187 set_default encryption none
193 case "$encryption" in
194 *tkip+aes|*tkip+ccmp|*aes+tkip|*ccmp+tkip) wpa_pairwise="CCMP TKIP";;
195 *aes|*ccmp) wpa_pairwise="CCMP";;
196 *tkip) wpa_pairwise="TKIP";;
199 # 802.11n requires CCMP for WPA
200 [ "$enable_ht:$wpa_pairwise" = "1:TKIP" ] && wpa_pairwise="CCMP TKIP"
203 # psk-mixed/tkip => WPA1+2 PSK, TKIP
204 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
205 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
207 case "$encryption" in
223 case "$encryption" in
232 case "$encryption" in
247 json_get_var _w_type mode
250 json_get_var network_bridge bridge
253 for_each_interface() {
254 local _w_types="$1"; shift
255 local _w_ifaces _w_iface
259 json_get_keys _w_ifaces interfaces
260 json_select interfaces
261 for _w_iface in $_w_ifaces; do
262 json_select "$_w_iface"
263 if [ -n "$_w_types" ]; then
267 _w_types=" $_w_types "
268 [[ "${_w_types%$_w_type*}" = "$_w_types" ]] && {
279 _wdev_common_device_config() {
280 config_add_string channel hwmode
283 _wdev_common_iface_config() {
284 config_add_string mode ssid encryption key
287 init_wireless_driver() {
295 json_add_string name "$1"
297 json_add_array device
298 _wdev_common_device_config
299 eval "drv_$1_init_device_config"
303 _wdev_common_iface_config
304 eval "drv_$1_init_iface_config"
311 interface="$1"; shift
313 export __netifd_device="$interface"
316 [[ "$name" == "$1" ]] || return 0
317 _wdev_handler "$1" "$cmd"