a29f06c0bcf06e368fdd8173dd6746483f57c03a
[deliverable/linux.git] / net / mac80211 / cfg.c
1 /*
2 * mac80211 configuration hooks for cfg80211
3 *
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
9 #include <linux/ieee80211.h>
10 #include <linux/nl80211.h>
11 #include <linux/rtnetlink.h>
12 #include <linux/slab.h>
13 #include <net/net_namespace.h>
14 #include <linux/rcupdate.h>
15 #include <linux/if_ether.h>
16 #include <net/cfg80211.h>
17 #include "ieee80211_i.h"
18 #include "driver-ops.h"
19 #include "cfg.h"
20 #include "rate.h"
21 #include "mesh.h"
22
23 static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
27 {
28 struct ieee80211_local *local = wiphy_priv(wiphy);
29 struct net_device *dev;
30 struct ieee80211_sub_if_data *sdata;
31 int err;
32
33 err = ieee80211_if_add(local, name, &dev, type, params);
34 if (err)
35 return ERR_PTR(err);
36
37 if (type == NL80211_IFTYPE_MONITOR && flags) {
38 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
39 sdata->u.mntr_flags = *flags;
40 }
41
42 return dev;
43 }
44
45 static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
46 {
47 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
48
49 return 0;
50 }
51
52 static int ieee80211_change_iface(struct wiphy *wiphy,
53 struct net_device *dev,
54 enum nl80211_iftype type, u32 *flags,
55 struct vif_params *params)
56 {
57 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
58 int ret;
59
60 ret = ieee80211_if_change_type(sdata, type);
61 if (ret)
62 return ret;
63
64 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
66 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
67 else if (type == NL80211_IFTYPE_STATION &&
68 params && params->use_4addr >= 0)
69 sdata->u.mgd.use_4addr = params->use_4addr;
70
71 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
73
74 if (ieee80211_sdata_running(sdata)) {
75 /*
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
82 */
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
85 return -EBUSY;
86
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
90
91 ieee80211_configure_filter(local);
92 } else {
93 /*
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
97 */
98 sdata->u.mntr_flags = *flags;
99 }
100 }
101
102 return 0;
103 }
104
105 static int ieee80211_set_noack_map(struct wiphy *wiphy,
106 struct net_device *dev,
107 u16 noack_map)
108 {
109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
110
111 sdata->noack_map = noack_map;
112 return 0;
113 }
114
115 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
116 u8 key_idx, bool pairwise, const u8 *mac_addr,
117 struct key_params *params)
118 {
119 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
120 struct sta_info *sta = NULL;
121 struct ieee80211_key *key;
122 int err;
123
124 if (!ieee80211_sdata_running(sdata))
125 return -ENETDOWN;
126
127 /* reject WEP and TKIP keys if WEP failed to initialize */
128 switch (params->cipher) {
129 case WLAN_CIPHER_SUITE_WEP40:
130 case WLAN_CIPHER_SUITE_TKIP:
131 case WLAN_CIPHER_SUITE_WEP104:
132 if (IS_ERR(sdata->local->wep_tx_tfm))
133 return -EINVAL;
134 break;
135 default:
136 break;
137 }
138
139 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
140 params->key, params->seq_len, params->seq);
141 if (IS_ERR(key))
142 return PTR_ERR(key);
143
144 if (pairwise)
145 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
146
147 mutex_lock(&sdata->local->sta_mtx);
148
149 if (mac_addr) {
150 if (ieee80211_vif_is_mesh(&sdata->vif))
151 sta = sta_info_get(sdata, mac_addr);
152 else
153 sta = sta_info_get_bss(sdata, mac_addr);
154 if (!sta) {
155 ieee80211_key_free(sdata->local, key);
156 err = -ENOENT;
157 goto out_unlock;
158 }
159 }
160
161 err = ieee80211_key_link(key, sdata, sta);
162 if (err)
163 ieee80211_key_free(sdata->local, key);
164
165 out_unlock:
166 mutex_unlock(&sdata->local->sta_mtx);
167
168 return err;
169 }
170
171 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
172 u8 key_idx, bool pairwise, const u8 *mac_addr)
173 {
174 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
175 struct ieee80211_local *local = sdata->local;
176 struct sta_info *sta;
177 struct ieee80211_key *key = NULL;
178 int ret;
179
180 mutex_lock(&local->sta_mtx);
181 mutex_lock(&local->key_mtx);
182
183 if (mac_addr) {
184 ret = -ENOENT;
185
186 sta = sta_info_get_bss(sdata, mac_addr);
187 if (!sta)
188 goto out_unlock;
189
190 if (pairwise)
191 key = key_mtx_dereference(local, sta->ptk);
192 else
193 key = key_mtx_dereference(local, sta->gtk[key_idx]);
194 } else
195 key = key_mtx_dereference(local, sdata->keys[key_idx]);
196
197 if (!key) {
198 ret = -ENOENT;
199 goto out_unlock;
200 }
201
202 __ieee80211_key_free(key);
203
204 ret = 0;
205 out_unlock:
206 mutex_unlock(&local->key_mtx);
207 mutex_unlock(&local->sta_mtx);
208
209 return ret;
210 }
211
212 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
213 u8 key_idx, bool pairwise, const u8 *mac_addr,
214 void *cookie,
215 void (*callback)(void *cookie,
216 struct key_params *params))
217 {
218 struct ieee80211_sub_if_data *sdata;
219 struct sta_info *sta = NULL;
220 u8 seq[6] = {0};
221 struct key_params params;
222 struct ieee80211_key *key = NULL;
223 u64 pn64;
224 u32 iv32;
225 u16 iv16;
226 int err = -ENOENT;
227
228 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
229
230 rcu_read_lock();
231
232 if (mac_addr) {
233 sta = sta_info_get_bss(sdata, mac_addr);
234 if (!sta)
235 goto out;
236
237 if (pairwise)
238 key = rcu_dereference(sta->ptk);
239 else if (key_idx < NUM_DEFAULT_KEYS)
240 key = rcu_dereference(sta->gtk[key_idx]);
241 } else
242 key = rcu_dereference(sdata->keys[key_idx]);
243
244 if (!key)
245 goto out;
246
247 memset(&params, 0, sizeof(params));
248
249 params.cipher = key->conf.cipher;
250
251 switch (key->conf.cipher) {
252 case WLAN_CIPHER_SUITE_TKIP:
253 iv32 = key->u.tkip.tx.iv32;
254 iv16 = key->u.tkip.tx.iv16;
255
256 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
257 drv_get_tkip_seq(sdata->local,
258 key->conf.hw_key_idx,
259 &iv32, &iv16);
260
261 seq[0] = iv16 & 0xff;
262 seq[1] = (iv16 >> 8) & 0xff;
263 seq[2] = iv32 & 0xff;
264 seq[3] = (iv32 >> 8) & 0xff;
265 seq[4] = (iv32 >> 16) & 0xff;
266 seq[5] = (iv32 >> 24) & 0xff;
267 params.seq = seq;
268 params.seq_len = 6;
269 break;
270 case WLAN_CIPHER_SUITE_CCMP:
271 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
272 seq[0] = pn64;
273 seq[1] = pn64 >> 8;
274 seq[2] = pn64 >> 16;
275 seq[3] = pn64 >> 24;
276 seq[4] = pn64 >> 32;
277 seq[5] = pn64 >> 40;
278 params.seq = seq;
279 params.seq_len = 6;
280 break;
281 case WLAN_CIPHER_SUITE_AES_CMAC:
282 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
283 seq[0] = pn64;
284 seq[1] = pn64 >> 8;
285 seq[2] = pn64 >> 16;
286 seq[3] = pn64 >> 24;
287 seq[4] = pn64 >> 32;
288 seq[5] = pn64 >> 40;
289 params.seq = seq;
290 params.seq_len = 6;
291 break;
292 }
293
294 params.key = key->conf.key;
295 params.key_len = key->conf.keylen;
296
297 callback(cookie, &params);
298 err = 0;
299
300 out:
301 rcu_read_unlock();
302 return err;
303 }
304
305 static int ieee80211_config_default_key(struct wiphy *wiphy,
306 struct net_device *dev,
307 u8 key_idx, bool uni,
308 bool multi)
309 {
310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
311
312 ieee80211_set_default_key(sdata, key_idx, uni, multi);
313
314 return 0;
315 }
316
317 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
318 struct net_device *dev,
319 u8 key_idx)
320 {
321 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
322
323 ieee80211_set_default_mgmt_key(sdata, key_idx);
324
325 return 0;
326 }
327
328 static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
329 {
330 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
331 struct ieee80211_supported_band *sband;
332 sband = sta->local->hw.wiphy->bands[
333 sta->local->hw.conf.channel->band];
334 rate->legacy = sband->bitrates[idx].bitrate;
335 } else
336 rate->mcs = idx;
337 }
338
339 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
340 {
341 struct ieee80211_sub_if_data *sdata = sta->sdata;
342 struct timespec uptime;
343
344 sinfo->generation = sdata->local->sta_generation;
345
346 sinfo->filled = STATION_INFO_INACTIVE_TIME |
347 STATION_INFO_RX_BYTES |
348 STATION_INFO_TX_BYTES |
349 STATION_INFO_RX_PACKETS |
350 STATION_INFO_TX_PACKETS |
351 STATION_INFO_TX_RETRIES |
352 STATION_INFO_TX_FAILED |
353 STATION_INFO_TX_BITRATE |
354 STATION_INFO_RX_BITRATE |
355 STATION_INFO_RX_DROP_MISC |
356 STATION_INFO_BSS_PARAM |
357 STATION_INFO_CONNECTED_TIME |
358 STATION_INFO_STA_FLAGS;
359
360 do_posix_clock_monotonic_gettime(&uptime);
361 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
362
363 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
364 sinfo->rx_bytes = sta->rx_bytes;
365 sinfo->tx_bytes = sta->tx_bytes;
366 sinfo->rx_packets = sta->rx_packets;
367 sinfo->tx_packets = sta->tx_packets;
368 sinfo->tx_retries = sta->tx_retry_count;
369 sinfo->tx_failed = sta->tx_retry_failed;
370 sinfo->rx_dropped_misc = sta->rx_dropped;
371
372 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
373 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
374 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
375 sinfo->signal = (s8)sta->last_signal;
376 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
377 }
378
379 sinfo->txrate.flags = 0;
380 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
381 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
382 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
383 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
384 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
385 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
386 rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
387
388 sinfo->rxrate.flags = 0;
389 if (sta->last_rx_rate_flag & RX_FLAG_HT)
390 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
391 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
392 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
393 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
394 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
395 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
396
397 if (ieee80211_vif_is_mesh(&sdata->vif)) {
398 #ifdef CONFIG_MAC80211_MESH
399 sinfo->filled |= STATION_INFO_LLID |
400 STATION_INFO_PLID |
401 STATION_INFO_PLINK_STATE;
402
403 sinfo->llid = le16_to_cpu(sta->llid);
404 sinfo->plid = le16_to_cpu(sta->plid);
405 sinfo->plink_state = sta->plink_state;
406 #endif
407 }
408
409 sinfo->bss_param.flags = 0;
410 if (sdata->vif.bss_conf.use_cts_prot)
411 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
412 if (sdata->vif.bss_conf.use_short_preamble)
413 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
414 if (sdata->vif.bss_conf.use_short_slot)
415 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
416 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
417 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
418
419 sinfo->sta_flags.set = 0;
420 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
421 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
422 BIT(NL80211_STA_FLAG_WME) |
423 BIT(NL80211_STA_FLAG_MFP) |
424 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
425 BIT(NL80211_STA_FLAG_TDLS_PEER);
426 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
427 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
428 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
429 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
430 if (test_sta_flag(sta, WLAN_STA_WME))
431 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
432 if (test_sta_flag(sta, WLAN_STA_MFP))
433 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
434 if (test_sta_flag(sta, WLAN_STA_AUTH))
435 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
436 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
437 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
438 }
439
440
441 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
442 int idx, u8 *mac, struct station_info *sinfo)
443 {
444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
445 struct sta_info *sta;
446 int ret = -ENOENT;
447
448 rcu_read_lock();
449
450 sta = sta_info_get_by_idx(sdata, idx);
451 if (sta) {
452 ret = 0;
453 memcpy(mac, sta->sta.addr, ETH_ALEN);
454 sta_set_sinfo(sta, sinfo);
455 }
456
457 rcu_read_unlock();
458
459 return ret;
460 }
461
462 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
463 int idx, struct survey_info *survey)
464 {
465 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
466
467 return drv_get_survey(local, idx, survey);
468 }
469
470 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
471 u8 *mac, struct station_info *sinfo)
472 {
473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
474 struct sta_info *sta;
475 int ret = -ENOENT;
476
477 rcu_read_lock();
478
479 sta = sta_info_get_bss(sdata, mac);
480 if (sta) {
481 ret = 0;
482 sta_set_sinfo(sta, sinfo);
483 }
484
485 rcu_read_unlock();
486
487 return ret;
488 }
489
490 static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
491 struct beacon_parameters *params)
492 {
493 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
494
495 bss_conf->ssid_len = params->ssid_len;
496
497 if (params->ssid_len)
498 memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
499
500 bss_conf->hidden_ssid =
501 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
502 }
503
504 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
505 u8 *resp, size_t resp_len)
506 {
507 struct sk_buff *new, *old;
508
509 if (!resp || !resp_len)
510 return -EINVAL;
511
512 old = rtnl_dereference(sdata->u.ap.probe_resp);
513
514 new = dev_alloc_skb(resp_len);
515 if (!new)
516 return -ENOMEM;
517
518 memcpy(skb_put(new, resp_len), resp, resp_len);
519
520 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
521 synchronize_rcu();
522
523 if (old)
524 dev_kfree_skb(old);
525
526 return 0;
527 }
528
529 /*
530 * This handles both adding a beacon and setting new beacon info
531 */
532 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
533 struct beacon_parameters *params)
534 {
535 struct beacon_data *new, *old;
536 int new_head_len, new_tail_len;
537 int size;
538 int err = -EINVAL;
539 u32 changed = 0;
540
541 old = rtnl_dereference(sdata->u.ap.beacon);
542
543 /* head must not be zero-length */
544 if (params->head && !params->head_len)
545 return -EINVAL;
546
547 /*
548 * This is a kludge. beacon interval should really be part
549 * of the beacon information.
550 */
551 if (params->interval &&
552 (sdata->vif.bss_conf.beacon_int != params->interval)) {
553 sdata->vif.bss_conf.beacon_int = params->interval;
554 ieee80211_bss_info_change_notify(sdata,
555 BSS_CHANGED_BEACON_INT);
556 }
557
558 /* Need to have a beacon head if we don't have one yet */
559 if (!params->head && !old)
560 return err;
561
562 /* sorry, no way to start beaconing without dtim period */
563 if (!params->dtim_period && !old)
564 return err;
565
566 /* new or old head? */
567 if (params->head)
568 new_head_len = params->head_len;
569 else
570 new_head_len = old->head_len;
571
572 /* new or old tail? */
573 if (params->tail || !old)
574 /* params->tail_len will be zero for !params->tail */
575 new_tail_len = params->tail_len;
576 else
577 new_tail_len = old->tail_len;
578
579 size = sizeof(*new) + new_head_len + new_tail_len;
580
581 new = kzalloc(size, GFP_KERNEL);
582 if (!new)
583 return -ENOMEM;
584
585 /* start filling the new info now */
586
587 /* new or old dtim period? */
588 if (params->dtim_period)
589 new->dtim_period = params->dtim_period;
590 else
591 new->dtim_period = old->dtim_period;
592
593 /*
594 * pointers go into the block we allocated,
595 * memory is | beacon_data | head | tail |
596 */
597 new->head = ((u8 *) new) + sizeof(*new);
598 new->tail = new->head + new_head_len;
599 new->head_len = new_head_len;
600 new->tail_len = new_tail_len;
601
602 /* copy in head */
603 if (params->head)
604 memcpy(new->head, params->head, new_head_len);
605 else
606 memcpy(new->head, old->head, new_head_len);
607
608 /* copy in optional tail */
609 if (params->tail)
610 memcpy(new->tail, params->tail, new_tail_len);
611 else
612 if (old)
613 memcpy(new->tail, old->tail, new_tail_len);
614
615 sdata->vif.bss_conf.dtim_period = new->dtim_period;
616
617 RCU_INIT_POINTER(sdata->u.ap.beacon, new);
618
619 synchronize_rcu();
620
621 kfree(old);
622
623 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
624 params->probe_resp_len);
625 if (!err)
626 changed |= BSS_CHANGED_AP_PROBE_RESP;
627
628 ieee80211_config_ap_ssid(sdata, params);
629 changed |= BSS_CHANGED_BEACON_ENABLED |
630 BSS_CHANGED_BEACON |
631 BSS_CHANGED_SSID;
632
633 ieee80211_bss_info_change_notify(sdata, changed);
634 return 0;
635 }
636
637 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
638 struct beacon_parameters *params)
639 {
640 struct ieee80211_sub_if_data *sdata;
641 struct beacon_data *old;
642 struct ieee80211_sub_if_data *vlan;
643 int ret;
644
645 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
646
647 old = rtnl_dereference(sdata->u.ap.beacon);
648 if (old)
649 return -EALREADY;
650
651 ret = ieee80211_config_beacon(sdata, params);
652 if (ret)
653 return ret;
654
655 /*
656 * Apply control port protocol, this allows us to
657 * not encrypt dynamic WEP control frames.
658 */
659 sdata->control_port_protocol = params->crypto.control_port_ethertype;
660 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
661 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
662 vlan->control_port_protocol =
663 params->crypto.control_port_ethertype;
664 vlan->control_port_no_encrypt =
665 params->crypto.control_port_no_encrypt;
666 }
667
668 return 0;
669 }
670
671 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
672 struct beacon_parameters *params)
673 {
674 struct ieee80211_sub_if_data *sdata;
675 struct beacon_data *old;
676
677 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
678
679 old = rtnl_dereference(sdata->u.ap.beacon);
680 if (!old)
681 return -ENOENT;
682
683 return ieee80211_config_beacon(sdata, params);
684 }
685
686 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
687 {
688 struct ieee80211_sub_if_data *sdata;
689 struct beacon_data *old;
690
691 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
692
693 old = rtnl_dereference(sdata->u.ap.beacon);
694 if (!old)
695 return -ENOENT;
696
697 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
698 synchronize_rcu();
699 kfree(old);
700
701 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
702 return 0;
703 }
704
705 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
706 struct iapp_layer2_update {
707 u8 da[ETH_ALEN]; /* broadcast */
708 u8 sa[ETH_ALEN]; /* STA addr */
709 __be16 len; /* 6 */
710 u8 dsap; /* 0 */
711 u8 ssap; /* 0 */
712 u8 control;
713 u8 xid_info[3];
714 } __packed;
715
716 static void ieee80211_send_layer2_update(struct sta_info *sta)
717 {
718 struct iapp_layer2_update *msg;
719 struct sk_buff *skb;
720
721 /* Send Level 2 Update Frame to update forwarding tables in layer 2
722 * bridge devices */
723
724 skb = dev_alloc_skb(sizeof(*msg));
725 if (!skb)
726 return;
727 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
728
729 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
730 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
731
732 memset(msg->da, 0xff, ETH_ALEN);
733 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
734 msg->len = htons(6);
735 msg->dsap = 0;
736 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
737 msg->control = 0xaf; /* XID response lsb.1111F101.
738 * F=0 (no poll command; unsolicited frame) */
739 msg->xid_info[0] = 0x81; /* XID format identifier */
740 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
741 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
742
743 skb->dev = sta->sdata->dev;
744 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
745 memset(skb->cb, 0, sizeof(skb->cb));
746 netif_rx_ni(skb);
747 }
748
749 static void sta_apply_parameters(struct ieee80211_local *local,
750 struct sta_info *sta,
751 struct station_parameters *params)
752 {
753 u32 rates;
754 int i, j;
755 struct ieee80211_supported_band *sband;
756 struct ieee80211_sub_if_data *sdata = sta->sdata;
757 u32 mask, set;
758
759 sband = local->hw.wiphy->bands[local->oper_channel->band];
760
761 mask = params->sta_flags_mask;
762 set = params->sta_flags_set;
763
764 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
765 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
766 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
767 else
768 clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
769 }
770
771 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
772 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
773 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
774 else
775 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
776 }
777
778 if (mask & BIT(NL80211_STA_FLAG_WME)) {
779 if (set & BIT(NL80211_STA_FLAG_WME)) {
780 set_sta_flag(sta, WLAN_STA_WME);
781 sta->sta.wme = true;
782 } else {
783 clear_sta_flag(sta, WLAN_STA_WME);
784 sta->sta.wme = false;
785 }
786 }
787
788 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
789 if (set & BIT(NL80211_STA_FLAG_MFP))
790 set_sta_flag(sta, WLAN_STA_MFP);
791 else
792 clear_sta_flag(sta, WLAN_STA_MFP);
793 }
794
795 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
796 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
797 set_sta_flag(sta, WLAN_STA_AUTH);
798 else
799 clear_sta_flag(sta, WLAN_STA_AUTH);
800 }
801
802 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
803 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
804 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
805 else
806 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
807 }
808
809 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
810 sta->sta.uapsd_queues = params->uapsd_queues;
811 sta->sta.max_sp = params->max_sp;
812 }
813
814 /*
815 * cfg80211 validates this (1-2007) and allows setting the AID
816 * only when creating a new station entry
817 */
818 if (params->aid)
819 sta->sta.aid = params->aid;
820
821 /*
822 * FIXME: updating the following information is racy when this
823 * function is called from ieee80211_change_station().
824 * However, all this information should be static so
825 * maybe we should just reject attemps to change it.
826 */
827
828 if (params->listen_interval >= 0)
829 sta->listen_interval = params->listen_interval;
830
831 if (params->supported_rates) {
832 rates = 0;
833
834 for (i = 0; i < params->supported_rates_len; i++) {
835 int rate = (params->supported_rates[i] & 0x7f) * 5;
836 for (j = 0; j < sband->n_bitrates; j++) {
837 if (sband->bitrates[j].bitrate == rate)
838 rates |= BIT(j);
839 }
840 }
841 sta->sta.supp_rates[local->oper_channel->band] = rates;
842 }
843
844 if (params->ht_capa)
845 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
846 params->ht_capa,
847 &sta->sta.ht_cap);
848
849 if (ieee80211_vif_is_mesh(&sdata->vif)) {
850 #ifdef CONFIG_MAC80211_MESH
851 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
852 switch (params->plink_state) {
853 case NL80211_PLINK_LISTEN:
854 case NL80211_PLINK_ESTAB:
855 case NL80211_PLINK_BLOCKED:
856 sta->plink_state = params->plink_state;
857 break;
858 default:
859 /* nothing */
860 break;
861 }
862 else
863 switch (params->plink_action) {
864 case PLINK_ACTION_OPEN:
865 mesh_plink_open(sta);
866 break;
867 case PLINK_ACTION_BLOCK:
868 mesh_plink_block(sta);
869 break;
870 }
871 #endif
872 }
873 }
874
875 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
876 u8 *mac, struct station_parameters *params)
877 {
878 struct ieee80211_local *local = wiphy_priv(wiphy);
879 struct sta_info *sta;
880 struct ieee80211_sub_if_data *sdata;
881 int err;
882 int layer2_update;
883
884 if (params->vlan) {
885 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
886
887 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
888 sdata->vif.type != NL80211_IFTYPE_AP)
889 return -EINVAL;
890 } else
891 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
892
893 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
894 return -EINVAL;
895
896 if (is_multicast_ether_addr(mac))
897 return -EINVAL;
898
899 /* Only TDLS-supporting stations can add TDLS peers */
900 if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
901 !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
902 sdata->vif.type == NL80211_IFTYPE_STATION))
903 return -ENOTSUPP;
904
905 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
906 if (!sta)
907 return -ENOMEM;
908
909 set_sta_flag(sta, WLAN_STA_AUTH);
910 set_sta_flag(sta, WLAN_STA_ASSOC);
911
912 sta_apply_parameters(local, sta, params);
913
914 /*
915 * for TDLS, rate control should be initialized only when supported
916 * rates are known.
917 */
918 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
919 rate_control_rate_init(sta);
920
921 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
922 sdata->vif.type == NL80211_IFTYPE_AP;
923
924 err = sta_info_insert_rcu(sta);
925 if (err) {
926 rcu_read_unlock();
927 return err;
928 }
929
930 if (layer2_update)
931 ieee80211_send_layer2_update(sta);
932
933 rcu_read_unlock();
934
935 return 0;
936 }
937
938 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
939 u8 *mac)
940 {
941 struct ieee80211_local *local = wiphy_priv(wiphy);
942 struct ieee80211_sub_if_data *sdata;
943
944 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
945
946 if (mac)
947 return sta_info_destroy_addr_bss(sdata, mac);
948
949 sta_info_flush(local, sdata);
950 return 0;
951 }
952
953 static int ieee80211_change_station(struct wiphy *wiphy,
954 struct net_device *dev,
955 u8 *mac,
956 struct station_parameters *params)
957 {
958 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
959 struct ieee80211_local *local = wiphy_priv(wiphy);
960 struct sta_info *sta;
961 struct ieee80211_sub_if_data *vlansdata;
962
963 rcu_read_lock();
964
965 sta = sta_info_get_bss(sdata, mac);
966 if (!sta) {
967 rcu_read_unlock();
968 return -ENOENT;
969 }
970
971 /* The TDLS bit cannot be toggled after the STA was added */
972 if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
973 !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
974 !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
975 rcu_read_unlock();
976 return -EINVAL;
977 }
978
979 if (params->vlan && params->vlan != sta->sdata->dev) {
980 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
981
982 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
983 vlansdata->vif.type != NL80211_IFTYPE_AP) {
984 rcu_read_unlock();
985 return -EINVAL;
986 }
987
988 if (params->vlan->ieee80211_ptr->use_4addr) {
989 if (vlansdata->u.vlan.sta) {
990 rcu_read_unlock();
991 return -EBUSY;
992 }
993
994 RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
995 }
996
997 sta->sdata = vlansdata;
998 ieee80211_send_layer2_update(sta);
999 }
1000
1001 sta_apply_parameters(local, sta, params);
1002
1003 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1004 rate_control_rate_init(sta);
1005
1006 rcu_read_unlock();
1007
1008 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1009 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1010 ieee80211_recalc_ps(local, -1);
1011
1012 return 0;
1013 }
1014
1015 #ifdef CONFIG_MAC80211_MESH
1016 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1017 u8 *dst, u8 *next_hop)
1018 {
1019 struct ieee80211_sub_if_data *sdata;
1020 struct mesh_path *mpath;
1021 struct sta_info *sta;
1022 int err;
1023
1024 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1025
1026 rcu_read_lock();
1027 sta = sta_info_get(sdata, next_hop);
1028 if (!sta) {
1029 rcu_read_unlock();
1030 return -ENOENT;
1031 }
1032
1033 err = mesh_path_add(dst, sdata);
1034 if (err) {
1035 rcu_read_unlock();
1036 return err;
1037 }
1038
1039 mpath = mesh_path_lookup(dst, sdata);
1040 if (!mpath) {
1041 rcu_read_unlock();
1042 return -ENXIO;
1043 }
1044 mesh_path_fix_nexthop(mpath, sta);
1045
1046 rcu_read_unlock();
1047 return 0;
1048 }
1049
1050 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1051 u8 *dst)
1052 {
1053 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1054
1055 if (dst)
1056 return mesh_path_del(dst, sdata);
1057
1058 mesh_path_flush_by_iface(sdata);
1059 return 0;
1060 }
1061
1062 static int ieee80211_change_mpath(struct wiphy *wiphy,
1063 struct net_device *dev,
1064 u8 *dst, u8 *next_hop)
1065 {
1066 struct ieee80211_sub_if_data *sdata;
1067 struct mesh_path *mpath;
1068 struct sta_info *sta;
1069
1070 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1071
1072 rcu_read_lock();
1073
1074 sta = sta_info_get(sdata, next_hop);
1075 if (!sta) {
1076 rcu_read_unlock();
1077 return -ENOENT;
1078 }
1079
1080 mpath = mesh_path_lookup(dst, sdata);
1081 if (!mpath) {
1082 rcu_read_unlock();
1083 return -ENOENT;
1084 }
1085
1086 mesh_path_fix_nexthop(mpath, sta);
1087
1088 rcu_read_unlock();
1089 return 0;
1090 }
1091
1092 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1093 struct mpath_info *pinfo)
1094 {
1095 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1096
1097 if (next_hop_sta)
1098 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1099 else
1100 memset(next_hop, 0, ETH_ALEN);
1101
1102 pinfo->generation = mesh_paths_generation;
1103
1104 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1105 MPATH_INFO_SN |
1106 MPATH_INFO_METRIC |
1107 MPATH_INFO_EXPTIME |
1108 MPATH_INFO_DISCOVERY_TIMEOUT |
1109 MPATH_INFO_DISCOVERY_RETRIES |
1110 MPATH_INFO_FLAGS;
1111
1112 pinfo->frame_qlen = mpath->frame_queue.qlen;
1113 pinfo->sn = mpath->sn;
1114 pinfo->metric = mpath->metric;
1115 if (time_before(jiffies, mpath->exp_time))
1116 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1117 pinfo->discovery_timeout =
1118 jiffies_to_msecs(mpath->discovery_timeout);
1119 pinfo->discovery_retries = mpath->discovery_retries;
1120 pinfo->flags = 0;
1121 if (mpath->flags & MESH_PATH_ACTIVE)
1122 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1123 if (mpath->flags & MESH_PATH_RESOLVING)
1124 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1125 if (mpath->flags & MESH_PATH_SN_VALID)
1126 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1127 if (mpath->flags & MESH_PATH_FIXED)
1128 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1129 if (mpath->flags & MESH_PATH_RESOLVING)
1130 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1131
1132 pinfo->flags = mpath->flags;
1133 }
1134
1135 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1136 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1137
1138 {
1139 struct ieee80211_sub_if_data *sdata;
1140 struct mesh_path *mpath;
1141
1142 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1143
1144 rcu_read_lock();
1145 mpath = mesh_path_lookup(dst, sdata);
1146 if (!mpath) {
1147 rcu_read_unlock();
1148 return -ENOENT;
1149 }
1150 memcpy(dst, mpath->dst, ETH_ALEN);
1151 mpath_set_pinfo(mpath, next_hop, pinfo);
1152 rcu_read_unlock();
1153 return 0;
1154 }
1155
1156 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1157 int idx, u8 *dst, u8 *next_hop,
1158 struct mpath_info *pinfo)
1159 {
1160 struct ieee80211_sub_if_data *sdata;
1161 struct mesh_path *mpath;
1162
1163 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1164
1165 rcu_read_lock();
1166 mpath = mesh_path_lookup_by_idx(idx, sdata);
1167 if (!mpath) {
1168 rcu_read_unlock();
1169 return -ENOENT;
1170 }
1171 memcpy(dst, mpath->dst, ETH_ALEN);
1172 mpath_set_pinfo(mpath, next_hop, pinfo);
1173 rcu_read_unlock();
1174 return 0;
1175 }
1176
1177 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1178 struct net_device *dev,
1179 struct mesh_config *conf)
1180 {
1181 struct ieee80211_sub_if_data *sdata;
1182 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1183
1184 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1185 return 0;
1186 }
1187
1188 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1189 {
1190 return (mask >> (parm-1)) & 0x1;
1191 }
1192
1193 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1194 const struct mesh_setup *setup)
1195 {
1196 u8 *new_ie;
1197 const u8 *old_ie;
1198
1199 /* allocate information elements */
1200 new_ie = NULL;
1201 old_ie = ifmsh->ie;
1202
1203 if (setup->ie_len) {
1204 new_ie = kmemdup(setup->ie, setup->ie_len,
1205 GFP_KERNEL);
1206 if (!new_ie)
1207 return -ENOMEM;
1208 }
1209 ifmsh->ie_len = setup->ie_len;
1210 ifmsh->ie = new_ie;
1211 kfree(old_ie);
1212
1213 /* now copy the rest of the setup parameters */
1214 ifmsh->mesh_id_len = setup->mesh_id_len;
1215 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1216 ifmsh->mesh_pp_id = setup->path_sel_proto;
1217 ifmsh->mesh_pm_id = setup->path_metric;
1218 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1219 if (setup->is_authenticated)
1220 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1221 if (setup->is_secure)
1222 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1223
1224 return 0;
1225 }
1226
1227 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1228 struct net_device *dev, u32 mask,
1229 const struct mesh_config *nconf)
1230 {
1231 struct mesh_config *conf;
1232 struct ieee80211_sub_if_data *sdata;
1233 struct ieee80211_if_mesh *ifmsh;
1234
1235 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1236 ifmsh = &sdata->u.mesh;
1237
1238 /* Set the config options which we are interested in setting */
1239 conf = &(sdata->u.mesh.mshcfg);
1240 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1241 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1242 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1243 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1244 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1245 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1246 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1247 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1248 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1249 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1250 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1251 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1252 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1253 conf->dot11MeshTTL = nconf->element_ttl;
1254 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1255 conf->auto_open_plinks = nconf->auto_open_plinks;
1256 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1257 conf->dot11MeshHWMPmaxPREQretries =
1258 nconf->dot11MeshHWMPmaxPREQretries;
1259 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1260 conf->path_refresh_time = nconf->path_refresh_time;
1261 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1262 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1263 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1264 conf->dot11MeshHWMPactivePathTimeout =
1265 nconf->dot11MeshHWMPactivePathTimeout;
1266 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1267 conf->dot11MeshHWMPpreqMinInterval =
1268 nconf->dot11MeshHWMPpreqMinInterval;
1269 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1270 mask))
1271 conf->dot11MeshHWMPnetDiameterTraversalTime =
1272 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1273 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1274 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1275 ieee80211_mesh_root_setup(ifmsh);
1276 }
1277 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1278 /* our current gate announcement implementation rides on root
1279 * announcements, so require this ifmsh to also be a root node
1280 * */
1281 if (nconf->dot11MeshGateAnnouncementProtocol &&
1282 !conf->dot11MeshHWMPRootMode) {
1283 conf->dot11MeshHWMPRootMode = 1;
1284 ieee80211_mesh_root_setup(ifmsh);
1285 }
1286 conf->dot11MeshGateAnnouncementProtocol =
1287 nconf->dot11MeshGateAnnouncementProtocol;
1288 }
1289 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1290 conf->dot11MeshHWMPRannInterval =
1291 nconf->dot11MeshHWMPRannInterval;
1292 }
1293 return 0;
1294 }
1295
1296 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1297 const struct mesh_config *conf,
1298 const struct mesh_setup *setup)
1299 {
1300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1301 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1302 int err;
1303
1304 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1305 err = copy_mesh_setup(ifmsh, setup);
1306 if (err)
1307 return err;
1308 ieee80211_start_mesh(sdata);
1309
1310 return 0;
1311 }
1312
1313 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1314 {
1315 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1316
1317 ieee80211_stop_mesh(sdata);
1318
1319 return 0;
1320 }
1321 #endif
1322
1323 static int ieee80211_change_bss(struct wiphy *wiphy,
1324 struct net_device *dev,
1325 struct bss_parameters *params)
1326 {
1327 struct ieee80211_sub_if_data *sdata;
1328 u32 changed = 0;
1329
1330 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1331
1332 if (params->use_cts_prot >= 0) {
1333 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1334 changed |= BSS_CHANGED_ERP_CTS_PROT;
1335 }
1336 if (params->use_short_preamble >= 0) {
1337 sdata->vif.bss_conf.use_short_preamble =
1338 params->use_short_preamble;
1339 changed |= BSS_CHANGED_ERP_PREAMBLE;
1340 }
1341
1342 if (!sdata->vif.bss_conf.use_short_slot &&
1343 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1344 sdata->vif.bss_conf.use_short_slot = true;
1345 changed |= BSS_CHANGED_ERP_SLOT;
1346 }
1347
1348 if (params->use_short_slot_time >= 0) {
1349 sdata->vif.bss_conf.use_short_slot =
1350 params->use_short_slot_time;
1351 changed |= BSS_CHANGED_ERP_SLOT;
1352 }
1353
1354 if (params->basic_rates) {
1355 int i, j;
1356 u32 rates = 0;
1357 struct ieee80211_local *local = wiphy_priv(wiphy);
1358 struct ieee80211_supported_band *sband =
1359 wiphy->bands[local->oper_channel->band];
1360
1361 for (i = 0; i < params->basic_rates_len; i++) {
1362 int rate = (params->basic_rates[i] & 0x7f) * 5;
1363 for (j = 0; j < sband->n_bitrates; j++) {
1364 if (sband->bitrates[j].bitrate == rate)
1365 rates |= BIT(j);
1366 }
1367 }
1368 sdata->vif.bss_conf.basic_rates = rates;
1369 changed |= BSS_CHANGED_BASIC_RATES;
1370 }
1371
1372 if (params->ap_isolate >= 0) {
1373 if (params->ap_isolate)
1374 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1375 else
1376 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1377 }
1378
1379 if (params->ht_opmode >= 0) {
1380 sdata->vif.bss_conf.ht_operation_mode =
1381 (u16) params->ht_opmode;
1382 changed |= BSS_CHANGED_HT;
1383 }
1384
1385 ieee80211_bss_info_change_notify(sdata, changed);
1386
1387 return 0;
1388 }
1389
1390 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1391 struct net_device *dev,
1392 struct ieee80211_txq_params *params)
1393 {
1394 struct ieee80211_local *local = wiphy_priv(wiphy);
1395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1396 struct ieee80211_tx_queue_params p;
1397
1398 if (!local->ops->conf_tx)
1399 return -EOPNOTSUPP;
1400
1401 memset(&p, 0, sizeof(p));
1402 p.aifs = params->aifs;
1403 p.cw_max = params->cwmax;
1404 p.cw_min = params->cwmin;
1405 p.txop = params->txop;
1406
1407 /*
1408 * Setting tx queue params disables u-apsd because it's only
1409 * called in master mode.
1410 */
1411 p.uapsd = false;
1412
1413 if (params->queue >= local->hw.queues)
1414 return -EINVAL;
1415
1416 sdata->tx_conf[params->queue] = p;
1417 if (drv_conf_tx(local, sdata, params->queue, &p)) {
1418 wiphy_debug(local->hw.wiphy,
1419 "failed to set TX queue parameters for queue %d\n",
1420 params->queue);
1421 return -EINVAL;
1422 }
1423
1424 return 0;
1425 }
1426
1427 static int ieee80211_set_channel(struct wiphy *wiphy,
1428 struct net_device *netdev,
1429 struct ieee80211_channel *chan,
1430 enum nl80211_channel_type channel_type)
1431 {
1432 struct ieee80211_local *local = wiphy_priv(wiphy);
1433 struct ieee80211_sub_if_data *sdata = NULL;
1434 struct ieee80211_channel *old_oper;
1435 enum nl80211_channel_type old_oper_type;
1436 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
1437
1438 if (netdev)
1439 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1440
1441 switch (ieee80211_get_channel_mode(local, NULL)) {
1442 case CHAN_MODE_HOPPING:
1443 return -EBUSY;
1444 case CHAN_MODE_FIXED:
1445 if (local->oper_channel != chan)
1446 return -EBUSY;
1447 if (!sdata && local->_oper_channel_type == channel_type)
1448 return 0;
1449 break;
1450 case CHAN_MODE_UNDEFINED:
1451 break;
1452 }
1453
1454 if (sdata)
1455 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1456 old_oper_type = local->_oper_channel_type;
1457
1458 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1459 return -EBUSY;
1460
1461 old_oper = local->oper_channel;
1462 local->oper_channel = chan;
1463
1464 /* Update driver if changes were actually made. */
1465 if ((old_oper != local->oper_channel) ||
1466 (old_oper_type != local->_oper_channel_type))
1467 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1468
1469 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1470 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
1471 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1472
1473 return 0;
1474 }
1475
1476 #ifdef CONFIG_PM
1477 static int ieee80211_suspend(struct wiphy *wiphy,
1478 struct cfg80211_wowlan *wowlan)
1479 {
1480 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1481 }
1482
1483 static int ieee80211_resume(struct wiphy *wiphy)
1484 {
1485 return __ieee80211_resume(wiphy_priv(wiphy));
1486 }
1487 #else
1488 #define ieee80211_suspend NULL
1489 #define ieee80211_resume NULL
1490 #endif
1491
1492 static int ieee80211_scan(struct wiphy *wiphy,
1493 struct net_device *dev,
1494 struct cfg80211_scan_request *req)
1495 {
1496 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1497
1498 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1499 case NL80211_IFTYPE_STATION:
1500 case NL80211_IFTYPE_ADHOC:
1501 case NL80211_IFTYPE_MESH_POINT:
1502 case NL80211_IFTYPE_P2P_CLIENT:
1503 break;
1504 case NL80211_IFTYPE_P2P_GO:
1505 if (sdata->local->ops->hw_scan)
1506 break;
1507 /*
1508 * FIXME: implement NoA while scanning in software,
1509 * for now fall through to allow scanning only when
1510 * beaconing hasn't been configured yet
1511 */
1512 case NL80211_IFTYPE_AP:
1513 if (sdata->u.ap.beacon)
1514 return -EOPNOTSUPP;
1515 break;
1516 default:
1517 return -EOPNOTSUPP;
1518 }
1519
1520 return ieee80211_request_scan(sdata, req);
1521 }
1522
1523 static int
1524 ieee80211_sched_scan_start(struct wiphy *wiphy,
1525 struct net_device *dev,
1526 struct cfg80211_sched_scan_request *req)
1527 {
1528 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1529
1530 if (!sdata->local->ops->sched_scan_start)
1531 return -EOPNOTSUPP;
1532
1533 return ieee80211_request_sched_scan_start(sdata, req);
1534 }
1535
1536 static int
1537 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1538 {
1539 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1540
1541 if (!sdata->local->ops->sched_scan_stop)
1542 return -EOPNOTSUPP;
1543
1544 return ieee80211_request_sched_scan_stop(sdata);
1545 }
1546
1547 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1548 struct cfg80211_auth_request *req)
1549 {
1550 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1551 }
1552
1553 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1554 struct cfg80211_assoc_request *req)
1555 {
1556 struct ieee80211_local *local = wiphy_priv(wiphy);
1557 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1558
1559 switch (ieee80211_get_channel_mode(local, sdata)) {
1560 case CHAN_MODE_HOPPING:
1561 return -EBUSY;
1562 case CHAN_MODE_FIXED:
1563 if (local->oper_channel == req->bss->channel)
1564 break;
1565 return -EBUSY;
1566 case CHAN_MODE_UNDEFINED:
1567 break;
1568 }
1569
1570 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1571 }
1572
1573 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1574 struct cfg80211_deauth_request *req,
1575 void *cookie)
1576 {
1577 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1578 req, cookie);
1579 }
1580
1581 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1582 struct cfg80211_disassoc_request *req,
1583 void *cookie)
1584 {
1585 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1586 req, cookie);
1587 }
1588
1589 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1590 struct cfg80211_ibss_params *params)
1591 {
1592 struct ieee80211_local *local = wiphy_priv(wiphy);
1593 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1594
1595 switch (ieee80211_get_channel_mode(local, sdata)) {
1596 case CHAN_MODE_HOPPING:
1597 return -EBUSY;
1598 case CHAN_MODE_FIXED:
1599 if (!params->channel_fixed)
1600 return -EBUSY;
1601 if (local->oper_channel == params->channel)
1602 break;
1603 return -EBUSY;
1604 case CHAN_MODE_UNDEFINED:
1605 break;
1606 }
1607
1608 return ieee80211_ibss_join(sdata, params);
1609 }
1610
1611 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1612 {
1613 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1614
1615 return ieee80211_ibss_leave(sdata);
1616 }
1617
1618 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1619 {
1620 struct ieee80211_local *local = wiphy_priv(wiphy);
1621 int err;
1622
1623 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1624 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1625
1626 if (err)
1627 return err;
1628 }
1629
1630 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1631 err = drv_set_coverage_class(local, wiphy->coverage_class);
1632
1633 if (err)
1634 return err;
1635 }
1636
1637 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1638 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1639
1640 if (err)
1641 return err;
1642 }
1643
1644 if (changed & WIPHY_PARAM_RETRY_SHORT)
1645 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1646 if (changed & WIPHY_PARAM_RETRY_LONG)
1647 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1648 if (changed &
1649 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1650 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1651
1652 return 0;
1653 }
1654
1655 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1656 enum nl80211_tx_power_setting type, int mbm)
1657 {
1658 struct ieee80211_local *local = wiphy_priv(wiphy);
1659 struct ieee80211_channel *chan = local->hw.conf.channel;
1660 u32 changes = 0;
1661
1662 switch (type) {
1663 case NL80211_TX_POWER_AUTOMATIC:
1664 local->user_power_level = -1;
1665 break;
1666 case NL80211_TX_POWER_LIMITED:
1667 if (mbm < 0 || (mbm % 100))
1668 return -EOPNOTSUPP;
1669 local->user_power_level = MBM_TO_DBM(mbm);
1670 break;
1671 case NL80211_TX_POWER_FIXED:
1672 if (mbm < 0 || (mbm % 100))
1673 return -EOPNOTSUPP;
1674 /* TODO: move to cfg80211 when it knows the channel */
1675 if (MBM_TO_DBM(mbm) > chan->max_power)
1676 return -EINVAL;
1677 local->user_power_level = MBM_TO_DBM(mbm);
1678 break;
1679 }
1680
1681 ieee80211_hw_config(local, changes);
1682
1683 return 0;
1684 }
1685
1686 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1687 {
1688 struct ieee80211_local *local = wiphy_priv(wiphy);
1689
1690 *dbm = local->hw.conf.power_level;
1691
1692 return 0;
1693 }
1694
1695 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1696 const u8 *addr)
1697 {
1698 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1699
1700 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1701
1702 return 0;
1703 }
1704
1705 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1706 {
1707 struct ieee80211_local *local = wiphy_priv(wiphy);
1708
1709 drv_rfkill_poll(local);
1710 }
1711
1712 #ifdef CONFIG_NL80211_TESTMODE
1713 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1714 {
1715 struct ieee80211_local *local = wiphy_priv(wiphy);
1716
1717 if (!local->ops->testmode_cmd)
1718 return -EOPNOTSUPP;
1719
1720 return local->ops->testmode_cmd(&local->hw, data, len);
1721 }
1722
1723 static int ieee80211_testmode_dump(struct wiphy *wiphy,
1724 struct sk_buff *skb,
1725 struct netlink_callback *cb,
1726 void *data, int len)
1727 {
1728 struct ieee80211_local *local = wiphy_priv(wiphy);
1729
1730 if (!local->ops->testmode_dump)
1731 return -EOPNOTSUPP;
1732
1733 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1734 }
1735 #endif
1736
1737 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1738 enum ieee80211_smps_mode smps_mode)
1739 {
1740 const u8 *ap;
1741 enum ieee80211_smps_mode old_req;
1742 int err;
1743
1744 lockdep_assert_held(&sdata->u.mgd.mtx);
1745
1746 old_req = sdata->u.mgd.req_smps;
1747 sdata->u.mgd.req_smps = smps_mode;
1748
1749 if (old_req == smps_mode &&
1750 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1751 return 0;
1752
1753 /*
1754 * If not associated, or current association is not an HT
1755 * association, there's no need to send an action frame.
1756 */
1757 if (!sdata->u.mgd.associated ||
1758 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
1759 mutex_lock(&sdata->local->iflist_mtx);
1760 ieee80211_recalc_smps(sdata->local);
1761 mutex_unlock(&sdata->local->iflist_mtx);
1762 return 0;
1763 }
1764
1765 ap = sdata->u.mgd.associated->bssid;
1766
1767 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1768 if (sdata->u.mgd.powersave)
1769 smps_mode = IEEE80211_SMPS_DYNAMIC;
1770 else
1771 smps_mode = IEEE80211_SMPS_OFF;
1772 }
1773
1774 /* send SM PS frame to AP */
1775 err = ieee80211_send_smps_action(sdata, smps_mode,
1776 ap, ap);
1777 if (err)
1778 sdata->u.mgd.req_smps = old_req;
1779
1780 return err;
1781 }
1782
1783 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1784 bool enabled, int timeout)
1785 {
1786 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1787 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1788
1789 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1790 return -EOPNOTSUPP;
1791
1792 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1793 return -EOPNOTSUPP;
1794
1795 if (enabled == sdata->u.mgd.powersave &&
1796 timeout == local->dynamic_ps_forced_timeout)
1797 return 0;
1798
1799 sdata->u.mgd.powersave = enabled;
1800 local->dynamic_ps_forced_timeout = timeout;
1801
1802 /* no change, but if automatic follow powersave */
1803 mutex_lock(&sdata->u.mgd.mtx);
1804 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1805 mutex_unlock(&sdata->u.mgd.mtx);
1806
1807 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1808 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1809
1810 ieee80211_recalc_ps(local, -1);
1811
1812 return 0;
1813 }
1814
1815 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1816 struct net_device *dev,
1817 s32 rssi_thold, u32 rssi_hyst)
1818 {
1819 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1820 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1821 struct ieee80211_vif *vif = &sdata->vif;
1822 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1823
1824 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1825 rssi_hyst == bss_conf->cqm_rssi_hyst)
1826 return 0;
1827
1828 bss_conf->cqm_rssi_thold = rssi_thold;
1829 bss_conf->cqm_rssi_hyst = rssi_hyst;
1830
1831 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1832 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1833 return -EOPNOTSUPP;
1834 return 0;
1835 }
1836
1837 /* tell the driver upon association, unless already associated */
1838 if (sdata->u.mgd.associated)
1839 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1840
1841 return 0;
1842 }
1843
1844 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1845 struct net_device *dev,
1846 const u8 *addr,
1847 const struct cfg80211_bitrate_mask *mask)
1848 {
1849 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1850 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1851 int i, ret;
1852
1853 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1854 ret = drv_set_bitrate_mask(local, sdata, mask);
1855 if (ret)
1856 return ret;
1857 }
1858
1859 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1860 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1861
1862 return 0;
1863 }
1864
1865 static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1866 struct net_device *dev,
1867 struct ieee80211_channel *chan,
1868 enum nl80211_channel_type chantype,
1869 unsigned int duration, u64 *cookie)
1870 {
1871 int ret;
1872 u32 random_cookie;
1873
1874 lockdep_assert_held(&local->mtx);
1875
1876 if (local->hw_roc_cookie)
1877 return -EBUSY;
1878 /* must be nonzero */
1879 random_cookie = random32() | 1;
1880
1881 *cookie = random_cookie;
1882 local->hw_roc_dev = dev;
1883 local->hw_roc_cookie = random_cookie;
1884 local->hw_roc_channel = chan;
1885 local->hw_roc_channel_type = chantype;
1886 local->hw_roc_duration = duration;
1887 ret = drv_remain_on_channel(local, chan, chantype, duration);
1888 if (ret) {
1889 local->hw_roc_channel = NULL;
1890 local->hw_roc_cookie = 0;
1891 }
1892
1893 return ret;
1894 }
1895
1896 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1897 struct net_device *dev,
1898 struct ieee80211_channel *chan,
1899 enum nl80211_channel_type channel_type,
1900 unsigned int duration,
1901 u64 *cookie)
1902 {
1903 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1904 struct ieee80211_local *local = sdata->local;
1905
1906 if (local->ops->remain_on_channel) {
1907 int ret;
1908
1909 mutex_lock(&local->mtx);
1910 ret = ieee80211_remain_on_channel_hw(local, dev,
1911 chan, channel_type,
1912 duration, cookie);
1913 local->hw_roc_for_tx = false;
1914 mutex_unlock(&local->mtx);
1915
1916 return ret;
1917 }
1918
1919 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1920 duration, cookie);
1921 }
1922
1923 static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1924 u64 cookie)
1925 {
1926 int ret;
1927
1928 lockdep_assert_held(&local->mtx);
1929
1930 if (local->hw_roc_cookie != cookie)
1931 return -ENOENT;
1932
1933 ret = drv_cancel_remain_on_channel(local);
1934 if (ret)
1935 return ret;
1936
1937 local->hw_roc_cookie = 0;
1938 local->hw_roc_channel = NULL;
1939
1940 ieee80211_recalc_idle(local);
1941
1942 return 0;
1943 }
1944
1945 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1946 struct net_device *dev,
1947 u64 cookie)
1948 {
1949 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1950 struct ieee80211_local *local = sdata->local;
1951
1952 if (local->ops->cancel_remain_on_channel) {
1953 int ret;
1954
1955 mutex_lock(&local->mtx);
1956 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1957 mutex_unlock(&local->mtx);
1958
1959 return ret;
1960 }
1961
1962 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1963 }
1964
1965 static enum work_done_result
1966 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
1967 {
1968 /*
1969 * Use the data embedded in the work struct for reporting
1970 * here so if the driver mangled the SKB before dropping
1971 * it (which is the only way we really should get here)
1972 * then we don't report mangled data.
1973 *
1974 * If there was no wait time, then by the time we get here
1975 * the driver will likely not have reported the status yet,
1976 * so in that case userspace will have to deal with it.
1977 */
1978
1979 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
1980 cfg80211_mgmt_tx_status(wk->sdata->dev,
1981 (unsigned long) wk->offchan_tx.frame,
1982 wk->ie, wk->ie_len, false, GFP_KERNEL);
1983
1984 return WORK_DONE_DESTROY;
1985 }
1986
1987 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1988 struct ieee80211_channel *chan, bool offchan,
1989 enum nl80211_channel_type channel_type,
1990 bool channel_type_valid, unsigned int wait,
1991 const u8 *buf, size_t len, bool no_cck,
1992 bool dont_wait_for_ack, u64 *cookie)
1993 {
1994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1995 struct ieee80211_local *local = sdata->local;
1996 struct sk_buff *skb;
1997 struct sta_info *sta;
1998 struct ieee80211_work *wk;
1999 const struct ieee80211_mgmt *mgmt = (void *)buf;
2000 u32 flags;
2001 bool is_offchan = false;
2002
2003 if (dont_wait_for_ack)
2004 flags = IEEE80211_TX_CTL_NO_ACK;
2005 else
2006 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2007 IEEE80211_TX_CTL_REQ_TX_STATUS;
2008
2009 /* Check that we are on the requested channel for transmission */
2010 if (chan != local->tmp_channel &&
2011 chan != local->oper_channel)
2012 is_offchan = true;
2013 if (channel_type_valid &&
2014 (channel_type != local->tmp_channel_type &&
2015 channel_type != local->_oper_channel_type))
2016 is_offchan = true;
2017
2018 if (chan == local->hw_roc_channel) {
2019 /* TODO: check channel type? */
2020 is_offchan = false;
2021 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2022 }
2023
2024 if (no_cck)
2025 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2026
2027 if (is_offchan && !offchan)
2028 return -EBUSY;
2029
2030 switch (sdata->vif.type) {
2031 case NL80211_IFTYPE_ADHOC:
2032 case NL80211_IFTYPE_AP:
2033 case NL80211_IFTYPE_AP_VLAN:
2034 case NL80211_IFTYPE_P2P_GO:
2035 case NL80211_IFTYPE_MESH_POINT:
2036 if (!ieee80211_is_action(mgmt->frame_control) ||
2037 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2038 break;
2039 rcu_read_lock();
2040 sta = sta_info_get(sdata, mgmt->da);
2041 rcu_read_unlock();
2042 if (!sta)
2043 return -ENOLINK;
2044 break;
2045 case NL80211_IFTYPE_STATION:
2046 case NL80211_IFTYPE_P2P_CLIENT:
2047 break;
2048 default:
2049 return -EOPNOTSUPP;
2050 }
2051
2052 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2053 if (!skb)
2054 return -ENOMEM;
2055 skb_reserve(skb, local->hw.extra_tx_headroom);
2056
2057 memcpy(skb_put(skb, len), buf, len);
2058
2059 IEEE80211_SKB_CB(skb)->flags = flags;
2060
2061 skb->dev = sdata->dev;
2062
2063 *cookie = (unsigned long) skb;
2064
2065 if (is_offchan && local->ops->remain_on_channel) {
2066 unsigned int duration;
2067 int ret;
2068
2069 mutex_lock(&local->mtx);
2070 /*
2071 * If the duration is zero, then the driver
2072 * wouldn't actually do anything. Set it to
2073 * 100 for now.
2074 *
2075 * TODO: cancel the off-channel operation
2076 * when we get the SKB's TX status and
2077 * the wait time was zero before.
2078 */
2079 duration = 100;
2080 if (wait)
2081 duration = wait;
2082 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2083 channel_type,
2084 duration, cookie);
2085 if (ret) {
2086 kfree_skb(skb);
2087 mutex_unlock(&local->mtx);
2088 return ret;
2089 }
2090
2091 local->hw_roc_for_tx = true;
2092 local->hw_roc_duration = wait;
2093
2094 /*
2095 * queue up frame for transmission after
2096 * ieee80211_ready_on_channel call
2097 */
2098
2099 /* modify cookie to prevent API mismatches */
2100 *cookie ^= 2;
2101 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2102 local->hw_roc_skb = skb;
2103 local->hw_roc_skb_for_status = skb;
2104 mutex_unlock(&local->mtx);
2105
2106 return 0;
2107 }
2108
2109 /*
2110 * Can transmit right away if the channel was the
2111 * right one and there's no wait involved... If a
2112 * wait is involved, we might otherwise not be on
2113 * the right channel for long enough!
2114 */
2115 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2116 ieee80211_tx_skb(sdata, skb);
2117 return 0;
2118 }
2119
2120 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2121 if (!wk) {
2122 kfree_skb(skb);
2123 return -ENOMEM;
2124 }
2125
2126 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2127 wk->chan = chan;
2128 wk->chan_type = channel_type;
2129 wk->sdata = sdata;
2130 wk->done = ieee80211_offchan_tx_done;
2131 wk->offchan_tx.frame = skb;
2132 wk->offchan_tx.wait = wait;
2133 wk->ie_len = len;
2134 memcpy(wk->ie, buf, len);
2135
2136 ieee80211_add_work(wk);
2137 return 0;
2138 }
2139
2140 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2141 struct net_device *dev,
2142 u64 cookie)
2143 {
2144 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2145 struct ieee80211_local *local = sdata->local;
2146 struct ieee80211_work *wk;
2147 int ret = -ENOENT;
2148
2149 mutex_lock(&local->mtx);
2150
2151 if (local->ops->cancel_remain_on_channel) {
2152 cookie ^= 2;
2153 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2154
2155 if (ret == 0) {
2156 kfree_skb(local->hw_roc_skb);
2157 local->hw_roc_skb = NULL;
2158 local->hw_roc_skb_for_status = NULL;
2159 }
2160
2161 mutex_unlock(&local->mtx);
2162
2163 return ret;
2164 }
2165
2166 list_for_each_entry(wk, &local->work_list, list) {
2167 if (wk->sdata != sdata)
2168 continue;
2169
2170 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2171 continue;
2172
2173 if (cookie != (unsigned long) wk->offchan_tx.frame)
2174 continue;
2175
2176 wk->timeout = jiffies;
2177
2178 ieee80211_queue_work(&local->hw, &local->work_work);
2179 ret = 0;
2180 break;
2181 }
2182 mutex_unlock(&local->mtx);
2183
2184 return ret;
2185 }
2186
2187 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2188 struct net_device *dev,
2189 u16 frame_type, bool reg)
2190 {
2191 struct ieee80211_local *local = wiphy_priv(wiphy);
2192
2193 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2194 return;
2195
2196 if (reg)
2197 local->probe_req_reg++;
2198 else
2199 local->probe_req_reg--;
2200
2201 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2202 }
2203
2204 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2205 {
2206 struct ieee80211_local *local = wiphy_priv(wiphy);
2207
2208 if (local->started)
2209 return -EOPNOTSUPP;
2210
2211 return drv_set_antenna(local, tx_ant, rx_ant);
2212 }
2213
2214 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2215 {
2216 struct ieee80211_local *local = wiphy_priv(wiphy);
2217
2218 return drv_get_antenna(local, tx_ant, rx_ant);
2219 }
2220
2221 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2222 {
2223 struct ieee80211_local *local = wiphy_priv(wiphy);
2224
2225 return drv_set_ringparam(local, tx, rx);
2226 }
2227
2228 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2229 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2230 {
2231 struct ieee80211_local *local = wiphy_priv(wiphy);
2232
2233 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2234 }
2235
2236 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2237 struct net_device *dev,
2238 struct cfg80211_gtk_rekey_data *data)
2239 {
2240 struct ieee80211_local *local = wiphy_priv(wiphy);
2241 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2242
2243 if (!local->ops->set_rekey_data)
2244 return -EOPNOTSUPP;
2245
2246 drv_set_rekey_data(local, sdata, data);
2247
2248 return 0;
2249 }
2250
2251 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2252 {
2253 u8 *pos = (void *)skb_put(skb, 7);
2254
2255 *pos++ = WLAN_EID_EXT_CAPABILITY;
2256 *pos++ = 5; /* len */
2257 *pos++ = 0x0;
2258 *pos++ = 0x0;
2259 *pos++ = 0x0;
2260 *pos++ = 0x0;
2261 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2262 }
2263
2264 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2265 {
2266 struct ieee80211_local *local = sdata->local;
2267 u16 capab;
2268
2269 capab = 0;
2270 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2271 return capab;
2272
2273 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2274 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2275 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2276 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2277
2278 return capab;
2279 }
2280
2281 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2282 u8 *peer, u8 *bssid)
2283 {
2284 struct ieee80211_tdls_lnkie *lnkid;
2285
2286 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2287
2288 lnkid->ie_type = WLAN_EID_LINK_ID;
2289 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2290
2291 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2292 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2293 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2294 }
2295
2296 static int
2297 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2298 u8 *peer, u8 action_code, u8 dialog_token,
2299 u16 status_code, struct sk_buff *skb)
2300 {
2301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2302 struct ieee80211_tdls_data *tf;
2303
2304 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2305
2306 memcpy(tf->da, peer, ETH_ALEN);
2307 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2308 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2309 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2310
2311 switch (action_code) {
2312 case WLAN_TDLS_SETUP_REQUEST:
2313 tf->category = WLAN_CATEGORY_TDLS;
2314 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2315
2316 skb_put(skb, sizeof(tf->u.setup_req));
2317 tf->u.setup_req.dialog_token = dialog_token;
2318 tf->u.setup_req.capability =
2319 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2320
2321 ieee80211_add_srates_ie(&sdata->vif, skb);
2322 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2323 ieee80211_tdls_add_ext_capab(skb);
2324 break;
2325 case WLAN_TDLS_SETUP_RESPONSE:
2326 tf->category = WLAN_CATEGORY_TDLS;
2327 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2328
2329 skb_put(skb, sizeof(tf->u.setup_resp));
2330 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2331 tf->u.setup_resp.dialog_token = dialog_token;
2332 tf->u.setup_resp.capability =
2333 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2334
2335 ieee80211_add_srates_ie(&sdata->vif, skb);
2336 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2337 ieee80211_tdls_add_ext_capab(skb);
2338 break;
2339 case WLAN_TDLS_SETUP_CONFIRM:
2340 tf->category = WLAN_CATEGORY_TDLS;
2341 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2342
2343 skb_put(skb, sizeof(tf->u.setup_cfm));
2344 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2345 tf->u.setup_cfm.dialog_token = dialog_token;
2346 break;
2347 case WLAN_TDLS_TEARDOWN:
2348 tf->category = WLAN_CATEGORY_TDLS;
2349 tf->action_code = WLAN_TDLS_TEARDOWN;
2350
2351 skb_put(skb, sizeof(tf->u.teardown));
2352 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2353 break;
2354 case WLAN_TDLS_DISCOVERY_REQUEST:
2355 tf->category = WLAN_CATEGORY_TDLS;
2356 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2357
2358 skb_put(skb, sizeof(tf->u.discover_req));
2359 tf->u.discover_req.dialog_token = dialog_token;
2360 break;
2361 default:
2362 return -EINVAL;
2363 }
2364
2365 return 0;
2366 }
2367
2368 static int
2369 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2370 u8 *peer, u8 action_code, u8 dialog_token,
2371 u16 status_code, struct sk_buff *skb)
2372 {
2373 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2374 struct ieee80211_mgmt *mgmt;
2375
2376 mgmt = (void *)skb_put(skb, 24);
2377 memset(mgmt, 0, 24);
2378 memcpy(mgmt->da, peer, ETH_ALEN);
2379 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2380 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2381
2382 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2383 IEEE80211_STYPE_ACTION);
2384
2385 switch (action_code) {
2386 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2387 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2388 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2389 mgmt->u.action.u.tdls_discover_resp.action_code =
2390 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2391 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2392 dialog_token;
2393 mgmt->u.action.u.tdls_discover_resp.capability =
2394 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2395
2396 ieee80211_add_srates_ie(&sdata->vif, skb);
2397 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2398 ieee80211_tdls_add_ext_capab(skb);
2399 break;
2400 default:
2401 return -EINVAL;
2402 }
2403
2404 return 0;
2405 }
2406
2407 static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2408 u8 *peer, u8 action_code, u8 dialog_token,
2409 u16 status_code, const u8 *extra_ies,
2410 size_t extra_ies_len)
2411 {
2412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2413 struct ieee80211_local *local = sdata->local;
2414 struct ieee80211_tx_info *info;
2415 struct sk_buff *skb = NULL;
2416 bool send_direct;
2417 int ret;
2418
2419 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2420 return -ENOTSUPP;
2421
2422 /* make sure we are in managed mode, and associated */
2423 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2424 !sdata->u.mgd.associated)
2425 return -EINVAL;
2426
2427 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2428 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2429 #endif
2430
2431 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2432 max(sizeof(struct ieee80211_mgmt),
2433 sizeof(struct ieee80211_tdls_data)) +
2434 50 + /* supported rates */
2435 7 + /* ext capab */
2436 extra_ies_len +
2437 sizeof(struct ieee80211_tdls_lnkie));
2438 if (!skb)
2439 return -ENOMEM;
2440
2441 info = IEEE80211_SKB_CB(skb);
2442 skb_reserve(skb, local->hw.extra_tx_headroom);
2443
2444 switch (action_code) {
2445 case WLAN_TDLS_SETUP_REQUEST:
2446 case WLAN_TDLS_SETUP_RESPONSE:
2447 case WLAN_TDLS_SETUP_CONFIRM:
2448 case WLAN_TDLS_TEARDOWN:
2449 case WLAN_TDLS_DISCOVERY_REQUEST:
2450 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2451 action_code, dialog_token,
2452 status_code, skb);
2453 send_direct = false;
2454 break;
2455 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2456 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2457 dialog_token, status_code,
2458 skb);
2459 send_direct = true;
2460 break;
2461 default:
2462 ret = -ENOTSUPP;
2463 break;
2464 }
2465
2466 if (ret < 0)
2467 goto fail;
2468
2469 if (extra_ies_len)
2470 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2471
2472 /* the TDLS link IE is always added last */
2473 switch (action_code) {
2474 case WLAN_TDLS_SETUP_REQUEST:
2475 case WLAN_TDLS_SETUP_CONFIRM:
2476 case WLAN_TDLS_TEARDOWN:
2477 case WLAN_TDLS_DISCOVERY_REQUEST:
2478 /* we are the initiator */
2479 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2480 sdata->u.mgd.bssid);
2481 break;
2482 case WLAN_TDLS_SETUP_RESPONSE:
2483 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2484 /* we are the responder */
2485 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2486 sdata->u.mgd.bssid);
2487 break;
2488 default:
2489 ret = -ENOTSUPP;
2490 goto fail;
2491 }
2492
2493 if (send_direct) {
2494 ieee80211_tx_skb(sdata, skb);
2495 return 0;
2496 }
2497
2498 /*
2499 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2500 * we should default to AC_VI.
2501 */
2502 switch (action_code) {
2503 case WLAN_TDLS_SETUP_REQUEST:
2504 case WLAN_TDLS_SETUP_RESPONSE:
2505 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2506 skb->priority = 2;
2507 break;
2508 default:
2509 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2510 skb->priority = 5;
2511 break;
2512 }
2513
2514 /* disable bottom halves when entering the Tx path */
2515 local_bh_disable();
2516 ret = ieee80211_subif_start_xmit(skb, dev);
2517 local_bh_enable();
2518
2519 return ret;
2520
2521 fail:
2522 dev_kfree_skb(skb);
2523 return ret;
2524 }
2525
2526 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2527 u8 *peer, enum nl80211_tdls_operation oper)
2528 {
2529 struct sta_info *sta;
2530 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2531
2532 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2533 return -ENOTSUPP;
2534
2535 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2536 return -EINVAL;
2537
2538 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2539 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2540 #endif
2541
2542 switch (oper) {
2543 case NL80211_TDLS_ENABLE_LINK:
2544 rcu_read_lock();
2545 sta = sta_info_get(sdata, peer);
2546 if (!sta) {
2547 rcu_read_unlock();
2548 return -ENOLINK;
2549 }
2550
2551 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
2552 rcu_read_unlock();
2553 break;
2554 case NL80211_TDLS_DISABLE_LINK:
2555 return sta_info_destroy_addr(sdata, peer);
2556 case NL80211_TDLS_TEARDOWN:
2557 case NL80211_TDLS_SETUP:
2558 case NL80211_TDLS_DISCOVERY_REQ:
2559 /* We don't support in-driver setup/teardown/discovery */
2560 return -ENOTSUPP;
2561 default:
2562 return -ENOTSUPP;
2563 }
2564
2565 return 0;
2566 }
2567
2568 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2569 const u8 *peer, u64 *cookie)
2570 {
2571 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2572 struct ieee80211_local *local = sdata->local;
2573 struct ieee80211_qos_hdr *nullfunc;
2574 struct sk_buff *skb;
2575 int size = sizeof(*nullfunc);
2576 __le16 fc;
2577 bool qos;
2578 struct ieee80211_tx_info *info;
2579 struct sta_info *sta;
2580
2581 rcu_read_lock();
2582 sta = sta_info_get(sdata, peer);
2583 if (sta) {
2584 qos = test_sta_flag(sta, WLAN_STA_WME);
2585 rcu_read_unlock();
2586 } else {
2587 rcu_read_unlock();
2588 return -ENOLINK;
2589 }
2590
2591 if (qos) {
2592 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2593 IEEE80211_STYPE_QOS_NULLFUNC |
2594 IEEE80211_FCTL_FROMDS);
2595 } else {
2596 size -= 2;
2597 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2598 IEEE80211_STYPE_NULLFUNC |
2599 IEEE80211_FCTL_FROMDS);
2600 }
2601
2602 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2603 if (!skb)
2604 return -ENOMEM;
2605
2606 skb->dev = dev;
2607
2608 skb_reserve(skb, local->hw.extra_tx_headroom);
2609
2610 nullfunc = (void *) skb_put(skb, size);
2611 nullfunc->frame_control = fc;
2612 nullfunc->duration_id = 0;
2613 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2614 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2615 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2616 nullfunc->seq_ctrl = 0;
2617
2618 info = IEEE80211_SKB_CB(skb);
2619
2620 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2621 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2622
2623 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2624 skb->priority = 7;
2625 if (qos)
2626 nullfunc->qos_ctrl = cpu_to_le16(7);
2627
2628 local_bh_disable();
2629 ieee80211_xmit(sdata, skb);
2630 local_bh_enable();
2631
2632 *cookie = (unsigned long) skb;
2633 return 0;
2634 }
2635
2636 static struct ieee80211_channel *
2637 ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2638 {
2639 struct ieee80211_local *local = wiphy_priv(wiphy);
2640
2641 return local->oper_channel;
2642 }
2643
2644 struct cfg80211_ops mac80211_config_ops = {
2645 .add_virtual_intf = ieee80211_add_iface,
2646 .del_virtual_intf = ieee80211_del_iface,
2647 .change_virtual_intf = ieee80211_change_iface,
2648 .add_key = ieee80211_add_key,
2649 .del_key = ieee80211_del_key,
2650 .get_key = ieee80211_get_key,
2651 .set_default_key = ieee80211_config_default_key,
2652 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
2653 .add_beacon = ieee80211_add_beacon,
2654 .set_beacon = ieee80211_set_beacon,
2655 .del_beacon = ieee80211_del_beacon,
2656 .add_station = ieee80211_add_station,
2657 .del_station = ieee80211_del_station,
2658 .change_station = ieee80211_change_station,
2659 .get_station = ieee80211_get_station,
2660 .dump_station = ieee80211_dump_station,
2661 .dump_survey = ieee80211_dump_survey,
2662 #ifdef CONFIG_MAC80211_MESH
2663 .add_mpath = ieee80211_add_mpath,
2664 .del_mpath = ieee80211_del_mpath,
2665 .change_mpath = ieee80211_change_mpath,
2666 .get_mpath = ieee80211_get_mpath,
2667 .dump_mpath = ieee80211_dump_mpath,
2668 .update_mesh_config = ieee80211_update_mesh_config,
2669 .get_mesh_config = ieee80211_get_mesh_config,
2670 .join_mesh = ieee80211_join_mesh,
2671 .leave_mesh = ieee80211_leave_mesh,
2672 #endif
2673 .change_bss = ieee80211_change_bss,
2674 .set_txq_params = ieee80211_set_txq_params,
2675 .set_channel = ieee80211_set_channel,
2676 .suspend = ieee80211_suspend,
2677 .resume = ieee80211_resume,
2678 .scan = ieee80211_scan,
2679 .sched_scan_start = ieee80211_sched_scan_start,
2680 .sched_scan_stop = ieee80211_sched_scan_stop,
2681 .auth = ieee80211_auth,
2682 .assoc = ieee80211_assoc,
2683 .deauth = ieee80211_deauth,
2684 .disassoc = ieee80211_disassoc,
2685 .join_ibss = ieee80211_join_ibss,
2686 .leave_ibss = ieee80211_leave_ibss,
2687 .set_wiphy_params = ieee80211_set_wiphy_params,
2688 .set_tx_power = ieee80211_set_tx_power,
2689 .get_tx_power = ieee80211_get_tx_power,
2690 .set_wds_peer = ieee80211_set_wds_peer,
2691 .rfkill_poll = ieee80211_rfkill_poll,
2692 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
2693 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
2694 .set_power_mgmt = ieee80211_set_power_mgmt,
2695 .set_bitrate_mask = ieee80211_set_bitrate_mask,
2696 .remain_on_channel = ieee80211_remain_on_channel,
2697 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2698 .mgmt_tx = ieee80211_mgmt_tx,
2699 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
2700 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
2701 .mgmt_frame_register = ieee80211_mgmt_frame_register,
2702 .set_antenna = ieee80211_set_antenna,
2703 .get_antenna = ieee80211_get_antenna,
2704 .set_ringparam = ieee80211_set_ringparam,
2705 .get_ringparam = ieee80211_get_ringparam,
2706 .set_rekey_data = ieee80211_set_rekey_data,
2707 .tdls_oper = ieee80211_tdls_oper,
2708 .tdls_mgmt = ieee80211_tdls_mgmt,
2709 .probe_client = ieee80211_probe_client,
2710 .get_channel = ieee80211_wiphy_get_channel,
2711 .set_noack_map = ieee80211_set_noack_map,
2712 };
This page took 0.159096 seconds and 4 git commands to generate.