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_add_key(struct wiphy *wiphy, struct net_device *dev,
106 u8 key_idx, bool pairwise, const u8 *mac_addr,
107 struct key_params *params)
109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
110 struct sta_info *sta = NULL;
111 struct ieee80211_key *key;
114 if (!ieee80211_sdata_running(sdata))
117 /* reject WEP and TKIP keys if WEP failed to initialize */
118 switch (params->cipher) {
119 case WLAN_CIPHER_SUITE_WEP40:
120 case WLAN_CIPHER_SUITE_TKIP:
121 case WLAN_CIPHER_SUITE_WEP104:
122 if (IS_ERR(sdata->local->wep_tx_tfm))
129 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
130 params->key, params->seq_len, params->seq);
135 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
137 mutex_lock(&sdata->local->sta_mtx);
140 if (ieee80211_vif_is_mesh(&sdata->vif))
141 sta = sta_info_get(sdata, mac_addr);
143 sta = sta_info_get_bss(sdata, mac_addr);
145 ieee80211_key_free(sdata->local, key);
151 err = ieee80211_key_link(key, sdata, sta);
153 ieee80211_key_free(sdata->local, key);
156 mutex_unlock(&sdata->local->sta_mtx);
161 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
162 u8 key_idx, bool pairwise, const u8 *mac_addr)
164 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
165 struct ieee80211_local *local = sdata->local;
166 struct sta_info *sta;
167 struct ieee80211_key *key = NULL;
170 mutex_lock(&local->sta_mtx);
171 mutex_lock(&local->key_mtx);
176 sta = sta_info_get_bss(sdata, mac_addr);
181 key = key_mtx_dereference(local, sta->ptk);
183 key = key_mtx_dereference(local, sta->gtk[key_idx]);
185 key = key_mtx_dereference(local, sdata->keys[key_idx]);
192 __ieee80211_key_free(key);
196 mutex_unlock(&local->key_mtx);
197 mutex_unlock(&local->sta_mtx);
202 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
203 u8 key_idx, bool pairwise, const u8 *mac_addr,
205 void (*callback)(void *cookie,
206 struct key_params *params))
208 struct ieee80211_sub_if_data *sdata;
209 struct sta_info *sta = NULL;
211 struct key_params params;
212 struct ieee80211_key *key = NULL;
218 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
223 sta = sta_info_get_bss(sdata, mac_addr);
228 key = rcu_dereference(sta->ptk);
229 else if (key_idx < NUM_DEFAULT_KEYS)
230 key = rcu_dereference(sta->gtk[key_idx]);
232 key = rcu_dereference(sdata->keys[key_idx]);
237 memset(¶ms, 0, sizeof(params));
239 params.cipher = key->conf.cipher;
241 switch (key->conf.cipher) {
242 case WLAN_CIPHER_SUITE_TKIP:
243 iv32 = key->u.tkip.tx.iv32;
244 iv16 = key->u.tkip.tx.iv16;
246 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
247 drv_get_tkip_seq(sdata->local,
248 key->conf.hw_key_idx,
251 seq[0] = iv16 & 0xff;
252 seq[1] = (iv16 >> 8) & 0xff;
253 seq[2] = iv32 & 0xff;
254 seq[3] = (iv32 >> 8) & 0xff;
255 seq[4] = (iv32 >> 16) & 0xff;
256 seq[5] = (iv32 >> 24) & 0xff;
260 case WLAN_CIPHER_SUITE_CCMP:
261 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
271 case WLAN_CIPHER_SUITE_AES_CMAC:
272 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
284 params.key = key->conf.key;
285 params.key_len = key->conf.keylen;
287 callback(cookie, ¶ms);
295 static int ieee80211_config_default_key(struct wiphy *wiphy,
296 struct net_device *dev,
297 u8 key_idx, bool uni,
300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
302 ieee80211_set_default_key(sdata, key_idx, uni, multi);
307 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
308 struct net_device *dev,
311 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
313 ieee80211_set_default_mgmt_key(sdata, key_idx);
318 static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
320 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
321 struct ieee80211_supported_band *sband;
322 sband = sta->local->hw.wiphy->bands[
323 sta->local->hw.conf.channel->band];
324 rate->legacy = sband->bitrates[idx].bitrate;
329 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
331 struct ieee80211_sub_if_data *sdata = sta->sdata;
332 struct timespec uptime;
334 sinfo->generation = sdata->local->sta_generation;
336 sinfo->filled = STATION_INFO_INACTIVE_TIME |
337 STATION_INFO_RX_BYTES |
338 STATION_INFO_TX_BYTES |
339 STATION_INFO_RX_PACKETS |
340 STATION_INFO_TX_PACKETS |
341 STATION_INFO_TX_RETRIES |
342 STATION_INFO_TX_FAILED |
343 STATION_INFO_TX_BITRATE |
344 STATION_INFO_RX_BITRATE |
345 STATION_INFO_RX_DROP_MISC |
346 STATION_INFO_BSS_PARAM |
347 STATION_INFO_CONNECTED_TIME |
348 STATION_INFO_STA_FLAGS;
350 do_posix_clock_monotonic_gettime(&uptime);
351 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
353 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
354 sinfo->rx_bytes = sta->rx_bytes;
355 sinfo->tx_bytes = sta->tx_bytes;
356 sinfo->rx_packets = sta->rx_packets;
357 sinfo->tx_packets = sta->tx_packets;
358 sinfo->tx_retries = sta->tx_retry_count;
359 sinfo->tx_failed = sta->tx_retry_failed;
360 sinfo->rx_dropped_misc = sta->rx_dropped;
362 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
363 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
364 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
365 sinfo->signal = (s8)sta->last_signal;
366 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
369 sinfo->txrate.flags = 0;
370 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
371 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
372 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
373 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
374 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
375 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
376 rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
378 sinfo->rxrate.flags = 0;
379 if (sta->last_rx_rate_flag & RX_FLAG_HT)
380 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
381 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
382 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
383 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
384 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
385 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
387 if (ieee80211_vif_is_mesh(&sdata->vif)) {
388 #ifdef CONFIG_MAC80211_MESH
389 sinfo->filled |= STATION_INFO_LLID |
391 STATION_INFO_PLINK_STATE;
393 sinfo->llid = le16_to_cpu(sta->llid);
394 sinfo->plid = le16_to_cpu(sta->plid);
395 sinfo->plink_state = sta->plink_state;
399 sinfo->bss_param.flags = 0;
400 if (sdata->vif.bss_conf.use_cts_prot)
401 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
402 if (sdata->vif.bss_conf.use_short_preamble)
403 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
404 if (sdata->vif.bss_conf.use_short_slot)
405 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
406 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
407 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
409 sinfo->sta_flags.set = 0;
410 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
411 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
412 BIT(NL80211_STA_FLAG_WME) |
413 BIT(NL80211_STA_FLAG_MFP) |
414 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
415 BIT(NL80211_STA_FLAG_TDLS_PEER);
416 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
417 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
418 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
419 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
420 if (test_sta_flag(sta, WLAN_STA_WME))
421 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
422 if (test_sta_flag(sta, WLAN_STA_MFP))
423 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
424 if (test_sta_flag(sta, WLAN_STA_AUTH))
425 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
426 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
427 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
431 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
432 int idx, u8 *mac, struct station_info *sinfo)
434 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
435 struct sta_info *sta;
440 sta = sta_info_get_by_idx(sdata, idx);
443 memcpy(mac, sta->sta.addr, ETH_ALEN);
444 sta_set_sinfo(sta, sinfo);
452 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
453 int idx, struct survey_info *survey)
455 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
457 return drv_get_survey(local, idx, survey);
460 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
461 u8 *mac, struct station_info *sinfo)
463 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
464 struct sta_info *sta;
469 sta = sta_info_get_bss(sdata, mac);
472 sta_set_sinfo(sta, sinfo);
480 static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
481 struct beacon_parameters *params)
483 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
485 bss_conf->ssid_len = params->ssid_len;
487 if (params->ssid_len)
488 memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
490 bss_conf->hidden_ssid =
491 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
494 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
495 u8 *resp, size_t resp_len)
497 struct sk_buff *new, *old;
499 if (!resp || !resp_len)
502 old = sdata->u.ap.probe_resp;
504 new = dev_alloc_skb(resp_len);
508 memcpy(skb_put(new, resp_len), resp, resp_len);
510 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
520 * This handles both adding a beacon and setting new beacon info
522 static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
523 struct beacon_parameters *params)
525 struct beacon_data *new, *old;
526 int new_head_len, new_tail_len;
531 old = rtnl_dereference(sdata->u.ap.beacon);
533 /* head must not be zero-length */
534 if (params->head && !params->head_len)
538 * This is a kludge. beacon interval should really be part
539 * of the beacon information.
541 if (params->interval &&
542 (sdata->vif.bss_conf.beacon_int != params->interval)) {
543 sdata->vif.bss_conf.beacon_int = params->interval;
544 ieee80211_bss_info_change_notify(sdata,
545 BSS_CHANGED_BEACON_INT);
548 /* Need to have a beacon head if we don't have one yet */
549 if (!params->head && !old)
552 /* sorry, no way to start beaconing without dtim period */
553 if (!params->dtim_period && !old)
556 /* new or old head? */
558 new_head_len = params->head_len;
560 new_head_len = old->head_len;
562 /* new or old tail? */
563 if (params->tail || !old)
564 /* params->tail_len will be zero for !params->tail */
565 new_tail_len = params->tail_len;
567 new_tail_len = old->tail_len;
569 size = sizeof(*new) + new_head_len + new_tail_len;
571 new = kzalloc(size, GFP_KERNEL);
575 /* start filling the new info now */
577 /* new or old dtim period? */
578 if (params->dtim_period)
579 new->dtim_period = params->dtim_period;
581 new->dtim_period = old->dtim_period;
584 * pointers go into the block we allocated,
585 * memory is | beacon_data | head | tail |
587 new->head = ((u8 *) new) + sizeof(*new);
588 new->tail = new->head + new_head_len;
589 new->head_len = new_head_len;
590 new->tail_len = new_tail_len;
594 memcpy(new->head, params->head, new_head_len);
596 memcpy(new->head, old->head, new_head_len);
598 /* copy in optional tail */
600 memcpy(new->tail, params->tail, new_tail_len);
603 memcpy(new->tail, old->tail, new_tail_len);
605 sdata->vif.bss_conf.dtim_period = new->dtim_period;
607 RCU_INIT_POINTER(sdata->u.ap.beacon, new);
613 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
614 params->probe_resp_len);
616 changed |= BSS_CHANGED_AP_PROBE_RESP;
618 ieee80211_config_ap_ssid(sdata, params);
619 changed |= BSS_CHANGED_BEACON_ENABLED |
623 ieee80211_bss_info_change_notify(sdata, changed);
627 static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
628 struct beacon_parameters *params)
630 struct ieee80211_sub_if_data *sdata;
631 struct beacon_data *old;
632 struct ieee80211_sub_if_data *vlan;
635 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
637 old = rtnl_dereference(sdata->u.ap.beacon);
641 ret = ieee80211_config_beacon(sdata, params);
646 * Apply control port protocol, this allows us to
647 * not encrypt dynamic WEP control frames.
649 sdata->control_port_protocol = params->crypto.control_port_ethertype;
650 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
651 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
652 vlan->control_port_protocol =
653 params->crypto.control_port_ethertype;
654 vlan->control_port_no_encrypt =
655 params->crypto.control_port_no_encrypt;
661 static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
662 struct beacon_parameters *params)
664 struct ieee80211_sub_if_data *sdata;
665 struct beacon_data *old;
667 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
669 old = rtnl_dereference(sdata->u.ap.beacon);
673 return ieee80211_config_beacon(sdata, params);
676 static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
678 struct ieee80211_sub_if_data *sdata;
679 struct beacon_data *old;
681 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
683 old = rtnl_dereference(sdata->u.ap.beacon);
687 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
691 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
695 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
696 struct iapp_layer2_update {
697 u8 da[ETH_ALEN]; /* broadcast */
698 u8 sa[ETH_ALEN]; /* STA addr */
706 static void ieee80211_send_layer2_update(struct sta_info *sta)
708 struct iapp_layer2_update *msg;
711 /* Send Level 2 Update Frame to update forwarding tables in layer 2
714 skb = dev_alloc_skb(sizeof(*msg));
717 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
719 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
720 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
722 memset(msg->da, 0xff, ETH_ALEN);
723 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
726 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
727 msg->control = 0xaf; /* XID response lsb.1111F101.
728 * F=0 (no poll command; unsolicited frame) */
729 msg->xid_info[0] = 0x81; /* XID format identifier */
730 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
731 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
733 skb->dev = sta->sdata->dev;
734 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
735 memset(skb->cb, 0, sizeof(skb->cb));
739 static void sta_apply_parameters(struct ieee80211_local *local,
740 struct sta_info *sta,
741 struct station_parameters *params)
745 struct ieee80211_supported_band *sband;
746 struct ieee80211_sub_if_data *sdata = sta->sdata;
749 sband = local->hw.wiphy->bands[local->oper_channel->band];
751 mask = params->sta_flags_mask;
752 set = params->sta_flags_set;
754 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
755 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
756 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
758 clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
761 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
762 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
763 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
765 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
768 if (mask & BIT(NL80211_STA_FLAG_WME)) {
769 if (set & BIT(NL80211_STA_FLAG_WME)) {
770 set_sta_flag(sta, WLAN_STA_WME);
773 clear_sta_flag(sta, WLAN_STA_WME);
774 sta->sta.wme = false;
778 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
779 if (set & BIT(NL80211_STA_FLAG_MFP))
780 set_sta_flag(sta, WLAN_STA_MFP);
782 clear_sta_flag(sta, WLAN_STA_MFP);
785 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
786 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
787 set_sta_flag(sta, WLAN_STA_AUTH);
789 clear_sta_flag(sta, WLAN_STA_AUTH);
792 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
793 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
794 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
796 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
799 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
800 sta->sta.uapsd_queues = params->uapsd_queues;
801 sta->sta.max_sp = params->max_sp;
805 * cfg80211 validates this (1-2007) and allows setting the AID
806 * only when creating a new station entry
809 sta->sta.aid = params->aid;
812 * FIXME: updating the following information is racy when this
813 * function is called from ieee80211_change_station().
814 * However, all this information should be static so
815 * maybe we should just reject attemps to change it.
818 if (params->listen_interval >= 0)
819 sta->listen_interval = params->listen_interval;
821 if (params->supported_rates) {
824 for (i = 0; i < params->supported_rates_len; i++) {
825 int rate = (params->supported_rates[i] & 0x7f) * 5;
826 for (j = 0; j < sband->n_bitrates; j++) {
827 if (sband->bitrates[j].bitrate == rate)
831 sta->sta.supp_rates[local->oper_channel->band] = rates;
835 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
839 if (ieee80211_vif_is_mesh(&sdata->vif)) {
840 #ifdef CONFIG_MAC80211_MESH
841 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
842 switch (params->plink_state) {
843 case NL80211_PLINK_LISTEN:
844 case NL80211_PLINK_ESTAB:
845 case NL80211_PLINK_BLOCKED:
846 sta->plink_state = params->plink_state;
853 switch (params->plink_action) {
854 case PLINK_ACTION_OPEN:
855 mesh_plink_open(sta);
857 case PLINK_ACTION_BLOCK:
858 mesh_plink_block(sta);
865 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
866 u8 *mac, struct station_parameters *params)
868 struct ieee80211_local *local = wiphy_priv(wiphy);
869 struct sta_info *sta;
870 struct ieee80211_sub_if_data *sdata;
875 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
877 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
878 sdata->vif.type != NL80211_IFTYPE_AP)
881 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
883 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
886 if (is_multicast_ether_addr(mac))
889 /* Only TDLS-supporting stations can add TDLS peers */
890 if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
891 !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
892 sdata->vif.type == NL80211_IFTYPE_STATION))
895 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
899 set_sta_flag(sta, WLAN_STA_AUTH);
900 set_sta_flag(sta, WLAN_STA_ASSOC);
902 sta_apply_parameters(local, sta, params);
905 * for TDLS, rate control should be initialized only when supported
908 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
909 rate_control_rate_init(sta);
911 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
912 sdata->vif.type == NL80211_IFTYPE_AP;
914 err = sta_info_insert_rcu(sta);
921 ieee80211_send_layer2_update(sta);
928 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
931 struct ieee80211_local *local = wiphy_priv(wiphy);
932 struct ieee80211_sub_if_data *sdata;
934 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
937 return sta_info_destroy_addr_bss(sdata, mac);
939 sta_info_flush(local, sdata);
943 static int ieee80211_change_station(struct wiphy *wiphy,
944 struct net_device *dev,
946 struct station_parameters *params)
948 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
949 struct ieee80211_local *local = wiphy_priv(wiphy);
950 struct sta_info *sta;
951 struct ieee80211_sub_if_data *vlansdata;
955 sta = sta_info_get_bss(sdata, mac);
961 /* The TDLS bit cannot be toggled after the STA was added */
962 if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
963 !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
964 !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
969 if (params->vlan && params->vlan != sta->sdata->dev) {
970 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
972 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
973 vlansdata->vif.type != NL80211_IFTYPE_AP) {
978 if (params->vlan->ieee80211_ptr->use_4addr) {
979 if (vlansdata->u.vlan.sta) {
984 RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
987 sta->sdata = vlansdata;
988 ieee80211_send_layer2_update(sta);
991 sta_apply_parameters(local, sta, params);
993 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
994 rate_control_rate_init(sta);
998 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
999 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1000 ieee80211_recalc_ps(local, -1);
1005 #ifdef CONFIG_MAC80211_MESH
1006 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1007 u8 *dst, u8 *next_hop)
1009 struct ieee80211_sub_if_data *sdata;
1010 struct mesh_path *mpath;
1011 struct sta_info *sta;
1014 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1017 sta = sta_info_get(sdata, next_hop);
1023 err = mesh_path_add(dst, sdata);
1029 mpath = mesh_path_lookup(dst, sdata);
1034 mesh_path_fix_nexthop(mpath, sta);
1040 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1043 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1046 return mesh_path_del(dst, sdata);
1048 mesh_path_flush_by_iface(sdata);
1052 static int ieee80211_change_mpath(struct wiphy *wiphy,
1053 struct net_device *dev,
1054 u8 *dst, u8 *next_hop)
1056 struct ieee80211_sub_if_data *sdata;
1057 struct mesh_path *mpath;
1058 struct sta_info *sta;
1060 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1064 sta = sta_info_get(sdata, next_hop);
1070 mpath = mesh_path_lookup(dst, sdata);
1076 mesh_path_fix_nexthop(mpath, sta);
1082 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1083 struct mpath_info *pinfo)
1085 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1088 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1090 memset(next_hop, 0, ETH_ALEN);
1092 pinfo->generation = mesh_paths_generation;
1094 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1097 MPATH_INFO_EXPTIME |
1098 MPATH_INFO_DISCOVERY_TIMEOUT |
1099 MPATH_INFO_DISCOVERY_RETRIES |
1102 pinfo->frame_qlen = mpath->frame_queue.qlen;
1103 pinfo->sn = mpath->sn;
1104 pinfo->metric = mpath->metric;
1105 if (time_before(jiffies, mpath->exp_time))
1106 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1107 pinfo->discovery_timeout =
1108 jiffies_to_msecs(mpath->discovery_timeout);
1109 pinfo->discovery_retries = mpath->discovery_retries;
1111 if (mpath->flags & MESH_PATH_ACTIVE)
1112 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1113 if (mpath->flags & MESH_PATH_RESOLVING)
1114 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1115 if (mpath->flags & MESH_PATH_SN_VALID)
1116 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1117 if (mpath->flags & MESH_PATH_FIXED)
1118 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1119 if (mpath->flags & MESH_PATH_RESOLVING)
1120 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1122 pinfo->flags = mpath->flags;
1125 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1126 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1129 struct ieee80211_sub_if_data *sdata;
1130 struct mesh_path *mpath;
1132 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1135 mpath = mesh_path_lookup(dst, sdata);
1140 memcpy(dst, mpath->dst, ETH_ALEN);
1141 mpath_set_pinfo(mpath, next_hop, pinfo);
1146 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1147 int idx, u8 *dst, u8 *next_hop,
1148 struct mpath_info *pinfo)
1150 struct ieee80211_sub_if_data *sdata;
1151 struct mesh_path *mpath;
1153 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1156 mpath = mesh_path_lookup_by_idx(idx, sdata);
1161 memcpy(dst, mpath->dst, ETH_ALEN);
1162 mpath_set_pinfo(mpath, next_hop, pinfo);
1167 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1168 struct net_device *dev,
1169 struct mesh_config *conf)
1171 struct ieee80211_sub_if_data *sdata;
1172 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1174 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1178 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1180 return (mask >> (parm-1)) & 0x1;
1183 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1184 const struct mesh_setup *setup)
1189 /* allocate information elements */
1193 if (setup->ie_len) {
1194 new_ie = kmemdup(setup->ie, setup->ie_len,
1199 ifmsh->ie_len = setup->ie_len;
1203 /* now copy the rest of the setup parameters */
1204 ifmsh->mesh_id_len = setup->mesh_id_len;
1205 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1206 ifmsh->mesh_pp_id = setup->path_sel_proto;
1207 ifmsh->mesh_pm_id = setup->path_metric;
1208 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1209 if (setup->is_authenticated)
1210 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1211 if (setup->is_secure)
1212 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1217 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1218 struct net_device *dev, u32 mask,
1219 const struct mesh_config *nconf)
1221 struct mesh_config *conf;
1222 struct ieee80211_sub_if_data *sdata;
1223 struct ieee80211_if_mesh *ifmsh;
1225 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1226 ifmsh = &sdata->u.mesh;
1228 /* Set the config options which we are interested in setting */
1229 conf = &(sdata->u.mesh.mshcfg);
1230 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1231 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1232 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1233 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1234 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1235 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1236 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1237 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1238 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1239 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1240 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1241 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1242 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1243 conf->dot11MeshTTL = nconf->element_ttl;
1244 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1245 conf->auto_open_plinks = nconf->auto_open_plinks;
1246 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1247 conf->dot11MeshHWMPmaxPREQretries =
1248 nconf->dot11MeshHWMPmaxPREQretries;
1249 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1250 conf->path_refresh_time = nconf->path_refresh_time;
1251 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1252 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1253 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1254 conf->dot11MeshHWMPactivePathTimeout =
1255 nconf->dot11MeshHWMPactivePathTimeout;
1256 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1257 conf->dot11MeshHWMPpreqMinInterval =
1258 nconf->dot11MeshHWMPpreqMinInterval;
1259 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1261 conf->dot11MeshHWMPnetDiameterTraversalTime =
1262 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1263 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1264 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1265 ieee80211_mesh_root_setup(ifmsh);
1267 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1268 /* our current gate announcement implementation rides on root
1269 * announcements, so require this ifmsh to also be a root node
1271 if (nconf->dot11MeshGateAnnouncementProtocol &&
1272 !conf->dot11MeshHWMPRootMode) {
1273 conf->dot11MeshHWMPRootMode = 1;
1274 ieee80211_mesh_root_setup(ifmsh);
1276 conf->dot11MeshGateAnnouncementProtocol =
1277 nconf->dot11MeshGateAnnouncementProtocol;
1279 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1280 conf->dot11MeshHWMPRannInterval =
1281 nconf->dot11MeshHWMPRannInterval;
1286 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1287 const struct mesh_config *conf,
1288 const struct mesh_setup *setup)
1290 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1291 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1294 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1295 err = copy_mesh_setup(ifmsh, setup);
1298 ieee80211_start_mesh(sdata);
1303 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1307 ieee80211_stop_mesh(sdata);
1313 static int ieee80211_change_bss(struct wiphy *wiphy,
1314 struct net_device *dev,
1315 struct bss_parameters *params)
1317 struct ieee80211_sub_if_data *sdata;
1320 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1322 if (params->use_cts_prot >= 0) {
1323 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1324 changed |= BSS_CHANGED_ERP_CTS_PROT;
1326 if (params->use_short_preamble >= 0) {
1327 sdata->vif.bss_conf.use_short_preamble =
1328 params->use_short_preamble;
1329 changed |= BSS_CHANGED_ERP_PREAMBLE;
1332 if (!sdata->vif.bss_conf.use_short_slot &&
1333 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1334 sdata->vif.bss_conf.use_short_slot = true;
1335 changed |= BSS_CHANGED_ERP_SLOT;
1338 if (params->use_short_slot_time >= 0) {
1339 sdata->vif.bss_conf.use_short_slot =
1340 params->use_short_slot_time;
1341 changed |= BSS_CHANGED_ERP_SLOT;
1344 if (params->basic_rates) {
1347 struct ieee80211_local *local = wiphy_priv(wiphy);
1348 struct ieee80211_supported_band *sband =
1349 wiphy->bands[local->oper_channel->band];
1351 for (i = 0; i < params->basic_rates_len; i++) {
1352 int rate = (params->basic_rates[i] & 0x7f) * 5;
1353 for (j = 0; j < sband->n_bitrates; j++) {
1354 if (sband->bitrates[j].bitrate == rate)
1358 sdata->vif.bss_conf.basic_rates = rates;
1359 changed |= BSS_CHANGED_BASIC_RATES;
1362 if (params->ap_isolate >= 0) {
1363 if (params->ap_isolate)
1364 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1366 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1369 if (params->ht_opmode >= 0) {
1370 sdata->vif.bss_conf.ht_operation_mode =
1371 (u16) params->ht_opmode;
1372 changed |= BSS_CHANGED_HT;
1375 ieee80211_bss_info_change_notify(sdata, changed);
1380 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1381 struct net_device *dev,
1382 struct ieee80211_txq_params *params)
1384 struct ieee80211_local *local = wiphy_priv(wiphy);
1385 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1386 struct ieee80211_tx_queue_params p;
1388 if (!local->ops->conf_tx)
1391 memset(&p, 0, sizeof(p));
1392 p.aifs = params->aifs;
1393 p.cw_max = params->cwmax;
1394 p.cw_min = params->cwmin;
1395 p.txop = params->txop;
1398 * Setting tx queue params disables u-apsd because it's only
1399 * called in master mode.
1403 if (params->queue >= local->hw.queues)
1406 sdata->tx_conf[params->queue] = p;
1407 if (drv_conf_tx(local, sdata, params->queue, &p)) {
1408 wiphy_debug(local->hw.wiphy,
1409 "failed to set TX queue parameters for queue %d\n",
1417 static int ieee80211_set_channel(struct wiphy *wiphy,
1418 struct net_device *netdev,
1419 struct ieee80211_channel *chan,
1420 enum nl80211_channel_type channel_type)
1422 struct ieee80211_local *local = wiphy_priv(wiphy);
1423 struct ieee80211_sub_if_data *sdata = NULL;
1424 struct ieee80211_channel *old_oper;
1425 enum nl80211_channel_type old_oper_type;
1426 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
1429 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1431 switch (ieee80211_get_channel_mode(local, NULL)) {
1432 case CHAN_MODE_HOPPING:
1434 case CHAN_MODE_FIXED:
1435 if (local->oper_channel != chan)
1437 if (!sdata && local->_oper_channel_type == channel_type)
1440 case CHAN_MODE_UNDEFINED:
1445 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1446 old_oper_type = local->_oper_channel_type;
1448 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1451 old_oper = local->oper_channel;
1452 local->oper_channel = chan;
1454 /* Update driver if changes were actually made. */
1455 if ((old_oper != local->oper_channel) ||
1456 (old_oper_type != local->_oper_channel_type))
1457 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1459 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1460 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
1461 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1467 static int ieee80211_suspend(struct wiphy *wiphy,
1468 struct cfg80211_wowlan *wowlan)
1470 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1473 static int ieee80211_resume(struct wiphy *wiphy)
1475 return __ieee80211_resume(wiphy_priv(wiphy));
1478 #define ieee80211_suspend NULL
1479 #define ieee80211_resume NULL
1482 static int ieee80211_scan(struct wiphy *wiphy,
1483 struct net_device *dev,
1484 struct cfg80211_scan_request *req)
1486 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1488 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1489 case NL80211_IFTYPE_STATION:
1490 case NL80211_IFTYPE_ADHOC:
1491 case NL80211_IFTYPE_MESH_POINT:
1492 case NL80211_IFTYPE_P2P_CLIENT:
1494 case NL80211_IFTYPE_P2P_GO:
1495 if (sdata->local->ops->hw_scan)
1498 * FIXME: implement NoA while scanning in software,
1499 * for now fall through to allow scanning only when
1500 * beaconing hasn't been configured yet
1502 case NL80211_IFTYPE_AP:
1503 if (sdata->u.ap.beacon)
1510 return ieee80211_request_scan(sdata, req);
1514 ieee80211_sched_scan_start(struct wiphy *wiphy,
1515 struct net_device *dev,
1516 struct cfg80211_sched_scan_request *req)
1518 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1520 if (!sdata->local->ops->sched_scan_start)
1523 return ieee80211_request_sched_scan_start(sdata, req);
1527 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1529 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1531 if (!sdata->local->ops->sched_scan_stop)
1534 return ieee80211_request_sched_scan_stop(sdata);
1537 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1538 struct cfg80211_auth_request *req)
1540 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1543 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1544 struct cfg80211_assoc_request *req)
1546 struct ieee80211_local *local = wiphy_priv(wiphy);
1547 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1549 switch (ieee80211_get_channel_mode(local, sdata)) {
1550 case CHAN_MODE_HOPPING:
1552 case CHAN_MODE_FIXED:
1553 if (local->oper_channel == req->bss->channel)
1556 case CHAN_MODE_UNDEFINED:
1560 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1563 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1564 struct cfg80211_deauth_request *req,
1567 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1571 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1572 struct cfg80211_disassoc_request *req,
1575 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1579 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1580 struct cfg80211_ibss_params *params)
1582 struct ieee80211_local *local = wiphy_priv(wiphy);
1583 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1585 switch (ieee80211_get_channel_mode(local, sdata)) {
1586 case CHAN_MODE_HOPPING:
1588 case CHAN_MODE_FIXED:
1589 if (!params->channel_fixed)
1591 if (local->oper_channel == params->channel)
1594 case CHAN_MODE_UNDEFINED:
1598 return ieee80211_ibss_join(sdata, params);
1601 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1603 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1605 return ieee80211_ibss_leave(sdata);
1608 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1610 struct ieee80211_local *local = wiphy_priv(wiphy);
1613 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1614 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1620 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1621 err = drv_set_coverage_class(local, wiphy->coverage_class);
1627 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1628 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1634 if (changed & WIPHY_PARAM_RETRY_SHORT)
1635 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1636 if (changed & WIPHY_PARAM_RETRY_LONG)
1637 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1639 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1640 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1645 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1646 enum nl80211_tx_power_setting type, int mbm)
1648 struct ieee80211_local *local = wiphy_priv(wiphy);
1649 struct ieee80211_channel *chan = local->hw.conf.channel;
1653 case NL80211_TX_POWER_AUTOMATIC:
1654 local->user_power_level = -1;
1656 case NL80211_TX_POWER_LIMITED:
1657 if (mbm < 0 || (mbm % 100))
1659 local->user_power_level = MBM_TO_DBM(mbm);
1661 case NL80211_TX_POWER_FIXED:
1662 if (mbm < 0 || (mbm % 100))
1664 /* TODO: move to cfg80211 when it knows the channel */
1665 if (MBM_TO_DBM(mbm) > chan->max_power)
1667 local->user_power_level = MBM_TO_DBM(mbm);
1671 ieee80211_hw_config(local, changes);
1676 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1678 struct ieee80211_local *local = wiphy_priv(wiphy);
1680 *dbm = local->hw.conf.power_level;
1685 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1688 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1690 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1695 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1697 struct ieee80211_local *local = wiphy_priv(wiphy);
1699 drv_rfkill_poll(local);
1702 #ifdef CONFIG_NL80211_TESTMODE
1703 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1705 struct ieee80211_local *local = wiphy_priv(wiphy);
1707 if (!local->ops->testmode_cmd)
1710 return local->ops->testmode_cmd(&local->hw, data, len);
1713 static int ieee80211_testmode_dump(struct wiphy *wiphy,
1714 struct sk_buff *skb,
1715 struct netlink_callback *cb,
1716 void *data, int len)
1718 struct ieee80211_local *local = wiphy_priv(wiphy);
1720 if (!local->ops->testmode_dump)
1723 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1727 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1728 enum ieee80211_smps_mode smps_mode)
1731 enum ieee80211_smps_mode old_req;
1734 lockdep_assert_held(&sdata->u.mgd.mtx);
1736 old_req = sdata->u.mgd.req_smps;
1737 sdata->u.mgd.req_smps = smps_mode;
1739 if (old_req == smps_mode &&
1740 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1744 * If not associated, or current association is not an HT
1745 * association, there's no need to send an action frame.
1747 if (!sdata->u.mgd.associated ||
1748 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
1749 mutex_lock(&sdata->local->iflist_mtx);
1750 ieee80211_recalc_smps(sdata->local);
1751 mutex_unlock(&sdata->local->iflist_mtx);
1755 ap = sdata->u.mgd.associated->bssid;
1757 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1758 if (sdata->u.mgd.powersave)
1759 smps_mode = IEEE80211_SMPS_DYNAMIC;
1761 smps_mode = IEEE80211_SMPS_OFF;
1764 /* send SM PS frame to AP */
1765 err = ieee80211_send_smps_action(sdata, smps_mode,
1768 sdata->u.mgd.req_smps = old_req;
1773 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1774 bool enabled, int timeout)
1776 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1777 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1779 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1782 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1785 if (enabled == sdata->u.mgd.powersave &&
1786 timeout == local->dynamic_ps_forced_timeout)
1789 sdata->u.mgd.powersave = enabled;
1790 local->dynamic_ps_forced_timeout = timeout;
1792 /* no change, but if automatic follow powersave */
1793 mutex_lock(&sdata->u.mgd.mtx);
1794 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1795 mutex_unlock(&sdata->u.mgd.mtx);
1797 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1798 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1800 ieee80211_recalc_ps(local, -1);
1805 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1806 struct net_device *dev,
1807 s32 rssi_thold, u32 rssi_hyst)
1809 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1810 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1811 struct ieee80211_vif *vif = &sdata->vif;
1812 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1814 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1815 rssi_hyst == bss_conf->cqm_rssi_hyst)
1818 bss_conf->cqm_rssi_thold = rssi_thold;
1819 bss_conf->cqm_rssi_hyst = rssi_hyst;
1821 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1822 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1827 /* tell the driver upon association, unless already associated */
1828 if (sdata->u.mgd.associated)
1829 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1834 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1835 struct net_device *dev,
1837 const struct cfg80211_bitrate_mask *mask)
1839 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1840 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1843 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1844 ret = drv_set_bitrate_mask(local, sdata, mask);
1849 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1850 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1855 static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1856 struct net_device *dev,
1857 struct ieee80211_channel *chan,
1858 enum nl80211_channel_type chantype,
1859 unsigned int duration, u64 *cookie)
1864 lockdep_assert_held(&local->mtx);
1866 if (local->hw_roc_cookie)
1868 /* must be nonzero */
1869 random_cookie = random32() | 1;
1871 *cookie = random_cookie;
1872 local->hw_roc_dev = dev;
1873 local->hw_roc_cookie = random_cookie;
1874 local->hw_roc_channel = chan;
1875 local->hw_roc_channel_type = chantype;
1876 local->hw_roc_duration = duration;
1877 ret = drv_remain_on_channel(local, chan, chantype, duration);
1879 local->hw_roc_channel = NULL;
1880 local->hw_roc_cookie = 0;
1886 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1887 struct net_device *dev,
1888 struct ieee80211_channel *chan,
1889 enum nl80211_channel_type channel_type,
1890 unsigned int duration,
1893 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1894 struct ieee80211_local *local = sdata->local;
1896 if (local->ops->remain_on_channel) {
1899 mutex_lock(&local->mtx);
1900 ret = ieee80211_remain_on_channel_hw(local, dev,
1903 local->hw_roc_for_tx = false;
1904 mutex_unlock(&local->mtx);
1909 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1913 static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1918 lockdep_assert_held(&local->mtx);
1920 if (local->hw_roc_cookie != cookie)
1923 ret = drv_cancel_remain_on_channel(local);
1927 local->hw_roc_cookie = 0;
1928 local->hw_roc_channel = NULL;
1930 ieee80211_recalc_idle(local);
1935 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1936 struct net_device *dev,
1939 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1940 struct ieee80211_local *local = sdata->local;
1942 if (local->ops->cancel_remain_on_channel) {
1945 mutex_lock(&local->mtx);
1946 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1947 mutex_unlock(&local->mtx);
1952 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1955 static enum work_done_result
1956 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
1959 * Use the data embedded in the work struct for reporting
1960 * here so if the driver mangled the SKB before dropping
1961 * it (which is the only way we really should get here)
1962 * then we don't report mangled data.
1964 * If there was no wait time, then by the time we get here
1965 * the driver will likely not have reported the status yet,
1966 * so in that case userspace will have to deal with it.
1969 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
1970 cfg80211_mgmt_tx_status(wk->sdata->dev,
1971 (unsigned long) wk->offchan_tx.frame,
1972 wk->ie, wk->ie_len, false, GFP_KERNEL);
1974 return WORK_DONE_DESTROY;
1977 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1978 struct ieee80211_channel *chan, bool offchan,
1979 enum nl80211_channel_type channel_type,
1980 bool channel_type_valid, unsigned int wait,
1981 const u8 *buf, size_t len, bool no_cck,
1982 bool dont_wait_for_ack, u64 *cookie)
1984 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1985 struct ieee80211_local *local = sdata->local;
1986 struct sk_buff *skb;
1987 struct sta_info *sta;
1988 struct ieee80211_work *wk;
1989 const struct ieee80211_mgmt *mgmt = (void *)buf;
1991 bool is_offchan = false;
1993 if (dont_wait_for_ack)
1994 flags = IEEE80211_TX_CTL_NO_ACK;
1996 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1997 IEEE80211_TX_CTL_REQ_TX_STATUS;
1999 /* Check that we are on the requested channel for transmission */
2000 if (chan != local->tmp_channel &&
2001 chan != local->oper_channel)
2003 if (channel_type_valid &&
2004 (channel_type != local->tmp_channel_type &&
2005 channel_type != local->_oper_channel_type))
2008 if (chan == local->hw_roc_channel) {
2009 /* TODO: check channel type? */
2011 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2015 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2017 if (is_offchan && !offchan)
2020 switch (sdata->vif.type) {
2021 case NL80211_IFTYPE_ADHOC:
2022 case NL80211_IFTYPE_AP:
2023 case NL80211_IFTYPE_AP_VLAN:
2024 case NL80211_IFTYPE_P2P_GO:
2025 case NL80211_IFTYPE_MESH_POINT:
2026 if (!ieee80211_is_action(mgmt->frame_control) ||
2027 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2030 sta = sta_info_get(sdata, mgmt->da);
2035 case NL80211_IFTYPE_STATION:
2036 case NL80211_IFTYPE_P2P_CLIENT:
2042 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2045 skb_reserve(skb, local->hw.extra_tx_headroom);
2047 memcpy(skb_put(skb, len), buf, len);
2049 IEEE80211_SKB_CB(skb)->flags = flags;
2051 skb->dev = sdata->dev;
2053 *cookie = (unsigned long) skb;
2055 if (is_offchan && local->ops->remain_on_channel) {
2056 unsigned int duration;
2059 mutex_lock(&local->mtx);
2061 * If the duration is zero, then the driver
2062 * wouldn't actually do anything. Set it to
2065 * TODO: cancel the off-channel operation
2066 * when we get the SKB's TX status and
2067 * the wait time was zero before.
2072 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2077 mutex_unlock(&local->mtx);
2081 local->hw_roc_for_tx = true;
2082 local->hw_roc_duration = wait;
2085 * queue up frame for transmission after
2086 * ieee80211_ready_on_channel call
2089 /* modify cookie to prevent API mismatches */
2091 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2092 local->hw_roc_skb = skb;
2093 local->hw_roc_skb_for_status = skb;
2094 mutex_unlock(&local->mtx);
2100 * Can transmit right away if the channel was the
2101 * right one and there's no wait involved... If a
2102 * wait is involved, we might otherwise not be on
2103 * the right channel for long enough!
2105 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2106 ieee80211_tx_skb(sdata, skb);
2110 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2116 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2118 wk->chan_type = channel_type;
2120 wk->done = ieee80211_offchan_tx_done;
2121 wk->offchan_tx.frame = skb;
2122 wk->offchan_tx.wait = wait;
2124 memcpy(wk->ie, buf, len);
2126 ieee80211_add_work(wk);
2130 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2131 struct net_device *dev,
2134 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2135 struct ieee80211_local *local = sdata->local;
2136 struct ieee80211_work *wk;
2139 mutex_lock(&local->mtx);
2141 if (local->ops->cancel_remain_on_channel) {
2143 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2146 kfree_skb(local->hw_roc_skb);
2147 local->hw_roc_skb = NULL;
2148 local->hw_roc_skb_for_status = NULL;
2151 mutex_unlock(&local->mtx);
2156 list_for_each_entry(wk, &local->work_list, list) {
2157 if (wk->sdata != sdata)
2160 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2163 if (cookie != (unsigned long) wk->offchan_tx.frame)
2166 wk->timeout = jiffies;
2168 ieee80211_queue_work(&local->hw, &local->work_work);
2172 mutex_unlock(&local->mtx);
2177 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2178 struct net_device *dev,
2179 u16 frame_type, bool reg)
2181 struct ieee80211_local *local = wiphy_priv(wiphy);
2183 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2187 local->probe_req_reg++;
2189 local->probe_req_reg--;
2191 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2194 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2196 struct ieee80211_local *local = wiphy_priv(wiphy);
2201 return drv_set_antenna(local, tx_ant, rx_ant);
2204 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2206 struct ieee80211_local *local = wiphy_priv(wiphy);
2208 return drv_get_antenna(local, tx_ant, rx_ant);
2211 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2213 struct ieee80211_local *local = wiphy_priv(wiphy);
2215 return drv_set_ringparam(local, tx, rx);
2218 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2219 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2221 struct ieee80211_local *local = wiphy_priv(wiphy);
2223 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2226 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2227 struct net_device *dev,
2228 struct cfg80211_gtk_rekey_data *data)
2230 struct ieee80211_local *local = wiphy_priv(wiphy);
2231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2233 if (!local->ops->set_rekey_data)
2236 drv_set_rekey_data(local, sdata, data);
2241 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2243 u8 *pos = (void *)skb_put(skb, 7);
2245 *pos++ = WLAN_EID_EXT_CAPABILITY;
2246 *pos++ = 5; /* len */
2251 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2254 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2256 struct ieee80211_local *local = sdata->local;
2260 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2263 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2264 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2265 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2266 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2271 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2272 u8 *peer, u8 *bssid)
2274 struct ieee80211_tdls_lnkie *lnkid;
2276 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2278 lnkid->ie_type = WLAN_EID_LINK_ID;
2279 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2281 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2282 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2283 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2287 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2288 u8 *peer, u8 action_code, u8 dialog_token,
2289 u16 status_code, struct sk_buff *skb)
2291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2292 struct ieee80211_tdls_data *tf;
2294 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2296 memcpy(tf->da, peer, ETH_ALEN);
2297 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2298 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2299 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2301 switch (action_code) {
2302 case WLAN_TDLS_SETUP_REQUEST:
2303 tf->category = WLAN_CATEGORY_TDLS;
2304 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2306 skb_put(skb, sizeof(tf->u.setup_req));
2307 tf->u.setup_req.dialog_token = dialog_token;
2308 tf->u.setup_req.capability =
2309 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2311 ieee80211_add_srates_ie(&sdata->vif, skb);
2312 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2313 ieee80211_tdls_add_ext_capab(skb);
2315 case WLAN_TDLS_SETUP_RESPONSE:
2316 tf->category = WLAN_CATEGORY_TDLS;
2317 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2319 skb_put(skb, sizeof(tf->u.setup_resp));
2320 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2321 tf->u.setup_resp.dialog_token = dialog_token;
2322 tf->u.setup_resp.capability =
2323 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2325 ieee80211_add_srates_ie(&sdata->vif, skb);
2326 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2327 ieee80211_tdls_add_ext_capab(skb);
2329 case WLAN_TDLS_SETUP_CONFIRM:
2330 tf->category = WLAN_CATEGORY_TDLS;
2331 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2333 skb_put(skb, sizeof(tf->u.setup_cfm));
2334 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2335 tf->u.setup_cfm.dialog_token = dialog_token;
2337 case WLAN_TDLS_TEARDOWN:
2338 tf->category = WLAN_CATEGORY_TDLS;
2339 tf->action_code = WLAN_TDLS_TEARDOWN;
2341 skb_put(skb, sizeof(tf->u.teardown));
2342 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2344 case WLAN_TDLS_DISCOVERY_REQUEST:
2345 tf->category = WLAN_CATEGORY_TDLS;
2346 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2348 skb_put(skb, sizeof(tf->u.discover_req));
2349 tf->u.discover_req.dialog_token = dialog_token;
2359 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2360 u8 *peer, u8 action_code, u8 dialog_token,
2361 u16 status_code, struct sk_buff *skb)
2363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2364 struct ieee80211_mgmt *mgmt;
2366 mgmt = (void *)skb_put(skb, 24);
2367 memset(mgmt, 0, 24);
2368 memcpy(mgmt->da, peer, ETH_ALEN);
2369 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2370 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2372 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2373 IEEE80211_STYPE_ACTION);
2375 switch (action_code) {
2376 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2377 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2378 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2379 mgmt->u.action.u.tdls_discover_resp.action_code =
2380 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2381 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2383 mgmt->u.action.u.tdls_discover_resp.capability =
2384 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2386 ieee80211_add_srates_ie(&sdata->vif, skb);
2387 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2388 ieee80211_tdls_add_ext_capab(skb);
2397 static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2398 u8 *peer, u8 action_code, u8 dialog_token,
2399 u16 status_code, const u8 *extra_ies,
2400 size_t extra_ies_len)
2402 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2403 struct ieee80211_local *local = sdata->local;
2404 struct ieee80211_tx_info *info;
2405 struct sk_buff *skb = NULL;
2409 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2412 /* make sure we are in managed mode, and associated */
2413 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2414 !sdata->u.mgd.associated)
2417 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2418 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2421 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2422 max(sizeof(struct ieee80211_mgmt),
2423 sizeof(struct ieee80211_tdls_data)) +
2424 50 + /* supported rates */
2427 sizeof(struct ieee80211_tdls_lnkie));
2431 info = IEEE80211_SKB_CB(skb);
2432 skb_reserve(skb, local->hw.extra_tx_headroom);
2434 switch (action_code) {
2435 case WLAN_TDLS_SETUP_REQUEST:
2436 case WLAN_TDLS_SETUP_RESPONSE:
2437 case WLAN_TDLS_SETUP_CONFIRM:
2438 case WLAN_TDLS_TEARDOWN:
2439 case WLAN_TDLS_DISCOVERY_REQUEST:
2440 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2441 action_code, dialog_token,
2443 send_direct = false;
2445 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2446 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2447 dialog_token, status_code,
2460 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2462 /* the TDLS link IE is always added last */
2463 switch (action_code) {
2464 case WLAN_TDLS_SETUP_REQUEST:
2465 case WLAN_TDLS_SETUP_CONFIRM:
2466 case WLAN_TDLS_TEARDOWN:
2467 case WLAN_TDLS_DISCOVERY_REQUEST:
2468 /* we are the initiator */
2469 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2470 sdata->u.mgd.bssid);
2472 case WLAN_TDLS_SETUP_RESPONSE:
2473 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2474 /* we are the responder */
2475 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2476 sdata->u.mgd.bssid);
2484 ieee80211_tx_skb(sdata, skb);
2489 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2490 * we should default to AC_VI.
2492 switch (action_code) {
2493 case WLAN_TDLS_SETUP_REQUEST:
2494 case WLAN_TDLS_SETUP_RESPONSE:
2495 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2499 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2504 /* disable bottom halves when entering the Tx path */
2506 ret = ieee80211_subif_start_xmit(skb, dev);
2516 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2517 u8 *peer, enum nl80211_tdls_operation oper)
2519 struct sta_info *sta;
2520 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2522 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2525 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2528 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2529 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2533 case NL80211_TDLS_ENABLE_LINK:
2535 sta = sta_info_get(sdata, peer);
2541 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
2544 case NL80211_TDLS_DISABLE_LINK:
2545 return sta_info_destroy_addr(sdata, peer);
2546 case NL80211_TDLS_TEARDOWN:
2547 case NL80211_TDLS_SETUP:
2548 case NL80211_TDLS_DISCOVERY_REQ:
2549 /* We don't support in-driver setup/teardown/discovery */
2558 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2559 const u8 *peer, u64 *cookie)
2561 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2562 struct ieee80211_local *local = sdata->local;
2563 struct ieee80211_qos_hdr *nullfunc;
2564 struct sk_buff *skb;
2565 int size = sizeof(*nullfunc);
2568 struct ieee80211_tx_info *info;
2569 struct sta_info *sta;
2572 sta = sta_info_get(sdata, peer);
2574 qos = test_sta_flag(sta, WLAN_STA_WME);
2582 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2583 IEEE80211_STYPE_QOS_NULLFUNC |
2584 IEEE80211_FCTL_FROMDS);
2587 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2588 IEEE80211_STYPE_NULLFUNC |
2589 IEEE80211_FCTL_FROMDS);
2592 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2598 skb_reserve(skb, local->hw.extra_tx_headroom);
2600 nullfunc = (void *) skb_put(skb, size);
2601 nullfunc->frame_control = fc;
2602 nullfunc->duration_id = 0;
2603 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2604 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2605 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2606 nullfunc->seq_ctrl = 0;
2608 info = IEEE80211_SKB_CB(skb);
2610 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2611 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2613 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2616 nullfunc->qos_ctrl = cpu_to_le16(7);
2619 ieee80211_xmit(sdata, skb);
2622 *cookie = (unsigned long) skb;
2626 static struct ieee80211_channel *
2627 ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2629 struct ieee80211_local *local = wiphy_priv(wiphy);
2631 return local->oper_channel;
2634 struct cfg80211_ops mac80211_config_ops = {
2635 .add_virtual_intf = ieee80211_add_iface,
2636 .del_virtual_intf = ieee80211_del_iface,
2637 .change_virtual_intf = ieee80211_change_iface,
2638 .add_key = ieee80211_add_key,
2639 .del_key = ieee80211_del_key,
2640 .get_key = ieee80211_get_key,
2641 .set_default_key = ieee80211_config_default_key,
2642 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
2643 .add_beacon = ieee80211_add_beacon,
2644 .set_beacon = ieee80211_set_beacon,
2645 .del_beacon = ieee80211_del_beacon,
2646 .add_station = ieee80211_add_station,
2647 .del_station = ieee80211_del_station,
2648 .change_station = ieee80211_change_station,
2649 .get_station = ieee80211_get_station,
2650 .dump_station = ieee80211_dump_station,
2651 .dump_survey = ieee80211_dump_survey,
2652 #ifdef CONFIG_MAC80211_MESH
2653 .add_mpath = ieee80211_add_mpath,
2654 .del_mpath = ieee80211_del_mpath,
2655 .change_mpath = ieee80211_change_mpath,
2656 .get_mpath = ieee80211_get_mpath,
2657 .dump_mpath = ieee80211_dump_mpath,
2658 .update_mesh_config = ieee80211_update_mesh_config,
2659 .get_mesh_config = ieee80211_get_mesh_config,
2660 .join_mesh = ieee80211_join_mesh,
2661 .leave_mesh = ieee80211_leave_mesh,
2663 .change_bss = ieee80211_change_bss,
2664 .set_txq_params = ieee80211_set_txq_params,
2665 .set_channel = ieee80211_set_channel,
2666 .suspend = ieee80211_suspend,
2667 .resume = ieee80211_resume,
2668 .scan = ieee80211_scan,
2669 .sched_scan_start = ieee80211_sched_scan_start,
2670 .sched_scan_stop = ieee80211_sched_scan_stop,
2671 .auth = ieee80211_auth,
2672 .assoc = ieee80211_assoc,
2673 .deauth = ieee80211_deauth,
2674 .disassoc = ieee80211_disassoc,
2675 .join_ibss = ieee80211_join_ibss,
2676 .leave_ibss = ieee80211_leave_ibss,
2677 .set_wiphy_params = ieee80211_set_wiphy_params,
2678 .set_tx_power = ieee80211_set_tx_power,
2679 .get_tx_power = ieee80211_get_tx_power,
2680 .set_wds_peer = ieee80211_set_wds_peer,
2681 .rfkill_poll = ieee80211_rfkill_poll,
2682 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
2683 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
2684 .set_power_mgmt = ieee80211_set_power_mgmt,
2685 .set_bitrate_mask = ieee80211_set_bitrate_mask,
2686 .remain_on_channel = ieee80211_remain_on_channel,
2687 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2688 .mgmt_tx = ieee80211_mgmt_tx,
2689 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
2690 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
2691 .mgmt_frame_register = ieee80211_mgmt_frame_register,
2692 .set_antenna = ieee80211_set_antenna,
2693 .get_antenna = ieee80211_get_antenna,
2694 .set_ringparam = ieee80211_set_ringparam,
2695 .get_ringparam = ieee80211_get_ringparam,
2696 .set_rekey_data = ieee80211_set_rekey_data,
2697 .tdls_oper = ieee80211_tdls_oper,
2698 .tdls_mgmt = ieee80211_tdls_mgmt,
2699 .probe_client = ieee80211_probe_client,
2700 .get_channel = ieee80211_wiphy_get_channel,