2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * This file is GPLv2 as found in COPYING.
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"
23 static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
26 struct vif_params *params)
28 struct ieee80211_local *local = wiphy_priv(wiphy);
29 struct net_device *dev;
30 struct ieee80211_sub_if_data *sdata;
33 err = ieee80211_if_add(local, name, &dev, type, params);
37 if (type == NL80211_IFTYPE_MONITOR && flags) {
38 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
39 sdata->u.mntr_flags = *flags;
45 static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
47 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
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)
57 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
60 ret = ieee80211_if_change_type(sdata, type);
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;
71 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
74 if (ieee80211_sdata_running(sdata)) {
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
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
91 ieee80211_configure_filter(local);
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
98 sdata->u.mntr_flags = *flags;
105 static int ieee80211_set_noack_map(struct wiphy *wiphy,
106 struct net_device *dev,
109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
111 sdata->noack_map = noack_map;
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)
119 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
120 struct sta_info *sta = NULL;
121 struct ieee80211_key *key;
124 if (!ieee80211_sdata_running(sdata))
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))
139 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
140 params->key, params->seq_len, params->seq);
145 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
147 mutex_lock(&sdata->local->sta_mtx);
150 if (ieee80211_vif_is_mesh(&sdata->vif))
151 sta = sta_info_get(sdata, mac_addr);
153 sta = sta_info_get_bss(sdata, mac_addr);
155 ieee80211_key_free(sdata->local, key);
161 err = ieee80211_key_link(key, sdata, sta);
163 ieee80211_key_free(sdata->local, key);
166 mutex_unlock(&sdata->local->sta_mtx);
171 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
172 u8 key_idx, bool pairwise, const u8 *mac_addr)
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;
180 mutex_lock(&local->sta_mtx);
181 mutex_lock(&local->key_mtx);
186 sta = sta_info_get_bss(sdata, mac_addr);
191 key = key_mtx_dereference(local, sta->ptk);
193 key = key_mtx_dereference(local, sta->gtk[key_idx]);
195 key = key_mtx_dereference(local, sdata->keys[key_idx]);
202 __ieee80211_key_free(key);
206 mutex_unlock(&local->key_mtx);
207 mutex_unlock(&local->sta_mtx);
212 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
213 u8 key_idx, bool pairwise, const u8 *mac_addr,
215 void (*callback)(void *cookie,
216 struct key_params *params))
218 struct ieee80211_sub_if_data *sdata;
219 struct sta_info *sta = NULL;
221 struct key_params params;
222 struct ieee80211_key *key = NULL;
228 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
233 sta = sta_info_get_bss(sdata, mac_addr);
238 key = rcu_dereference(sta->ptk);
239 else if (key_idx < NUM_DEFAULT_KEYS)
240 key = rcu_dereference(sta->gtk[key_idx]);
242 key = rcu_dereference(sdata->keys[key_idx]);
247 memset(¶ms, 0, sizeof(params));
249 params.cipher = key->conf.cipher;
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;
256 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
257 drv_get_tkip_seq(sdata->local,
258 key->conf.hw_key_idx,
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;
270 case WLAN_CIPHER_SUITE_CCMP:
271 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
281 case WLAN_CIPHER_SUITE_AES_CMAC:
282 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
294 params.key = key->conf.key;
295 params.key_len = key->conf.keylen;
297 callback(cookie, ¶ms);
305 static int ieee80211_config_default_key(struct wiphy *wiphy,
306 struct net_device *dev,
307 u8 key_idx, bool uni,
310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
312 ieee80211_set_default_key(sdata, key_idx, uni, multi);
317 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
318 struct net_device *dev,
321 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
323 ieee80211_set_default_mgmt_key(sdata, key_idx);
328 static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
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;
339 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
341 struct ieee80211_sub_if_data *sdata = sta->sdata;
342 struct timespec uptime;
344 sinfo->generation = sdata->local->sta_generation;
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;
360 do_posix_clock_monotonic_gettime(&uptime);
361 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
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;
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);
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);
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);
397 if (ieee80211_vif_is_mesh(&sdata->vif)) {
398 #ifdef CONFIG_MAC80211_MESH
399 sinfo->filled |= STATION_INFO_LLID |
401 STATION_INFO_PLINK_STATE;
403 sinfo->llid = le16_to_cpu(sta->llid);
404 sinfo->plid = le16_to_cpu(sta->plid);
405 sinfo->plink_state = sta->plink_state;
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;
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);
441 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
442 int idx, u8 *mac, struct station_info *sinfo)
444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
445 struct sta_info *sta;
450 sta = sta_info_get_by_idx(sdata, idx);
453 memcpy(mac, sta->sta.addr, ETH_ALEN);
454 sta_set_sinfo(sta, sinfo);
462 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
463 int idx, struct survey_info *survey)
465 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
467 return drv_get_survey(local, idx, survey);
470 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
471 u8 *mac, struct station_info *sinfo)
473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
474 struct sta_info *sta;
479 sta = sta_info_get_bss(sdata, mac);
482 sta_set_sinfo(sta, sinfo);
490 static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
491 struct beacon_parameters *params)
493 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
495 bss_conf->ssid_len = params->ssid_len;
497 if (params->ssid_len)
498 memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
500 bss_conf->hidden_ssid =
501 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
504 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
505 u8 *resp, size_t resp_len)
507 struct sk_buff *new, *old;
509 if (!resp || !resp_len)
512 old = sdata->u.ap.probe_resp;
514 new = dev_alloc_skb(resp_len);
518 memcpy(skb_put(new, resp_len), resp, resp_len);
520 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
530 * This handles both adding a beacon and setting new beacon info
532 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
533 struct beacon_parameters *params)
535 struct beacon_data *new, *old;
536 int new_head_len, new_tail_len;
541 old = rtnl_dereference(sdata->u.ap.beacon);
543 /* head must not be zero-length */
544 if (params->head && !params->head_len)
548 * This is a kludge. beacon interval should really be part
549 * of the beacon information.
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);
558 /* Need to have a beacon head if we don't have one yet */
559 if (!params->head && !old)
562 /* sorry, no way to start beaconing without dtim period */
563 if (!params->dtim_period && !old)
566 /* new or old head? */
568 new_head_len = params->head_len;
570 new_head_len = old->head_len;
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;
577 new_tail_len = old->tail_len;
579 size = sizeof(*new) + new_head_len + new_tail_len;
581 new = kzalloc(size, GFP_KERNEL);
585 /* start filling the new info now */
587 /* new or old dtim period? */
588 if (params->dtim_period)
589 new->dtim_period = params->dtim_period;
591 new->dtim_period = old->dtim_period;
594 * pointers go into the block we allocated,
595 * memory is | beacon_data | head | tail |
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;
604 memcpy(new->head, params->head, new_head_len);
606 memcpy(new->head, old->head, new_head_len);
608 /* copy in optional tail */
610 memcpy(new->tail, params->tail, new_tail_len);
613 memcpy(new->tail, old->tail, new_tail_len);
615 sdata->vif.bss_conf.dtim_period = new->dtim_period;
617 RCU_INIT_POINTER(sdata->u.ap.beacon, new);
623 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
624 params->probe_resp_len);
626 changed |= BSS_CHANGED_AP_PROBE_RESP;
628 ieee80211_config_ap_ssid(sdata, params);
629 changed |= BSS_CHANGED_BEACON_ENABLED |
633 ieee80211_bss_info_change_notify(sdata, changed);
637 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
638 struct beacon_parameters *params)
640 struct ieee80211_sub_if_data *sdata;
641 struct beacon_data *old;
642 struct ieee80211_sub_if_data *vlan;
645 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
647 old = rtnl_dereference(sdata->u.ap.beacon);
651 ret = ieee80211_config_beacon(sdata, params);
656 * Apply control port protocol, this allows us to
657 * not encrypt dynamic WEP control frames.
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;
671 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
672 struct beacon_parameters *params)
674 struct ieee80211_sub_if_data *sdata;
675 struct beacon_data *old;
677 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
679 old = rtnl_dereference(sdata->u.ap.beacon);
683 return ieee80211_config_beacon(sdata, params);
686 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
688 struct ieee80211_sub_if_data *sdata;
689 struct beacon_data *old;
691 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
693 old = rtnl_dereference(sdata->u.ap.beacon);
697 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
701 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
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 */
716 static void ieee80211_send_layer2_update(struct sta_info *sta)
718 struct iapp_layer2_update *msg;
721 /* Send Level 2 Update Frame to update forwarding tables in layer 2
724 skb = dev_alloc_skb(sizeof(*msg));
727 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
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 */
732 memset(msg->da, 0xff, ETH_ALEN);
733 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
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) */
743 skb->dev = sta->sdata->dev;
744 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
745 memset(skb->cb, 0, sizeof(skb->cb));
749 static void sta_apply_parameters(struct ieee80211_local *local,
750 struct sta_info *sta,
751 struct station_parameters *params)
755 struct ieee80211_supported_band *sband;
756 struct ieee80211_sub_if_data *sdata = sta->sdata;
759 sband = local->hw.wiphy->bands[local->oper_channel->band];
761 mask = params->sta_flags_mask;
762 set = params->sta_flags_set;
764 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
765 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
766 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
768 clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
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);
775 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
778 if (mask & BIT(NL80211_STA_FLAG_WME)) {
779 if (set & BIT(NL80211_STA_FLAG_WME)) {
780 set_sta_flag(sta, WLAN_STA_WME);
783 clear_sta_flag(sta, WLAN_STA_WME);
784 sta->sta.wme = false;
788 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
789 if (set & BIT(NL80211_STA_FLAG_MFP))
790 set_sta_flag(sta, WLAN_STA_MFP);
792 clear_sta_flag(sta, WLAN_STA_MFP);
795 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
796 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
797 set_sta_flag(sta, WLAN_STA_AUTH);
799 clear_sta_flag(sta, WLAN_STA_AUTH);
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);
806 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
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;
815 * cfg80211 validates this (1-2007) and allows setting the AID
816 * only when creating a new station entry
819 sta->sta.aid = params->aid;
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.
828 if (params->listen_interval >= 0)
829 sta->listen_interval = params->listen_interval;
831 if (params->supported_rates) {
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)
841 sta->sta.supp_rates[local->oper_channel->band] = rates;
845 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
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;
863 switch (params->plink_action) {
864 case PLINK_ACTION_OPEN:
865 mesh_plink_open(sta);
867 case PLINK_ACTION_BLOCK:
868 mesh_plink_block(sta);
875 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
876 u8 *mac, struct station_parameters *params)
878 struct ieee80211_local *local = wiphy_priv(wiphy);
879 struct sta_info *sta;
880 struct ieee80211_sub_if_data *sdata;
885 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
887 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
888 sdata->vif.type != NL80211_IFTYPE_AP)
891 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
893 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
896 if (is_multicast_ether_addr(mac))
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))
905 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
909 set_sta_flag(sta, WLAN_STA_AUTH);
910 set_sta_flag(sta, WLAN_STA_ASSOC);
912 sta_apply_parameters(local, sta, params);
915 * for TDLS, rate control should be initialized only when supported
918 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
919 rate_control_rate_init(sta);
921 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
922 sdata->vif.type == NL80211_IFTYPE_AP;
924 err = sta_info_insert_rcu(sta);
931 ieee80211_send_layer2_update(sta);
938 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
941 struct ieee80211_local *local = wiphy_priv(wiphy);
942 struct ieee80211_sub_if_data *sdata;
944 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
947 return sta_info_destroy_addr_bss(sdata, mac);
949 sta_info_flush(local, sdata);
953 static int ieee80211_change_station(struct wiphy *wiphy,
954 struct net_device *dev,
956 struct station_parameters *params)
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;
965 sta = sta_info_get_bss(sdata, mac);
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)) {
979 if (params->vlan && params->vlan != sta->sdata->dev) {
980 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
982 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
983 vlansdata->vif.type != NL80211_IFTYPE_AP) {
988 if (params->vlan->ieee80211_ptr->use_4addr) {
989 if (vlansdata->u.vlan.sta) {
994 RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
997 sta->sdata = vlansdata;
998 ieee80211_send_layer2_update(sta);
1001 sta_apply_parameters(local, sta, params);
1003 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1004 rate_control_rate_init(sta);
1008 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1009 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1010 ieee80211_recalc_ps(local, -1);
1015 #ifdef CONFIG_MAC80211_MESH
1016 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1017 u8 *dst, u8 *next_hop)
1019 struct ieee80211_sub_if_data *sdata;
1020 struct mesh_path *mpath;
1021 struct sta_info *sta;
1024 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1027 sta = sta_info_get(sdata, next_hop);
1033 err = mesh_path_add(dst, sdata);
1039 mpath = mesh_path_lookup(dst, sdata);
1044 mesh_path_fix_nexthop(mpath, sta);
1050 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1053 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1056 return mesh_path_del(dst, sdata);
1058 mesh_path_flush_by_iface(sdata);
1062 static int ieee80211_change_mpath(struct wiphy *wiphy,
1063 struct net_device *dev,
1064 u8 *dst, u8 *next_hop)
1066 struct ieee80211_sub_if_data *sdata;
1067 struct mesh_path *mpath;
1068 struct sta_info *sta;
1070 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1074 sta = sta_info_get(sdata, next_hop);
1080 mpath = mesh_path_lookup(dst, sdata);
1086 mesh_path_fix_nexthop(mpath, sta);
1092 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1093 struct mpath_info *pinfo)
1095 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1098 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1100 memset(next_hop, 0, ETH_ALEN);
1102 pinfo->generation = mesh_paths_generation;
1104 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1107 MPATH_INFO_EXPTIME |
1108 MPATH_INFO_DISCOVERY_TIMEOUT |
1109 MPATH_INFO_DISCOVERY_RETRIES |
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;
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;
1132 pinfo->flags = mpath->flags;
1135 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1136 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1139 struct ieee80211_sub_if_data *sdata;
1140 struct mesh_path *mpath;
1142 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1145 mpath = mesh_path_lookup(dst, sdata);
1150 memcpy(dst, mpath->dst, ETH_ALEN);
1151 mpath_set_pinfo(mpath, next_hop, pinfo);
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)
1160 struct ieee80211_sub_if_data *sdata;
1161 struct mesh_path *mpath;
1163 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1166 mpath = mesh_path_lookup_by_idx(idx, sdata);
1171 memcpy(dst, mpath->dst, ETH_ALEN);
1172 mpath_set_pinfo(mpath, next_hop, pinfo);
1177 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1178 struct net_device *dev,
1179 struct mesh_config *conf)
1181 struct ieee80211_sub_if_data *sdata;
1182 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1184 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1188 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1190 return (mask >> (parm-1)) & 0x1;
1193 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1194 const struct mesh_setup *setup)
1199 /* allocate information elements */
1203 if (setup->ie_len) {
1204 new_ie = kmemdup(setup->ie, setup->ie_len,
1209 ifmsh->ie_len = setup->ie_len;
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;
1227 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1228 struct net_device *dev, u32 mask,
1229 const struct mesh_config *nconf)
1231 struct mesh_config *conf;
1232 struct ieee80211_sub_if_data *sdata;
1233 struct ieee80211_if_mesh *ifmsh;
1235 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1236 ifmsh = &sdata->u.mesh;
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,
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);
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
1281 if (nconf->dot11MeshGateAnnouncementProtocol &&
1282 !conf->dot11MeshHWMPRootMode) {
1283 conf->dot11MeshHWMPRootMode = 1;
1284 ieee80211_mesh_root_setup(ifmsh);
1286 conf->dot11MeshGateAnnouncementProtocol =
1287 nconf->dot11MeshGateAnnouncementProtocol;
1289 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1290 conf->dot11MeshHWMPRannInterval =
1291 nconf->dot11MeshHWMPRannInterval;
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)
1300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1301 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1304 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1305 err = copy_mesh_setup(ifmsh, setup);
1308 ieee80211_start_mesh(sdata);
1313 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1315 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1317 ieee80211_stop_mesh(sdata);
1323 static int ieee80211_change_bss(struct wiphy *wiphy,
1324 struct net_device *dev,
1325 struct bss_parameters *params)
1327 struct ieee80211_sub_if_data *sdata;
1330 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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;
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;
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;
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;
1354 if (params->basic_rates) {
1357 struct ieee80211_local *local = wiphy_priv(wiphy);
1358 struct ieee80211_supported_band *sband =
1359 wiphy->bands[local->oper_channel->band];
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)
1368 sdata->vif.bss_conf.basic_rates = rates;
1369 changed |= BSS_CHANGED_BASIC_RATES;
1372 if (params->ap_isolate >= 0) {
1373 if (params->ap_isolate)
1374 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1376 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1379 if (params->ht_opmode >= 0) {
1380 sdata->vif.bss_conf.ht_operation_mode =
1381 (u16) params->ht_opmode;
1382 changed |= BSS_CHANGED_HT;
1385 ieee80211_bss_info_change_notify(sdata, changed);
1390 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1391 struct net_device *dev,
1392 struct ieee80211_txq_params *params)
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;
1398 if (!local->ops->conf_tx)
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;
1408 * Setting tx queue params disables u-apsd because it's only
1409 * called in master mode.
1413 if (params->queue >= local->hw.queues)
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",
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)
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;
1439 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1441 switch (ieee80211_get_channel_mode(local, NULL)) {
1442 case CHAN_MODE_HOPPING:
1444 case CHAN_MODE_FIXED:
1445 if (local->oper_channel != chan)
1447 if (!sdata && local->_oper_channel_type == channel_type)
1450 case CHAN_MODE_UNDEFINED:
1455 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1456 old_oper_type = local->_oper_channel_type;
1458 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1461 old_oper = local->oper_channel;
1462 local->oper_channel = chan;
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);
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);
1477 static int ieee80211_suspend(struct wiphy *wiphy,
1478 struct cfg80211_wowlan *wowlan)
1480 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1483 static int ieee80211_resume(struct wiphy *wiphy)
1485 return __ieee80211_resume(wiphy_priv(wiphy));
1488 #define ieee80211_suspend NULL
1489 #define ieee80211_resume NULL
1492 static int ieee80211_scan(struct wiphy *wiphy,
1493 struct net_device *dev,
1494 struct cfg80211_scan_request *req)
1496 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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:
1504 case NL80211_IFTYPE_P2P_GO:
1505 if (sdata->local->ops->hw_scan)
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
1512 case NL80211_IFTYPE_AP:
1513 if (sdata->u.ap.beacon)
1520 return ieee80211_request_scan(sdata, req);
1524 ieee80211_sched_scan_start(struct wiphy *wiphy,
1525 struct net_device *dev,
1526 struct cfg80211_sched_scan_request *req)
1528 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1530 if (!sdata->local->ops->sched_scan_start)
1533 return ieee80211_request_sched_scan_start(sdata, req);
1537 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1539 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1541 if (!sdata->local->ops->sched_scan_stop)
1544 return ieee80211_request_sched_scan_stop(sdata);
1547 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1548 struct cfg80211_auth_request *req)
1550 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1553 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1554 struct cfg80211_assoc_request *req)
1556 struct ieee80211_local *local = wiphy_priv(wiphy);
1557 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1559 switch (ieee80211_get_channel_mode(local, sdata)) {
1560 case CHAN_MODE_HOPPING:
1562 case CHAN_MODE_FIXED:
1563 if (local->oper_channel == req->bss->channel)
1566 case CHAN_MODE_UNDEFINED:
1570 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1573 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1574 struct cfg80211_deauth_request *req,
1577 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1581 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1582 struct cfg80211_disassoc_request *req,
1585 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1589 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1590 struct cfg80211_ibss_params *params)
1592 struct ieee80211_local *local = wiphy_priv(wiphy);
1593 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1595 switch (ieee80211_get_channel_mode(local, sdata)) {
1596 case CHAN_MODE_HOPPING:
1598 case CHAN_MODE_FIXED:
1599 if (!params->channel_fixed)
1601 if (local->oper_channel == params->channel)
1604 case CHAN_MODE_UNDEFINED:
1608 return ieee80211_ibss_join(sdata, params);
1611 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1613 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1615 return ieee80211_ibss_leave(sdata);
1618 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1620 struct ieee80211_local *local = wiphy_priv(wiphy);
1623 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1624 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1630 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1631 err = drv_set_coverage_class(local, wiphy->coverage_class);
1637 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1638 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
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;
1649 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1650 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1655 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1656 enum nl80211_tx_power_setting type, int mbm)
1658 struct ieee80211_local *local = wiphy_priv(wiphy);
1659 struct ieee80211_channel *chan = local->hw.conf.channel;
1663 case NL80211_TX_POWER_AUTOMATIC:
1664 local->user_power_level = -1;
1666 case NL80211_TX_POWER_LIMITED:
1667 if (mbm < 0 || (mbm % 100))
1669 local->user_power_level = MBM_TO_DBM(mbm);
1671 case NL80211_TX_POWER_FIXED:
1672 if (mbm < 0 || (mbm % 100))
1674 /* TODO: move to cfg80211 when it knows the channel */
1675 if (MBM_TO_DBM(mbm) > chan->max_power)
1677 local->user_power_level = MBM_TO_DBM(mbm);
1681 ieee80211_hw_config(local, changes);
1686 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1688 struct ieee80211_local *local = wiphy_priv(wiphy);
1690 *dbm = local->hw.conf.power_level;
1695 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1698 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1700 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1705 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1707 struct ieee80211_local *local = wiphy_priv(wiphy);
1709 drv_rfkill_poll(local);
1712 #ifdef CONFIG_NL80211_TESTMODE
1713 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1715 struct ieee80211_local *local = wiphy_priv(wiphy);
1717 if (!local->ops->testmode_cmd)
1720 return local->ops->testmode_cmd(&local->hw, data, len);
1723 static int ieee80211_testmode_dump(struct wiphy *wiphy,
1724 struct sk_buff *skb,
1725 struct netlink_callback *cb,
1726 void *data, int len)
1728 struct ieee80211_local *local = wiphy_priv(wiphy);
1730 if (!local->ops->testmode_dump)
1733 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1737 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1738 enum ieee80211_smps_mode smps_mode)
1741 enum ieee80211_smps_mode old_req;
1744 lockdep_assert_held(&sdata->u.mgd.mtx);
1746 old_req = sdata->u.mgd.req_smps;
1747 sdata->u.mgd.req_smps = smps_mode;
1749 if (old_req == smps_mode &&
1750 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1754 * If not associated, or current association is not an HT
1755 * association, there's no need to send an action frame.
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);
1765 ap = sdata->u.mgd.associated->bssid;
1767 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1768 if (sdata->u.mgd.powersave)
1769 smps_mode = IEEE80211_SMPS_DYNAMIC;
1771 smps_mode = IEEE80211_SMPS_OFF;
1774 /* send SM PS frame to AP */
1775 err = ieee80211_send_smps_action(sdata, smps_mode,
1778 sdata->u.mgd.req_smps = old_req;
1783 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1784 bool enabled, int timeout)
1786 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1787 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1789 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1792 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1795 if (enabled == sdata->u.mgd.powersave &&
1796 timeout == local->dynamic_ps_forced_timeout)
1799 sdata->u.mgd.powersave = enabled;
1800 local->dynamic_ps_forced_timeout = timeout;
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);
1807 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1808 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1810 ieee80211_recalc_ps(local, -1);
1815 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1816 struct net_device *dev,
1817 s32 rssi_thold, u32 rssi_hyst)
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;
1824 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1825 rssi_hyst == bss_conf->cqm_rssi_hyst)
1828 bss_conf->cqm_rssi_thold = rssi_thold;
1829 bss_conf->cqm_rssi_hyst = rssi_hyst;
1831 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1832 if (sdata->vif.type != NL80211_IFTYPE_STATION)
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);
1844 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1845 struct net_device *dev,
1847 const struct cfg80211_bitrate_mask *mask)
1849 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1850 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1853 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1854 ret = drv_set_bitrate_mask(local, sdata, mask);
1859 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1860 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
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)
1874 lockdep_assert_held(&local->mtx);
1876 if (local->hw_roc_cookie)
1878 /* must be nonzero */
1879 random_cookie = random32() | 1;
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);
1889 local->hw_roc_channel = NULL;
1890 local->hw_roc_cookie = 0;
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,
1903 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1904 struct ieee80211_local *local = sdata->local;
1906 if (local->ops->remain_on_channel) {
1909 mutex_lock(&local->mtx);
1910 ret = ieee80211_remain_on_channel_hw(local, dev,
1913 local->hw_roc_for_tx = false;
1914 mutex_unlock(&local->mtx);
1919 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1923 static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1928 lockdep_assert_held(&local->mtx);
1930 if (local->hw_roc_cookie != cookie)
1933 ret = drv_cancel_remain_on_channel(local);
1937 local->hw_roc_cookie = 0;
1938 local->hw_roc_channel = NULL;
1940 ieee80211_recalc_idle(local);
1945 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1946 struct net_device *dev,
1949 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1950 struct ieee80211_local *local = sdata->local;
1952 if (local->ops->cancel_remain_on_channel) {
1955 mutex_lock(&local->mtx);
1956 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1957 mutex_unlock(&local->mtx);
1962 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1965 static enum work_done_result
1966 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
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.
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.
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);
1984 return WORK_DONE_DESTROY;
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)
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;
2001 bool is_offchan = false;
2003 if (dont_wait_for_ack)
2004 flags = IEEE80211_TX_CTL_NO_ACK;
2006 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2007 IEEE80211_TX_CTL_REQ_TX_STATUS;
2009 /* Check that we are on the requested channel for transmission */
2010 if (chan != local->tmp_channel &&
2011 chan != local->oper_channel)
2013 if (channel_type_valid &&
2014 (channel_type != local->tmp_channel_type &&
2015 channel_type != local->_oper_channel_type))
2018 if (chan == local->hw_roc_channel) {
2019 /* TODO: check channel type? */
2021 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2025 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2027 if (is_offchan && !offchan)
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)
2040 sta = sta_info_get(sdata, mgmt->da);
2045 case NL80211_IFTYPE_STATION:
2046 case NL80211_IFTYPE_P2P_CLIENT:
2052 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2055 skb_reserve(skb, local->hw.extra_tx_headroom);
2057 memcpy(skb_put(skb, len), buf, len);
2059 IEEE80211_SKB_CB(skb)->flags = flags;
2061 skb->dev = sdata->dev;
2063 *cookie = (unsigned long) skb;
2065 if (is_offchan && local->ops->remain_on_channel) {
2066 unsigned int duration;
2069 mutex_lock(&local->mtx);
2071 * If the duration is zero, then the driver
2072 * wouldn't actually do anything. Set it to
2075 * TODO: cancel the off-channel operation
2076 * when we get the SKB's TX status and
2077 * the wait time was zero before.
2082 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2087 mutex_unlock(&local->mtx);
2091 local->hw_roc_for_tx = true;
2092 local->hw_roc_duration = wait;
2095 * queue up frame for transmission after
2096 * ieee80211_ready_on_channel call
2099 /* modify cookie to prevent API mismatches */
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);
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!
2115 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2116 ieee80211_tx_skb(sdata, skb);
2120 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2126 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2128 wk->chan_type = channel_type;
2130 wk->done = ieee80211_offchan_tx_done;
2131 wk->offchan_tx.frame = skb;
2132 wk->offchan_tx.wait = wait;
2134 memcpy(wk->ie, buf, len);
2136 ieee80211_add_work(wk);
2140 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2141 struct net_device *dev,
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;
2149 mutex_lock(&local->mtx);
2151 if (local->ops->cancel_remain_on_channel) {
2153 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2156 kfree_skb(local->hw_roc_skb);
2157 local->hw_roc_skb = NULL;
2158 local->hw_roc_skb_for_status = NULL;
2161 mutex_unlock(&local->mtx);
2166 list_for_each_entry(wk, &local->work_list, list) {
2167 if (wk->sdata != sdata)
2170 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2173 if (cookie != (unsigned long) wk->offchan_tx.frame)
2176 wk->timeout = jiffies;
2178 ieee80211_queue_work(&local->hw, &local->work_work);
2182 mutex_unlock(&local->mtx);
2187 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2188 struct net_device *dev,
2189 u16 frame_type, bool reg)
2191 struct ieee80211_local *local = wiphy_priv(wiphy);
2193 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2197 local->probe_req_reg++;
2199 local->probe_req_reg--;
2201 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2204 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2206 struct ieee80211_local *local = wiphy_priv(wiphy);
2211 return drv_set_antenna(local, tx_ant, rx_ant);
2214 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2216 struct ieee80211_local *local = wiphy_priv(wiphy);
2218 return drv_get_antenna(local, tx_ant, rx_ant);
2221 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2223 struct ieee80211_local *local = wiphy_priv(wiphy);
2225 return drv_set_ringparam(local, tx, rx);
2228 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2229 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2231 struct ieee80211_local *local = wiphy_priv(wiphy);
2233 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2236 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2237 struct net_device *dev,
2238 struct cfg80211_gtk_rekey_data *data)
2240 struct ieee80211_local *local = wiphy_priv(wiphy);
2241 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2243 if (!local->ops->set_rekey_data)
2246 drv_set_rekey_data(local, sdata, data);
2251 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2253 u8 *pos = (void *)skb_put(skb, 7);
2255 *pos++ = WLAN_EID_EXT_CAPABILITY;
2256 *pos++ = 5; /* len */
2261 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2264 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2266 struct ieee80211_local *local = sdata->local;
2270 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
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;
2281 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2282 u8 *peer, u8 *bssid)
2284 struct ieee80211_tdls_lnkie *lnkid;
2286 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2288 lnkid->ie_type = WLAN_EID_LINK_ID;
2289 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2291 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2292 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2293 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
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)
2301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2302 struct ieee80211_tdls_data *tf;
2304 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
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;
2311 switch (action_code) {
2312 case WLAN_TDLS_SETUP_REQUEST:
2313 tf->category = WLAN_CATEGORY_TDLS;
2314 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
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));
2321 ieee80211_add_srates_ie(&sdata->vif, skb);
2322 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2323 ieee80211_tdls_add_ext_capab(skb);
2325 case WLAN_TDLS_SETUP_RESPONSE:
2326 tf->category = WLAN_CATEGORY_TDLS;
2327 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
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));
2335 ieee80211_add_srates_ie(&sdata->vif, skb);
2336 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2337 ieee80211_tdls_add_ext_capab(skb);
2339 case WLAN_TDLS_SETUP_CONFIRM:
2340 tf->category = WLAN_CATEGORY_TDLS;
2341 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
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;
2347 case WLAN_TDLS_TEARDOWN:
2348 tf->category = WLAN_CATEGORY_TDLS;
2349 tf->action_code = WLAN_TDLS_TEARDOWN;
2351 skb_put(skb, sizeof(tf->u.teardown));
2352 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2354 case WLAN_TDLS_DISCOVERY_REQUEST:
2355 tf->category = WLAN_CATEGORY_TDLS;
2356 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2358 skb_put(skb, sizeof(tf->u.discover_req));
2359 tf->u.discover_req.dialog_token = dialog_token;
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)
2373 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2374 struct ieee80211_mgmt *mgmt;
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);
2382 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2383 IEEE80211_STYPE_ACTION);
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 =
2393 mgmt->u.action.u.tdls_discover_resp.capability =
2394 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2396 ieee80211_add_srates_ie(&sdata->vif, skb);
2397 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2398 ieee80211_tdls_add_ext_capab(skb);
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)
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;
2419 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2422 /* make sure we are in managed mode, and associated */
2423 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2424 !sdata->u.mgd.associated)
2427 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2428 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
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 */
2437 sizeof(struct ieee80211_tdls_lnkie));
2441 info = IEEE80211_SKB_CB(skb);
2442 skb_reserve(skb, local->hw.extra_tx_headroom);
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,
2453 send_direct = false;
2455 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2456 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2457 dialog_token, status_code,
2470 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
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);
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);
2494 ieee80211_tx_skb(sdata, skb);
2499 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2500 * we should default to AC_VI.
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);
2509 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2514 /* disable bottom halves when entering the Tx path */
2516 ret = ieee80211_subif_start_xmit(skb, dev);
2526 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2527 u8 *peer, enum nl80211_tdls_operation oper)
2529 struct sta_info *sta;
2530 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2532 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2535 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2538 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2539 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2543 case NL80211_TDLS_ENABLE_LINK:
2545 sta = sta_info_get(sdata, peer);
2551 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
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 */
2568 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2569 const u8 *peer, u64 *cookie)
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);
2578 struct ieee80211_tx_info *info;
2579 struct sta_info *sta;
2582 sta = sta_info_get(sdata, peer);
2584 qos = test_sta_flag(sta, WLAN_STA_WME);
2592 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2593 IEEE80211_STYPE_QOS_NULLFUNC |
2594 IEEE80211_FCTL_FROMDS);
2597 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2598 IEEE80211_STYPE_NULLFUNC |
2599 IEEE80211_FCTL_FROMDS);
2602 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2608 skb_reserve(skb, local->hw.extra_tx_headroom);
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;
2618 info = IEEE80211_SKB_CB(skb);
2620 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2621 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2623 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2626 nullfunc->qos_ctrl = cpu_to_le16(7);
2629 ieee80211_xmit(sdata, skb);
2632 *cookie = (unsigned long) skb;
2636 static struct ieee80211_channel *
2637 ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2639 struct ieee80211_local *local = wiphy_priv(wiphy);
2641 return local->oper_channel;
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,
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,