aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2014-05-22 13:58:36 -0400
committerJohn W. Linville <linville@tuxdriver.com>2014-05-22 13:58:36 -0400
commit40a10fd740a4d5a9f3da255cf8dae48c6723d1a6 (patch)
treea65eb4adca8e37ed7335345e94e36918593f7f92 /net/mac80211
parent99abe65ff18b6bbac2e55524827b571c3eccfa86 (diff)
parent67af9811539be83dbdc0739215d29af23c870405 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Makefile3
-rw-r--r--net/mac80211/cfg.c538
-rw-r--r--net/mac80211/chan.c4
-rw-r--r--net/mac80211/driver-ops.h121
-rw-r--r--net/mac80211/ibss.c2
-rw-r--r--net/mac80211/ieee80211_i.h17
-rw-r--r--net/mac80211/iface.c7
-rw-r--r--net/mac80211/key.c7
-rw-r--r--net/mac80211/main.c2
-rw-r--r--net/mac80211/mesh.c2
-rw-r--r--net/mac80211/mesh_pathtbl.c6
-rw-r--r--net/mac80211/mesh_sync.c2
-rw-r--r--net/mac80211/mlme.c46
-rw-r--r--net/mac80211/rc80211_minstrel.c12
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c22
-rw-r--r--net/mac80211/scan.c15
-rw-r--r--net/mac80211/tdls.c325
-rw-r--r--net/mac80211/trace.h32
-rw-r--r--net/mac80211/tx.c189
-rw-r--r--net/mac80211/util.c46
20 files changed, 913 insertions, 485 deletions
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 9d7d840aac6d..1e46ffa69167 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -25,7 +25,8 @@ mac80211-y := \
25 wme.o \ 25 wme.o \
26 event.o \ 26 event.o \
27 chan.o \ 27 chan.o \
28 trace.o mlme.o 28 trace.o mlme.o \
29 tdls.o
29 30
30mac80211-$(CONFIG_MAC80211_LEDS) += led.o 31mac80211-$(CONFIG_MAC80211_LEDS) += led.o
31mac80211-$(CONFIG_MAC80211_DEBUGFS) += \ 32mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 7b8d3cf89574..d7513a503be1 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -472,8 +472,10 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
472{ 472{
473 struct ieee80211_sub_if_data *sdata = sta->sdata; 473 struct ieee80211_sub_if_data *sdata = sta->sdata;
474 struct ieee80211_local *local = sdata->local; 474 struct ieee80211_local *local = sdata->local;
475 struct rate_control_ref *ref = local->rate_ctrl;
475 struct timespec uptime; 476 struct timespec uptime;
476 u64 packets = 0; 477 u64 packets = 0;
478 u32 thr = 0;
477 int i, ac; 479 int i, ac;
478 480
479 sinfo->generation = sdata->local->sta_generation; 481 sinfo->generation = sdata->local->sta_generation;
@@ -587,6 +589,17 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
587 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED); 589 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
588 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) 590 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
589 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); 591 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
592
593 /* check if the driver has a SW RC implementation */
594 if (ref && ref->ops->get_expected_throughput)
595 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
596 else
597 thr = drv_get_expected_throughput(local, &sta->sta);
598
599 if (thr != 0) {
600 sinfo->filled |= STATION_INFO_EXPECTED_THROUGHPUT;
601 sinfo->expected_throughput = thr;
602 }
590} 603}
591 604
592static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = { 605static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
@@ -777,7 +790,7 @@ static void ieee80211_get_et_strings(struct wiphy *wiphy,
777} 790}
778 791
779static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, 792static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
780 int idx, u8 *mac, struct station_info *sinfo) 793 int idx, u8 *mac, struct station_info *sinfo)
781{ 794{
782 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 795 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
783 struct ieee80211_local *local = sdata->local; 796 struct ieee80211_local *local = sdata->local;
@@ -807,7 +820,7 @@ static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
807} 820}
808 821
809static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, 822static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
810 u8 *mac, struct station_info *sinfo) 823 const u8 *mac, struct station_info *sinfo)
811{ 824{
812 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 825 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
813 struct ieee80211_local *local = sdata->local; 826 struct ieee80211_local *local = sdata->local;
@@ -1084,6 +1097,31 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1084 return 0; 1097 return 0;
1085} 1098}
1086 1099
1100bool ieee80211_csa_needs_block_tx(struct ieee80211_local *local)
1101{
1102 struct ieee80211_sub_if_data *sdata;
1103
1104 lockdep_assert_held(&local->mtx);
1105
1106 rcu_read_lock();
1107 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1108 if (!ieee80211_sdata_running(sdata))
1109 continue;
1110
1111 if (!sdata->vif.csa_active)
1112 continue;
1113
1114 if (!sdata->csa_block_tx)
1115 continue;
1116
1117 rcu_read_unlock();
1118 return true;
1119 }
1120 rcu_read_unlock();
1121
1122 return false;
1123}
1124
1087static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) 1125static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1088{ 1126{
1089 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1127 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -1101,7 +1139,14 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1101 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata); 1139 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1102 1140
1103 /* abort any running channel switch */ 1141 /* abort any running channel switch */
1142 mutex_lock(&local->mtx);
1104 sdata->vif.csa_active = false; 1143 sdata->vif.csa_active = false;
1144 if (!ieee80211_csa_needs_block_tx(local))
1145 ieee80211_wake_queues_by_reason(&local->hw,
1146 IEEE80211_MAX_QUEUE_MAP,
1147 IEEE80211_QUEUE_STOP_REASON_CSA);
1148 mutex_unlock(&local->mtx);
1149
1105 kfree(sdata->u.ap.next_beacon); 1150 kfree(sdata->u.ap.next_beacon);
1106 sdata->u.ap.next_beacon = NULL; 1151 sdata->u.ap.next_beacon = NULL;
1107 1152
@@ -1425,7 +1470,8 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1425} 1470}
1426 1471
1427static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, 1472static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1428 u8 *mac, struct station_parameters *params) 1473 const u8 *mac,
1474 struct station_parameters *params)
1429{ 1475{
1430 struct ieee80211_local *local = wiphy_priv(wiphy); 1476 struct ieee80211_local *local = wiphy_priv(wiphy);
1431 struct sta_info *sta; 1477 struct sta_info *sta;
@@ -1459,6 +1505,8 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1459 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) { 1505 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1460 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); 1506 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1461 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); 1507 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1508 } else {
1509 sta->sta.tdls = true;
1462 } 1510 }
1463 1511
1464 err = sta_apply_parameters(local, sta, params); 1512 err = sta_apply_parameters(local, sta, params);
@@ -1492,7 +1540,7 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1492} 1540}
1493 1541
1494static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, 1542static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1495 u8 *mac) 1543 const u8 *mac)
1496{ 1544{
1497 struct ieee80211_sub_if_data *sdata; 1545 struct ieee80211_sub_if_data *sdata;
1498 1546
@@ -1506,7 +1554,7 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1506} 1554}
1507 1555
1508static int ieee80211_change_station(struct wiphy *wiphy, 1556static int ieee80211_change_station(struct wiphy *wiphy,
1509 struct net_device *dev, u8 *mac, 1557 struct net_device *dev, const u8 *mac,
1510 struct station_parameters *params) 1558 struct station_parameters *params)
1511{ 1559{
1512 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1560 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -1631,7 +1679,7 @@ out_err:
1631 1679
1632#ifdef CONFIG_MAC80211_MESH 1680#ifdef CONFIG_MAC80211_MESH
1633static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, 1681static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1634 u8 *dst, u8 *next_hop) 1682 const u8 *dst, const u8 *next_hop)
1635{ 1683{
1636 struct ieee80211_sub_if_data *sdata; 1684 struct ieee80211_sub_if_data *sdata;
1637 struct mesh_path *mpath; 1685 struct mesh_path *mpath;
@@ -1659,7 +1707,7 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1659} 1707}
1660 1708
1661static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, 1709static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1662 u8 *dst) 1710 const u8 *dst)
1663{ 1711{
1664 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1712 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1665 1713
@@ -1670,9 +1718,8 @@ static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1670 return 0; 1718 return 0;
1671} 1719}
1672 1720
1673static int ieee80211_change_mpath(struct wiphy *wiphy, 1721static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1674 struct net_device *dev, 1722 const u8 *dst, const u8 *next_hop)
1675 u8 *dst, u8 *next_hop)
1676{ 1723{
1677 struct ieee80211_sub_if_data *sdata; 1724 struct ieee80211_sub_if_data *sdata;
1678 struct mesh_path *mpath; 1725 struct mesh_path *mpath;
@@ -1764,8 +1811,8 @@ static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1764} 1811}
1765 1812
1766static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, 1813static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1767 int idx, u8 *dst, u8 *next_hop, 1814 int idx, u8 *dst, u8 *next_hop,
1768 struct mpath_info *pinfo) 1815 struct mpath_info *pinfo)
1769{ 1816{
1770 struct ieee80211_sub_if_data *sdata; 1817 struct ieee80211_sub_if_data *sdata;
1771 struct mesh_path *mpath; 1818 struct mesh_path *mpath;
@@ -3019,26 +3066,11 @@ void ieee80211_csa_finish(struct ieee80211_vif *vif)
3019} 3066}
3020EXPORT_SYMBOL(ieee80211_csa_finish); 3067EXPORT_SYMBOL(ieee80211_csa_finish);
3021 3068
3022static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) 3069static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3070 u32 *changed)
3023{ 3071{
3024 struct ieee80211_local *local = sdata->local; 3072 int err;
3025 int err, changed = 0;
3026
3027 sdata_assert_lock(sdata);
3028
3029 mutex_lock(&local->mtx);
3030 sdata->radar_required = sdata->csa_radar_required;
3031 err = ieee80211_vif_change_channel(sdata, &changed);
3032 mutex_unlock(&local->mtx);
3033 if (WARN_ON(err < 0))
3034 return;
3035
3036 if (!local->use_chanctx) {
3037 local->_oper_chandef = sdata->csa_chandef;
3038 ieee80211_hw_config(local, 0);
3039 }
3040 3073
3041 sdata->vif.csa_active = false;
3042 switch (sdata->vif.type) { 3074 switch (sdata->vif.type) {
3043 case NL80211_IFTYPE_AP: 3075 case NL80211_IFTYPE_AP:
3044 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon); 3076 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
@@ -3046,35 +3078,74 @@ static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3046 sdata->u.ap.next_beacon = NULL; 3078 sdata->u.ap.next_beacon = NULL;
3047 3079
3048 if (err < 0) 3080 if (err < 0)
3049 return; 3081 return err;
3050 changed |= err; 3082 *changed |= err;
3051 break; 3083 break;
3052 case NL80211_IFTYPE_ADHOC: 3084 case NL80211_IFTYPE_ADHOC:
3053 err = ieee80211_ibss_finish_csa(sdata); 3085 err = ieee80211_ibss_finish_csa(sdata);
3054 if (err < 0) 3086 if (err < 0)
3055 return; 3087 return err;
3056 changed |= err; 3088 *changed |= err;
3057 break; 3089 break;
3058#ifdef CONFIG_MAC80211_MESH 3090#ifdef CONFIG_MAC80211_MESH
3059 case NL80211_IFTYPE_MESH_POINT: 3091 case NL80211_IFTYPE_MESH_POINT:
3060 err = ieee80211_mesh_finish_csa(sdata); 3092 err = ieee80211_mesh_finish_csa(sdata);
3061 if (err < 0) 3093 if (err < 0)
3062 return; 3094 return err;
3063 changed |= err; 3095 *changed |= err;
3064 break; 3096 break;
3065#endif 3097#endif
3066 default: 3098 default:
3067 WARN_ON(1); 3099 WARN_ON(1);
3068 return; 3100 return -EINVAL;
3101 }
3102
3103 return 0;
3104}
3105
3106static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3107{
3108 struct ieee80211_local *local = sdata->local;
3109 u32 changed = 0;
3110 int err;
3111
3112 sdata_assert_lock(sdata);
3113 lockdep_assert_held(&local->mtx);
3114
3115 sdata->radar_required = sdata->csa_radar_required;
3116 err = ieee80211_vif_change_channel(sdata, &changed);
3117 if (err < 0)
3118 return err;
3119
3120 if (!local->use_chanctx) {
3121 local->_oper_chandef = sdata->csa_chandef;
3122 ieee80211_hw_config(local, 0);
3069 } 3123 }
3070 3124
3125 sdata->vif.csa_active = false;
3126
3127 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3128 if (err)
3129 return err;
3130
3071 ieee80211_bss_info_change_notify(sdata, changed); 3131 ieee80211_bss_info_change_notify(sdata, changed);
3132 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3072 3133
3073 ieee80211_wake_queues_by_reason(&sdata->local->hw, 3134 if (!ieee80211_csa_needs_block_tx(local))
3135 ieee80211_wake_queues_by_reason(&local->hw,
3074 IEEE80211_MAX_QUEUE_MAP, 3136 IEEE80211_MAX_QUEUE_MAP,
3075 IEEE80211_QUEUE_STOP_REASON_CSA); 3137 IEEE80211_QUEUE_STOP_REASON_CSA);
3076 3138
3077 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef); 3139 return 0;
3140}
3141
3142static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3143{
3144 if (__ieee80211_csa_finalize(sdata)) {
3145 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3146 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3147 GFP_KERNEL);
3148 }
3078} 3149}
3079 3150
3080void ieee80211_csa_finalize_work(struct work_struct *work) 3151void ieee80211_csa_finalize_work(struct work_struct *work)
@@ -3082,8 +3153,11 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
3082 struct ieee80211_sub_if_data *sdata = 3153 struct ieee80211_sub_if_data *sdata =
3083 container_of(work, struct ieee80211_sub_if_data, 3154 container_of(work, struct ieee80211_sub_if_data,
3084 csa_finalize_work); 3155 csa_finalize_work);
3156 struct ieee80211_local *local = sdata->local;
3085 3157
3086 sdata_lock(sdata); 3158 sdata_lock(sdata);
3159 mutex_lock(&local->mtx);
3160
3087 /* AP might have been stopped while waiting for the lock. */ 3161 /* AP might have been stopped while waiting for the lock. */
3088 if (!sdata->vif.csa_active) 3162 if (!sdata->vif.csa_active)
3089 goto unlock; 3163 goto unlock;
@@ -3094,6 +3168,7 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
3094 ieee80211_csa_finalize(sdata); 3168 ieee80211_csa_finalize(sdata);
3095 3169
3096unlock: 3170unlock:
3171 mutex_unlock(&local->mtx);
3097 sdata_unlock(sdata); 3172 sdata_unlock(sdata);
3098} 3173}
3099 3174
@@ -3129,9 +3204,25 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3129 if (params->count <= 1) 3204 if (params->count <= 1)
3130 break; 3205 break;
3131 3206
3132 sdata->csa_counter_offset_beacon = 3207 if ((params->n_counter_offsets_beacon >
3133 params->counter_offset_beacon; 3208 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3134 sdata->csa_counter_offset_presp = params->counter_offset_presp; 3209 (params->n_counter_offsets_presp >
3210 IEEE80211_MAX_CSA_COUNTERS_NUM))
3211 return -EINVAL;
3212
3213 /* make sure we don't have garbage in other counters */
3214 memset(sdata->csa_counter_offset_beacon, 0,
3215 sizeof(sdata->csa_counter_offset_beacon));
3216 memset(sdata->csa_counter_offset_presp, 0,
3217 sizeof(sdata->csa_counter_offset_presp));
3218
3219 memcpy(sdata->csa_counter_offset_beacon,
3220 params->counter_offsets_beacon,
3221 params->n_counter_offsets_beacon * sizeof(u16));
3222 memcpy(sdata->csa_counter_offset_presp,
3223 params->counter_offsets_presp,
3224 params->n_counter_offsets_presp * sizeof(u16));
3225
3135 err = ieee80211_assign_beacon(sdata, &params->beacon_csa); 3226 err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
3136 if (err < 0) { 3227 if (err < 0) {
3137 kfree(sdata->u.ap.next_beacon); 3228 kfree(sdata->u.ap.next_beacon);
@@ -3220,8 +3311,9 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3220 return 0; 3311 return 0;
3221} 3312}
3222 3313
3223int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 3314static int
3224 struct cfg80211_csa_settings *params) 3315__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3316 struct cfg80211_csa_settings *params)
3225{ 3317{
3226 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3318 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3227 struct ieee80211_local *local = sdata->local; 3319 struct ieee80211_local *local = sdata->local;
@@ -3230,6 +3322,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3230 int err, num_chanctx, changed = 0; 3322 int err, num_chanctx, changed = 0;
3231 3323
3232 sdata_assert_lock(sdata); 3324 sdata_assert_lock(sdata);
3325 lockdep_assert_held(&local->mtx);
3233 3326
3234 if (!list_empty(&local->roc_list) || local->scanning) 3327 if (!list_empty(&local->roc_list) || local->scanning)
3235 return -EBUSY; 3328 return -EBUSY;
@@ -3272,15 +3365,16 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3272 return err; 3365 return err;
3273 3366
3274 sdata->csa_radar_required = params->radar_required; 3367 sdata->csa_radar_required = params->radar_required;
3275
3276 if (params->block_tx)
3277 ieee80211_stop_queues_by_reason(&local->hw,
3278 IEEE80211_MAX_QUEUE_MAP,
3279 IEEE80211_QUEUE_STOP_REASON_CSA);
3280
3281 sdata->csa_chandef = params->chandef; 3368 sdata->csa_chandef = params->chandef;
3369 sdata->csa_block_tx = params->block_tx;
3370 sdata->csa_current_counter = params->count;
3282 sdata->vif.csa_active = true; 3371 sdata->vif.csa_active = true;
3283 3372
3373 if (sdata->csa_block_tx)
3374 ieee80211_stop_queues_by_reason(&local->hw,
3375 IEEE80211_MAX_QUEUE_MAP,
3376 IEEE80211_QUEUE_STOP_REASON_CSA);
3377
3284 if (changed) { 3378 if (changed) {
3285 ieee80211_bss_info_change_notify(sdata, changed); 3379 ieee80211_bss_info_change_notify(sdata, changed);
3286 drv_channel_switch_beacon(sdata, &params->chandef); 3380 drv_channel_switch_beacon(sdata, &params->chandef);
@@ -3292,6 +3386,20 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3292 return 0; 3386 return 0;
3293} 3387}
3294 3388
3389int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3390 struct cfg80211_csa_settings *params)
3391{
3392 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3393 struct ieee80211_local *local = sdata->local;
3394 int err;
3395
3396 mutex_lock(&local->mtx);
3397 err = __ieee80211_channel_switch(wiphy, dev, params);
3398 mutex_unlock(&local->mtx);
3399
3400 return err;
3401}
3402
3295static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, 3403static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3296 struct cfg80211_mgmt_tx_params *params, 3404 struct cfg80211_mgmt_tx_params *params,
3297 u64 *cookie) 3405 u64 *cookie)
@@ -3304,6 +3412,7 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3304 bool need_offchan = false; 3412 bool need_offchan = false;
3305 u32 flags; 3413 u32 flags;
3306 int ret; 3414 int ret;
3415 u8 *data;
3307 3416
3308 if (params->dont_wait_for_ack) 3417 if (params->dont_wait_for_ack)
3309 flags = IEEE80211_TX_CTL_NO_ACK; 3418 flags = IEEE80211_TX_CTL_NO_ACK;
@@ -3397,7 +3506,20 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
3397 } 3506 }
3398 skb_reserve(skb, local->hw.extra_tx_headroom); 3507 skb_reserve(skb, local->hw.extra_tx_headroom);
3399 3508
3400 memcpy(skb_put(skb, params->len), params->buf, params->len); 3509 data = skb_put(skb, params->len);
3510 memcpy(data, params->buf, params->len);
3511
3512 /* Update CSA counters */
3513 if (sdata->vif.csa_active &&
3514 (sdata->vif.type == NL80211_IFTYPE_AP ||
3515 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3516 params->n_csa_offsets) {
3517 int i;
3518 u8 c = sdata->csa_current_counter;
3519
3520 for (i = 0; i < params->n_csa_offsets; i++)
3521 data[params->csa_offsets[i]] = c;
3522 }
3401 3523
3402 IEEE80211_SKB_CB(skb)->flags = flags; 3524 IEEE80211_SKB_CB(skb)->flags = flags;
3403 3525
@@ -3506,320 +3628,6 @@ static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3506 return 0; 3628 return 0;
3507} 3629}
3508 3630
3509static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
3510{
3511 u8 *pos = (void *)skb_put(skb, 7);
3512
3513 *pos++ = WLAN_EID_EXT_CAPABILITY;
3514 *pos++ = 5; /* len */
3515 *pos++ = 0x0;
3516 *pos++ = 0x0;
3517 *pos++ = 0x0;
3518 *pos++ = 0x0;
3519 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3520}
3521
3522static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3523{
3524 struct ieee80211_local *local = sdata->local;
3525 u16 capab;
3526
3527 capab = 0;
3528 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
3529 return capab;
3530
3531 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3532 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3533 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3534 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3535
3536 return capab;
3537}
3538
3539static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3540 u8 *peer, u8 *bssid)
3541{
3542 struct ieee80211_tdls_lnkie *lnkid;
3543
3544 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3545
3546 lnkid->ie_type = WLAN_EID_LINK_ID;
3547 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3548
3549 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3550 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3551 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3552}
3553
3554static int
3555ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3556 u8 *peer, u8 action_code, u8 dialog_token,
3557 u16 status_code, struct sk_buff *skb)
3558{
3559 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3560 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
3561 struct ieee80211_tdls_data *tf;
3562
3563 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3564
3565 memcpy(tf->da, peer, ETH_ALEN);
3566 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3567 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3568 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3569
3570 switch (action_code) {
3571 case WLAN_TDLS_SETUP_REQUEST:
3572 tf->category = WLAN_CATEGORY_TDLS;
3573 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3574
3575 skb_put(skb, sizeof(tf->u.setup_req));
3576 tf->u.setup_req.dialog_token = dialog_token;
3577 tf->u.setup_req.capability =
3578 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3579
3580 ieee80211_add_srates_ie(sdata, skb, false, band);
3581 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3582 ieee80211_tdls_add_ext_capab(skb);
3583 break;
3584 case WLAN_TDLS_SETUP_RESPONSE:
3585 tf->category = WLAN_CATEGORY_TDLS;
3586 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3587
3588 skb_put(skb, sizeof(tf->u.setup_resp));
3589 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3590 tf->u.setup_resp.dialog_token = dialog_token;
3591 tf->u.setup_resp.capability =
3592 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3593
3594 ieee80211_add_srates_ie(sdata, skb, false, band);
3595 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3596 ieee80211_tdls_add_ext_capab(skb);
3597 break;
3598 case WLAN_TDLS_SETUP_CONFIRM:
3599 tf->category = WLAN_CATEGORY_TDLS;
3600 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3601
3602 skb_put(skb, sizeof(tf->u.setup_cfm));
3603 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3604 tf->u.setup_cfm.dialog_token = dialog_token;
3605 break;
3606 case WLAN_TDLS_TEARDOWN:
3607 tf->category = WLAN_CATEGORY_TDLS;
3608 tf->action_code = WLAN_TDLS_TEARDOWN;
3609
3610 skb_put(skb, sizeof(tf->u.teardown));
3611 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3612 break;
3613 case WLAN_TDLS_DISCOVERY_REQUEST:
3614 tf->category = WLAN_CATEGORY_TDLS;
3615 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3616
3617 skb_put(skb, sizeof(tf->u.discover_req));
3618 tf->u.discover_req.dialog_token = dialog_token;
3619 break;
3620 default:
3621 return -EINVAL;
3622 }
3623
3624 return 0;
3625}
3626
3627static int
3628ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3629 u8 *peer, u8 action_code, u8 dialog_token,
3630 u16 status_code, struct sk_buff *skb)
3631{
3632 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3633 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
3634 struct ieee80211_mgmt *mgmt;
3635
3636 mgmt = (void *)skb_put(skb, 24);
3637 memset(mgmt, 0, 24);
3638 memcpy(mgmt->da, peer, ETH_ALEN);
3639 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3640 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3641
3642 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3643 IEEE80211_STYPE_ACTION);
3644
3645 switch (action_code) {
3646 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3647 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3648 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3649 mgmt->u.action.u.tdls_discover_resp.action_code =
3650 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3651 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3652 dialog_token;
3653 mgmt->u.action.u.tdls_discover_resp.capability =
3654 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3655
3656 ieee80211_add_srates_ie(sdata, skb, false, band);
3657 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
3658 ieee80211_tdls_add_ext_capab(skb);
3659 break;
3660 default:
3661 return -EINVAL;
3662 }
3663
3664 return 0;
3665}
3666
3667static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3668 u8 *peer, u8 action_code, u8 dialog_token,
3669 u16 status_code, u32 peer_capability,
3670 const u8 *extra_ies, size_t extra_ies_len)
3671{
3672 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3673 struct ieee80211_local *local = sdata->local;
3674 struct sk_buff *skb = NULL;
3675 bool send_direct;
3676 int ret;
3677
3678 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3679 return -ENOTSUPP;
3680
3681 /* make sure we are in managed mode, and associated */
3682 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3683 !sdata->u.mgd.associated)
3684 return -EINVAL;
3685
3686 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3687 action_code, peer);
3688
3689 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3690 max(sizeof(struct ieee80211_mgmt),
3691 sizeof(struct ieee80211_tdls_data)) +
3692 50 + /* supported rates */
3693 7 + /* ext capab */
3694 extra_ies_len +
3695 sizeof(struct ieee80211_tdls_lnkie));
3696 if (!skb)
3697 return -ENOMEM;
3698
3699 skb_reserve(skb, local->hw.extra_tx_headroom);
3700
3701 switch (action_code) {
3702 case WLAN_TDLS_SETUP_REQUEST:
3703 case WLAN_TDLS_SETUP_RESPONSE:
3704 case WLAN_TDLS_SETUP_CONFIRM:
3705 case WLAN_TDLS_TEARDOWN:
3706 case WLAN_TDLS_DISCOVERY_REQUEST:
3707 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3708 action_code, dialog_token,
3709 status_code, skb);
3710 send_direct = false;
3711 break;
3712 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3713 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3714 dialog_token, status_code,
3715 skb);
3716 send_direct = true;
3717 break;
3718 default:
3719 ret = -ENOTSUPP;
3720 break;
3721 }
3722
3723 if (ret < 0)
3724 goto fail;
3725
3726 if (extra_ies_len)
3727 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3728
3729 /* the TDLS link IE is always added last */
3730 switch (action_code) {
3731 case WLAN_TDLS_SETUP_REQUEST:
3732 case WLAN_TDLS_SETUP_CONFIRM:
3733 case WLAN_TDLS_TEARDOWN:
3734 case WLAN_TDLS_DISCOVERY_REQUEST:
3735 /* we are the initiator */
3736 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3737 sdata->u.mgd.bssid);
3738 break;
3739 case WLAN_TDLS_SETUP_RESPONSE:
3740 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3741 /* we are the responder */
3742 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3743 sdata->u.mgd.bssid);
3744 break;
3745 default:
3746 ret = -ENOTSUPP;
3747 goto fail;
3748 }
3749
3750 if (send_direct) {
3751 ieee80211_tx_skb(sdata, skb);
3752 return 0;
3753 }
3754
3755 /*
3756 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3757 * we should default to AC_VI.
3758 */
3759 switch (action_code) {
3760 case WLAN_TDLS_SETUP_REQUEST:
3761 case WLAN_TDLS_SETUP_RESPONSE:
3762 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3763 skb->priority = 2;
3764 break;
3765 default:
3766 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3767 skb->priority = 5;
3768 break;
3769 }
3770
3771 /* disable bottom halves when entering the Tx path */
3772 local_bh_disable();
3773 ret = ieee80211_subif_start_xmit(skb, dev);
3774 local_bh_enable();
3775
3776 return ret;
3777
3778fail:
3779 dev_kfree_skb(skb);
3780 return ret;
3781}
3782
3783static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3784 u8 *peer, enum nl80211_tdls_operation oper)
3785{
3786 struct sta_info *sta;
3787 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3788
3789 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3790 return -ENOTSUPP;
3791
3792 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3793 return -EINVAL;
3794
3795 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
3796
3797 switch (oper) {
3798 case NL80211_TDLS_ENABLE_LINK:
3799 rcu_read_lock();
3800 sta = sta_info_get(sdata, peer);
3801 if (!sta) {
3802 rcu_read_unlock();
3803 return -ENOLINK;
3804 }
3805
3806 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
3807 rcu_read_unlock();
3808 break;
3809 case NL80211_TDLS_DISABLE_LINK:
3810 return sta_info_destroy_addr(sdata, peer);
3811 case NL80211_TDLS_TEARDOWN:
3812 case NL80211_TDLS_SETUP:
3813 case NL80211_TDLS_DISCOVERY_REQ:
3814 /* We don't support in-driver setup/teardown/discovery */
3815 return -ENOTSUPP;
3816 default:
3817 return -ENOTSUPP;
3818 }
3819
3820 return 0;
3821}
3822
3823static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, 3631static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3824 const u8 *peer, u64 *cookie) 3632 const u8 *peer, u64 *cookie)
3825{ 3633{
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 48e6d6f010cd..a310e33972de 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -855,7 +855,7 @@ static void
855__ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, 855__ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
856 bool clear) 856 bool clear)
857{ 857{
858 struct ieee80211_local *local = sdata->local; 858 struct ieee80211_local *local __maybe_unused = sdata->local;
859 struct ieee80211_sub_if_data *vlan; 859 struct ieee80211_sub_if_data *vlan;
860 struct ieee80211_chanctx_conf *conf; 860 struct ieee80211_chanctx_conf *conf;
861 861
@@ -871,7 +871,7 @@ __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
871 * to a channel context that has already been freed. 871 * to a channel context that has already been freed.
872 */ 872 */
873 conf = rcu_dereference_protected(sdata->vif.chanctx_conf, 873 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
874 lockdep_is_held(&local->chanctx_mtx)); 874 lockdep_is_held(&local->chanctx_mtx));
875 WARN_ON(!conf); 875 WARN_ON(!conf);
876 876
877 if (clear) 877 if (clear)
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 5331582a2c81..696ef78b1fb7 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -5,11 +5,11 @@
5#include "ieee80211_i.h" 5#include "ieee80211_i.h"
6#include "trace.h" 6#include "trace.h"
7 7
8static inline void check_sdata_in_driver(struct ieee80211_sub_if_data *sdata) 8static inline bool check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
9{ 9{
10 WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER), 10 return !WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER),
11 "%s: Failed check-sdata-in-driver check, flags: 0x%x\n", 11 "%s: Failed check-sdata-in-driver check, flags: 0x%x\n",
12 sdata->dev ? sdata->dev->name : sdata->name, sdata->flags); 12 sdata->dev ? sdata->dev->name : sdata->name, sdata->flags);
13} 13}
14 14
15static inline struct ieee80211_sub_if_data * 15static inline struct ieee80211_sub_if_data *
@@ -168,7 +168,8 @@ static inline int drv_change_interface(struct ieee80211_local *local,
168 168
169 might_sleep(); 169 might_sleep();
170 170
171 check_sdata_in_driver(sdata); 171 if (!check_sdata_in_driver(sdata))
172 return -EIO;
172 173
173 trace_drv_change_interface(local, sdata, type, p2p); 174 trace_drv_change_interface(local, sdata, type, p2p);
174 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p); 175 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
@@ -181,7 +182,8 @@ static inline void drv_remove_interface(struct ieee80211_local *local,
181{ 182{
182 might_sleep(); 183 might_sleep();
183 184
184 check_sdata_in_driver(sdata); 185 if (!check_sdata_in_driver(sdata))
186 return;
185 187
186 trace_drv_remove_interface(local, sdata); 188 trace_drv_remove_interface(local, sdata);
187 local->ops->remove_interface(&local->hw, &sdata->vif); 189 local->ops->remove_interface(&local->hw, &sdata->vif);
@@ -219,7 +221,8 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
219 sdata->vif.type == NL80211_IFTYPE_MONITOR)) 221 sdata->vif.type == NL80211_IFTYPE_MONITOR))
220 return; 222 return;
221 223
222 check_sdata_in_driver(sdata); 224 if (!check_sdata_in_driver(sdata))
225 return;
223 226
224 trace_drv_bss_info_changed(local, sdata, info, changed); 227 trace_drv_bss_info_changed(local, sdata, info, changed);
225 if (local->ops->bss_info_changed) 228 if (local->ops->bss_info_changed)
@@ -278,7 +281,8 @@ static inline int drv_set_key(struct ieee80211_local *local,
278 might_sleep(); 281 might_sleep();
279 282
280 sdata = get_bss_sdata(sdata); 283 sdata = get_bss_sdata(sdata);
281 check_sdata_in_driver(sdata); 284 if (!check_sdata_in_driver(sdata))
285 return -EIO;
282 286
283 trace_drv_set_key(local, cmd, sdata, sta, key); 287 trace_drv_set_key(local, cmd, sdata, sta, key);
284 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key); 288 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
@@ -298,7 +302,8 @@ static inline void drv_update_tkip_key(struct ieee80211_local *local,
298 ista = &sta->sta; 302 ista = &sta->sta;
299 303
300 sdata = get_bss_sdata(sdata); 304 sdata = get_bss_sdata(sdata);
301 check_sdata_in_driver(sdata); 305 if (!check_sdata_in_driver(sdata))
306 return;
302 307
303 trace_drv_update_tkip_key(local, sdata, conf, ista, iv32); 308 trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
304 if (local->ops->update_tkip_key) 309 if (local->ops->update_tkip_key)
@@ -315,7 +320,8 @@ static inline int drv_hw_scan(struct ieee80211_local *local,
315 320
316 might_sleep(); 321 might_sleep();
317 322
318 check_sdata_in_driver(sdata); 323 if (!check_sdata_in_driver(sdata))
324 return -EIO;
319 325
320 trace_drv_hw_scan(local, sdata); 326 trace_drv_hw_scan(local, sdata);
321 ret = local->ops->hw_scan(&local->hw, &sdata->vif, req); 327 ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
@@ -328,7 +334,8 @@ static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
328{ 334{
329 might_sleep(); 335 might_sleep();
330 336
331 check_sdata_in_driver(sdata); 337 if (!check_sdata_in_driver(sdata))
338 return;
332 339
333 trace_drv_cancel_hw_scan(local, sdata); 340 trace_drv_cancel_hw_scan(local, sdata);
334 local->ops->cancel_hw_scan(&local->hw, &sdata->vif); 341 local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
@@ -345,7 +352,8 @@ drv_sched_scan_start(struct ieee80211_local *local,
345 352
346 might_sleep(); 353 might_sleep();
347 354
348 check_sdata_in_driver(sdata); 355 if (!check_sdata_in_driver(sdata))
356 return -EIO;
349 357
350 trace_drv_sched_scan_start(local, sdata); 358 trace_drv_sched_scan_start(local, sdata);
351 ret = local->ops->sched_scan_start(&local->hw, &sdata->vif, 359 ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
@@ -361,7 +369,8 @@ static inline int drv_sched_scan_stop(struct ieee80211_local *local,
361 369
362 might_sleep(); 370 might_sleep();
363 371
364 check_sdata_in_driver(sdata); 372 if (!check_sdata_in_driver(sdata))
373 return -EIO;
365 374
366 trace_drv_sched_scan_stop(local, sdata); 375 trace_drv_sched_scan_stop(local, sdata);
367 ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif); 376 ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
@@ -462,7 +471,8 @@ static inline void drv_sta_notify(struct ieee80211_local *local,
462 struct ieee80211_sta *sta) 471 struct ieee80211_sta *sta)
463{ 472{
464 sdata = get_bss_sdata(sdata); 473 sdata = get_bss_sdata(sdata);
465 check_sdata_in_driver(sdata); 474 if (!check_sdata_in_driver(sdata))
475 return;
466 476
467 trace_drv_sta_notify(local, sdata, cmd, sta); 477 trace_drv_sta_notify(local, sdata, cmd, sta);
468 if (local->ops->sta_notify) 478 if (local->ops->sta_notify)
@@ -479,7 +489,8 @@ static inline int drv_sta_add(struct ieee80211_local *local,
479 might_sleep(); 489 might_sleep();
480 490
481 sdata = get_bss_sdata(sdata); 491 sdata = get_bss_sdata(sdata);
482 check_sdata_in_driver(sdata); 492 if (!check_sdata_in_driver(sdata))
493 return -EIO;
483 494
484 trace_drv_sta_add(local, sdata, sta); 495 trace_drv_sta_add(local, sdata, sta);
485 if (local->ops->sta_add) 496 if (local->ops->sta_add)
@@ -497,7 +508,8 @@ static inline void drv_sta_remove(struct ieee80211_local *local,
497 might_sleep(); 508 might_sleep();
498 509
499 sdata = get_bss_sdata(sdata); 510 sdata = get_bss_sdata(sdata);
500 check_sdata_in_driver(sdata); 511 if (!check_sdata_in_driver(sdata))
512 return;
501 513
502 trace_drv_sta_remove(local, sdata, sta); 514 trace_drv_sta_remove(local, sdata, sta);
503 if (local->ops->sta_remove) 515 if (local->ops->sta_remove)
@@ -515,7 +527,8 @@ static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
515 might_sleep(); 527 might_sleep();
516 528
517 sdata = get_bss_sdata(sdata); 529 sdata = get_bss_sdata(sdata);
518 check_sdata_in_driver(sdata); 530 if (!check_sdata_in_driver(sdata))
531 return;
519 532
520 if (local->ops->sta_add_debugfs) 533 if (local->ops->sta_add_debugfs)
521 local->ops->sta_add_debugfs(&local->hw, &sdata->vif, 534 local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
@@ -545,7 +558,8 @@ static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
545 might_sleep(); 558 might_sleep();
546 559
547 sdata = get_bss_sdata(sdata); 560 sdata = get_bss_sdata(sdata);
548 check_sdata_in_driver(sdata); 561 if (!check_sdata_in_driver(sdata))
562 return;
549 563
550 trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta); 564 trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
551 if (local->ops->sta_pre_rcu_remove) 565 if (local->ops->sta_pre_rcu_remove)
@@ -566,7 +580,8 @@ int drv_sta_state(struct ieee80211_local *local,
566 might_sleep(); 580 might_sleep();
567 581
568 sdata = get_bss_sdata(sdata); 582 sdata = get_bss_sdata(sdata);
569 check_sdata_in_driver(sdata); 583 if (!check_sdata_in_driver(sdata))
584 return -EIO;
570 585
571 trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state); 586 trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
572 if (local->ops->sta_state) { 587 if (local->ops->sta_state) {
@@ -590,7 +605,8 @@ static inline void drv_sta_rc_update(struct ieee80211_local *local,
590 struct ieee80211_sta *sta, u32 changed) 605 struct ieee80211_sta *sta, u32 changed)
591{ 606{
592 sdata = get_bss_sdata(sdata); 607 sdata = get_bss_sdata(sdata);
593 check_sdata_in_driver(sdata); 608 if (!check_sdata_in_driver(sdata))
609 return;
594 610
595 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED && 611 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
596 (sdata->vif.type != NL80211_IFTYPE_ADHOC && 612 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
@@ -612,7 +628,8 @@ static inline int drv_conf_tx(struct ieee80211_local *local,
612 628
613 might_sleep(); 629 might_sleep();
614 630
615 check_sdata_in_driver(sdata); 631 if (!check_sdata_in_driver(sdata))
632 return -EIO;
616 633
617 trace_drv_conf_tx(local, sdata, ac, params); 634 trace_drv_conf_tx(local, sdata, ac, params);
618 if (local->ops->conf_tx) 635 if (local->ops->conf_tx)
@@ -629,7 +646,8 @@ static inline u64 drv_get_tsf(struct ieee80211_local *local,
629 646
630 might_sleep(); 647 might_sleep();
631 648
632 check_sdata_in_driver(sdata); 649 if (!check_sdata_in_driver(sdata))
650 return ret;
633 651
634 trace_drv_get_tsf(local, sdata); 652 trace_drv_get_tsf(local, sdata);
635 if (local->ops->get_tsf) 653 if (local->ops->get_tsf)
@@ -644,7 +662,8 @@ static inline void drv_set_tsf(struct ieee80211_local *local,
644{ 662{
645 might_sleep(); 663 might_sleep();
646 664
647 check_sdata_in_driver(sdata); 665 if (!check_sdata_in_driver(sdata))
666 return;
648 667
649 trace_drv_set_tsf(local, sdata, tsf); 668 trace_drv_set_tsf(local, sdata, tsf);
650 if (local->ops->set_tsf) 669 if (local->ops->set_tsf)
@@ -657,7 +676,8 @@ static inline void drv_reset_tsf(struct ieee80211_local *local,
657{ 676{
658 might_sleep(); 677 might_sleep();
659 678
660 check_sdata_in_driver(sdata); 679 if (!check_sdata_in_driver(sdata))
680 return;
661 681
662 trace_drv_reset_tsf(local, sdata); 682 trace_drv_reset_tsf(local, sdata);
663 if (local->ops->reset_tsf) 683 if (local->ops->reset_tsf)
@@ -689,7 +709,8 @@ static inline int drv_ampdu_action(struct ieee80211_local *local,
689 might_sleep(); 709 might_sleep();
690 710
691 sdata = get_bss_sdata(sdata); 711 sdata = get_bss_sdata(sdata);
692 check_sdata_in_driver(sdata); 712 if (!check_sdata_in_driver(sdata))
713 return -EIO;
693 714
694 trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size); 715 trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
695 716
@@ -733,8 +754,8 @@ static inline void drv_flush(struct ieee80211_local *local,
733 754
734 might_sleep(); 755 might_sleep();
735 756
736 if (sdata) 757 if (sdata && !check_sdata_in_driver(sdata))
737 check_sdata_in_driver(sdata); 758 return;
738 759
739 trace_drv_flush(local, queues, drop); 760 trace_drv_flush(local, queues, drop);
740 if (local->ops->flush) 761 if (local->ops->flush)
@@ -854,7 +875,8 @@ static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
854 875
855 might_sleep(); 876 might_sleep();
856 877
857 check_sdata_in_driver(sdata); 878 if (!check_sdata_in_driver(sdata))
879 return -EIO;
858 880
859 trace_drv_set_bitrate_mask(local, sdata, mask); 881 trace_drv_set_bitrate_mask(local, sdata, mask);
860 if (local->ops->set_bitrate_mask) 882 if (local->ops->set_bitrate_mask)
@@ -869,7 +891,8 @@ static inline void drv_set_rekey_data(struct ieee80211_local *local,
869 struct ieee80211_sub_if_data *sdata, 891 struct ieee80211_sub_if_data *sdata,
870 struct cfg80211_gtk_rekey_data *data) 892 struct cfg80211_gtk_rekey_data *data)
871{ 893{
872 check_sdata_in_driver(sdata); 894 if (!check_sdata_in_driver(sdata))
895 return;
873 896
874 trace_drv_set_rekey_data(local, sdata, data); 897 trace_drv_set_rekey_data(local, sdata, data);
875 if (local->ops->set_rekey_data) 898 if (local->ops->set_rekey_data)
@@ -937,7 +960,8 @@ static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
937{ 960{
938 might_sleep(); 961 might_sleep();
939 962
940 check_sdata_in_driver(sdata); 963 if (!check_sdata_in_driver(sdata))
964 return;
941 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION); 965 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
942 966
943 trace_drv_mgd_prepare_tx(local, sdata); 967 trace_drv_mgd_prepare_tx(local, sdata);
@@ -964,6 +988,9 @@ static inline int drv_add_chanctx(struct ieee80211_local *local,
964static inline void drv_remove_chanctx(struct ieee80211_local *local, 988static inline void drv_remove_chanctx(struct ieee80211_local *local,
965 struct ieee80211_chanctx *ctx) 989 struct ieee80211_chanctx *ctx)
966{ 990{
991 if (WARN_ON(!ctx->driver_present))
992 return;
993
967 trace_drv_remove_chanctx(local, ctx); 994 trace_drv_remove_chanctx(local, ctx);
968 if (local->ops->remove_chanctx) 995 if (local->ops->remove_chanctx)
969 local->ops->remove_chanctx(&local->hw, &ctx->conf); 996 local->ops->remove_chanctx(&local->hw, &ctx->conf);
@@ -989,7 +1016,8 @@ static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
989{ 1016{
990 int ret = 0; 1017 int ret = 0;
991 1018
992 check_sdata_in_driver(sdata); 1019 if (!check_sdata_in_driver(sdata))
1020 return -EIO;
993 1021
994 trace_drv_assign_vif_chanctx(local, sdata, ctx); 1022 trace_drv_assign_vif_chanctx(local, sdata, ctx);
995 if (local->ops->assign_vif_chanctx) { 1023 if (local->ops->assign_vif_chanctx) {
@@ -1007,7 +1035,8 @@ static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
1007 struct ieee80211_sub_if_data *sdata, 1035 struct ieee80211_sub_if_data *sdata,
1008 struct ieee80211_chanctx *ctx) 1036 struct ieee80211_chanctx *ctx)
1009{ 1037{
1010 check_sdata_in_driver(sdata); 1038 if (!check_sdata_in_driver(sdata))
1039 return;
1011 1040
1012 trace_drv_unassign_vif_chanctx(local, sdata, ctx); 1041 trace_drv_unassign_vif_chanctx(local, sdata, ctx);
1013 if (local->ops->unassign_vif_chanctx) { 1042 if (local->ops->unassign_vif_chanctx) {
@@ -1024,7 +1053,8 @@ static inline int drv_start_ap(struct ieee80211_local *local,
1024{ 1053{
1025 int ret = 0; 1054 int ret = 0;
1026 1055
1027 check_sdata_in_driver(sdata); 1056 if (!check_sdata_in_driver(sdata))
1057 return -EIO;
1028 1058
1029 trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf); 1059 trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
1030 if (local->ops->start_ap) 1060 if (local->ops->start_ap)
@@ -1036,7 +1066,8 @@ static inline int drv_start_ap(struct ieee80211_local *local,
1036static inline void drv_stop_ap(struct ieee80211_local *local, 1066static inline void drv_stop_ap(struct ieee80211_local *local,
1037 struct ieee80211_sub_if_data *sdata) 1067 struct ieee80211_sub_if_data *sdata)
1038{ 1068{
1039 check_sdata_in_driver(sdata); 1069 if (!check_sdata_in_driver(sdata))
1070 return;
1040 1071
1041 trace_drv_stop_ap(local, sdata); 1072 trace_drv_stop_ap(local, sdata);
1042 if (local->ops->stop_ap) 1073 if (local->ops->stop_ap)
@@ -1059,7 +1090,8 @@ drv_set_default_unicast_key(struct ieee80211_local *local,
1059 struct ieee80211_sub_if_data *sdata, 1090 struct ieee80211_sub_if_data *sdata,
1060 int key_idx) 1091 int key_idx)
1061{ 1092{
1062 check_sdata_in_driver(sdata); 1093 if (!check_sdata_in_driver(sdata))
1094 return;
1063 1095
1064 WARN_ON_ONCE(key_idx < -1 || key_idx > 3); 1096 WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
1065 1097
@@ -1101,7 +1133,8 @@ static inline int drv_join_ibss(struct ieee80211_local *local,
1101 int ret = 0; 1133 int ret = 0;
1102 1134
1103 might_sleep(); 1135 might_sleep();
1104 check_sdata_in_driver(sdata); 1136 if (!check_sdata_in_driver(sdata))
1137 return -EIO;
1105 1138
1106 trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf); 1139 trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
1107 if (local->ops->join_ibss) 1140 if (local->ops->join_ibss)
@@ -1114,7 +1147,8 @@ static inline void drv_leave_ibss(struct ieee80211_local *local,
1114 struct ieee80211_sub_if_data *sdata) 1147 struct ieee80211_sub_if_data *sdata)
1115{ 1148{
1116 might_sleep(); 1149 might_sleep();
1117 check_sdata_in_driver(sdata); 1150 if (!check_sdata_in_driver(sdata))
1151 return;
1118 1152
1119 trace_drv_leave_ibss(local, sdata); 1153 trace_drv_leave_ibss(local, sdata);
1120 if (local->ops->leave_ibss) 1154 if (local->ops->leave_ibss)
@@ -1122,4 +1156,17 @@ static inline void drv_leave_ibss(struct ieee80211_local *local,
1122 trace_drv_return_void(local); 1156 trace_drv_return_void(local);
1123} 1157}
1124 1158
1159static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1160 struct ieee80211_sta *sta)
1161{
1162 u32 ret = 0;
1163
1164 trace_drv_get_expected_throughput(sta);
1165 if (local->ops->get_expected_throughput)
1166 ret = local->ops->get_expected_throughput(sta);
1167 trace_drv_return_u32(local, ret);
1168
1169 return ret;
1170}
1171
1125#endif /* __MAC80211_DRIVER_OPS */ 1172#endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index ff4d4155a84d..1bbac94da58d 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -143,7 +143,7 @@ ieee80211_ibss_build_presp(struct ieee80211_sub_if_data *sdata,
143 *pos++ = csa_settings->block_tx ? 1 : 0; 143 *pos++ = csa_settings->block_tx ? 1 : 0;
144 *pos++ = ieee80211_frequency_to_channel( 144 *pos++ = ieee80211_frequency_to_channel(
145 csa_settings->chandef.chan->center_freq); 145 csa_settings->chandef.chan->center_freq);
146 sdata->csa_counter_offset_beacon = (pos - presp->head); 146 sdata->csa_counter_offset_beacon[0] = (pos - presp->head);
147 *pos++ = csa_settings->count; 147 *pos++ = csa_settings->count;
148 } 148 }
149 149
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index b455f62d357a..ed2b817d5ece 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -753,9 +753,10 @@ struct ieee80211_sub_if_data {
753 struct mac80211_qos_map __rcu *qos_map; 753 struct mac80211_qos_map __rcu *qos_map;
754 754
755 struct work_struct csa_finalize_work; 755 struct work_struct csa_finalize_work;
756 int csa_counter_offset_beacon; 756 u16 csa_counter_offset_beacon[IEEE80211_MAX_CSA_COUNTERS_NUM];
757 int csa_counter_offset_presp; 757 u16 csa_counter_offset_presp[IEEE80211_MAX_CSA_COUNTERS_NUM];
758 bool csa_radar_required; 758 bool csa_radar_required;
759 bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */
759 struct cfg80211_chan_def csa_chandef; 760 struct cfg80211_chan_def csa_chandef;
760 761
761 struct list_head assigned_chanctx_list; /* protected by chanctx_mtx */ 762 struct list_head assigned_chanctx_list; /* protected by chanctx_mtx */
@@ -765,6 +766,7 @@ struct ieee80211_sub_if_data {
765 struct ieee80211_chanctx *reserved_chanctx; 766 struct ieee80211_chanctx *reserved_chanctx;
766 struct cfg80211_chan_def reserved_chandef; 767 struct cfg80211_chan_def reserved_chandef;
767 bool reserved_radar_required; 768 bool reserved_radar_required;
769 u8 csa_current_counter;
768 770
769 /* used to reconfigure hardware SM PS */ 771 /* used to reconfigure hardware SM PS */
770 struct work_struct recalc_smps; 772 struct work_struct recalc_smps;
@@ -1458,6 +1460,7 @@ __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
1458int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata, 1460int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
1459 struct cfg80211_sched_scan_request *req); 1461 struct cfg80211_sched_scan_request *req);
1460int ieee80211_request_sched_scan_stop(struct ieee80211_sub_if_data *sdata); 1462int ieee80211_request_sched_scan_stop(struct ieee80211_sub_if_data *sdata);
1463void ieee80211_sched_scan_end(struct ieee80211_local *local);
1461void ieee80211_sched_scan_stopped_work(struct work_struct *work); 1464void ieee80211_sched_scan_stopped_work(struct work_struct *work);
1462 1465
1463/* off-channel helpers */ 1466/* off-channel helpers */
@@ -1472,6 +1475,7 @@ void ieee80211_sw_roc_work(struct work_struct *work);
1472void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc); 1475void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc);
1473 1476
1474/* channel switch handling */ 1477/* channel switch handling */
1478bool ieee80211_csa_needs_block_tx(struct ieee80211_local *local);
1475void ieee80211_csa_finalize_work(struct work_struct *work); 1479void ieee80211_csa_finalize_work(struct work_struct *work);
1476int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 1480int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
1477 struct cfg80211_csa_settings *params); 1481 struct cfg80211_csa_settings *params);
@@ -1833,6 +1837,15 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
1833 u8 radar_detect); 1837 u8 radar_detect);
1834int ieee80211_max_num_channels(struct ieee80211_local *local); 1838int ieee80211_max_num_channels(struct ieee80211_local *local);
1835 1839
1840/* TDLS */
1841int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
1842 const u8 *peer, u8 action_code, u8 dialog_token,
1843 u16 status_code, u32 peer_capability,
1844 const u8 *extra_ies, size_t extra_ies_len);
1845int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
1846 const u8 *peer, enum nl80211_tdls_operation oper);
1847
1848
1836#ifdef CONFIG_MAC80211_NOINLINE 1849#ifdef CONFIG_MAC80211_NOINLINE
1837#define debug_noinline noinline 1850#define debug_noinline noinline
1838#else 1851#else
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 7fff3dcaac43..79fc98815da8 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -838,8 +838,15 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
838 838
839 cancel_work_sync(&sdata->recalc_smps); 839 cancel_work_sync(&sdata->recalc_smps);
840 sdata_lock(sdata); 840 sdata_lock(sdata);
841 mutex_lock(&local->mtx);
841 sdata->vif.csa_active = false; 842 sdata->vif.csa_active = false;
843 if (!ieee80211_csa_needs_block_tx(local))
844 ieee80211_wake_queues_by_reason(&local->hw,
845 IEEE80211_MAX_QUEUE_MAP,
846 IEEE80211_QUEUE_STOP_REASON_CSA);
847 mutex_unlock(&local->mtx);
842 sdata_unlock(sdata); 848 sdata_unlock(sdata);
849
843 cancel_work_sync(&sdata->csa_finalize_work); 850 cancel_work_sync(&sdata->csa_finalize_work);
844 851
845 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work); 852 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 6ff65a1ebaa9..16d97f044a20 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -325,7 +325,8 @@ ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
325 struct ieee80211_key *key; 325 struct ieee80211_key *key;
326 int i, j, err; 326 int i, j, err;
327 327
328 BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS); 328 if (WARN_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS))
329 return ERR_PTR(-EINVAL);
329 330
330 key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL); 331 key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL);
331 if (!key) 332 if (!key)
@@ -481,8 +482,8 @@ int ieee80211_key_link(struct ieee80211_key *key,
481 int idx, ret; 482 int idx, ret;
482 bool pairwise; 483 bool pairwise;
483 484
484 BUG_ON(!sdata); 485 if (WARN_ON(!sdata || !key))
485 BUG_ON(!key); 486 return -EINVAL;
486 487
487 pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE; 488 pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
488 idx = key->conf.keyidx; 489 idx = key->conf.keyidx;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 27b9364cdf17..d17c26d6e369 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -956,6 +956,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
956 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) 956 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
957 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP; 957 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
958 958
959 local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
960
959 result = wiphy_register(local->hw.wiphy); 961 result = wiphy_register(local->hw.wiphy);
960 if (result < 0) 962 if (result < 0)
961 goto fail_wiphy_register; 963 goto fail_wiphy_register;
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index b06ddc9519ce..6495a3f0428d 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -679,7 +679,7 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
679 *pos++ = 0x0; 679 *pos++ = 0x0;
680 *pos++ = ieee80211_frequency_to_channel( 680 *pos++ = ieee80211_frequency_to_channel(
681 csa->settings.chandef.chan->center_freq); 681 csa->settings.chandef.chan->center_freq);
682 sdata->csa_counter_offset_beacon = hdr_len + 6; 682 sdata->csa_counter_offset_beacon[0] = hdr_len + 6;
683 *pos++ = csa->settings.count; 683 *pos++ = csa->settings.count;
684 *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; 684 *pos++ = WLAN_EID_CHAN_SWITCH_PARAM;
685 *pos++ = 6; 685 *pos++ = 6;
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index 7d050ed6fe5a..cf032a8db9d7 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -287,8 +287,10 @@ static void mesh_path_move_to_queue(struct mesh_path *gate_mpath,
287 struct sk_buff_head failq; 287 struct sk_buff_head failq;
288 unsigned long flags; 288 unsigned long flags;
289 289
290 BUG_ON(gate_mpath == from_mpath); 290 if (WARN_ON(gate_mpath == from_mpath))
291 BUG_ON(!gate_mpath->next_hop); 291 return;
292 if (WARN_ON(!gate_mpath->next_hop))
293 return;
292 294
293 __skb_queue_head_init(&failq); 295 __skb_queue_head_init(&failq);
294 296
diff --git a/net/mac80211/mesh_sync.c b/net/mac80211/mesh_sync.c
index 2bc5dc25d5ad..09625d6205c3 100644
--- a/net/mac80211/mesh_sync.c
+++ b/net/mac80211/mesh_sync.c
@@ -171,7 +171,7 @@ static void mesh_sync_offset_adjust_tbtt(struct ieee80211_sub_if_data *sdata,
171 u8 cap; 171 u8 cap;
172 172
173 WARN_ON(ifmsh->mesh_sp_id != IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET); 173 WARN_ON(ifmsh->mesh_sp_id != IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET);
174 BUG_ON(!rcu_read_lock_held()); 174 WARN_ON(!rcu_read_lock_held());
175 cap = beacon->meshconf->meshconf_cap; 175 cap = beacon->meshconf->meshconf_cap;
176 176
177 spin_lock_bh(&ifmsh->sync_offset_lock); 177 spin_lock_bh(&ifmsh->sync_offset_lock);
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 488826f188a7..7f073ef1e0a6 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -975,16 +975,23 @@ static void ieee80211_chswitch_work(struct work_struct *work)
975 /* XXX: shouldn't really modify cfg80211-owned data! */ 975 /* XXX: shouldn't really modify cfg80211-owned data! */
976 ifmgd->associated->channel = sdata->csa_chandef.chan; 976 ifmgd->associated->channel = sdata->csa_chandef.chan;
977 977
978 ieee80211_bss_info_change_notify(sdata, changed);
979
980 mutex_lock(&local->mtx);
981 sdata->vif.csa_active = false;
978 /* XXX: wait for a beacon first? */ 982 /* XXX: wait for a beacon first? */
979 ieee80211_wake_queues_by_reason(&local->hw, 983 if (!ieee80211_csa_needs_block_tx(local))
984 ieee80211_wake_queues_by_reason(&local->hw,
980 IEEE80211_MAX_QUEUE_MAP, 985 IEEE80211_MAX_QUEUE_MAP,
981 IEEE80211_QUEUE_STOP_REASON_CSA); 986 IEEE80211_QUEUE_STOP_REASON_CSA);
987 mutex_unlock(&local->mtx);
982 988
983 ieee80211_bss_info_change_notify(sdata, changed);
984
985 out:
986 sdata->vif.csa_active = false;
987 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; 989 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
990
991 ieee80211_sta_reset_beacon_monitor(sdata);
992 ieee80211_sta_reset_conn_monitor(sdata);
993
994out:
988 sdata_unlock(sdata); 995 sdata_unlock(sdata);
989} 996}
990 997
@@ -1100,12 +1107,16 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1100 mutex_unlock(&local->chanctx_mtx); 1107 mutex_unlock(&local->chanctx_mtx);
1101 1108
1102 sdata->csa_chandef = csa_ie.chandef; 1109 sdata->csa_chandef = csa_ie.chandef;
1110
1111 mutex_lock(&local->mtx);
1103 sdata->vif.csa_active = true; 1112 sdata->vif.csa_active = true;
1113 sdata->csa_block_tx = csa_ie.mode;
1104 1114
1105 if (csa_ie.mode) 1115 if (sdata->csa_block_tx)
1106 ieee80211_stop_queues_by_reason(&local->hw, 1116 ieee80211_stop_queues_by_reason(&local->hw,
1107 IEEE80211_MAX_QUEUE_MAP, 1117 IEEE80211_MAX_QUEUE_MAP,
1108 IEEE80211_QUEUE_STOP_REASON_CSA); 1118 IEEE80211_QUEUE_STOP_REASON_CSA);
1119 mutex_unlock(&local->mtx);
1109 1120
1110 if (local->ops->channel_switch) { 1121 if (local->ops->channel_switch) {
1111 /* use driver's channel switch callback */ 1122 /* use driver's channel switch callback */
@@ -1817,6 +1828,12 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1817 ifmgd->flags = 0; 1828 ifmgd->flags = 0;
1818 mutex_lock(&local->mtx); 1829 mutex_lock(&local->mtx);
1819 ieee80211_vif_release_channel(sdata); 1830 ieee80211_vif_release_channel(sdata);
1831
1832 sdata->vif.csa_active = false;
1833 if (!ieee80211_csa_needs_block_tx(local))
1834 ieee80211_wake_queues_by_reason(&local->hw,
1835 IEEE80211_MAX_QUEUE_MAP,
1836 IEEE80211_QUEUE_STOP_REASON_CSA);
1820 mutex_unlock(&local->mtx); 1837 mutex_unlock(&local->mtx);
1821 1838
1822 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; 1839 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
@@ -2045,6 +2062,7 @@ EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2045 2062
2046static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) 2063static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2047{ 2064{
2065 struct ieee80211_local *local = sdata->local;
2048 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2066 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2049 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 2067 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2050 2068
@@ -2058,10 +2076,14 @@ static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2058 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 2076 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2059 true, frame_buf); 2077 true, frame_buf);
2060 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; 2078 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
2079
2080 mutex_lock(&local->mtx);
2061 sdata->vif.csa_active = false; 2081 sdata->vif.csa_active = false;
2062 ieee80211_wake_queues_by_reason(&sdata->local->hw, 2082 if (!ieee80211_csa_needs_block_tx(local))
2083 ieee80211_wake_queues_by_reason(&local->hw,
2063 IEEE80211_MAX_QUEUE_MAP, 2084 IEEE80211_MAX_QUEUE_MAP,
2064 IEEE80211_QUEUE_STOP_REASON_CSA); 2085 IEEE80211_QUEUE_STOP_REASON_CSA);
2086 mutex_unlock(&local->mtx);
2065 2087
2066 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, 2088 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
2067 IEEE80211_DEAUTH_FRAME_LEN); 2089 IEEE80211_DEAUTH_FRAME_LEN);
@@ -3546,6 +3568,9 @@ static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3546 if (local->quiescing) 3568 if (local->quiescing)
3547 return; 3569 return;
3548 3570
3571 if (sdata->vif.csa_active)
3572 return;
3573
3549 sdata->u.mgd.connection_loss = false; 3574 sdata->u.mgd.connection_loss = false;
3550 ieee80211_queue_work(&sdata->local->hw, 3575 ieee80211_queue_work(&sdata->local->hw,
3551 &sdata->u.mgd.beacon_connection_loss_work); 3576 &sdata->u.mgd.beacon_connection_loss_work);
@@ -3561,6 +3586,9 @@ static void ieee80211_sta_conn_mon_timer(unsigned long data)
3561 if (local->quiescing) 3586 if (local->quiescing)
3562 return; 3587 return;
3563 3588
3589 if (sdata->vif.csa_active)
3590 return;
3591
3564 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); 3592 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
3565} 3593}
3566 3594
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index 26fd94fa0aed..1c1469c36dca 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -657,6 +657,17 @@ minstrel_free(void *priv)
657 kfree(priv); 657 kfree(priv);
658} 658}
659 659
660static u32 minstrel_get_expected_throughput(void *priv_sta)
661{
662 struct minstrel_sta_info *mi = priv_sta;
663 int idx = mi->max_tp_rate[0];
664
665 /* convert pkt per sec in kbps (1200 is the average pkt size used for
666 * computing cur_tp
667 */
668 return MINSTREL_TRUNC(mi->r[idx].cur_tp) * 1200 * 8 / 1024;
669}
670
660const struct rate_control_ops mac80211_minstrel = { 671const struct rate_control_ops mac80211_minstrel = {
661 .name = "minstrel", 672 .name = "minstrel",
662 .tx_status = minstrel_tx_status, 673 .tx_status = minstrel_tx_status,
@@ -670,6 +681,7 @@ const struct rate_control_ops mac80211_minstrel = {
670 .add_sta_debugfs = minstrel_add_sta_debugfs, 681 .add_sta_debugfs = minstrel_add_sta_debugfs,
671 .remove_sta_debugfs = minstrel_remove_sta_debugfs, 682 .remove_sta_debugfs = minstrel_remove_sta_debugfs,
672#endif 683#endif
684 .get_expected_throughput = minstrel_get_expected_throughput,
673}; 685};
674 686
675int __init 687int __init
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index bccaf854a309..85c1e74b7714 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -22,7 +22,7 @@
22#define MCS_NBITS (AVG_PKT_SIZE << 3) 22#define MCS_NBITS (AVG_PKT_SIZE << 3)
23 23
24/* Number of symbols for a packet with (bps) bits per symbol */ 24/* Number of symbols for a packet with (bps) bits per symbol */
25#define MCS_NSYMS(bps) ((MCS_NBITS + (bps) - 1) / (bps)) 25#define MCS_NSYMS(bps) DIV_ROUND_UP(MCS_NBITS, (bps))
26 26
27/* Transmission time (nanoseconds) for a packet containing (syms) symbols */ 27/* Transmission time (nanoseconds) for a packet containing (syms) symbols */
28#define MCS_SYMBOL_TIME(sgi, syms) \ 28#define MCS_SYMBOL_TIME(sgi, syms) \
@@ -226,8 +226,9 @@ minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate)
226 nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len); 226 nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len);
227 227
228 nsecs += minstrel_mcs_groups[group].duration[rate]; 228 nsecs += minstrel_mcs_groups[group].duration[rate];
229 tp = 1000000 * ((prob * 1000) / nsecs);
230 229
230 /* prob is scaled - see MINSTREL_FRAC above */
231 tp = 1000000 * ((prob * 1000) / nsecs);
231 mr->cur_tp = MINSTREL_TRUNC(tp); 232 mr->cur_tp = MINSTREL_TRUNC(tp);
232} 233}
233 234
@@ -1031,6 +1032,22 @@ minstrel_ht_free(void *priv)
1031 mac80211_minstrel.free(priv); 1032 mac80211_minstrel.free(priv);
1032} 1033}
1033 1034
1035static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
1036{
1037 struct minstrel_ht_sta_priv *msp = priv_sta;
1038 struct minstrel_ht_sta *mi = &msp->ht;
1039 int i, j;
1040
1041 if (!msp->is_ht)
1042 return mac80211_minstrel.get_expected_throughput(priv_sta);
1043
1044 i = mi->max_tp_rate / MCS_GROUP_RATES;
1045 j = mi->max_tp_rate % MCS_GROUP_RATES;
1046
1047 /* convert cur_tp from pkt per second in kbps */
1048 return mi->groups[i].rates[j].cur_tp * AVG_PKT_SIZE * 8 / 1024;
1049}
1050
1034static const struct rate_control_ops mac80211_minstrel_ht = { 1051static const struct rate_control_ops mac80211_minstrel_ht = {
1035 .name = "minstrel_ht", 1052 .name = "minstrel_ht",
1036 .tx_status = minstrel_ht_tx_status, 1053 .tx_status = minstrel_ht_tx_status,
@@ -1045,6 +1062,7 @@ static const struct rate_control_ops mac80211_minstrel_ht = {
1045 .add_sta_debugfs = minstrel_ht_add_sta_debugfs, 1062 .add_sta_debugfs = minstrel_ht_add_sta_debugfs,
1046 .remove_sta_debugfs = minstrel_ht_remove_sta_debugfs, 1063 .remove_sta_debugfs = minstrel_ht_remove_sta_debugfs,
1047#endif 1064#endif
1065 .get_expected_throughput = minstrel_ht_get_expected_throughput,
1048}; 1066};
1049 1067
1050 1068
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 28185c8dc19a..f40661eb75b5 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -1076,12 +1076,8 @@ void ieee80211_sched_scan_results(struct ieee80211_hw *hw)
1076} 1076}
1077EXPORT_SYMBOL(ieee80211_sched_scan_results); 1077EXPORT_SYMBOL(ieee80211_sched_scan_results);
1078 1078
1079void ieee80211_sched_scan_stopped_work(struct work_struct *work) 1079void ieee80211_sched_scan_end(struct ieee80211_local *local)
1080{ 1080{
1081 struct ieee80211_local *local =
1082 container_of(work, struct ieee80211_local,
1083 sched_scan_stopped_work);
1084
1085 mutex_lock(&local->mtx); 1081 mutex_lock(&local->mtx);
1086 1082
1087 if (!rcu_access_pointer(local->sched_scan_sdata)) { 1083 if (!rcu_access_pointer(local->sched_scan_sdata)) {
@@ -1099,6 +1095,15 @@ void ieee80211_sched_scan_stopped_work(struct work_struct *work)
1099 cfg80211_sched_scan_stopped(local->hw.wiphy); 1095 cfg80211_sched_scan_stopped(local->hw.wiphy);
1100} 1096}
1101 1097
1098void ieee80211_sched_scan_stopped_work(struct work_struct *work)
1099{
1100 struct ieee80211_local *local =
1101 container_of(work, struct ieee80211_local,
1102 sched_scan_stopped_work);
1103
1104 ieee80211_sched_scan_end(local);
1105}
1106
1102void ieee80211_sched_scan_stopped(struct ieee80211_hw *hw) 1107void ieee80211_sched_scan_stopped(struct ieee80211_hw *hw)
1103{ 1108{
1104 struct ieee80211_local *local = hw_to_local(hw); 1109 struct ieee80211_local *local = hw_to_local(hw);
diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
new file mode 100644
index 000000000000..652813b2d3df
--- /dev/null
+++ b/net/mac80211/tdls.c
@@ -0,0 +1,325 @@
1/*
2 * mac80211 TDLS handling code
3 *
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2014, Intel Corporation
6 *
7 * This file is GPLv2 as found in COPYING.
8 */
9
10#include <linux/ieee80211.h>
11#include "ieee80211_i.h"
12
13static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
14{
15 u8 *pos = (void *)skb_put(skb, 7);
16
17 *pos++ = WLAN_EID_EXT_CAPABILITY;
18 *pos++ = 5; /* len */
19 *pos++ = 0x0;
20 *pos++ = 0x0;
21 *pos++ = 0x0;
22 *pos++ = 0x0;
23 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
24}
25
26static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
27{
28 struct ieee80211_local *local = sdata->local;
29 u16 capab;
30
31 capab = 0;
32 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
33 return capab;
34
35 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
36 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
37 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
38 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
39
40 return capab;
41}
42
43static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, const u8 *src_addr,
44 const u8 *peer, const u8 *bssid)
45{
46 struct ieee80211_tdls_lnkie *lnkid;
47
48 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
49
50 lnkid->ie_type = WLAN_EID_LINK_ID;
51 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
52
53 memcpy(lnkid->bssid, bssid, ETH_ALEN);
54 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
55 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
56}
57
58static int
59ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
60 const u8 *peer, u8 action_code, u8 dialog_token,
61 u16 status_code, struct sk_buff *skb)
62{
63 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
64 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
65 struct ieee80211_tdls_data *tf;
66
67 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
68
69 memcpy(tf->da, peer, ETH_ALEN);
70 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
71 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
72 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
73
74 switch (action_code) {
75 case WLAN_TDLS_SETUP_REQUEST:
76 tf->category = WLAN_CATEGORY_TDLS;
77 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
78
79 skb_put(skb, sizeof(tf->u.setup_req));
80 tf->u.setup_req.dialog_token = dialog_token;
81 tf->u.setup_req.capability =
82 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
83
84 ieee80211_add_srates_ie(sdata, skb, false, band);
85 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
86 ieee80211_tdls_add_ext_capab(skb);
87 break;
88 case WLAN_TDLS_SETUP_RESPONSE:
89 tf->category = WLAN_CATEGORY_TDLS;
90 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
91
92 skb_put(skb, sizeof(tf->u.setup_resp));
93 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
94 tf->u.setup_resp.dialog_token = dialog_token;
95 tf->u.setup_resp.capability =
96 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
97
98 ieee80211_add_srates_ie(sdata, skb, false, band);
99 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
100 ieee80211_tdls_add_ext_capab(skb);
101 break;
102 case WLAN_TDLS_SETUP_CONFIRM:
103 tf->category = WLAN_CATEGORY_TDLS;
104 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
105
106 skb_put(skb, sizeof(tf->u.setup_cfm));
107 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
108 tf->u.setup_cfm.dialog_token = dialog_token;
109 break;
110 case WLAN_TDLS_TEARDOWN:
111 tf->category = WLAN_CATEGORY_TDLS;
112 tf->action_code = WLAN_TDLS_TEARDOWN;
113
114 skb_put(skb, sizeof(tf->u.teardown));
115 tf->u.teardown.reason_code = cpu_to_le16(status_code);
116 break;
117 case WLAN_TDLS_DISCOVERY_REQUEST:
118 tf->category = WLAN_CATEGORY_TDLS;
119 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
120
121 skb_put(skb, sizeof(tf->u.discover_req));
122 tf->u.discover_req.dialog_token = dialog_token;
123 break;
124 default:
125 return -EINVAL;
126 }
127
128 return 0;
129}
130
131static int
132ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
133 const u8 *peer, u8 action_code, u8 dialog_token,
134 u16 status_code, struct sk_buff *skb)
135{
136 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
137 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
138 struct ieee80211_mgmt *mgmt;
139
140 mgmt = (void *)skb_put(skb, 24);
141 memset(mgmt, 0, 24);
142 memcpy(mgmt->da, peer, ETH_ALEN);
143 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
144 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
145
146 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
147 IEEE80211_STYPE_ACTION);
148
149 switch (action_code) {
150 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
151 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
152 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
153 mgmt->u.action.u.tdls_discover_resp.action_code =
154 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
155 mgmt->u.action.u.tdls_discover_resp.dialog_token =
156 dialog_token;
157 mgmt->u.action.u.tdls_discover_resp.capability =
158 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
159
160 ieee80211_add_srates_ie(sdata, skb, false, band);
161 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
162 ieee80211_tdls_add_ext_capab(skb);
163 break;
164 default:
165 return -EINVAL;
166 }
167
168 return 0;
169}
170
171int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
172 const u8 *peer, u8 action_code, u8 dialog_token,
173 u16 status_code, u32 peer_capability,
174 const u8 *extra_ies, size_t extra_ies_len)
175{
176 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
177 struct ieee80211_local *local = sdata->local;
178 struct sk_buff *skb = NULL;
179 bool send_direct;
180 int ret;
181
182 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
183 return -ENOTSUPP;
184
185 /* make sure we are in managed mode, and associated */
186 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
187 !sdata->u.mgd.associated)
188 return -EINVAL;
189
190 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
191 action_code, peer);
192
193 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
194 max(sizeof(struct ieee80211_mgmt),
195 sizeof(struct ieee80211_tdls_data)) +
196 50 + /* supported rates */
197 7 + /* ext capab */
198 extra_ies_len +
199 sizeof(struct ieee80211_tdls_lnkie));
200 if (!skb)
201 return -ENOMEM;
202
203 skb_reserve(skb, local->hw.extra_tx_headroom);
204
205 switch (action_code) {
206 case WLAN_TDLS_SETUP_REQUEST:
207 case WLAN_TDLS_SETUP_RESPONSE:
208 case WLAN_TDLS_SETUP_CONFIRM:
209 case WLAN_TDLS_TEARDOWN:
210 case WLAN_TDLS_DISCOVERY_REQUEST:
211 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
212 action_code, dialog_token,
213 status_code, skb);
214 send_direct = false;
215 break;
216 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
217 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
218 dialog_token, status_code,
219 skb);
220 send_direct = true;
221 break;
222 default:
223 ret = -ENOTSUPP;
224 break;
225 }
226
227 if (ret < 0)
228 goto fail;
229
230 if (extra_ies_len)
231 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
232
233 /* the TDLS link IE is always added last */
234 switch (action_code) {
235 case WLAN_TDLS_SETUP_REQUEST:
236 case WLAN_TDLS_SETUP_CONFIRM:
237 case WLAN_TDLS_TEARDOWN:
238 case WLAN_TDLS_DISCOVERY_REQUEST:
239 /* we are the initiator */
240 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
241 sdata->u.mgd.bssid);
242 break;
243 case WLAN_TDLS_SETUP_RESPONSE:
244 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
245 /* we are the responder */
246 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
247 sdata->u.mgd.bssid);
248 break;
249 default:
250 ret = -ENOTSUPP;
251 goto fail;
252 }
253
254 if (send_direct) {
255 ieee80211_tx_skb(sdata, skb);
256 return 0;
257 }
258
259 /*
260 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
261 * we should default to AC_VI.
262 */
263 switch (action_code) {
264 case WLAN_TDLS_SETUP_REQUEST:
265 case WLAN_TDLS_SETUP_RESPONSE:
266 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
267 skb->priority = 2;
268 break;
269 default:
270 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
271 skb->priority = 5;
272 break;
273 }
274
275 /* disable bottom halves when entering the Tx path */
276 local_bh_disable();
277 ret = ieee80211_subif_start_xmit(skb, dev);
278 local_bh_enable();
279
280 return ret;
281
282fail:
283 dev_kfree_skb(skb);
284 return ret;
285}
286
287int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
288 const u8 *peer, enum nl80211_tdls_operation oper)
289{
290 struct sta_info *sta;
291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
292
293 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
294 return -ENOTSUPP;
295
296 if (sdata->vif.type != NL80211_IFTYPE_STATION)
297 return -EINVAL;
298
299 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
300
301 switch (oper) {
302 case NL80211_TDLS_ENABLE_LINK:
303 rcu_read_lock();
304 sta = sta_info_get(sdata, peer);
305 if (!sta) {
306 rcu_read_unlock();
307 return -ENOLINK;
308 }
309
310 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
311 rcu_read_unlock();
312 break;
313 case NL80211_TDLS_DISABLE_LINK:
314 return sta_info_destroy_addr(sdata, peer);
315 case NL80211_TDLS_TEARDOWN:
316 case NL80211_TDLS_SETUP:
317 case NL80211_TDLS_DISCOVERY_REQ:
318 /* We don't support in-driver setup/teardown/discovery */
319 return -ENOTSUPP;
320 default:
321 return -ENOTSUPP;
322 }
323
324 return 0;
325}
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index cec5b60487a4..762e4cd16386 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -184,6 +184,20 @@ TRACE_EVENT(drv_return_bool,
184 "true" : "false") 184 "true" : "false")
185); 185);
186 186
187TRACE_EVENT(drv_return_u32,
188 TP_PROTO(struct ieee80211_local *local, u32 ret),
189 TP_ARGS(local, ret),
190 TP_STRUCT__entry(
191 LOCAL_ENTRY
192 __field(u32, ret)
193 ),
194 TP_fast_assign(
195 LOCAL_ASSIGN;
196 __entry->ret = ret;
197 ),
198 TP_printk(LOCAL_PR_FMT " - %u", LOCAL_PR_ARG, __entry->ret)
199);
200
187TRACE_EVENT(drv_return_u64, 201TRACE_EVENT(drv_return_u64,
188 TP_PROTO(struct ieee80211_local *local, u64 ret), 202 TP_PROTO(struct ieee80211_local *local, u64 ret),
189 TP_ARGS(local, ret), 203 TP_ARGS(local, ret),
@@ -1499,6 +1513,24 @@ DEFINE_EVENT(local_sdata_evt, drv_leave_ibss,
1499 TP_ARGS(local, sdata) 1513 TP_ARGS(local, sdata)
1500); 1514);
1501 1515
1516TRACE_EVENT(drv_get_expected_throughput,
1517 TP_PROTO(struct ieee80211_sta *sta),
1518
1519 TP_ARGS(sta),
1520
1521 TP_STRUCT__entry(
1522 STA_ENTRY
1523 ),
1524
1525 TP_fast_assign(
1526 STA_ASSIGN;
1527 ),
1528
1529 TP_printk(
1530 STA_PR_FMT, STA_PR_ARG
1531 )
1532);
1533
1502/* 1534/*
1503 * Tracing for API calls that drivers call. 1535 * Tracing for API calls that drivers call.
1504 */ 1536 */
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 19d36d4117e0..5214686d9fd1 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -2328,7 +2328,8 @@ void ieee80211_tx_pending(unsigned long data)
2328/* functions for drivers to get certain frames */ 2328/* functions for drivers to get certain frames */
2329 2329
2330static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, 2330static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2331 struct ps_data *ps, struct sk_buff *skb) 2331 struct ps_data *ps, struct sk_buff *skb,
2332 bool is_template)
2332{ 2333{
2333 u8 *pos, *tim; 2334 u8 *pos, *tim;
2334 int aid0 = 0; 2335 int aid0 = 0;
@@ -2341,11 +2342,12 @@ static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2341 * checking byte-for-byte */ 2342 * checking byte-for-byte */
2342 have_bits = !bitmap_empty((unsigned long *)ps->tim, 2343 have_bits = !bitmap_empty((unsigned long *)ps->tim,
2343 IEEE80211_MAX_AID+1); 2344 IEEE80211_MAX_AID+1);
2344 2345 if (!is_template) {
2345 if (ps->dtim_count == 0) 2346 if (ps->dtim_count == 0)
2346 ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1; 2347 ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1;
2347 else 2348 else
2348 ps->dtim_count--; 2349 ps->dtim_count--;
2350 }
2349 2351
2350 tim = pos = (u8 *) skb_put(skb, 6); 2352 tim = pos = (u8 *) skb_put(skb, 6);
2351 *pos++ = WLAN_EID_TIM; 2353 *pos++ = WLAN_EID_TIM;
@@ -2391,7 +2393,8 @@ static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2391} 2393}
2392 2394
2393static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, 2395static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2394 struct ps_data *ps, struct sk_buff *skb) 2396 struct ps_data *ps, struct sk_buff *skb,
2397 bool is_template)
2395{ 2398{
2396 struct ieee80211_local *local = sdata->local; 2399 struct ieee80211_local *local = sdata->local;
2397 2400
@@ -2403,24 +2406,24 @@ static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2403 * of the tim bitmap in mac80211 and the driver. 2406 * of the tim bitmap in mac80211 and the driver.
2404 */ 2407 */
2405 if (local->tim_in_locked_section) { 2408 if (local->tim_in_locked_section) {
2406 __ieee80211_beacon_add_tim(sdata, ps, skb); 2409 __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
2407 } else { 2410 } else {
2408 spin_lock_bh(&local->tim_lock); 2411 spin_lock_bh(&local->tim_lock);
2409 __ieee80211_beacon_add_tim(sdata, ps, skb); 2412 __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
2410 spin_unlock_bh(&local->tim_lock); 2413 spin_unlock_bh(&local->tim_lock);
2411 } 2414 }
2412 2415
2413 return 0; 2416 return 0;
2414} 2417}
2415 2418
2416static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata, 2419static void ieee80211_set_csa(struct ieee80211_sub_if_data *sdata,
2417 struct beacon_data *beacon) 2420 struct beacon_data *beacon)
2418{ 2421{
2419 struct probe_resp *resp; 2422 struct probe_resp *resp;
2420 int counter_offset_beacon = sdata->csa_counter_offset_beacon;
2421 int counter_offset_presp = sdata->csa_counter_offset_presp;
2422 u8 *beacon_data; 2423 u8 *beacon_data;
2423 size_t beacon_data_len; 2424 size_t beacon_data_len;
2425 int i;
2426 u8 count = sdata->csa_current_counter;
2424 2427
2425 switch (sdata->vif.type) { 2428 switch (sdata->vif.type) {
2426 case NL80211_IFTYPE_AP: 2429 case NL80211_IFTYPE_AP:
@@ -2438,40 +2441,57 @@ static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata,
2438 default: 2441 default:
2439 return; 2442 return;
2440 } 2443 }
2441 if (WARN_ON(counter_offset_beacon >= beacon_data_len))
2442 return;
2443 2444
2444 /* Warn if the driver did not check for/react to csa 2445 for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) {
2445 * completeness. A beacon with CSA counter set to 0 should 2446 u16 counter_offset_beacon =
2446 * never occur, because a counter of 1 means switch just 2447 sdata->csa_counter_offset_beacon[i];
2447 * before the next beacon. 2448 u16 counter_offset_presp = sdata->csa_counter_offset_presp[i];
2448 */
2449 if (WARN_ON(beacon_data[counter_offset_beacon] == 1))
2450 return;
2451 2449
2452 beacon_data[counter_offset_beacon]--; 2450 if (counter_offset_beacon) {
2451 if (WARN_ON(counter_offset_beacon >= beacon_data_len))
2452 return;
2453 2453
2454 if (sdata->vif.type == NL80211_IFTYPE_AP && counter_offset_presp) { 2454 beacon_data[counter_offset_beacon] = count;
2455 rcu_read_lock(); 2455 }
2456 resp = rcu_dereference(sdata->u.ap.probe_resp); 2456
2457 if (sdata->vif.type == NL80211_IFTYPE_AP &&
2458 counter_offset_presp) {
2459 rcu_read_lock();
2460 resp = rcu_dereference(sdata->u.ap.probe_resp);
2457 2461
2458 /* if nl80211 accepted the offset, this should not happen. */ 2462 /* If nl80211 accepted the offset, this should
2459 if (WARN_ON(!resp)) { 2463 * not happen.
2464 */
2465 if (WARN_ON(!resp)) {
2466 rcu_read_unlock();
2467 return;
2468 }
2469 resp->data[counter_offset_presp] = count;
2460 rcu_read_unlock(); 2470 rcu_read_unlock();
2461 return;
2462 } 2471 }
2463 resp->data[counter_offset_presp]--;
2464 rcu_read_unlock();
2465 } 2472 }
2466} 2473}
2467 2474
2475u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif)
2476{
2477 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2478
2479 sdata->csa_current_counter--;
2480
2481 /* the counter should never reach 0 */
2482 WARN_ON(!sdata->csa_current_counter);
2483
2484 return sdata->csa_current_counter;
2485}
2486EXPORT_SYMBOL(ieee80211_csa_update_counter);
2487
2468bool ieee80211_csa_is_complete(struct ieee80211_vif *vif) 2488bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
2469{ 2489{
2470 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 2490 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2471 struct beacon_data *beacon = NULL; 2491 struct beacon_data *beacon = NULL;
2472 u8 *beacon_data; 2492 u8 *beacon_data;
2473 size_t beacon_data_len; 2493 size_t beacon_data_len;
2474 int counter_beacon = sdata->csa_counter_offset_beacon; 2494 int counter_beacon = sdata->csa_counter_offset_beacon[0];
2475 int ret = false; 2495 int ret = false;
2476 2496
2477 if (!ieee80211_sdata_running(sdata)) 2497 if (!ieee80211_sdata_running(sdata))
@@ -2521,9 +2541,11 @@ bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
2521} 2541}
2522EXPORT_SYMBOL(ieee80211_csa_is_complete); 2542EXPORT_SYMBOL(ieee80211_csa_is_complete);
2523 2543
2524struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw, 2544static struct sk_buff *
2525 struct ieee80211_vif *vif, 2545__ieee80211_beacon_get(struct ieee80211_hw *hw,
2526 u16 *tim_offset, u16 *tim_length) 2546 struct ieee80211_vif *vif,
2547 struct ieee80211_mutable_offsets *offs,
2548 bool is_template)
2527{ 2549{
2528 struct ieee80211_local *local = hw_to_local(hw); 2550 struct ieee80211_local *local = hw_to_local(hw);
2529 struct sk_buff *skb = NULL; 2551 struct sk_buff *skb = NULL;
@@ -2532,6 +2554,7 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2532 enum ieee80211_band band; 2554 enum ieee80211_band band;
2533 struct ieee80211_tx_rate_control txrc; 2555 struct ieee80211_tx_rate_control txrc;
2534 struct ieee80211_chanctx_conf *chanctx_conf; 2556 struct ieee80211_chanctx_conf *chanctx_conf;
2557 int csa_off_base = 0;
2535 2558
2536 rcu_read_lock(); 2559 rcu_read_lock();
2537 2560
@@ -2541,18 +2564,20 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2541 if (!ieee80211_sdata_running(sdata) || !chanctx_conf) 2564 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
2542 goto out; 2565 goto out;
2543 2566
2544 if (tim_offset) 2567 if (offs)
2545 *tim_offset = 0; 2568 memset(offs, 0, sizeof(*offs));
2546 if (tim_length)
2547 *tim_length = 0;
2548 2569
2549 if (sdata->vif.type == NL80211_IFTYPE_AP) { 2570 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2550 struct ieee80211_if_ap *ap = &sdata->u.ap; 2571 struct ieee80211_if_ap *ap = &sdata->u.ap;
2551 struct beacon_data *beacon = rcu_dereference(ap->beacon); 2572 struct beacon_data *beacon = rcu_dereference(ap->beacon);
2552 2573
2553 if (beacon) { 2574 if (beacon) {
2554 if (sdata->vif.csa_active) 2575 if (sdata->vif.csa_active) {
2555 ieee80211_update_csa(sdata, beacon); 2576 if (!is_template)
2577 ieee80211_csa_update_counter(vif);
2578
2579 ieee80211_set_csa(sdata, beacon);
2580 }
2556 2581
2557 /* 2582 /*
2558 * headroom, head length, 2583 * headroom, head length,
@@ -2569,12 +2594,16 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2569 memcpy(skb_put(skb, beacon->head_len), beacon->head, 2594 memcpy(skb_put(skb, beacon->head_len), beacon->head,
2570 beacon->head_len); 2595 beacon->head_len);
2571 2596
2572 ieee80211_beacon_add_tim(sdata, &ap->ps, skb); 2597 ieee80211_beacon_add_tim(sdata, &ap->ps, skb,
2598 is_template);
2573 2599
2574 if (tim_offset) 2600 if (offs) {
2575 *tim_offset = beacon->head_len; 2601 offs->tim_offset = beacon->head_len;
2576 if (tim_length) 2602 offs->tim_length = skb->len - beacon->head_len;
2577 *tim_length = skb->len - beacon->head_len; 2603
2604 /* for AP the csa offsets are from tail */
2605 csa_off_base = skb->len;
2606 }
2578 2607
2579 if (beacon->tail) 2608 if (beacon->tail)
2580 memcpy(skb_put(skb, beacon->tail_len), 2609 memcpy(skb_put(skb, beacon->tail_len),
@@ -2589,9 +2618,12 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2589 if (!presp) 2618 if (!presp)
2590 goto out; 2619 goto out;
2591 2620
2592 if (sdata->vif.csa_active) 2621 if (sdata->vif.csa_active) {
2593 ieee80211_update_csa(sdata, presp); 2622 if (!is_template)
2623 ieee80211_csa_update_counter(vif);
2594 2624
2625 ieee80211_set_csa(sdata, presp);
2626 }
2595 2627
2596 skb = dev_alloc_skb(local->tx_headroom + presp->head_len + 2628 skb = dev_alloc_skb(local->tx_headroom + presp->head_len +
2597 local->hw.extra_beacon_tailroom); 2629 local->hw.extra_beacon_tailroom);
@@ -2611,8 +2643,17 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2611 if (!bcn) 2643 if (!bcn)
2612 goto out; 2644 goto out;
2613 2645
2614 if (sdata->vif.csa_active) 2646 if (sdata->vif.csa_active) {
2615 ieee80211_update_csa(sdata, bcn); 2647 if (!is_template)
2648 /* TODO: For mesh csa_counter is in TU, so
2649 * decrementing it by one isn't correct, but
2650 * for now we leave it consistent with overall
2651 * mac80211's behavior.
2652 */
2653 ieee80211_csa_update_counter(vif);
2654
2655 ieee80211_set_csa(sdata, bcn);
2656 }
2616 2657
2617 if (ifmsh->sync_ops) 2658 if (ifmsh->sync_ops)
2618 ifmsh->sync_ops->adjust_tbtt(sdata, bcn); 2659 ifmsh->sync_ops->adjust_tbtt(sdata, bcn);
@@ -2626,13 +2667,33 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2626 goto out; 2667 goto out;
2627 skb_reserve(skb, local->tx_headroom); 2668 skb_reserve(skb, local->tx_headroom);
2628 memcpy(skb_put(skb, bcn->head_len), bcn->head, bcn->head_len); 2669 memcpy(skb_put(skb, bcn->head_len), bcn->head, bcn->head_len);
2629 ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb); 2670 ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template);
2671
2672 if (offs) {
2673 offs->tim_offset = bcn->head_len;
2674 offs->tim_length = skb->len - bcn->head_len;
2675 }
2676
2630 memcpy(skb_put(skb, bcn->tail_len), bcn->tail, bcn->tail_len); 2677 memcpy(skb_put(skb, bcn->tail_len), bcn->tail, bcn->tail_len);
2631 } else { 2678 } else {
2632 WARN_ON(1); 2679 WARN_ON(1);
2633 goto out; 2680 goto out;
2634 } 2681 }
2635 2682
2683 /* CSA offsets */
2684 if (offs) {
2685 int i;
2686
2687 for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) {
2688 u16 csa_off = sdata->csa_counter_offset_beacon[i];
2689
2690 if (!csa_off)
2691 continue;
2692
2693 offs->csa_counter_offs[i] = csa_off_base + csa_off;
2694 }
2695 }
2696
2636 band = chanctx_conf->def.chan->band; 2697 band = chanctx_conf->def.chan->band;
2637 2698
2638 info = IEEE80211_SKB_CB(skb); 2699 info = IEEE80211_SKB_CB(skb);
@@ -2663,6 +2724,32 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2663 out: 2724 out:
2664 rcu_read_unlock(); 2725 rcu_read_unlock();
2665 return skb; 2726 return skb;
2727
2728}
2729
2730struct sk_buff *
2731ieee80211_beacon_get_template(struct ieee80211_hw *hw,
2732 struct ieee80211_vif *vif,
2733 struct ieee80211_mutable_offsets *offs)
2734{
2735 return __ieee80211_beacon_get(hw, vif, offs, true);
2736}
2737EXPORT_SYMBOL(ieee80211_beacon_get_template);
2738
2739struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2740 struct ieee80211_vif *vif,
2741 u16 *tim_offset, u16 *tim_length)
2742{
2743 struct ieee80211_mutable_offsets offs = {};
2744 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
2745
2746 if (tim_offset)
2747 *tim_offset = offs.tim_offset;
2748
2749 if (tim_length)
2750 *tim_length = offs.tim_length;
2751
2752 return bcn;
2666} 2753}
2667EXPORT_SYMBOL(ieee80211_beacon_get_tim); 2754EXPORT_SYMBOL(ieee80211_beacon_get_tim);
2668 2755
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index c08bd4aca6bb..6886601afe1c 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1457,6 +1457,44 @@ void ieee80211_stop_device(struct ieee80211_local *local)
1457 drv_stop(local); 1457 drv_stop(local);
1458} 1458}
1459 1459
1460static void ieee80211_handle_reconfig_failure(struct ieee80211_local *local)
1461{
1462 struct ieee80211_sub_if_data *sdata;
1463 struct ieee80211_chanctx *ctx;
1464
1465 /*
1466 * We get here if during resume the device can't be restarted properly.
1467 * We might also get here if this happens during HW reset, which is a
1468 * slightly different situation and we need to drop all connections in
1469 * the latter case.
1470 *
1471 * Ask cfg80211 to turn off all interfaces, this will result in more
1472 * warnings but at least we'll then get into a clean stopped state.
1473 */
1474
1475 local->resuming = false;
1476 local->suspended = false;
1477 local->started = false;
1478
1479 /* scheduled scan clearly can't be running any more, but tell
1480 * cfg80211 and clear local state
1481 */
1482 ieee80211_sched_scan_end(local);
1483
1484 list_for_each_entry(sdata, &local->interfaces, list)
1485 sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
1486
1487 /* Mark channel contexts as not being in the driver any more to avoid
1488 * removing them from the driver during the shutdown process...
1489 */
1490 mutex_lock(&local->chanctx_mtx);
1491 list_for_each_entry(ctx, &local->chanctx_list, list)
1492 ctx->driver_present = false;
1493 mutex_unlock(&local->chanctx_mtx);
1494
1495 cfg80211_shutdown_all_interfaces(local->hw.wiphy);
1496}
1497
1460static void ieee80211_assign_chanctx(struct ieee80211_local *local, 1498static void ieee80211_assign_chanctx(struct ieee80211_local *local,
1461 struct ieee80211_sub_if_data *sdata) 1499 struct ieee80211_sub_if_data *sdata)
1462{ 1500{
@@ -1520,9 +1558,11 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1520 */ 1558 */
1521 res = drv_start(local); 1559 res = drv_start(local);
1522 if (res) { 1560 if (res) {
1523 WARN(local->suspended, "Hardware became unavailable " 1561 if (local->suspended)
1524 "upon resume. This could be a software issue " 1562 WARN(1, "Hardware became unavailable upon resume. This could be a software issue prior to suspend or a hardware issue.\n");
1525 "prior to suspend or a hardware issue.\n"); 1563 else
1564 WARN(1, "Hardware became unavailable during restart.\n");
1565 ieee80211_handle_reconfig_failure(local);
1526 return res; 1566 return res;
1527 } 1567 }
1528 1568