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