aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_core.c8
-rw-r--r--net/bluetooth/hci_event.c2
-rw-r--r--net/bluetooth/hidp/core.c2
-rw-r--r--net/bluetooth/l2cap_core.c11
-rw-r--r--net/bluetooth/sco.c2
-rw-r--r--net/mac80211/agg-tx.c253
-rw-r--r--net/mac80211/cfg.c179
-rw-r--r--net/mac80211/chan.c3
-rw-r--r--net/mac80211/driver-ops.h23
-rw-r--r--net/mac80211/ht.c33
-rw-r--r--net/mac80211/ibss.c57
-rw-r--r--net/mac80211/ieee80211_i.h29
-rw-r--r--net/mac80211/iface.c38
-rw-r--r--net/mac80211/main.c70
-rw-r--r--net/mac80211/mesh.c35
-rw-r--r--net/mac80211/mesh.h16
-rw-r--r--net/mac80211/mesh_hwmp.c10
-rw-r--r--net/mac80211/mesh_plink.c14
-rw-r--r--net/mac80211/mlme.c72
-rw-r--r--net/mac80211/offchannel.c34
-rw-r--r--net/mac80211/pm.c64
-rw-r--r--net/mac80211/rx.c31
-rw-r--r--net/mac80211/scan.c24
-rw-r--r--net/mac80211/sta_info.c48
-rw-r--r--net/mac80211/sta_info.h42
-rw-r--r--net/mac80211/trace.h24
-rw-r--r--net/mac80211/tx.c56
-rw-r--r--net/mac80211/util.c25
-rw-r--r--net/nfc/core.c50
-rw-r--r--net/nfc/hci/command.c7
-rw-r--r--net/nfc/hci/core.c57
-rw-r--r--net/nfc/hci/hcp.c7
-rw-r--r--net/nfc/llcp/commands.c2
-rw-r--r--net/nfc/llcp/llcp.c44
-rw-r--r--net/nfc/llcp/llcp.h1
-rw-r--r--net/nfc/llcp/sock.c22
-rw-r--r--net/nfc/nci/core.c2
-rw-r--r--net/nfc/netlink.c1
-rw-r--r--net/wireless/ap.c62
-rw-r--r--net/wireless/chan.c4
-rw-r--r--net/wireless/core.c26
-rw-r--r--net/wireless/core.h25
-rw-r--r--net/wireless/mesh.c8
-rw-r--r--net/wireless/mlme.c62
-rw-r--r--net/wireless/nl80211.c268
-rw-r--r--net/wireless/reg.c1124
-rw-r--r--net/wireless/reg.h7
-rw-r--r--net/wireless/sme.c9
-rw-r--r--net/wireless/util.c41
49 files changed, 1672 insertions, 1362 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 596660d37c5e..0f78e34220c9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2810,14 +2810,6 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
2810 if (conn) { 2810 if (conn) {
2811 hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); 2811 hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF);
2812 2812
2813 hci_dev_lock(hdev);
2814 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
2815 !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2816 mgmt_device_connected(hdev, &conn->dst, conn->type,
2817 conn->dst_type, 0, NULL, 0,
2818 conn->dev_class);
2819 hci_dev_unlock(hdev);
2820
2821 /* Send to upper protocol */ 2813 /* Send to upper protocol */
2822 l2cap_recv_acldata(conn, skb, flags); 2814 l2cap_recv_acldata(conn, skb, flags);
2823 return; 2815 return;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 705078a0cc39..81b44481d0d9 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2688,7 +2688,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2688 if (ev->opcode != HCI_OP_NOP) 2688 if (ev->opcode != HCI_OP_NOP)
2689 del_timer(&hdev->cmd_timer); 2689 del_timer(&hdev->cmd_timer);
2690 2690
2691 if (ev->ncmd) { 2691 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
2692 atomic_set(&hdev->cmd_cnt, 1); 2692 atomic_set(&hdev->cmd_cnt, 1);
2693 if (!skb_queue_empty(&hdev->cmd_q)) 2693 if (!skb_queue_empty(&hdev->cmd_q))
2694 queue_work(hdev->workqueue, &hdev->cmd_work); 2694 queue_work(hdev->workqueue, &hdev->cmd_work);
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index b2bcbe2dc328..a7352ff3fd1e 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -931,7 +931,7 @@ static int hidp_setup_hid(struct hidp_session *session,
931 hid->version = req->version; 931 hid->version = req->version;
932 hid->country = req->country; 932 hid->country = req->country;
933 933
934 strncpy(hid->name, req->name, 128); 934 strncpy(hid->name, req->name, sizeof(req->name) - 1);
935 935
936 snprintf(hid->phys, sizeof(hid->phys), "%pMR", 936 snprintf(hid->phys, sizeof(hid->phys), "%pMR",
937 &bt_sk(session->ctrl_sock->sk)->src); 937 &bt_sk(session->ctrl_sock->sk)->src);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 2c78208d793e..22e658322845 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3727,6 +3727,17 @@ sendresp:
3727static int l2cap_connect_req(struct l2cap_conn *conn, 3727static int l2cap_connect_req(struct l2cap_conn *conn,
3728 struct l2cap_cmd_hdr *cmd, u8 *data) 3728 struct l2cap_cmd_hdr *cmd, u8 *data)
3729{ 3729{
3730 struct hci_dev *hdev = conn->hcon->hdev;
3731 struct hci_conn *hcon = conn->hcon;
3732
3733 hci_dev_lock(hdev);
3734 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
3735 !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags))
3736 mgmt_device_connected(hdev, &hcon->dst, hcon->type,
3737 hcon->dst_type, 0, NULL, 0,
3738 hcon->dev_class);
3739 hci_dev_unlock(hdev);
3740
3730 l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP, 0); 3741 l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP, 0);
3731 return 0; 3742 return 0;
3732} 3743}
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 531a93d613d4..57f250c20e39 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -352,7 +352,7 @@ static void __sco_sock_close(struct sock *sk)
352 352
353 case BT_CONNECTED: 353 case BT_CONNECTED:
354 case BT_CONFIG: 354 case BT_CONFIG:
355 if (sco_pi(sk)->conn) { 355 if (sco_pi(sk)->conn->hcon) {
356 sk->sk_state = BT_DISCONN; 356 sk->sk_state = BT_DISCONN;
357 sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT); 357 sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT);
358 hci_conn_put(sco_pi(sk)->conn->hcon); 358 hci_conn_put(sco_pi(sk)->conn->hcon);
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index eb9df22418f0..2f0ccbc5f13e 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -149,16 +149,133 @@ void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
149 rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx); 149 rcu_assign_pointer(sta->ampdu_mlme.tid_tx[tid], tid_tx);
150} 150}
151 151
152static inline int ieee80211_ac_from_tid(int tid)
153{
154 return ieee802_1d_to_ac[tid & 7];
155}
156
157/*
158 * When multiple aggregation sessions on multiple stations
159 * are being created/destroyed simultaneously, we need to
160 * refcount the global queue stop caused by that in order
161 * to not get into a situation where one of the aggregation
162 * setup or teardown re-enables queues before the other is
163 * ready to handle that.
164 *
165 * These two functions take care of this issue by keeping
166 * a global "agg_queue_stop" refcount.
167 */
168static void __acquires(agg_queue)
169ieee80211_stop_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
170{
171 int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
172
173 if (atomic_inc_return(&sdata->local->agg_queue_stop[queue]) == 1)
174 ieee80211_stop_queue_by_reason(
175 &sdata->local->hw, queue,
176 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
177 __acquire(agg_queue);
178}
179
180static void __releases(agg_queue)
181ieee80211_wake_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
182{
183 int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
184
185 if (atomic_dec_return(&sdata->local->agg_queue_stop[queue]) == 0)
186 ieee80211_wake_queue_by_reason(
187 &sdata->local->hw, queue,
188 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
189 __release(agg_queue);
190}
191
192/*
193 * splice packets from the STA's pending to the local pending,
194 * requires a call to ieee80211_agg_splice_finish later
195 */
196static void __acquires(agg_queue)
197ieee80211_agg_splice_packets(struct ieee80211_sub_if_data *sdata,
198 struct tid_ampdu_tx *tid_tx, u16 tid)
199{
200 struct ieee80211_local *local = sdata->local;
201 int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
202 unsigned long flags;
203
204 ieee80211_stop_queue_agg(sdata, tid);
205
206 if (WARN(!tid_tx,
207 "TID %d gone but expected when splicing aggregates from the pending queue\n",
208 tid))
209 return;
210
211 if (!skb_queue_empty(&tid_tx->pending)) {
212 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
213 /* copy over remaining packets */
214 skb_queue_splice_tail_init(&tid_tx->pending,
215 &local->pending[queue]);
216 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
217 }
218}
219
220static void __releases(agg_queue)
221ieee80211_agg_splice_finish(struct ieee80211_sub_if_data *sdata, u16 tid)
222{
223 ieee80211_wake_queue_agg(sdata, tid);
224}
225
226static void ieee80211_remove_tid_tx(struct sta_info *sta, int tid)
227{
228 struct tid_ampdu_tx *tid_tx;
229
230 lockdep_assert_held(&sta->ampdu_mlme.mtx);
231 lockdep_assert_held(&sta->lock);
232
233 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
234
235 /*
236 * When we get here, the TX path will not be lockless any more wrt.
237 * aggregation, since the OPERATIONAL bit has long been cleared.
238 * Thus it will block on getting the lock, if it occurs. So if we
239 * stop the queue now, we will not get any more packets, and any
240 * that might be being processed will wait for us here, thereby
241 * guaranteeing that no packets go to the tid_tx pending queue any
242 * more.
243 */
244
245 ieee80211_agg_splice_packets(sta->sdata, tid_tx, tid);
246
247 /* future packets must not find the tid_tx struct any more */
248 ieee80211_assign_tid_tx(sta, tid, NULL);
249
250 ieee80211_agg_splice_finish(sta->sdata, tid);
251
252 kfree_rcu(tid_tx, rcu_head);
253}
254
152int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, 255int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
153 enum ieee80211_back_parties initiator, 256 enum ieee80211_agg_stop_reason reason)
154 bool tx)
155{ 257{
156 struct ieee80211_local *local = sta->local; 258 struct ieee80211_local *local = sta->local;
157 struct tid_ampdu_tx *tid_tx; 259 struct tid_ampdu_tx *tid_tx;
260 enum ieee80211_ampdu_mlme_action action;
158 int ret; 261 int ret;
159 262
160 lockdep_assert_held(&sta->ampdu_mlme.mtx); 263 lockdep_assert_held(&sta->ampdu_mlme.mtx);
161 264
265 switch (reason) {
266 case AGG_STOP_DECLINED:
267 case AGG_STOP_LOCAL_REQUEST:
268 case AGG_STOP_PEER_REQUEST:
269 action = IEEE80211_AMPDU_TX_STOP_CONT;
270 break;
271 case AGG_STOP_DESTROY_STA:
272 action = IEEE80211_AMPDU_TX_STOP_FLUSH;
273 break;
274 default:
275 WARN_ON_ONCE(1);
276 return -EINVAL;
277 }
278
162 spin_lock_bh(&sta->lock); 279 spin_lock_bh(&sta->lock);
163 280
164 tid_tx = rcu_dereference_protected_tid_tx(sta, tid); 281 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
@@ -167,10 +284,19 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
167 return -ENOENT; 284 return -ENOENT;
168 } 285 }
169 286
170 /* if we're already stopping ignore any new requests to stop */ 287 /*
288 * if we're already stopping ignore any new requests to stop
289 * unless we're destroying it in which case notify the driver
290 */
171 if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) { 291 if (test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
172 spin_unlock_bh(&sta->lock); 292 spin_unlock_bh(&sta->lock);
173 return -EALREADY; 293 if (reason != AGG_STOP_DESTROY_STA)
294 return -EALREADY;
295 ret = drv_ampdu_action(local, sta->sdata,
296 IEEE80211_AMPDU_TX_STOP_FLUSH_CONT,
297 &sta->sta, tid, NULL, 0);
298 WARN_ON_ONCE(ret);
299 goto remove_tid_tx;
174 } 300 }
175 301
176 if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) { 302 if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
@@ -212,11 +338,12 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
212 */ 338 */
213 synchronize_net(); 339 synchronize_net();
214 340
215 tid_tx->stop_initiator = initiator; 341 tid_tx->stop_initiator = reason == AGG_STOP_PEER_REQUEST ?
216 tid_tx->tx_stop = tx; 342 WLAN_BACK_RECIPIENT :
343 WLAN_BACK_INITIATOR;
344 tid_tx->tx_stop = reason == AGG_STOP_LOCAL_REQUEST;
217 345
218 ret = drv_ampdu_action(local, sta->sdata, 346 ret = drv_ampdu_action(local, sta->sdata, action,
219 IEEE80211_AMPDU_TX_STOP,
220 &sta->sta, tid, NULL, 0); 347 &sta->sta, tid, NULL, 0);
221 348
222 /* HW shall not deny going back to legacy */ 349 /* HW shall not deny going back to legacy */
@@ -227,7 +354,14 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
227 */ 354 */
228 } 355 }
229 356
230 return ret; 357 if (reason == AGG_STOP_DESTROY_STA) {
358 remove_tid_tx:
359 spin_lock_bh(&sta->lock);
360 ieee80211_remove_tid_tx(sta, tid);
361 spin_unlock_bh(&sta->lock);
362 }
363
364 return 0;
231} 365}
232 366
233/* 367/*
@@ -264,80 +398,6 @@ static void sta_addba_resp_timer_expired(unsigned long data)
264 rcu_read_unlock(); 398 rcu_read_unlock();
265} 399}
266 400
267static inline int ieee80211_ac_from_tid(int tid)
268{
269 return ieee802_1d_to_ac[tid & 7];
270}
271
272/*
273 * When multiple aggregation sessions on multiple stations
274 * are being created/destroyed simultaneously, we need to
275 * refcount the global queue stop caused by that in order
276 * to not get into a situation where one of the aggregation
277 * setup or teardown re-enables queues before the other is
278 * ready to handle that.
279 *
280 * These two functions take care of this issue by keeping
281 * a global "agg_queue_stop" refcount.
282 */
283static void __acquires(agg_queue)
284ieee80211_stop_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
285{
286 int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
287
288 if (atomic_inc_return(&sdata->local->agg_queue_stop[queue]) == 1)
289 ieee80211_stop_queue_by_reason(
290 &sdata->local->hw, queue,
291 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
292 __acquire(agg_queue);
293}
294
295static void __releases(agg_queue)
296ieee80211_wake_queue_agg(struct ieee80211_sub_if_data *sdata, int tid)
297{
298 int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
299
300 if (atomic_dec_return(&sdata->local->agg_queue_stop[queue]) == 0)
301 ieee80211_wake_queue_by_reason(
302 &sdata->local->hw, queue,
303 IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
304 __release(agg_queue);
305}
306
307/*
308 * splice packets from the STA's pending to the local pending,
309 * requires a call to ieee80211_agg_splice_finish later
310 */
311static void __acquires(agg_queue)
312ieee80211_agg_splice_packets(struct ieee80211_sub_if_data *sdata,
313 struct tid_ampdu_tx *tid_tx, u16 tid)
314{
315 struct ieee80211_local *local = sdata->local;
316 int queue = sdata->vif.hw_queue[ieee80211_ac_from_tid(tid)];
317 unsigned long flags;
318
319 ieee80211_stop_queue_agg(sdata, tid);
320
321 if (WARN(!tid_tx,
322 "TID %d gone but expected when splicing aggregates from the pending queue\n",
323 tid))
324 return;
325
326 if (!skb_queue_empty(&tid_tx->pending)) {
327 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
328 /* copy over remaining packets */
329 skb_queue_splice_tail_init(&tid_tx->pending,
330 &local->pending[queue]);
331 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
332 }
333}
334
335static void __releases(agg_queue)
336ieee80211_agg_splice_finish(struct ieee80211_sub_if_data *sdata, u16 tid)
337{
338 ieee80211_wake_queue_agg(sdata, tid);
339}
340
341void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid) 401void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
342{ 402{
343 struct tid_ampdu_tx *tid_tx; 403 struct tid_ampdu_tx *tid_tx;
@@ -660,14 +720,13 @@ void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif,
660EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); 720EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
661 721
662int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, 722int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
663 enum ieee80211_back_parties initiator, 723 enum ieee80211_agg_stop_reason reason)
664 bool tx)
665{ 724{
666 int ret; 725 int ret;
667 726
668 mutex_lock(&sta->ampdu_mlme.mtx); 727 mutex_lock(&sta->ampdu_mlme.mtx);
669 728
670 ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator, tx); 729 ret = ___ieee80211_stop_tx_ba_session(sta, tid, reason);
671 730
672 mutex_unlock(&sta->ampdu_mlme.mtx); 731 mutex_unlock(&sta->ampdu_mlme.mtx);
673 732
@@ -751,24 +810,7 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
751 ieee80211_send_delba(sta->sdata, ra, tid, 810 ieee80211_send_delba(sta->sdata, ra, tid,
752 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); 811 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
753 812
754 /* 813 ieee80211_remove_tid_tx(sta, tid);
755 * When we get here, the TX path will not be lockless any more wrt.
756 * aggregation, since the OPERATIONAL bit has long been cleared.
757 * Thus it will block on getting the lock, if it occurs. So if we
758 * stop the queue now, we will not get any more packets, and any
759 * that might be being processed will wait for us here, thereby
760 * guaranteeing that no packets go to the tid_tx pending queue any
761 * more.
762 */
763
764 ieee80211_agg_splice_packets(sta->sdata, tid_tx, tid);
765
766 /* future packets must not find the tid_tx struct any more */
767 ieee80211_assign_tid_tx(sta, tid, NULL);
768
769 ieee80211_agg_splice_finish(sta->sdata, tid);
770
771 kfree_rcu(tid_tx, rcu_head);
772 814
773 unlock_sta: 815 unlock_sta:
774 spin_unlock_bh(&sta->lock); 816 spin_unlock_bh(&sta->lock);
@@ -868,8 +910,7 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
868 } 910 }
869 911
870 } else { 912 } else {
871 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 913 ___ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_DECLINED);
872 false);
873 } 914 }
874 915
875 out: 916 out:
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 47e0aca614b7..661b878bd19c 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -164,7 +164,17 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
164 sta = sta_info_get(sdata, mac_addr); 164 sta = sta_info_get(sdata, mac_addr);
165 else 165 else
166 sta = sta_info_get_bss(sdata, mac_addr); 166 sta = sta_info_get_bss(sdata, mac_addr);
167 if (!sta) { 167 /*
168 * The ASSOC test makes sure the driver is ready to
169 * receive the key. When wpa_supplicant has roamed
170 * using FT, it attempts to set the key before
171 * association has completed, this rejects that attempt
172 * so it will set the key again after assocation.
173 *
174 * TODO: accept the key if we have a station entry and
175 * add it to the device after the station.
176 */
177 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
168 ieee80211_key_free(sdata->local, key); 178 ieee80211_key_free(sdata->local, key);
169 err = -ENOENT; 179 err = -ENOENT;
170 goto out_unlock; 180 goto out_unlock;
@@ -510,6 +520,7 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
510 BIT(NL80211_STA_FLAG_WME) | 520 BIT(NL80211_STA_FLAG_WME) |
511 BIT(NL80211_STA_FLAG_MFP) | 521 BIT(NL80211_STA_FLAG_MFP) |
512 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 522 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
523 BIT(NL80211_STA_FLAG_ASSOCIATED) |
513 BIT(NL80211_STA_FLAG_TDLS_PEER); 524 BIT(NL80211_STA_FLAG_TDLS_PEER);
514 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 525 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
515 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED); 526 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
@@ -521,6 +532,8 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
521 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP); 532 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
522 if (test_sta_flag(sta, WLAN_STA_AUTH)) 533 if (test_sta_flag(sta, WLAN_STA_AUTH))
523 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); 534 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
535 if (test_sta_flag(sta, WLAN_STA_ASSOC))
536 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
524 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) 537 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
525 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); 538 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
526} 539}
@@ -930,6 +943,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
930 943
931 sdata->vif.bss_conf.beacon_int = params->beacon_interval; 944 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
932 sdata->vif.bss_conf.dtim_period = params->dtim_period; 945 sdata->vif.bss_conf.dtim_period = params->dtim_period;
946 sdata->vif.bss_conf.enable_beacon = true;
933 947
934 sdata->vif.bss_conf.ssid_len = params->ssid_len; 948 sdata->vif.bss_conf.ssid_len = params->ssid_len;
935 if (params->ssid_len) 949 if (params->ssid_len)
@@ -1010,8 +1024,15 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1010 kfree_rcu(old_probe_resp, rcu_head); 1024 kfree_rcu(old_probe_resp, rcu_head);
1011 1025
1012 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 1026 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1013 sta_info_flush(local, vlan); 1027 sta_info_flush_defer(vlan);
1014 sta_info_flush(local, sdata); 1028 sta_info_flush_defer(sdata);
1029 rcu_barrier();
1030 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1031 sta_info_flush_cleanup(vlan);
1032 sta_info_flush_cleanup(sdata);
1033
1034 sdata->vif.bss_conf.enable_beacon = false;
1035 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1015 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); 1036 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1016 1037
1017 drv_stop_ap(sdata->local, sdata); 1038 drv_stop_ap(sdata->local, sdata);
@@ -1069,6 +1090,58 @@ static void ieee80211_send_layer2_update(struct sta_info *sta)
1069 netif_rx_ni(skb); 1090 netif_rx_ni(skb);
1070} 1091}
1071 1092
1093static int sta_apply_auth_flags(struct ieee80211_local *local,
1094 struct sta_info *sta,
1095 u32 mask, u32 set)
1096{
1097 int ret;
1098
1099 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1100 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1101 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1102 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1103 if (ret)
1104 return ret;
1105 }
1106
1107 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1108 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1109 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1110 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1111 if (ret)
1112 return ret;
1113 }
1114
1115 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1116 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1117 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1118 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1119 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1120 else
1121 ret = 0;
1122 if (ret)
1123 return ret;
1124 }
1125
1126 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1127 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1128 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1129 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1130 if (ret)
1131 return ret;
1132 }
1133
1134 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1135 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1136 test_sta_flag(sta, WLAN_STA_AUTH)) {
1137 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1138 if (ret)
1139 return ret;
1140 }
1141
1142 return 0;
1143}
1144
1072static int sta_apply_parameters(struct ieee80211_local *local, 1145static int sta_apply_parameters(struct ieee80211_local *local,
1073 struct sta_info *sta, 1146 struct sta_info *sta,
1074 struct station_parameters *params) 1147 struct station_parameters *params)
@@ -1086,52 +1159,20 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1086 mask = params->sta_flags_mask; 1159 mask = params->sta_flags_mask;
1087 set = params->sta_flags_set; 1160 set = params->sta_flags_set;
1088 1161
1089 /* 1162 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1090 * In mesh mode, we can clear AUTHENTICATED flag but must 1163 /*
1091 * also make ASSOCIATED follow appropriately for the driver 1164 * In mesh mode, ASSOCIATED isn't part of the nl80211
1092 * API. See also below, after AUTHORIZED changes. 1165 * API but must follow AUTHENTICATED for driver state.
1093 */ 1166 */
1094 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { 1167 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1095 /* cfg80211 should not allow this in non-mesh modes */ 1168 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1096 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif))) 1169 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1097 return -EINVAL; 1170 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1098
1099 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1100 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1101 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1102 if (ret)
1103 return ret;
1104 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1105 if (ret)
1106 return ret;
1107 }
1108 }
1109
1110 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1111 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1112 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1113 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1114 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1115 if (ret)
1116 return ret;
1117 }
1118
1119 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1120 /* cfg80211 should not allow this in non-mesh modes */
1121 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1122 return -EINVAL;
1123
1124 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1125 test_sta_flag(sta, WLAN_STA_AUTH)) {
1126 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1127 if (ret)
1128 return ret;
1129 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1130 if (ret)
1131 return ret;
1132 }
1133 } 1171 }
1134 1172
1173 ret = sta_apply_auth_flags(local, sta, mask, set);
1174 if (ret)
1175 return ret;
1135 1176
1136 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { 1177 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1137 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) 1178 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
@@ -1177,10 +1218,11 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1177 sta->sta.aid = params->aid; 1218 sta->sta.aid = params->aid;
1178 1219
1179 /* 1220 /*
1180 * FIXME: updating the following information is racy when this 1221 * Some of the following updates would be racy if called on an
1181 * function is called from ieee80211_change_station(). 1222 * existing station, via ieee80211_change_station(). However,
1182 * However, all this information should be static so 1223 * all such changes are rejected by cfg80211 except for updates
1183 * maybe we should just reject attemps to change it. 1224 * changing the supported rates on an existing but not yet used
1225 * TDLS peer.
1184 */ 1226 */
1185 1227
1186 if (params->listen_interval >= 0) 1228 if (params->listen_interval >= 0)
@@ -1211,18 +1253,33 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1211 1253
1212 if (ieee80211_vif_is_mesh(&sdata->vif)) { 1254 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1213#ifdef CONFIG_MAC80211_MESH 1255#ifdef CONFIG_MAC80211_MESH
1214 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED) 1256 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED) {
1257 u32 changed = 0;
1258
1215 switch (params->plink_state) { 1259 switch (params->plink_state) {
1216 case NL80211_PLINK_LISTEN:
1217 case NL80211_PLINK_ESTAB: 1260 case NL80211_PLINK_ESTAB:
1261 if (sta->plink_state != NL80211_PLINK_ESTAB)
1262 changed = mesh_plink_inc_estab_count(
1263 sdata);
1264 sta->plink_state = params->plink_state;
1265 break;
1266 case NL80211_PLINK_LISTEN:
1218 case NL80211_PLINK_BLOCKED: 1267 case NL80211_PLINK_BLOCKED:
1268 case NL80211_PLINK_OPN_SNT:
1269 case NL80211_PLINK_OPN_RCVD:
1270 case NL80211_PLINK_CNF_RCVD:
1271 case NL80211_PLINK_HOLDING:
1272 if (sta->plink_state == NL80211_PLINK_ESTAB)
1273 changed = mesh_plink_dec_estab_count(
1274 sdata);
1219 sta->plink_state = params->plink_state; 1275 sta->plink_state = params->plink_state;
1220 break; 1276 break;
1221 default: 1277 default:
1222 /* nothing */ 1278 /* nothing */
1223 break; 1279 break;
1224 } 1280 }
1225 else 1281 ieee80211_bss_info_change_notify(sdata, changed);
1282 } else {
1226 switch (params->plink_action) { 1283 switch (params->plink_action) {
1227 case PLINK_ACTION_OPEN: 1284 case PLINK_ACTION_OPEN:
1228 mesh_plink_open(sta); 1285 mesh_plink_open(sta);
@@ -1231,6 +1288,7 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1231 mesh_plink_block(sta); 1288 mesh_plink_block(sta);
1232 break; 1289 break;
1233 } 1290 }
1291 }
1234#endif 1292#endif
1235 } 1293 }
1236 1294
@@ -1265,6 +1323,10 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1265 if (!sta) 1323 if (!sta)
1266 return -ENOMEM; 1324 return -ENOMEM;
1267 1325
1326 /*
1327 * defaults -- if userspace wants something else we'll
1328 * change it accordingly in sta_apply_parameters()
1329 */
1268 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); 1330 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1269 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); 1331 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1270 1332
@@ -1301,7 +1363,6 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1301static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, 1363static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1302 u8 *mac) 1364 u8 *mac)
1303{ 1365{
1304 struct ieee80211_local *local = wiphy_priv(wiphy);
1305 struct ieee80211_sub_if_data *sdata; 1366 struct ieee80211_sub_if_data *sdata;
1306 1367
1307 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1368 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -1309,7 +1370,7 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1309 if (mac) 1370 if (mac)
1310 return sta_info_destroy_addr_bss(sdata, mac); 1371 return sta_info_destroy_addr_bss(sdata, mac);
1311 1372
1312 sta_info_flush(local, sdata); 1373 sta_info_flush(sdata);
1313 return 0; 1374 return 0;
1314} 1375}
1315 1376
@@ -1615,6 +1676,9 @@ static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1615 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, 1676 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1616 sizeof(setup->mcast_rate)); 1677 sizeof(setup->mcast_rate));
1617 1678
1679 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1680 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1681
1618 return 0; 1682 return 0;
1619} 1683}
1620 1684
@@ -2197,7 +2261,8 @@ static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2197 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2261 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2198 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2262 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2199 2263
2200 if (sdata->vif.type != NL80211_IFTYPE_STATION) 2264 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2265 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
2201 return -EOPNOTSUPP; 2266 return -EOPNOTSUPP;
2202 2267
2203 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) 2268 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index 80e55527504b..1bfe0a8b19d2 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -381,7 +381,8 @@ void ieee80211_iter_chan_contexts_atomic(
381 381
382 rcu_read_lock(); 382 rcu_read_lock();
383 list_for_each_entry_rcu(ctx, &local->chanctx_list, list) 383 list_for_each_entry_rcu(ctx, &local->chanctx_list, list)
384 iter(hw, &ctx->conf, iter_data); 384 if (ctx->driver_present)
385 iter(hw, &ctx->conf, iter_data);
385 rcu_read_unlock(); 386 rcu_read_unlock();
386} 387}
387EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic); 388EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic);
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 698dc7e6f309..0c07f94c5378 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -207,6 +207,14 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
207{ 207{
208 might_sleep(); 208 might_sleep();
209 209
210 WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
211 BSS_CHANGED_BEACON_ENABLED) &&
212 sdata->vif.type != NL80211_IFTYPE_AP &&
213 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
214 sdata->vif.type != NL80211_IFTYPE_MESH_POINT);
215 WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE &&
216 changed & ~BSS_CHANGED_IDLE);
217
210 check_sdata_in_driver(sdata); 218 check_sdata_in_driver(sdata);
211 219
212 trace_drv_bss_info_changed(local, sdata, info, changed); 220 trace_drv_bss_info_changed(local, sdata, info, changed);
@@ -913,6 +921,8 @@ static inline int drv_add_chanctx(struct ieee80211_local *local,
913 if (local->ops->add_chanctx) 921 if (local->ops->add_chanctx)
914 ret = local->ops->add_chanctx(&local->hw, &ctx->conf); 922 ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
915 trace_drv_return_int(local, ret); 923 trace_drv_return_int(local, ret);
924 if (!ret)
925 ctx->driver_present = true;
916 926
917 return ret; 927 return ret;
918} 928}
@@ -924,6 +934,7 @@ static inline void drv_remove_chanctx(struct ieee80211_local *local,
924 if (local->ops->remove_chanctx) 934 if (local->ops->remove_chanctx)
925 local->ops->remove_chanctx(&local->hw, &ctx->conf); 935 local->ops->remove_chanctx(&local->hw, &ctx->conf);
926 trace_drv_return_void(local); 936 trace_drv_return_void(local);
937 ctx->driver_present = false;
927} 938}
928 939
929static inline void drv_change_chanctx(struct ieee80211_local *local, 940static inline void drv_change_chanctx(struct ieee80211_local *local,
@@ -931,8 +942,10 @@ static inline void drv_change_chanctx(struct ieee80211_local *local,
931 u32 changed) 942 u32 changed)
932{ 943{
933 trace_drv_change_chanctx(local, ctx, changed); 944 trace_drv_change_chanctx(local, ctx, changed);
934 if (local->ops->change_chanctx) 945 if (local->ops->change_chanctx) {
946 WARN_ON_ONCE(!ctx->driver_present);
935 local->ops->change_chanctx(&local->hw, &ctx->conf, changed); 947 local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
948 }
936 trace_drv_return_void(local); 949 trace_drv_return_void(local);
937} 950}
938 951
@@ -945,10 +958,12 @@ static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
945 check_sdata_in_driver(sdata); 958 check_sdata_in_driver(sdata);
946 959
947 trace_drv_assign_vif_chanctx(local, sdata, ctx); 960 trace_drv_assign_vif_chanctx(local, sdata, ctx);
948 if (local->ops->assign_vif_chanctx) 961 if (local->ops->assign_vif_chanctx) {
962 WARN_ON_ONCE(!ctx->driver_present);
949 ret = local->ops->assign_vif_chanctx(&local->hw, 963 ret = local->ops->assign_vif_chanctx(&local->hw,
950 &sdata->vif, 964 &sdata->vif,
951 &ctx->conf); 965 &ctx->conf);
966 }
952 trace_drv_return_int(local, ret); 967 trace_drv_return_int(local, ret);
953 968
954 return ret; 969 return ret;
@@ -961,10 +976,12 @@ static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
961 check_sdata_in_driver(sdata); 976 check_sdata_in_driver(sdata);
962 977
963 trace_drv_unassign_vif_chanctx(local, sdata, ctx); 978 trace_drv_unassign_vif_chanctx(local, sdata, ctx);
964 if (local->ops->unassign_vif_chanctx) 979 if (local->ops->unassign_vif_chanctx) {
980 WARN_ON_ONCE(!ctx->driver_present);
965 local->ops->unassign_vif_chanctx(&local->hw, 981 local->ops->unassign_vif_chanctx(&local->hw,
966 &sdata->vif, 982 &sdata->vif,
967 &ctx->conf); 983 &ctx->conf);
984 }
968 trace_drv_return_void(local); 985 trace_drv_return_void(local);
969} 986}
970 987
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index a71d891794a4..61ac7c48ac0c 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -62,6 +62,9 @@ void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
62 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SUP_WIDTH_20_40); 62 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SUP_WIDTH_20_40);
63 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SGI_40); 63 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SGI_40);
64 64
65 /* Allow user to disable SGI-20 (SGI-40 is handled above) */
66 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SGI_20);
67
65 /* Allow user to disable the max-AMSDU bit. */ 68 /* Allow user to disable the max-AMSDU bit. */
66 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_MAX_AMSDU); 69 __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_MAX_AMSDU);
67 70
@@ -117,6 +120,21 @@ void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
117 IEEE80211_HT_CAP_SGI_20 | 120 IEEE80211_HT_CAP_SGI_20 |
118 IEEE80211_HT_CAP_SGI_40 | 121 IEEE80211_HT_CAP_SGI_40 |
119 IEEE80211_HT_CAP_DSSSCCK40)); 122 IEEE80211_HT_CAP_DSSSCCK40));
123
124 /* Unset 40 MHz if we're not using a 40 MHz channel */
125 switch (sdata->vif.bss_conf.chandef.width) {
126 case NL80211_CHAN_WIDTH_20_NOHT:
127 case NL80211_CHAN_WIDTH_20:
128 ht_cap->cap &= ~IEEE80211_HT_CAP_SGI_40;
129 ht_cap->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
130 break;
131 case NL80211_CHAN_WIDTH_40:
132 case NL80211_CHAN_WIDTH_80:
133 case NL80211_CHAN_WIDTH_80P80:
134 case NL80211_CHAN_WIDTH_160:
135 break;
136 }
137
120 /* 138 /*
121 * The STBC bits are asymmetric -- if we don't have 139 * The STBC bits are asymmetric -- if we don't have
122 * TX then mask out the peer's RX and vice versa. 140 * TX then mask out the peer's RX and vice versa.
@@ -179,16 +197,19 @@ void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
179 ieee80211_apply_htcap_overrides(sdata, ht_cap); 197 ieee80211_apply_htcap_overrides(sdata, ht_cap);
180} 198}
181 199
182void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta, bool tx) 200void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
201 enum ieee80211_agg_stop_reason reason)
183{ 202{
184 int i; 203 int i;
185 204
186 cancel_work_sync(&sta->ampdu_mlme.work); 205 cancel_work_sync(&sta->ampdu_mlme.work);
187 206
188 for (i = 0; i < IEEE80211_NUM_TIDS; i++) { 207 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
189 __ieee80211_stop_tx_ba_session(sta, i, WLAN_BACK_INITIATOR, tx); 208 __ieee80211_stop_tx_ba_session(sta, i, reason);
190 __ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT, 209 __ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
191 WLAN_REASON_QSTA_LEAVE_QBSS, tx); 210 WLAN_REASON_QSTA_LEAVE_QBSS,
211 reason != AGG_STOP_DESTROY_STA &&
212 reason != AGG_STOP_PEER_REQUEST);
192 } 213 }
193} 214}
194 215
@@ -245,8 +266,7 @@ void ieee80211_ba_session_work(struct work_struct *work)
245 if (tid_tx && test_and_clear_bit(HT_AGG_STATE_WANT_STOP, 266 if (tid_tx && test_and_clear_bit(HT_AGG_STATE_WANT_STOP,
246 &tid_tx->state)) 267 &tid_tx->state))
247 ___ieee80211_stop_tx_ba_session(sta, tid, 268 ___ieee80211_stop_tx_ba_session(sta, tid,
248 WLAN_BACK_INITIATOR, 269 AGG_STOP_LOCAL_REQUEST);
249 true);
250 } 270 }
251 mutex_unlock(&sta->ampdu_mlme.mtx); 271 mutex_unlock(&sta->ampdu_mlme.mtx);
252} 272}
@@ -314,8 +334,7 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
314 __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0, 334 __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
315 true); 335 true);
316 else 336 else
317 __ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_RECIPIENT, 337 __ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_PEER_REQUEST);
318 true);
319} 338}
320 339
321int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata, 340int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 6b7644e818d8..b4b866f41919 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -67,7 +67,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
67 skb_reserve(skb, sdata->local->hw.extra_tx_headroom); 67 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
68 68
69 if (!ether_addr_equal(ifibss->bssid, bssid)) 69 if (!ether_addr_equal(ifibss->bssid, bssid))
70 sta_info_flush(sdata->local, sdata); 70 sta_info_flush(sdata);
71 71
72 /* if merging, indicate to driver that we leave the old IBSS */ 72 /* if merging, indicate to driver that we leave the old IBSS */
73 if (sdata->vif.bss_conf.ibss_joined) { 73 if (sdata->vif.bss_conf.ibss_joined) {
@@ -191,6 +191,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
191 191
192 rcu_assign_pointer(ifibss->presp, skb); 192 rcu_assign_pointer(ifibss->presp, skb);
193 193
194 sdata->vif.bss_conf.enable_beacon = true;
194 sdata->vif.bss_conf.beacon_int = beacon_int; 195 sdata->vif.bss_conf.beacon_int = beacon_int;
195 sdata->vif.bss_conf.basic_rates = basic_rates; 196 sdata->vif.bss_conf.basic_rates = basic_rates;
196 bss_change = BSS_CHANGED_BEACON_INT; 197 bss_change = BSS_CHANGED_BEACON_INT;
@@ -425,11 +426,9 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
425} 426}
426 427
427static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 428static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
428 struct ieee80211_mgmt *mgmt, 429 struct ieee80211_mgmt *mgmt, size_t len,
429 size_t len,
430 struct ieee80211_rx_status *rx_status, 430 struct ieee80211_rx_status *rx_status,
431 struct ieee802_11_elems *elems, 431 struct ieee802_11_elems *elems)
432 bool beacon)
433{ 432{
434 struct ieee80211_local *local = sdata->local; 433 struct ieee80211_local *local = sdata->local;
435 int freq; 434 int freq;
@@ -530,7 +529,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
530 } 529 }
531 530
532 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, 531 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
533 channel, beacon); 532 channel);
534 if (!bss) 533 if (!bss)
535 return; 534 return;
536 535
@@ -877,14 +876,21 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
877 ieee80211_tx_skb(sdata, skb); 876 ieee80211_tx_skb(sdata, skb);
878} 877}
879 878
880static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 879static
881 struct ieee80211_mgmt *mgmt, 880void ieee80211_rx_mgmt_probe_beacon(struct ieee80211_sub_if_data *sdata,
882 size_t len, 881 struct ieee80211_mgmt *mgmt, size_t len,
883 struct ieee80211_rx_status *rx_status) 882 struct ieee80211_rx_status *rx_status)
884{ 883{
885 size_t baselen; 884 size_t baselen;
886 struct ieee802_11_elems elems; 885 struct ieee802_11_elems elems;
887 886
887 BUILD_BUG_ON(offsetof(typeof(mgmt->u.probe_resp), variable) !=
888 offsetof(typeof(mgmt->u.beacon), variable));
889
890 /*
891 * either beacon or probe_resp but the variable field is at the
892 * same offset
893 */
888 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 894 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
889 if (baselen > len) 895 if (baselen > len)
890 return; 896 return;
@@ -892,25 +898,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
892 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 898 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
893 &elems); 899 &elems);
894 900
895 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 901 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
896}
897
898static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
899 struct ieee80211_mgmt *mgmt,
900 size_t len,
901 struct ieee80211_rx_status *rx_status)
902{
903 size_t baselen;
904 struct ieee802_11_elems elems;
905
906 /* Process beacon from the current BSS */
907 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
908 if (baselen > len)
909 return;
910
911 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
912
913 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
914} 902}
915 903
916void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 904void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
@@ -934,12 +922,9 @@ void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
934 ieee80211_rx_mgmt_probe_req(sdata, skb); 922 ieee80211_rx_mgmt_probe_req(sdata, skb);
935 break; 923 break;
936 case IEEE80211_STYPE_PROBE_RESP: 924 case IEEE80211_STYPE_PROBE_RESP:
937 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
938 rx_status);
939 break;
940 case IEEE80211_STYPE_BEACON: 925 case IEEE80211_STYPE_BEACON:
941 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, 926 ieee80211_rx_mgmt_probe_beacon(sdata, mgmt, skb->len,
942 rx_status); 927 rx_status);
943 break; 928 break;
944 case IEEE80211_STYPE_AUTH: 929 case IEEE80211_STYPE_AUTH:
945 ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len); 930 ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len);
@@ -1182,7 +1167,7 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1182 memset(ifibss->bssid, 0, ETH_ALEN); 1167 memset(ifibss->bssid, 0, ETH_ALEN);
1183 ifibss->ssid_len = 0; 1168 ifibss->ssid_len = 0;
1184 1169
1185 sta_info_flush(sdata->local, sdata); 1170 sta_info_flush(sdata);
1186 1171
1187 spin_lock_bh(&ifibss->incomplete_lock); 1172 spin_lock_bh(&ifibss->incomplete_lock);
1188 while (!list_empty(&ifibss->incomplete_stations)) { 1173 while (!list_empty(&ifibss->incomplete_stations)) {
@@ -1205,6 +1190,8 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
1205 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); 1190 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
1206 sdata->vif.bss_conf.ibss_joined = false; 1191 sdata->vif.bss_conf.ibss_joined = false;
1207 sdata->vif.bss_conf.ibss_creator = false; 1192 sdata->vif.bss_conf.ibss_creator = false;
1193 sdata->vif.bss_conf.enable_beacon = false;
1194 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1208 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | 1195 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1209 BSS_CHANGED_IBSS); 1196 BSS_CHANGED_IBSS);
1210 synchronize_rcu(); 1197 synchronize_rcu();
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 8563b9a5cac3..63f0430c131e 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -405,6 +405,8 @@ struct ieee80211_mgd_assoc_data {
405 405
406 u8 ap_ht_param; 406 u8 ap_ht_param;
407 407
408 struct ieee80211_vht_cap ap_vht_cap;
409
408 size_t ie_len; 410 size_t ie_len;
409 u8 ie[]; 411 u8 ie[];
410}; 412};
@@ -659,10 +661,13 @@ enum ieee80211_sub_if_data_flags {
659 * change handling while the interface is up 661 * change handling while the interface is up
660 * @SDATA_STATE_OFFCHANNEL: This interface is currently in offchannel 662 * @SDATA_STATE_OFFCHANNEL: This interface is currently in offchannel
661 * mode, so queues are stopped 663 * mode, so queues are stopped
664 * @SDATA_STATE_OFFCHANNEL_BEACON_STOPPED: Beaconing was stopped due
665 * to offchannel, reset when offchannel returns
662 */ 666 */
663enum ieee80211_sdata_state_bits { 667enum ieee80211_sdata_state_bits {
664 SDATA_STATE_RUNNING, 668 SDATA_STATE_RUNNING,
665 SDATA_STATE_OFFCHANNEL, 669 SDATA_STATE_OFFCHANNEL,
670 SDATA_STATE_OFFCHANNEL_BEACON_STOPPED,
666}; 671};
667 672
668/** 673/**
@@ -685,6 +690,7 @@ struct ieee80211_chanctx {
685 690
686 enum ieee80211_chanctx_mode mode; 691 enum ieee80211_chanctx_mode mode;
687 int refcount; 692 int refcount;
693 bool driver_present;
688 694
689 struct ieee80211_chanctx_conf conf; 695 struct ieee80211_chanctx_conf conf;
690}; 696};
@@ -783,6 +789,11 @@ struct ieee80211_sub_if_data {
783 struct dentry *default_mgmt_key; 789 struct dentry *default_mgmt_key;
784 } debugfs; 790 } debugfs;
785#endif 791#endif
792
793#ifdef CONFIG_PM
794 struct ieee80211_bss_conf suspend_bss_conf;
795#endif
796
786 /* must be last, dynamically sized area in this! */ 797 /* must be last, dynamically sized area in this! */
787 struct ieee80211_vif vif; 798 struct ieee80211_vif vif;
788}; 799};
@@ -1346,8 +1357,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
1346 struct ieee80211_mgmt *mgmt, 1357 struct ieee80211_mgmt *mgmt,
1347 size_t len, 1358 size_t len,
1348 struct ieee802_11_elems *elems, 1359 struct ieee802_11_elems *elems,
1349 struct ieee80211_channel *channel, 1360 struct ieee80211_channel *channel);
1350 bool beacon);
1351void ieee80211_rx_bss_put(struct ieee80211_local *local, 1361void ieee80211_rx_bss_put(struct ieee80211_local *local,
1352 struct ieee80211_bss *bss); 1362 struct ieee80211_bss *bss);
1353 1363
@@ -1358,10 +1368,8 @@ int ieee80211_request_sched_scan_stop(struct ieee80211_sub_if_data *sdata);
1358void ieee80211_sched_scan_stopped_work(struct work_struct *work); 1368void ieee80211_sched_scan_stopped_work(struct work_struct *work);
1359 1369
1360/* off-channel helpers */ 1370/* off-channel helpers */
1361void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local, 1371void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local);
1362 bool offchannel_ps_enable); 1372void ieee80211_offchannel_return(struct ieee80211_local *local);
1363void ieee80211_offchannel_return(struct ieee80211_local *local,
1364 bool offchannel_ps_disable);
1365void ieee80211_roc_setup(struct ieee80211_local *local); 1373void ieee80211_roc_setup(struct ieee80211_local *local);
1366void ieee80211_start_next_roc(struct ieee80211_local *local); 1374void ieee80211_start_next_roc(struct ieee80211_local *local);
1367void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata); 1375void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata);
@@ -1422,7 +1430,8 @@ void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
1422 u16 initiator, u16 reason, bool stop); 1430 u16 initiator, u16 reason, bool stop);
1423void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid, 1431void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
1424 u16 initiator, u16 reason, bool stop); 1432 u16 initiator, u16 reason, bool stop);
1425void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta, bool tx); 1433void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
1434 enum ieee80211_agg_stop_reason reason);
1426void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata, 1435void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
1427 struct sta_info *sta, 1436 struct sta_info *sta,
1428 struct ieee80211_mgmt *mgmt, size_t len); 1437 struct ieee80211_mgmt *mgmt, size_t len);
@@ -1436,11 +1445,9 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
1436 size_t len); 1445 size_t len);
1437 1446
1438int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, 1447int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
1439 enum ieee80211_back_parties initiator, 1448 enum ieee80211_agg_stop_reason reason);
1440 bool tx);
1441int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, 1449int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
1442 enum ieee80211_back_parties initiator, 1450 enum ieee80211_agg_stop_reason reason);
1443 bool tx);
1444void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid); 1451void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid);
1445void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid); 1452void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid);
1446void ieee80211_ba_session_work(struct work_struct *work); 1453void ieee80211_ba_session_work(struct work_struct *work);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 8be854e86cd9..06fac2991d40 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -747,7 +747,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
747 unsigned long flags; 747 unsigned long flags;
748 struct sk_buff *skb, *tmp; 748 struct sk_buff *skb, *tmp;
749 u32 hw_reconf_flags = 0; 749 u32 hw_reconf_flags = 0;
750 int i; 750 int i, flushed;
751 751
752 clear_bit(SDATA_STATE_RUNNING, &sdata->state); 752 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
753 753
@@ -772,11 +772,15 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
772 * (because if we remove a STA after ops->remove_interface() 772 * (because if we remove a STA after ops->remove_interface()
773 * the driver will have removed the vif info already!) 773 * the driver will have removed the vif info already!)
774 * 774 *
775 * This is relevant only in AP, WDS and mesh modes, since in 775 * This is relevant only in WDS mode, in all other modes we've
776 * all other modes we've already removed all stations when 776 * already removed all stations when disconnecting or similar,
777 * disconnecting etc. 777 * so warn otherwise.
778 *
779 * We call sta_info_flush_cleanup() later, to combine RCU waits.
778 */ 780 */
779 sta_info_flush(local, sdata); 781 flushed = sta_info_flush_defer(sdata);
782 WARN_ON_ONCE((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
783 (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1));
780 784
781 /* 785 /*
782 * Don't count this interface for promisc/allmulti while it 786 * Don't count this interface for promisc/allmulti while it
@@ -859,11 +863,17 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
859 cancel_work_sync(&sdata->work); 863 cancel_work_sync(&sdata->work);
860 /* 864 /*
861 * When we get here, the interface is marked down. 865 * When we get here, the interface is marked down.
862 * Call synchronize_rcu() to wait for the RX path 866 *
863 * should it be using the interface and enqueuing 867 * sta_info_flush_cleanup() requires rcu_barrier()
864 * frames at this very time on another CPU. 868 * first to wait for the station call_rcu() calls
869 * to complete, here we need at least sychronize_rcu()
870 * it to wait for the RX path in case it is using the
871 * interface and enqueuing frames at this very time on
872 * another CPU.
865 */ 873 */
866 synchronize_rcu(); 874 rcu_barrier();
875 sta_info_flush_cleanup(sdata);
876
867 skb_queue_purge(&sdata->skb_queue); 877 skb_queue_purge(&sdata->skb_queue);
868 878
869 /* 879 /*
@@ -961,7 +971,6 @@ static void ieee80211_set_multicast_list(struct net_device *dev)
961 */ 971 */
962static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata) 972static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
963{ 973{
964 struct ieee80211_local *local = sdata->local;
965 int flushed; 974 int flushed;
966 int i; 975 int i;
967 976
@@ -977,7 +986,7 @@ static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
977 if (ieee80211_vif_is_mesh(&sdata->vif)) 986 if (ieee80211_vif_is_mesh(&sdata->vif))
978 mesh_rmc_free(sdata); 987 mesh_rmc_free(sdata);
979 988
980 flushed = sta_info_flush(local, sdata); 989 flushed = sta_info_flush(sdata);
981 WARN_ON(flushed); 990 WARN_ON(flushed);
982} 991}
983 992
@@ -1218,6 +1227,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1218 case NL80211_IFTYPE_AP: 1227 case NL80211_IFTYPE_AP:
1219 skb_queue_head_init(&sdata->u.ap.ps.bc_buf); 1228 skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
1220 INIT_LIST_HEAD(&sdata->u.ap.vlans); 1229 INIT_LIST_HEAD(&sdata->u.ap.vlans);
1230 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1221 break; 1231 break;
1222 case NL80211_IFTYPE_P2P_CLIENT: 1232 case NL80211_IFTYPE_P2P_CLIENT:
1223 type = NL80211_IFTYPE_STATION; 1233 type = NL80211_IFTYPE_STATION;
@@ -1225,9 +1235,11 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1225 sdata->vif.p2p = true; 1235 sdata->vif.p2p = true;
1226 /* fall through */ 1236 /* fall through */
1227 case NL80211_IFTYPE_STATION: 1237 case NL80211_IFTYPE_STATION:
1238 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
1228 ieee80211_sta_setup_sdata(sdata); 1239 ieee80211_sta_setup_sdata(sdata);
1229 break; 1240 break;
1230 case NL80211_IFTYPE_ADHOC: 1241 case NL80211_IFTYPE_ADHOC:
1242 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
1231 ieee80211_ibss_setup_sdata(sdata); 1243 ieee80211_ibss_setup_sdata(sdata);
1232 break; 1244 break;
1233 case NL80211_IFTYPE_MESH_POINT: 1245 case NL80211_IFTYPE_MESH_POINT:
@@ -1241,8 +1253,12 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1241 MONITOR_FLAG_OTHER_BSS; 1253 MONITOR_FLAG_OTHER_BSS;
1242 break; 1254 break;
1243 case NL80211_IFTYPE_WDS: 1255 case NL80211_IFTYPE_WDS:
1256 sdata->vif.bss_conf.bssid = NULL;
1257 break;
1244 case NL80211_IFTYPE_AP_VLAN: 1258 case NL80211_IFTYPE_AP_VLAN:
1259 break;
1245 case NL80211_IFTYPE_P2P_DEVICE: 1260 case NL80211_IFTYPE_P2P_DEVICE:
1261 sdata->vif.bss_conf.bssid = sdata->vif.addr;
1246 break; 1262 break;
1247 case NL80211_IFTYPE_UNSPECIFIED: 1263 case NL80211_IFTYPE_UNSPECIFIED:
1248 case NUM_NL80211_IFTYPES: 1264 case NUM_NL80211_IFTYPES:
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 1b087fff93e7..39cfe8f10ad2 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -207,76 +207,10 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
207 u32 changed) 207 u32 changed)
208{ 208{
209 struct ieee80211_local *local = sdata->local; 209 struct ieee80211_local *local = sdata->local;
210 static const u8 zero[ETH_ALEN] = { 0 };
211 210
212 if (!changed) 211 if (!changed)
213 return; 212 return;
214 213
215 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
216 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
217 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
218 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
219 else if (sdata->vif.type == NL80211_IFTYPE_AP)
220 sdata->vif.bss_conf.bssid = sdata->vif.addr;
221 else if (sdata->vif.type == NL80211_IFTYPE_WDS)
222 sdata->vif.bss_conf.bssid = NULL;
223 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
224 sdata->vif.bss_conf.bssid = zero;
225 } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
226 sdata->vif.bss_conf.bssid = sdata->vif.addr;
227 WARN_ONCE(changed & ~(BSS_CHANGED_IDLE),
228 "P2P Device BSS changed %#x", changed);
229 } else {
230 WARN_ON(1);
231 return;
232 }
233
234 switch (sdata->vif.type) {
235 case NL80211_IFTYPE_AP:
236 case NL80211_IFTYPE_ADHOC:
237 case NL80211_IFTYPE_WDS:
238 case NL80211_IFTYPE_MESH_POINT:
239 break;
240 default:
241 /* do not warn to simplify caller in scan.c */
242 changed &= ~BSS_CHANGED_BEACON_ENABLED;
243 if (WARN_ON(changed & BSS_CHANGED_BEACON))
244 return;
245 break;
246 }
247
248 if (changed & BSS_CHANGED_BEACON_ENABLED) {
249 if (local->quiescing || !ieee80211_sdata_running(sdata) ||
250 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) {
251 sdata->vif.bss_conf.enable_beacon = false;
252 } else {
253 /*
254 * Beacon should be enabled, but AP mode must
255 * check whether there is a beacon configured.
256 */
257 switch (sdata->vif.type) {
258 case NL80211_IFTYPE_AP:
259 sdata->vif.bss_conf.enable_beacon =
260 !!sdata->u.ap.beacon;
261 break;
262 case NL80211_IFTYPE_ADHOC:
263 sdata->vif.bss_conf.enable_beacon =
264 !!sdata->u.ibss.presp;
265 break;
266#ifdef CONFIG_MAC80211_MESH
267 case NL80211_IFTYPE_MESH_POINT:
268 sdata->vif.bss_conf.enable_beacon =
269 !!sdata->u.mesh.mesh_id_len;
270 break;
271#endif
272 default:
273 /* not reached */
274 WARN_ON(1);
275 break;
276 }
277 }
278 }
279
280 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed); 214 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
281} 215}
282 216
@@ -537,6 +471,7 @@ static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
537 471
538 .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 472 .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
539 IEEE80211_HT_CAP_MAX_AMSDU | 473 IEEE80211_HT_CAP_MAX_AMSDU |
474 IEEE80211_HT_CAP_SGI_20 |
540 IEEE80211_HT_CAP_SGI_40), 475 IEEE80211_HT_CAP_SGI_40),
541 .mcs = { 476 .mcs = {
542 .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff, 477 .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -606,7 +541,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
606 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS | 541 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
607 NL80211_FEATURE_SAE | 542 NL80211_FEATURE_SAE |
608 NL80211_FEATURE_HT_IBSS | 543 NL80211_FEATURE_HT_IBSS |
609 NL80211_FEATURE_VIF_TXPOWER; 544 NL80211_FEATURE_VIF_TXPOWER |
545 NL80211_FEATURE_FULL_AP_CLIENT_STATE;
610 546
611 if (!ops->hw_scan) 547 if (!ops->hw_scan)
612 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN | 548 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 649ad513547f..694e27376afa 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -20,16 +20,11 @@
20int mesh_allocated; 20int mesh_allocated;
21static struct kmem_cache *rm_cache; 21static struct kmem_cache *rm_cache;
22 22
23#ifdef CONFIG_MAC80211_MESH
24bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt) 23bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
25{ 24{
26 return (mgmt->u.action.u.mesh_action.action_code == 25 return (mgmt->u.action.u.mesh_action.action_code ==
27 WLAN_MESH_ACTION_HWMP_PATH_SELECTION); 26 WLAN_MESH_ACTION_HWMP_PATH_SELECTION);
28} 27}
29#else
30bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
31{ return false; }
32#endif
33 28
34void ieee80211s_init(void) 29void ieee80211s_init(void)
35{ 30{
@@ -607,6 +602,12 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
607{ 602{
608 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 603 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
609 struct ieee80211_local *local = sdata->local; 604 struct ieee80211_local *local = sdata->local;
605 u32 changed = BSS_CHANGED_BEACON |
606 BSS_CHANGED_BEACON_ENABLED |
607 BSS_CHANGED_HT |
608 BSS_CHANGED_BASIC_RATES |
609 BSS_CHANGED_BEACON_INT;
610 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
610 611
611 local->fif_other_bss++; 612 local->fif_other_bss++;
612 /* mesh ifaces must set allmulti to forward mcast traffic */ 613 /* mesh ifaces must set allmulti to forward mcast traffic */
@@ -624,15 +625,16 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
624 ieee80211_queue_work(&local->hw, &sdata->work); 625 ieee80211_queue_work(&local->hw, &sdata->work);
625 sdata->vif.bss_conf.ht_operation_mode = 626 sdata->vif.bss_conf.ht_operation_mode =
626 ifmsh->mshcfg.ht_opmode; 627 ifmsh->mshcfg.ht_opmode;
627 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL; 628 sdata->vif.bss_conf.enable_beacon = true;
628 sdata->vif.bss_conf.basic_rates = 629 sdata->vif.bss_conf.basic_rates =
629 ieee80211_mandatory_rates(sdata->local, 630 ieee80211_mandatory_rates(local, band);
630 ieee80211_get_sdata_band(sdata)); 631
631 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON | 632 if (band == IEEE80211_BAND_5GHZ) {
632 BSS_CHANGED_BEACON_ENABLED | 633 sdata->vif.bss_conf.use_short_slot = true;
633 BSS_CHANGED_HT | 634 changed |= BSS_CHANGED_ERP_SLOT;
634 BSS_CHANGED_BASIC_RATES | 635 }
635 BSS_CHANGED_BEACON_INT); 636
637 ieee80211_bss_info_change_notify(sdata, changed);
636 638
637 netif_carrier_on(sdata->dev); 639 netif_carrier_on(sdata->dev);
638} 640}
@@ -646,10 +648,12 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
646 648
647 /* stop the beacon */ 649 /* stop the beacon */
648 ifmsh->mesh_id_len = 0; 650 ifmsh->mesh_id_len = 0;
651 sdata->vif.bss_conf.enable_beacon = false;
652 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
649 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); 653 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
650 654
651 /* flush STAs and mpaths on this iface */ 655 /* flush STAs and mpaths on this iface */
652 sta_info_flush(sdata->local, sdata); 656 sta_info_flush(sdata);
653 mesh_path_flush_by_iface(sdata); 657 mesh_path_flush_by_iface(sdata);
654 658
655 del_timer_sync(&sdata->u.mesh.housekeeping_timer); 659 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
@@ -805,6 +809,7 @@ void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
805void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) 809void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
806{ 810{
807 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 811 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
812 static u8 zero_addr[ETH_ALEN] = {};
808 813
809 setup_timer(&ifmsh->housekeeping_timer, 814 setup_timer(&ifmsh->housekeeping_timer,
810 ieee80211_mesh_housekeeping_timer, 815 ieee80211_mesh_housekeeping_timer,
@@ -830,4 +835,6 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
830 INIT_LIST_HEAD(&ifmsh->preq_queue.list); 835 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
831 spin_lock_init(&ifmsh->mesh_preq_queue_lock); 836 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
832 spin_lock_init(&ifmsh->sync_offset_lock); 837 spin_lock_init(&ifmsh->sync_offset_lock);
838
839 sdata->vif.bss_conf.bssid = zero_addr;
833} 840}
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index 84c28c6101cd..aff301544c7f 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -191,8 +191,6 @@ struct mesh_rmc {
191#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) 191#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
192#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) 192#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
193 193
194#define MESH_DEFAULT_BEACON_INTERVAL 1000 /* in 1024 us units */
195
196#define MESH_PATH_EXPIRE (600 * HZ) 194#define MESH_PATH_EXPIRE (600 * HZ)
197 195
198/* Default maximum number of plinks per interface */ 196/* Default maximum number of plinks per interface */
@@ -307,6 +305,20 @@ extern int mesh_paths_generation;
307#ifdef CONFIG_MAC80211_MESH 305#ifdef CONFIG_MAC80211_MESH
308extern int mesh_allocated; 306extern int mesh_allocated;
309 307
308static inline
309u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
310{
311 atomic_inc(&sdata->u.mesh.estab_plinks);
312 return mesh_accept_plinks_update(sdata);
313}
314
315static inline
316u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
317{
318 atomic_dec(&sdata->u.mesh.estab_plinks);
319 return mesh_accept_plinks_update(sdata);
320}
321
310static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata) 322static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
311{ 323{
312 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks - 324 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks -
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 47aeee2d8db1..6b4603a90031 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -215,16 +215,19 @@ static void prepare_frame_for_deferred_tx(struct ieee80211_sub_if_data *sdata,
215 skb->priority = 7; 215 skb->priority = 7;
216 216
217 info->control.vif = &sdata->vif; 217 info->control.vif = &sdata->vif;
218 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
218 ieee80211_set_qos_hdr(sdata, skb); 219 ieee80211_set_qos_hdr(sdata, skb);
219} 220}
220 221
221/** 222/**
222 * mesh_send_path error - Sends a PERR mesh management frame 223 * mesh_path_error_tx - Sends a PERR mesh management frame
223 * 224 *
225 * @ttl: allowed remaining hops
224 * @target: broken destination 226 * @target: broken destination
225 * @target_sn: SN of the broken destination 227 * @target_sn: SN of the broken destination
226 * @target_rcode: reason code for this PERR 228 * @target_rcode: reason code for this PERR
227 * @ra: node this frame is addressed to 229 * @ra: node this frame is addressed to
230 * @sdata: local mesh subif
228 * 231 *
229 * Note: This function may be called with driver locks taken that the driver 232 * Note: This function may be called with driver locks taken that the driver
230 * also acquires in the TX path. To avoid a deadlock we don't transmit the 233 * also acquires in the TX path. To avoid a deadlock we don't transmit the
@@ -246,11 +249,13 @@ int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn,
246 return -EAGAIN; 249 return -EAGAIN;
247 250
248 skb = dev_alloc_skb(local->tx_headroom + 251 skb = dev_alloc_skb(local->tx_headroom +
252 IEEE80211_ENCRYPT_HEADROOM +
253 IEEE80211_ENCRYPT_TAILROOM +
249 hdr_len + 254 hdr_len +
250 2 + 15 /* PERR IE */); 255 2 + 15 /* PERR IE */);
251 if (!skb) 256 if (!skb)
252 return -1; 257 return -1;
253 skb_reserve(skb, local->tx_headroom); 258 skb_reserve(skb, local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM);
254 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); 259 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
255 memset(mgmt, 0, hdr_len); 260 memset(mgmt, 0, hdr_len);
256 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 261 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
@@ -350,6 +355,7 @@ static u32 airtime_link_metric_get(struct ieee80211_local *local,
350 * @sdata: local mesh subif 355 * @sdata: local mesh subif
351 * @mgmt: mesh management frame 356 * @mgmt: mesh management frame
352 * @hwmp_ie: hwmp information element (PREP or PREQ) 357 * @hwmp_ie: hwmp information element (PREP or PREQ)
358 * @action: type of hwmp ie
353 * 359 *
354 * This function updates the path routing information to the originator and the 360 * This function updates the path routing information to the originator and the
355 * transmitter of a HWMP PREQ or PREP frame. 361 * transmitter of a HWMP PREQ or PREP frame.
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 4b274e9c91a5..9e0416696a83 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -41,20 +41,6 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
41 enum ieee80211_self_protected_actioncode action, 41 enum ieee80211_self_protected_actioncode action,
42 u8 *da, __le16 llid, __le16 plid, __le16 reason); 42 u8 *da, __le16 llid, __le16 plid, __le16 reason);
43 43
44static inline
45u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
46{
47 atomic_inc(&sdata->u.mesh.estab_plinks);
48 return mesh_accept_plinks_update(sdata);
49}
50
51static inline
52u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
53{
54 atomic_dec(&sdata->u.mesh.estab_plinks);
55 return mesh_accept_plinks_update(sdata);
56}
57
58/** 44/**
59 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine 45 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
60 * 46 *
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index a3552929a21d..e930175771ff 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -199,11 +199,11 @@ static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata,
199 case NL80211_CHAN_WIDTH_40: 199 case NL80211_CHAN_WIDTH_40:
200 if (sdata->vif.bss_conf.chandef.chan->center_freq > 200 if (sdata->vif.bss_conf.chandef.chan->center_freq >
201 sdata->vif.bss_conf.chandef.center_freq1 && 201 sdata->vif.bss_conf.chandef.center_freq1 &&
202 chan->flags & IEEE80211_CHAN_NO_HT40PLUS) 202 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
203 disable_40 = true; 203 disable_40 = true;
204 if (sdata->vif.bss_conf.chandef.chan->center_freq < 204 if (sdata->vif.bss_conf.chandef.chan->center_freq <
205 sdata->vif.bss_conf.chandef.center_freq1 && 205 sdata->vif.bss_conf.chandef.center_freq1 &&
206 chan->flags & IEEE80211_CHAN_NO_HT40MINUS) 206 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
207 disable_40 = true; 207 disable_40 = true;
208 break; 208 break;
209 default: 209 default:
@@ -341,11 +341,13 @@ static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
341 341
342static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, 342static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
343 struct sk_buff *skb, 343 struct sk_buff *skb,
344 struct ieee80211_supported_band *sband) 344 struct ieee80211_supported_band *sband,
345 struct ieee80211_vht_cap *ap_vht_cap)
345{ 346{
346 u8 *pos; 347 u8 *pos;
347 u32 cap; 348 u32 cap;
348 struct ieee80211_sta_vht_cap vht_cap; 349 struct ieee80211_sta_vht_cap vht_cap;
350 int i;
349 351
350 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); 352 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
351 353
@@ -364,6 +366,42 @@ static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
364 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; 366 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
365 } 367 }
366 368
369 /*
370 * Some APs apparently get confused if our capabilities are better
371 * than theirs, so restrict what we advertise in the assoc request.
372 */
373 if (!(ap_vht_cap->vht_cap_info &
374 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
375 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
376
377 if (!(ap_vht_cap->vht_cap_info &
378 cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
379 cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
380 IEEE80211_VHT_CAP_RXSTBC_3 |
381 IEEE80211_VHT_CAP_RXSTBC_4);
382
383 for (i = 0; i < 8; i++) {
384 int shift = i * 2;
385 u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
386 u16 ap_mcs, our_mcs;
387
388 ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
389 mask) >> shift;
390 our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
391 mask) >> shift;
392
393 switch (ap_mcs) {
394 default:
395 if (our_mcs <= ap_mcs)
396 break;
397 /* fall through */
398 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
399 vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
400 vht_cap.vht_mcs.rx_mcs_map |=
401 cpu_to_le16(ap_mcs << shift);
402 }
403 }
404
367 /* reserve and fill IE */ 405 /* reserve and fill IE */
368 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); 406 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
369 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); 407 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
@@ -562,7 +600,8 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
562 sband, chan, sdata->smps_mode); 600 sband, chan, sdata->smps_mode);
563 601
564 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) 602 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
565 ieee80211_add_vht_ie(sdata, skb, sband); 603 ieee80211_add_vht_ie(sdata, skb, sband,
604 &assoc_data->ap_vht_cap);
566 605
567 /* if present, add any custom non-vendor IEs that go after HT */ 606 /* if present, add any custom non-vendor IEs that go after HT */
568 if (assoc_data->ie_len && assoc_data->ie) { 607 if (assoc_data->ie_len && assoc_data->ie) {
@@ -1486,7 +1525,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1486 sta = sta_info_get(sdata, ifmgd->bssid); 1525 sta = sta_info_get(sdata, ifmgd->bssid);
1487 if (sta) { 1526 if (sta) {
1488 set_sta_flag(sta, WLAN_STA_BLOCK_BA); 1527 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
1489 ieee80211_sta_tear_down_BA_sessions(sta, false); 1528 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
1490 } 1529 }
1491 mutex_unlock(&local->sta_mtx); 1530 mutex_unlock(&local->sta_mtx);
1492 1531
@@ -1521,7 +1560,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1521 memset(ifmgd->bssid, 0, ETH_ALEN); 1560 memset(ifmgd->bssid, 0, ETH_ALEN);
1522 1561
1523 /* remove AP and TDLS peers */ 1562 /* remove AP and TDLS peers */
1524 sta_info_flush(local, sdata); 1563 sta_info_flush_defer(sdata);
1525 1564
1526 /* finally reset all BSS / config parameters */ 1565 /* finally reset all BSS / config parameters */
1527 changed |= ieee80211_reset_erp_info(sdata); 1566 changed |= ieee80211_reset_erp_info(sdata);
@@ -2369,8 +2408,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2369static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 2408static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2370 struct ieee80211_mgmt *mgmt, size_t len, 2409 struct ieee80211_mgmt *mgmt, size_t len,
2371 struct ieee80211_rx_status *rx_status, 2410 struct ieee80211_rx_status *rx_status,
2372 struct ieee802_11_elems *elems, 2411 struct ieee802_11_elems *elems)
2373 bool beacon)
2374{ 2412{
2375 struct ieee80211_local *local = sdata->local; 2413 struct ieee80211_local *local = sdata->local;
2376 int freq; 2414 int freq;
@@ -2404,7 +2442,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
2404 return; 2442 return;
2405 2443
2406 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, 2444 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
2407 channel, beacon); 2445 channel);
2408 if (bss) 2446 if (bss)
2409 ieee80211_rx_bss_put(local, bss); 2447 ieee80211_rx_bss_put(local, bss);
2410 2448
@@ -2447,7 +2485,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
2447 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 2485 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2448 &elems); 2486 &elems);
2449 2487
2450 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 2488 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2451 2489
2452 if (ifmgd->associated && 2490 if (ifmgd->associated &&
2453 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) 2491 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
@@ -2528,8 +2566,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2528 ieee802_11_parse_elems(mgmt->u.beacon.variable, 2566 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2529 len - baselen, &elems); 2567 len - baselen, &elems);
2530 2568
2531 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, 2569 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2532 false);
2533 ifmgd->assoc_data->have_beacon = true; 2570 ifmgd->assoc_data->have_beacon = true;
2534 ifmgd->assoc_data->sent_assoc = false; 2571 ifmgd->assoc_data->sent_assoc = false;
2535 /* continue assoc process */ 2572 /* continue assoc process */
@@ -2682,8 +2719,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2682 ifmgd->beacon_crc = ncrc; 2719 ifmgd->beacon_crc = ncrc;
2683 ifmgd->beacon_crc_valid = true; 2720 ifmgd->beacon_crc_valid = true;
2684 2721
2685 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, 2722 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2686 true);
2687 2723
2688 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, 2724 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
2689 elems.wmm_param_len)) 2725 elems.wmm_param_len))
@@ -3756,7 +3792,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3756 struct ieee80211_bss *bss = (void *)req->bss->priv; 3792 struct ieee80211_bss *bss = (void *)req->bss->priv;
3757 struct ieee80211_mgd_assoc_data *assoc_data; 3793 struct ieee80211_mgd_assoc_data *assoc_data;
3758 struct ieee80211_supported_band *sband; 3794 struct ieee80211_supported_band *sband;
3759 const u8 *ssidie, *ht_ie; 3795 const u8 *ssidie, *ht_ie, *vht_ie;
3760 int i, err; 3796 int i, err;
3761 3797
3762 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); 3798 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
@@ -3875,6 +3911,12 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3875 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; 3911 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
3876 else 3912 else
3877 ifmgd->flags |= IEEE80211_STA_DISABLE_HT; 3913 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3914 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
3915 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
3916 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
3917 sizeof(struct ieee80211_vht_cap));
3918 else
3919 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3878 rcu_read_unlock(); 3920 rcu_read_unlock();
3879 3921
3880 if (bss->wmm_used && bss->uapsd_supported && 3922 if (bss->wmm_used && bss->uapsd_supported &&
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index a5379aea7d09..82baf5b6ecf4 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -102,8 +102,7 @@ static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
102 ieee80211_sta_reset_conn_monitor(sdata); 102 ieee80211_sta_reset_conn_monitor(sdata);
103} 103}
104 104
105void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local, 105void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local)
106 bool offchannel_ps_enable)
107{ 106{
108 struct ieee80211_sub_if_data *sdata; 107 struct ieee80211_sub_if_data *sdata;
109 108
@@ -126,16 +125,17 @@ void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
126 set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state); 125 set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
127 126
128 /* Check to see if we should disable beaconing. */ 127 /* Check to see if we should disable beaconing. */
129 if (sdata->vif.type == NL80211_IFTYPE_AP || 128 if (sdata->vif.bss_conf.enable_beacon) {
130 sdata->vif.type == NL80211_IFTYPE_ADHOC || 129 set_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED,
131 sdata->vif.type == NL80211_IFTYPE_MESH_POINT) 130 &sdata->state);
131 sdata->vif.bss_conf.enable_beacon = false;
132 ieee80211_bss_info_change_notify( 132 ieee80211_bss_info_change_notify(
133 sdata, BSS_CHANGED_BEACON_ENABLED); 133 sdata, BSS_CHANGED_BEACON_ENABLED);
134 }
134 135
135 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { 136 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
136 netif_tx_stop_all_queues(sdata->dev); 137 netif_tx_stop_all_queues(sdata->dev);
137 if (offchannel_ps_enable && 138 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
138 (sdata->vif.type == NL80211_IFTYPE_STATION) &&
139 sdata->u.mgd.associated) 139 sdata->u.mgd.associated)
140 ieee80211_offchannel_ps_enable(sdata); 140 ieee80211_offchannel_ps_enable(sdata);
141 } 141 }
@@ -143,8 +143,7 @@ void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
143 mutex_unlock(&local->iflist_mtx); 143 mutex_unlock(&local->iflist_mtx);
144} 144}
145 145
146void ieee80211_offchannel_return(struct ieee80211_local *local, 146void ieee80211_offchannel_return(struct ieee80211_local *local)
147 bool offchannel_ps_disable)
148{ 147{
149 struct ieee80211_sub_if_data *sdata; 148 struct ieee80211_sub_if_data *sdata;
150 149
@@ -163,11 +162,9 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
163 continue; 162 continue;
164 163
165 /* Tell AP we're back */ 164 /* Tell AP we're back */
166 if (offchannel_ps_disable && 165 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
167 sdata->vif.type == NL80211_IFTYPE_STATION) { 166 sdata->u.mgd.associated)
168 if (sdata->u.mgd.associated) 167 ieee80211_offchannel_ps_disable(sdata);
169 ieee80211_offchannel_ps_disable(sdata);
170 }
171 168
172 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { 169 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
173 /* 170 /*
@@ -183,11 +180,12 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
183 netif_tx_wake_all_queues(sdata->dev); 180 netif_tx_wake_all_queues(sdata->dev);
184 } 181 }
185 182
186 if (sdata->vif.type == NL80211_IFTYPE_AP || 183 if (test_and_clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED,
187 sdata->vif.type == NL80211_IFTYPE_ADHOC || 184 &sdata->state)) {
188 sdata->vif.type == NL80211_IFTYPE_MESH_POINT) 185 sdata->vif.bss_conf.enable_beacon = true;
189 ieee80211_bss_info_change_notify( 186 ieee80211_bss_info_change_notify(
190 sdata, BSS_CHANGED_BEACON_ENABLED); 187 sdata, BSS_CHANGED_BEACON_ENABLED);
188 }
191 } 189 }
192 mutex_unlock(&local->iflist_mtx); 190 mutex_unlock(&local->iflist_mtx);
193} 191}
@@ -385,7 +383,7 @@ void ieee80211_sw_roc_work(struct work_struct *work)
385 local->tmp_channel = NULL; 383 local->tmp_channel = NULL;
386 ieee80211_hw_config(local, 0); 384 ieee80211_hw_config(local, 0);
387 385
388 ieee80211_offchannel_return(local, true); 386 ieee80211_offchannel_return(local);
389 } 387 }
390 388
391 ieee80211_recalc_idle(local); 389 ieee80211_recalc_idle(local);
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index 79a48f37d409..e45b83610e85 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -7,25 +7,23 @@
7#include "led.h" 7#include "led.h"
8 8
9/* return value indicates whether the driver should be further notified */ 9/* return value indicates whether the driver should be further notified */
10static bool ieee80211_quiesce(struct ieee80211_sub_if_data *sdata) 10static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata)
11{ 11{
12 switch (sdata->vif.type) { 12 switch (sdata->vif.type) {
13 case NL80211_IFTYPE_STATION: 13 case NL80211_IFTYPE_STATION:
14 ieee80211_sta_quiesce(sdata); 14 ieee80211_sta_quiesce(sdata);
15 return true; 15 break;
16 case NL80211_IFTYPE_ADHOC: 16 case NL80211_IFTYPE_ADHOC:
17 ieee80211_ibss_quiesce(sdata); 17 ieee80211_ibss_quiesce(sdata);
18 return true; 18 break;
19 case NL80211_IFTYPE_MESH_POINT: 19 case NL80211_IFTYPE_MESH_POINT:
20 ieee80211_mesh_quiesce(sdata); 20 ieee80211_mesh_quiesce(sdata);
21 return true; 21 break;
22 case NL80211_IFTYPE_AP_VLAN:
23 case NL80211_IFTYPE_MONITOR:
24 /* don't tell driver about this */
25 return false;
26 default: 22 default:
27 return true; 23 break;
28 } 24 }
25
26 cancel_work_sync(&sdata->work);
29} 27}
30 28
31int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) 29int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
@@ -44,7 +42,8 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
44 mutex_lock(&local->sta_mtx); 42 mutex_lock(&local->sta_mtx);
45 list_for_each_entry(sta, &local->sta_list, list) { 43 list_for_each_entry(sta, &local->sta_list, list) {
46 set_sta_flag(sta, WLAN_STA_BLOCK_BA); 44 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
47 ieee80211_sta_tear_down_BA_sessions(sta, true); 45 ieee80211_sta_tear_down_BA_sessions(
46 sta, AGG_STOP_LOCAL_REQUEST);
48 } 47 }
49 mutex_unlock(&local->sta_mtx); 48 mutex_unlock(&local->sta_mtx);
50 } 49 }
@@ -94,10 +93,9 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94 WARN_ON(err != 1); 93 WARN_ON(err != 1);
95 local->wowlan = false; 94 local->wowlan = false;
96 } else { 95 } else {
97 list_for_each_entry(sdata, &local->interfaces, list) { 96 list_for_each_entry(sdata, &local->interfaces, list)
98 cancel_work_sync(&sdata->work); 97 if (ieee80211_sdata_running(sdata))
99 ieee80211_quiesce(sdata); 98 ieee80211_quiesce(sdata);
100 }
101 goto suspend; 99 goto suspend;
102 } 100 }
103 } 101 }
@@ -124,17 +122,43 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
124 122
125 /* remove all interfaces */ 123 /* remove all interfaces */
126 list_for_each_entry(sdata, &local->interfaces, list) { 124 list_for_each_entry(sdata, &local->interfaces, list) {
127 cancel_work_sync(&sdata->work); 125 static u8 zero_addr[ETH_ALEN] = {};
126 u32 changed = 0;
128 127
129 if (!ieee80211_quiesce(sdata)) 128 if (!ieee80211_sdata_running(sdata))
130 continue; 129 continue;
131 130
132 if (!ieee80211_sdata_running(sdata)) 131 switch (sdata->vif.type) {
132 case NL80211_IFTYPE_AP_VLAN:
133 case NL80211_IFTYPE_MONITOR:
134 /* skip these */
133 continue; 135 continue;
136 case NL80211_IFTYPE_STATION:
137 if (sdata->vif.bss_conf.assoc)
138 changed = BSS_CHANGED_ASSOC |
139 BSS_CHANGED_BSSID |
140 BSS_CHANGED_IDLE;
141 break;
142 case NL80211_IFTYPE_AP:
143 case NL80211_IFTYPE_ADHOC:
144 case NL80211_IFTYPE_MESH_POINT:
145 if (sdata->vif.bss_conf.enable_beacon)
146 changed = BSS_CHANGED_BEACON_ENABLED;
147 break;
148 default:
149 break;
150 }
151
152 ieee80211_quiesce(sdata);
153
154 sdata->suspend_bss_conf = sdata->vif.bss_conf;
155 memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
156 sdata->vif.bss_conf.idle = true;
157 if (sdata->suspend_bss_conf.bssid)
158 sdata->vif.bss_conf.bssid = zero_addr;
134 159
135 /* disable beaconing */ 160 /* disable beaconing or remove association */
136 ieee80211_bss_info_change_notify(sdata, 161 ieee80211_bss_info_change_notify(sdata, changed);
137 BSS_CHANGED_BEACON_ENABLED);
138 162
139 if (sdata->vif.type == NL80211_IFTYPE_AP && 163 if (sdata->vif.type == NL80211_IFTYPE_AP &&
140 rcu_access_pointer(sdata->u.ap.beacon)) 164 rcu_access_pointer(sdata->u.ap.beacon))
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 580704eba8b8..a19089565c4b 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2353,7 +2353,7 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2353 sdata->vif.type != NL80211_IFTYPE_ADHOC) 2353 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2354 break; 2354 break;
2355 2355
2356 /* verify action & smps_control are present */ 2356 /* verify action & smps_control/chanwidth are present */
2357 if (len < IEEE80211_MIN_ACTION_SIZE + 2) 2357 if (len < IEEE80211_MIN_ACTION_SIZE + 2)
2358 goto invalid; 2358 goto invalid;
2359 2359
@@ -2392,6 +2392,35 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2392 IEEE80211_RC_SMPS_CHANGED); 2392 IEEE80211_RC_SMPS_CHANGED);
2393 goto handled; 2393 goto handled;
2394 } 2394 }
2395 case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
2396 struct ieee80211_supported_band *sband;
2397 u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
2398 bool old_40mhz, new_40mhz;
2399
2400 /* If it doesn't support 40 MHz it can't change ... */
2401 if (!rx->sta->supports_40mhz)
2402 goto handled;
2403
2404 old_40mhz = rx->sta->sta.ht_cap.cap &
2405 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2406 new_40mhz = chanwidth == IEEE80211_HT_CHANWIDTH_ANY;
2407
2408 if (old_40mhz == new_40mhz)
2409 goto handled;
2410
2411 if (new_40mhz)
2412 rx->sta->sta.ht_cap.cap |=
2413 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2414 else
2415 rx->sta->sta.ht_cap.cap &=
2416 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2417
2418 sband = rx->local->hw.wiphy->bands[status->band];
2419
2420 rate_control_rate_update(local, sband, rx->sta,
2421 IEEE80211_RC_BW_CHANGED);
2422 goto handled;
2423 }
2395 default: 2424 default:
2396 goto invalid; 2425 goto invalid;
2397 } 2426 }
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index d59fc6818b1c..607684c47d55 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -65,12 +65,11 @@ static bool is_uapsd_supported(struct ieee802_11_elems *elems)
65struct ieee80211_bss * 65struct ieee80211_bss *
66ieee80211_bss_info_update(struct ieee80211_local *local, 66ieee80211_bss_info_update(struct ieee80211_local *local,
67 struct ieee80211_rx_status *rx_status, 67 struct ieee80211_rx_status *rx_status,
68 struct ieee80211_mgmt *mgmt, 68 struct ieee80211_mgmt *mgmt, size_t len,
69 size_t len,
70 struct ieee802_11_elems *elems, 69 struct ieee802_11_elems *elems,
71 struct ieee80211_channel *channel, 70 struct ieee80211_channel *channel)
72 bool beacon)
73{ 71{
72 bool beacon = ieee80211_is_beacon(mgmt->frame_control);
74 struct cfg80211_bss *cbss; 73 struct cfg80211_bss *cbss;
75 struct ieee80211_bss *bss; 74 struct ieee80211_bss *bss;
76 int clen, srlen; 75 int clen, srlen;
@@ -203,7 +202,7 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
203 202
204 bss = ieee80211_bss_info_update(local, rx_status, 203 bss = ieee80211_bss_info_update(local, rx_status,
205 mgmt, skb->len, &elems, 204 mgmt, skb->len, &elems,
206 channel, beacon); 205 channel);
207 if (bss) 206 if (bss)
208 ieee80211_rx_bss_put(local, bss); 207 ieee80211_rx_bss_put(local, bss);
209} 208}
@@ -292,7 +291,7 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
292 if (!was_hw_scan) { 291 if (!was_hw_scan) {
293 ieee80211_configure_filter(local); 292 ieee80211_configure_filter(local);
294 drv_sw_scan_complete(local); 293 drv_sw_scan_complete(local);
295 ieee80211_offchannel_return(local, true); 294 ieee80211_offchannel_return(local);
296 } 295 }
297 296
298 ieee80211_recalc_idle(local); 297 ieee80211_recalc_idle(local);
@@ -341,7 +340,7 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
341 local->next_scan_state = SCAN_DECISION; 340 local->next_scan_state = SCAN_DECISION;
342 local->scan_channel_idx = 0; 341 local->scan_channel_idx = 0;
343 342
344 ieee80211_offchannel_stop_vifs(local, true); 343 ieee80211_offchannel_stop_vifs(local);
345 344
346 ieee80211_configure_filter(local); 345 ieee80211_configure_filter(local);
347 346
@@ -678,12 +677,8 @@ static void ieee80211_scan_state_suspend(struct ieee80211_local *local,
678 local->scan_channel = NULL; 677 local->scan_channel = NULL;
679 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 678 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
680 679
681 /* 680 /* disable PS */
682 * Re-enable vifs and beaconing. Leave PS 681 ieee80211_offchannel_return(local);
683 * in off-channel state..will put that back
684 * on-channel at the end of scanning.
685 */
686 ieee80211_offchannel_return(local, false);
687 682
688 *next_delay = HZ / 5; 683 *next_delay = HZ / 5;
689 /* afterwards, resume scan & go to next channel */ 684 /* afterwards, resume scan & go to next channel */
@@ -693,8 +688,7 @@ static void ieee80211_scan_state_suspend(struct ieee80211_local *local,
693static void ieee80211_scan_state_resume(struct ieee80211_local *local, 688static void ieee80211_scan_state_resume(struct ieee80211_local *local,
694 unsigned long *next_delay) 689 unsigned long *next_delay)
695{ 690{
696 /* PS already is in off-channel mode */ 691 ieee80211_offchannel_stop_vifs(local);
697 ieee80211_offchannel_stop_vifs(local, false);
698 692
699 if (local->ops->flush) { 693 if (local->ops->flush) {
700 drv_flush(local, false); 694 drv_flush(local, false);
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index ca9fde198188..9d864ed5f3da 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -104,6 +104,16 @@ static void cleanup_single_sta(struct sta_info *sta)
104 * neither mac80211 nor the driver can reference this 104 * neither mac80211 nor the driver can reference this
105 * sta struct any more except by still existing timers 105 * sta struct any more except by still existing timers
106 * associated with this station that we clean up below. 106 * associated with this station that we clean up below.
107 *
108 * Note though that this still uses the sdata and even
109 * calls the driver in AP and mesh mode, so interfaces
110 * of those types mush use call sta_info_flush_cleanup()
111 * (typically via sta_info_flush()) before deconfiguring
112 * the driver.
113 *
114 * In station mode, nothing happens here so it doesn't
115 * have to (and doesn't) do that, this is intentional to
116 * speed up roaming.
107 */ 117 */
108 118
109 if (test_sta_flag(sta, WLAN_STA_PS_STA)) { 119 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
@@ -774,7 +784,7 @@ int __must_check __sta_info_destroy(struct sta_info *sta)
774 * will be sufficient. 784 * will be sufficient.
775 */ 785 */
776 set_sta_flag(sta, WLAN_STA_BLOCK_BA); 786 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
777 ieee80211_sta_tear_down_BA_sessions(sta, false); 787 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
778 788
779 ret = sta_info_hash_del(local, sta); 789 ret = sta_info_hash_del(local, sta);
780 if (ret) 790 if (ret)
@@ -885,20 +895,12 @@ void sta_info_init(struct ieee80211_local *local)
885void sta_info_stop(struct ieee80211_local *local) 895void sta_info_stop(struct ieee80211_local *local)
886{ 896{
887 del_timer_sync(&local->sta_cleanup); 897 del_timer_sync(&local->sta_cleanup);
888 sta_info_flush(local, NULL);
889} 898}
890 899
891/** 900
892 * sta_info_flush - flush matching STA entries from the STA table 901int sta_info_flush_defer(struct ieee80211_sub_if_data *sdata)
893 *
894 * Returns the number of removed STA entries.
895 *
896 * @local: local interface data
897 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
898 */
899int sta_info_flush(struct ieee80211_local *local,
900 struct ieee80211_sub_if_data *sdata)
901{ 902{
903 struct ieee80211_local *local = sdata->local;
902 struct sta_info *sta, *tmp; 904 struct sta_info *sta, *tmp;
903 int ret = 0; 905 int ret = 0;
904 906
@@ -906,30 +908,22 @@ int sta_info_flush(struct ieee80211_local *local,
906 908
907 mutex_lock(&local->sta_mtx); 909 mutex_lock(&local->sta_mtx);
908 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 910 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
909 if (!sdata || sdata == sta->sdata) { 911 if (sdata == sta->sdata) {
910 WARN_ON(__sta_info_destroy(sta)); 912 WARN_ON(__sta_info_destroy(sta));
911 ret++; 913 ret++;
912 } 914 }
913 } 915 }
914 mutex_unlock(&local->sta_mtx); 916 mutex_unlock(&local->sta_mtx);
915 917
916 rcu_barrier();
917
918 if (sdata) {
919 ieee80211_cleanup_sdata_stas(sdata);
920 cancel_work_sync(&sdata->cleanup_stations_wk);
921 } else {
922 mutex_lock(&local->iflist_mtx);
923 list_for_each_entry(sdata, &local->interfaces, list) {
924 ieee80211_cleanup_sdata_stas(sdata);
925 cancel_work_sync(&sdata->cleanup_stations_wk);
926 }
927 mutex_unlock(&local->iflist_mtx);
928 }
929
930 return ret; 918 return ret;
931} 919}
932 920
921void sta_info_flush_cleanup(struct ieee80211_sub_if_data *sdata)
922{
923 ieee80211_cleanup_sdata_stas(sdata);
924 cancel_work_sync(&sdata->cleanup_stations_wk);
925}
926
933void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 927void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
934 unsigned long exp_time) 928 unsigned long exp_time)
935{ 929{
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 37c1889afd3a..af7d78aa5523 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -92,6 +92,13 @@ enum ieee80211_sta_info_flags {
92#define HT_AGG_STATE_WANT_START 4 92#define HT_AGG_STATE_WANT_START 4
93#define HT_AGG_STATE_WANT_STOP 5 93#define HT_AGG_STATE_WANT_STOP 5
94 94
95enum ieee80211_agg_stop_reason {
96 AGG_STOP_DECLINED,
97 AGG_STOP_LOCAL_REQUEST,
98 AGG_STOP_PEER_REQUEST,
99 AGG_STOP_DESTROY_STA,
100};
101
95/** 102/**
96 * struct tid_ampdu_tx - TID aggregation information (Tx). 103 * struct tid_ampdu_tx - TID aggregation information (Tx).
97 * 104 *
@@ -548,8 +555,39 @@ void sta_info_recalc_tim(struct sta_info *sta);
548 555
549void sta_info_init(struct ieee80211_local *local); 556void sta_info_init(struct ieee80211_local *local);
550void sta_info_stop(struct ieee80211_local *local); 557void sta_info_stop(struct ieee80211_local *local);
551int sta_info_flush(struct ieee80211_local *local, 558int sta_info_flush_defer(struct ieee80211_sub_if_data *sdata);
552 struct ieee80211_sub_if_data *sdata); 559
560/**
561 * sta_info_flush_cleanup - flush the sta_info cleanup queue
562 * @sdata: the interface
563 *
564 * Flushes the sta_info cleanup queue for a given interface;
565 * this is necessary before the interface is removed or, for
566 * AP/mesh interfaces, before it is deconfigured.
567 *
568 * Note an rcu_barrier() must precede the function, after all
569 * stations have been flushed/removed to ensure the call_rcu()
570 * calls that add stations to the cleanup queue have completed.
571 */
572void sta_info_flush_cleanup(struct ieee80211_sub_if_data *sdata);
573
574/**
575 * sta_info_flush - flush matching STA entries from the STA table
576 *
577 * Returns the number of removed STA entries.
578 *
579 * @sdata: sdata to remove all stations from
580 */
581static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata)
582{
583 int ret = sta_info_flush_defer(sdata);
584
585 rcu_barrier();
586 sta_info_flush_cleanup(sdata);
587
588 return ret;
589}
590
553void sta_set_rate_info_tx(struct sta_info *sta, 591void sta_set_rate_info_tx(struct sta_info *sta,
554 const struct ieee80211_tx_rate *rate, 592 const struct ieee80211_tx_rate *rate,
555 struct rate_info *rinfo); 593 struct rate_info *rinfo);
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index a8270b441a6f..41861b91daa3 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -28,21 +28,27 @@
28#define VIF_PR_FMT " vif:%s(%d%s)" 28#define VIF_PR_FMT " vif:%s(%d%s)"
29#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type, __entry->p2p ? "/p2p" : "" 29#define VIF_PR_ARG __get_str(vif_name), __entry->vif_type, __entry->p2p ? "/p2p" : ""
30 30
31#define CHANCTX_ENTRY __field(u32, control_freq) \ 31#define CHANDEF_ENTRY __field(u32, control_freq) \
32 __field(u32, chan_width) \ 32 __field(u32, chan_width) \
33 __field(u32, center_freq1) \ 33 __field(u32, center_freq1) \
34 __field(u32, center_freq2) \ 34 __field(u32, center_freq2)
35#define CHANDEF_ASSIGN(c) \
36 __entry->control_freq = (c)->chan->center_freq; \
37 __entry->chan_width = (c)->width; \
38 __entry->center_freq1 = (c)->center_freq1; \
39 __entry->center_freq1 = (c)->center_freq2;
40#define CHANDEF_PR_FMT " control:%d MHz width:%d center: %d/%d MHz"
41#define CHANDEF_PR_ARG __entry->control_freq, __entry->chan_width, \
42 __entry->center_freq1, __entry->center_freq2
43
44#define CHANCTX_ENTRY CHANDEF_ENTRY \
35 __field(u8, rx_chains_static) \ 45 __field(u8, rx_chains_static) \
36 __field(u8, rx_chains_dynamic) 46 __field(u8, rx_chains_dynamic)
37#define CHANCTX_ASSIGN __entry->control_freq = ctx->conf.def.chan->center_freq;\ 47#define CHANCTX_ASSIGN CHANDEF_ASSIGN(&ctx->conf.def) \
38 __entry->chan_width = ctx->conf.def.width; \
39 __entry->center_freq1 = ctx->conf.def.center_freq1; \
40 __entry->center_freq2 = ctx->conf.def.center_freq2; \
41 __entry->rx_chains_static = ctx->conf.rx_chains_static; \ 48 __entry->rx_chains_static = ctx->conf.rx_chains_static; \
42 __entry->rx_chains_dynamic = ctx->conf.rx_chains_dynamic 49 __entry->rx_chains_dynamic = ctx->conf.rx_chains_dynamic
43#define CHANCTX_PR_FMT " control:%d MHz width:%d center: %d/%d MHz chains:%d/%d" 50#define CHANCTX_PR_FMT CHANDEF_PR_FMT " chains:%d/%d"
44#define CHANCTX_PR_ARG __entry->control_freq, __entry->chan_width, \ 51#define CHANCTX_PR_ARG CHANDEF_PR_ARG, \
45 __entry->center_freq1, __entry->center_freq2, \
46 __entry->rx_chains_static, __entry->rx_chains_dynamic 52 __entry->rx_chains_static, __entry->rx_chains_dynamic
47 53
48 54
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index e9eadc40c09c..f32d68186dbc 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1673,10 +1673,13 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1673 chanctx_conf = 1673 chanctx_conf =
1674 rcu_dereference(tmp_sdata->vif.chanctx_conf); 1674 rcu_dereference(tmp_sdata->vif.chanctx_conf);
1675 } 1675 }
1676 if (!chanctx_conf)
1677 goto fail_rcu;
1678 1676
1679 chan = chanctx_conf->def.chan; 1677 if (chanctx_conf)
1678 chan = chanctx_conf->def.chan;
1679 else if (!local->use_chanctx)
1680 chan = local->_oper_channel;
1681 else
1682 goto fail_rcu;
1680 1683
1681 /* 1684 /*
1682 * Frame injection is not allowed if beaconing is not allowed 1685 * Frame injection is not allowed if beaconing is not allowed
@@ -2261,9 +2264,8 @@ void ieee80211_tx_pending(unsigned long data)
2261 2264
2262/* functions for drivers to get certain frames */ 2265/* functions for drivers to get certain frames */
2263 2266
2264static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, 2267static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2265 struct ps_data *ps, 2268 struct ps_data *ps, struct sk_buff *skb)
2266 struct sk_buff *skb)
2267{ 2269{
2268 u8 *pos, *tim; 2270 u8 *pos, *tim;
2269 int aid0 = 0; 2271 int aid0 = 0;
@@ -2325,6 +2327,31 @@ static void ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2325 } 2327 }
2326} 2328}
2327 2329
2330static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
2331 struct ps_data *ps, struct sk_buff *skb)
2332{
2333 struct ieee80211_local *local = sdata->local;
2334
2335 /*
2336 * Not very nice, but we want to allow the driver to call
2337 * ieee80211_beacon_get() as a response to the set_tim()
2338 * callback. That, however, is already invoked under the
2339 * sta_lock to guarantee consistent and race-free update
2340 * of the tim bitmap in mac80211 and the driver.
2341 */
2342 if (local->tim_in_locked_section) {
2343 __ieee80211_beacon_add_tim(sdata, ps, skb);
2344 } else {
2345 unsigned long flags;
2346
2347 spin_lock_irqsave(&local->tim_lock, flags);
2348 __ieee80211_beacon_add_tim(sdata, ps, skb);
2349 spin_unlock_irqrestore(&local->tim_lock, flags);
2350 }
2351
2352 return 0;
2353}
2354
2328struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw, 2355struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2329 struct ieee80211_vif *vif, 2356 struct ieee80211_vif *vif,
2330 u16 *tim_offset, u16 *tim_length) 2357 u16 *tim_offset, u16 *tim_length)
@@ -2369,22 +2396,7 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2369 memcpy(skb_put(skb, beacon->head_len), beacon->head, 2396 memcpy(skb_put(skb, beacon->head_len), beacon->head,
2370 beacon->head_len); 2397 beacon->head_len);
2371 2398
2372 /* 2399 ieee80211_beacon_add_tim(sdata, &ap->ps, skb);
2373 * Not very nice, but we want to allow the driver to call
2374 * ieee80211_beacon_get() as a response to the set_tim()
2375 * callback. That, however, is already invoked under the
2376 * sta_lock to guarantee consistent and race-free update
2377 * of the tim bitmap in mac80211 and the driver.
2378 */
2379 if (local->tim_in_locked_section) {
2380 ieee80211_beacon_add_tim(sdata, &ap->ps, skb);
2381 } else {
2382 unsigned long flags;
2383
2384 spin_lock_irqsave(&local->tim_lock, flags);
2385 ieee80211_beacon_add_tim(sdata, &ap->ps, skb);
2386 spin_unlock_irqrestore(&local->tim_lock, flags);
2387 }
2388 2400
2389 if (tim_offset) 2401 if (tim_offset)
2390 *tim_offset = beacon->head_len; 2402 *tim_offset = beacon->head_len;
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index f11e8c540db4..7519018ff71a 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1358,6 +1358,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1358 struct ieee80211_chanctx *ctx; 1358 struct ieee80211_chanctx *ctx;
1359 struct sta_info *sta; 1359 struct sta_info *sta;
1360 int res, i; 1360 int res, i;
1361 bool reconfig_due_to_wowlan = false;
1361 1362
1362#ifdef CONFIG_PM 1363#ifdef CONFIG_PM
1363 if (local->suspended) 1364 if (local->suspended)
@@ -1377,6 +1378,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1377 * res is 1, which means the driver requested 1378 * res is 1, which means the driver requested
1378 * to go through a regular reset on wakeup. 1379 * to go through a regular reset on wakeup.
1379 */ 1380 */
1381 reconfig_due_to_wowlan = true;
1380 } 1382 }
1381#endif 1383#endif
1382 /* everything else happens only if HW was up & running */ 1384 /* everything else happens only if HW was up & running */
@@ -1526,6 +1528,11 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1526 BSS_CHANGED_IDLE | 1528 BSS_CHANGED_IDLE |
1527 BSS_CHANGED_TXPOWER; 1529 BSS_CHANGED_TXPOWER;
1528 1530
1531#ifdef CONFIG_PM
1532 if (local->resuming && !reconfig_due_to_wowlan)
1533 sdata->vif.bss_conf = sdata->suspend_bss_conf;
1534#endif
1535
1529 switch (sdata->vif.type) { 1536 switch (sdata->vif.type) {
1530 case NL80211_IFTYPE_STATION: 1537 case NL80211_IFTYPE_STATION:
1531 changed |= BSS_CHANGED_ASSOC | 1538 changed |= BSS_CHANGED_ASSOC |
@@ -1550,9 +1557,11 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1550 1557
1551 /* fall through */ 1558 /* fall through */
1552 case NL80211_IFTYPE_MESH_POINT: 1559 case NL80211_IFTYPE_MESH_POINT:
1553 changed |= BSS_CHANGED_BEACON | 1560 if (sdata->vif.bss_conf.enable_beacon) {
1554 BSS_CHANGED_BEACON_ENABLED; 1561 changed |= BSS_CHANGED_BEACON |
1555 ieee80211_bss_info_change_notify(sdata, changed); 1562 BSS_CHANGED_BEACON_ENABLED;
1563 ieee80211_bss_info_change_notify(sdata, changed);
1564 }
1556 break; 1565 break;
1557 case NL80211_IFTYPE_WDS: 1566 case NL80211_IFTYPE_WDS:
1558 break; 1567 break;
@@ -1632,7 +1641,8 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1632 mutex_lock(&local->sta_mtx); 1641 mutex_lock(&local->sta_mtx);
1633 1642
1634 list_for_each_entry(sta, &local->sta_list, list) { 1643 list_for_each_entry(sta, &local->sta_list, list) {
1635 ieee80211_sta_tear_down_BA_sessions(sta, true); 1644 ieee80211_sta_tear_down_BA_sessions(
1645 sta, AGG_STOP_LOCAL_REQUEST);
1636 clear_sta_flag(sta, WLAN_STA_BLOCK_BA); 1646 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
1637 } 1647 }
1638 1648
@@ -1646,10 +1656,11 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1646 * If this is for hw restart things are still running. 1656 * If this is for hw restart things are still running.
1647 * We may want to change that later, however. 1657 * We may want to change that later, however.
1648 */ 1658 */
1649 if (!local->suspended) { 1659 if (!local->suspended || reconfig_due_to_wowlan)
1650 drv_restart_complete(local); 1660 drv_restart_complete(local);
1661
1662 if (!local->suspended)
1651 return 0; 1663 return 0;
1652 }
1653 1664
1654#ifdef CONFIG_PM 1665#ifdef CONFIG_PM
1655 /* first set suspended false, then resuming */ 1666 /* first set suspended false, then resuming */
@@ -1864,7 +1875,7 @@ u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
1864} 1875}
1865 1876
1866u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap, 1877u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
1867 u32 cap) 1878 u32 cap)
1868{ 1879{
1869 __le32 tmp; 1880 __le32 tmp;
1870 1881
diff --git a/net/nfc/core.c b/net/nfc/core.c
index aa64ea441676..25522e56d350 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -338,7 +338,7 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
338 dev->active_target = target; 338 dev->active_target = target;
339 dev->rf_mode = NFC_RF_INITIATOR; 339 dev->rf_mode = NFC_RF_INITIATOR;
340 340
341 if (dev->ops->check_presence) 341 if (dev->ops->check_presence && !dev->shutting_down)
342 mod_timer(&dev->check_pres_timer, jiffies + 342 mod_timer(&dev->check_pres_timer, jiffies +
343 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS)); 343 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
344 } 344 }
@@ -429,7 +429,7 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
429 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb, 429 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb,
430 cb_context); 430 cb_context);
431 431
432 if (!rc && dev->ops->check_presence) 432 if (!rc && dev->ops->check_presence && !dev->shutting_down)
433 mod_timer(&dev->check_pres_timer, jiffies + 433 mod_timer(&dev->check_pres_timer, jiffies +
434 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS)); 434 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
435 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) { 435 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) {
@@ -684,11 +684,6 @@ static void nfc_release(struct device *d)
684 684
685 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); 685 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
686 686
687 if (dev->ops->check_presence) {
688 del_timer_sync(&dev->check_pres_timer);
689 cancel_work_sync(&dev->check_pres_work);
690 }
691
692 nfc_genl_data_exit(&dev->genl_data); 687 nfc_genl_data_exit(&dev->genl_data);
693 kfree(dev->targets); 688 kfree(dev->targets);
694 kfree(dev); 689 kfree(dev);
@@ -706,15 +701,16 @@ static void nfc_check_pres_work(struct work_struct *work)
706 rc = dev->ops->check_presence(dev, dev->active_target); 701 rc = dev->ops->check_presence(dev, dev->active_target);
707 if (rc == -EOPNOTSUPP) 702 if (rc == -EOPNOTSUPP)
708 goto exit; 703 goto exit;
709 if (!rc) { 704 if (rc) {
710 mod_timer(&dev->check_pres_timer, jiffies +
711 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
712 } else {
713 u32 active_target_idx = dev->active_target->idx; 705 u32 active_target_idx = dev->active_target->idx;
714 device_unlock(&dev->dev); 706 device_unlock(&dev->dev);
715 nfc_target_lost(dev, active_target_idx); 707 nfc_target_lost(dev, active_target_idx);
716 return; 708 return;
717 } 709 }
710
711 if (!dev->shutting_down)
712 mod_timer(&dev->check_pres_timer, jiffies +
713 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
718 } 714 }
719 715
720exit: 716exit:
@@ -761,6 +757,7 @@ struct nfc_dev *nfc_get_device(unsigned int idx)
761 */ 757 */
762struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, 758struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
763 u32 supported_protocols, 759 u32 supported_protocols,
760 u32 supported_se,
764 int tx_headroom, int tx_tailroom) 761 int tx_headroom, int tx_tailroom)
765{ 762{
766 struct nfc_dev *dev; 763 struct nfc_dev *dev;
@@ -778,6 +775,8 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
778 775
779 dev->ops = ops; 776 dev->ops = ops;
780 dev->supported_protocols = supported_protocols; 777 dev->supported_protocols = supported_protocols;
778 dev->supported_se = supported_se;
779 dev->active_se = NFC_SE_NONE;
781 dev->tx_headroom = tx_headroom; 780 dev->tx_headroom = tx_headroom;
782 dev->tx_tailroom = tx_tailroom; 781 dev->tx_tailroom = tx_tailroom;
783 782
@@ -853,26 +852,27 @@ void nfc_unregister_device(struct nfc_dev *dev)
853 852
854 id = dev->idx; 853 id = dev->idx;
855 854
856 mutex_lock(&nfc_devlist_mutex); 855 if (dev->ops->check_presence) {
857 nfc_devlist_generation++; 856 device_lock(&dev->dev);
858 857 dev->shutting_down = true;
859 /* lock to avoid unregistering a device while an operation 858 device_unlock(&dev->dev);
860 is in progress */ 859 del_timer_sync(&dev->check_pres_timer);
861 device_lock(&dev->dev); 860 cancel_work_sync(&dev->check_pres_work);
862 device_del(&dev->dev); 861 }
863 device_unlock(&dev->dev);
864 862
865 mutex_unlock(&nfc_devlist_mutex); 863 rc = nfc_genl_device_removed(dev);
864 if (rc)
865 pr_debug("The userspace won't be notified that the device %s "
866 "was removed\n", dev_name(&dev->dev));
866 867
867 nfc_llcp_unregister_device(dev); 868 nfc_llcp_unregister_device(dev);
868 869
869 rc = nfc_genl_device_removed(dev); 870 mutex_lock(&nfc_devlist_mutex);
870 if (rc) 871 nfc_devlist_generation++;
871 pr_debug("The userspace won't be notified that the device %s was removed\n", 872 device_del(&dev->dev);
872 dev_name(&dev->dev)); 873 mutex_unlock(&nfc_devlist_mutex);
873 874
874 ida_simple_remove(&nfc_index_ida, id); 875 ida_simple_remove(&nfc_index_ida, id);
875
876} 876}
877EXPORT_SYMBOL(nfc_unregister_device); 877EXPORT_SYMBOL(nfc_unregister_device);
878 878
diff --git a/net/nfc/hci/command.c b/net/nfc/hci/command.c
index 7d99410e6c1a..64f922be9281 100644
--- a/net/nfc/hci/command.c
+++ b/net/nfc/hci/command.c
@@ -280,14 +280,19 @@ static int nfc_hci_delete_pipe(struct nfc_hci_dev *hdev, u8 pipe)
280static int nfc_hci_clear_all_pipes(struct nfc_hci_dev *hdev) 280static int nfc_hci_clear_all_pipes(struct nfc_hci_dev *hdev)
281{ 281{
282 u8 param[2]; 282 u8 param[2];
283 size_t param_len = 2;
283 284
284 /* TODO: Find out what the identity reference data is 285 /* TODO: Find out what the identity reference data is
285 * and fill param with it. HCI spec 6.1.3.5 */ 286 * and fill param with it. HCI spec 6.1.3.5 */
286 287
287 pr_debug("\n"); 288 pr_debug("\n");
288 289
290 if (test_bit(NFC_HCI_QUIRK_SHORT_CLEAR, &hdev->quirks))
291 param_len = 0;
292
289 return nfc_hci_execute_cmd(hdev, NFC_HCI_ADMIN_PIPE, 293 return nfc_hci_execute_cmd(hdev, NFC_HCI_ADMIN_PIPE,
290 NFC_HCI_ADM_CLEAR_ALL_PIPE, param, 2, NULL); 294 NFC_HCI_ADM_CLEAR_ALL_PIPE, param, param_len,
295 NULL);
291} 296}
292 297
293int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate) 298int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate)
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index 7bea574d5934..91020b210d87 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -57,6 +57,8 @@ static void nfc_hci_msg_tx_work(struct work_struct *work)
57 int r = 0; 57 int r = 0;
58 58
59 mutex_lock(&hdev->msg_tx_mutex); 59 mutex_lock(&hdev->msg_tx_mutex);
60 if (hdev->shutting_down)
61 goto exit;
60 62
61 if (hdev->cmd_pending_msg) { 63 if (hdev->cmd_pending_msg) {
62 if (timer_pending(&hdev->cmd_timer) == 0) { 64 if (timer_pending(&hdev->cmd_timer) == 0) {
@@ -295,6 +297,12 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
295 goto exit; 297 goto exit;
296 } 298 }
297 299
300 if (hdev->ops->event_received) {
301 r = hdev->ops->event_received(hdev, gate, event, skb);
302 if (r <= 0)
303 goto exit_noskb;
304 }
305
298 switch (event) { 306 switch (event) {
299 case NFC_HCI_EVT_TARGET_DISCOVERED: 307 case NFC_HCI_EVT_TARGET_DISCOVERED:
300 if (skb->len < 1) { /* no status data? */ 308 if (skb->len < 1) { /* no status data? */
@@ -320,17 +328,15 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
320 r = nfc_hci_target_discovered(hdev, gate); 328 r = nfc_hci_target_discovered(hdev, gate);
321 break; 329 break;
322 default: 330 default:
323 if (hdev->ops->event_received) { 331 pr_info("Discarded unknown event %x to gate %x\n", event, gate);
324 hdev->ops->event_received(hdev, gate, event, skb); 332 r = -EINVAL;
325 return;
326 }
327
328 break; 333 break;
329 } 334 }
330 335
331exit: 336exit:
332 kfree_skb(skb); 337 kfree_skb(skb);
333 338
339exit_noskb:
334 if (r) { 340 if (r) {
335 /* TODO: There was an error dispatching the event, 341 /* TODO: There was an error dispatching the event,
336 * how to propagate up to nfc core? 342 * how to propagate up to nfc core?
@@ -669,8 +675,10 @@ static int hci_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb)
669 675
670 if (hdev->ops->tm_send) 676 if (hdev->ops->tm_send)
671 return hdev->ops->tm_send(hdev, skb); 677 return hdev->ops->tm_send(hdev, skb);
672 else 678
673 return -ENOTSUPP; 679 kfree_skb(skb);
680
681 return -ENOTSUPP;
674} 682}
675 683
676static int hci_check_presence(struct nfc_dev *nfc_dev, 684static int hci_check_presence(struct nfc_dev *nfc_dev,
@@ -787,7 +795,9 @@ static struct nfc_ops hci_nfc_ops = {
787 795
788struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops, 796struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
789 struct nfc_hci_init_data *init_data, 797 struct nfc_hci_init_data *init_data,
798 unsigned long quirks,
790 u32 protocols, 799 u32 protocols,
800 u32 supported_se,
791 const char *llc_name, 801 const char *llc_name,
792 int tx_headroom, 802 int tx_headroom,
793 int tx_tailroom, 803 int tx_tailroom,
@@ -813,7 +823,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
813 return NULL; 823 return NULL;
814 } 824 }
815 825
816 hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, 826 hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols, supported_se,
817 tx_headroom + HCI_CMDS_HEADROOM, 827 tx_headroom + HCI_CMDS_HEADROOM,
818 tx_tailroom); 828 tx_tailroom);
819 if (!hdev->ndev) { 829 if (!hdev->ndev) {
@@ -830,6 +840,8 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
830 840
831 memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe)); 841 memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
832 842
843 hdev->quirks = quirks;
844
833 return hdev; 845 return hdev;
834} 846}
835EXPORT_SYMBOL(nfc_hci_allocate_device); 847EXPORT_SYMBOL(nfc_hci_allocate_device);
@@ -868,6 +880,28 @@ void nfc_hci_unregister_device(struct nfc_hci_dev *hdev)
868{ 880{
869 struct hci_msg *msg, *n; 881 struct hci_msg *msg, *n;
870 882
883 mutex_lock(&hdev->msg_tx_mutex);
884
885 if (hdev->cmd_pending_msg) {
886 if (hdev->cmd_pending_msg->cb)
887 hdev->cmd_pending_msg->cb(
888 hdev->cmd_pending_msg->cb_context,
889 NULL, -ESHUTDOWN);
890 kfree(hdev->cmd_pending_msg);
891 hdev->cmd_pending_msg = NULL;
892 }
893
894 hdev->shutting_down = true;
895
896 mutex_unlock(&hdev->msg_tx_mutex);
897
898 del_timer_sync(&hdev->cmd_timer);
899 cancel_work_sync(&hdev->msg_tx_work);
900
901 cancel_work_sync(&hdev->msg_rx_work);
902
903 nfc_unregister_device(hdev->ndev);
904
871 skb_queue_purge(&hdev->rx_hcp_frags); 905 skb_queue_purge(&hdev->rx_hcp_frags);
872 skb_queue_purge(&hdev->msg_rx_queue); 906 skb_queue_purge(&hdev->msg_rx_queue);
873 907
@@ -876,13 +910,6 @@ void nfc_hci_unregister_device(struct nfc_hci_dev *hdev)
876 skb_queue_purge(&msg->msg_frags); 910 skb_queue_purge(&msg->msg_frags);
877 kfree(msg); 911 kfree(msg);
878 } 912 }
879
880 del_timer_sync(&hdev->cmd_timer);
881
882 nfc_unregister_device(hdev->ndev);
883
884 cancel_work_sync(&hdev->msg_tx_work);
885 cancel_work_sync(&hdev->msg_rx_work);
886} 913}
887EXPORT_SYMBOL(nfc_hci_unregister_device); 914EXPORT_SYMBOL(nfc_hci_unregister_device);
888 915
diff --git a/net/nfc/hci/hcp.c b/net/nfc/hci/hcp.c
index bc308a7ca609..b6b4109f2343 100644
--- a/net/nfc/hci/hcp.c
+++ b/net/nfc/hci/hcp.c
@@ -105,6 +105,13 @@ int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
105 } 105 }
106 106
107 mutex_lock(&hdev->msg_tx_mutex); 107 mutex_lock(&hdev->msg_tx_mutex);
108
109 if (hdev->shutting_down) {
110 err = -ESHUTDOWN;
111 mutex_unlock(&hdev->msg_tx_mutex);
112 goto out_skb_err;
113 }
114
108 list_add_tail(&cmd->msg_l, &hdev->msg_tx_queue); 115 list_add_tail(&cmd->msg_l, &hdev->msg_tx_queue);
109 mutex_unlock(&hdev->msg_tx_mutex); 116 mutex_unlock(&hdev->msg_tx_mutex);
110 117
diff --git a/net/nfc/llcp/commands.c b/net/nfc/llcp/commands.c
index df24be48d4da..c6bc3bd95052 100644
--- a/net/nfc/llcp/commands.c
+++ b/net/nfc/llcp/commands.c
@@ -304,6 +304,8 @@ int nfc_llcp_send_symm(struct nfc_dev *dev)
304 304
305 skb = llcp_add_header(skb, 0, 0, LLCP_PDU_SYMM); 305 skb = llcp_add_header(skb, 0, 0, LLCP_PDU_SYMM);
306 306
307 __net_timestamp(skb);
308
307 nfc_llcp_send_to_raw_sock(local, skb, NFC_LLCP_DIRECTION_TX); 309 nfc_llcp_send_to_raw_sock(local, skb, NFC_LLCP_DIRECTION_TX);
308 310
309 return nfc_data_exchange(dev, local->target_idx, skb, 311 return nfc_data_exchange(dev, local->target_idx, skb,
diff --git a/net/nfc/llcp/llcp.c b/net/nfc/llcp/llcp.c
index ec43914c92a9..85bc75c38dea 100644
--- a/net/nfc/llcp/llcp.c
+++ b/net/nfc/llcp/llcp.c
@@ -54,7 +54,6 @@ static void nfc_llcp_socket_purge(struct nfc_llcp_sock *sock)
54 54
55 skb_queue_purge(&sock->tx_queue); 55 skb_queue_purge(&sock->tx_queue);
56 skb_queue_purge(&sock->tx_pending_queue); 56 skb_queue_purge(&sock->tx_pending_queue);
57 skb_queue_purge(&sock->tx_backlog_queue);
58 57
59 if (local == NULL) 58 if (local == NULL)
60 return; 59 return;
@@ -668,6 +667,8 @@ static void nfc_llcp_tx_work(struct work_struct *work)
668 if (ptype == LLCP_PDU_I) 667 if (ptype == LLCP_PDU_I)
669 copy_skb = skb_copy(skb, GFP_ATOMIC); 668 copy_skb = skb_copy(skb, GFP_ATOMIC);
670 669
670 __net_timestamp(skb);
671
671 nfc_llcp_send_to_raw_sock(local, skb, 672 nfc_llcp_send_to_raw_sock(local, skb,
672 NFC_LLCP_DIRECTION_TX); 673 NFC_LLCP_DIRECTION_TX);
673 674
@@ -781,9 +782,15 @@ static void nfc_llcp_recv_ui(struct nfc_llcp_local *local,
781 782
782 /* There is no sequence with UI frames */ 783 /* There is no sequence with UI frames */
783 skb_pull(skb, LLCP_HEADER_SIZE); 784 skb_pull(skb, LLCP_HEADER_SIZE);
784 if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) { 785 if (!sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
785 pr_err("receive queue is full\n"); 786 /*
786 skb_queue_head(&llcp_sock->tx_backlog_queue, skb); 787 * UI frames will be freed from the socket layer, so we
788 * need to keep them alive until someone receives them.
789 */
790 skb_get(skb);
791 } else {
792 pr_err("Receive queue is full\n");
793 kfree_skb(skb);
787 } 794 }
788 795
789 nfc_llcp_sock_put(llcp_sock); 796 nfc_llcp_sock_put(llcp_sock);
@@ -976,9 +983,15 @@ static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local,
976 pr_err("Received out of sequence I PDU\n"); 983 pr_err("Received out of sequence I PDU\n");
977 984
978 skb_pull(skb, LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE); 985 skb_pull(skb, LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE);
979 if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) { 986 if (!sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
980 pr_err("receive queue is full\n"); 987 /*
981 skb_queue_head(&llcp_sock->tx_backlog_queue, skb); 988 * I frames will be freed from the socket layer, so we
989 * need to keep them alive until someone receives them.
990 */
991 skb_get(skb);
992 } else {
993 pr_err("Receive queue is full\n");
994 kfree_skb(skb);
982 } 995 }
983 } 996 }
984 997
@@ -1245,6 +1258,8 @@ static void nfc_llcp_rx_work(struct work_struct *work)
1245 print_hex_dump(KERN_DEBUG, "LLCP Rx: ", DUMP_PREFIX_OFFSET, 1258 print_hex_dump(KERN_DEBUG, "LLCP Rx: ", DUMP_PREFIX_OFFSET,
1246 16, 1, skb->data, skb->len, true); 1259 16, 1, skb->data, skb->len, true);
1247 1260
1261 __net_timestamp(skb);
1262
1248 nfc_llcp_send_to_raw_sock(local, skb, NFC_LLCP_DIRECTION_RX); 1263 nfc_llcp_send_to_raw_sock(local, skb, NFC_LLCP_DIRECTION_RX);
1249 1264
1250 switch (ptype) { 1265 switch (ptype) {
@@ -1296,6 +1311,13 @@ static void nfc_llcp_rx_work(struct work_struct *work)
1296 local->rx_pending = NULL; 1311 local->rx_pending = NULL;
1297} 1312}
1298 1313
1314static void __nfc_llcp_recv(struct nfc_llcp_local *local, struct sk_buff *skb)
1315{
1316 local->rx_pending = skb;
1317 del_timer(&local->link_timer);
1318 schedule_work(&local->rx_work);
1319}
1320
1299void nfc_llcp_recv(void *data, struct sk_buff *skb, int err) 1321void nfc_llcp_recv(void *data, struct sk_buff *skb, int err)
1300{ 1322{
1301 struct nfc_llcp_local *local = (struct nfc_llcp_local *) data; 1323 struct nfc_llcp_local *local = (struct nfc_llcp_local *) data;
@@ -1306,9 +1328,7 @@ void nfc_llcp_recv(void *data, struct sk_buff *skb, int err)
1306 return; 1328 return;
1307 } 1329 }
1308 1330
1309 local->rx_pending = skb_get(skb); 1331 __nfc_llcp_recv(local, skb);
1310 del_timer(&local->link_timer);
1311 schedule_work(&local->rx_work);
1312} 1332}
1313 1333
1314int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb) 1334int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb)
@@ -1319,9 +1339,7 @@ int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb)
1319 if (local == NULL) 1339 if (local == NULL)
1320 return -ENODEV; 1340 return -ENODEV;
1321 1341
1322 local->rx_pending = skb_get(skb); 1342 __nfc_llcp_recv(local, skb);
1323 del_timer(&local->link_timer);
1324 schedule_work(&local->rx_work);
1325 1343
1326 return 0; 1344 return 0;
1327} 1345}
diff --git a/net/nfc/llcp/llcp.h b/net/nfc/llcp/llcp.h
index 0d62366f8cc3..0eae5c509504 100644
--- a/net/nfc/llcp/llcp.h
+++ b/net/nfc/llcp/llcp.h
@@ -121,7 +121,6 @@ struct nfc_llcp_sock {
121 121
122 struct sk_buff_head tx_queue; 122 struct sk_buff_head tx_queue;
123 struct sk_buff_head tx_pending_queue; 123 struct sk_buff_head tx_pending_queue;
124 struct sk_buff_head tx_backlog_queue;
125 124
126 struct list_head accept_queue; 125 struct list_head accept_queue;
127 struct sock *parent; 126 struct sock *parent;
diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
index fea22eb41b82..5332751943a9 100644
--- a/net/nfc/llcp/sock.c
+++ b/net/nfc/llcp/sock.c
@@ -672,25 +672,27 @@ static int llcp_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
672 copied = min_t(unsigned int, rlen, len); 672 copied = min_t(unsigned int, rlen, len);
673 673
674 cskb = skb; 674 cskb = skb;
675 if (memcpy_toiovec(msg->msg_iov, cskb->data, copied)) { 675 if (skb_copy_datagram_iovec(cskb, 0, msg->msg_iov, copied)) {
676 if (!(flags & MSG_PEEK)) 676 if (!(flags & MSG_PEEK))
677 skb_queue_head(&sk->sk_receive_queue, skb); 677 skb_queue_head(&sk->sk_receive_queue, skb);
678 return -EFAULT; 678 return -EFAULT;
679 } 679 }
680 680
681 sock_recv_timestamp(msg, sk, skb);
682
681 if (sk->sk_type == SOCK_DGRAM && msg->msg_name) { 683 if (sk->sk_type == SOCK_DGRAM && msg->msg_name) {
682 struct nfc_llcp_ui_cb *ui_cb = nfc_llcp_ui_skb_cb(skb); 684 struct nfc_llcp_ui_cb *ui_cb = nfc_llcp_ui_skb_cb(skb);
683 struct sockaddr_nfc_llcp sockaddr; 685 struct sockaddr_nfc_llcp *sockaddr =
686 (struct sockaddr_nfc_llcp *) msg->msg_name;
684 687
685 pr_debug("Datagram socket %d %d\n", ui_cb->dsap, ui_cb->ssap); 688 msg->msg_namelen = sizeof(struct sockaddr_nfc_llcp);
686 689
687 sockaddr.sa_family = AF_NFC; 690 pr_debug("Datagram socket %d %d\n", ui_cb->dsap, ui_cb->ssap);
688 sockaddr.nfc_protocol = NFC_PROTO_NFC_DEP;
689 sockaddr.dsap = ui_cb->dsap;
690 sockaddr.ssap = ui_cb->ssap;
691 691
692 memcpy(msg->msg_name, &sockaddr, sizeof(sockaddr)); 692 sockaddr->sa_family = AF_NFC;
693 msg->msg_namelen = sizeof(sockaddr); 693 sockaddr->nfc_protocol = NFC_PROTO_NFC_DEP;
694 sockaddr->dsap = ui_cb->dsap;
695 sockaddr->ssap = ui_cb->ssap;
694 } 696 }
695 697
696 /* Mark read part of skb as used */ 698 /* Mark read part of skb as used */
@@ -806,7 +808,6 @@ struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp)
806 llcp_sock->reserved_ssap = LLCP_SAP_MAX; 808 llcp_sock->reserved_ssap = LLCP_SAP_MAX;
807 skb_queue_head_init(&llcp_sock->tx_queue); 809 skb_queue_head_init(&llcp_sock->tx_queue);
808 skb_queue_head_init(&llcp_sock->tx_pending_queue); 810 skb_queue_head_init(&llcp_sock->tx_pending_queue);
809 skb_queue_head_init(&llcp_sock->tx_backlog_queue);
810 INIT_LIST_HEAD(&llcp_sock->accept_queue); 811 INIT_LIST_HEAD(&llcp_sock->accept_queue);
811 812
812 if (sock != NULL) 813 if (sock != NULL)
@@ -821,7 +822,6 @@ void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
821 822
822 skb_queue_purge(&sock->tx_queue); 823 skb_queue_purge(&sock->tx_queue);
823 skb_queue_purge(&sock->tx_pending_queue); 824 skb_queue_purge(&sock->tx_pending_queue);
824 skb_queue_purge(&sock->tx_backlog_queue);
825 825
826 list_del_init(&sock->accept_queue); 826 list_del_init(&sock->accept_queue);
827 827
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 5f98dc1bf039..48ada0ec749e 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -658,6 +658,7 @@ static struct nfc_ops nci_nfc_ops = {
658 */ 658 */
659struct nci_dev *nci_allocate_device(struct nci_ops *ops, 659struct nci_dev *nci_allocate_device(struct nci_ops *ops,
660 __u32 supported_protocols, 660 __u32 supported_protocols,
661 __u32 supported_se,
661 int tx_headroom, int tx_tailroom) 662 int tx_headroom, int tx_tailroom)
662{ 663{
663 struct nci_dev *ndev; 664 struct nci_dev *ndev;
@@ -680,6 +681,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
680 681
681 ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops, 682 ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops,
682 supported_protocols, 683 supported_protocols,
684 supported_se,
683 tx_headroom + NCI_DATA_HDR_SIZE, 685 tx_headroom + NCI_DATA_HDR_SIZE,
684 tx_tailroom); 686 tx_tailroom);
685 if (!ndev->nfc_dev) 687 if (!ndev->nfc_dev)
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 3568ae16786d..504b883439f1 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -366,6 +366,7 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
366 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || 366 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
367 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || 367 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
368 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) || 368 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
369 nla_put_u32(msg, NFC_ATTR_SE, dev->supported_se) ||
369 nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) || 370 nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) ||
370 nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode)) 371 nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode))
371 goto nla_put_failure; 372 goto nla_put_failure;
diff --git a/net/wireless/ap.c b/net/wireless/ap.c
index 324e8d851dc4..a4a14e8f55cc 100644
--- a/net/wireless/ap.c
+++ b/net/wireless/ap.c
@@ -46,3 +46,65 @@ int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
46 46
47 return err; 47 return err;
48} 48}
49
50void cfg80211_ch_switch_notify(struct net_device *dev,
51 struct cfg80211_chan_def *chandef)
52{
53 struct wireless_dev *wdev = dev->ieee80211_ptr;
54 struct wiphy *wiphy = wdev->wiphy;
55 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
56
57 trace_cfg80211_ch_switch_notify(dev, chandef);
58
59 wdev_lock(wdev);
60
61 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
62 wdev->iftype != NL80211_IFTYPE_P2P_GO))
63 goto out;
64
65 wdev->channel = chandef->chan;
66 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
67out:
68 wdev_unlock(wdev);
69 return;
70}
71EXPORT_SYMBOL(cfg80211_ch_switch_notify);
72
73bool cfg80211_rx_spurious_frame(struct net_device *dev,
74 const u8 *addr, gfp_t gfp)
75{
76 struct wireless_dev *wdev = dev->ieee80211_ptr;
77 bool ret;
78
79 trace_cfg80211_rx_spurious_frame(dev, addr);
80
81 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
82 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
83 trace_cfg80211_return_bool(false);
84 return false;
85 }
86 ret = nl80211_unexpected_frame(dev, addr, gfp);
87 trace_cfg80211_return_bool(ret);
88 return ret;
89}
90EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
91
92bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
93 const u8 *addr, gfp_t gfp)
94{
95 struct wireless_dev *wdev = dev->ieee80211_ptr;
96 bool ret;
97
98 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
99
100 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
101 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
102 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
103 trace_cfg80211_return_bool(false);
104 return false;
105 }
106 ret = nl80211_unexpected_4addr_frame(dev, addr, gfp);
107 trace_cfg80211_return_bool(ret);
108 return ret;
109}
110EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index a7990bb16529..396373f3ec26 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -76,6 +76,10 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
76 return false; 76 return false;
77 if (!chandef->center_freq2) 77 if (!chandef->center_freq2)
78 return false; 78 return false;
79 /* adjacent is not allowed -- that's a 160 MHz channel */
80 if (chandef->center_freq1 - chandef->center_freq2 == 80 ||
81 chandef->center_freq2 - chandef->center_freq1 == 80)
82 return false;
79 break; 83 break;
80 case NL80211_CHAN_WIDTH_80: 84 case NL80211_CHAN_WIDTH_80:
81 if (chandef->center_freq1 != control_freq + 30 && 85 if (chandef->center_freq1 != control_freq + 30 &&
diff --git a/net/wireless/core.c b/net/wireless/core.c
index b677eab55b68..9245729694d2 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -57,9 +57,6 @@ struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
57{ 57{
58 struct cfg80211_registered_device *result = NULL, *rdev; 58 struct cfg80211_registered_device *result = NULL, *rdev;
59 59
60 if (!wiphy_idx_valid(wiphy_idx))
61 return NULL;
62
63 assert_cfg80211_lock(); 60 assert_cfg80211_lock();
64 61
65 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 62 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
@@ -74,10 +71,8 @@ struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
74 71
75int get_wiphy_idx(struct wiphy *wiphy) 72int get_wiphy_idx(struct wiphy *wiphy)
76{ 73{
77 struct cfg80211_registered_device *rdev; 74 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
78 if (!wiphy) 75
79 return WIPHY_IDX_STALE;
80 rdev = wiphy_to_dev(wiphy);
81 return rdev->wiphy_idx; 76 return rdev->wiphy_idx;
82} 77}
83 78
@@ -86,9 +81,6 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
86{ 81{
87 struct cfg80211_registered_device *rdev; 82 struct cfg80211_registered_device *rdev;
88 83
89 if (!wiphy_idx_valid(wiphy_idx))
90 return NULL;
91
92 assert_cfg80211_lock(); 84 assert_cfg80211_lock();
93 85
94 rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx); 86 rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx);
@@ -309,7 +301,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
309 301
310 rdev->wiphy_idx = wiphy_counter++; 302 rdev->wiphy_idx = wiphy_counter++;
311 303
312 if (unlikely(!wiphy_idx_valid(rdev->wiphy_idx))) { 304 if (unlikely(rdev->wiphy_idx < 0)) {
313 wiphy_counter--; 305 wiphy_counter--;
314 mutex_unlock(&cfg80211_mutex); 306 mutex_unlock(&cfg80211_mutex);
315 /* ugh, wrapped! */ 307 /* ugh, wrapped! */
@@ -390,8 +382,11 @@ static int wiphy_verify_combinations(struct wiphy *wiphy)
390 382
391 c = &wiphy->iface_combinations[i]; 383 c = &wiphy->iface_combinations[i];
392 384
393 /* Combinations with just one interface aren't real */ 385 /*
394 if (WARN_ON(c->max_interfaces < 2)) 386 * Combinations with just one interface aren't real,
387 * however we make an exception for DFS.
388 */
389 if (WARN_ON((c->max_interfaces < 2) && !c->radar_detect_widths))
395 return -EINVAL; 390 return -EINVAL;
396 391
397 /* Need at least one channel */ 392 /* Need at least one channel */
@@ -406,6 +401,11 @@ static int wiphy_verify_combinations(struct wiphy *wiphy)
406 CFG80211_MAX_NUM_DIFFERENT_CHANNELS)) 401 CFG80211_MAX_NUM_DIFFERENT_CHANNELS))
407 return -EINVAL; 402 return -EINVAL;
408 403
404 /* DFS only works on one channel. */
405 if (WARN_ON(c->radar_detect_widths &&
406 (c->num_different_channels > 1)))
407 return -EINVAL;
408
409 if (WARN_ON(!c->n_limits)) 409 if (WARN_ON(!c->n_limits))
410 return -EINVAL; 410 return -EINVAL;
411 411
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 3563097169cb..8396f7671c8d 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -18,6 +18,9 @@
18#include <net/cfg80211.h> 18#include <net/cfg80211.h>
19#include "reg.h" 19#include "reg.h"
20 20
21
22#define WIPHY_IDX_INVALID -1
23
21struct cfg80211_registered_device { 24struct cfg80211_registered_device {
22 const struct cfg80211_ops *ops; 25 const struct cfg80211_ops *ops;
23 struct list_head list; 26 struct list_head list;
@@ -86,7 +89,7 @@ struct cfg80211_registered_device {
86 89
87 /* must be last because of the way we do wiphy_priv(), 90 /* must be last because of the way we do wiphy_priv(),
88 * and it should at least be aligned to NETDEV_ALIGN */ 91 * and it should at least be aligned to NETDEV_ALIGN */
89 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); 92 struct wiphy wiphy __aligned(NETDEV_ALIGN);
90}; 93};
91 94
92static inline 95static inline
@@ -96,13 +99,6 @@ struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
96 return container_of(wiphy, struct cfg80211_registered_device, wiphy); 99 return container_of(wiphy, struct cfg80211_registered_device, wiphy);
97} 100}
98 101
99/* Note 0 is valid, hence phy0 */
100static inline
101bool wiphy_idx_valid(int wiphy_idx)
102{
103 return wiphy_idx >= 0;
104}
105
106static inline void 102static inline void
107cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev) 103cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
108{ 104{
@@ -126,12 +122,6 @@ static inline void assert_cfg80211_lock(void)
126 lockdep_assert_held(&cfg80211_mutex); 122 lockdep_assert_held(&cfg80211_mutex);
127} 123}
128 124
129/*
130 * You can use this to mark a wiphy_idx as not having an associated wiphy.
131 * It guarantees cfg80211_rdev_by_wiphy_idx(wiphy_idx) will return NULL
132 */
133#define WIPHY_IDX_STALE -1
134
135struct cfg80211_internal_bss { 125struct cfg80211_internal_bss {
136 struct list_head list; 126 struct list_head list;
137 struct rb_node rbn; 127 struct rb_node rbn;
@@ -435,7 +425,8 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
435 struct wireless_dev *wdev, 425 struct wireless_dev *wdev,
436 enum nl80211_iftype iftype, 426 enum nl80211_iftype iftype,
437 struct ieee80211_channel *chan, 427 struct ieee80211_channel *chan,
438 enum cfg80211_chan_mode chanmode); 428 enum cfg80211_chan_mode chanmode,
429 u8 radar_detect);
439 430
440static inline int 431static inline int
441cfg80211_can_change_interface(struct cfg80211_registered_device *rdev, 432cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
@@ -443,7 +434,7 @@ cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
443 enum nl80211_iftype iftype) 434 enum nl80211_iftype iftype)
444{ 435{
445 return cfg80211_can_use_iftype_chan(rdev, wdev, iftype, NULL, 436 return cfg80211_can_use_iftype_chan(rdev, wdev, iftype, NULL,
446 CHAN_MODE_UNDEFINED); 437 CHAN_MODE_UNDEFINED, 0);
447} 438}
448 439
449static inline int 440static inline int
@@ -460,7 +451,7 @@ cfg80211_can_use_chan(struct cfg80211_registered_device *rdev,
460 enum cfg80211_chan_mode chanmode) 451 enum cfg80211_chan_mode chanmode)
461{ 452{
462 return cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, 453 return cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
463 chan, chanmode); 454 chan, chanmode, 0);
464} 455}
465 456
466void 457void
diff --git a/net/wireless/mesh.c b/net/wireless/mesh.c
index f9d6ce5cfabb..55957a284f6c 100644
--- a/net/wireless/mesh.c
+++ b/net/wireless/mesh.c
@@ -44,6 +44,10 @@
44 44
45#define MESH_SYNC_NEIGHBOR_OFFSET_MAX 50 45#define MESH_SYNC_NEIGHBOR_OFFSET_MAX 50
46 46
47#define MESH_DEFAULT_BEACON_INTERVAL 1000 /* in 1024 us units (=TUs) */
48#define MESH_DEFAULT_DTIM_PERIOD 2
49#define MESH_DEFAULT_AWAKE_WINDOW 10 /* in 1024 us units (=TUs) */
50
47const struct mesh_config default_mesh_config = { 51const struct mesh_config default_mesh_config = {
48 .dot11MeshRetryTimeout = MESH_RET_T, 52 .dot11MeshRetryTimeout = MESH_RET_T,
49 .dot11MeshConfirmTimeout = MESH_CONF_T, 53 .dot11MeshConfirmTimeout = MESH_CONF_T,
@@ -69,6 +73,8 @@ const struct mesh_config default_mesh_config = {
69 .dot11MeshHWMPactivePathToRootTimeout = MESH_PATH_TO_ROOT_TIMEOUT, 73 .dot11MeshHWMPactivePathToRootTimeout = MESH_PATH_TO_ROOT_TIMEOUT,
70 .dot11MeshHWMProotInterval = MESH_ROOT_INTERVAL, 74 .dot11MeshHWMProotInterval = MESH_ROOT_INTERVAL,
71 .dot11MeshHWMPconfirmationInterval = MESH_ROOT_CONFIRMATION_INTERVAL, 75 .dot11MeshHWMPconfirmationInterval = MESH_ROOT_CONFIRMATION_INTERVAL,
76 .power_mode = NL80211_MESH_POWER_ACTIVE,
77 .dot11MeshAwakeWindowDuration = MESH_DEFAULT_AWAKE_WINDOW,
72}; 78};
73 79
74const struct mesh_setup default_mesh_setup = { 80const struct mesh_setup default_mesh_setup = {
@@ -79,6 +85,8 @@ const struct mesh_setup default_mesh_setup = {
79 .ie = NULL, 85 .ie = NULL,
80 .ie_len = 0, 86 .ie_len = 0,
81 .is_secure = false, 87 .is_secure = false,
88 .beacon_interval = MESH_DEFAULT_BEACON_INTERVAL,
89 .dtim_period = MESH_DEFAULT_DTIM_PERIOD,
82}; 90};
83 91
84int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev, 92int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index 5e8123ee63fd..461e692cdfec 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -987,65 +987,3 @@ void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
987 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 987 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
988} 988}
989EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 989EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
990
991void cfg80211_ch_switch_notify(struct net_device *dev,
992 struct cfg80211_chan_def *chandef)
993{
994 struct wireless_dev *wdev = dev->ieee80211_ptr;
995 struct wiphy *wiphy = wdev->wiphy;
996 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
997
998 trace_cfg80211_ch_switch_notify(dev, chandef);
999
1000 wdev_lock(wdev);
1001
1002 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
1003 wdev->iftype != NL80211_IFTYPE_P2P_GO))
1004 goto out;
1005
1006 wdev->channel = chandef->chan;
1007 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
1008out:
1009 wdev_unlock(wdev);
1010 return;
1011}
1012EXPORT_SYMBOL(cfg80211_ch_switch_notify);
1013
1014bool cfg80211_rx_spurious_frame(struct net_device *dev,
1015 const u8 *addr, gfp_t gfp)
1016{
1017 struct wireless_dev *wdev = dev->ieee80211_ptr;
1018 bool ret;
1019
1020 trace_cfg80211_rx_spurious_frame(dev, addr);
1021
1022 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
1023 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
1024 trace_cfg80211_return_bool(false);
1025 return false;
1026 }
1027 ret = nl80211_unexpected_frame(dev, addr, gfp);
1028 trace_cfg80211_return_bool(ret);
1029 return ret;
1030}
1031EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
1032
1033bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
1034 const u8 *addr, gfp_t gfp)
1035{
1036 struct wireless_dev *wdev = dev->ieee80211_ptr;
1037 bool ret;
1038
1039 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
1040
1041 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
1042 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
1043 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
1044 trace_cfg80211_return_bool(false);
1045 return false;
1046 }
1047 ret = nl80211_unexpected_4addr_frame(dev, addr, gfp);
1048 trace_cfg80211_return_bool(ret);
1049 return ret;
1050}
1051EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index f45706adaf34..33de80364c5c 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -856,6 +856,9 @@ static int nl80211_put_iface_combinations(struct wiphy *wiphy,
856 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 856 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
857 c->max_interfaces)) 857 c->max_interfaces))
858 goto nla_put_failure; 858 goto nla_put_failure;
859 if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
860 c->radar_detect_widths))
861 goto nla_put_failure;
859 862
860 nla_nest_end(msg, nl_combi); 863 nla_nest_end(msg, nl_combi);
861 } 864 }
@@ -2079,6 +2082,13 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2079 !(rdev->wiphy.interface_modes & (1 << type))) 2082 !(rdev->wiphy.interface_modes & (1 << type)))
2080 return -EOPNOTSUPP; 2083 return -EOPNOTSUPP;
2081 2084
2085 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2086 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2087 ETH_ALEN);
2088 if (!is_valid_ether_addr(params.macaddr))
2089 return -EADDRNOTAVAIL;
2090 }
2091
2082 if (info->attrs[NL80211_ATTR_4ADDR]) { 2092 if (info->attrs[NL80211_ATTR_4ADDR]) {
2083 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 2093 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2084 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 2094 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
@@ -3001,6 +3011,18 @@ static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
3001 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, 3011 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3002 sinfo->beacon_loss_count)) 3012 sinfo->beacon_loss_count))
3003 goto nla_put_failure; 3013 goto nla_put_failure;
3014 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3015 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3016 sinfo->local_pm))
3017 goto nla_put_failure;
3018 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3019 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3020 sinfo->peer_pm))
3021 goto nla_put_failure;
3022 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3023 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3024 sinfo->nonpeer_pm))
3025 goto nla_put_failure;
3004 if (sinfo->filled & STATION_INFO_BSS_PARAM) { 3026 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3005 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); 3027 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3006 if (!bss_param) 3028 if (!bss_param)
@@ -3188,13 +3210,9 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3188 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 3210 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3189 } 3211 }
3190 3212
3191 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 3213 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL] ||
3192 params.listen_interval = 3214 info->attrs[NL80211_ATTR_HT_CAPABILITY])
3193 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 3215 return -EINVAL;
3194
3195 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3196 params.ht_capa =
3197 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3198 3216
3199 if (!rdev->ops->change_station) 3217 if (!rdev->ops->change_station)
3200 return -EOPNOTSUPP; 3218 return -EOPNOTSUPP;
@@ -3210,6 +3228,17 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3210 params.plink_state = 3228 params.plink_state =
3211 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 3229 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3212 3230
3231 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3232 enum nl80211_mesh_power_mode pm = nla_get_u32(
3233 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3234
3235 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3236 pm > NL80211_MESH_POWER_MAX)
3237 return -EINVAL;
3238
3239 params.local_pm = pm;
3240 }
3241
3213 switch (dev->ieee80211_ptr->iftype) { 3242 switch (dev->ieee80211_ptr->iftype) {
3214 case NL80211_IFTYPE_AP: 3243 case NL80211_IFTYPE_AP:
3215 case NL80211_IFTYPE_AP_VLAN: 3244 case NL80211_IFTYPE_AP_VLAN:
@@ -3217,6 +3246,8 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3217 /* disallow mesh-specific things */ 3246 /* disallow mesh-specific things */
3218 if (params.plink_action) 3247 if (params.plink_action)
3219 return -EINVAL; 3248 return -EINVAL;
3249 if (params.local_pm)
3250 return -EINVAL;
3220 3251
3221 /* TDLS can't be set, ... */ 3252 /* TDLS can't be set, ... */
3222 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 3253 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
@@ -3231,11 +3262,25 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3231 /* accept only the listed bits */ 3262 /* accept only the listed bits */
3232 if (params.sta_flags_mask & 3263 if (params.sta_flags_mask &
3233 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 3264 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3265 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3266 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3234 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 3267 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3235 BIT(NL80211_STA_FLAG_WME) | 3268 BIT(NL80211_STA_FLAG_WME) |
3236 BIT(NL80211_STA_FLAG_MFP))) 3269 BIT(NL80211_STA_FLAG_MFP)))
3237 return -EINVAL; 3270 return -EINVAL;
3238 3271
3272 /* but authenticated/associated only if driver handles it */
3273 if (!(rdev->wiphy.features &
3274 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3275 params.sta_flags_mask &
3276 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3277 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3278 return -EINVAL;
3279
3280 /* reject other things that can't change */
3281 if (params.supported_rates)
3282 return -EINVAL;
3283
3239 /* must be last in here for error handling */ 3284 /* must be last in here for error handling */
3240 params.vlan = get_vlan(info, rdev); 3285 params.vlan = get_vlan(info, rdev);
3241 if (IS_ERR(params.vlan)) 3286 if (IS_ERR(params.vlan))
@@ -3255,9 +3300,7 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3255 /* disallow things sta doesn't support */ 3300 /* disallow things sta doesn't support */
3256 if (params.plink_action) 3301 if (params.plink_action)
3257 return -EINVAL; 3302 return -EINVAL;
3258 if (params.ht_capa) 3303 if (params.local_pm)
3259 return -EINVAL;
3260 if (params.listen_interval >= 0)
3261 return -EINVAL; 3304 return -EINVAL;
3262 /* reject any changes other than AUTHORIZED */ 3305 /* reject any changes other than AUTHORIZED */
3263 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 3306 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
@@ -3267,9 +3310,7 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3267 /* disallow things mesh doesn't support */ 3310 /* disallow things mesh doesn't support */
3268 if (params.vlan) 3311 if (params.vlan)
3269 return -EINVAL; 3312 return -EINVAL;
3270 if (params.ht_capa) 3313 if (params.supported_rates)
3271 return -EINVAL;
3272 if (params.listen_interval >= 0)
3273 return -EINVAL; 3314 return -EINVAL;
3274 /* 3315 /*
3275 * No special handling for TDLS here -- the userspace 3316 * No special handling for TDLS here -- the userspace
@@ -3393,17 +3434,31 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3393 /* but don't bother the driver with it */ 3434 /* but don't bother the driver with it */
3394 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 3435 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3395 3436
3437 /* allow authenticated/associated only if driver handles it */
3438 if (!(rdev->wiphy.features &
3439 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3440 params.sta_flags_mask &
3441 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3442 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3443 return -EINVAL;
3444
3396 /* must be last in here for error handling */ 3445 /* must be last in here for error handling */
3397 params.vlan = get_vlan(info, rdev); 3446 params.vlan = get_vlan(info, rdev);
3398 if (IS_ERR(params.vlan)) 3447 if (IS_ERR(params.vlan))
3399 return PTR_ERR(params.vlan); 3448 return PTR_ERR(params.vlan);
3400 break; 3449 break;
3401 case NL80211_IFTYPE_MESH_POINT: 3450 case NL80211_IFTYPE_MESH_POINT:
3451 /* associated is disallowed */
3452 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3453 return -EINVAL;
3402 /* TDLS peers cannot be added */ 3454 /* TDLS peers cannot be added */
3403 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 3455 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3404 return -EINVAL; 3456 return -EINVAL;
3405 break; 3457 break;
3406 case NL80211_IFTYPE_STATION: 3458 case NL80211_IFTYPE_STATION:
3459 /* associated is disallowed */
3460 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3461 return -EINVAL;
3407 /* Only TDLS peers can be added */ 3462 /* Only TDLS peers can be added */
3408 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 3463 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3409 return -EINVAL; 3464 return -EINVAL;
@@ -3787,12 +3842,8 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3787 * window between nl80211_init() and regulatory_init(), if that is 3842 * window between nl80211_init() and regulatory_init(), if that is
3788 * even possible. 3843 * even possible.
3789 */ 3844 */
3790 mutex_lock(&cfg80211_mutex); 3845 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
3791 if (unlikely(!cfg80211_regdomain)) {
3792 mutex_unlock(&cfg80211_mutex);
3793 return -EINPROGRESS; 3846 return -EINPROGRESS;
3794 }
3795 mutex_unlock(&cfg80211_mutex);
3796 3847
3797 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 3848 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3798 return -EINVAL; 3849 return -EINVAL;
@@ -3908,7 +3959,11 @@ static int nl80211_get_mesh_config(struct sk_buff *skb,
3908 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 3959 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
3909 cur_params.dot11MeshHWMProotInterval) || 3960 cur_params.dot11MeshHWMProotInterval) ||
3910 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 3961 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
3911 cur_params.dot11MeshHWMPconfirmationInterval)) 3962 cur_params.dot11MeshHWMPconfirmationInterval) ||
3963 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
3964 cur_params.power_mode) ||
3965 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
3966 cur_params.dot11MeshAwakeWindowDuration))
3912 goto nla_put_failure; 3967 goto nla_put_failure;
3913 nla_nest_end(msg, pinfoattr); 3968 nla_nest_end(msg, pinfoattr);
3914 genlmsg_end(msg, hdr); 3969 genlmsg_end(msg, hdr);
@@ -3947,6 +4002,8 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
3947 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 4002 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
3948 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, 4003 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
3949 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, 4004 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
4005 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4006 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
3950}; 4007};
3951 4008
3952static const struct nla_policy 4009static const struct nla_policy
@@ -3967,13 +4024,15 @@ static int nl80211_parse_mesh_config(struct genl_info *info,
3967 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 4024 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
3968 u32 mask = 0; 4025 u32 mask = 0;
3969 4026
3970#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ 4027#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
3971do {\ 4028do { \
3972 if (table[attr_num]) {\ 4029 if (tb[attr]) { \
3973 cfg->param = nla_fn(table[attr_num]); \ 4030 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
3974 mask |= (1 << (attr_num - 1)); \ 4031 return -EINVAL; \
3975 } \ 4032 cfg->param = fn(tb[attr]); \
3976} while (0);\ 4033 mask |= (1 << (attr - 1)); \
4034 } \
4035} while (0)
3977 4036
3978 4037
3979 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 4038 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
@@ -3988,83 +4047,98 @@ do {\
3988 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 4047 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3989 4048
3990 /* Fill in the params struct */ 4049 /* Fill in the params struct */
3991 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 4050 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
3992 mask, NL80211_MESHCONF_RETRY_TIMEOUT, 4051 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
3993 nla_get_u16); 4052 nla_get_u16);
3994 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 4053 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
3995 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, 4054 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3996 nla_get_u16); 4055 nla_get_u16);
3997 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 4056 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
3998 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, 4057 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
3999 nla_get_u16); 4058 nla_get_u16);
4000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 4059 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
4001 mask, NL80211_MESHCONF_MAX_PEER_LINKS, 4060 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4002 nla_get_u16); 4061 nla_get_u16);
4003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 4062 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
4004 mask, NL80211_MESHCONF_MAX_RETRIES, 4063 mask, NL80211_MESHCONF_MAX_RETRIES,
4005 nla_get_u8); 4064 nla_get_u8);
4006 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 4065 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
4007 mask, NL80211_MESHCONF_TTL, nla_get_u8); 4066 mask, NL80211_MESHCONF_TTL, nla_get_u8);
4008 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 4067 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
4009 mask, NL80211_MESHCONF_ELEMENT_TTL, 4068 mask, NL80211_MESHCONF_ELEMENT_TTL,
4010 nla_get_u8); 4069 nla_get_u8);
4011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 4070 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
4012 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 4071 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4013 nla_get_u8); 4072 nla_get_u8);
4014 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, 4073 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4074 1, 255, mask,
4015 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 4075 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4016 nla_get_u32); 4076 nla_get_u32);
4017 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 4077 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
4018 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 4078 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4019 nla_get_u8); 4079 nla_get_u8);
4020 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 4080 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
4021 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, 4081 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4022 nla_get_u32); 4082 nla_get_u32);
4023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 4083 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
4024 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 4084 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4025 nla_get_u16); 4085 nla_get_u16);
4026 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, 4086 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4087 1, 65535, mask,
4027 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 4088 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4028 nla_get_u32); 4089 nla_get_u32);
4029 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, 4090 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
4030 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 4091 1, 65535, mask,
4092 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4031 nla_get_u16); 4093 nla_get_u16);
4032 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, 4094 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
4033 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 4095 1, 65535, mask,
4096 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4034 nla_get_u16); 4097 nla_get_u16);
4035 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 4098 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4036 dot11MeshHWMPnetDiameterTraversalTime, mask, 4099 dot11MeshHWMPnetDiameterTraversalTime,
4100 1, 65535, mask,
4037 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 4101 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4038 nla_get_u16); 4102 nla_get_u16);
4039 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 4103 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4040 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 4104 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4041 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 4105 nla_get_u8);
4042 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 4106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4107 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4043 nla_get_u16); 4108 nla_get_u16);
4044 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 4109 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4045 dot11MeshGateAnnouncementProtocol, mask, 4110 dot11MeshGateAnnouncementProtocol, 0, 1,
4046 NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 4111 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4047 nla_get_u8); 4112 nla_get_u8);
4048 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 4113 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
4049 mask, NL80211_MESHCONF_FORWARDING, 4114 mask, NL80211_MESHCONF_FORWARDING,
4050 nla_get_u8); 4115 nla_get_u8);
4051 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 4116 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
4052 mask, NL80211_MESHCONF_RSSI_THRESHOLD, 4117 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4053 nla_get_u32); 4118 nla_get_u32);
4054 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 4119 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
4055 mask, NL80211_MESHCONF_HT_OPMODE, 4120 mask, NL80211_MESHCONF_HT_OPMODE,
4056 nla_get_u16); 4121 nla_get_u16);
4057 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, 4122 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
4058 mask, 4123 1, 65535, mask,
4059 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 4124 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4060 nla_get_u32); 4125 nla_get_u32);
4061 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 4126 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
4062 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 4127 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4063 nla_get_u16); 4128 nla_get_u16);
4064 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 4129 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
4065 dot11MeshHWMPconfirmationInterval, mask, 4130 dot11MeshHWMPconfirmationInterval,
4131 1, 65535, mask,
4066 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 4132 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4067 nla_get_u16); 4133 nla_get_u16);
4134 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4135 NL80211_MESH_POWER_ACTIVE,
4136 NL80211_MESH_POWER_MAX,
4137 mask, NL80211_MESHCONF_POWER_MODE,
4138 nla_get_u32);
4139 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4140 0, 65535, mask,
4141 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
4068 if (mask_out) 4142 if (mask_out)
4069 *mask_out = mask; 4143 *mask_out = mask;
4070 4144
@@ -4152,6 +4226,7 @@ static int nl80211_update_mesh_config(struct sk_buff *skb,
4152 4226
4153static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) 4227static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4154{ 4228{
4229 const struct ieee80211_regdomain *regdom;
4155 struct sk_buff *msg; 4230 struct sk_buff *msg;
4156 void *hdr = NULL; 4231 void *hdr = NULL;
4157 struct nlattr *nl_reg_rules; 4232 struct nlattr *nl_reg_rules;
@@ -4174,35 +4249,36 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4174 if (!hdr) 4249 if (!hdr)
4175 goto put_failure; 4250 goto put_failure;
4176 4251
4177 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
4178 cfg80211_regdomain->alpha2) ||
4179 (cfg80211_regdomain->dfs_region &&
4180 nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
4181 cfg80211_regdomain->dfs_region)))
4182 goto nla_put_failure;
4183
4184 if (reg_last_request_cell_base() && 4252 if (reg_last_request_cell_base() &&
4185 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 4253 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4186 NL80211_USER_REG_HINT_CELL_BASE)) 4254 NL80211_USER_REG_HINT_CELL_BASE))
4187 goto nla_put_failure; 4255 goto nla_put_failure;
4188 4256
4257 rcu_read_lock();
4258 regdom = rcu_dereference(cfg80211_regdomain);
4259
4260 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4261 (regdom->dfs_region &&
4262 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4263 goto nla_put_failure_rcu;
4264
4189 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); 4265 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4190 if (!nl_reg_rules) 4266 if (!nl_reg_rules)
4191 goto nla_put_failure; 4267 goto nla_put_failure_rcu;
4192 4268
4193 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { 4269 for (i = 0; i < regdom->n_reg_rules; i++) {
4194 struct nlattr *nl_reg_rule; 4270 struct nlattr *nl_reg_rule;
4195 const struct ieee80211_reg_rule *reg_rule; 4271 const struct ieee80211_reg_rule *reg_rule;
4196 const struct ieee80211_freq_range *freq_range; 4272 const struct ieee80211_freq_range *freq_range;
4197 const struct ieee80211_power_rule *power_rule; 4273 const struct ieee80211_power_rule *power_rule;
4198 4274
4199 reg_rule = &cfg80211_regdomain->reg_rules[i]; 4275 reg_rule = &regdom->reg_rules[i];
4200 freq_range = &reg_rule->freq_range; 4276 freq_range = &reg_rule->freq_range;
4201 power_rule = &reg_rule->power_rule; 4277 power_rule = &reg_rule->power_rule;
4202 4278
4203 nl_reg_rule = nla_nest_start(msg, i); 4279 nl_reg_rule = nla_nest_start(msg, i);
4204 if (!nl_reg_rule) 4280 if (!nl_reg_rule)
4205 goto nla_put_failure; 4281 goto nla_put_failure_rcu;
4206 4282
4207 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 4283 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4208 reg_rule->flags) || 4284 reg_rule->flags) ||
@@ -4216,10 +4292,11 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4216 power_rule->max_antenna_gain) || 4292 power_rule->max_antenna_gain) ||
4217 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 4293 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4218 power_rule->max_eirp)) 4294 power_rule->max_eirp))
4219 goto nla_put_failure; 4295 goto nla_put_failure_rcu;
4220 4296
4221 nla_nest_end(msg, nl_reg_rule); 4297 nla_nest_end(msg, nl_reg_rule);
4222 } 4298 }
4299 rcu_read_unlock();
4223 4300
4224 nla_nest_end(msg, nl_reg_rules); 4301 nla_nest_end(msg, nl_reg_rules);
4225 4302
@@ -4227,6 +4304,8 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4227 err = genlmsg_reply(msg, info); 4304 err = genlmsg_reply(msg, info);
4228 goto out; 4305 goto out;
4229 4306
4307nla_put_failure_rcu:
4308 rcu_read_unlock();
4230nla_put_failure: 4309nla_put_failure:
4231 genlmsg_cancel(msg, hdr); 4310 genlmsg_cancel(msg, hdr);
4232put_failure: 4311put_failure:
@@ -4259,27 +4338,18 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4259 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 4338 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4260 4339
4261 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 4340 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4262 rem_reg_rules) { 4341 rem_reg_rules) {
4263 num_rules++; 4342 num_rules++;
4264 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 4343 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
4265 return -EINVAL; 4344 return -EINVAL;
4266 } 4345 }
4267 4346
4268 mutex_lock(&cfg80211_mutex);
4269
4270 if (!reg_is_valid_request(alpha2)) {
4271 r = -EINVAL;
4272 goto bad_reg;
4273 }
4274
4275 size_of_regd = sizeof(struct ieee80211_regdomain) + 4347 size_of_regd = sizeof(struct ieee80211_regdomain) +
4276 (num_rules * sizeof(struct ieee80211_reg_rule)); 4348 num_rules * sizeof(struct ieee80211_reg_rule);
4277 4349
4278 rd = kzalloc(size_of_regd, GFP_KERNEL); 4350 rd = kzalloc(size_of_regd, GFP_KERNEL);
4279 if (!rd) { 4351 if (!rd)
4280 r = -ENOMEM; 4352 return -ENOMEM;
4281 goto bad_reg;
4282 }
4283 4353
4284 rd->n_reg_rules = num_rules; 4354 rd->n_reg_rules = num_rules;
4285 rd->alpha2[0] = alpha2[0]; 4355 rd->alpha2[0] = alpha2[0];
@@ -4293,10 +4363,10 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4293 rd->dfs_region = dfs_region; 4363 rd->dfs_region = dfs_region;
4294 4364
4295 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 4365 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
4296 rem_reg_rules) { 4366 rem_reg_rules) {
4297 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, 4367 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
4298 nla_data(nl_reg_rule), nla_len(nl_reg_rule), 4368 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4299 reg_rule_policy); 4369 reg_rule_policy);
4300 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 4370 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4301 if (r) 4371 if (r)
4302 goto bad_reg; 4372 goto bad_reg;
@@ -4309,16 +4379,14 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4309 } 4379 }
4310 } 4380 }
4311 4381
4312 BUG_ON(rule_idx != num_rules); 4382 mutex_lock(&cfg80211_mutex);
4313 4383
4314 r = set_regdom(rd); 4384 r = set_regdom(rd);
4315 4385 /* set_regdom took ownership */
4386 rd = NULL;
4316 mutex_unlock(&cfg80211_mutex); 4387 mutex_unlock(&cfg80211_mutex);
4317 4388
4318 return r;
4319
4320 bad_reg: 4389 bad_reg:
4321 mutex_unlock(&cfg80211_mutex);
4322 kfree(rd); 4390 kfree(rd);
4323 return r; 4391 return r;
4324} 4392}
@@ -5867,6 +5935,15 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5867 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 5935 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5868 } 5936 }
5869 5937
5938 if (info->attrs[NL80211_ATTR_USE_MFP]) {
5939 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
5940 if (connect.mfp != NL80211_MFP_REQUIRED &&
5941 connect.mfp != NL80211_MFP_NO)
5942 return -EINVAL;
5943 } else {
5944 connect.mfp = NL80211_MFP_NO;
5945 }
5946
5870 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 5947 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5871 connect.channel = 5948 connect.channel =
5872 ieee80211_get_channel(wiphy, 5949 ieee80211_get_channel(wiphy,
@@ -6652,6 +6729,21 @@ static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6652 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 6729 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6653 return -EINVAL; 6730 return -EINVAL;
6654 6731
6732 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6733 setup.beacon_interval =
6734 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6735 if (setup.beacon_interval < 10 ||
6736 setup.beacon_interval > 10000)
6737 return -EINVAL;
6738 }
6739
6740 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
6741 setup.dtim_period =
6742 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
6743 if (setup.dtim_period < 1 || setup.dtim_period > 100)
6744 return -EINVAL;
6745 }
6746
6655 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 6747 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
6656 /* parse additional setup parameters if given */ 6748 /* parse additional setup parameters if given */
6657 err = nl80211_parse_mesh_setup(info, &setup); 6749 err = nl80211_parse_mesh_setup(info, &setup);
@@ -8051,7 +8143,7 @@ void nl80211_send_reg_change_event(struct regulatory_request *request)
8051 goto nla_put_failure; 8143 goto nla_put_failure;
8052 } 8144 }
8053 8145
8054 if (wiphy_idx_valid(request->wiphy_idx) && 8146 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
8055 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 8147 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
8056 goto nla_put_failure; 8148 goto nla_put_failure;
8057 8149
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 82c4fc7c994c..de02d633c212 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -48,7 +48,6 @@
48#include <linux/export.h> 48#include <linux/export.h>
49#include <linux/slab.h> 49#include <linux/slab.h>
50#include <linux/list.h> 50#include <linux/list.h>
51#include <linux/random.h>
52#include <linux/ctype.h> 51#include <linux/ctype.h>
53#include <linux/nl80211.h> 52#include <linux/nl80211.h>
54#include <linux/platform_device.h> 53#include <linux/platform_device.h>
@@ -66,6 +65,13 @@
66#define REG_DBG_PRINT(args...) 65#define REG_DBG_PRINT(args...)
67#endif 66#endif
68 67
68enum reg_request_treatment {
69 REG_REQ_OK,
70 REG_REQ_IGNORE,
71 REG_REQ_INTERSECT,
72 REG_REQ_ALREADY_SET,
73};
74
69static struct regulatory_request core_request_world = { 75static struct regulatory_request core_request_world = {
70 .initiator = NL80211_REGDOM_SET_BY_CORE, 76 .initiator = NL80211_REGDOM_SET_BY_CORE,
71 .alpha2[0] = '0', 77 .alpha2[0] = '0',
@@ -76,7 +82,8 @@ static struct regulatory_request core_request_world = {
76}; 82};
77 83
78/* Receipt of information from last regulatory request */ 84/* Receipt of information from last regulatory request */
79static struct regulatory_request *last_request = &core_request_world; 85static struct regulatory_request __rcu *last_request =
86 (void __rcu *)&core_request_world;
80 87
81/* To trigger userspace events */ 88/* To trigger userspace events */
82static struct platform_device *reg_pdev; 89static struct platform_device *reg_pdev;
@@ -88,16 +95,16 @@ static struct device_type reg_device_type = {
88/* 95/*
89 * Central wireless core regulatory domains, we only need two, 96 * Central wireless core regulatory domains, we only need two,
90 * the current one and a world regulatory domain in case we have no 97 * the current one and a world regulatory domain in case we have no
91 * information to give us an alpha2 98 * information to give us an alpha2.
92 */ 99 */
93const struct ieee80211_regdomain *cfg80211_regdomain; 100const struct ieee80211_regdomain __rcu *cfg80211_regdomain;
94 101
95/* 102/*
96 * Protects static reg.c components: 103 * Protects static reg.c components:
97 * - cfg80211_world_regdom 104 * - cfg80211_regdomain (if not used with RCU)
98 * - cfg80211_regdom 105 * - cfg80211_world_regdom
99 * - last_request 106 * - last_request (if not used with RCU)
100 * - reg_num_devs_support_basehint 107 * - reg_num_devs_support_basehint
101 */ 108 */
102static DEFINE_MUTEX(reg_mutex); 109static DEFINE_MUTEX(reg_mutex);
103 110
@@ -112,6 +119,31 @@ static inline void assert_reg_lock(void)
112 lockdep_assert_held(&reg_mutex); 119 lockdep_assert_held(&reg_mutex);
113} 120}
114 121
122static const struct ieee80211_regdomain *get_cfg80211_regdom(void)
123{
124 return rcu_dereference_protected(cfg80211_regdomain,
125 lockdep_is_held(&reg_mutex));
126}
127
128static const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy)
129{
130 return rcu_dereference_protected(wiphy->regd,
131 lockdep_is_held(&reg_mutex));
132}
133
134static void rcu_free_regdom(const struct ieee80211_regdomain *r)
135{
136 if (!r)
137 return;
138 kfree_rcu((struct ieee80211_regdomain *)r, rcu_head);
139}
140
141static struct regulatory_request *get_last_request(void)
142{
143 return rcu_dereference_check(last_request,
144 lockdep_is_held(&reg_mutex));
145}
146
115/* Used to queue up regulatory hints */ 147/* Used to queue up regulatory hints */
116static LIST_HEAD(reg_requests_list); 148static LIST_HEAD(reg_requests_list);
117static spinlock_t reg_requests_lock; 149static spinlock_t reg_requests_lock;
@@ -177,28 +209,37 @@ static char user_alpha2[2];
177module_param(ieee80211_regdom, charp, 0444); 209module_param(ieee80211_regdom, charp, 0444);
178MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); 210MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
179 211
180static void reset_regdomains(bool full_reset) 212static void reset_regdomains(bool full_reset,
213 const struct ieee80211_regdomain *new_regdom)
181{ 214{
215 const struct ieee80211_regdomain *r;
216 struct regulatory_request *lr;
217
218 assert_reg_lock();
219
220 r = get_cfg80211_regdom();
221
182 /* avoid freeing static information or freeing something twice */ 222 /* avoid freeing static information or freeing something twice */
183 if (cfg80211_regdomain == cfg80211_world_regdom) 223 if (r == cfg80211_world_regdom)
184 cfg80211_regdomain = NULL; 224 r = NULL;
185 if (cfg80211_world_regdom == &world_regdom) 225 if (cfg80211_world_regdom == &world_regdom)
186 cfg80211_world_regdom = NULL; 226 cfg80211_world_regdom = NULL;
187 if (cfg80211_regdomain == &world_regdom) 227 if (r == &world_regdom)
188 cfg80211_regdomain = NULL; 228 r = NULL;
189 229
190 kfree(cfg80211_regdomain); 230 rcu_free_regdom(r);
191 kfree(cfg80211_world_regdom); 231 rcu_free_regdom(cfg80211_world_regdom);
192 232
193 cfg80211_world_regdom = &world_regdom; 233 cfg80211_world_regdom = &world_regdom;
194 cfg80211_regdomain = NULL; 234 rcu_assign_pointer(cfg80211_regdomain, new_regdom);
195 235
196 if (!full_reset) 236 if (!full_reset)
197 return; 237 return;
198 238
199 if (last_request != &core_request_world) 239 lr = get_last_request();
200 kfree(last_request); 240 if (lr != &core_request_world && lr)
201 last_request = &core_request_world; 241 kfree_rcu(lr, rcu_head);
242 rcu_assign_pointer(last_request, &core_request_world);
202} 243}
203 244
204/* 245/*
@@ -207,30 +248,29 @@ static void reset_regdomains(bool full_reset)
207 */ 248 */
208static void update_world_regdomain(const struct ieee80211_regdomain *rd) 249static void update_world_regdomain(const struct ieee80211_regdomain *rd)
209{ 250{
210 BUG_ON(!last_request); 251 struct regulatory_request *lr;
252
253 lr = get_last_request();
254
255 WARN_ON(!lr);
211 256
212 reset_regdomains(false); 257 reset_regdomains(false, rd);
213 258
214 cfg80211_world_regdom = rd; 259 cfg80211_world_regdom = rd;
215 cfg80211_regdomain = rd;
216} 260}
217 261
218bool is_world_regdom(const char *alpha2) 262bool is_world_regdom(const char *alpha2)
219{ 263{
220 if (!alpha2) 264 if (!alpha2)
221 return false; 265 return false;
222 if (alpha2[0] == '0' && alpha2[1] == '0') 266 return alpha2[0] == '0' && alpha2[1] == '0';
223 return true;
224 return false;
225} 267}
226 268
227static bool is_alpha2_set(const char *alpha2) 269static bool is_alpha2_set(const char *alpha2)
228{ 270{
229 if (!alpha2) 271 if (!alpha2)
230 return false; 272 return false;
231 if (alpha2[0] != 0 && alpha2[1] != 0) 273 return alpha2[0] && alpha2[1];
232 return true;
233 return false;
234} 274}
235 275
236static bool is_unknown_alpha2(const char *alpha2) 276static bool is_unknown_alpha2(const char *alpha2)
@@ -241,9 +281,7 @@ static bool is_unknown_alpha2(const char *alpha2)
241 * Special case where regulatory domain was built by driver 281 * Special case where regulatory domain was built by driver
242 * but a specific alpha2 cannot be determined 282 * but a specific alpha2 cannot be determined
243 */ 283 */
244 if (alpha2[0] == '9' && alpha2[1] == '9') 284 return alpha2[0] == '9' && alpha2[1] == '9';
245 return true;
246 return false;
247} 285}
248 286
249static bool is_intersected_alpha2(const char *alpha2) 287static bool is_intersected_alpha2(const char *alpha2)
@@ -255,39 +293,30 @@ static bool is_intersected_alpha2(const char *alpha2)
255 * result of an intersection between two regulatory domain 293 * result of an intersection between two regulatory domain
256 * structures 294 * structures
257 */ 295 */
258 if (alpha2[0] == '9' && alpha2[1] == '8') 296 return alpha2[0] == '9' && alpha2[1] == '8';
259 return true;
260 return false;
261} 297}
262 298
263static bool is_an_alpha2(const char *alpha2) 299static bool is_an_alpha2(const char *alpha2)
264{ 300{
265 if (!alpha2) 301 if (!alpha2)
266 return false; 302 return false;
267 if (isalpha(alpha2[0]) && isalpha(alpha2[1])) 303 return isalpha(alpha2[0]) && isalpha(alpha2[1]);
268 return true;
269 return false;
270} 304}
271 305
272static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y) 306static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
273{ 307{
274 if (!alpha2_x || !alpha2_y) 308 if (!alpha2_x || !alpha2_y)
275 return false; 309 return false;
276 if (alpha2_x[0] == alpha2_y[0] && 310 return alpha2_x[0] == alpha2_y[0] && alpha2_x[1] == alpha2_y[1];
277 alpha2_x[1] == alpha2_y[1])
278 return true;
279 return false;
280} 311}
281 312
282static bool regdom_changes(const char *alpha2) 313static bool regdom_changes(const char *alpha2)
283{ 314{
284 assert_cfg80211_lock(); 315 const struct ieee80211_regdomain *r = get_cfg80211_regdom();
285 316
286 if (!cfg80211_regdomain) 317 if (!r)
287 return true; 318 return true;
288 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) 319 return !alpha2_equal(r->alpha2, alpha2);
289 return false;
290 return true;
291} 320}
292 321
293/* 322/*
@@ -301,38 +330,36 @@ static bool is_user_regdom_saved(void)
301 return false; 330 return false;
302 331
303 /* This would indicate a mistake on the design */ 332 /* This would indicate a mistake on the design */
304 if (WARN((!is_world_regdom(user_alpha2) && 333 if (WARN(!is_world_regdom(user_alpha2) && !is_an_alpha2(user_alpha2),
305 !is_an_alpha2(user_alpha2)),
306 "Unexpected user alpha2: %c%c\n", 334 "Unexpected user alpha2: %c%c\n",
307 user_alpha2[0], 335 user_alpha2[0], user_alpha2[1]))
308 user_alpha2[1]))
309 return false; 336 return false;
310 337
311 return true; 338 return true;
312} 339}
313 340
314static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, 341static const struct ieee80211_regdomain *
315 const struct ieee80211_regdomain *src_regd) 342reg_copy_regd(const struct ieee80211_regdomain *src_regd)
316{ 343{
317 struct ieee80211_regdomain *regd; 344 struct ieee80211_regdomain *regd;
318 int size_of_regd = 0; 345 int size_of_regd;
319 unsigned int i; 346 unsigned int i;
320 347
321 size_of_regd = sizeof(struct ieee80211_regdomain) + 348 size_of_regd =
322 ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule)); 349 sizeof(struct ieee80211_regdomain) +
350 src_regd->n_reg_rules * sizeof(struct ieee80211_reg_rule);
323 351
324 regd = kzalloc(size_of_regd, GFP_KERNEL); 352 regd = kzalloc(size_of_regd, GFP_KERNEL);
325 if (!regd) 353 if (!regd)
326 return -ENOMEM; 354 return ERR_PTR(-ENOMEM);
327 355
328 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); 356 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
329 357
330 for (i = 0; i < src_regd->n_reg_rules; i++) 358 for (i = 0; i < src_regd->n_reg_rules; i++)
331 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i], 359 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
332 sizeof(struct ieee80211_reg_rule)); 360 sizeof(struct ieee80211_reg_rule));
333 361
334 *dst_regd = regd; 362 return regd;
335 return 0;
336} 363}
337 364
338#ifdef CONFIG_CFG80211_INTERNAL_REGDB 365#ifdef CONFIG_CFG80211_INTERNAL_REGDB
@@ -347,9 +374,8 @@ static DEFINE_MUTEX(reg_regdb_search_mutex);
347static void reg_regdb_search(struct work_struct *work) 374static void reg_regdb_search(struct work_struct *work)
348{ 375{
349 struct reg_regdb_search_request *request; 376 struct reg_regdb_search_request *request;
350 const struct ieee80211_regdomain *curdom, *regdom; 377 const struct ieee80211_regdomain *curdom, *regdom = NULL;
351 int i, r; 378 int i;
352 bool set_reg = false;
353 379
354 mutex_lock(&cfg80211_mutex); 380 mutex_lock(&cfg80211_mutex);
355 381
@@ -360,14 +386,11 @@ static void reg_regdb_search(struct work_struct *work)
360 list); 386 list);
361 list_del(&request->list); 387 list_del(&request->list);
362 388
363 for (i=0; i<reg_regdb_size; i++) { 389 for (i = 0; i < reg_regdb_size; i++) {
364 curdom = reg_regdb[i]; 390 curdom = reg_regdb[i];
365 391
366 if (!memcmp(request->alpha2, curdom->alpha2, 2)) { 392 if (alpha2_equal(request->alpha2, curdom->alpha2)) {
367 r = reg_copy_regd(&regdom, curdom); 393 regdom = reg_copy_regd(curdom);
368 if (r)
369 break;
370 set_reg = true;
371 break; 394 break;
372 } 395 }
373 } 396 }
@@ -376,7 +399,7 @@ static void reg_regdb_search(struct work_struct *work)
376 } 399 }
377 mutex_unlock(&reg_regdb_search_mutex); 400 mutex_unlock(&reg_regdb_search_mutex);
378 401
379 if (set_reg) 402 if (!IS_ERR_OR_NULL(regdom))
380 set_regdom(regdom); 403 set_regdom(regdom);
381 404
382 mutex_unlock(&cfg80211_mutex); 405 mutex_unlock(&cfg80211_mutex);
@@ -434,15 +457,14 @@ static int call_crda(const char *alpha2)
434 return kobject_uevent(&reg_pdev->dev.kobj, KOBJ_CHANGE); 457 return kobject_uevent(&reg_pdev->dev.kobj, KOBJ_CHANGE);
435} 458}
436 459
437/* Used by nl80211 before kmalloc'ing our regulatory domain */ 460static bool reg_is_valid_request(const char *alpha2)
438bool reg_is_valid_request(const char *alpha2)
439{ 461{
440 assert_cfg80211_lock(); 462 struct regulatory_request *lr = get_last_request();
441 463
442 if (!last_request) 464 if (!lr || lr->processed)
443 return false; 465 return false;
444 466
445 return alpha2_equal(last_request->alpha2, alpha2); 467 return alpha2_equal(lr->alpha2, alpha2);
446} 468}
447 469
448/* Sanity check on a regulatory rule */ 470/* Sanity check on a regulatory rule */
@@ -460,7 +482,7 @@ static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
460 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 482 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
461 483
462 if (freq_range->end_freq_khz <= freq_range->start_freq_khz || 484 if (freq_range->end_freq_khz <= freq_range->start_freq_khz ||
463 freq_range->max_bandwidth_khz > freq_diff) 485 freq_range->max_bandwidth_khz > freq_diff)
464 return false; 486 return false;
465 487
466 return true; 488 return true;
@@ -487,8 +509,7 @@ static bool is_valid_rd(const struct ieee80211_regdomain *rd)
487} 509}
488 510
489static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range, 511static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range,
490 u32 center_freq_khz, 512 u32 center_freq_khz, u32 bw_khz)
491 u32 bw_khz)
492{ 513{
493 u32 start_freq_khz, end_freq_khz; 514 u32 start_freq_khz, end_freq_khz;
494 515
@@ -518,7 +539,7 @@ static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range,
518 * regulatory rule support for other "bands". 539 * regulatory rule support for other "bands".
519 **/ 540 **/
520static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range, 541static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
521 u32 freq_khz) 542 u32 freq_khz)
522{ 543{
523#define ONE_GHZ_IN_KHZ 1000000 544#define ONE_GHZ_IN_KHZ 1000000
524 /* 545 /*
@@ -540,10 +561,9 @@ static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
540 * Helper for regdom_intersect(), this does the real 561 * Helper for regdom_intersect(), this does the real
541 * mathematical intersection fun 562 * mathematical intersection fun
542 */ 563 */
543static int reg_rules_intersect( 564static int reg_rules_intersect(const struct ieee80211_reg_rule *rule1,
544 const struct ieee80211_reg_rule *rule1, 565 const struct ieee80211_reg_rule *rule2,
545 const struct ieee80211_reg_rule *rule2, 566 struct ieee80211_reg_rule *intersected_rule)
546 struct ieee80211_reg_rule *intersected_rule)
547{ 567{
548 const struct ieee80211_freq_range *freq_range1, *freq_range2; 568 const struct ieee80211_freq_range *freq_range1, *freq_range2;
549 struct ieee80211_freq_range *freq_range; 569 struct ieee80211_freq_range *freq_range;
@@ -560,11 +580,11 @@ static int reg_rules_intersect(
560 power_rule = &intersected_rule->power_rule; 580 power_rule = &intersected_rule->power_rule;
561 581
562 freq_range->start_freq_khz = max(freq_range1->start_freq_khz, 582 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
563 freq_range2->start_freq_khz); 583 freq_range2->start_freq_khz);
564 freq_range->end_freq_khz = min(freq_range1->end_freq_khz, 584 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
565 freq_range2->end_freq_khz); 585 freq_range2->end_freq_khz);
566 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz, 586 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
567 freq_range2->max_bandwidth_khz); 587 freq_range2->max_bandwidth_khz);
568 588
569 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 589 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
570 if (freq_range->max_bandwidth_khz > freq_diff) 590 if (freq_range->max_bandwidth_khz > freq_diff)
@@ -575,7 +595,7 @@ static int reg_rules_intersect(
575 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, 595 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
576 power_rule2->max_antenna_gain); 596 power_rule2->max_antenna_gain);
577 597
578 intersected_rule->flags = (rule1->flags | rule2->flags); 598 intersected_rule->flags = rule1->flags | rule2->flags;
579 599
580 if (!is_valid_reg_rule(intersected_rule)) 600 if (!is_valid_reg_rule(intersected_rule))
581 return -EINVAL; 601 return -EINVAL;
@@ -596,9 +616,9 @@ static int reg_rules_intersect(
596 * resulting intersection of rules between rd1 and rd2. We will 616 * resulting intersection of rules between rd1 and rd2. We will
597 * kzalloc() this structure for you. 617 * kzalloc() this structure for you.
598 */ 618 */
599static struct ieee80211_regdomain *regdom_intersect( 619static struct ieee80211_regdomain *
600 const struct ieee80211_regdomain *rd1, 620regdom_intersect(const struct ieee80211_regdomain *rd1,
601 const struct ieee80211_regdomain *rd2) 621 const struct ieee80211_regdomain *rd2)
602{ 622{
603 int r, size_of_regd; 623 int r, size_of_regd;
604 unsigned int x, y; 624 unsigned int x, y;
@@ -607,12 +627,7 @@ static struct ieee80211_regdomain *regdom_intersect(
607 struct ieee80211_reg_rule *intersected_rule; 627 struct ieee80211_reg_rule *intersected_rule;
608 struct ieee80211_regdomain *rd; 628 struct ieee80211_regdomain *rd;
609 /* This is just a dummy holder to help us count */ 629 /* This is just a dummy holder to help us count */
610 struct ieee80211_reg_rule irule; 630 struct ieee80211_reg_rule dummy_rule;
611
612 /* Uses the stack temporarily for counter arithmetic */
613 intersected_rule = &irule;
614
615 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
616 631
617 if (!rd1 || !rd2) 632 if (!rd1 || !rd2)
618 return NULL; 633 return NULL;
@@ -629,11 +644,8 @@ static struct ieee80211_regdomain *regdom_intersect(
629 rule1 = &rd1->reg_rules[x]; 644 rule1 = &rd1->reg_rules[x];
630 for (y = 0; y < rd2->n_reg_rules; y++) { 645 for (y = 0; y < rd2->n_reg_rules; y++) {
631 rule2 = &rd2->reg_rules[y]; 646 rule2 = &rd2->reg_rules[y];
632 if (!reg_rules_intersect(rule1, rule2, 647 if (!reg_rules_intersect(rule1, rule2, &dummy_rule))
633 intersected_rule))
634 num_rules++; 648 num_rules++;
635 memset(intersected_rule, 0,
636 sizeof(struct ieee80211_reg_rule));
637 } 649 }
638 } 650 }
639 651
@@ -641,15 +653,15 @@ static struct ieee80211_regdomain *regdom_intersect(
641 return NULL; 653 return NULL;
642 654
643 size_of_regd = sizeof(struct ieee80211_regdomain) + 655 size_of_regd = sizeof(struct ieee80211_regdomain) +
644 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule)); 656 num_rules * sizeof(struct ieee80211_reg_rule);
645 657
646 rd = kzalloc(size_of_regd, GFP_KERNEL); 658 rd = kzalloc(size_of_regd, GFP_KERNEL);
647 if (!rd) 659 if (!rd)
648 return NULL; 660 return NULL;
649 661
650 for (x = 0; x < rd1->n_reg_rules; x++) { 662 for (x = 0; x < rd1->n_reg_rules && rule_idx < num_rules; x++) {
651 rule1 = &rd1->reg_rules[x]; 663 rule1 = &rd1->reg_rules[x];
652 for (y = 0; y < rd2->n_reg_rules; y++) { 664 for (y = 0; y < rd2->n_reg_rules && rule_idx < num_rules; y++) {
653 rule2 = &rd2->reg_rules[y]; 665 rule2 = &rd2->reg_rules[y];
654 /* 666 /*
655 * This time around instead of using the stack lets 667 * This time around instead of using the stack lets
@@ -657,8 +669,7 @@ static struct ieee80211_regdomain *regdom_intersect(
657 * a memcpy() 669 * a memcpy()
658 */ 670 */
659 intersected_rule = &rd->reg_rules[rule_idx]; 671 intersected_rule = &rd->reg_rules[rule_idx];
660 r = reg_rules_intersect(rule1, rule2, 672 r = reg_rules_intersect(rule1, rule2, intersected_rule);
661 intersected_rule);
662 /* 673 /*
663 * No need to memset here the intersected rule here as 674 * No need to memset here the intersected rule here as
664 * we're not using the stack anymore 675 * we're not using the stack anymore
@@ -699,34 +710,16 @@ static u32 map_regdom_flags(u32 rd_flags)
699 return channel_flags; 710 return channel_flags;
700} 711}
701 712
702static int freq_reg_info_regd(struct wiphy *wiphy, 713static const struct ieee80211_reg_rule *
703 u32 center_freq, 714freq_reg_info_regd(struct wiphy *wiphy, u32 center_freq,
704 u32 desired_bw_khz, 715 const struct ieee80211_regdomain *regd)
705 const struct ieee80211_reg_rule **reg_rule,
706 const struct ieee80211_regdomain *custom_regd)
707{ 716{
708 int i; 717 int i;
709 bool band_rule_found = false; 718 bool band_rule_found = false;
710 const struct ieee80211_regdomain *regd;
711 bool bw_fits = false; 719 bool bw_fits = false;
712 720
713 if (!desired_bw_khz)
714 desired_bw_khz = MHZ_TO_KHZ(20);
715
716 regd = custom_regd ? custom_regd : cfg80211_regdomain;
717
718 /*
719 * Follow the driver's regulatory domain, if present, unless a country
720 * IE has been processed or a user wants to help complaince further
721 */
722 if (!custom_regd &&
723 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
724 last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
725 wiphy->regd)
726 regd = wiphy->regd;
727
728 if (!regd) 721 if (!regd)
729 return -EINVAL; 722 return ERR_PTR(-EINVAL);
730 723
731 for (i = 0; i < regd->n_reg_rules; i++) { 724 for (i = 0; i < regd->n_reg_rules; i++) {
732 const struct ieee80211_reg_rule *rr; 725 const struct ieee80211_reg_rule *rr;
@@ -743,33 +736,36 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
743 if (!band_rule_found) 736 if (!band_rule_found)
744 band_rule_found = freq_in_rule_band(fr, center_freq); 737 band_rule_found = freq_in_rule_band(fr, center_freq);
745 738
746 bw_fits = reg_does_bw_fit(fr, 739 bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(20));
747 center_freq,
748 desired_bw_khz);
749 740
750 if (band_rule_found && bw_fits) { 741 if (band_rule_found && bw_fits)
751 *reg_rule = rr; 742 return rr;
752 return 0;
753 }
754 } 743 }
755 744
756 if (!band_rule_found) 745 if (!band_rule_found)
757 return -ERANGE; 746 return ERR_PTR(-ERANGE);
758 747
759 return -EINVAL; 748 return ERR_PTR(-EINVAL);
760} 749}
761 750
762int freq_reg_info(struct wiphy *wiphy, 751const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy,
763 u32 center_freq, 752 u32 center_freq)
764 u32 desired_bw_khz,
765 const struct ieee80211_reg_rule **reg_rule)
766{ 753{
767 assert_cfg80211_lock(); 754 const struct ieee80211_regdomain *regd;
768 return freq_reg_info_regd(wiphy, 755 struct regulatory_request *lr = get_last_request();
769 center_freq, 756
770 desired_bw_khz, 757 /*
771 reg_rule, 758 * Follow the driver's regulatory domain, if present, unless a country
772 NULL); 759 * IE has been processed or a user wants to help complaince further
760 */
761 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
762 lr->initiator != NL80211_REGDOM_SET_BY_USER &&
763 wiphy->regd)
764 regd = get_wiphy_regdom(wiphy);
765 else
766 regd = get_cfg80211_regdom();
767
768 return freq_reg_info_regd(wiphy, center_freq, regd);
773} 769}
774EXPORT_SYMBOL(freq_reg_info); 770EXPORT_SYMBOL(freq_reg_info);
775 771
@@ -792,7 +788,6 @@ static const char *reg_initiator_name(enum nl80211_reg_initiator initiator)
792} 788}
793 789
794static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan, 790static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
795 u32 desired_bw_khz,
796 const struct ieee80211_reg_rule *reg_rule) 791 const struct ieee80211_reg_rule *reg_rule)
797{ 792{
798 const struct ieee80211_power_rule *power_rule; 793 const struct ieee80211_power_rule *power_rule;
@@ -807,21 +802,16 @@ static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
807 else 802 else
808 snprintf(max_antenna_gain, 32, "%d", power_rule->max_antenna_gain); 803 snprintf(max_antenna_gain, 32, "%d", power_rule->max_antenna_gain);
809 804
810 REG_DBG_PRINT("Updating information on frequency %d MHz " 805 REG_DBG_PRINT("Updating information on frequency %d MHz with regulatory rule:\n",
811 "for a %d MHz width channel with regulatory rule:\n", 806 chan->center_freq);
812 chan->center_freq,
813 KHZ_TO_MHZ(desired_bw_khz));
814 807
815 REG_DBG_PRINT("%d KHz - %d KHz @ %d KHz), (%s mBi, %d mBm)\n", 808 REG_DBG_PRINT("%d KHz - %d KHz @ %d KHz), (%s mBi, %d mBm)\n",
816 freq_range->start_freq_khz, 809 freq_range->start_freq_khz, freq_range->end_freq_khz,
817 freq_range->end_freq_khz, 810 freq_range->max_bandwidth_khz, max_antenna_gain,
818 freq_range->max_bandwidth_khz,
819 max_antenna_gain,
820 power_rule->max_eirp); 811 power_rule->max_eirp);
821} 812}
822#else 813#else
823static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan, 814static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
824 u32 desired_bw_khz,
825 const struct ieee80211_reg_rule *reg_rule) 815 const struct ieee80211_reg_rule *reg_rule)
826{ 816{
827 return; 817 return;
@@ -831,43 +821,25 @@ static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
831/* 821/*
832 * Note that right now we assume the desired channel bandwidth 822 * Note that right now we assume the desired channel bandwidth
833 * is always 20 MHz for each individual channel (HT40 uses 20 MHz 823 * is always 20 MHz for each individual channel (HT40 uses 20 MHz
834 * per channel, the primary and the extension channel). To support 824 * per channel, the primary and the extension channel).
835 * smaller custom bandwidths such as 5 MHz or 10 MHz we'll need a
836 * new ieee80211_channel.target_bw and re run the regulatory check
837 * on the wiphy with the target_bw specified. Then we can simply use
838 * that below for the desired_bw_khz below.
839 */ 825 */
840static void handle_channel(struct wiphy *wiphy, 826static void handle_channel(struct wiphy *wiphy,
841 enum nl80211_reg_initiator initiator, 827 enum nl80211_reg_initiator initiator,
842 enum ieee80211_band band, 828 struct ieee80211_channel *chan)
843 unsigned int chan_idx)
844{ 829{
845 int r;
846 u32 flags, bw_flags = 0; 830 u32 flags, bw_flags = 0;
847 u32 desired_bw_khz = MHZ_TO_KHZ(20);
848 const struct ieee80211_reg_rule *reg_rule = NULL; 831 const struct ieee80211_reg_rule *reg_rule = NULL;
849 const struct ieee80211_power_rule *power_rule = NULL; 832 const struct ieee80211_power_rule *power_rule = NULL;
850 const struct ieee80211_freq_range *freq_range = NULL; 833 const struct ieee80211_freq_range *freq_range = NULL;
851 struct ieee80211_supported_band *sband;
852 struct ieee80211_channel *chan;
853 struct wiphy *request_wiphy = NULL; 834 struct wiphy *request_wiphy = NULL;
835 struct regulatory_request *lr = get_last_request();
854 836
855 assert_cfg80211_lock(); 837 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
856
857 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
858
859 sband = wiphy->bands[band];
860 BUG_ON(chan_idx >= sband->n_channels);
861 chan = &sband->channels[chan_idx];
862 838
863 flags = chan->orig_flags; 839 flags = chan->orig_flags;
864 840
865 r = freq_reg_info(wiphy, 841 reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
866 MHZ_TO_KHZ(chan->center_freq), 842 if (IS_ERR(reg_rule)) {
867 desired_bw_khz,
868 &reg_rule);
869
870 if (r) {
871 /* 843 /*
872 * We will disable all channels that do not match our 844 * We will disable all channels that do not match our
873 * received regulatory rule unless the hint is coming 845 * received regulatory rule unless the hint is coming
@@ -879,7 +851,7 @@ static void handle_channel(struct wiphy *wiphy,
879 * while 5 GHz is still supported. 851 * while 5 GHz is still supported.
880 */ 852 */
881 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && 853 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE &&
882 r == -ERANGE) 854 PTR_ERR(reg_rule) == -ERANGE)
883 return; 855 return;
884 856
885 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq); 857 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
@@ -887,7 +859,7 @@ static void handle_channel(struct wiphy *wiphy,
887 return; 859 return;
888 } 860 }
889 861
890 chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule); 862 chan_reg_rule_print_dbg(chan, reg_rule);
891 863
892 power_rule = &reg_rule->power_rule; 864 power_rule = &reg_rule->power_rule;
893 freq_range = &reg_rule->freq_range; 865 freq_range = &reg_rule->freq_range;
@@ -895,7 +867,7 @@ static void handle_channel(struct wiphy *wiphy,
895 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40)) 867 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40))
896 bw_flags = IEEE80211_CHAN_NO_HT40; 868 bw_flags = IEEE80211_CHAN_NO_HT40;
897 869
898 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && 870 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
899 request_wiphy && request_wiphy == wiphy && 871 request_wiphy && request_wiphy == wiphy &&
900 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) { 872 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
901 /* 873 /*
@@ -914,8 +886,9 @@ static void handle_channel(struct wiphy *wiphy,
914 886
915 chan->beacon_found = false; 887 chan->beacon_found = false;
916 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); 888 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags);
917 chan->max_antenna_gain = min(chan->orig_mag, 889 chan->max_antenna_gain =
918 (int) MBI_TO_DBI(power_rule->max_antenna_gain)); 890 min_t(int, chan->orig_mag,
891 MBI_TO_DBI(power_rule->max_antenna_gain));
919 chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); 892 chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp);
920 if (chan->orig_mpwr) { 893 if (chan->orig_mpwr) {
921 /* 894 /*
@@ -935,68 +908,65 @@ static void handle_channel(struct wiphy *wiphy,
935} 908}
936 909
937static void handle_band(struct wiphy *wiphy, 910static void handle_band(struct wiphy *wiphy,
938 enum ieee80211_band band, 911 enum nl80211_reg_initiator initiator,
939 enum nl80211_reg_initiator initiator) 912 struct ieee80211_supported_band *sband)
940{ 913{
941 unsigned int i; 914 unsigned int i;
942 struct ieee80211_supported_band *sband;
943 915
944 BUG_ON(!wiphy->bands[band]); 916 if (!sband)
945 sband = wiphy->bands[band]; 917 return;
946 918
947 for (i = 0; i < sband->n_channels; i++) 919 for (i = 0; i < sband->n_channels; i++)
948 handle_channel(wiphy, initiator, band, i); 920 handle_channel(wiphy, initiator, &sband->channels[i]);
949} 921}
950 922
951static bool reg_request_cell_base(struct regulatory_request *request) 923static bool reg_request_cell_base(struct regulatory_request *request)
952{ 924{
953 if (request->initiator != NL80211_REGDOM_SET_BY_USER) 925 if (request->initiator != NL80211_REGDOM_SET_BY_USER)
954 return false; 926 return false;
955 if (request->user_reg_hint_type != NL80211_USER_REG_HINT_CELL_BASE) 927 return request->user_reg_hint_type == NL80211_USER_REG_HINT_CELL_BASE;
956 return false;
957 return true;
958} 928}
959 929
960bool reg_last_request_cell_base(void) 930bool reg_last_request_cell_base(void)
961{ 931{
962 bool val; 932 bool val;
963 assert_cfg80211_lock();
964 933
965 mutex_lock(&reg_mutex); 934 mutex_lock(&reg_mutex);
966 val = reg_request_cell_base(last_request); 935 val = reg_request_cell_base(get_last_request());
967 mutex_unlock(&reg_mutex); 936 mutex_unlock(&reg_mutex);
937
968 return val; 938 return val;
969} 939}
970 940
971#ifdef CONFIG_CFG80211_CERTIFICATION_ONUS 941#ifdef CONFIG_CFG80211_CERTIFICATION_ONUS
972
973/* Core specific check */ 942/* Core specific check */
974static int reg_ignore_cell_hint(struct regulatory_request *pending_request) 943static enum reg_request_treatment
944reg_ignore_cell_hint(struct regulatory_request *pending_request)
975{ 945{
946 struct regulatory_request *lr = get_last_request();
947
976 if (!reg_num_devs_support_basehint) 948 if (!reg_num_devs_support_basehint)
977 return -EOPNOTSUPP; 949 return REG_REQ_IGNORE;
978 950
979 if (reg_request_cell_base(last_request)) { 951 if (reg_request_cell_base(lr) &&
980 if (!regdom_changes(pending_request->alpha2)) 952 !regdom_changes(pending_request->alpha2))
981 return -EALREADY; 953 return REG_REQ_ALREADY_SET;
982 return 0; 954
983 } 955 return REG_REQ_OK;
984 return 0;
985} 956}
986 957
987/* Device specific check */ 958/* Device specific check */
988static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy) 959static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy)
989{ 960{
990 if (!(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS)) 961 return !(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS);
991 return true;
992 return false;
993} 962}
994#else 963#else
995static int reg_ignore_cell_hint(struct regulatory_request *pending_request) 964static int reg_ignore_cell_hint(struct regulatory_request *pending_request)
996{ 965{
997 return -EOPNOTSUPP; 966 return REG_REQ_IGNORE;
998} 967}
999static int reg_dev_ignore_cell_hint(struct wiphy *wiphy) 968
969static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy)
1000{ 970{
1001 return true; 971 return true;
1002} 972}
@@ -1006,18 +976,17 @@ static int reg_dev_ignore_cell_hint(struct wiphy *wiphy)
1006static bool ignore_reg_update(struct wiphy *wiphy, 976static bool ignore_reg_update(struct wiphy *wiphy,
1007 enum nl80211_reg_initiator initiator) 977 enum nl80211_reg_initiator initiator)
1008{ 978{
1009 if (!last_request) { 979 struct regulatory_request *lr = get_last_request();
1010 REG_DBG_PRINT("Ignoring regulatory request %s since " 980
1011 "last_request is not set\n", 981 if (!lr) {
982 REG_DBG_PRINT("Ignoring regulatory request %s since last_request is not set\n",
1012 reg_initiator_name(initiator)); 983 reg_initiator_name(initiator));
1013 return true; 984 return true;
1014 } 985 }
1015 986
1016 if (initiator == NL80211_REGDOM_SET_BY_CORE && 987 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
1017 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) { 988 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) {
1018 REG_DBG_PRINT("Ignoring regulatory request %s " 989 REG_DBG_PRINT("Ignoring regulatory request %s since the driver uses its own custom regulatory domain\n",
1019 "since the driver uses its own custom "
1020 "regulatory domain\n",
1021 reg_initiator_name(initiator)); 990 reg_initiator_name(initiator));
1022 return true; 991 return true;
1023 } 992 }
@@ -1028,22 +997,35 @@ static bool ignore_reg_update(struct wiphy *wiphy,
1028 */ 997 */
1029 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd && 998 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
1030 initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && 999 initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1031 !is_world_regdom(last_request->alpha2)) { 1000 !is_world_regdom(lr->alpha2)) {
1032 REG_DBG_PRINT("Ignoring regulatory request %s " 1001 REG_DBG_PRINT("Ignoring regulatory request %s since the driver requires its own regulatory domain to be set first\n",
1033 "since the driver requires its own regulatory "
1034 "domain to be set first\n",
1035 reg_initiator_name(initiator)); 1002 reg_initiator_name(initiator));
1036 return true; 1003 return true;
1037 } 1004 }
1038 1005
1039 if (reg_request_cell_base(last_request)) 1006 if (reg_request_cell_base(lr))
1040 return reg_dev_ignore_cell_hint(wiphy); 1007 return reg_dev_ignore_cell_hint(wiphy);
1041 1008
1042 return false; 1009 return false;
1043} 1010}
1044 1011
1045static void handle_reg_beacon(struct wiphy *wiphy, 1012static bool reg_is_world_roaming(struct wiphy *wiphy)
1046 unsigned int chan_idx, 1013{
1014 const struct ieee80211_regdomain *cr = get_cfg80211_regdom();
1015 const struct ieee80211_regdomain *wr = get_wiphy_regdom(wiphy);
1016 struct regulatory_request *lr = get_last_request();
1017
1018 if (is_world_regdom(cr->alpha2) || (wr && is_world_regdom(wr->alpha2)))
1019 return true;
1020
1021 if (lr && lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1022 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1023 return true;
1024
1025 return false;
1026}
1027
1028static void handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx,
1047 struct reg_beacon *reg_beacon) 1029 struct reg_beacon *reg_beacon)
1048{ 1030{
1049 struct ieee80211_supported_band *sband; 1031 struct ieee80211_supported_band *sband;
@@ -1051,8 +1033,6 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1051 bool channel_changed = false; 1033 bool channel_changed = false;
1052 struct ieee80211_channel chan_before; 1034 struct ieee80211_channel chan_before;
1053 1035
1054 assert_cfg80211_lock();
1055
1056 sband = wiphy->bands[reg_beacon->chan.band]; 1036 sband = wiphy->bands[reg_beacon->chan.band];
1057 chan = &sband->channels[chan_idx]; 1037 chan = &sband->channels[chan_idx];
1058 1038
@@ -1064,6 +1044,9 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1064 1044
1065 chan->beacon_found = true; 1045 chan->beacon_found = true;
1066 1046
1047 if (!reg_is_world_roaming(wiphy))
1048 return;
1049
1067 if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS) 1050 if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS)
1068 return; 1051 return;
1069 1052
@@ -1094,8 +1077,6 @@ static void wiphy_update_new_beacon(struct wiphy *wiphy,
1094 unsigned int i; 1077 unsigned int i;
1095 struct ieee80211_supported_band *sband; 1078 struct ieee80211_supported_band *sband;
1096 1079
1097 assert_cfg80211_lock();
1098
1099 if (!wiphy->bands[reg_beacon->chan.band]) 1080 if (!wiphy->bands[reg_beacon->chan.band])
1100 return; 1081 return;
1101 1082
@@ -1114,11 +1095,6 @@ static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1114 struct ieee80211_supported_band *sband; 1095 struct ieee80211_supported_band *sband;
1115 struct reg_beacon *reg_beacon; 1096 struct reg_beacon *reg_beacon;
1116 1097
1117 assert_cfg80211_lock();
1118
1119 if (list_empty(&reg_beacon_list))
1120 return;
1121
1122 list_for_each_entry(reg_beacon, &reg_beacon_list, list) { 1098 list_for_each_entry(reg_beacon, &reg_beacon_list, list) {
1123 if (!wiphy->bands[reg_beacon->chan.band]) 1099 if (!wiphy->bands[reg_beacon->chan.band])
1124 continue; 1100 continue;
@@ -1128,18 +1104,6 @@ static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1128 } 1104 }
1129} 1105}
1130 1106
1131static bool reg_is_world_roaming(struct wiphy *wiphy)
1132{
1133 if (is_world_regdom(cfg80211_regdomain->alpha2) ||
1134 (wiphy->regd && is_world_regdom(wiphy->regd->alpha2)))
1135 return true;
1136 if (last_request &&
1137 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1138 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1139 return true;
1140 return false;
1141}
1142
1143/* Reap the advantages of previously found beacons */ 1107/* Reap the advantages of previously found beacons */
1144static void reg_process_beacons(struct wiphy *wiphy) 1108static void reg_process_beacons(struct wiphy *wiphy)
1145{ 1109{
@@ -1149,39 +1113,29 @@ static void reg_process_beacons(struct wiphy *wiphy)
1149 */ 1113 */
1150 if (!last_request) 1114 if (!last_request)
1151 return; 1115 return;
1152 if (!reg_is_world_roaming(wiphy))
1153 return;
1154 wiphy_update_beacon_reg(wiphy); 1116 wiphy_update_beacon_reg(wiphy);
1155} 1117}
1156 1118
1157static bool is_ht40_not_allowed(struct ieee80211_channel *chan) 1119static bool is_ht40_allowed(struct ieee80211_channel *chan)
1158{ 1120{
1159 if (!chan) 1121 if (!chan)
1160 return true; 1122 return false;
1161 if (chan->flags & IEEE80211_CHAN_DISABLED) 1123 if (chan->flags & IEEE80211_CHAN_DISABLED)
1162 return true; 1124 return false;
1163 /* This would happen when regulatory rules disallow HT40 completely */ 1125 /* This would happen when regulatory rules disallow HT40 completely */
1164 if (IEEE80211_CHAN_NO_HT40 == (chan->flags & (IEEE80211_CHAN_NO_HT40))) 1126 if ((chan->flags & IEEE80211_CHAN_NO_HT40) == IEEE80211_CHAN_NO_HT40)
1165 return true; 1127 return false;
1166 return false; 1128 return true;
1167} 1129}
1168 1130
1169static void reg_process_ht_flags_channel(struct wiphy *wiphy, 1131static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1170 enum ieee80211_band band, 1132 struct ieee80211_channel *channel)
1171 unsigned int chan_idx)
1172{ 1133{
1173 struct ieee80211_supported_band *sband; 1134 struct ieee80211_supported_band *sband = wiphy->bands[channel->band];
1174 struct ieee80211_channel *channel;
1175 struct ieee80211_channel *channel_before = NULL, *channel_after = NULL; 1135 struct ieee80211_channel *channel_before = NULL, *channel_after = NULL;
1176 unsigned int i; 1136 unsigned int i;
1177 1137
1178 assert_cfg80211_lock(); 1138 if (!is_ht40_allowed(channel)) {
1179
1180 sband = wiphy->bands[band];
1181 BUG_ON(chan_idx >= sband->n_channels);
1182 channel = &sband->channels[chan_idx];
1183
1184 if (is_ht40_not_allowed(channel)) {
1185 channel->flags |= IEEE80211_CHAN_NO_HT40; 1139 channel->flags |= IEEE80211_CHAN_NO_HT40;
1186 return; 1140 return;
1187 } 1141 }
@@ -1192,6 +1146,7 @@ static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1192 */ 1146 */
1193 for (i = 0; i < sband->n_channels; i++) { 1147 for (i = 0; i < sband->n_channels; i++) {
1194 struct ieee80211_channel *c = &sband->channels[i]; 1148 struct ieee80211_channel *c = &sband->channels[i];
1149
1195 if (c->center_freq == (channel->center_freq - 20)) 1150 if (c->center_freq == (channel->center_freq - 20))
1196 channel_before = c; 1151 channel_before = c;
1197 if (c->center_freq == (channel->center_freq + 20)) 1152 if (c->center_freq == (channel->center_freq + 20))
@@ -1203,28 +1158,27 @@ static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1203 * if that ever changes we also need to change the below logic 1158 * if that ever changes we also need to change the below logic
1204 * to include that as well. 1159 * to include that as well.
1205 */ 1160 */
1206 if (is_ht40_not_allowed(channel_before)) 1161 if (!is_ht40_allowed(channel_before))
1207 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; 1162 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
1208 else 1163 else
1209 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; 1164 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
1210 1165
1211 if (is_ht40_not_allowed(channel_after)) 1166 if (!is_ht40_allowed(channel_after))
1212 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; 1167 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
1213 else 1168 else
1214 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; 1169 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
1215} 1170}
1216 1171
1217static void reg_process_ht_flags_band(struct wiphy *wiphy, 1172static void reg_process_ht_flags_band(struct wiphy *wiphy,
1218 enum ieee80211_band band) 1173 struct ieee80211_supported_band *sband)
1219{ 1174{
1220 unsigned int i; 1175 unsigned int i;
1221 struct ieee80211_supported_band *sband;
1222 1176
1223 BUG_ON(!wiphy->bands[band]); 1177 if (!sband)
1224 sband = wiphy->bands[band]; 1178 return;
1225 1179
1226 for (i = 0; i < sband->n_channels; i++) 1180 for (i = 0; i < sband->n_channels; i++)
1227 reg_process_ht_flags_channel(wiphy, band, i); 1181 reg_process_ht_flags_channel(wiphy, &sband->channels[i]);
1228} 1182}
1229 1183
1230static void reg_process_ht_flags(struct wiphy *wiphy) 1184static void reg_process_ht_flags(struct wiphy *wiphy)
@@ -1234,34 +1188,29 @@ static void reg_process_ht_flags(struct wiphy *wiphy)
1234 if (!wiphy) 1188 if (!wiphy)
1235 return; 1189 return;
1236 1190
1237 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1191 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1238 if (wiphy->bands[band]) 1192 reg_process_ht_flags_band(wiphy, wiphy->bands[band]);
1239 reg_process_ht_flags_band(wiphy, band);
1240 }
1241
1242} 1193}
1243 1194
1244static void wiphy_update_regulatory(struct wiphy *wiphy, 1195static void wiphy_update_regulatory(struct wiphy *wiphy,
1245 enum nl80211_reg_initiator initiator) 1196 enum nl80211_reg_initiator initiator)
1246{ 1197{
1247 enum ieee80211_band band; 1198 enum ieee80211_band band;
1248 1199 struct regulatory_request *lr = get_last_request();
1249 assert_reg_lock();
1250 1200
1251 if (ignore_reg_update(wiphy, initiator)) 1201 if (ignore_reg_update(wiphy, initiator))
1252 return; 1202 return;
1253 1203
1254 last_request->dfs_region = cfg80211_regdomain->dfs_region; 1204 lr->dfs_region = get_cfg80211_regdom()->dfs_region;
1255 1205
1256 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1206 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1257 if (wiphy->bands[band]) 1207 handle_band(wiphy, initiator, wiphy->bands[band]);
1258 handle_band(wiphy, band, initiator);
1259 }
1260 1208
1261 reg_process_beacons(wiphy); 1209 reg_process_beacons(wiphy);
1262 reg_process_ht_flags(wiphy); 1210 reg_process_ht_flags(wiphy);
1211
1263 if (wiphy->reg_notifier) 1212 if (wiphy->reg_notifier)
1264 wiphy->reg_notifier(wiphy, last_request); 1213 wiphy->reg_notifier(wiphy, lr);
1265} 1214}
1266 1215
1267static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) 1216static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
@@ -1269,6 +1218,8 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
1269 struct cfg80211_registered_device *rdev; 1218 struct cfg80211_registered_device *rdev;
1270 struct wiphy *wiphy; 1219 struct wiphy *wiphy;
1271 1220
1221 assert_cfg80211_lock();
1222
1272 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 1223 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1273 wiphy = &rdev->wiphy; 1224 wiphy = &rdev->wiphy;
1274 wiphy_update_regulatory(wiphy, initiator); 1225 wiphy_update_regulatory(wiphy, initiator);
@@ -1280,47 +1231,30 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
1280 if (initiator == NL80211_REGDOM_SET_BY_CORE && 1231 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
1281 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY && 1232 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY &&
1282 wiphy->reg_notifier) 1233 wiphy->reg_notifier)
1283 wiphy->reg_notifier(wiphy, last_request); 1234 wiphy->reg_notifier(wiphy, get_last_request());
1284 } 1235 }
1285} 1236}
1286 1237
1287static void handle_channel_custom(struct wiphy *wiphy, 1238static void handle_channel_custom(struct wiphy *wiphy,
1288 enum ieee80211_band band, 1239 struct ieee80211_channel *chan,
1289 unsigned int chan_idx,
1290 const struct ieee80211_regdomain *regd) 1240 const struct ieee80211_regdomain *regd)
1291{ 1241{
1292 int r;
1293 u32 desired_bw_khz = MHZ_TO_KHZ(20);
1294 u32 bw_flags = 0; 1242 u32 bw_flags = 0;
1295 const struct ieee80211_reg_rule *reg_rule = NULL; 1243 const struct ieee80211_reg_rule *reg_rule = NULL;
1296 const struct ieee80211_power_rule *power_rule = NULL; 1244 const struct ieee80211_power_rule *power_rule = NULL;
1297 const struct ieee80211_freq_range *freq_range = NULL; 1245 const struct ieee80211_freq_range *freq_range = NULL;
1298 struct ieee80211_supported_band *sband;
1299 struct ieee80211_channel *chan;
1300
1301 assert_reg_lock();
1302 1246
1303 sband = wiphy->bands[band]; 1247 reg_rule = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq),
1304 BUG_ON(chan_idx >= sband->n_channels); 1248 regd);
1305 chan = &sband->channels[chan_idx];
1306
1307 r = freq_reg_info_regd(wiphy,
1308 MHZ_TO_KHZ(chan->center_freq),
1309 desired_bw_khz,
1310 &reg_rule,
1311 regd);
1312 1249
1313 if (r) { 1250 if (IS_ERR(reg_rule)) {
1314 REG_DBG_PRINT("Disabling freq %d MHz as custom " 1251 REG_DBG_PRINT("Disabling freq %d MHz as custom regd has no rule that fits it\n",
1315 "regd has no rule that fits a %d MHz " 1252 chan->center_freq);
1316 "wide channel\n",
1317 chan->center_freq,
1318 KHZ_TO_MHZ(desired_bw_khz));
1319 chan->flags = IEEE80211_CHAN_DISABLED; 1253 chan->flags = IEEE80211_CHAN_DISABLED;
1320 return; 1254 return;
1321 } 1255 }
1322 1256
1323 chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule); 1257 chan_reg_rule_print_dbg(chan, reg_rule);
1324 1258
1325 power_rule = &reg_rule->power_rule; 1259 power_rule = &reg_rule->power_rule;
1326 freq_range = &reg_rule->freq_range; 1260 freq_range = &reg_rule->freq_range;
@@ -1334,17 +1268,17 @@ static void handle_channel_custom(struct wiphy *wiphy,
1334 (int) MBM_TO_DBM(power_rule->max_eirp); 1268 (int) MBM_TO_DBM(power_rule->max_eirp);
1335} 1269}
1336 1270
1337static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band, 1271static void handle_band_custom(struct wiphy *wiphy,
1272 struct ieee80211_supported_band *sband,
1338 const struct ieee80211_regdomain *regd) 1273 const struct ieee80211_regdomain *regd)
1339{ 1274{
1340 unsigned int i; 1275 unsigned int i;
1341 struct ieee80211_supported_band *sband;
1342 1276
1343 BUG_ON(!wiphy->bands[band]); 1277 if (!sband)
1344 sband = wiphy->bands[band]; 1278 return;
1345 1279
1346 for (i = 0; i < sband->n_channels; i++) 1280 for (i = 0; i < sband->n_channels; i++)
1347 handle_channel_custom(wiphy, band, i, regd); 1281 handle_channel_custom(wiphy, &sband->channels[i], regd);
1348} 1282}
1349 1283
1350/* Used by drivers prior to wiphy registration */ 1284/* Used by drivers prior to wiphy registration */
@@ -1354,60 +1288,50 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
1354 enum ieee80211_band band; 1288 enum ieee80211_band band;
1355 unsigned int bands_set = 0; 1289 unsigned int bands_set = 0;
1356 1290
1357 mutex_lock(&reg_mutex);
1358 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1291 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1359 if (!wiphy->bands[band]) 1292 if (!wiphy->bands[band])
1360 continue; 1293 continue;
1361 handle_band_custom(wiphy, band, regd); 1294 handle_band_custom(wiphy, wiphy->bands[band], regd);
1362 bands_set++; 1295 bands_set++;
1363 } 1296 }
1364 mutex_unlock(&reg_mutex);
1365 1297
1366 /* 1298 /*
1367 * no point in calling this if it won't have any effect 1299 * no point in calling this if it won't have any effect
1368 * on your device's supportd bands. 1300 * on your device's supported bands.
1369 */ 1301 */
1370 WARN_ON(!bands_set); 1302 WARN_ON(!bands_set);
1371} 1303}
1372EXPORT_SYMBOL(wiphy_apply_custom_regulatory); 1304EXPORT_SYMBOL(wiphy_apply_custom_regulatory);
1373 1305
1374/*
1375 * Return value which can be used by ignore_request() to indicate
1376 * it has been determined we should intersect two regulatory domains
1377 */
1378#define REG_INTERSECT 1
1379
1380/* This has the logic which determines when a new request 1306/* This has the logic which determines when a new request
1381 * should be ignored. */ 1307 * should be ignored. */
1382static int ignore_request(struct wiphy *wiphy, 1308static enum reg_request_treatment
1309get_reg_request_treatment(struct wiphy *wiphy,
1383 struct regulatory_request *pending_request) 1310 struct regulatory_request *pending_request)
1384{ 1311{
1385 struct wiphy *last_wiphy = NULL; 1312 struct wiphy *last_wiphy = NULL;
1386 1313 struct regulatory_request *lr = get_last_request();
1387 assert_cfg80211_lock();
1388 1314
1389 /* All initial requests are respected */ 1315 /* All initial requests are respected */
1390 if (!last_request) 1316 if (!lr)
1391 return 0; 1317 return REG_REQ_OK;
1392 1318
1393 switch (pending_request->initiator) { 1319 switch (pending_request->initiator) {
1394 case NL80211_REGDOM_SET_BY_CORE: 1320 case NL80211_REGDOM_SET_BY_CORE:
1395 return 0; 1321 return REG_REQ_OK;
1396 case NL80211_REGDOM_SET_BY_COUNTRY_IE: 1322 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
1397 1323 if (reg_request_cell_base(lr)) {
1398 if (reg_request_cell_base(last_request)) {
1399 /* Trust a Cell base station over the AP's country IE */ 1324 /* Trust a Cell base station over the AP's country IE */
1400 if (regdom_changes(pending_request->alpha2)) 1325 if (regdom_changes(pending_request->alpha2))
1401 return -EOPNOTSUPP; 1326 return REG_REQ_IGNORE;
1402 return -EALREADY; 1327 return REG_REQ_ALREADY_SET;
1403 } 1328 }
1404 1329
1405 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 1330 last_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
1406 1331
1407 if (unlikely(!is_an_alpha2(pending_request->alpha2))) 1332 if (unlikely(!is_an_alpha2(pending_request->alpha2)))
1408 return -EINVAL; 1333 return -EINVAL;
1409 if (last_request->initiator == 1334 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1410 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1411 if (last_wiphy != wiphy) { 1335 if (last_wiphy != wiphy) {
1412 /* 1336 /*
1413 * Two cards with two APs claiming different 1337 * Two cards with two APs claiming different
@@ -1416,23 +1340,23 @@ static int ignore_request(struct wiphy *wiphy,
1416 * to be correct. Reject second one for now. 1340 * to be correct. Reject second one for now.
1417 */ 1341 */
1418 if (regdom_changes(pending_request->alpha2)) 1342 if (regdom_changes(pending_request->alpha2))
1419 return -EOPNOTSUPP; 1343 return REG_REQ_IGNORE;
1420 return -EALREADY; 1344 return REG_REQ_ALREADY_SET;
1421 } 1345 }
1422 /* 1346 /*
1423 * Two consecutive Country IE hints on the same wiphy. 1347 * Two consecutive Country IE hints on the same wiphy.
1424 * This should be picked up early by the driver/stack 1348 * This should be picked up early by the driver/stack
1425 */ 1349 */
1426 if (WARN_ON(regdom_changes(pending_request->alpha2))) 1350 if (WARN_ON(regdom_changes(pending_request->alpha2)))
1427 return 0; 1351 return REG_REQ_OK;
1428 return -EALREADY; 1352 return REG_REQ_ALREADY_SET;
1429 } 1353 }
1430 return 0; 1354 return 0;
1431 case NL80211_REGDOM_SET_BY_DRIVER: 1355 case NL80211_REGDOM_SET_BY_DRIVER:
1432 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) { 1356 if (lr->initiator == NL80211_REGDOM_SET_BY_CORE) {
1433 if (regdom_changes(pending_request->alpha2)) 1357 if (regdom_changes(pending_request->alpha2))
1434 return 0; 1358 return REG_REQ_OK;
1435 return -EALREADY; 1359 return REG_REQ_ALREADY_SET;
1436 } 1360 }
1437 1361
1438 /* 1362 /*
@@ -1440,59 +1364,59 @@ static int ignore_request(struct wiphy *wiphy,
1440 * back in or if you add a new device for which the previously 1364 * back in or if you add a new device for which the previously
1441 * loaded card also agrees on the regulatory domain. 1365 * loaded card also agrees on the regulatory domain.
1442 */ 1366 */
1443 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && 1367 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1444 !regdom_changes(pending_request->alpha2)) 1368 !regdom_changes(pending_request->alpha2))
1445 return -EALREADY; 1369 return REG_REQ_ALREADY_SET;
1446 1370
1447 return REG_INTERSECT; 1371 return REG_REQ_INTERSECT;
1448 case NL80211_REGDOM_SET_BY_USER: 1372 case NL80211_REGDOM_SET_BY_USER:
1449 if (reg_request_cell_base(pending_request)) 1373 if (reg_request_cell_base(pending_request))
1450 return reg_ignore_cell_hint(pending_request); 1374 return reg_ignore_cell_hint(pending_request);
1451 1375
1452 if (reg_request_cell_base(last_request)) 1376 if (reg_request_cell_base(lr))
1453 return -EOPNOTSUPP; 1377 return REG_REQ_IGNORE;
1454 1378
1455 if (last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) 1379 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
1456 return REG_INTERSECT; 1380 return REG_REQ_INTERSECT;
1457 /* 1381 /*
1458 * If the user knows better the user should set the regdom 1382 * If the user knows better the user should set the regdom
1459 * to their country before the IE is picked up 1383 * to their country before the IE is picked up
1460 */ 1384 */
1461 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER && 1385 if (lr->initiator == NL80211_REGDOM_SET_BY_USER &&
1462 last_request->intersect) 1386 lr->intersect)
1463 return -EOPNOTSUPP; 1387 return REG_REQ_IGNORE;
1464 /* 1388 /*
1465 * Process user requests only after previous user/driver/core 1389 * Process user requests only after previous user/driver/core
1466 * requests have been processed 1390 * requests have been processed
1467 */ 1391 */
1468 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE || 1392 if ((lr->initiator == NL80211_REGDOM_SET_BY_CORE ||
1469 last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER || 1393 lr->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
1470 last_request->initiator == NL80211_REGDOM_SET_BY_USER) { 1394 lr->initiator == NL80211_REGDOM_SET_BY_USER) &&
1471 if (regdom_changes(last_request->alpha2)) 1395 regdom_changes(lr->alpha2))
1472 return -EAGAIN; 1396 return REG_REQ_IGNORE;
1473 }
1474 1397
1475 if (!regdom_changes(pending_request->alpha2)) 1398 if (!regdom_changes(pending_request->alpha2))
1476 return -EALREADY; 1399 return REG_REQ_ALREADY_SET;
1477 1400
1478 return 0; 1401 return REG_REQ_OK;
1479 } 1402 }
1480 1403
1481 return -EINVAL; 1404 return REG_REQ_IGNORE;
1482} 1405}
1483 1406
1484static void reg_set_request_processed(void) 1407static void reg_set_request_processed(void)
1485{ 1408{
1486 bool need_more_processing = false; 1409 bool need_more_processing = false;
1410 struct regulatory_request *lr = get_last_request();
1487 1411
1488 last_request->processed = true; 1412 lr->processed = true;
1489 1413
1490 spin_lock(&reg_requests_lock); 1414 spin_lock(&reg_requests_lock);
1491 if (!list_empty(&reg_requests_list)) 1415 if (!list_empty(&reg_requests_list))
1492 need_more_processing = true; 1416 need_more_processing = true;
1493 spin_unlock(&reg_requests_lock); 1417 spin_unlock(&reg_requests_lock);
1494 1418
1495 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER) 1419 if (lr->initiator == NL80211_REGDOM_SET_BY_USER)
1496 cancel_delayed_work(&reg_timeout); 1420 cancel_delayed_work(&reg_timeout);
1497 1421
1498 if (need_more_processing) 1422 if (need_more_processing)
@@ -1508,116 +1432,122 @@ static void reg_set_request_processed(void)
1508 * The Wireless subsystem can use this function to hint to the wireless core 1432 * The Wireless subsystem can use this function to hint to the wireless core
1509 * what it believes should be the current regulatory domain. 1433 * what it believes should be the current regulatory domain.
1510 * 1434 *
1511 * Returns zero if all went fine, %-EALREADY if a regulatory domain had 1435 * Returns one of the different reg request treatment values.
1512 * already been set or other standard error codes.
1513 * 1436 *
1514 * Caller must hold &cfg80211_mutex and &reg_mutex 1437 * Caller must hold &reg_mutex
1515 */ 1438 */
1516static int __regulatory_hint(struct wiphy *wiphy, 1439static enum reg_request_treatment
1517 struct regulatory_request *pending_request) 1440__regulatory_hint(struct wiphy *wiphy,
1441 struct regulatory_request *pending_request)
1518{ 1442{
1443 const struct ieee80211_regdomain *regd;
1519 bool intersect = false; 1444 bool intersect = false;
1520 int r = 0; 1445 enum reg_request_treatment treatment;
1521 1446 struct regulatory_request *lr;
1522 assert_cfg80211_lock();
1523 1447
1524 r = ignore_request(wiphy, pending_request); 1448 treatment = get_reg_request_treatment(wiphy, pending_request);
1525 1449
1526 if (r == REG_INTERSECT) { 1450 switch (treatment) {
1451 case REG_REQ_INTERSECT:
1527 if (pending_request->initiator == 1452 if (pending_request->initiator ==
1528 NL80211_REGDOM_SET_BY_DRIVER) { 1453 NL80211_REGDOM_SET_BY_DRIVER) {
1529 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); 1454 regd = reg_copy_regd(get_cfg80211_regdom());
1530 if (r) { 1455 if (IS_ERR(regd)) {
1531 kfree(pending_request); 1456 kfree(pending_request);
1532 return r; 1457 return PTR_ERR(regd);
1533 } 1458 }
1459 rcu_assign_pointer(wiphy->regd, regd);
1534 } 1460 }
1535 intersect = true; 1461 intersect = true;
1536 } else if (r) { 1462 break;
1463 case REG_REQ_OK:
1464 break;
1465 default:
1537 /* 1466 /*
1538 * If the regulatory domain being requested by the 1467 * If the regulatory domain being requested by the
1539 * driver has already been set just copy it to the 1468 * driver has already been set just copy it to the
1540 * wiphy 1469 * wiphy
1541 */ 1470 */
1542 if (r == -EALREADY && 1471 if (treatment == REG_REQ_ALREADY_SET &&
1543 pending_request->initiator == 1472 pending_request->initiator == NL80211_REGDOM_SET_BY_DRIVER) {
1544 NL80211_REGDOM_SET_BY_DRIVER) { 1473 regd = reg_copy_regd(get_cfg80211_regdom());
1545 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); 1474 if (IS_ERR(regd)) {
1546 if (r) {
1547 kfree(pending_request); 1475 kfree(pending_request);
1548 return r; 1476 return REG_REQ_IGNORE;
1549 } 1477 }
1550 r = -EALREADY; 1478 treatment = REG_REQ_ALREADY_SET;
1479 rcu_assign_pointer(wiphy->regd, regd);
1551 goto new_request; 1480 goto new_request;
1552 } 1481 }
1553 kfree(pending_request); 1482 kfree(pending_request);
1554 return r; 1483 return treatment;
1555 } 1484 }
1556 1485
1557new_request: 1486new_request:
1558 if (last_request != &core_request_world) 1487 lr = get_last_request();
1559 kfree(last_request); 1488 if (lr != &core_request_world && lr)
1489 kfree_rcu(lr, rcu_head);
1560 1490
1561 last_request = pending_request; 1491 pending_request->intersect = intersect;
1562 last_request->intersect = intersect; 1492 pending_request->processed = false;
1493 rcu_assign_pointer(last_request, pending_request);
1494 lr = pending_request;
1563 1495
1564 pending_request = NULL; 1496 pending_request = NULL;
1565 1497
1566 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER) { 1498 if (lr->initiator == NL80211_REGDOM_SET_BY_USER) {
1567 user_alpha2[0] = last_request->alpha2[0]; 1499 user_alpha2[0] = lr->alpha2[0];
1568 user_alpha2[1] = last_request->alpha2[1]; 1500 user_alpha2[1] = lr->alpha2[1];
1569 } 1501 }
1570 1502
1571 /* When r == REG_INTERSECT we do need to call CRDA */ 1503 /* When r == REG_REQ_INTERSECT we do need to call CRDA */
1572 if (r < 0) { 1504 if (treatment != REG_REQ_OK && treatment != REG_REQ_INTERSECT) {
1573 /* 1505 /*
1574 * Since CRDA will not be called in this case as we already 1506 * Since CRDA will not be called in this case as we already
1575 * have applied the requested regulatory domain before we just 1507 * have applied the requested regulatory domain before we just
1576 * inform userspace we have processed the request 1508 * inform userspace we have processed the request
1577 */ 1509 */
1578 if (r == -EALREADY) { 1510 if (treatment == REG_REQ_ALREADY_SET) {
1579 nl80211_send_reg_change_event(last_request); 1511 nl80211_send_reg_change_event(lr);
1580 reg_set_request_processed(); 1512 reg_set_request_processed();
1581 } 1513 }
1582 return r; 1514 return treatment;
1583 } 1515 }
1584 1516
1585 return call_crda(last_request->alpha2); 1517 if (call_crda(lr->alpha2))
1518 return REG_REQ_IGNORE;
1519 return REG_REQ_OK;
1586} 1520}
1587 1521
1588/* This processes *all* regulatory hints */ 1522/* This processes *all* regulatory hints */
1589static void reg_process_hint(struct regulatory_request *reg_request, 1523static void reg_process_hint(struct regulatory_request *reg_request,
1590 enum nl80211_reg_initiator reg_initiator) 1524 enum nl80211_reg_initiator reg_initiator)
1591{ 1525{
1592 int r = 0;
1593 struct wiphy *wiphy = NULL; 1526 struct wiphy *wiphy = NULL;
1594 1527
1595 BUG_ON(!reg_request->alpha2); 1528 if (WARN_ON(!reg_request->alpha2))
1529 return;
1596 1530
1597 if (wiphy_idx_valid(reg_request->wiphy_idx)) 1531 if (reg_request->wiphy_idx != WIPHY_IDX_INVALID)
1598 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); 1532 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
1599 1533
1600 if (reg_initiator == NL80211_REGDOM_SET_BY_DRIVER && 1534 if (reg_initiator == NL80211_REGDOM_SET_BY_DRIVER && !wiphy) {
1601 !wiphy) {
1602 kfree(reg_request); 1535 kfree(reg_request);
1603 return; 1536 return;
1604 } 1537 }
1605 1538
1606 r = __regulatory_hint(wiphy, reg_request); 1539 switch (__regulatory_hint(wiphy, reg_request)) {
1607 /* This is required so that the orig_* parameters are saved */ 1540 case REG_REQ_ALREADY_SET:
1608 if (r == -EALREADY && wiphy && 1541 /* This is required so that the orig_* parameters are saved */
1609 wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) { 1542 if (wiphy && wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY)
1610 wiphy_update_regulatory(wiphy, reg_initiator); 1543 wiphy_update_regulatory(wiphy, reg_initiator);
1611 return; 1544 break;
1545 default:
1546 if (reg_initiator == NL80211_REGDOM_SET_BY_USER)
1547 schedule_delayed_work(&reg_timeout,
1548 msecs_to_jiffies(3142));
1549 break;
1612 } 1550 }
1613
1614 /*
1615 * We only time out user hints, given that they should be the only
1616 * source of bogus requests.
1617 */
1618 if (r != -EALREADY &&
1619 reg_initiator == NL80211_REGDOM_SET_BY_USER)
1620 schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142));
1621} 1551}
1622 1552
1623/* 1553/*
@@ -1627,15 +1557,15 @@ static void reg_process_hint(struct regulatory_request *reg_request,
1627 */ 1557 */
1628static void reg_process_pending_hints(void) 1558static void reg_process_pending_hints(void)
1629{ 1559{
1630 struct regulatory_request *reg_request; 1560 struct regulatory_request *reg_request, *lr;
1631 1561
1632 mutex_lock(&cfg80211_mutex); 1562 mutex_lock(&cfg80211_mutex);
1633 mutex_lock(&reg_mutex); 1563 mutex_lock(&reg_mutex);
1564 lr = get_last_request();
1634 1565
1635 /* When last_request->processed becomes true this will be rescheduled */ 1566 /* When last_request->processed becomes true this will be rescheduled */
1636 if (last_request && !last_request->processed) { 1567 if (lr && !lr->processed) {
1637 REG_DBG_PRINT("Pending regulatory request, waiting " 1568 REG_DBG_PRINT("Pending regulatory request, waiting for it to be processed...\n");
1638 "for it to be processed...\n");
1639 goto out; 1569 goto out;
1640 } 1570 }
1641 1571
@@ -1666,23 +1596,14 @@ static void reg_process_pending_beacon_hints(void)
1666 struct cfg80211_registered_device *rdev; 1596 struct cfg80211_registered_device *rdev;
1667 struct reg_beacon *pending_beacon, *tmp; 1597 struct reg_beacon *pending_beacon, *tmp;
1668 1598
1669 /*
1670 * No need to hold the reg_mutex here as we just touch wiphys
1671 * and do not read or access regulatory variables.
1672 */
1673 mutex_lock(&cfg80211_mutex); 1599 mutex_lock(&cfg80211_mutex);
1600 mutex_lock(&reg_mutex);
1674 1601
1675 /* This goes through the _pending_ beacon list */ 1602 /* This goes through the _pending_ beacon list */
1676 spin_lock_bh(&reg_pending_beacons_lock); 1603 spin_lock_bh(&reg_pending_beacons_lock);
1677 1604
1678 if (list_empty(&reg_pending_beacons)) {
1679 spin_unlock_bh(&reg_pending_beacons_lock);
1680 goto out;
1681 }
1682
1683 list_for_each_entry_safe(pending_beacon, tmp, 1605 list_for_each_entry_safe(pending_beacon, tmp,
1684 &reg_pending_beacons, list) { 1606 &reg_pending_beacons, list) {
1685
1686 list_del_init(&pending_beacon->list); 1607 list_del_init(&pending_beacon->list);
1687 1608
1688 /* Applies the beacon hint to current wiphys */ 1609 /* Applies the beacon hint to current wiphys */
@@ -1694,7 +1615,7 @@ static void reg_process_pending_beacon_hints(void)
1694 } 1615 }
1695 1616
1696 spin_unlock_bh(&reg_pending_beacons_lock); 1617 spin_unlock_bh(&reg_pending_beacons_lock);
1697out: 1618 mutex_unlock(&reg_mutex);
1698 mutex_unlock(&cfg80211_mutex); 1619 mutex_unlock(&cfg80211_mutex);
1699} 1620}
1700 1621
@@ -1706,10 +1627,8 @@ static void reg_todo(struct work_struct *work)
1706 1627
1707static void queue_regulatory_request(struct regulatory_request *request) 1628static void queue_regulatory_request(struct regulatory_request *request)
1708{ 1629{
1709 if (isalpha(request->alpha2[0])) 1630 request->alpha2[0] = toupper(request->alpha2[0]);
1710 request->alpha2[0] = toupper(request->alpha2[0]); 1631 request->alpha2[1] = toupper(request->alpha2[1]);
1711 if (isalpha(request->alpha2[1]))
1712 request->alpha2[1] = toupper(request->alpha2[1]);
1713 1632
1714 spin_lock(&reg_requests_lock); 1633 spin_lock(&reg_requests_lock);
1715 list_add_tail(&request->list, &reg_requests_list); 1634 list_add_tail(&request->list, &reg_requests_list);
@@ -1726,8 +1645,7 @@ static int regulatory_hint_core(const char *alpha2)
1726{ 1645{
1727 struct regulatory_request *request; 1646 struct regulatory_request *request;
1728 1647
1729 request = kzalloc(sizeof(struct regulatory_request), 1648 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1730 GFP_KERNEL);
1731 if (!request) 1649 if (!request)
1732 return -ENOMEM; 1650 return -ENOMEM;
1733 1651
@@ -1746,13 +1664,14 @@ int regulatory_hint_user(const char *alpha2,
1746{ 1664{
1747 struct regulatory_request *request; 1665 struct regulatory_request *request;
1748 1666
1749 BUG_ON(!alpha2); 1667 if (WARN_ON(!alpha2))
1668 return -EINVAL;
1750 1669
1751 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); 1670 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1752 if (!request) 1671 if (!request)
1753 return -ENOMEM; 1672 return -ENOMEM;
1754 1673
1755 request->wiphy_idx = WIPHY_IDX_STALE; 1674 request->wiphy_idx = WIPHY_IDX_INVALID;
1756 request->alpha2[0] = alpha2[0]; 1675 request->alpha2[0] = alpha2[0];
1757 request->alpha2[1] = alpha2[1]; 1676 request->alpha2[1] = alpha2[1];
1758 request->initiator = NL80211_REGDOM_SET_BY_USER; 1677 request->initiator = NL80211_REGDOM_SET_BY_USER;
@@ -1768,8 +1687,8 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1768{ 1687{
1769 struct regulatory_request *request; 1688 struct regulatory_request *request;
1770 1689
1771 BUG_ON(!alpha2); 1690 if (WARN_ON(!alpha2 || !wiphy))
1772 BUG_ON(!wiphy); 1691 return -EINVAL;
1773 1692
1774 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); 1693 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1775 if (!request) 1694 if (!request)
@@ -1777,9 +1696,6 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1777 1696
1778 request->wiphy_idx = get_wiphy_idx(wiphy); 1697 request->wiphy_idx = get_wiphy_idx(wiphy);
1779 1698
1780 /* Must have registered wiphy first */
1781 BUG_ON(!wiphy_idx_valid(request->wiphy_idx));
1782
1783 request->alpha2[0] = alpha2[0]; 1699 request->alpha2[0] = alpha2[0];
1784 request->alpha2[1] = alpha2[1]; 1700 request->alpha2[1] = alpha2[1];
1785 request->initiator = NL80211_REGDOM_SET_BY_DRIVER; 1701 request->initiator = NL80211_REGDOM_SET_BY_DRIVER;
@@ -1794,18 +1710,17 @@ EXPORT_SYMBOL(regulatory_hint);
1794 * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and 1710 * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and
1795 * therefore cannot iterate over the rdev list here. 1711 * therefore cannot iterate over the rdev list here.
1796 */ 1712 */
1797void regulatory_hint_11d(struct wiphy *wiphy, 1713void regulatory_hint_11d(struct wiphy *wiphy, enum ieee80211_band band,
1798 enum ieee80211_band band, 1714 const u8 *country_ie, u8 country_ie_len)
1799 const u8 *country_ie,
1800 u8 country_ie_len)
1801{ 1715{
1802 char alpha2[2]; 1716 char alpha2[2];
1803 enum environment_cap env = ENVIRON_ANY; 1717 enum environment_cap env = ENVIRON_ANY;
1804 struct regulatory_request *request; 1718 struct regulatory_request *request, *lr;
1805 1719
1806 mutex_lock(&reg_mutex); 1720 mutex_lock(&reg_mutex);
1721 lr = get_last_request();
1807 1722
1808 if (unlikely(!last_request)) 1723 if (unlikely(!lr))
1809 goto out; 1724 goto out;
1810 1725
1811 /* IE len must be evenly divisible by 2 */ 1726 /* IE len must be evenly divisible by 2 */
@@ -1828,9 +1743,8 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1828 * We leave conflict resolution to the workqueue, where can hold 1743 * We leave conflict resolution to the workqueue, where can hold
1829 * cfg80211_mutex. 1744 * cfg80211_mutex.
1830 */ 1745 */
1831 if (likely(last_request->initiator == 1746 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1832 NL80211_REGDOM_SET_BY_COUNTRY_IE && 1747 lr->wiphy_idx != WIPHY_IDX_INVALID)
1833 wiphy_idx_valid(last_request->wiphy_idx)))
1834 goto out; 1748 goto out;
1835 1749
1836 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); 1750 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
@@ -1843,12 +1757,7 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1843 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; 1757 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE;
1844 request->country_ie_env = env; 1758 request->country_ie_env = env;
1845 1759
1846 mutex_unlock(&reg_mutex);
1847
1848 queue_regulatory_request(request); 1760 queue_regulatory_request(request);
1849
1850 return;
1851
1852out: 1761out:
1853 mutex_unlock(&reg_mutex); 1762 mutex_unlock(&reg_mutex);
1854} 1763}
@@ -1863,8 +1772,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1863 if (is_user_regdom_saved()) { 1772 if (is_user_regdom_saved()) {
1864 /* Unless we're asked to ignore it and reset it */ 1773 /* Unless we're asked to ignore it and reset it */
1865 if (reset_user) { 1774 if (reset_user) {
1866 REG_DBG_PRINT("Restoring regulatory settings " 1775 REG_DBG_PRINT("Restoring regulatory settings including user preference\n");
1867 "including user preference\n");
1868 user_alpha2[0] = '9'; 1776 user_alpha2[0] = '9';
1869 user_alpha2[1] = '7'; 1777 user_alpha2[1] = '7';
1870 1778
@@ -1874,26 +1782,20 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1874 * back as they were for a full restore. 1782 * back as they were for a full restore.
1875 */ 1783 */
1876 if (!is_world_regdom(ieee80211_regdom)) { 1784 if (!is_world_regdom(ieee80211_regdom)) {
1877 REG_DBG_PRINT("Keeping preference on " 1785 REG_DBG_PRINT("Keeping preference on module parameter ieee80211_regdom: %c%c\n",
1878 "module parameter ieee80211_regdom: %c%c\n", 1786 ieee80211_regdom[0], ieee80211_regdom[1]);
1879 ieee80211_regdom[0],
1880 ieee80211_regdom[1]);
1881 alpha2[0] = ieee80211_regdom[0]; 1787 alpha2[0] = ieee80211_regdom[0];
1882 alpha2[1] = ieee80211_regdom[1]; 1788 alpha2[1] = ieee80211_regdom[1];
1883 } 1789 }
1884 } else { 1790 } else {
1885 REG_DBG_PRINT("Restoring regulatory settings " 1791 REG_DBG_PRINT("Restoring regulatory settings while preserving user preference for: %c%c\n",
1886 "while preserving user preference for: %c%c\n", 1792 user_alpha2[0], user_alpha2[1]);
1887 user_alpha2[0],
1888 user_alpha2[1]);
1889 alpha2[0] = user_alpha2[0]; 1793 alpha2[0] = user_alpha2[0];
1890 alpha2[1] = user_alpha2[1]; 1794 alpha2[1] = user_alpha2[1];
1891 } 1795 }
1892 } else if (!is_world_regdom(ieee80211_regdom)) { 1796 } else if (!is_world_regdom(ieee80211_regdom)) {
1893 REG_DBG_PRINT("Keeping preference on " 1797 REG_DBG_PRINT("Keeping preference on module parameter ieee80211_regdom: %c%c\n",
1894 "module parameter ieee80211_regdom: %c%c\n", 1798 ieee80211_regdom[0], ieee80211_regdom[1]);
1895 ieee80211_regdom[0],
1896 ieee80211_regdom[1]);
1897 alpha2[0] = ieee80211_regdom[0]; 1799 alpha2[0] = ieee80211_regdom[0];
1898 alpha2[1] = ieee80211_regdom[1]; 1800 alpha2[1] = ieee80211_regdom[1];
1899 } else 1801 } else
@@ -1948,7 +1850,7 @@ static void restore_regulatory_settings(bool reset_user)
1948 mutex_lock(&cfg80211_mutex); 1850 mutex_lock(&cfg80211_mutex);
1949 mutex_lock(&reg_mutex); 1851 mutex_lock(&reg_mutex);
1950 1852
1951 reset_regdomains(true); 1853 reset_regdomains(true, &world_regdom);
1952 restore_alpha2(alpha2, reset_user); 1854 restore_alpha2(alpha2, reset_user);
1953 1855
1954 /* 1856 /*
@@ -1958,49 +1860,35 @@ static void restore_regulatory_settings(bool reset_user)
1958 * settings. 1860 * settings.
1959 */ 1861 */
1960 spin_lock(&reg_requests_lock); 1862 spin_lock(&reg_requests_lock);
1961 if (!list_empty(&reg_requests_list)) { 1863 list_for_each_entry_safe(reg_request, tmp, &reg_requests_list, list) {
1962 list_for_each_entry_safe(reg_request, tmp, 1864 if (reg_request->initiator != NL80211_REGDOM_SET_BY_USER)
1963 &reg_requests_list, list) { 1865 continue;
1964 if (reg_request->initiator != 1866 list_move_tail(&reg_request->list, &tmp_reg_req_list);
1965 NL80211_REGDOM_SET_BY_USER)
1966 continue;
1967 list_move_tail(&reg_request->list, &tmp_reg_req_list);
1968 }
1969 } 1867 }
1970 spin_unlock(&reg_requests_lock); 1868 spin_unlock(&reg_requests_lock);
1971 1869
1972 /* Clear beacon hints */ 1870 /* Clear beacon hints */
1973 spin_lock_bh(&reg_pending_beacons_lock); 1871 spin_lock_bh(&reg_pending_beacons_lock);
1974 if (!list_empty(&reg_pending_beacons)) { 1872 list_for_each_entry_safe(reg_beacon, btmp, &reg_pending_beacons, list) {
1975 list_for_each_entry_safe(reg_beacon, btmp, 1873 list_del(&reg_beacon->list);
1976 &reg_pending_beacons, list) { 1874 kfree(reg_beacon);
1977 list_del(&reg_beacon->list);
1978 kfree(reg_beacon);
1979 }
1980 } 1875 }
1981 spin_unlock_bh(&reg_pending_beacons_lock); 1876 spin_unlock_bh(&reg_pending_beacons_lock);
1982 1877
1983 if (!list_empty(&reg_beacon_list)) { 1878 list_for_each_entry_safe(reg_beacon, btmp, &reg_beacon_list, list) {
1984 list_for_each_entry_safe(reg_beacon, btmp, 1879 list_del(&reg_beacon->list);
1985 &reg_beacon_list, list) { 1880 kfree(reg_beacon);
1986 list_del(&reg_beacon->list);
1987 kfree(reg_beacon);
1988 }
1989 } 1881 }
1990 1882
1991 /* First restore to the basic regulatory settings */ 1883 /* First restore to the basic regulatory settings */
1992 cfg80211_regdomain = cfg80211_world_regdom; 1884 world_alpha2[0] = cfg80211_world_regdom->alpha2[0];
1993 world_alpha2[0] = cfg80211_regdomain->alpha2[0]; 1885 world_alpha2[1] = cfg80211_world_regdom->alpha2[1];
1994 world_alpha2[1] = cfg80211_regdomain->alpha2[1];
1995 1886
1996 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 1887 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1997 if (rdev->wiphy.flags & WIPHY_FLAG_CUSTOM_REGULATORY) 1888 if (rdev->wiphy.flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1998 restore_custom_reg_settings(&rdev->wiphy); 1889 restore_custom_reg_settings(&rdev->wiphy);
1999 } 1890 }
2000 1891
2001 mutex_unlock(&reg_mutex);
2002 mutex_unlock(&cfg80211_mutex);
2003
2004 regulatory_hint_core(world_alpha2); 1892 regulatory_hint_core(world_alpha2);
2005 1893
2006 /* 1894 /*
@@ -2011,20 +1899,8 @@ static void restore_regulatory_settings(bool reset_user)
2011 if (is_an_alpha2(alpha2)) 1899 if (is_an_alpha2(alpha2))
2012 regulatory_hint_user(user_alpha2, NL80211_USER_REG_HINT_USER); 1900 regulatory_hint_user(user_alpha2, NL80211_USER_REG_HINT_USER);
2013 1901
2014 if (list_empty(&tmp_reg_req_list))
2015 return;
2016
2017 mutex_lock(&cfg80211_mutex);
2018 mutex_lock(&reg_mutex);
2019
2020 spin_lock(&reg_requests_lock); 1902 spin_lock(&reg_requests_lock);
2021 list_for_each_entry_safe(reg_request, tmp, &tmp_reg_req_list, list) { 1903 list_splice_tail_init(&tmp_reg_req_list, &reg_requests_list);
2022 REG_DBG_PRINT("Adding request for country %c%c back "
2023 "into the queue\n",
2024 reg_request->alpha2[0],
2025 reg_request->alpha2[1]);
2026 list_move_tail(&reg_request->list, &reg_requests_list);
2027 }
2028 spin_unlock(&reg_requests_lock); 1904 spin_unlock(&reg_requests_lock);
2029 1905
2030 mutex_unlock(&reg_mutex); 1906 mutex_unlock(&reg_mutex);
@@ -2037,8 +1913,7 @@ static void restore_regulatory_settings(bool reset_user)
2037 1913
2038void regulatory_hint_disconnect(void) 1914void regulatory_hint_disconnect(void)
2039{ 1915{
2040 REG_DBG_PRINT("All devices are disconnected, going to " 1916 REG_DBG_PRINT("All devices are disconnected, going to restore regulatory settings\n");
2041 "restore regulatory settings\n");
2042 restore_regulatory_settings(false); 1917 restore_regulatory_settings(false);
2043} 1918}
2044 1919
@@ -2051,31 +1926,48 @@ static bool freq_is_chan_12_13_14(u16 freq)
2051 return false; 1926 return false;
2052} 1927}
2053 1928
1929static bool pending_reg_beacon(struct ieee80211_channel *beacon_chan)
1930{
1931 struct reg_beacon *pending_beacon;
1932
1933 list_for_each_entry(pending_beacon, &reg_pending_beacons, list)
1934 if (beacon_chan->center_freq ==
1935 pending_beacon->chan.center_freq)
1936 return true;
1937 return false;
1938}
1939
2054int regulatory_hint_found_beacon(struct wiphy *wiphy, 1940int regulatory_hint_found_beacon(struct wiphy *wiphy,
2055 struct ieee80211_channel *beacon_chan, 1941 struct ieee80211_channel *beacon_chan,
2056 gfp_t gfp) 1942 gfp_t gfp)
2057{ 1943{
2058 struct reg_beacon *reg_beacon; 1944 struct reg_beacon *reg_beacon;
1945 bool processing;
2059 1946
2060 if (likely((beacon_chan->beacon_found || 1947 if (beacon_chan->beacon_found ||
2061 (beacon_chan->flags & IEEE80211_CHAN_RADAR) || 1948 beacon_chan->flags & IEEE80211_CHAN_RADAR ||
2062 (beacon_chan->band == IEEE80211_BAND_2GHZ && 1949 (beacon_chan->band == IEEE80211_BAND_2GHZ &&
2063 !freq_is_chan_12_13_14(beacon_chan->center_freq))))) 1950 !freq_is_chan_12_13_14(beacon_chan->center_freq)))
1951 return 0;
1952
1953 spin_lock_bh(&reg_pending_beacons_lock);
1954 processing = pending_reg_beacon(beacon_chan);
1955 spin_unlock_bh(&reg_pending_beacons_lock);
1956
1957 if (processing)
2064 return 0; 1958 return 0;
2065 1959
2066 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp); 1960 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp);
2067 if (!reg_beacon) 1961 if (!reg_beacon)
2068 return -ENOMEM; 1962 return -ENOMEM;
2069 1963
2070 REG_DBG_PRINT("Found new beacon on " 1964 REG_DBG_PRINT("Found new beacon on frequency: %d MHz (Ch %d) on %s\n",
2071 "frequency: %d MHz (Ch %d) on %s\n",
2072 beacon_chan->center_freq, 1965 beacon_chan->center_freq,
2073 ieee80211_frequency_to_channel(beacon_chan->center_freq), 1966 ieee80211_frequency_to_channel(beacon_chan->center_freq),
2074 wiphy_name(wiphy)); 1967 wiphy_name(wiphy));
2075 1968
2076 memcpy(&reg_beacon->chan, beacon_chan, 1969 memcpy(&reg_beacon->chan, beacon_chan,
2077 sizeof(struct ieee80211_channel)); 1970 sizeof(struct ieee80211_channel));
2078
2079 1971
2080 /* 1972 /*
2081 * Since we can be called from BH or and non-BH context 1973 * Since we can be called from BH or and non-BH context
@@ -2155,21 +2047,19 @@ static void print_dfs_region(u8 dfs_region)
2155 pr_info(" DFS Master region JP"); 2047 pr_info(" DFS Master region JP");
2156 break; 2048 break;
2157 default: 2049 default:
2158 pr_info(" DFS Master region Uknown"); 2050 pr_info(" DFS Master region Unknown");
2159 break; 2051 break;
2160 } 2052 }
2161} 2053}
2162 2054
2163static void print_regdomain(const struct ieee80211_regdomain *rd) 2055static void print_regdomain(const struct ieee80211_regdomain *rd)
2164{ 2056{
2057 struct regulatory_request *lr = get_last_request();
2165 2058
2166 if (is_intersected_alpha2(rd->alpha2)) { 2059 if (is_intersected_alpha2(rd->alpha2)) {
2167 2060 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2168 if (last_request->initiator ==
2169 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2170 struct cfg80211_registered_device *rdev; 2061 struct cfg80211_registered_device *rdev;
2171 rdev = cfg80211_rdev_by_wiphy_idx( 2062 rdev = cfg80211_rdev_by_wiphy_idx(lr->wiphy_idx);
2172 last_request->wiphy_idx);
2173 if (rdev) { 2063 if (rdev) {
2174 pr_info("Current regulatory domain updated by AP to: %c%c\n", 2064 pr_info("Current regulatory domain updated by AP to: %c%c\n",
2175 rdev->country_ie_alpha2[0], 2065 rdev->country_ie_alpha2[0],
@@ -2178,22 +2068,21 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
2178 pr_info("Current regulatory domain intersected:\n"); 2068 pr_info("Current regulatory domain intersected:\n");
2179 } else 2069 } else
2180 pr_info("Current regulatory domain intersected:\n"); 2070 pr_info("Current regulatory domain intersected:\n");
2181 } else if (is_world_regdom(rd->alpha2)) 2071 } else if (is_world_regdom(rd->alpha2)) {
2182 pr_info("World regulatory domain updated:\n"); 2072 pr_info("World regulatory domain updated:\n");
2183 else { 2073 } else {
2184 if (is_unknown_alpha2(rd->alpha2)) 2074 if (is_unknown_alpha2(rd->alpha2))
2185 pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n"); 2075 pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n");
2186 else { 2076 else {
2187 if (reg_request_cell_base(last_request)) 2077 if (reg_request_cell_base(lr))
2188 pr_info("Regulatory domain changed " 2078 pr_info("Regulatory domain changed to country: %c%c by Cell Station\n",
2189 "to country: %c%c by Cell Station\n",
2190 rd->alpha2[0], rd->alpha2[1]); 2079 rd->alpha2[0], rd->alpha2[1]);
2191 else 2080 else
2192 pr_info("Regulatory domain changed " 2081 pr_info("Regulatory domain changed to country: %c%c\n",
2193 "to country: %c%c\n",
2194 rd->alpha2[0], rd->alpha2[1]); 2082 rd->alpha2[0], rd->alpha2[1]);
2195 } 2083 }
2196 } 2084 }
2085
2197 print_dfs_region(rd->dfs_region); 2086 print_dfs_region(rd->dfs_region);
2198 print_rd_rules(rd); 2087 print_rd_rules(rd);
2199} 2088}
@@ -2207,22 +2096,23 @@ static void print_regdomain_info(const struct ieee80211_regdomain *rd)
2207/* Takes ownership of rd only if it doesn't fail */ 2096/* Takes ownership of rd only if it doesn't fail */
2208static int __set_regdom(const struct ieee80211_regdomain *rd) 2097static int __set_regdom(const struct ieee80211_regdomain *rd)
2209{ 2098{
2099 const struct ieee80211_regdomain *regd;
2210 const struct ieee80211_regdomain *intersected_rd = NULL; 2100 const struct ieee80211_regdomain *intersected_rd = NULL;
2211 struct wiphy *request_wiphy; 2101 struct wiphy *request_wiphy;
2102 struct regulatory_request *lr = get_last_request();
2103
2212 /* Some basic sanity checks first */ 2104 /* Some basic sanity checks first */
2213 2105
2106 if (!reg_is_valid_request(rd->alpha2))
2107 return -EINVAL;
2108
2214 if (is_world_regdom(rd->alpha2)) { 2109 if (is_world_regdom(rd->alpha2)) {
2215 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
2216 return -EINVAL;
2217 update_world_regdomain(rd); 2110 update_world_regdomain(rd);
2218 return 0; 2111 return 0;
2219 } 2112 }
2220 2113
2221 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && 2114 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
2222 !is_unknown_alpha2(rd->alpha2)) 2115 !is_unknown_alpha2(rd->alpha2))
2223 return -EINVAL;
2224
2225 if (!last_request)
2226 return -EINVAL; 2116 return -EINVAL;
2227 2117
2228 /* 2118 /*
@@ -2230,7 +2120,7 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2230 * rd is non static (it means CRDA was present and was used last) 2120 * rd is non static (it means CRDA was present and was used last)
2231 * and the pending request came in from a country IE 2121 * and the pending request came in from a country IE
2232 */ 2122 */
2233 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { 2123 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2234 /* 2124 /*
2235 * If someone else asked us to change the rd lets only bother 2125 * If someone else asked us to change the rd lets only bother
2236 * checking if the alpha2 changes if CRDA was already called 2126 * checking if the alpha2 changes if CRDA was already called
@@ -2246,29 +2136,23 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2246 * internal EEPROM data 2136 * internal EEPROM data
2247 */ 2137 */
2248 2138
2249 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
2250 return -EINVAL;
2251
2252 if (!is_valid_rd(rd)) { 2139 if (!is_valid_rd(rd)) {
2253 pr_err("Invalid regulatory domain detected:\n"); 2140 pr_err("Invalid regulatory domain detected:\n");
2254 print_regdomain_info(rd); 2141 print_regdomain_info(rd);
2255 return -EINVAL; 2142 return -EINVAL;
2256 } 2143 }
2257 2144
2258 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 2145 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
2259 if (!request_wiphy && 2146 if (!request_wiphy &&
2260 (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER || 2147 (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
2261 last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)) { 2148 lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)) {
2262 schedule_delayed_work(&reg_timeout, 0); 2149 schedule_delayed_work(&reg_timeout, 0);
2263 return -ENODEV; 2150 return -ENODEV;
2264 } 2151 }
2265 2152
2266 if (!last_request->intersect) { 2153 if (!lr->intersect) {
2267 int r; 2154 if (lr->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
2268 2155 reset_regdomains(false, rd);
2269 if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
2270 reset_regdomains(false);
2271 cfg80211_regdomain = rd;
2272 return 0; 2156 return 0;
2273 } 2157 }
2274 2158
@@ -2284,20 +2168,19 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2284 if (request_wiphy->regd) 2168 if (request_wiphy->regd)
2285 return -EALREADY; 2169 return -EALREADY;
2286 2170
2287 r = reg_copy_regd(&request_wiphy->regd, rd); 2171 regd = reg_copy_regd(rd);
2288 if (r) 2172 if (IS_ERR(regd))
2289 return r; 2173 return PTR_ERR(regd);
2290 2174
2291 reset_regdomains(false); 2175 rcu_assign_pointer(request_wiphy->regd, regd);
2292 cfg80211_regdomain = rd; 2176 reset_regdomains(false, rd);
2293 return 0; 2177 return 0;
2294 } 2178 }
2295 2179
2296 /* Intersection requires a bit more work */ 2180 /* Intersection requires a bit more work */
2297 2181
2298 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { 2182 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2299 2183 intersected_rd = regdom_intersect(rd, get_cfg80211_regdom());
2300 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
2301 if (!intersected_rd) 2184 if (!intersected_rd)
2302 return -EINVAL; 2185 return -EINVAL;
2303 2186
@@ -2306,15 +2189,14 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2306 * However if a driver requested this specific regulatory 2189 * However if a driver requested this specific regulatory
2307 * domain we keep it for its private use 2190 * domain we keep it for its private use
2308 */ 2191 */
2309 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER) 2192 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER)
2310 request_wiphy->regd = rd; 2193 rcu_assign_pointer(request_wiphy->regd, rd);
2311 else 2194 else
2312 kfree(rd); 2195 kfree(rd);
2313 2196
2314 rd = NULL; 2197 rd = NULL;
2315 2198
2316 reset_regdomains(false); 2199 reset_regdomains(false, intersected_rd);
2317 cfg80211_regdomain = intersected_rd;
2318 2200
2319 return 0; 2201 return 0;
2320 } 2202 }
@@ -2326,15 +2208,15 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2326/* 2208/*
2327 * Use this call to set the current regulatory domain. Conflicts with 2209 * Use this call to set the current regulatory domain. Conflicts with
2328 * multiple drivers can be ironed out later. Caller must've already 2210 * multiple drivers can be ironed out later. Caller must've already
2329 * kmalloc'd the rd structure. Caller must hold cfg80211_mutex 2211 * kmalloc'd the rd structure.
2330 */ 2212 */
2331int set_regdom(const struct ieee80211_regdomain *rd) 2213int set_regdom(const struct ieee80211_regdomain *rd)
2332{ 2214{
2215 struct regulatory_request *lr;
2333 int r; 2216 int r;
2334 2217
2335 assert_cfg80211_lock();
2336
2337 mutex_lock(&reg_mutex); 2218 mutex_lock(&reg_mutex);
2219 lr = get_last_request();
2338 2220
2339 /* Note that this doesn't update the wiphys, this is done below */ 2221 /* Note that this doesn't update the wiphys, this is done below */
2340 r = __set_regdom(rd); 2222 r = __set_regdom(rd);
@@ -2343,23 +2225,25 @@ int set_regdom(const struct ieee80211_regdomain *rd)
2343 reg_set_request_processed(); 2225 reg_set_request_processed();
2344 2226
2345 kfree(rd); 2227 kfree(rd);
2346 mutex_unlock(&reg_mutex); 2228 goto out;
2347 return r;
2348 } 2229 }
2349 2230
2350 /* This would make this whole thing pointless */ 2231 /* This would make this whole thing pointless */
2351 if (!last_request->intersect) 2232 if (WARN_ON(!lr->intersect && rd != get_cfg80211_regdom())) {
2352 BUG_ON(rd != cfg80211_regdomain); 2233 r = -EINVAL;
2234 goto out;
2235 }
2353 2236
2354 /* update all wiphys now with the new established regulatory domain */ 2237 /* update all wiphys now with the new established regulatory domain */
2355 update_all_wiphy_regulatory(last_request->initiator); 2238 update_all_wiphy_regulatory(lr->initiator);
2356 2239
2357 print_regdomain(cfg80211_regdomain); 2240 print_regdomain(get_cfg80211_regdom());
2358 2241
2359 nl80211_send_reg_change_event(last_request); 2242 nl80211_send_reg_change_event(lr);
2360 2243
2361 reg_set_request_processed(); 2244 reg_set_request_processed();
2362 2245
2246 out:
2363 mutex_unlock(&reg_mutex); 2247 mutex_unlock(&reg_mutex);
2364 2248
2365 return r; 2249 return r;
@@ -2367,20 +2251,26 @@ int set_regdom(const struct ieee80211_regdomain *rd)
2367 2251
2368int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env) 2252int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
2369{ 2253{
2370 if (last_request && !last_request->processed) { 2254 struct regulatory_request *lr;
2371 if (add_uevent_var(env, "COUNTRY=%c%c", 2255 u8 alpha2[2];
2372 last_request->alpha2[0], 2256 bool add = false;
2373 last_request->alpha2[1])) 2257
2374 return -ENOMEM; 2258 rcu_read_lock();
2259 lr = get_last_request();
2260 if (lr && !lr->processed) {
2261 memcpy(alpha2, lr->alpha2, 2);
2262 add = true;
2375 } 2263 }
2264 rcu_read_unlock();
2376 2265
2266 if (add)
2267 return add_uevent_var(env, "COUNTRY=%c%c",
2268 alpha2[0], alpha2[1]);
2377 return 0; 2269 return 0;
2378} 2270}
2379 2271
2380void wiphy_regulatory_register(struct wiphy *wiphy) 2272void wiphy_regulatory_register(struct wiphy *wiphy)
2381{ 2273{
2382 assert_cfg80211_lock();
2383
2384 mutex_lock(&reg_mutex); 2274 mutex_lock(&reg_mutex);
2385 2275
2386 if (!reg_dev_ignore_cell_hint(wiphy)) 2276 if (!reg_dev_ignore_cell_hint(wiphy))
@@ -2395,32 +2285,32 @@ void wiphy_regulatory_register(struct wiphy *wiphy)
2395void wiphy_regulatory_deregister(struct wiphy *wiphy) 2285void wiphy_regulatory_deregister(struct wiphy *wiphy)
2396{ 2286{
2397 struct wiphy *request_wiphy = NULL; 2287 struct wiphy *request_wiphy = NULL;
2398 2288 struct regulatory_request *lr;
2399 assert_cfg80211_lock();
2400 2289
2401 mutex_lock(&reg_mutex); 2290 mutex_lock(&reg_mutex);
2291 lr = get_last_request();
2402 2292
2403 if (!reg_dev_ignore_cell_hint(wiphy)) 2293 if (!reg_dev_ignore_cell_hint(wiphy))
2404 reg_num_devs_support_basehint--; 2294 reg_num_devs_support_basehint--;
2405 2295
2406 kfree(wiphy->regd); 2296 rcu_free_regdom(get_wiphy_regdom(wiphy));
2297 rcu_assign_pointer(wiphy->regd, NULL);
2407 2298
2408 if (last_request) 2299 if (lr)
2409 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 2300 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
2410 2301
2411 if (!request_wiphy || request_wiphy != wiphy) 2302 if (!request_wiphy || request_wiphy != wiphy)
2412 goto out; 2303 goto out;
2413 2304
2414 last_request->wiphy_idx = WIPHY_IDX_STALE; 2305 lr->wiphy_idx = WIPHY_IDX_INVALID;
2415 last_request->country_ie_env = ENVIRON_ANY; 2306 lr->country_ie_env = ENVIRON_ANY;
2416out: 2307out:
2417 mutex_unlock(&reg_mutex); 2308 mutex_unlock(&reg_mutex);
2418} 2309}
2419 2310
2420static void reg_timeout_work(struct work_struct *work) 2311static void reg_timeout_work(struct work_struct *work)
2421{ 2312{
2422 REG_DBG_PRINT("Timeout while waiting for CRDA to reply, " 2313 REG_DBG_PRINT("Timeout while waiting for CRDA to reply, restoring regulatory settings\n");
2423 "restoring regulatory settings\n");
2424 restore_regulatory_settings(true); 2314 restore_regulatory_settings(true);
2425} 2315}
2426 2316
@@ -2439,13 +2329,13 @@ int __init regulatory_init(void)
2439 2329
2440 reg_regdb_size_check(); 2330 reg_regdb_size_check();
2441 2331
2442 cfg80211_regdomain = cfg80211_world_regdom; 2332 rcu_assign_pointer(cfg80211_regdomain, cfg80211_world_regdom);
2443 2333
2444 user_alpha2[0] = '9'; 2334 user_alpha2[0] = '9';
2445 user_alpha2[1] = '7'; 2335 user_alpha2[1] = '7';
2446 2336
2447 /* We always try to get an update for the static regdomain */ 2337 /* We always try to get an update for the static regdomain */
2448 err = regulatory_hint_core(cfg80211_regdomain->alpha2); 2338 err = regulatory_hint_core(cfg80211_world_regdom->alpha2);
2449 if (err) { 2339 if (err) {
2450 if (err == -ENOMEM) 2340 if (err == -ENOMEM)
2451 return err; 2341 return err;
@@ -2457,10 +2347,6 @@ int __init regulatory_init(void)
2457 * errors as non-fatal. 2347 * errors as non-fatal.
2458 */ 2348 */
2459 pr_err("kobject_uevent_env() was unable to call CRDA during init\n"); 2349 pr_err("kobject_uevent_env() was unable to call CRDA during init\n");
2460#ifdef CONFIG_CFG80211_REG_DEBUG
2461 /* We want to find out exactly why when debugging */
2462 WARN_ON(err);
2463#endif
2464 } 2350 }
2465 2351
2466 /* 2352 /*
@@ -2474,7 +2360,7 @@ int __init regulatory_init(void)
2474 return 0; 2360 return 0;
2475} 2361}
2476 2362
2477void /* __init_or_exit */ regulatory_exit(void) 2363void regulatory_exit(void)
2478{ 2364{
2479 struct regulatory_request *reg_request, *tmp; 2365 struct regulatory_request *reg_request, *tmp;
2480 struct reg_beacon *reg_beacon, *btmp; 2366 struct reg_beacon *reg_beacon, *btmp;
@@ -2482,43 +2368,27 @@ void /* __init_or_exit */ regulatory_exit(void)
2482 cancel_work_sync(&reg_work); 2368 cancel_work_sync(&reg_work);
2483 cancel_delayed_work_sync(&reg_timeout); 2369 cancel_delayed_work_sync(&reg_timeout);
2484 2370
2485 mutex_lock(&cfg80211_mutex); 2371 /* Lock to suppress warnings */
2486 mutex_lock(&reg_mutex); 2372 mutex_lock(&reg_mutex);
2487 2373 reset_regdomains(true, NULL);
2488 reset_regdomains(true); 2374 mutex_unlock(&reg_mutex);
2489 2375
2490 dev_set_uevent_suppress(&reg_pdev->dev, true); 2376 dev_set_uevent_suppress(&reg_pdev->dev, true);
2491 2377
2492 platform_device_unregister(reg_pdev); 2378 platform_device_unregister(reg_pdev);
2493 2379
2494 spin_lock_bh(&reg_pending_beacons_lock); 2380 list_for_each_entry_safe(reg_beacon, btmp, &reg_pending_beacons, list) {
2495 if (!list_empty(&reg_pending_beacons)) { 2381 list_del(&reg_beacon->list);
2496 list_for_each_entry_safe(reg_beacon, btmp, 2382 kfree(reg_beacon);
2497 &reg_pending_beacons, list) {
2498 list_del(&reg_beacon->list);
2499 kfree(reg_beacon);
2500 }
2501 } 2383 }
2502 spin_unlock_bh(&reg_pending_beacons_lock);
2503 2384
2504 if (!list_empty(&reg_beacon_list)) { 2385 list_for_each_entry_safe(reg_beacon, btmp, &reg_beacon_list, list) {
2505 list_for_each_entry_safe(reg_beacon, btmp, 2386 list_del(&reg_beacon->list);
2506 &reg_beacon_list, list) { 2387 kfree(reg_beacon);
2507 list_del(&reg_beacon->list);
2508 kfree(reg_beacon);
2509 }
2510 } 2388 }
2511 2389
2512 spin_lock(&reg_requests_lock); 2390 list_for_each_entry_safe(reg_request, tmp, &reg_requests_list, list) {
2513 if (!list_empty(&reg_requests_list)) { 2391 list_del(&reg_request->list);
2514 list_for_each_entry_safe(reg_request, tmp, 2392 kfree(reg_request);
2515 &reg_requests_list, list) {
2516 list_del(&reg_request->list);
2517 kfree(reg_request);
2518 }
2519 } 2393 }
2520 spin_unlock(&reg_requests_lock);
2521
2522 mutex_unlock(&reg_mutex);
2523 mutex_unlock(&cfg80211_mutex);
2524} 2394}
diff --git a/net/wireless/reg.h b/net/wireless/reg.h
index 4c0a32ffd530..af2d5f8a5d82 100644
--- a/net/wireless/reg.h
+++ b/net/wireless/reg.h
@@ -16,10 +16,9 @@
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19extern const struct ieee80211_regdomain *cfg80211_regdomain; 19extern const struct ieee80211_regdomain __rcu *cfg80211_regdomain;
20 20
21bool is_world_regdom(const char *alpha2); 21bool is_world_regdom(const char *alpha2);
22bool reg_is_valid_request(const char *alpha2);
23bool reg_supported_dfs_region(u8 dfs_region); 22bool reg_supported_dfs_region(u8 dfs_region);
24 23
25int regulatory_hint_user(const char *alpha2, 24int regulatory_hint_user(const char *alpha2,
@@ -55,8 +54,8 @@ bool reg_last_request_cell_base(void);
55 * set the wiphy->disable_beacon_hints to true. 54 * set the wiphy->disable_beacon_hints to true.
56 */ 55 */
57int regulatory_hint_found_beacon(struct wiphy *wiphy, 56int regulatory_hint_found_beacon(struct wiphy *wiphy,
58 struct ieee80211_channel *beacon_chan, 57 struct ieee80211_channel *beacon_chan,
59 gfp_t gfp); 58 gfp_t gfp);
60 59
61/** 60/**
62 * regulatory_hint_11d - hints a country IE as a regulatory domain 61 * regulatory_hint_11d - hints a country IE as a regulatory domain
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
index f2431e41a373..a825dfe12cf7 100644
--- a/net/wireless/sme.c
+++ b/net/wireless/sme.c
@@ -192,7 +192,8 @@ static int cfg80211_conn_do_work(struct wireless_dev *wdev)
192 prev_bssid, 192 prev_bssid,
193 params->ssid, params->ssid_len, 193 params->ssid, params->ssid_len,
194 params->ie, params->ie_len, 194 params->ie, params->ie_len,
195 false, &params->crypto, 195 params->mfp != NL80211_MFP_NO,
196 &params->crypto,
196 params->flags, &params->ht_capa, 197 params->flags, &params->ht_capa,
197 &params->ht_capa_mask); 198 &params->ht_capa_mask);
198 if (err) 199 if (err)
@@ -519,10 +520,8 @@ void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
519 * - country_ie + 2, the start of the country ie data, and 520 * - country_ie + 2, the start of the country ie data, and
520 * - and country_ie[1] which is the IE length 521 * - and country_ie[1] which is the IE length
521 */ 522 */
522 regulatory_hint_11d(wdev->wiphy, 523 regulatory_hint_11d(wdev->wiphy, bss->channel->band,
523 bss->channel->band, 524 country_ie + 2, country_ie[1]);
524 country_ie + 2,
525 country_ie[1]);
526 kfree(country_ie); 525 kfree(country_ie);
527} 526}
528 527
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 16d76a807c2f..1c2795d52db0 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1184,7 +1184,8 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
1184 struct wireless_dev *wdev, 1184 struct wireless_dev *wdev,
1185 enum nl80211_iftype iftype, 1185 enum nl80211_iftype iftype,
1186 struct ieee80211_channel *chan, 1186 struct ieee80211_channel *chan,
1187 enum cfg80211_chan_mode chanmode) 1187 enum cfg80211_chan_mode chanmode,
1188 u8 radar_detect)
1188{ 1189{
1189 struct wireless_dev *wdev_iter; 1190 struct wireless_dev *wdev_iter;
1190 u32 used_iftypes = BIT(iftype); 1191 u32 used_iftypes = BIT(iftype);
@@ -1195,14 +1196,45 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
1195 enum cfg80211_chan_mode chmode; 1196 enum cfg80211_chan_mode chmode;
1196 int num_different_channels = 0; 1197 int num_different_channels = 0;
1197 int total = 1; 1198 int total = 1;
1199 bool radar_required;
1198 int i, j; 1200 int i, j;
1199 1201
1200 ASSERT_RTNL(); 1202 ASSERT_RTNL();
1201 lockdep_assert_held(&rdev->devlist_mtx); 1203 lockdep_assert_held(&rdev->devlist_mtx);
1202 1204
1205 if (WARN_ON(hweight32(radar_detect) > 1))
1206 return -EINVAL;
1207
1208 switch (iftype) {
1209 case NL80211_IFTYPE_ADHOC:
1210 case NL80211_IFTYPE_AP:
1211 case NL80211_IFTYPE_AP_VLAN:
1212 case NL80211_IFTYPE_MESH_POINT:
1213 case NL80211_IFTYPE_P2P_GO:
1214 case NL80211_IFTYPE_WDS:
1215 radar_required = !!(chan->flags & IEEE80211_CHAN_RADAR);
1216 break;
1217 case NL80211_IFTYPE_P2P_CLIENT:
1218 case NL80211_IFTYPE_STATION:
1219 case NL80211_IFTYPE_MONITOR:
1220 radar_required = false;
1221 break;
1222 case NL80211_IFTYPE_P2P_DEVICE:
1223 case NUM_NL80211_IFTYPES:
1224 case NL80211_IFTYPE_UNSPECIFIED:
1225 default:
1226 return -EINVAL;
1227 }
1228
1229 if (radar_required && !radar_detect)
1230 return -EINVAL;
1231
1203 /* Always allow software iftypes */ 1232 /* Always allow software iftypes */
1204 if (rdev->wiphy.software_iftypes & BIT(iftype)) 1233 if (rdev->wiphy.software_iftypes & BIT(iftype)) {
1234 if (radar_detect)
1235 return -EINVAL;
1205 return 0; 1236 return 0;
1237 }
1206 1238
1207 memset(num, 0, sizeof(num)); 1239 memset(num, 0, sizeof(num));
1208 memset(used_channels, 0, sizeof(used_channels)); 1240 memset(used_channels, 0, sizeof(used_channels));
@@ -1275,7 +1307,7 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
1275 used_iftypes |= BIT(wdev_iter->iftype); 1307 used_iftypes |= BIT(wdev_iter->iftype);
1276 } 1308 }
1277 1309
1278 if (total == 1) 1310 if (total == 1 && !radar_detect)
1279 return 0; 1311 return 0;
1280 1312
1281 for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) { 1313 for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
@@ -1308,6 +1340,9 @@ int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
1308 } 1340 }
1309 } 1341 }
1310 1342
1343 if (radar_detect && !(c->radar_detect_widths & radar_detect))
1344 goto cont;
1345
1311 /* 1346 /*
1312 * Finally check that all iftypes that we're currently 1347 * Finally check that all iftypes that we're currently
1313 * using are actually part of this combination. If they 1348 * using are actually part of this combination. If they