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