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