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