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