]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - net/mac80211/cfg.c
mac80211: allow vendor specific cipher suites
[mirror_ubuntu-jammy-kernel.git] / net / mac80211 / cfg.c
1 /*
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 <net/cfg80211.h>
16 #include "ieee80211_i.h"
17 #include "driver-ops.h"
18 #include "cfg.h"
19 #include "rate.h"
20 #include "mesh.h"
21
22 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
23 enum nl80211_iftype type, u32 *flags,
24 struct vif_params *params)
25 {
26 struct ieee80211_local *local = wiphy_priv(wiphy);
27 struct net_device *dev;
28 struct ieee80211_sub_if_data *sdata;
29 int err;
30
31 err = ieee80211_if_add(local, name, &dev, type, params);
32 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
33 return err;
34
35 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
36 sdata->u.mntr_flags = *flags;
37 return 0;
38 }
39
40 static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
41 {
42 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
43
44 return 0;
45 }
46
47 static int ieee80211_change_iface(struct wiphy *wiphy,
48 struct net_device *dev,
49 enum nl80211_iftype type, u32 *flags,
50 struct vif_params *params)
51 {
52 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
53 int ret;
54
55 if (ieee80211_sdata_running(sdata))
56 return -EBUSY;
57
58 ret = ieee80211_if_change_type(sdata, type);
59 if (ret)
60 return ret;
61
62 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
63 ieee80211_sdata_set_mesh_id(sdata,
64 params->mesh_id_len,
65 params->mesh_id);
66
67 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0)
69 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
70 else if (type == NL80211_IFTYPE_STATION &&
71 params && params->use_4addr >= 0)
72 sdata->u.mgd.use_4addr = params->use_4addr;
73
74 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
75 sdata->u.mntr_flags = *flags;
76
77 return 0;
78 }
79
80 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
81 u8 key_idx, const u8 *mac_addr,
82 struct key_params *params)
83 {
84 struct ieee80211_sub_if_data *sdata;
85 struct sta_info *sta = NULL;
86 struct ieee80211_key *key;
87 int err;
88
89 if (!netif_running(dev))
90 return -ENETDOWN;
91
92 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
93
94 /* reject WEP and TKIP keys if WEP failed to initialize */
95 switch (params->cipher) {
96 case WLAN_CIPHER_SUITE_WEP40:
97 case WLAN_CIPHER_SUITE_TKIP:
98 case WLAN_CIPHER_SUITE_WEP104:
99 if (IS_ERR(sdata->local->wep_tx_tfm))
100 return -EINVAL;
101 break;
102 default:
103 break;
104 }
105
106 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
107 params->key, params->seq_len, params->seq);
108 if (IS_ERR(key))
109 return PTR_ERR(key);
110
111 mutex_lock(&sdata->local->sta_mtx);
112
113 if (mac_addr) {
114 sta = sta_info_get_bss(sdata, mac_addr);
115 if (!sta) {
116 ieee80211_key_free(sdata->local, key);
117 err = -ENOENT;
118 goto out_unlock;
119 }
120 }
121
122 err = ieee80211_key_link(key, sdata, sta);
123 if (err)
124 ieee80211_key_free(sdata->local, key);
125
126 out_unlock:
127 mutex_unlock(&sdata->local->sta_mtx);
128
129 return err;
130 }
131
132 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
133 u8 key_idx, const u8 *mac_addr)
134 {
135 struct ieee80211_sub_if_data *sdata;
136 struct sta_info *sta;
137 int ret;
138
139 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
140
141 mutex_lock(&sdata->local->sta_mtx);
142
143 if (mac_addr) {
144 ret = -ENOENT;
145
146 sta = sta_info_get_bss(sdata, mac_addr);
147 if (!sta)
148 goto out_unlock;
149
150 if (sta->key) {
151 ieee80211_key_free(sdata->local, sta->key);
152 WARN_ON(sta->key);
153 ret = 0;
154 }
155
156 goto out_unlock;
157 }
158
159 if (!sdata->keys[key_idx]) {
160 ret = -ENOENT;
161 goto out_unlock;
162 }
163
164 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
165 WARN_ON(sdata->keys[key_idx]);
166
167 ret = 0;
168 out_unlock:
169 mutex_unlock(&sdata->local->sta_mtx);
170
171 return ret;
172 }
173
174 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
175 u8 key_idx, const u8 *mac_addr, void *cookie,
176 void (*callback)(void *cookie,
177 struct key_params *params))
178 {
179 struct ieee80211_sub_if_data *sdata;
180 struct sta_info *sta = NULL;
181 u8 seq[6] = {0};
182 struct key_params params;
183 struct ieee80211_key *key;
184 u32 iv32;
185 u16 iv16;
186 int err = -ENOENT;
187
188 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
189
190 rcu_read_lock();
191
192 if (mac_addr) {
193 sta = sta_info_get_bss(sdata, mac_addr);
194 if (!sta)
195 goto out;
196
197 key = sta->key;
198 } else
199 key = sdata->keys[key_idx];
200
201 if (!key)
202 goto out;
203
204 memset(&params, 0, sizeof(params));
205
206 params.cipher = key->conf.cipher;
207
208 switch (key->conf.cipher) {
209 case WLAN_CIPHER_SUITE_TKIP:
210 iv32 = key->u.tkip.tx.iv32;
211 iv16 = key->u.tkip.tx.iv16;
212
213 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
214 drv_get_tkip_seq(sdata->local,
215 key->conf.hw_key_idx,
216 &iv32, &iv16);
217
218 seq[0] = iv16 & 0xff;
219 seq[1] = (iv16 >> 8) & 0xff;
220 seq[2] = iv32 & 0xff;
221 seq[3] = (iv32 >> 8) & 0xff;
222 seq[4] = (iv32 >> 16) & 0xff;
223 seq[5] = (iv32 >> 24) & 0xff;
224 params.seq = seq;
225 params.seq_len = 6;
226 break;
227 case WLAN_CIPHER_SUITE_CCMP:
228 seq[0] = key->u.ccmp.tx_pn[5];
229 seq[1] = key->u.ccmp.tx_pn[4];
230 seq[2] = key->u.ccmp.tx_pn[3];
231 seq[3] = key->u.ccmp.tx_pn[2];
232 seq[4] = key->u.ccmp.tx_pn[1];
233 seq[5] = key->u.ccmp.tx_pn[0];
234 params.seq = seq;
235 params.seq_len = 6;
236 break;
237 case WLAN_CIPHER_SUITE_AES_CMAC:
238 seq[0] = key->u.aes_cmac.tx_pn[5];
239 seq[1] = key->u.aes_cmac.tx_pn[4];
240 seq[2] = key->u.aes_cmac.tx_pn[3];
241 seq[3] = key->u.aes_cmac.tx_pn[2];
242 seq[4] = key->u.aes_cmac.tx_pn[1];
243 seq[5] = key->u.aes_cmac.tx_pn[0];
244 params.seq = seq;
245 params.seq_len = 6;
246 break;
247 }
248
249 params.key = key->conf.key;
250 params.key_len = key->conf.keylen;
251
252 callback(cookie, &params);
253 err = 0;
254
255 out:
256 rcu_read_unlock();
257 return err;
258 }
259
260 static int ieee80211_config_default_key(struct wiphy *wiphy,
261 struct net_device *dev,
262 u8 key_idx)
263 {
264 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
265
266 ieee80211_set_default_key(sdata, key_idx);
267
268 return 0;
269 }
270
271 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
272 struct net_device *dev,
273 u8 key_idx)
274 {
275 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
276
277 ieee80211_set_default_mgmt_key(sdata, key_idx);
278
279 return 0;
280 }
281
282 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
283 {
284 struct ieee80211_sub_if_data *sdata = sta->sdata;
285
286 sinfo->generation = sdata->local->sta_generation;
287
288 sinfo->filled = STATION_INFO_INACTIVE_TIME |
289 STATION_INFO_RX_BYTES |
290 STATION_INFO_TX_BYTES |
291 STATION_INFO_RX_PACKETS |
292 STATION_INFO_TX_PACKETS |
293 STATION_INFO_TX_BITRATE;
294
295 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
296 sinfo->rx_bytes = sta->rx_bytes;
297 sinfo->tx_bytes = sta->tx_bytes;
298 sinfo->rx_packets = sta->rx_packets;
299 sinfo->tx_packets = sta->tx_packets;
300
301 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
302 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
303 sinfo->filled |= STATION_INFO_SIGNAL;
304 sinfo->signal = (s8)sta->last_signal;
305 }
306
307 sinfo->txrate.flags = 0;
308 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
309 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
310 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
311 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
312 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
313 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
314
315 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
316 struct ieee80211_supported_band *sband;
317 sband = sta->local->hw.wiphy->bands[
318 sta->local->hw.conf.channel->band];
319 sinfo->txrate.legacy =
320 sband->bitrates[sta->last_tx_rate.idx].bitrate;
321 } else
322 sinfo->txrate.mcs = sta->last_tx_rate.idx;
323
324 if (ieee80211_vif_is_mesh(&sdata->vif)) {
325 #ifdef CONFIG_MAC80211_MESH
326 sinfo->filled |= STATION_INFO_LLID |
327 STATION_INFO_PLID |
328 STATION_INFO_PLINK_STATE;
329
330 sinfo->llid = le16_to_cpu(sta->llid);
331 sinfo->plid = le16_to_cpu(sta->plid);
332 sinfo->plink_state = sta->plink_state;
333 #endif
334 }
335 }
336
337
338 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
339 int idx, u8 *mac, struct station_info *sinfo)
340 {
341 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
342 struct sta_info *sta;
343 int ret = -ENOENT;
344
345 rcu_read_lock();
346
347 sta = sta_info_get_by_idx(sdata, idx);
348 if (sta) {
349 ret = 0;
350 memcpy(mac, sta->sta.addr, ETH_ALEN);
351 sta_set_sinfo(sta, sinfo);
352 }
353
354 rcu_read_unlock();
355
356 return ret;
357 }
358
359 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
360 int idx, struct survey_info *survey)
361 {
362 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
363
364 return drv_get_survey(local, idx, survey);
365 }
366
367 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
368 u8 *mac, struct station_info *sinfo)
369 {
370 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
371 struct sta_info *sta;
372 int ret = -ENOENT;
373
374 rcu_read_lock();
375
376 sta = sta_info_get_bss(sdata, mac);
377 if (sta) {
378 ret = 0;
379 sta_set_sinfo(sta, sinfo);
380 }
381
382 rcu_read_unlock();
383
384 return ret;
385 }
386
387 /*
388 * This handles both adding a beacon and setting new beacon info
389 */
390 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
391 struct beacon_parameters *params)
392 {
393 struct beacon_data *new, *old;
394 int new_head_len, new_tail_len;
395 int size;
396 int err = -EINVAL;
397
398 old = sdata->u.ap.beacon;
399
400 /* head must not be zero-length */
401 if (params->head && !params->head_len)
402 return -EINVAL;
403
404 /*
405 * This is a kludge. beacon interval should really be part
406 * of the beacon information.
407 */
408 if (params->interval &&
409 (sdata->vif.bss_conf.beacon_int != params->interval)) {
410 sdata->vif.bss_conf.beacon_int = params->interval;
411 ieee80211_bss_info_change_notify(sdata,
412 BSS_CHANGED_BEACON_INT);
413 }
414
415 /* Need to have a beacon head if we don't have one yet */
416 if (!params->head && !old)
417 return err;
418
419 /* sorry, no way to start beaconing without dtim period */
420 if (!params->dtim_period && !old)
421 return err;
422
423 /* new or old head? */
424 if (params->head)
425 new_head_len = params->head_len;
426 else
427 new_head_len = old->head_len;
428
429 /* new or old tail? */
430 if (params->tail || !old)
431 /* params->tail_len will be zero for !params->tail */
432 new_tail_len = params->tail_len;
433 else
434 new_tail_len = old->tail_len;
435
436 size = sizeof(*new) + new_head_len + new_tail_len;
437
438 new = kzalloc(size, GFP_KERNEL);
439 if (!new)
440 return -ENOMEM;
441
442 /* start filling the new info now */
443
444 /* new or old dtim period? */
445 if (params->dtim_period)
446 new->dtim_period = params->dtim_period;
447 else
448 new->dtim_period = old->dtim_period;
449
450 /*
451 * pointers go into the block we allocated,
452 * memory is | beacon_data | head | tail |
453 */
454 new->head = ((u8 *) new) + sizeof(*new);
455 new->tail = new->head + new_head_len;
456 new->head_len = new_head_len;
457 new->tail_len = new_tail_len;
458
459 /* copy in head */
460 if (params->head)
461 memcpy(new->head, params->head, new_head_len);
462 else
463 memcpy(new->head, old->head, new_head_len);
464
465 /* copy in optional tail */
466 if (params->tail)
467 memcpy(new->tail, params->tail, new_tail_len);
468 else
469 if (old)
470 memcpy(new->tail, old->tail, new_tail_len);
471
472 sdata->vif.bss_conf.dtim_period = new->dtim_period;
473
474 rcu_assign_pointer(sdata->u.ap.beacon, new);
475
476 synchronize_rcu();
477
478 kfree(old);
479
480 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
481 BSS_CHANGED_BEACON);
482 return 0;
483 }
484
485 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
486 struct beacon_parameters *params)
487 {
488 struct ieee80211_sub_if_data *sdata;
489 struct beacon_data *old;
490
491 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
492
493 old = sdata->u.ap.beacon;
494
495 if (old)
496 return -EALREADY;
497
498 return ieee80211_config_beacon(sdata, params);
499 }
500
501 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
502 struct beacon_parameters *params)
503 {
504 struct ieee80211_sub_if_data *sdata;
505 struct beacon_data *old;
506
507 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
508
509 old = sdata->u.ap.beacon;
510
511 if (!old)
512 return -ENOENT;
513
514 return ieee80211_config_beacon(sdata, params);
515 }
516
517 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
518 {
519 struct ieee80211_sub_if_data *sdata;
520 struct beacon_data *old;
521
522 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
523
524 old = sdata->u.ap.beacon;
525
526 if (!old)
527 return -ENOENT;
528
529 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
530 synchronize_rcu();
531 kfree(old);
532
533 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
534 return 0;
535 }
536
537 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
538 struct iapp_layer2_update {
539 u8 da[ETH_ALEN]; /* broadcast */
540 u8 sa[ETH_ALEN]; /* STA addr */
541 __be16 len; /* 6 */
542 u8 dsap; /* 0 */
543 u8 ssap; /* 0 */
544 u8 control;
545 u8 xid_info[3];
546 } __packed;
547
548 static void ieee80211_send_layer2_update(struct sta_info *sta)
549 {
550 struct iapp_layer2_update *msg;
551 struct sk_buff *skb;
552
553 /* Send Level 2 Update Frame to update forwarding tables in layer 2
554 * bridge devices */
555
556 skb = dev_alloc_skb(sizeof(*msg));
557 if (!skb)
558 return;
559 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
560
561 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
562 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
563
564 memset(msg->da, 0xff, ETH_ALEN);
565 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
566 msg->len = htons(6);
567 msg->dsap = 0;
568 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
569 msg->control = 0xaf; /* XID response lsb.1111F101.
570 * F=0 (no poll command; unsolicited frame) */
571 msg->xid_info[0] = 0x81; /* XID format identifier */
572 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
573 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
574
575 skb->dev = sta->sdata->dev;
576 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
577 memset(skb->cb, 0, sizeof(skb->cb));
578 netif_rx_ni(skb);
579 }
580
581 static void sta_apply_parameters(struct ieee80211_local *local,
582 struct sta_info *sta,
583 struct station_parameters *params)
584 {
585 u32 rates;
586 int i, j;
587 struct ieee80211_supported_band *sband;
588 struct ieee80211_sub_if_data *sdata = sta->sdata;
589 u32 mask, set;
590
591 sband = local->hw.wiphy->bands[local->oper_channel->band];
592
593 spin_lock_bh(&sta->lock);
594 mask = params->sta_flags_mask;
595 set = params->sta_flags_set;
596
597 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
598 sta->flags &= ~WLAN_STA_AUTHORIZED;
599 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
600 sta->flags |= WLAN_STA_AUTHORIZED;
601 }
602
603 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
604 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
605 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
606 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
607 }
608
609 if (mask & BIT(NL80211_STA_FLAG_WME)) {
610 sta->flags &= ~WLAN_STA_WME;
611 if (set & BIT(NL80211_STA_FLAG_WME))
612 sta->flags |= WLAN_STA_WME;
613 }
614
615 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
616 sta->flags &= ~WLAN_STA_MFP;
617 if (set & BIT(NL80211_STA_FLAG_MFP))
618 sta->flags |= WLAN_STA_MFP;
619 }
620 spin_unlock_bh(&sta->lock);
621
622 /*
623 * cfg80211 validates this (1-2007) and allows setting the AID
624 * only when creating a new station entry
625 */
626 if (params->aid)
627 sta->sta.aid = params->aid;
628
629 /*
630 * FIXME: updating the following information is racy when this
631 * function is called from ieee80211_change_station().
632 * However, all this information should be static so
633 * maybe we should just reject attemps to change it.
634 */
635
636 if (params->listen_interval >= 0)
637 sta->listen_interval = params->listen_interval;
638
639 if (params->supported_rates) {
640 rates = 0;
641
642 for (i = 0; i < params->supported_rates_len; i++) {
643 int rate = (params->supported_rates[i] & 0x7f) * 5;
644 for (j = 0; j < sband->n_bitrates; j++) {
645 if (sband->bitrates[j].bitrate == rate)
646 rates |= BIT(j);
647 }
648 }
649 sta->sta.supp_rates[local->oper_channel->band] = rates;
650 }
651
652 if (params->ht_capa)
653 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
654 params->ht_capa,
655 &sta->sta.ht_cap);
656
657 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
658 switch (params->plink_action) {
659 case PLINK_ACTION_OPEN:
660 mesh_plink_open(sta);
661 break;
662 case PLINK_ACTION_BLOCK:
663 mesh_plink_block(sta);
664 break;
665 }
666 }
667 }
668
669 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
670 u8 *mac, struct station_parameters *params)
671 {
672 struct ieee80211_local *local = wiphy_priv(wiphy);
673 struct sta_info *sta;
674 struct ieee80211_sub_if_data *sdata;
675 int err;
676 int layer2_update;
677
678 if (params->vlan) {
679 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
680
681 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
682 sdata->vif.type != NL80211_IFTYPE_AP)
683 return -EINVAL;
684 } else
685 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
686
687 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
688 return -EINVAL;
689
690 if (is_multicast_ether_addr(mac))
691 return -EINVAL;
692
693 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
694 if (!sta)
695 return -ENOMEM;
696
697 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
698
699 sta_apply_parameters(local, sta, params);
700
701 rate_control_rate_init(sta);
702
703 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
704 sdata->vif.type == NL80211_IFTYPE_AP;
705
706 err = sta_info_insert_rcu(sta);
707 if (err) {
708 rcu_read_unlock();
709 return err;
710 }
711
712 if (layer2_update)
713 ieee80211_send_layer2_update(sta);
714
715 rcu_read_unlock();
716
717 return 0;
718 }
719
720 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
721 u8 *mac)
722 {
723 struct ieee80211_local *local = wiphy_priv(wiphy);
724 struct ieee80211_sub_if_data *sdata;
725
726 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
727
728 if (mac)
729 return sta_info_destroy_addr_bss(sdata, mac);
730
731 sta_info_flush(local, sdata);
732 return 0;
733 }
734
735 static int ieee80211_change_station(struct wiphy *wiphy,
736 struct net_device *dev,
737 u8 *mac,
738 struct station_parameters *params)
739 {
740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741 struct ieee80211_local *local = wiphy_priv(wiphy);
742 struct sta_info *sta;
743 struct ieee80211_sub_if_data *vlansdata;
744
745 rcu_read_lock();
746
747 sta = sta_info_get_bss(sdata, mac);
748 if (!sta) {
749 rcu_read_unlock();
750 return -ENOENT;
751 }
752
753 if (params->vlan && params->vlan != sta->sdata->dev) {
754 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
755
756 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
757 vlansdata->vif.type != NL80211_IFTYPE_AP) {
758 rcu_read_unlock();
759 return -EINVAL;
760 }
761
762 if (params->vlan->ieee80211_ptr->use_4addr) {
763 if (vlansdata->u.vlan.sta) {
764 rcu_read_unlock();
765 return -EBUSY;
766 }
767
768 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
769 }
770
771 sta->sdata = vlansdata;
772 ieee80211_send_layer2_update(sta);
773 }
774
775 sta_apply_parameters(local, sta, params);
776
777 rcu_read_unlock();
778
779 return 0;
780 }
781
782 #ifdef CONFIG_MAC80211_MESH
783 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
784 u8 *dst, u8 *next_hop)
785 {
786 struct ieee80211_sub_if_data *sdata;
787 struct mesh_path *mpath;
788 struct sta_info *sta;
789 int err;
790
791 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
792
793 rcu_read_lock();
794 sta = sta_info_get(sdata, next_hop);
795 if (!sta) {
796 rcu_read_unlock();
797 return -ENOENT;
798 }
799
800 err = mesh_path_add(dst, sdata);
801 if (err) {
802 rcu_read_unlock();
803 return err;
804 }
805
806 mpath = mesh_path_lookup(dst, sdata);
807 if (!mpath) {
808 rcu_read_unlock();
809 return -ENXIO;
810 }
811 mesh_path_fix_nexthop(mpath, sta);
812
813 rcu_read_unlock();
814 return 0;
815 }
816
817 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
818 u8 *dst)
819 {
820 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
821
822 if (dst)
823 return mesh_path_del(dst, sdata);
824
825 mesh_path_flush(sdata);
826 return 0;
827 }
828
829 static int ieee80211_change_mpath(struct wiphy *wiphy,
830 struct net_device *dev,
831 u8 *dst, u8 *next_hop)
832 {
833 struct ieee80211_sub_if_data *sdata;
834 struct mesh_path *mpath;
835 struct sta_info *sta;
836
837 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
838
839 rcu_read_lock();
840
841 sta = sta_info_get(sdata, next_hop);
842 if (!sta) {
843 rcu_read_unlock();
844 return -ENOENT;
845 }
846
847 mpath = mesh_path_lookup(dst, sdata);
848 if (!mpath) {
849 rcu_read_unlock();
850 return -ENOENT;
851 }
852
853 mesh_path_fix_nexthop(mpath, sta);
854
855 rcu_read_unlock();
856 return 0;
857 }
858
859 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
860 struct mpath_info *pinfo)
861 {
862 if (mpath->next_hop)
863 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
864 else
865 memset(next_hop, 0, ETH_ALEN);
866
867 pinfo->generation = mesh_paths_generation;
868
869 pinfo->filled = MPATH_INFO_FRAME_QLEN |
870 MPATH_INFO_SN |
871 MPATH_INFO_METRIC |
872 MPATH_INFO_EXPTIME |
873 MPATH_INFO_DISCOVERY_TIMEOUT |
874 MPATH_INFO_DISCOVERY_RETRIES |
875 MPATH_INFO_FLAGS;
876
877 pinfo->frame_qlen = mpath->frame_queue.qlen;
878 pinfo->sn = mpath->sn;
879 pinfo->metric = mpath->metric;
880 if (time_before(jiffies, mpath->exp_time))
881 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
882 pinfo->discovery_timeout =
883 jiffies_to_msecs(mpath->discovery_timeout);
884 pinfo->discovery_retries = mpath->discovery_retries;
885 pinfo->flags = 0;
886 if (mpath->flags & MESH_PATH_ACTIVE)
887 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
888 if (mpath->flags & MESH_PATH_RESOLVING)
889 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
890 if (mpath->flags & MESH_PATH_SN_VALID)
891 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
892 if (mpath->flags & MESH_PATH_FIXED)
893 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
894 if (mpath->flags & MESH_PATH_RESOLVING)
895 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
896
897 pinfo->flags = mpath->flags;
898 }
899
900 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
901 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
902
903 {
904 struct ieee80211_sub_if_data *sdata;
905 struct mesh_path *mpath;
906
907 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
908
909 rcu_read_lock();
910 mpath = mesh_path_lookup(dst, sdata);
911 if (!mpath) {
912 rcu_read_unlock();
913 return -ENOENT;
914 }
915 memcpy(dst, mpath->dst, ETH_ALEN);
916 mpath_set_pinfo(mpath, next_hop, pinfo);
917 rcu_read_unlock();
918 return 0;
919 }
920
921 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
922 int idx, u8 *dst, u8 *next_hop,
923 struct mpath_info *pinfo)
924 {
925 struct ieee80211_sub_if_data *sdata;
926 struct mesh_path *mpath;
927
928 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
929
930 rcu_read_lock();
931 mpath = mesh_path_lookup_by_idx(idx, sdata);
932 if (!mpath) {
933 rcu_read_unlock();
934 return -ENOENT;
935 }
936 memcpy(dst, mpath->dst, ETH_ALEN);
937 mpath_set_pinfo(mpath, next_hop, pinfo);
938 rcu_read_unlock();
939 return 0;
940 }
941
942 static int ieee80211_get_mesh_params(struct wiphy *wiphy,
943 struct net_device *dev,
944 struct mesh_config *conf)
945 {
946 struct ieee80211_sub_if_data *sdata;
947 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
948
949 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
950 return 0;
951 }
952
953 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
954 {
955 return (mask >> (parm-1)) & 0x1;
956 }
957
958 static int ieee80211_set_mesh_params(struct wiphy *wiphy,
959 struct net_device *dev,
960 const struct mesh_config *nconf, u32 mask)
961 {
962 struct mesh_config *conf;
963 struct ieee80211_sub_if_data *sdata;
964 struct ieee80211_if_mesh *ifmsh;
965
966 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
967 ifmsh = &sdata->u.mesh;
968
969 /* Set the config options which we are interested in setting */
970 conf = &(sdata->u.mesh.mshcfg);
971 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
972 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
973 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
974 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
975 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
976 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
977 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
978 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
979 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
980 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
981 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
982 conf->dot11MeshTTL = nconf->dot11MeshTTL;
983 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
984 conf->auto_open_plinks = nconf->auto_open_plinks;
985 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
986 conf->dot11MeshHWMPmaxPREQretries =
987 nconf->dot11MeshHWMPmaxPREQretries;
988 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
989 conf->path_refresh_time = nconf->path_refresh_time;
990 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
991 conf->min_discovery_timeout = nconf->min_discovery_timeout;
992 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
993 conf->dot11MeshHWMPactivePathTimeout =
994 nconf->dot11MeshHWMPactivePathTimeout;
995 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
996 conf->dot11MeshHWMPpreqMinInterval =
997 nconf->dot11MeshHWMPpreqMinInterval;
998 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
999 mask))
1000 conf->dot11MeshHWMPnetDiameterTraversalTime =
1001 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1002 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1003 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1004 ieee80211_mesh_root_setup(ifmsh);
1005 }
1006 return 0;
1007 }
1008
1009 #endif
1010
1011 static int ieee80211_change_bss(struct wiphy *wiphy,
1012 struct net_device *dev,
1013 struct bss_parameters *params)
1014 {
1015 struct ieee80211_sub_if_data *sdata;
1016 u32 changed = 0;
1017
1018 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1019
1020 if (params->use_cts_prot >= 0) {
1021 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1022 changed |= BSS_CHANGED_ERP_CTS_PROT;
1023 }
1024 if (params->use_short_preamble >= 0) {
1025 sdata->vif.bss_conf.use_short_preamble =
1026 params->use_short_preamble;
1027 changed |= BSS_CHANGED_ERP_PREAMBLE;
1028 }
1029
1030 if (!sdata->vif.bss_conf.use_short_slot &&
1031 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1032 sdata->vif.bss_conf.use_short_slot = true;
1033 changed |= BSS_CHANGED_ERP_SLOT;
1034 }
1035
1036 if (params->use_short_slot_time >= 0) {
1037 sdata->vif.bss_conf.use_short_slot =
1038 params->use_short_slot_time;
1039 changed |= BSS_CHANGED_ERP_SLOT;
1040 }
1041
1042 if (params->basic_rates) {
1043 int i, j;
1044 u32 rates = 0;
1045 struct ieee80211_local *local = wiphy_priv(wiphy);
1046 struct ieee80211_supported_band *sband =
1047 wiphy->bands[local->oper_channel->band];
1048
1049 for (i = 0; i < params->basic_rates_len; i++) {
1050 int rate = (params->basic_rates[i] & 0x7f) * 5;
1051 for (j = 0; j < sband->n_bitrates; j++) {
1052 if (sband->bitrates[j].bitrate == rate)
1053 rates |= BIT(j);
1054 }
1055 }
1056 sdata->vif.bss_conf.basic_rates = rates;
1057 changed |= BSS_CHANGED_BASIC_RATES;
1058 }
1059
1060 if (params->ap_isolate >= 0) {
1061 if (params->ap_isolate)
1062 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1063 else
1064 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1065 }
1066
1067 ieee80211_bss_info_change_notify(sdata, changed);
1068
1069 return 0;
1070 }
1071
1072 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1073 struct ieee80211_txq_params *params)
1074 {
1075 struct ieee80211_local *local = wiphy_priv(wiphy);
1076 struct ieee80211_tx_queue_params p;
1077
1078 if (!local->ops->conf_tx)
1079 return -EOPNOTSUPP;
1080
1081 memset(&p, 0, sizeof(p));
1082 p.aifs = params->aifs;
1083 p.cw_max = params->cwmax;
1084 p.cw_min = params->cwmin;
1085 p.txop = params->txop;
1086
1087 /*
1088 * Setting tx queue params disables u-apsd because it's only
1089 * called in master mode.
1090 */
1091 p.uapsd = false;
1092
1093 if (drv_conf_tx(local, params->queue, &p)) {
1094 wiphy_debug(local->hw.wiphy,
1095 "failed to set TX queue parameters for queue %d\n",
1096 params->queue);
1097 return -EINVAL;
1098 }
1099
1100 return 0;
1101 }
1102
1103 static int ieee80211_set_channel(struct wiphy *wiphy,
1104 struct net_device *netdev,
1105 struct ieee80211_channel *chan,
1106 enum nl80211_channel_type channel_type)
1107 {
1108 struct ieee80211_local *local = wiphy_priv(wiphy);
1109 struct ieee80211_sub_if_data *sdata = NULL;
1110
1111 if (netdev)
1112 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1113
1114 switch (ieee80211_get_channel_mode(local, NULL)) {
1115 case CHAN_MODE_HOPPING:
1116 return -EBUSY;
1117 case CHAN_MODE_FIXED:
1118 if (local->oper_channel != chan)
1119 return -EBUSY;
1120 if (!sdata && local->_oper_channel_type == channel_type)
1121 return 0;
1122 break;
1123 case CHAN_MODE_UNDEFINED:
1124 break;
1125 }
1126
1127 local->oper_channel = chan;
1128
1129 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1130 return -EBUSY;
1131
1132 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1133 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1134 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1135
1136 return 0;
1137 }
1138
1139 #ifdef CONFIG_PM
1140 static int ieee80211_suspend(struct wiphy *wiphy)
1141 {
1142 return __ieee80211_suspend(wiphy_priv(wiphy));
1143 }
1144
1145 static int ieee80211_resume(struct wiphy *wiphy)
1146 {
1147 return __ieee80211_resume(wiphy_priv(wiphy));
1148 }
1149 #else
1150 #define ieee80211_suspend NULL
1151 #define ieee80211_resume NULL
1152 #endif
1153
1154 static int ieee80211_scan(struct wiphy *wiphy,
1155 struct net_device *dev,
1156 struct cfg80211_scan_request *req)
1157 {
1158 struct ieee80211_sub_if_data *sdata;
1159
1160 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1161
1162 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1163 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1164 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1165 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1166 return -EOPNOTSUPP;
1167
1168 return ieee80211_request_scan(sdata, req);
1169 }
1170
1171 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1172 struct cfg80211_auth_request *req)
1173 {
1174 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1175 }
1176
1177 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1178 struct cfg80211_assoc_request *req)
1179 {
1180 struct ieee80211_local *local = wiphy_priv(wiphy);
1181 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1182
1183 switch (ieee80211_get_channel_mode(local, sdata)) {
1184 case CHAN_MODE_HOPPING:
1185 return -EBUSY;
1186 case CHAN_MODE_FIXED:
1187 if (local->oper_channel == req->bss->channel)
1188 break;
1189 return -EBUSY;
1190 case CHAN_MODE_UNDEFINED:
1191 break;
1192 }
1193
1194 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1195 }
1196
1197 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1198 struct cfg80211_deauth_request *req,
1199 void *cookie)
1200 {
1201 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1202 req, cookie);
1203 }
1204
1205 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1206 struct cfg80211_disassoc_request *req,
1207 void *cookie)
1208 {
1209 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1210 req, cookie);
1211 }
1212
1213 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1214 struct cfg80211_ibss_params *params)
1215 {
1216 struct ieee80211_local *local = wiphy_priv(wiphy);
1217 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1218
1219 switch (ieee80211_get_channel_mode(local, sdata)) {
1220 case CHAN_MODE_HOPPING:
1221 return -EBUSY;
1222 case CHAN_MODE_FIXED:
1223 if (!params->channel_fixed)
1224 return -EBUSY;
1225 if (local->oper_channel == params->channel)
1226 break;
1227 return -EBUSY;
1228 case CHAN_MODE_UNDEFINED:
1229 break;
1230 }
1231
1232 return ieee80211_ibss_join(sdata, params);
1233 }
1234
1235 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1236 {
1237 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1238
1239 return ieee80211_ibss_leave(sdata);
1240 }
1241
1242 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1243 {
1244 struct ieee80211_local *local = wiphy_priv(wiphy);
1245 int err;
1246
1247 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1248 err = drv_set_coverage_class(local, wiphy->coverage_class);
1249
1250 if (err)
1251 return err;
1252 }
1253
1254 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1255 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1256
1257 if (err)
1258 return err;
1259 }
1260
1261 if (changed & WIPHY_PARAM_RETRY_SHORT)
1262 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1263 if (changed & WIPHY_PARAM_RETRY_LONG)
1264 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1265 if (changed &
1266 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1267 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1268
1269 return 0;
1270 }
1271
1272 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1273 enum nl80211_tx_power_setting type, int mbm)
1274 {
1275 struct ieee80211_local *local = wiphy_priv(wiphy);
1276 struct ieee80211_channel *chan = local->hw.conf.channel;
1277 u32 changes = 0;
1278
1279 switch (type) {
1280 case NL80211_TX_POWER_AUTOMATIC:
1281 local->user_power_level = -1;
1282 break;
1283 case NL80211_TX_POWER_LIMITED:
1284 if (mbm < 0 || (mbm % 100))
1285 return -EOPNOTSUPP;
1286 local->user_power_level = MBM_TO_DBM(mbm);
1287 break;
1288 case NL80211_TX_POWER_FIXED:
1289 if (mbm < 0 || (mbm % 100))
1290 return -EOPNOTSUPP;
1291 /* TODO: move to cfg80211 when it knows the channel */
1292 if (MBM_TO_DBM(mbm) > chan->max_power)
1293 return -EINVAL;
1294 local->user_power_level = MBM_TO_DBM(mbm);
1295 break;
1296 }
1297
1298 ieee80211_hw_config(local, changes);
1299
1300 return 0;
1301 }
1302
1303 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1304 {
1305 struct ieee80211_local *local = wiphy_priv(wiphy);
1306
1307 *dbm = local->hw.conf.power_level;
1308
1309 return 0;
1310 }
1311
1312 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1313 u8 *addr)
1314 {
1315 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1316
1317 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1318
1319 return 0;
1320 }
1321
1322 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1323 {
1324 struct ieee80211_local *local = wiphy_priv(wiphy);
1325
1326 drv_rfkill_poll(local);
1327 }
1328
1329 #ifdef CONFIG_NL80211_TESTMODE
1330 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1331 {
1332 struct ieee80211_local *local = wiphy_priv(wiphy);
1333
1334 if (!local->ops->testmode_cmd)
1335 return -EOPNOTSUPP;
1336
1337 return local->ops->testmode_cmd(&local->hw, data, len);
1338 }
1339 #endif
1340
1341 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1342 enum ieee80211_smps_mode smps_mode)
1343 {
1344 const u8 *ap;
1345 enum ieee80211_smps_mode old_req;
1346 int err;
1347
1348 old_req = sdata->u.mgd.req_smps;
1349 sdata->u.mgd.req_smps = smps_mode;
1350
1351 if (old_req == smps_mode &&
1352 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1353 return 0;
1354
1355 /*
1356 * If not associated, or current association is not an HT
1357 * association, there's no need to send an action frame.
1358 */
1359 if (!sdata->u.mgd.associated ||
1360 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
1361 mutex_lock(&sdata->local->iflist_mtx);
1362 ieee80211_recalc_smps(sdata->local, sdata);
1363 mutex_unlock(&sdata->local->iflist_mtx);
1364 return 0;
1365 }
1366
1367 ap = sdata->u.mgd.associated->bssid;
1368
1369 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1370 if (sdata->u.mgd.powersave)
1371 smps_mode = IEEE80211_SMPS_DYNAMIC;
1372 else
1373 smps_mode = IEEE80211_SMPS_OFF;
1374 }
1375
1376 /* send SM PS frame to AP */
1377 err = ieee80211_send_smps_action(sdata, smps_mode,
1378 ap, ap);
1379 if (err)
1380 sdata->u.mgd.req_smps = old_req;
1381
1382 return err;
1383 }
1384
1385 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1386 bool enabled, int timeout)
1387 {
1388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1389 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1390
1391 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1392 return -EOPNOTSUPP;
1393
1394 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1395 return -EOPNOTSUPP;
1396
1397 if (enabled == sdata->u.mgd.powersave &&
1398 timeout == local->dynamic_ps_forced_timeout)
1399 return 0;
1400
1401 sdata->u.mgd.powersave = enabled;
1402 local->dynamic_ps_forced_timeout = timeout;
1403
1404 /* no change, but if automatic follow powersave */
1405 mutex_lock(&sdata->u.mgd.mtx);
1406 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1407 mutex_unlock(&sdata->u.mgd.mtx);
1408
1409 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1410 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1411
1412 ieee80211_recalc_ps(local, -1);
1413
1414 return 0;
1415 }
1416
1417 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1418 struct net_device *dev,
1419 s32 rssi_thold, u32 rssi_hyst)
1420 {
1421 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1422 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1423 struct ieee80211_vif *vif = &sdata->vif;
1424 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1425
1426 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1427 rssi_hyst == bss_conf->cqm_rssi_hyst)
1428 return 0;
1429
1430 bss_conf->cqm_rssi_thold = rssi_thold;
1431 bss_conf->cqm_rssi_hyst = rssi_hyst;
1432
1433 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1434 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1435 return -EOPNOTSUPP;
1436 return 0;
1437 }
1438
1439 /* tell the driver upon association, unless already associated */
1440 if (sdata->u.mgd.associated)
1441 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1442
1443 return 0;
1444 }
1445
1446 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1447 struct net_device *dev,
1448 const u8 *addr,
1449 const struct cfg80211_bitrate_mask *mask)
1450 {
1451 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1452 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1453 int i;
1454
1455 /*
1456 * This _could_ be supported by providing a hook for
1457 * drivers for this function, but at this point it
1458 * doesn't seem worth bothering.
1459 */
1460 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1461 return -EOPNOTSUPP;
1462
1463
1464 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1465 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1466
1467 return 0;
1468 }
1469
1470 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1471 struct net_device *dev,
1472 struct ieee80211_channel *chan,
1473 enum nl80211_channel_type channel_type,
1474 unsigned int duration,
1475 u64 *cookie)
1476 {
1477 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1478
1479 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1480 duration, cookie);
1481 }
1482
1483 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1484 struct net_device *dev,
1485 u64 cookie)
1486 {
1487 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1488
1489 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1490 }
1491
1492 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1493 struct ieee80211_channel *chan,
1494 enum nl80211_channel_type channel_type,
1495 bool channel_type_valid,
1496 const u8 *buf, size_t len, u64 *cookie)
1497 {
1498 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1499 struct ieee80211_local *local = sdata->local;
1500 struct sk_buff *skb;
1501 struct sta_info *sta;
1502 const struct ieee80211_mgmt *mgmt = (void *)buf;
1503 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1504 IEEE80211_TX_CTL_REQ_TX_STATUS;
1505
1506 /* Check that we are on the requested channel for transmission */
1507 if (chan != local->tmp_channel &&
1508 chan != local->oper_channel)
1509 return -EBUSY;
1510 if (channel_type_valid &&
1511 (channel_type != local->tmp_channel_type &&
1512 channel_type != local->_oper_channel_type))
1513 return -EBUSY;
1514
1515 switch (sdata->vif.type) {
1516 case NL80211_IFTYPE_ADHOC:
1517 if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
1518 break;
1519 rcu_read_lock();
1520 sta = sta_info_get(sdata, mgmt->da);
1521 rcu_read_unlock();
1522 if (!sta)
1523 return -ENOLINK;
1524 break;
1525 case NL80211_IFTYPE_STATION:
1526 break;
1527 default:
1528 return -EOPNOTSUPP;
1529 }
1530
1531 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1532 if (!skb)
1533 return -ENOMEM;
1534 skb_reserve(skb, local->hw.extra_tx_headroom);
1535
1536 memcpy(skb_put(skb, len), buf, len);
1537
1538 IEEE80211_SKB_CB(skb)->flags = flags;
1539
1540 skb->dev = sdata->dev;
1541 ieee80211_tx_skb(sdata, skb);
1542
1543 *cookie = (unsigned long) skb;
1544 return 0;
1545 }
1546
1547 struct cfg80211_ops mac80211_config_ops = {
1548 .add_virtual_intf = ieee80211_add_iface,
1549 .del_virtual_intf = ieee80211_del_iface,
1550 .change_virtual_intf = ieee80211_change_iface,
1551 .add_key = ieee80211_add_key,
1552 .del_key = ieee80211_del_key,
1553 .get_key = ieee80211_get_key,
1554 .set_default_key = ieee80211_config_default_key,
1555 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
1556 .add_beacon = ieee80211_add_beacon,
1557 .set_beacon = ieee80211_set_beacon,
1558 .del_beacon = ieee80211_del_beacon,
1559 .add_station = ieee80211_add_station,
1560 .del_station = ieee80211_del_station,
1561 .change_station = ieee80211_change_station,
1562 .get_station = ieee80211_get_station,
1563 .dump_station = ieee80211_dump_station,
1564 .dump_survey = ieee80211_dump_survey,
1565 #ifdef CONFIG_MAC80211_MESH
1566 .add_mpath = ieee80211_add_mpath,
1567 .del_mpath = ieee80211_del_mpath,
1568 .change_mpath = ieee80211_change_mpath,
1569 .get_mpath = ieee80211_get_mpath,
1570 .dump_mpath = ieee80211_dump_mpath,
1571 .set_mesh_params = ieee80211_set_mesh_params,
1572 .get_mesh_params = ieee80211_get_mesh_params,
1573 #endif
1574 .change_bss = ieee80211_change_bss,
1575 .set_txq_params = ieee80211_set_txq_params,
1576 .set_channel = ieee80211_set_channel,
1577 .suspend = ieee80211_suspend,
1578 .resume = ieee80211_resume,
1579 .scan = ieee80211_scan,
1580 .auth = ieee80211_auth,
1581 .assoc = ieee80211_assoc,
1582 .deauth = ieee80211_deauth,
1583 .disassoc = ieee80211_disassoc,
1584 .join_ibss = ieee80211_join_ibss,
1585 .leave_ibss = ieee80211_leave_ibss,
1586 .set_wiphy_params = ieee80211_set_wiphy_params,
1587 .set_tx_power = ieee80211_set_tx_power,
1588 .get_tx_power = ieee80211_get_tx_power,
1589 .set_wds_peer = ieee80211_set_wds_peer,
1590 .rfkill_poll = ieee80211_rfkill_poll,
1591 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
1592 .set_power_mgmt = ieee80211_set_power_mgmt,
1593 .set_bitrate_mask = ieee80211_set_bitrate_mask,
1594 .remain_on_channel = ieee80211_remain_on_channel,
1595 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
1596 .mgmt_tx = ieee80211_mgmt_tx,
1597 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
1598 };