mac80211: add iw command wrapper with error logging
[openwrt/openwrt.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
index dbe4aac7d78832fdd8005b539be6bb1af0eb915d..e7d442f8ef1a0efb8087be90a740b4cd6348337f 100644 (file)
@@ -14,6 +14,10 @@ MP_CONFIG_INT="mesh_retry_timeout mesh_confirm_timeout mesh_holding_timeout mesh
 MP_CONFIG_BOOL="mesh_auto_open_plinks mesh_fwding"
 MP_CONFIG_STRING="mesh_power_mode"
 
+iw() {
+       command iw $@ || logger -t mac80211 "Failed command: iw $@"
+}
+
 drv_mac80211_init_device_config() {
        hostapd_common_add_device_config
 
@@ -610,6 +614,51 @@ mac80211_setup_adhoc() {
                ${keyspec:+keys $keyspec}
 }
 
+mac80211_setup_mesh() {
+       json_get_vars ssid mesh_id mcast_rate
+
+       mcval=
+       [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
+       [ -n "$mesh_id" ] && ssid="$mesh_id"
+
+       case "$htmode" in
+               VHT20|HT20) mesh_htmode=HT20;;
+               HT40*|VHT40)
+                       case "$hwmode" in
+                               a)
+                                       case "$(( ($channel / 4) % 2 ))" in
+                                               1) mesh_htmode="HT40+" ;;
+                                               0) mesh_htmode="HT40-";;
+                                       esac
+                               ;;
+                               *)
+                                       case "$htmode" in
+                                               HT40+) mesh_htmode="HT40+";;
+                                               HT40-) mesh_htmode="HT40-";;
+                                               *)
+                                                       if [ "$channel" -lt 7 ]; then
+                                                               mesh_htmode="HT40+"
+                                                       else
+                                                               mesh_htmode="HT40-"
+                                                       fi
+                                               ;;
+                                       esac
+                               ;;
+                       esac
+               ;;
+               VHT80)
+                       mesh_htmode="80Mhz"
+               ;;
+               VHT160)
+                       mesh_htmode="160Mhz"
+               ;;
+               *) mesh_htmode="NOHT" ;;
+       esac
+       iw dev "$ifname" mesh join "$ssid" freq $freq $mesh_htmode \
+               ${mcval:+mcast-rate $mcval} \
+               beacon-interval $beacon_int
+}
+
 mac80211_setup_vif() {
        local name="$1"
        local failed
@@ -633,57 +682,13 @@ mac80211_setup_vif() {
 
        case "$mode" in
                mesh)
-                       json_get_vars key
+                       wireless_vif_parse_encryption
+                       freq="$(get_freq "$phy" "$channel")"
                        if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ] || chan_is_dfs "$phy" "$channel"; then
-                               wireless_vif_parse_encryption
-                               freq="$(get_freq "$phy" "$channel")"
                                mac80211_setup_supplicant || failed=1
                        else
-                               json_get_vars mesh_id mcast_rate
-
-                               mcval=
-                               [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
-
-                               case "$htmode" in
-                                       VHT20|HT20) mesh_htmode=HT20;;
-                                       HT40*|VHT40)
-                                               case "$hwmode" in
-                                                       a)
-                                                               case "$(( ($channel / 4) % 2 ))" in
-                                                                       1) mesh_htmode="HT40+" ;;
-                                                                       0) mesh_htmode="HT40-";;
-                                                               esac
-                                                       ;;
-                                                       *)
-                                                               case "$htmode" in
-                                                                       HT40+) mesh_htmode="HT40+";;
-                                                                       HT40-) mesh_htmode="HT40-";;
-                                                                       *)
-                                                                               if [ "$channel" -lt 7 ]; then
-                                                                                       mesh_htmode="HT40+"
-                                                                               else
-                                                                                       mesh_htmode="HT40-"
-                                                                               fi
-                                                                       ;;
-                                                               esac
-                                                       ;;
-                                               esac
-                                       ;;
-                                       VHT80)
-                                               mesh_htmode="80Mhz"
-                                       ;;
-                                       VHT160)
-                                               mesh_htmode="160Mhz"
-                                       ;;
-                                       *) mesh_htmode="NOHT" ;;
-                               esac
-
-                               freq="$(get_freq "$phy" "$channel")"
-                               iw dev "$ifname" mesh join "$mesh_id" freq $freq $mesh_htmode \
-                                       ${mcval:+mcast-rate $mcval} \
-                                       beacon-interval $beacon_int
+                               mac80211_setup_mesh
                        fi
-
                        for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
                                json_get_var mp_val "$var"
                                [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val"