blob: caf3b83fe31b2c97203ea78a1c3d97b483eac83b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
9#include <linux/ieee80211.h>
10#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
12#include <linux/slab.h>
13#include <net/net_namespace.h>
14#include <linux/rcupdate.h>
15#include <linux/if_ether.h>
16#include <net/cfg80211.h>
17#include "ieee80211_i.h"
18#include "driver-ops.h"
19#include "cfg.h"
20#include "rate.h"
21#include "mesh.h"
22
23static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
27{
28 struct ieee80211_local *local = wiphy_priv(wiphy);
29 struct net_device *dev;
30 struct ieee80211_sub_if_data *sdata;
31 int err;
32
33 err = ieee80211_if_add(local, name, &dev, type, params);
34 if (err)
35 return ERR_PTR(err);
36
37 if (type == NL80211_IFTYPE_MONITOR && flags) {
38 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
39 sdata->u.mntr_flags = *flags;
40 }
41
42 return dev;
43}
44
45static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
46{
47 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
48
49 return 0;
50}
51
52static int ieee80211_change_iface(struct wiphy *wiphy,
53 struct net_device *dev,
54 enum nl80211_iftype type, u32 *flags,
55 struct vif_params *params)
56{
57 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
58 int ret;
59
60 ret = ieee80211_if_change_type(sdata, type);
61 if (ret)
62 return ret;
63
64 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
66 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
67 else if (type == NL80211_IFTYPE_STATION &&
68 params && params->use_4addr >= 0)
69 sdata->u.mgd.use_4addr = params->use_4addr;
70
71 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
73
74 if (ieee80211_sdata_running(sdata)) {
75 /*
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
82 */
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
85 return -EBUSY;
86
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
90
91 ieee80211_configure_filter(local);
92 } else {
93 /*
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
97 */
98 sdata->u.mntr_flags = *flags;
99 }
100 }
101
102 return 0;
103}
104
105static int ieee80211_set_noack_map(struct wiphy *wiphy,
106 struct net_device *dev,
107 u16 noack_map)
108{
109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
110
111 sdata->noack_map = noack_map;
112 return 0;
113}
114
115static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
116 u8 key_idx, bool pairwise, const u8 *mac_addr,
117 struct key_params *params)
118{
119 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
120 struct sta_info *sta = NULL;
121 struct ieee80211_key *key;
122 int err;
123
124 if (!ieee80211_sdata_running(sdata))
125 return -ENETDOWN;
126
127 /* reject WEP and TKIP keys if WEP failed to initialize */
128 switch (params->cipher) {
129 case WLAN_CIPHER_SUITE_WEP40:
130 case WLAN_CIPHER_SUITE_TKIP:
131 case WLAN_CIPHER_SUITE_WEP104:
132 if (IS_ERR(sdata->local->wep_tx_tfm))
133 return -EINVAL;
134 break;
135 default:
136 break;
137 }
138
139 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
140 params->key, params->seq_len, params->seq);
141 if (IS_ERR(key))
142 return PTR_ERR(key);
143
144 if (pairwise)
145 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
146
147 mutex_lock(&sdata->local->sta_mtx);
148
149 if (mac_addr) {
150 if (ieee80211_vif_is_mesh(&sdata->vif))
151 sta = sta_info_get(sdata, mac_addr);
152 else
153 sta = sta_info_get_bss(sdata, mac_addr);
154 /*
155 * The ASSOC test makes sure the driver is ready to
156 * receive the key. When wpa_supplicant has roamed
157 * using FT, it attempts to set the key before
158 * association has completed, this rejects that attempt
159 * so it will set the key again after assocation.
160 *
161 * TODO: accept the key if we have a station entry and
162 * add it to the device after the station.
163 */
164 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
165 ieee80211_key_free(sdata->local, key);
166 err = -ENOENT;
167 goto out_unlock;
168 }
169 }
170
171 err = ieee80211_key_link(key, sdata, sta);
172 if (err)
173 ieee80211_key_free(sdata->local, key);
174
175 out_unlock:
176 mutex_unlock(&sdata->local->sta_mtx);
177
178 return err;
179}
180
181static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
182 u8 key_idx, bool pairwise, const u8 *mac_addr)
183{
184 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
185 struct ieee80211_local *local = sdata->local;
186 struct sta_info *sta;
187 struct ieee80211_key *key = NULL;
188 int ret;
189
190 mutex_lock(&local->sta_mtx);
191 mutex_lock(&local->key_mtx);
192
193 if (mac_addr) {
194 ret = -ENOENT;
195
196 sta = sta_info_get_bss(sdata, mac_addr);
197 if (!sta)
198 goto out_unlock;
199
200 if (pairwise)
201 key = key_mtx_dereference(local, sta->ptk);
202 else
203 key = key_mtx_dereference(local, sta->gtk[key_idx]);
204 } else
205 key = key_mtx_dereference(local, sdata->keys[key_idx]);
206
207 if (!key) {
208 ret = -ENOENT;
209 goto out_unlock;
210 }
211
212 __ieee80211_key_free(key);
213
214 ret = 0;
215 out_unlock:
216 mutex_unlock(&local->key_mtx);
217 mutex_unlock(&local->sta_mtx);
218
219 return ret;
220}
221
222static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
223 u8 key_idx, bool pairwise, const u8 *mac_addr,
224 void *cookie,
225 void (*callback)(void *cookie,
226 struct key_params *params))
227{
228 struct ieee80211_sub_if_data *sdata;
229 struct sta_info *sta = NULL;
230 u8 seq[6] = {0};
231 struct key_params params;
232 struct ieee80211_key *key = NULL;
233 u64 pn64;
234 u32 iv32;
235 u16 iv16;
236 int err = -ENOENT;
237
238 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
239
240 rcu_read_lock();
241
242 if (mac_addr) {
243 sta = sta_info_get_bss(sdata, mac_addr);
244 if (!sta)
245 goto out;
246
247 if (pairwise)
248 key = rcu_dereference(sta->ptk);
249 else if (key_idx < NUM_DEFAULT_KEYS)
250 key = rcu_dereference(sta->gtk[key_idx]);
251 } else
252 key = rcu_dereference(sdata->keys[key_idx]);
253
254 if (!key)
255 goto out;
256
257 memset(&params, 0, sizeof(params));
258
259 params.cipher = key->conf.cipher;
260
261 switch (key->conf.cipher) {
262 case WLAN_CIPHER_SUITE_TKIP:
263 iv32 = key->u.tkip.tx.iv32;
264 iv16 = key->u.tkip.tx.iv16;
265
266 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
267 drv_get_tkip_seq(sdata->local,
268 key->conf.hw_key_idx,
269 &iv32, &iv16);
270
271 seq[0] = iv16 & 0xff;
272 seq[1] = (iv16 >> 8) & 0xff;
273 seq[2] = iv32 & 0xff;
274 seq[3] = (iv32 >> 8) & 0xff;
275 seq[4] = (iv32 >> 16) & 0xff;
276 seq[5] = (iv32 >> 24) & 0xff;
277 params.seq = seq;
278 params.seq_len = 6;
279 break;
280 case WLAN_CIPHER_SUITE_CCMP:
281 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
282 seq[0] = pn64;
283 seq[1] = pn64 >> 8;
284 seq[2] = pn64 >> 16;
285 seq[3] = pn64 >> 24;
286 seq[4] = pn64 >> 32;
287 seq[5] = pn64 >> 40;
288 params.seq = seq;
289 params.seq_len = 6;
290 break;
291 case WLAN_CIPHER_SUITE_AES_CMAC:
292 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
293 seq[0] = pn64;
294 seq[1] = pn64 >> 8;
295 seq[2] = pn64 >> 16;
296 seq[3] = pn64 >> 24;
297 seq[4] = pn64 >> 32;
298 seq[5] = pn64 >> 40;
299 params.seq = seq;
300 params.seq_len = 6;
301 break;
302 }
303
304 params.key = key->conf.key;
305 params.key_len = key->conf.keylen;
306
307 callback(cookie, &params);
308 err = 0;
309
310 out:
311 rcu_read_unlock();
312 return err;
313}
314
315static int ieee80211_config_default_key(struct wiphy *wiphy,
316 struct net_device *dev,
317 u8 key_idx, bool uni,
318 bool multi)
319{
320 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
321
322 ieee80211_set_default_key(sdata, key_idx, uni, multi);
323
324 return 0;
325}
326
327static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
328 struct net_device *dev,
329 u8 key_idx)
330{
331 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
332
333 ieee80211_set_default_mgmt_key(sdata, key_idx);
334
335 return 0;
336}
337
338static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
339{
340 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
341 struct ieee80211_supported_band *sband;
342 sband = sta->local->hw.wiphy->bands[
343 sta->local->hw.conf.channel->band];
344 rate->legacy = sband->bitrates[idx].bitrate;
345 } else
346 rate->mcs = idx;
347}
348
349void sta_set_rate_info_tx(struct sta_info *sta,
350 const struct ieee80211_tx_rate *rate,
351 struct rate_info *rinfo)
352{
353 rinfo->flags = 0;
354 if (rate->flags & IEEE80211_TX_RC_MCS)
355 rinfo->flags |= RATE_INFO_FLAGS_MCS;
356 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
357 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
358 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
359 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
360 rate_idx_to_bitrate(rinfo, sta, rate->idx);
361}
362
363static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
364{
365 struct ieee80211_sub_if_data *sdata = sta->sdata;
366 struct timespec uptime;
367
368 sinfo->generation = sdata->local->sta_generation;
369
370 sinfo->filled = STATION_INFO_INACTIVE_TIME |
371 STATION_INFO_RX_BYTES |
372 STATION_INFO_TX_BYTES |
373 STATION_INFO_RX_PACKETS |
374 STATION_INFO_TX_PACKETS |
375 STATION_INFO_TX_RETRIES |
376 STATION_INFO_TX_FAILED |
377 STATION_INFO_TX_BITRATE |
378 STATION_INFO_RX_BITRATE |
379 STATION_INFO_RX_DROP_MISC |
380 STATION_INFO_BSS_PARAM |
381 STATION_INFO_CONNECTED_TIME |
382 STATION_INFO_STA_FLAGS |
383 STATION_INFO_BEACON_LOSS_COUNT;
384
385 do_posix_clock_monotonic_gettime(&uptime);
386 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
387
388 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
389 sinfo->rx_bytes = sta->rx_bytes;
390 sinfo->tx_bytes = sta->tx_bytes;
391 sinfo->rx_packets = sta->rx_packets;
392 sinfo->tx_packets = sta->tx_packets;
393 sinfo->tx_retries = sta->tx_retry_count;
394 sinfo->tx_failed = sta->tx_retry_failed;
395 sinfo->rx_dropped_misc = sta->rx_dropped;
396 sinfo->beacon_loss_count = sta->beacon_loss_count;
397
398 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
399 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
400 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
401 sinfo->signal = (s8)sta->last_signal;
402 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
403 }
404
405 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
406
407 sinfo->rxrate.flags = 0;
408 if (sta->last_rx_rate_flag & RX_FLAG_HT)
409 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
410 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
411 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
412 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
413 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
414 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
415
416 if (ieee80211_vif_is_mesh(&sdata->vif)) {
417#ifdef CONFIG_MAC80211_MESH
418 sinfo->filled |= STATION_INFO_LLID |
419 STATION_INFO_PLID |
420 STATION_INFO_PLINK_STATE;
421
422 sinfo->llid = le16_to_cpu(sta->llid);
423 sinfo->plid = le16_to_cpu(sta->plid);
424 sinfo->plink_state = sta->plink_state;
425#endif
426 }
427
428 sinfo->bss_param.flags = 0;
429 if (sdata->vif.bss_conf.use_cts_prot)
430 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
431 if (sdata->vif.bss_conf.use_short_preamble)
432 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
433 if (sdata->vif.bss_conf.use_short_slot)
434 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
435 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
436 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
437
438 sinfo->sta_flags.set = 0;
439 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
440 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
441 BIT(NL80211_STA_FLAG_WME) |
442 BIT(NL80211_STA_FLAG_MFP) |
443 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
444 BIT(NL80211_STA_FLAG_TDLS_PEER);
445 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
446 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
447 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
448 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
449 if (test_sta_flag(sta, WLAN_STA_WME))
450 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
451 if (test_sta_flag(sta, WLAN_STA_MFP))
452 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
453 if (test_sta_flag(sta, WLAN_STA_AUTH))
454 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
455 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
456 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
457}
458
459
460static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
461 int idx, u8 *mac, struct station_info *sinfo)
462{
463 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
464 struct sta_info *sta;
465 int ret = -ENOENT;
466
467 rcu_read_lock();
468
469 sta = sta_info_get_by_idx(sdata, idx);
470 if (sta) {
471 ret = 0;
472 memcpy(mac, sta->sta.addr, ETH_ALEN);
473 sta_set_sinfo(sta, sinfo);
474 }
475
476 rcu_read_unlock();
477
478 return ret;
479}
480
481static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
482 int idx, struct survey_info *survey)
483{
484 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
485
486 return drv_get_survey(local, idx, survey);
487}
488
489static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
490 u8 *mac, struct station_info *sinfo)
491{
492 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
493 struct sta_info *sta;
494 int ret = -ENOENT;
495
496 rcu_read_lock();
497
498 sta = sta_info_get_bss(sdata, mac);
499 if (sta) {
500 ret = 0;
501 sta_set_sinfo(sta, sinfo);
502 }
503
504 rcu_read_unlock();
505
506 return ret;
507}
508
509static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
510 const u8 *resp, size_t resp_len)
511{
512 struct sk_buff *new, *old;
513
514 if (!resp || !resp_len)
515 return 1;
516
517 old = rtnl_dereference(sdata->u.ap.probe_resp);
518
519 new = dev_alloc_skb(resp_len);
520 if (!new)
521 return -ENOMEM;
522
523 memcpy(skb_put(new, resp_len), resp, resp_len);
524
525 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
526 if (old) {
527 /* TODO: use call_rcu() */
528 synchronize_rcu();
529 dev_kfree_skb(old);
530 }
531
532 return 0;
533}
534
535static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
536 struct cfg80211_beacon_data *params)
537{
538 struct beacon_data *new, *old;
539 int new_head_len, new_tail_len;
540 int size, err;
541 u32 changed = BSS_CHANGED_BEACON;
542
543 old = rtnl_dereference(sdata->u.ap.beacon);
544
545 /* Need to have a beacon head if we don't have one yet */
546 if (!params->head && !old)
547 return -EINVAL;
548
549 /* new or old head? */
550 if (params->head)
551 new_head_len = params->head_len;
552 else
553 new_head_len = old->head_len;
554
555 /* new or old tail? */
556 if (params->tail || !old)
557 /* params->tail_len will be zero for !params->tail */
558 new_tail_len = params->tail_len;
559 else
560 new_tail_len = old->tail_len;
561
562 size = sizeof(*new) + new_head_len + new_tail_len;
563
564 new = kzalloc(size, GFP_KERNEL);
565 if (!new)
566 return -ENOMEM;
567
568 /* start filling the new info now */
569
570 /*
571 * pointers go into the block we allocated,
572 * memory is | beacon_data | head | tail |
573 */
574 new->head = ((u8 *) new) + sizeof(*new);
575 new->tail = new->head + new_head_len;
576 new->head_len = new_head_len;
577 new->tail_len = new_tail_len;
578
579 /* copy in head */
580 if (params->head)
581 memcpy(new->head, params->head, new_head_len);
582 else
583 memcpy(new->head, old->head, new_head_len);
584
585 /* copy in optional tail */
586 if (params->tail)
587 memcpy(new->tail, params->tail, new_tail_len);
588 else
589 if (old)
590 memcpy(new->tail, old->tail, new_tail_len);
591
592 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
593 params->probe_resp_len);
594 if (err < 0)
595 return err;
596 if (err == 0)
597 changed |= BSS_CHANGED_AP_PROBE_RESP;
598
599 rcu_assign_pointer(sdata->u.ap.beacon, new);
600
601 if (old)
602 kfree_rcu(old, rcu_head);
603
604 return changed;
605}
606
607static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
608 struct cfg80211_ap_settings *params)
609{
610 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
611 struct beacon_data *old;
612 struct ieee80211_sub_if_data *vlan;
613 u32 changed = BSS_CHANGED_BEACON_INT |
614 BSS_CHANGED_BEACON_ENABLED |
615 BSS_CHANGED_BEACON |
616 BSS_CHANGED_SSID;
617 int err;
618
619 old = rtnl_dereference(sdata->u.ap.beacon);
620 if (old)
621 return -EALREADY;
622
623 /*
624 * Apply control port protocol, this allows us to
625 * not encrypt dynamic WEP control frames.
626 */
627 sdata->control_port_protocol = params->crypto.control_port_ethertype;
628 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
629 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
630 vlan->control_port_protocol =
631 params->crypto.control_port_ethertype;
632 vlan->control_port_no_encrypt =
633 params->crypto.control_port_no_encrypt;
634 }
635
636 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
637 sdata->vif.bss_conf.dtim_period = params->dtim_period;
638
639 sdata->vif.bss_conf.ssid_len = params->ssid_len;
640 if (params->ssid_len)
641 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
642 params->ssid_len);
643 sdata->vif.bss_conf.hidden_ssid =
644 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
645
646 err = ieee80211_assign_beacon(sdata, &params->beacon);
647 if (err < 0)
648 return err;
649 changed |= err;
650
651 ieee80211_bss_info_change_notify(sdata, changed);
652
653 return 0;
654}
655
656static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
657 struct cfg80211_beacon_data *params)
658{
659 struct ieee80211_sub_if_data *sdata;
660 struct beacon_data *old;
661 int err;
662
663 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
664
665 old = rtnl_dereference(sdata->u.ap.beacon);
666 if (!old)
667 return -ENOENT;
668
669 err = ieee80211_assign_beacon(sdata, params);
670 if (err < 0)
671 return err;
672 ieee80211_bss_info_change_notify(sdata, err);
673 return 0;
674}
675
676static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
677{
678 struct ieee80211_sub_if_data *sdata;
679 struct beacon_data *old;
680
681 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
682
683 old = rtnl_dereference(sdata->u.ap.beacon);
684 if (!old)
685 return -ENOENT;
686
687 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
688
689 kfree_rcu(old, rcu_head);
690
691 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
692
693 return 0;
694}
695
696/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
697struct iapp_layer2_update {
698 u8 da[ETH_ALEN]; /* broadcast */
699 u8 sa[ETH_ALEN]; /* STA addr */
700 __be16 len; /* 6 */
701 u8 dsap; /* 0 */
702 u8 ssap; /* 0 */
703 u8 control;
704 u8 xid_info[3];
705} __packed;
706
707static void ieee80211_send_layer2_update(struct sta_info *sta)
708{
709 struct iapp_layer2_update *msg;
710 struct sk_buff *skb;
711
712 /* Send Level 2 Update Frame to update forwarding tables in layer 2
713 * bridge devices */
714
715 skb = dev_alloc_skb(sizeof(*msg) + NET_IP_ALIGN);
716 if (!skb)
717 return;
718
719 //printk("[nxl-%s-%d] skb->data= %p iapp_layer2_update = %d\n ", __func__, __LINE__, skb->data, sizeof(struct iapp_layer2_update));
720 skb_reserve(skb, NET_IP_ALIGN);
721 //printk("[nxl-%s-%d] skb->data= %p\n", __func__, __LINE__, skb->data);
722
723 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
724
725 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
726 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
727
728 memset(msg->da, 0xff, ETH_ALEN);
729 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
730 msg->len = htons(6);
731 msg->dsap = 0;
732 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
733 msg->control = 0xaf; /* XID response lsb.1111F101.
734 * F=0 (no poll command; unsolicited frame) */
735 msg->xid_info[0] = 0x81; /* XID format identifier */
736 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
737 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
738
739 skb->dev = sta->sdata->dev;
740 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
741 memset(skb->cb, 0, sizeof(skb->cb));
742 netif_rx_ni(skb);
743}
744
745static int sta_apply_parameters(struct ieee80211_local *local,
746 struct sta_info *sta,
747 struct station_parameters *params)
748{
749 int ret = 0;
750 u32 rates;
751 int i, j;
752 struct ieee80211_supported_band *sband;
753 struct ieee80211_sub_if_data *sdata = sta->sdata;
754 u32 mask, set;
755
756 sband = local->hw.wiphy->bands[local->oper_channel->band];
757
758 mask = params->sta_flags_mask;
759 set = params->sta_flags_set;
760
761 /*
762 * In mesh mode, we can clear AUTHENTICATED flag but must
763 * also make ASSOCIATED follow appropriately for the driver
764 * API. See also below, after AUTHORIZED changes.
765 */
766 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
767 /* cfg80211 should not allow this in non-mesh modes */
768 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
769 return -EINVAL;
770
771 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
772 !test_sta_flag(sta, WLAN_STA_AUTH)) {
773 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
774 if (ret)
775 return ret;
776 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
777 if (ret)
778 return ret;
779 }
780 }
781
782 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
783 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
784 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
785 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
786 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
787 if (ret)
788 return ret;
789 }
790
791 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
792 /* cfg80211 should not allow this in non-mesh modes */
793 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
794 return -EINVAL;
795
796 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
797 test_sta_flag(sta, WLAN_STA_AUTH)) {
798 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
799 if (ret)
800 return ret;
801 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
802 if (ret)
803 return ret;
804 }
805 }
806
807
808 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
809 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
810 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
811 else
812 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
813 }
814
815 if (mask & BIT(NL80211_STA_FLAG_WME)) {
816 if (set & BIT(NL80211_STA_FLAG_WME)) {
817 set_sta_flag(sta, WLAN_STA_WME);
818 sta->sta.wme = true;
819 } else {
820 clear_sta_flag(sta, WLAN_STA_WME);
821 sta->sta.wme = false;
822 }
823 }
824
825 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
826 if (set & BIT(NL80211_STA_FLAG_MFP))
827 set_sta_flag(sta, WLAN_STA_MFP);
828 else
829 clear_sta_flag(sta, WLAN_STA_MFP);
830 }
831
832 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
833 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
834 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
835 else
836 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
837 }
838
839 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
840 sta->sta.uapsd_queues = params->uapsd_queues;
841 sta->sta.max_sp = params->max_sp;
842 }
843
844 /*
845 * cfg80211 validates this (1-2007) and allows setting the AID
846 * only when creating a new station entry
847 */
848 if (params->aid)
849 sta->sta.aid = params->aid;
850
851 /*
852 * FIXME: updating the following information is racy when this
853 * function is called from ieee80211_change_station().
854 * However, all this information should be static so
855 * maybe we should just reject attemps to change it.
856 */
857
858 if (params->listen_interval >= 0)
859 sta->listen_interval = params->listen_interval;
860
861 if (params->supported_rates) {
862 rates = 0;
863
864 for (i = 0; i < params->supported_rates_len; i++) {
865 int rate = (params->supported_rates[i] & 0x7f) * 5;
866 for (j = 0; j < sband->n_bitrates; j++) {
867 if (sband->bitrates[j].bitrate == rate)
868 rates |= BIT(j);
869 }
870 }
871 sta->sta.supp_rates[local->oper_channel->band] = rates;
872 }
873
874 if (params->ht_capa)
875 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
876 params->ht_capa,
877 &sta->sta.ht_cap);
878
879 if (ieee80211_vif_is_mesh(&sdata->vif)) {
880#ifdef CONFIG_MAC80211_MESH
881 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
882 switch (params->plink_state) {
883 case NL80211_PLINK_LISTEN:
884 case NL80211_PLINK_ESTAB:
885 case NL80211_PLINK_BLOCKED:
886 sta->plink_state = params->plink_state;
887 break;
888 default:
889 /* nothing */
890 break;
891 }
892 else
893 switch (params->plink_action) {
894 case PLINK_ACTION_OPEN:
895 mesh_plink_open(sta);
896 break;
897 case PLINK_ACTION_BLOCK:
898 mesh_plink_block(sta);
899 break;
900 }
901#endif
902 }
903
904 return 0;
905}
906
907static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
908 u8 *mac, struct station_parameters *params)
909{
910 struct ieee80211_local *local = wiphy_priv(wiphy);
911 struct sta_info *sta;
912 struct ieee80211_sub_if_data *sdata;
913 int err;
914 int layer2_update;
915
916 if (params->vlan) {
917 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
918
919 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
920 sdata->vif.type != NL80211_IFTYPE_AP)
921 return -EINVAL;
922 } else
923 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
924
925 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
926 return -EINVAL;
927
928 if (is_multicast_ether_addr(mac))
929 return -EINVAL;
930
931 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
932 if (!sta)
933 return -ENOMEM;
934
935 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
936 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
937
938 err = sta_apply_parameters(local, sta, params);
939 if (err) {
940 sta_info_free(local, sta);
941 return err;
942 }
943
944 /*
945 * for TDLS, rate control should be initialized only when supported
946 * rates are known.
947 */
948 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
949 rate_control_rate_init(sta);
950
951 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
952 sdata->vif.type == NL80211_IFTYPE_AP;
953
954 err = sta_info_insert_rcu(sta);
955 if (err) {
956 rcu_read_unlock();
957 return err;
958 }
959
960 if (layer2_update)
961 ieee80211_send_layer2_update(sta);
962
963 rcu_read_unlock();
964
965 return 0;
966}
967
968static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
969 u8 *mac)
970{
971 struct ieee80211_local *local = wiphy_priv(wiphy);
972 struct ieee80211_sub_if_data *sdata;
973
974 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
975
976 if (mac)
977 return sta_info_destroy_addr_bss(sdata, mac);
978
979 sta_info_flush(local, sdata);
980 return 0;
981}
982
983static int ieee80211_change_station(struct wiphy *wiphy,
984 struct net_device *dev,
985 u8 *mac,
986 struct station_parameters *params)
987{
988 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
989 struct ieee80211_local *local = wiphy_priv(wiphy);
990 struct sta_info *sta;
991 struct ieee80211_sub_if_data *vlansdata;
992 int err;
993
994 mutex_lock(&local->sta_mtx);
995
996 sta = sta_info_get_bss(sdata, mac);
997 if (!sta) {
998 mutex_unlock(&local->sta_mtx);
999 return -ENOENT;
1000 }
1001
1002 /* in station mode, supported rates are only valid with TDLS */
1003 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1004 params->supported_rates &&
1005 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1006 mutex_unlock(&local->sta_mtx);
1007 return -EINVAL;
1008 }
1009
1010 if (params->vlan && params->vlan != sta->sdata->dev) {
1011 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1012
1013 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1014 vlansdata->vif.type != NL80211_IFTYPE_AP) {
1015 mutex_unlock(&local->sta_mtx);
1016 return -EINVAL;
1017 }
1018
1019 if (params->vlan->ieee80211_ptr->use_4addr) {
1020 if (vlansdata->u.vlan.sta) {
1021 mutex_unlock(&local->sta_mtx);
1022 return -EBUSY;
1023 }
1024
1025 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1026 }
1027
1028 sta->sdata = vlansdata;
1029 ieee80211_send_layer2_update(sta);
1030 }
1031
1032 err = sta_apply_parameters(local, sta, params);
1033 if (err) {
1034 mutex_unlock(&local->sta_mtx);
1035 return err;
1036 }
1037
1038 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1039 rate_control_rate_init(sta);
1040
1041 mutex_unlock(&local->sta_mtx);
1042
1043 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1044 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1045 ieee80211_recalc_ps(local, -1);
1046
1047 return 0;
1048}
1049
1050#ifdef CONFIG_MAC80211_MESH
1051static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1052 u8 *dst, u8 *next_hop)
1053{
1054 struct ieee80211_sub_if_data *sdata;
1055 struct mesh_path *mpath;
1056 struct sta_info *sta;
1057 int err;
1058
1059 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1060
1061 rcu_read_lock();
1062 sta = sta_info_get(sdata, next_hop);
1063 if (!sta) {
1064 rcu_read_unlock();
1065 return -ENOENT;
1066 }
1067
1068 err = mesh_path_add(dst, sdata);
1069 if (err) {
1070 rcu_read_unlock();
1071 return err;
1072 }
1073
1074 mpath = mesh_path_lookup(dst, sdata);
1075 if (!mpath) {
1076 rcu_read_unlock();
1077 return -ENXIO;
1078 }
1079 mesh_path_fix_nexthop(mpath, sta);
1080
1081 rcu_read_unlock();
1082 return 0;
1083}
1084
1085static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1086 u8 *dst)
1087{
1088 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1089
1090 if (dst)
1091 return mesh_path_del(dst, sdata);
1092
1093 mesh_path_flush_by_iface(sdata);
1094 return 0;
1095}
1096
1097static int ieee80211_change_mpath(struct wiphy *wiphy,
1098 struct net_device *dev,
1099 u8 *dst, u8 *next_hop)
1100{
1101 struct ieee80211_sub_if_data *sdata;
1102 struct mesh_path *mpath;
1103 struct sta_info *sta;
1104
1105 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1106
1107 rcu_read_lock();
1108
1109 sta = sta_info_get(sdata, next_hop);
1110 if (!sta) {
1111 rcu_read_unlock();
1112 return -ENOENT;
1113 }
1114
1115 mpath = mesh_path_lookup(dst, sdata);
1116 if (!mpath) {
1117 rcu_read_unlock();
1118 return -ENOENT;
1119 }
1120
1121 mesh_path_fix_nexthop(mpath, sta);
1122
1123 rcu_read_unlock();
1124 return 0;
1125}
1126
1127static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1128 struct mpath_info *pinfo)
1129{
1130 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1131
1132 if (next_hop_sta)
1133 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1134 else
1135 memset(next_hop, 0, ETH_ALEN);
1136
1137 pinfo->generation = mesh_paths_generation;
1138
1139 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1140 MPATH_INFO_SN |
1141 MPATH_INFO_METRIC |
1142 MPATH_INFO_EXPTIME |
1143 MPATH_INFO_DISCOVERY_TIMEOUT |
1144 MPATH_INFO_DISCOVERY_RETRIES |
1145 MPATH_INFO_FLAGS;
1146
1147 pinfo->frame_qlen = mpath->frame_queue.qlen;
1148 pinfo->sn = mpath->sn;
1149 pinfo->metric = mpath->metric;
1150 if (time_before(jiffies, mpath->exp_time))
1151 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1152 pinfo->discovery_timeout =
1153 jiffies_to_msecs(mpath->discovery_timeout);
1154 pinfo->discovery_retries = mpath->discovery_retries;
1155 pinfo->flags = 0;
1156 if (mpath->flags & MESH_PATH_ACTIVE)
1157 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1158 if (mpath->flags & MESH_PATH_RESOLVING)
1159 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1160 if (mpath->flags & MESH_PATH_SN_VALID)
1161 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1162 if (mpath->flags & MESH_PATH_FIXED)
1163 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1164 if (mpath->flags & MESH_PATH_RESOLVING)
1165 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1166
1167 pinfo->flags = mpath->flags;
1168}
1169
1170static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1171 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1172
1173{
1174 struct ieee80211_sub_if_data *sdata;
1175 struct mesh_path *mpath;
1176
1177 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1178
1179 rcu_read_lock();
1180 mpath = mesh_path_lookup(dst, sdata);
1181 if (!mpath) {
1182 rcu_read_unlock();
1183 return -ENOENT;
1184 }
1185 memcpy(dst, mpath->dst, ETH_ALEN);
1186 mpath_set_pinfo(mpath, next_hop, pinfo);
1187 rcu_read_unlock();
1188 return 0;
1189}
1190
1191static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1192 int idx, u8 *dst, u8 *next_hop,
1193 struct mpath_info *pinfo)
1194{
1195 struct ieee80211_sub_if_data *sdata;
1196 struct mesh_path *mpath;
1197
1198 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1199
1200 rcu_read_lock();
1201 mpath = mesh_path_lookup_by_idx(idx, sdata);
1202 if (!mpath) {
1203 rcu_read_unlock();
1204 return -ENOENT;
1205 }
1206 memcpy(dst, mpath->dst, ETH_ALEN);
1207 mpath_set_pinfo(mpath, next_hop, pinfo);
1208 rcu_read_unlock();
1209 return 0;
1210}
1211
1212static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1213 struct net_device *dev,
1214 struct mesh_config *conf)
1215{
1216 struct ieee80211_sub_if_data *sdata;
1217 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1218
1219 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1220 return 0;
1221}
1222
1223static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1224{
1225 return (mask >> (parm-1)) & 0x1;
1226}
1227
1228static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1229 const struct mesh_setup *setup)
1230{
1231 u8 *new_ie;
1232 const u8 *old_ie;
1233 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1234 struct ieee80211_sub_if_data, u.mesh);
1235
1236 /* allocate information elements */
1237 new_ie = NULL;
1238 old_ie = ifmsh->ie;
1239
1240 if (setup->ie_len) {
1241 new_ie = kmemdup(setup->ie, setup->ie_len,
1242 GFP_KERNEL);
1243 if (!new_ie)
1244 return -ENOMEM;
1245 }
1246 ifmsh->ie_len = setup->ie_len;
1247 ifmsh->ie = new_ie;
1248 kfree(old_ie);
1249
1250 /* now copy the rest of the setup parameters */
1251 ifmsh->mesh_id_len = setup->mesh_id_len;
1252 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1253 ifmsh->mesh_pp_id = setup->path_sel_proto;
1254 ifmsh->mesh_pm_id = setup->path_metric;
1255 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1256 if (setup->is_authenticated)
1257 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1258 if (setup->is_secure)
1259 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1260
1261 /* mcast rate setting in Mesh Node */
1262 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1263 sizeof(setup->mcast_rate));
1264
1265 return 0;
1266}
1267
1268static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1269 struct net_device *dev, u32 mask,
1270 const struct mesh_config *nconf)
1271{
1272 struct mesh_config *conf;
1273 struct ieee80211_sub_if_data *sdata;
1274 struct ieee80211_if_mesh *ifmsh;
1275
1276 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1277 ifmsh = &sdata->u.mesh;
1278
1279 /* Set the config options which we are interested in setting */
1280 conf = &(sdata->u.mesh.mshcfg);
1281 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1282 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1283 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1284 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1285 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1286 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1287 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1288 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1289 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1290 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1291 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1292 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1293 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1294 conf->dot11MeshTTL = nconf->element_ttl;
1295 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1296 conf->auto_open_plinks = nconf->auto_open_plinks;
1297 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1298 conf->dot11MeshHWMPmaxPREQretries =
1299 nconf->dot11MeshHWMPmaxPREQretries;
1300 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1301 conf->path_refresh_time = nconf->path_refresh_time;
1302 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1303 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1304 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1305 conf->dot11MeshHWMPactivePathTimeout =
1306 nconf->dot11MeshHWMPactivePathTimeout;
1307 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1308 conf->dot11MeshHWMPpreqMinInterval =
1309 nconf->dot11MeshHWMPpreqMinInterval;
1310 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1311 conf->dot11MeshHWMPperrMinInterval =
1312 nconf->dot11MeshHWMPperrMinInterval;
1313 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1314 mask))
1315 conf->dot11MeshHWMPnetDiameterTraversalTime =
1316 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1317 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1318 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1319 ieee80211_mesh_root_setup(ifmsh);
1320 }
1321 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1322 /* our current gate announcement implementation rides on root
1323 * announcements, so require this ifmsh to also be a root node
1324 * */
1325 if (nconf->dot11MeshGateAnnouncementProtocol &&
1326 !conf->dot11MeshHWMPRootMode) {
1327 conf->dot11MeshHWMPRootMode = 1;
1328 ieee80211_mesh_root_setup(ifmsh);
1329 }
1330 conf->dot11MeshGateAnnouncementProtocol =
1331 nconf->dot11MeshGateAnnouncementProtocol;
1332 }
1333 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1334 conf->dot11MeshHWMPRannInterval =
1335 nconf->dot11MeshHWMPRannInterval;
1336 }
1337 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1338 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1339 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1340 /* our RSSI threshold implementation is supported only for
1341 * devices that report signal in dBm.
1342 */
1343 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1344 return -ENOTSUPP;
1345 conf->rssi_threshold = nconf->rssi_threshold;
1346 }
1347 return 0;
1348}
1349
1350static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1351 const struct mesh_config *conf,
1352 const struct mesh_setup *setup)
1353{
1354 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1355 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1356 int err;
1357
1358 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1359 err = copy_mesh_setup(ifmsh, setup);
1360 if (err)
1361 return err;
1362 ieee80211_start_mesh(sdata);
1363
1364 return 0;
1365}
1366
1367static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1368{
1369 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1370
1371 ieee80211_stop_mesh(sdata);
1372
1373 return 0;
1374}
1375#endif
1376
1377static int ieee80211_change_bss(struct wiphy *wiphy,
1378 struct net_device *dev,
1379 struct bss_parameters *params)
1380{
1381 struct ieee80211_sub_if_data *sdata;
1382 u32 changed = 0;
1383
1384 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1385
1386 if (params->use_cts_prot >= 0) {
1387 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1388 changed |= BSS_CHANGED_ERP_CTS_PROT;
1389 }
1390 if (params->use_short_preamble >= 0) {
1391 sdata->vif.bss_conf.use_short_preamble =
1392 params->use_short_preamble;
1393 changed |= BSS_CHANGED_ERP_PREAMBLE;
1394 }
1395
1396 if (!sdata->vif.bss_conf.use_short_slot &&
1397 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1398 sdata->vif.bss_conf.use_short_slot = true;
1399 changed |= BSS_CHANGED_ERP_SLOT;
1400 }
1401
1402 if (params->use_short_slot_time >= 0) {
1403 sdata->vif.bss_conf.use_short_slot =
1404 params->use_short_slot_time;
1405 changed |= BSS_CHANGED_ERP_SLOT;
1406 }
1407
1408 if (params->basic_rates) {
1409 int i, j;
1410 u32 rates = 0;
1411 struct ieee80211_local *local = wiphy_priv(wiphy);
1412 struct ieee80211_supported_band *sband =
1413 wiphy->bands[local->oper_channel->band];
1414
1415 for (i = 0; i < params->basic_rates_len; i++) {
1416 int rate = (params->basic_rates[i] & 0x7f) * 5;
1417 for (j = 0; j < sband->n_bitrates; j++) {
1418 if (sband->bitrates[j].bitrate == rate)
1419 rates |= BIT(j);
1420 }
1421 }
1422 sdata->vif.bss_conf.basic_rates = rates;
1423 changed |= BSS_CHANGED_BASIC_RATES;
1424 }
1425
1426 if (params->ap_isolate >= 0) {
1427 if (params->ap_isolate)
1428 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1429 else
1430 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1431 }
1432
1433 if (params->ht_opmode >= 0) {
1434 sdata->vif.bss_conf.ht_operation_mode =
1435 (u16) params->ht_opmode;
1436 changed |= BSS_CHANGED_HT;
1437 }
1438
1439 ieee80211_bss_info_change_notify(sdata, changed);
1440
1441 return 0;
1442}
1443
1444static int ieee80211_set_txq_params(struct wiphy *wiphy,
1445 struct net_device *dev,
1446 struct ieee80211_txq_params *params)
1447{
1448 struct ieee80211_local *local = wiphy_priv(wiphy);
1449 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1450 struct ieee80211_tx_queue_params p;
1451
1452 if (!local->ops->conf_tx)
1453 return -EOPNOTSUPP;
1454
1455 memset(&p, 0, sizeof(p));
1456 p.aifs = params->aifs;
1457 p.cw_max = params->cwmax;
1458 p.cw_min = params->cwmin;
1459 p.txop = params->txop;
1460
1461 /*
1462 * Setting tx queue params disables u-apsd because it's only
1463 * called in master mode.
1464 */
1465 p.uapsd = false;
1466
1467 if (params->queue >= local->hw.queues)
1468 return -EINVAL;
1469
1470 sdata->tx_conf[params->queue] = p;
1471 if (drv_conf_tx(local, sdata, params->queue, &p)) {
1472 wiphy_debug(local->hw.wiphy,
1473 "failed to set TX queue parameters for queue %d\n",
1474 params->queue);
1475 return -EINVAL;
1476 }
1477
1478 return 0;
1479}
1480
1481static int ieee80211_set_channel(struct wiphy *wiphy,
1482 struct net_device *netdev,
1483 struct ieee80211_channel *chan,
1484 enum nl80211_channel_type channel_type)
1485{
1486 struct ieee80211_local *local = wiphy_priv(wiphy);
1487 struct ieee80211_sub_if_data *sdata = NULL;
1488 struct ieee80211_channel *old_oper;
1489 enum nl80211_channel_type old_oper_type;
1490 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
1491
1492 if (netdev)
1493 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1494
1495 switch (ieee80211_get_channel_mode(local, NULL)) {
1496 case CHAN_MODE_HOPPING:
1497 return -EBUSY;
1498 case CHAN_MODE_FIXED:
1499 if (local->oper_channel != chan)
1500 return -EBUSY;
1501 if (!sdata && local->_oper_channel_type == channel_type)
1502 return 0;
1503 break;
1504 case CHAN_MODE_UNDEFINED:
1505 break;
1506 }
1507
1508 if (sdata)
1509 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1510 old_oper_type = local->_oper_channel_type;
1511
1512 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1513 return -EBUSY;
1514
1515 old_oper = local->oper_channel;
1516 local->oper_channel = chan;
1517
1518 /* Update driver if changes were actually made. */
1519 if ((old_oper != local->oper_channel) ||
1520 (old_oper_type != local->_oper_channel_type))
1521 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1522
1523 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1524 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
1525 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1526
1527 return 0;
1528}
1529
1530#ifdef CONFIG_PM
1531static int ieee80211_suspend(struct wiphy *wiphy,
1532 struct cfg80211_wowlan *wowlan)
1533{
1534 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1535}
1536
1537static int ieee80211_resume(struct wiphy *wiphy)
1538{
1539 return __ieee80211_resume(wiphy_priv(wiphy));
1540}
1541#else
1542#define ieee80211_suspend NULL
1543#define ieee80211_resume NULL
1544#endif
1545
1546static int ieee80211_scan(struct wiphy *wiphy,
1547 struct net_device *dev,
1548 struct cfg80211_scan_request *req)
1549{
1550 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1551
1552 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1553 case NL80211_IFTYPE_STATION:
1554 case NL80211_IFTYPE_ADHOC:
1555 case NL80211_IFTYPE_MESH_POINT:
1556 case NL80211_IFTYPE_P2P_CLIENT:
1557 break;
1558 case NL80211_IFTYPE_P2P_GO:
1559 if (sdata->local->ops->hw_scan)
1560 break;
1561 /*
1562 * FIXME: implement NoA while scanning in software,
1563 * for now fall through to allow scanning only when
1564 * beaconing hasn't been configured yet
1565 */
1566 case NL80211_IFTYPE_AP:
1567 if (sdata->u.ap.beacon)
1568 return -EOPNOTSUPP;
1569 break;
1570 default:
1571 return -EOPNOTSUPP;
1572 }
1573
1574 return ieee80211_request_scan(sdata, req);
1575}
1576
1577static int
1578ieee80211_sched_scan_start(struct wiphy *wiphy,
1579 struct net_device *dev,
1580 struct cfg80211_sched_scan_request *req)
1581{
1582 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1583
1584 if (!sdata->local->ops->sched_scan_start)
1585 return -EOPNOTSUPP;
1586
1587 return ieee80211_request_sched_scan_start(sdata, req);
1588}
1589
1590static int
1591ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1592{
1593 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1594
1595 if (!sdata->local->ops->sched_scan_stop)
1596 return -EOPNOTSUPP;
1597
1598 return ieee80211_request_sched_scan_stop(sdata);
1599}
1600
1601static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1602 struct cfg80211_auth_request *req)
1603{
1604 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1605}
1606
1607static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1608 struct cfg80211_assoc_request *req)
1609{
1610 struct ieee80211_local *local = wiphy_priv(wiphy);
1611 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1612
1613 switch (ieee80211_get_channel_mode(local, sdata)) {
1614 case CHAN_MODE_HOPPING:
1615 return -EBUSY;
1616 case CHAN_MODE_FIXED:
1617 if (local->oper_channel == req->bss->channel)
1618 break;
1619 return -EBUSY;
1620 case CHAN_MODE_UNDEFINED:
1621 break;
1622 }
1623
1624 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1625}
1626
1627static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1628 struct cfg80211_deauth_request *req)
1629{
1630 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1631}
1632
1633static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1634 struct cfg80211_disassoc_request *req)
1635{
1636 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1637}
1638
1639static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1640 struct cfg80211_ibss_params *params)
1641{
1642 struct ieee80211_local *local = wiphy_priv(wiphy);
1643 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1644
1645 switch (ieee80211_get_channel_mode(local, sdata)) {
1646 case CHAN_MODE_HOPPING:
1647 return -EBUSY;
1648 case CHAN_MODE_FIXED:
1649 if (!params->channel_fixed)
1650 return -EBUSY;
1651 if (local->oper_channel == params->channel)
1652 break;
1653 return -EBUSY;
1654 case CHAN_MODE_UNDEFINED:
1655 break;
1656 }
1657
1658 return ieee80211_ibss_join(sdata, params);
1659}
1660
1661static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1662{
1663 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1664
1665 return ieee80211_ibss_leave(sdata);
1666}
1667
1668static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1669{
1670 struct ieee80211_local *local = wiphy_priv(wiphy);
1671 int err;
1672
1673 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1674 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1675
1676 if (err)
1677 return err;
1678 }
1679
1680 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1681 err = drv_set_coverage_class(local, wiphy->coverage_class);
1682
1683 if (err)
1684 return err;
1685 }
1686
1687 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1688 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1689
1690 if (err)
1691 return err;
1692 }
1693
1694 if (changed & WIPHY_PARAM_RETRY_SHORT)
1695 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1696 if (changed & WIPHY_PARAM_RETRY_LONG)
1697 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1698 if (changed &
1699 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1700 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1701
1702 return 0;
1703}
1704
1705static int ieee80211_set_tx_power(struct wiphy *wiphy,
1706 enum nl80211_tx_power_setting type, int mbm)
1707{
1708 struct ieee80211_local *local = wiphy_priv(wiphy);
1709 struct ieee80211_channel *chan = local->hw.conf.channel;
1710 u32 changes = 0;
1711
1712 switch (type) {
1713 case NL80211_TX_POWER_AUTOMATIC:
1714 local->user_power_level = -1;
1715 break;
1716 case NL80211_TX_POWER_LIMITED:
1717 if (mbm < 0 || (mbm % 100))
1718 return -EOPNOTSUPP;
1719 local->user_power_level = MBM_TO_DBM(mbm);
1720 break;
1721 case NL80211_TX_POWER_FIXED:
1722 if (mbm < 0 || (mbm % 100))
1723 return -EOPNOTSUPP;
1724 /* TODO: move to cfg80211 when it knows the channel */
1725 if (MBM_TO_DBM(mbm) > chan->max_power)
1726 return -EINVAL;
1727 local->user_power_level = MBM_TO_DBM(mbm);
1728 break;
1729 }
1730
1731 ieee80211_hw_config(local, changes);
1732
1733 return 0;
1734}
1735
1736static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1737{
1738 struct ieee80211_local *local = wiphy_priv(wiphy);
1739
1740 *dbm = local->hw.conf.power_level;
1741
1742 return 0;
1743}
1744
1745static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1746 const u8 *addr)
1747{
1748 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1749
1750 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1751
1752 return 0;
1753}
1754
1755static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1756{
1757 struct ieee80211_local *local = wiphy_priv(wiphy);
1758
1759 drv_rfkill_poll(local);
1760}
1761
1762#ifdef CONFIG_NL80211_TESTMODE
1763static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1764{
1765 struct ieee80211_local *local = wiphy_priv(wiphy);
1766
1767 if (!local->ops->testmode_cmd)
1768 return -EOPNOTSUPP;
1769
1770 return local->ops->testmode_cmd(&local->hw, data, len);
1771}
1772
1773static int ieee80211_testmode_dump(struct wiphy *wiphy,
1774 struct sk_buff *skb,
1775 struct netlink_callback *cb,
1776 void *data, int len)
1777{
1778 struct ieee80211_local *local = wiphy_priv(wiphy);
1779
1780 if (!local->ops->testmode_dump)
1781 return -EOPNOTSUPP;
1782
1783 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1784}
1785#endif
1786
1787int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1788 enum ieee80211_smps_mode smps_mode)
1789{
1790 const u8 *ap;
1791 enum ieee80211_smps_mode old_req;
1792 int err;
1793
1794 lockdep_assert_held(&sdata->u.mgd.mtx);
1795
1796 old_req = sdata->u.mgd.req_smps;
1797 sdata->u.mgd.req_smps = smps_mode;
1798
1799 if (old_req == smps_mode &&
1800 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1801 return 0;
1802
1803 /*
1804 * If not associated, or current association is not an HT
1805 * association, there's no need to send an action frame.
1806 */
1807 if (!sdata->u.mgd.associated ||
1808 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
1809 mutex_lock(&sdata->local->iflist_mtx);
1810 ieee80211_recalc_smps(sdata->local);
1811 mutex_unlock(&sdata->local->iflist_mtx);
1812 return 0;
1813 }
1814
1815 ap = sdata->u.mgd.associated->bssid;
1816
1817 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1818 if (sdata->u.mgd.powersave)
1819 smps_mode = IEEE80211_SMPS_DYNAMIC;
1820 else
1821 smps_mode = IEEE80211_SMPS_OFF;
1822 }
1823
1824 /* send SM PS frame to AP */
1825 err = ieee80211_send_smps_action(sdata, smps_mode,
1826 ap, ap);
1827 if (err)
1828 sdata->u.mgd.req_smps = old_req;
1829
1830 return err;
1831}
1832
1833static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1834 bool enabled, int timeout)
1835{
1836 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1837 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1838
1839 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1840 return -EOPNOTSUPP;
1841
1842 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1843 return -EOPNOTSUPP;
1844
1845 if (enabled == sdata->u.mgd.powersave &&
1846 timeout == local->dynamic_ps_forced_timeout)
1847 return 0;
1848
1849 sdata->u.mgd.powersave = enabled;
1850 local->dynamic_ps_forced_timeout = timeout;
1851
1852 /* no change, but if automatic follow powersave */
1853 mutex_lock(&sdata->u.mgd.mtx);
1854 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1855 mutex_unlock(&sdata->u.mgd.mtx);
1856
1857 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1858 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1859
1860 ieee80211_recalc_ps(local, -1);
1861
1862 return 0;
1863}
1864
1865static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1866 struct net_device *dev,
1867 s32 rssi_thold, u32 rssi_hyst)
1868{
1869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1870 struct ieee80211_vif *vif = &sdata->vif;
1871 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1872
1873 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1874 rssi_hyst == bss_conf->cqm_rssi_hyst)
1875 return 0;
1876
1877 bss_conf->cqm_rssi_thold = rssi_thold;
1878 bss_conf->cqm_rssi_hyst = rssi_hyst;
1879
1880 /* tell the driver upon association, unless already associated */
1881 if (sdata->u.mgd.associated &&
1882 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
1883 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1884
1885 return 0;
1886}
1887
1888static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1889 struct net_device *dev,
1890 const u8 *addr,
1891 const struct cfg80211_bitrate_mask *mask)
1892{
1893 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1894 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1895 int i, ret;
1896
1897 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1898 ret = drv_set_bitrate_mask(local, sdata, mask);
1899 if (ret)
1900 return ret;
1901 }
1902
1903 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
1904 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1905 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
1906 sizeof(mask->control[i].mcs));
1907 }
1908
1909 return 0;
1910}
1911
1912static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1913 struct net_device *dev,
1914 struct ieee80211_channel *chan,
1915 enum nl80211_channel_type chantype,
1916 unsigned int duration, u64 *cookie)
1917{
1918 int ret;
1919 u32 random_cookie;
1920
1921 lockdep_assert_held(&local->mtx);
1922
1923 if (local->hw_roc_cookie)
1924 return -EBUSY;
1925 /* must be nonzero */
1926 random_cookie = random32() | 1;
1927
1928 *cookie = random_cookie;
1929 local->hw_roc_dev = dev;
1930 local->hw_roc_cookie = random_cookie;
1931 local->hw_roc_channel = chan;
1932 local->hw_roc_channel_type = chantype;
1933 local->hw_roc_duration = duration;
1934 ret = drv_remain_on_channel(local, chan, chantype, duration);
1935 if (ret) {
1936 local->hw_roc_channel = NULL;
1937 local->hw_roc_cookie = 0;
1938 }
1939
1940 return ret;
1941}
1942
1943static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1944 struct net_device *dev,
1945 struct ieee80211_channel *chan,
1946 enum nl80211_channel_type channel_type,
1947 unsigned int duration,
1948 u64 *cookie)
1949{
1950 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1951 struct ieee80211_local *local = sdata->local;
1952
1953 if (local->ops->remain_on_channel) {
1954 int ret;
1955
1956 mutex_lock(&local->mtx);
1957 ret = ieee80211_remain_on_channel_hw(local, dev,
1958 chan, channel_type,
1959 duration, cookie);
1960 local->hw_roc_for_tx = false;
1961 mutex_unlock(&local->mtx);
1962
1963 return ret;
1964 }
1965
1966 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1967 duration, cookie);
1968}
1969
1970static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1971 u64 cookie)
1972{
1973 int ret;
1974
1975 lockdep_assert_held(&local->mtx);
1976
1977 if (local->hw_roc_cookie != cookie)
1978 return -ENOENT;
1979
1980 ret = drv_cancel_remain_on_channel(local);
1981 if (ret)
1982 return ret;
1983
1984 local->hw_roc_cookie = 0;
1985 local->hw_roc_channel = NULL;
1986
1987 ieee80211_recalc_idle(local);
1988
1989 return 0;
1990}
1991
1992static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1993 struct net_device *dev,
1994 u64 cookie)
1995{
1996 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1997 struct ieee80211_local *local = sdata->local;
1998
1999 if (local->ops->cancel_remain_on_channel) {
2000 int ret;
2001
2002 mutex_lock(&local->mtx);
2003 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2004 mutex_unlock(&local->mtx);
2005
2006 return ret;
2007 }
2008
2009 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
2010}
2011
2012static enum work_done_result
2013ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
2014{
2015 /*
2016 * Use the data embedded in the work struct for reporting
2017 * here so if the driver mangled the SKB before dropping
2018 * it (which is the only way we really should get here)
2019 * then we don't report mangled data.
2020 *
2021 * If there was no wait time, then by the time we get here
2022 * the driver will likely not have reported the status yet,
2023 * so in that case userspace will have to deal with it.
2024 */
2025
2026 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
2027 cfg80211_mgmt_tx_status(wk->sdata->dev,
2028 (unsigned long) wk->offchan_tx.frame,
2029 wk->data, wk->data_len, false, GFP_KERNEL);
2030
2031 return WORK_DONE_DESTROY;
2032}
2033
2034static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2035 struct ieee80211_channel *chan, bool offchan,
2036 enum nl80211_channel_type channel_type,
2037 bool channel_type_valid, unsigned int wait,
2038 const u8 *buf, size_t len, bool no_cck,
2039 bool dont_wait_for_ack, u64 *cookie)
2040{
2041 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2042 struct ieee80211_local *local = sdata->local;
2043 struct sk_buff *skb;
2044 struct sta_info *sta;
2045 struct ieee80211_work *wk;
2046 const struct ieee80211_mgmt *mgmt = (void *)buf;
2047 u32 flags;
2048 bool is_offchan = false;
2049
2050 if (dont_wait_for_ack)
2051 flags = IEEE80211_TX_CTL_NO_ACK;
2052 else
2053 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2054 IEEE80211_TX_CTL_REQ_TX_STATUS;
2055
2056 /* Check that we are on the requested channel for transmission */
2057 if (chan != local->tmp_channel &&
2058 chan != local->oper_channel)
2059 is_offchan = true;
2060 if (channel_type_valid &&
2061 (channel_type != local->tmp_channel_type &&
2062 channel_type != local->_oper_channel_type))
2063 is_offchan = true;
2064
2065 if (chan == local->hw_roc_channel) {
2066 /* TODO: check channel type? */
2067 is_offchan = false;
2068 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2069 }
2070
2071 if (no_cck)
2072 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2073
2074 if (is_offchan && !offchan)
2075 return -EBUSY;
2076
2077 switch (sdata->vif.type) {
2078 case NL80211_IFTYPE_ADHOC:
2079 case NL80211_IFTYPE_AP:
2080 case NL80211_IFTYPE_AP_VLAN:
2081 case NL80211_IFTYPE_P2P_GO:
2082 case NL80211_IFTYPE_MESH_POINT:
2083 if (!ieee80211_is_action(mgmt->frame_control) ||
2084 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2085 break;
2086 rcu_read_lock();
2087 sta = sta_info_get(sdata, mgmt->da);
2088 rcu_read_unlock();
2089 if (!sta)
2090 return -ENOLINK;
2091 break;
2092 case NL80211_IFTYPE_STATION:
2093 case NL80211_IFTYPE_P2P_CLIENT:
2094 break;
2095 default:
2096 return -EOPNOTSUPP;
2097 }
2098
2099 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2100 if (!skb)
2101 return -ENOMEM;
2102 skb_reserve(skb, local->hw.extra_tx_headroom);
2103
2104 memcpy(skb_put(skb, len), buf, len);
2105
2106 IEEE80211_SKB_CB(skb)->flags = flags;
2107
2108 skb->dev = sdata->dev;
2109
2110 *cookie = (unsigned long) skb;
2111
2112 if (is_offchan && local->ops->remain_on_channel) {
2113 unsigned int duration;
2114 int ret;
2115
2116 mutex_lock(&local->mtx);
2117 /*
2118 * If the duration is zero, then the driver
2119 * wouldn't actually do anything. Set it to
2120 * 100 for now.
2121 *
2122 * TODO: cancel the off-channel operation
2123 * when we get the SKB's TX status and
2124 * the wait time was zero before.
2125 */
2126 duration = 100;
2127 if (wait)
2128 duration = wait;
2129 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2130 channel_type,
2131 duration, cookie);
2132 if (ret) {
2133 kfree_skb(skb);
2134 mutex_unlock(&local->mtx);
2135 return ret;
2136 }
2137
2138 local->hw_roc_for_tx = true;
2139 local->hw_roc_duration = wait;
2140
2141 /*
2142 * queue up frame for transmission after
2143 * ieee80211_ready_on_channel call
2144 */
2145
2146 /* modify cookie to prevent API mismatches */
2147 *cookie ^= 2;
2148 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2149 local->hw_roc_skb = skb;
2150 local->hw_roc_skb_for_status = skb;
2151 mutex_unlock(&local->mtx);
2152
2153 return 0;
2154 }
2155
2156 /*
2157 * Can transmit right away if the channel was the
2158 * right one and there's no wait involved... If a
2159 * wait is involved, we might otherwise not be on
2160 * the right channel for long enough!
2161 */
2162 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2163 ieee80211_tx_skb(sdata, skb);
2164 return 0;
2165 }
2166
2167 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2168 if (!wk) {
2169 kfree_skb(skb);
2170 return -ENOMEM;
2171 }
2172
2173 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2174 wk->chan = chan;
2175 wk->chan_type = channel_type;
2176 wk->sdata = sdata;
2177 wk->done = ieee80211_offchan_tx_done;
2178 wk->offchan_tx.frame = skb;
2179 wk->offchan_tx.wait = wait;
2180 wk->data_len = len;
2181 memcpy(wk->data, buf, len);
2182
2183 ieee80211_add_work(wk);
2184 return 0;
2185}
2186
2187static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2188 struct net_device *dev,
2189 u64 cookie)
2190{
2191 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2192 struct ieee80211_local *local = sdata->local;
2193 struct ieee80211_work *wk;
2194 int ret = -ENOENT;
2195
2196 mutex_lock(&local->mtx);
2197
2198 if (local->ops->cancel_remain_on_channel) {
2199 cookie ^= 2;
2200 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2201
2202 if (ret == 0) {
2203 kfree_skb(local->hw_roc_skb);
2204 local->hw_roc_skb = NULL;
2205 local->hw_roc_skb_for_status = NULL;
2206 }
2207
2208 mutex_unlock(&local->mtx);
2209
2210 return ret;
2211 }
2212
2213 list_for_each_entry(wk, &local->work_list, list) {
2214 if (wk->sdata != sdata)
2215 continue;
2216
2217 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2218 continue;
2219
2220 if (cookie != (unsigned long) wk->offchan_tx.frame)
2221 continue;
2222
2223 wk->timeout = jiffies;
2224
2225 ieee80211_queue_work(&local->hw, &local->work_work);
2226 ret = 0;
2227 break;
2228 }
2229 mutex_unlock(&local->mtx);
2230
2231 return ret;
2232}
2233
2234static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2235 struct net_device *dev,
2236 u16 frame_type, bool reg)
2237{
2238 struct ieee80211_local *local = wiphy_priv(wiphy);
2239
2240 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2241 return;
2242
2243 if (reg)
2244 local->probe_req_reg++;
2245 else
2246 local->probe_req_reg--;
2247
2248 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2249}
2250
2251static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2252{
2253 struct ieee80211_local *local = wiphy_priv(wiphy);
2254
2255 if (local->started)
2256 return -EOPNOTSUPP;
2257
2258 return drv_set_antenna(local, tx_ant, rx_ant);
2259}
2260
2261static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2262{
2263 struct ieee80211_local *local = wiphy_priv(wiphy);
2264
2265 return drv_get_antenna(local, tx_ant, rx_ant);
2266}
2267
2268static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2269{
2270 struct ieee80211_local *local = wiphy_priv(wiphy);
2271
2272 return drv_set_ringparam(local, tx, rx);
2273}
2274
2275static void ieee80211_get_ringparam(struct wiphy *wiphy,
2276 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2277{
2278 struct ieee80211_local *local = wiphy_priv(wiphy);
2279
2280 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2281}
2282
2283static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2284 struct net_device *dev,
2285 struct cfg80211_gtk_rekey_data *data)
2286{
2287 struct ieee80211_local *local = wiphy_priv(wiphy);
2288 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2289
2290 if (!local->ops->set_rekey_data)
2291 return -EOPNOTSUPP;
2292
2293 drv_set_rekey_data(local, sdata, data);
2294
2295 return 0;
2296}
2297
2298static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2299{
2300 u8 *pos = (void *)skb_put(skb, 7);
2301
2302 *pos++ = WLAN_EID_EXT_CAPABILITY;
2303 *pos++ = 5; /* len */
2304 *pos++ = 0x0;
2305 *pos++ = 0x0;
2306 *pos++ = 0x0;
2307 *pos++ = 0x0;
2308 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2309}
2310
2311static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2312{
2313 struct ieee80211_local *local = sdata->local;
2314 u16 capab;
2315
2316 capab = 0;
2317 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2318 return capab;
2319
2320 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2321 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2322 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2323 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2324
2325 return capab;
2326}
2327
2328static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2329 u8 *peer, u8 *bssid)
2330{
2331 struct ieee80211_tdls_lnkie *lnkid;
2332
2333 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2334
2335 lnkid->ie_type = WLAN_EID_LINK_ID;
2336 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2337
2338 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2339 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2340 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2341}
2342
2343static int
2344ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2345 u8 *peer, u8 action_code, u8 dialog_token,
2346 u16 status_code, struct sk_buff *skb)
2347{
2348 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2349 struct ieee80211_tdls_data *tf;
2350
2351 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2352
2353 memcpy(tf->da, peer, ETH_ALEN);
2354 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2355 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2356 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2357
2358 switch (action_code) {
2359 case WLAN_TDLS_SETUP_REQUEST:
2360 tf->category = WLAN_CATEGORY_TDLS;
2361 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2362
2363 skb_put(skb, sizeof(tf->u.setup_req));
2364 tf->u.setup_req.dialog_token = dialog_token;
2365 tf->u.setup_req.capability =
2366 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2367
2368 ieee80211_add_srates_ie(&sdata->vif, skb);
2369 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2370 ieee80211_tdls_add_ext_capab(skb);
2371 break;
2372 case WLAN_TDLS_SETUP_RESPONSE:
2373 tf->category = WLAN_CATEGORY_TDLS;
2374 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2375
2376 skb_put(skb, sizeof(tf->u.setup_resp));
2377 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2378 tf->u.setup_resp.dialog_token = dialog_token;
2379 tf->u.setup_resp.capability =
2380 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2381
2382 ieee80211_add_srates_ie(&sdata->vif, skb);
2383 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2384 ieee80211_tdls_add_ext_capab(skb);
2385 break;
2386 case WLAN_TDLS_SETUP_CONFIRM:
2387 tf->category = WLAN_CATEGORY_TDLS;
2388 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2389
2390 skb_put(skb, sizeof(tf->u.setup_cfm));
2391 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2392 tf->u.setup_cfm.dialog_token = dialog_token;
2393 break;
2394 case WLAN_TDLS_TEARDOWN:
2395 tf->category = WLAN_CATEGORY_TDLS;
2396 tf->action_code = WLAN_TDLS_TEARDOWN;
2397
2398 skb_put(skb, sizeof(tf->u.teardown));
2399 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2400 break;
2401 case WLAN_TDLS_DISCOVERY_REQUEST:
2402 tf->category = WLAN_CATEGORY_TDLS;
2403 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2404
2405 skb_put(skb, sizeof(tf->u.discover_req));
2406 tf->u.discover_req.dialog_token = dialog_token;
2407 break;
2408 default:
2409 return -EINVAL;
2410 }
2411
2412 return 0;
2413}
2414
2415static int
2416ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2417 u8 *peer, u8 action_code, u8 dialog_token,
2418 u16 status_code, struct sk_buff *skb)
2419{
2420 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2421 struct ieee80211_mgmt *mgmt;
2422
2423 mgmt = (void *)skb_put(skb, 24);
2424 memset(mgmt, 0, 24);
2425 memcpy(mgmt->da, peer, ETH_ALEN);
2426 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2427 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2428
2429 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2430 IEEE80211_STYPE_ACTION);
2431
2432 switch (action_code) {
2433 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2434 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2435 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2436 mgmt->u.action.u.tdls_discover_resp.action_code =
2437 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2438 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2439 dialog_token;
2440 mgmt->u.action.u.tdls_discover_resp.capability =
2441 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2442
2443 ieee80211_add_srates_ie(&sdata->vif, skb);
2444 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2445 ieee80211_tdls_add_ext_capab(skb);
2446 break;
2447 default:
2448 return -EINVAL;
2449 }
2450
2451 return 0;
2452}
2453
2454static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2455 u8 *peer, u8 action_code, u8 dialog_token,
2456 u16 status_code, const u8 *extra_ies,
2457 size_t extra_ies_len)
2458{
2459 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2460 struct ieee80211_local *local = sdata->local;
2461 struct ieee80211_tx_info *info;
2462 struct sk_buff *skb = NULL;
2463 bool send_direct;
2464 int ret;
2465
2466 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2467 return -ENOTSUPP;
2468
2469 /* make sure we are in managed mode, and associated */
2470 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2471 !sdata->u.mgd.associated)
2472 return -EINVAL;
2473
2474#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2475 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2476#endif
2477
2478 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2479 max(sizeof(struct ieee80211_mgmt),
2480 sizeof(struct ieee80211_tdls_data)) +
2481 50 + /* supported rates */
2482 7 + /* ext capab */
2483 extra_ies_len +
2484 sizeof(struct ieee80211_tdls_lnkie));
2485 if (!skb)
2486 return -ENOMEM;
2487
2488 info = IEEE80211_SKB_CB(skb);
2489 skb_reserve(skb, local->hw.extra_tx_headroom);
2490
2491 switch (action_code) {
2492 case WLAN_TDLS_SETUP_REQUEST:
2493 case WLAN_TDLS_SETUP_RESPONSE:
2494 case WLAN_TDLS_SETUP_CONFIRM:
2495 case WLAN_TDLS_TEARDOWN:
2496 case WLAN_TDLS_DISCOVERY_REQUEST:
2497 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2498 action_code, dialog_token,
2499 status_code, skb);
2500 send_direct = false;
2501 break;
2502 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2503 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2504 dialog_token, status_code,
2505 skb);
2506 send_direct = true;
2507 break;
2508 default:
2509 ret = -ENOTSUPP;
2510 break;
2511 }
2512
2513 if (ret < 0)
2514 goto fail;
2515
2516 if (extra_ies_len)
2517 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2518
2519 /* the TDLS link IE is always added last */
2520 switch (action_code) {
2521 case WLAN_TDLS_SETUP_REQUEST:
2522 case WLAN_TDLS_SETUP_CONFIRM:
2523 case WLAN_TDLS_TEARDOWN:
2524 case WLAN_TDLS_DISCOVERY_REQUEST:
2525 /* we are the initiator */
2526 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2527 sdata->u.mgd.bssid);
2528 break;
2529 case WLAN_TDLS_SETUP_RESPONSE:
2530 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2531 /* we are the responder */
2532 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2533 sdata->u.mgd.bssid);
2534 break;
2535 default:
2536 ret = -ENOTSUPP;
2537 goto fail;
2538 }
2539
2540 if (send_direct) {
2541 ieee80211_tx_skb(sdata, skb);
2542 return 0;
2543 }
2544
2545 /*
2546 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2547 * we should default to AC_VI.
2548 */
2549 switch (action_code) {
2550 case WLAN_TDLS_SETUP_REQUEST:
2551 case WLAN_TDLS_SETUP_RESPONSE:
2552 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2553 skb->priority = 2;
2554 break;
2555 default:
2556 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2557 skb->priority = 5;
2558 break;
2559 }
2560
2561 /* disable bottom halves when entering the Tx path */
2562 local_bh_disable();
2563 ret = ieee80211_subif_start_xmit(skb, dev);
2564 local_bh_enable();
2565
2566 return ret;
2567
2568fail:
2569 dev_kfree_skb(skb);
2570 return ret;
2571}
2572
2573static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2574 u8 *peer, enum nl80211_tdls_operation oper)
2575{
2576 struct sta_info *sta;
2577 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2578
2579 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2580 return -ENOTSUPP;
2581
2582 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2583 return -EINVAL;
2584
2585#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2586 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2587#endif
2588
2589 switch (oper) {
2590 case NL80211_TDLS_ENABLE_LINK:
2591 rcu_read_lock();
2592 sta = sta_info_get(sdata, peer);
2593 if (!sta) {
2594 rcu_read_unlock();
2595 return -ENOLINK;
2596 }
2597
2598 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
2599 rcu_read_unlock();
2600 break;
2601 case NL80211_TDLS_DISABLE_LINK:
2602 return sta_info_destroy_addr(sdata, peer);
2603 case NL80211_TDLS_TEARDOWN:
2604 case NL80211_TDLS_SETUP:
2605 case NL80211_TDLS_DISCOVERY_REQ:
2606 /* We don't support in-driver setup/teardown/discovery */
2607 return -ENOTSUPP;
2608 default:
2609 return -ENOTSUPP;
2610 }
2611
2612 return 0;
2613}
2614
2615static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2616 const u8 *peer, u64 *cookie)
2617{
2618 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2619 struct ieee80211_local *local = sdata->local;
2620 struct ieee80211_qos_hdr *nullfunc;
2621 struct sk_buff *skb;
2622 int size = sizeof(*nullfunc);
2623 __le16 fc;
2624 bool qos;
2625 struct ieee80211_tx_info *info;
2626 struct sta_info *sta;
2627
2628 rcu_read_lock();
2629 sta = sta_info_get(sdata, peer);
2630 if (sta) {
2631 qos = test_sta_flag(sta, WLAN_STA_WME);
2632 rcu_read_unlock();
2633 } else {
2634 rcu_read_unlock();
2635 return -ENOLINK;
2636 }
2637
2638 if (qos) {
2639 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2640 IEEE80211_STYPE_QOS_NULLFUNC |
2641 IEEE80211_FCTL_FROMDS);
2642 } else {
2643 size -= 2;
2644 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2645 IEEE80211_STYPE_NULLFUNC |
2646 IEEE80211_FCTL_FROMDS);
2647 }
2648
2649 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2650 if (!skb)
2651 return -ENOMEM;
2652
2653 skb->dev = dev;
2654
2655 skb_reserve(skb, local->hw.extra_tx_headroom);
2656
2657 nullfunc = (void *) skb_put(skb, size);
2658 nullfunc->frame_control = fc;
2659 nullfunc->duration_id = 0;
2660 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2661 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2662 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2663 nullfunc->seq_ctrl = 0;
2664
2665 info = IEEE80211_SKB_CB(skb);
2666
2667 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2668 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2669
2670 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2671 skb->priority = 7;
2672 if (qos)
2673 nullfunc->qos_ctrl = cpu_to_le16(7);
2674
2675 local_bh_disable();
2676 ieee80211_xmit(sdata, skb);
2677 local_bh_enable();
2678
2679 *cookie = (unsigned long) skb;
2680 return 0;
2681}
2682
2683static struct ieee80211_channel *
2684ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2685{
2686 struct ieee80211_local *local = wiphy_priv(wiphy);
2687
2688 return local->oper_channel;
2689}
2690
2691struct cfg80211_ops mac80211_config_ops = {
2692 .add_virtual_intf = ieee80211_add_iface,
2693 .del_virtual_intf = ieee80211_del_iface,
2694 .change_virtual_intf = ieee80211_change_iface,
2695 .add_key = ieee80211_add_key,
2696 .del_key = ieee80211_del_key,
2697 .get_key = ieee80211_get_key,
2698 .set_default_key = ieee80211_config_default_key,
2699 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
2700 .start_ap = ieee80211_start_ap,
2701 .change_beacon = ieee80211_change_beacon,
2702 .stop_ap = ieee80211_stop_ap,
2703 .add_station = ieee80211_add_station,
2704 .del_station = ieee80211_del_station,
2705 .change_station = ieee80211_change_station,
2706 .get_station = ieee80211_get_station,
2707 .dump_station = ieee80211_dump_station,
2708 .dump_survey = ieee80211_dump_survey,
2709#ifdef CONFIG_MAC80211_MESH
2710 .add_mpath = ieee80211_add_mpath,
2711 .del_mpath = ieee80211_del_mpath,
2712 .change_mpath = ieee80211_change_mpath,
2713 .get_mpath = ieee80211_get_mpath,
2714 .dump_mpath = ieee80211_dump_mpath,
2715 .update_mesh_config = ieee80211_update_mesh_config,
2716 .get_mesh_config = ieee80211_get_mesh_config,
2717 .join_mesh = ieee80211_join_mesh,
2718 .leave_mesh = ieee80211_leave_mesh,
2719#endif
2720 .change_bss = ieee80211_change_bss,
2721 .set_txq_params = ieee80211_set_txq_params,
2722 .set_channel = ieee80211_set_channel,
2723 .suspend = ieee80211_suspend,
2724 .resume = ieee80211_resume,
2725 .scan = ieee80211_scan,
2726 .sched_scan_start = ieee80211_sched_scan_start,
2727 .sched_scan_stop = ieee80211_sched_scan_stop,
2728 .auth = ieee80211_auth,
2729 .assoc = ieee80211_assoc,
2730 .deauth = ieee80211_deauth,
2731 .disassoc = ieee80211_disassoc,
2732 .join_ibss = ieee80211_join_ibss,
2733 .leave_ibss = ieee80211_leave_ibss,
2734 .set_wiphy_params = ieee80211_set_wiphy_params,
2735 .set_tx_power = ieee80211_set_tx_power,
2736 .get_tx_power = ieee80211_get_tx_power,
2737 .set_wds_peer = ieee80211_set_wds_peer,
2738 .rfkill_poll = ieee80211_rfkill_poll,
2739 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
2740 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
2741 .set_power_mgmt = ieee80211_set_power_mgmt,
2742 .set_bitrate_mask = ieee80211_set_bitrate_mask,
2743 .remain_on_channel = ieee80211_remain_on_channel,
2744 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2745 .mgmt_tx = ieee80211_mgmt_tx,
2746 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
2747 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
2748 .mgmt_frame_register = ieee80211_mgmt_frame_register,
2749 .set_antenna = ieee80211_set_antenna,
2750 .get_antenna = ieee80211_get_antenna,
2751 .set_ringparam = ieee80211_set_ringparam,
2752 .get_ringparam = ieee80211_get_ringparam,
2753 .set_rekey_data = ieee80211_set_rekey_data,
2754 .tdls_oper = ieee80211_tdls_oper,
2755 .tdls_mgmt = ieee80211_tdls_mgmt,
2756 .probe_client = ieee80211_probe_client,
2757 .get_channel = ieee80211_wiphy_get_channel,
2758 .set_noack_map = ieee80211_set_noack_map,
2759};