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 void sta_set_rate_info_tx(struct sta_info *sta,
340 const struct ieee80211_tx_rate *rate,
341 struct rate_info *rinfo)
344 if (rate->flags & IEEE80211_TX_RC_MCS)
345 rinfo->flags |= RATE_INFO_FLAGS_MCS;
346 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
347 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
348 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
349 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
350 rate_idx_to_bitrate(rinfo, sta, rate->idx);
353 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
355 struct ieee80211_sub_if_data *sdata = sta->sdata;
356 struct timespec uptime;
358 sinfo->generation = sdata->local->sta_generation;
360 sinfo->filled = STATION_INFO_INACTIVE_TIME |
361 STATION_INFO_RX_BYTES |
362 STATION_INFO_TX_BYTES |
363 STATION_INFO_RX_PACKETS |
364 STATION_INFO_TX_PACKETS |
365 STATION_INFO_TX_RETRIES |
366 STATION_INFO_TX_FAILED |
367 STATION_INFO_TX_BITRATE |
368 STATION_INFO_RX_BITRATE |
369 STATION_INFO_RX_DROP_MISC |
370 STATION_INFO_BSS_PARAM |
371 STATION_INFO_CONNECTED_TIME |
372 STATION_INFO_STA_FLAGS |
373 STATION_INFO_BEACON_LOSS_COUNT;
375 do_posix_clock_monotonic_gettime(&uptime);
376 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
378 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
379 sinfo->rx_bytes = sta->rx_bytes;
380 sinfo->tx_bytes = sta->tx_bytes;
381 sinfo->rx_packets = sta->rx_packets;
382 sinfo->tx_packets = sta->tx_packets;
383 sinfo->tx_retries = sta->tx_retry_count;
384 sinfo->tx_failed = sta->tx_retry_failed;
385 sinfo->rx_dropped_misc = sta->rx_dropped;
386 sinfo->beacon_loss_count = sta->beacon_loss_count;
388 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
389 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
390 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
391 sinfo->signal = (s8)sta->last_signal;
392 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
395 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
397 sinfo->rxrate.flags = 0;
398 if (sta->last_rx_rate_flag & RX_FLAG_HT)
399 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
400 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
401 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
402 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
403 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
404 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
406 if (ieee80211_vif_is_mesh(&sdata->vif)) {
407 #ifdef CONFIG_MAC80211_MESH
408 sinfo->filled |= STATION_INFO_LLID |
410 STATION_INFO_PLINK_STATE;
412 sinfo->llid = le16_to_cpu(sta->llid);
413 sinfo->plid = le16_to_cpu(sta->plid);
414 sinfo->plink_state = sta->plink_state;
415 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
416 sinfo->filled |= STATION_INFO_T_OFFSET;
417 sinfo->t_offset = sta->t_offset;
422 sinfo->bss_param.flags = 0;
423 if (sdata->vif.bss_conf.use_cts_prot)
424 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
425 if (sdata->vif.bss_conf.use_short_preamble)
426 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
427 if (sdata->vif.bss_conf.use_short_slot)
428 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
429 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
430 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
432 sinfo->sta_flags.set = 0;
433 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
434 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
435 BIT(NL80211_STA_FLAG_WME) |
436 BIT(NL80211_STA_FLAG_MFP) |
437 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
438 BIT(NL80211_STA_FLAG_TDLS_PEER);
439 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
440 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
441 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
442 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
443 if (test_sta_flag(sta, WLAN_STA_WME))
444 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
445 if (test_sta_flag(sta, WLAN_STA_MFP))
446 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
447 if (test_sta_flag(sta, WLAN_STA_AUTH))
448 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
449 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
450 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
453 static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
454 "rx_packets", "rx_bytes", "wep_weak_iv_count",
455 "rx_duplicates", "rx_fragments", "rx_dropped",
456 "tx_packets", "tx_bytes", "tx_fragments",
457 "tx_filtered", "tx_retry_failed", "tx_retries",
460 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
462 static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
463 struct net_device *dev,
466 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
469 if (sset == ETH_SS_STATS)
472 rv += drv_get_et_sset_count(sdata, sset);
479 static void ieee80211_get_et_stats(struct wiphy *wiphy,
480 struct net_device *dev,
481 struct ethtool_stats *stats,
484 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
485 struct sta_info *sta;
486 struct ieee80211_local *local = sdata->local;
489 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
491 #define ADD_STA_STATS(sta) \
493 data[i++] += sta->rx_packets; \
494 data[i++] += sta->rx_bytes; \
495 data[i++] += sta->wep_weak_iv_count; \
496 data[i++] += sta->num_duplicates; \
497 data[i++] += sta->rx_fragments; \
498 data[i++] += sta->rx_dropped; \
500 data[i++] += sta->tx_packets; \
501 data[i++] += sta->tx_bytes; \
502 data[i++] += sta->tx_fragments; \
503 data[i++] += sta->tx_filtered_count; \
504 data[i++] += sta->tx_retry_failed; \
505 data[i++] += sta->tx_retry_count; \
506 data[i++] += sta->beacon_loss_count; \
509 /* For Managed stations, find the single station based on BSSID
510 * and use that. For interface types, iterate through all available
511 * stations and add stats for any station that is assigned to this
517 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
518 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
519 if (sta && !WARN_ON(sta->sdata->dev != dev)) {
522 BUG_ON(i != STA_STATS_LEN);
525 list_for_each_entry_rcu(sta, &local->sta_list, list) {
526 /* Make sure this station belongs to the proper dev */
527 if (sta->sdata->dev != dev)
532 BUG_ON(i != STA_STATS_LEN);
538 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
541 static void ieee80211_get_et_strings(struct wiphy *wiphy,
542 struct net_device *dev,
545 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
546 int sz_sta_stats = 0;
548 if (sset == ETH_SS_STATS) {
549 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
550 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
552 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
555 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
556 int idx, u8 *mac, struct station_info *sinfo)
558 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
559 struct sta_info *sta;
564 sta = sta_info_get_by_idx(sdata, idx);
567 memcpy(mac, sta->sta.addr, ETH_ALEN);
568 sta_set_sinfo(sta, sinfo);
576 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
577 int idx, struct survey_info *survey)
579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
581 return drv_get_survey(local, idx, survey);
584 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
585 u8 *mac, struct station_info *sinfo)
587 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
588 struct sta_info *sta;
593 sta = sta_info_get_bss(sdata, mac);
596 sta_set_sinfo(sta, sinfo);
604 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
605 const u8 *resp, size_t resp_len)
607 struct sk_buff *new, *old;
609 if (!resp || !resp_len)
612 old = rtnl_dereference(sdata->u.ap.probe_resp);
614 new = dev_alloc_skb(resp_len);
618 memcpy(skb_put(new, resp_len), resp, resp_len);
620 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
622 /* TODO: use call_rcu() */
630 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
631 struct cfg80211_beacon_data *params)
633 struct beacon_data *new, *old;
634 int new_head_len, new_tail_len;
636 u32 changed = BSS_CHANGED_BEACON;
638 old = rtnl_dereference(sdata->u.ap.beacon);
640 /* Need to have a beacon head if we don't have one yet */
641 if (!params->head && !old)
644 /* new or old head? */
646 new_head_len = params->head_len;
648 new_head_len = old->head_len;
650 /* new or old tail? */
651 if (params->tail || !old)
652 /* params->tail_len will be zero for !params->tail */
653 new_tail_len = params->tail_len;
655 new_tail_len = old->tail_len;
657 size = sizeof(*new) + new_head_len + new_tail_len;
659 new = kzalloc(size, GFP_KERNEL);
663 /* start filling the new info now */
666 * pointers go into the block we allocated,
667 * memory is | beacon_data | head | tail |
669 new->head = ((u8 *) new) + sizeof(*new);
670 new->tail = new->head + new_head_len;
671 new->head_len = new_head_len;
672 new->tail_len = new_tail_len;
676 memcpy(new->head, params->head, new_head_len);
678 memcpy(new->head, old->head, new_head_len);
680 /* copy in optional tail */
682 memcpy(new->tail, params->tail, new_tail_len);
685 memcpy(new->tail, old->tail, new_tail_len);
687 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
688 params->probe_resp_len);
692 changed |= BSS_CHANGED_AP_PROBE_RESP;
694 rcu_assign_pointer(sdata->u.ap.beacon, new);
697 kfree_rcu(old, rcu_head);
702 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
703 struct cfg80211_ap_settings *params)
705 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
706 struct beacon_data *old;
707 struct ieee80211_sub_if_data *vlan;
708 u32 changed = BSS_CHANGED_BEACON_INT |
709 BSS_CHANGED_BEACON_ENABLED |
714 old = rtnl_dereference(sdata->u.ap.beacon);
719 * Apply control port protocol, this allows us to
720 * not encrypt dynamic WEP control frames.
722 sdata->control_port_protocol = params->crypto.control_port_ethertype;
723 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
724 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
725 vlan->control_port_protocol =
726 params->crypto.control_port_ethertype;
727 vlan->control_port_no_encrypt =
728 params->crypto.control_port_no_encrypt;
731 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
732 sdata->vif.bss_conf.dtim_period = params->dtim_period;
734 sdata->vif.bss_conf.ssid_len = params->ssid_len;
735 if (params->ssid_len)
736 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
738 sdata->vif.bss_conf.hidden_ssid =
739 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
741 err = ieee80211_assign_beacon(sdata, ¶ms->beacon);
746 ieee80211_bss_info_change_notify(sdata, changed);
748 netif_carrier_on(dev);
749 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
750 netif_carrier_on(vlan->dev);
755 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
756 struct cfg80211_beacon_data *params)
758 struct ieee80211_sub_if_data *sdata;
759 struct beacon_data *old;
762 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
764 old = rtnl_dereference(sdata->u.ap.beacon);
768 err = ieee80211_assign_beacon(sdata, params);
771 ieee80211_bss_info_change_notify(sdata, err);
775 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
777 struct ieee80211_sub_if_data *sdata, *vlan;
778 struct beacon_data *old;
780 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
782 old = rtnl_dereference(sdata->u.ap.beacon);
786 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
787 netif_carrier_off(vlan->dev);
788 netif_carrier_off(dev);
790 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
792 kfree_rcu(old, rcu_head);
794 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
799 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
800 struct iapp_layer2_update {
801 u8 da[ETH_ALEN]; /* broadcast */
802 u8 sa[ETH_ALEN]; /* STA addr */
810 static void ieee80211_send_layer2_update(struct sta_info *sta)
812 struct iapp_layer2_update *msg;
815 /* Send Level 2 Update Frame to update forwarding tables in layer 2
818 skb = dev_alloc_skb(sizeof(*msg));
821 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
823 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
824 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
826 memset(msg->da, 0xff, ETH_ALEN);
827 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
830 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
831 msg->control = 0xaf; /* XID response lsb.1111F101.
832 * F=0 (no poll command; unsolicited frame) */
833 msg->xid_info[0] = 0x81; /* XID format identifier */
834 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
835 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
837 skb->dev = sta->sdata->dev;
838 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
839 memset(skb->cb, 0, sizeof(skb->cb));
843 static int sta_apply_parameters(struct ieee80211_local *local,
844 struct sta_info *sta,
845 struct station_parameters *params)
850 struct ieee80211_supported_band *sband;
851 struct ieee80211_sub_if_data *sdata = sta->sdata;
854 sband = local->hw.wiphy->bands[local->oper_channel->band];
856 mask = params->sta_flags_mask;
857 set = params->sta_flags_set;
860 * In mesh mode, we can clear AUTHENTICATED flag but must
861 * also make ASSOCIATED follow appropriately for the driver
862 * API. See also below, after AUTHORIZED changes.
864 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
865 /* cfg80211 should not allow this in non-mesh modes */
866 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
869 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
870 !test_sta_flag(sta, WLAN_STA_AUTH)) {
871 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
874 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
880 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
881 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
882 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
883 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
884 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
889 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
890 /* cfg80211 should not allow this in non-mesh modes */
891 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
894 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
895 test_sta_flag(sta, WLAN_STA_AUTH)) {
896 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
899 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
906 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
907 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
908 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
910 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
913 if (mask & BIT(NL80211_STA_FLAG_WME)) {
914 if (set & BIT(NL80211_STA_FLAG_WME)) {
915 set_sta_flag(sta, WLAN_STA_WME);
918 clear_sta_flag(sta, WLAN_STA_WME);
919 sta->sta.wme = false;
923 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
924 if (set & BIT(NL80211_STA_FLAG_MFP))
925 set_sta_flag(sta, WLAN_STA_MFP);
927 clear_sta_flag(sta, WLAN_STA_MFP);
930 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
931 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
932 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
934 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
937 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
938 sta->sta.uapsd_queues = params->uapsd_queues;
939 sta->sta.max_sp = params->max_sp;
943 * cfg80211 validates this (1-2007) and allows setting the AID
944 * only when creating a new station entry
947 sta->sta.aid = params->aid;
950 * FIXME: updating the following information is racy when this
951 * function is called from ieee80211_change_station().
952 * However, all this information should be static so
953 * maybe we should just reject attemps to change it.
956 if (params->listen_interval >= 0)
957 sta->listen_interval = params->listen_interval;
959 if (params->supported_rates) {
962 for (i = 0; i < params->supported_rates_len; i++) {
963 int rate = (params->supported_rates[i] & 0x7f) * 5;
964 for (j = 0; j < sband->n_bitrates; j++) {
965 if (sband->bitrates[j].bitrate == rate)
969 sta->sta.supp_rates[local->oper_channel->band] = rates;
973 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
977 if (ieee80211_vif_is_mesh(&sdata->vif)) {
978 #ifdef CONFIG_MAC80211_MESH
979 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
980 switch (params->plink_state) {
981 case NL80211_PLINK_LISTEN:
982 case NL80211_PLINK_ESTAB:
983 case NL80211_PLINK_BLOCKED:
984 sta->plink_state = params->plink_state;
991 switch (params->plink_action) {
992 case PLINK_ACTION_OPEN:
993 mesh_plink_open(sta);
995 case PLINK_ACTION_BLOCK:
996 mesh_plink_block(sta);
1005 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1006 u8 *mac, struct station_parameters *params)
1008 struct ieee80211_local *local = wiphy_priv(wiphy);
1009 struct sta_info *sta;
1010 struct ieee80211_sub_if_data *sdata;
1015 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1017 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1018 sdata->vif.type != NL80211_IFTYPE_AP)
1021 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1023 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
1026 if (is_multicast_ether_addr(mac))
1029 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1033 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1034 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1036 err = sta_apply_parameters(local, sta, params);
1038 sta_info_free(local, sta);
1043 * for TDLS, rate control should be initialized only when supported
1046 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1047 rate_control_rate_init(sta);
1049 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1050 sdata->vif.type == NL80211_IFTYPE_AP;
1052 err = sta_info_insert_rcu(sta);
1059 ieee80211_send_layer2_update(sta);
1066 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1069 struct ieee80211_local *local = wiphy_priv(wiphy);
1070 struct ieee80211_sub_if_data *sdata;
1072 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1075 return sta_info_destroy_addr_bss(sdata, mac);
1077 sta_info_flush(local, sdata);
1081 static int ieee80211_change_station(struct wiphy *wiphy,
1082 struct net_device *dev,
1084 struct station_parameters *params)
1086 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1087 struct ieee80211_local *local = wiphy_priv(wiphy);
1088 struct sta_info *sta;
1089 struct ieee80211_sub_if_data *vlansdata;
1092 mutex_lock(&local->sta_mtx);
1094 sta = sta_info_get_bss(sdata, mac);
1096 mutex_unlock(&local->sta_mtx);
1100 /* in station mode, supported rates are only valid with TDLS */
1101 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1102 params->supported_rates &&
1103 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1104 mutex_unlock(&local->sta_mtx);
1108 if (params->vlan && params->vlan != sta->sdata->dev) {
1109 bool prev_4addr = false;
1110 bool new_4addr = false;
1112 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1114 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1115 vlansdata->vif.type != NL80211_IFTYPE_AP) {
1116 mutex_unlock(&local->sta_mtx);
1120 if (params->vlan->ieee80211_ptr->use_4addr) {
1121 if (vlansdata->u.vlan.sta) {
1122 mutex_unlock(&local->sta_mtx);
1126 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1130 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1131 sta->sdata->u.vlan.sta) {
1132 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1136 sta->sdata = vlansdata;
1138 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1139 prev_4addr != new_4addr) {
1141 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1143 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1146 ieee80211_send_layer2_update(sta);
1149 err = sta_apply_parameters(local, sta, params);
1151 mutex_unlock(&local->sta_mtx);
1155 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1156 rate_control_rate_init(sta);
1158 mutex_unlock(&local->sta_mtx);
1160 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1161 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1162 ieee80211_recalc_ps(local, -1);
1167 #ifdef CONFIG_MAC80211_MESH
1168 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1169 u8 *dst, u8 *next_hop)
1171 struct ieee80211_sub_if_data *sdata;
1172 struct mesh_path *mpath;
1173 struct sta_info *sta;
1176 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1179 sta = sta_info_get(sdata, next_hop);
1185 err = mesh_path_add(dst, sdata);
1191 mpath = mesh_path_lookup(dst, sdata);
1196 mesh_path_fix_nexthop(mpath, sta);
1202 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1205 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1208 return mesh_path_del(dst, sdata);
1210 mesh_path_flush_by_iface(sdata);
1214 static int ieee80211_change_mpath(struct wiphy *wiphy,
1215 struct net_device *dev,
1216 u8 *dst, u8 *next_hop)
1218 struct ieee80211_sub_if_data *sdata;
1219 struct mesh_path *mpath;
1220 struct sta_info *sta;
1222 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1226 sta = sta_info_get(sdata, next_hop);
1232 mpath = mesh_path_lookup(dst, sdata);
1238 mesh_path_fix_nexthop(mpath, sta);
1244 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1245 struct mpath_info *pinfo)
1247 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1250 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1252 memset(next_hop, 0, ETH_ALEN);
1254 pinfo->generation = mesh_paths_generation;
1256 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1259 MPATH_INFO_EXPTIME |
1260 MPATH_INFO_DISCOVERY_TIMEOUT |
1261 MPATH_INFO_DISCOVERY_RETRIES |
1264 pinfo->frame_qlen = mpath->frame_queue.qlen;
1265 pinfo->sn = mpath->sn;
1266 pinfo->metric = mpath->metric;
1267 if (time_before(jiffies, mpath->exp_time))
1268 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1269 pinfo->discovery_timeout =
1270 jiffies_to_msecs(mpath->discovery_timeout);
1271 pinfo->discovery_retries = mpath->discovery_retries;
1273 if (mpath->flags & MESH_PATH_ACTIVE)
1274 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1275 if (mpath->flags & MESH_PATH_RESOLVING)
1276 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1277 if (mpath->flags & MESH_PATH_SN_VALID)
1278 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1279 if (mpath->flags & MESH_PATH_FIXED)
1280 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1281 if (mpath->flags & MESH_PATH_RESOLVING)
1282 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1284 pinfo->flags = mpath->flags;
1287 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1288 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1291 struct ieee80211_sub_if_data *sdata;
1292 struct mesh_path *mpath;
1294 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1297 mpath = mesh_path_lookup(dst, sdata);
1302 memcpy(dst, mpath->dst, ETH_ALEN);
1303 mpath_set_pinfo(mpath, next_hop, pinfo);
1308 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1309 int idx, u8 *dst, u8 *next_hop,
1310 struct mpath_info *pinfo)
1312 struct ieee80211_sub_if_data *sdata;
1313 struct mesh_path *mpath;
1315 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1318 mpath = mesh_path_lookup_by_idx(idx, sdata);
1323 memcpy(dst, mpath->dst, ETH_ALEN);
1324 mpath_set_pinfo(mpath, next_hop, pinfo);
1329 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1330 struct net_device *dev,
1331 struct mesh_config *conf)
1333 struct ieee80211_sub_if_data *sdata;
1334 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1336 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1340 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1342 return (mask >> (parm-1)) & 0x1;
1345 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1346 const struct mesh_setup *setup)
1350 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1351 struct ieee80211_sub_if_data, u.mesh);
1353 /* allocate information elements */
1357 if (setup->ie_len) {
1358 new_ie = kmemdup(setup->ie, setup->ie_len,
1363 ifmsh->ie_len = setup->ie_len;
1367 /* now copy the rest of the setup parameters */
1368 ifmsh->mesh_id_len = setup->mesh_id_len;
1369 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1370 ifmsh->mesh_sp_id = setup->sync_method;
1371 ifmsh->mesh_pp_id = setup->path_sel_proto;
1372 ifmsh->mesh_pm_id = setup->path_metric;
1373 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1374 if (setup->is_authenticated)
1375 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1376 if (setup->is_secure)
1377 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1379 /* mcast rate setting in Mesh Node */
1380 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1381 sizeof(setup->mcast_rate));
1386 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1387 struct net_device *dev, u32 mask,
1388 const struct mesh_config *nconf)
1390 struct mesh_config *conf;
1391 struct ieee80211_sub_if_data *sdata;
1392 struct ieee80211_if_mesh *ifmsh;
1394 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1395 ifmsh = &sdata->u.mesh;
1397 /* Set the config options which we are interested in setting */
1398 conf = &(sdata->u.mesh.mshcfg);
1399 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1400 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1401 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1402 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1403 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1404 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1405 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1406 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1407 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1408 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1409 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1410 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1411 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1412 conf->dot11MeshTTL = nconf->element_ttl;
1413 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1414 conf->auto_open_plinks = nconf->auto_open_plinks;
1415 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1416 conf->dot11MeshNbrOffsetMaxNeighbor =
1417 nconf->dot11MeshNbrOffsetMaxNeighbor;
1418 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1419 conf->dot11MeshHWMPmaxPREQretries =
1420 nconf->dot11MeshHWMPmaxPREQretries;
1421 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1422 conf->path_refresh_time = nconf->path_refresh_time;
1423 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1424 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1425 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1426 conf->dot11MeshHWMPactivePathTimeout =
1427 nconf->dot11MeshHWMPactivePathTimeout;
1428 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1429 conf->dot11MeshHWMPpreqMinInterval =
1430 nconf->dot11MeshHWMPpreqMinInterval;
1431 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1432 conf->dot11MeshHWMPperrMinInterval =
1433 nconf->dot11MeshHWMPperrMinInterval;
1434 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1436 conf->dot11MeshHWMPnetDiameterTraversalTime =
1437 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1438 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1439 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1440 ieee80211_mesh_root_setup(ifmsh);
1442 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1443 /* our current gate announcement implementation rides on root
1444 * announcements, so require this ifmsh to also be a root node
1446 if (nconf->dot11MeshGateAnnouncementProtocol &&
1447 !conf->dot11MeshHWMPRootMode) {
1448 conf->dot11MeshHWMPRootMode = 1;
1449 ieee80211_mesh_root_setup(ifmsh);
1451 conf->dot11MeshGateAnnouncementProtocol =
1452 nconf->dot11MeshGateAnnouncementProtocol;
1454 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1455 conf->dot11MeshHWMPRannInterval =
1456 nconf->dot11MeshHWMPRannInterval;
1458 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1459 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1460 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1461 /* our RSSI threshold implementation is supported only for
1462 * devices that report signal in dBm.
1464 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1466 conf->rssi_threshold = nconf->rssi_threshold;
1471 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1472 const struct mesh_config *conf,
1473 const struct mesh_setup *setup)
1475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1476 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1479 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1480 err = copy_mesh_setup(ifmsh, setup);
1483 ieee80211_start_mesh(sdata);
1488 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1490 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1492 ieee80211_stop_mesh(sdata);
1498 static int ieee80211_change_bss(struct wiphy *wiphy,
1499 struct net_device *dev,
1500 struct bss_parameters *params)
1502 struct ieee80211_sub_if_data *sdata;
1505 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1507 if (params->use_cts_prot >= 0) {
1508 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1509 changed |= BSS_CHANGED_ERP_CTS_PROT;
1511 if (params->use_short_preamble >= 0) {
1512 sdata->vif.bss_conf.use_short_preamble =
1513 params->use_short_preamble;
1514 changed |= BSS_CHANGED_ERP_PREAMBLE;
1517 if (!sdata->vif.bss_conf.use_short_slot &&
1518 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1519 sdata->vif.bss_conf.use_short_slot = true;
1520 changed |= BSS_CHANGED_ERP_SLOT;
1523 if (params->use_short_slot_time >= 0) {
1524 sdata->vif.bss_conf.use_short_slot =
1525 params->use_short_slot_time;
1526 changed |= BSS_CHANGED_ERP_SLOT;
1529 if (params->basic_rates) {
1532 struct ieee80211_local *local = wiphy_priv(wiphy);
1533 struct ieee80211_supported_band *sband =
1534 wiphy->bands[local->oper_channel->band];
1536 for (i = 0; i < params->basic_rates_len; i++) {
1537 int rate = (params->basic_rates[i] & 0x7f) * 5;
1538 for (j = 0; j < sband->n_bitrates; j++) {
1539 if (sband->bitrates[j].bitrate == rate)
1543 sdata->vif.bss_conf.basic_rates = rates;
1544 changed |= BSS_CHANGED_BASIC_RATES;
1547 if (params->ap_isolate >= 0) {
1548 if (params->ap_isolate)
1549 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1551 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1554 if (params->ht_opmode >= 0) {
1555 sdata->vif.bss_conf.ht_operation_mode =
1556 (u16) params->ht_opmode;
1557 changed |= BSS_CHANGED_HT;
1560 ieee80211_bss_info_change_notify(sdata, changed);
1565 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1566 struct net_device *dev,
1567 struct ieee80211_txq_params *params)
1569 struct ieee80211_local *local = wiphy_priv(wiphy);
1570 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1571 struct ieee80211_tx_queue_params p;
1573 if (!local->ops->conf_tx)
1576 if (local->hw.queues < IEEE80211_NUM_ACS)
1579 memset(&p, 0, sizeof(p));
1580 p.aifs = params->aifs;
1581 p.cw_max = params->cwmax;
1582 p.cw_min = params->cwmin;
1583 p.txop = params->txop;
1586 * Setting tx queue params disables u-apsd because it's only
1587 * called in master mode.
1591 sdata->tx_conf[params->ac] = p;
1592 if (drv_conf_tx(local, sdata, params->ac, &p)) {
1593 wiphy_debug(local->hw.wiphy,
1594 "failed to set TX queue parameters for AC %d\n",
1602 static int ieee80211_set_channel(struct wiphy *wiphy,
1603 struct net_device *netdev,
1604 struct ieee80211_channel *chan,
1605 enum nl80211_channel_type channel_type)
1607 struct ieee80211_local *local = wiphy_priv(wiphy);
1608 struct ieee80211_sub_if_data *sdata = NULL;
1609 struct ieee80211_channel *old_oper;
1610 enum nl80211_channel_type old_oper_type;
1611 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
1614 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1616 switch (ieee80211_get_channel_mode(local, NULL)) {
1617 case CHAN_MODE_HOPPING:
1619 case CHAN_MODE_FIXED:
1620 if (local->oper_channel != chan)
1622 if (!sdata && local->_oper_channel_type == channel_type)
1625 case CHAN_MODE_UNDEFINED:
1630 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1631 old_oper_type = local->_oper_channel_type;
1633 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1636 old_oper = local->oper_channel;
1637 local->oper_channel = chan;
1639 /* Update driver if changes were actually made. */
1640 if ((old_oper != local->oper_channel) ||
1641 (old_oper_type != local->_oper_channel_type))
1642 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1644 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1645 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
1646 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1652 static int ieee80211_suspend(struct wiphy *wiphy,
1653 struct cfg80211_wowlan *wowlan)
1655 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1658 static int ieee80211_resume(struct wiphy *wiphy)
1660 return __ieee80211_resume(wiphy_priv(wiphy));
1663 #define ieee80211_suspend NULL
1664 #define ieee80211_resume NULL
1667 static int ieee80211_scan(struct wiphy *wiphy,
1668 struct net_device *dev,
1669 struct cfg80211_scan_request *req)
1671 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1673 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1674 case NL80211_IFTYPE_STATION:
1675 case NL80211_IFTYPE_ADHOC:
1676 case NL80211_IFTYPE_MESH_POINT:
1677 case NL80211_IFTYPE_P2P_CLIENT:
1679 case NL80211_IFTYPE_P2P_GO:
1680 if (sdata->local->ops->hw_scan)
1683 * FIXME: implement NoA while scanning in software,
1684 * for now fall through to allow scanning only when
1685 * beaconing hasn't been configured yet
1687 case NL80211_IFTYPE_AP:
1688 if (sdata->u.ap.beacon)
1695 return ieee80211_request_scan(sdata, req);
1699 ieee80211_sched_scan_start(struct wiphy *wiphy,
1700 struct net_device *dev,
1701 struct cfg80211_sched_scan_request *req)
1703 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1705 if (!sdata->local->ops->sched_scan_start)
1708 return ieee80211_request_sched_scan_start(sdata, req);
1712 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1714 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1716 if (!sdata->local->ops->sched_scan_stop)
1719 return ieee80211_request_sched_scan_stop(sdata);
1722 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1723 struct cfg80211_auth_request *req)
1725 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1728 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1729 struct cfg80211_assoc_request *req)
1731 struct ieee80211_local *local = wiphy_priv(wiphy);
1732 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1734 switch (ieee80211_get_channel_mode(local, sdata)) {
1735 case CHAN_MODE_HOPPING:
1737 case CHAN_MODE_FIXED:
1738 if (local->oper_channel == req->bss->channel)
1741 case CHAN_MODE_UNDEFINED:
1745 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1748 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1749 struct cfg80211_deauth_request *req)
1751 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1754 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1755 struct cfg80211_disassoc_request *req)
1757 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1760 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1761 struct cfg80211_ibss_params *params)
1763 struct ieee80211_local *local = wiphy_priv(wiphy);
1764 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1766 switch (ieee80211_get_channel_mode(local, sdata)) {
1767 case CHAN_MODE_HOPPING:
1769 case CHAN_MODE_FIXED:
1770 if (!params->channel_fixed)
1772 if (local->oper_channel == params->channel)
1775 case CHAN_MODE_UNDEFINED:
1779 return ieee80211_ibss_join(sdata, params);
1782 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1784 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1786 return ieee80211_ibss_leave(sdata);
1789 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1791 struct ieee80211_local *local = wiphy_priv(wiphy);
1794 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1795 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1801 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1802 err = drv_set_coverage_class(local, wiphy->coverage_class);
1808 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1809 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1815 if (changed & WIPHY_PARAM_RETRY_SHORT)
1816 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1817 if (changed & WIPHY_PARAM_RETRY_LONG)
1818 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1820 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1821 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1826 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1827 enum nl80211_tx_power_setting type, int mbm)
1829 struct ieee80211_local *local = wiphy_priv(wiphy);
1830 struct ieee80211_channel *chan = local->hw.conf.channel;
1834 case NL80211_TX_POWER_AUTOMATIC:
1835 local->user_power_level = -1;
1837 case NL80211_TX_POWER_LIMITED:
1838 if (mbm < 0 || (mbm % 100))
1840 local->user_power_level = MBM_TO_DBM(mbm);
1842 case NL80211_TX_POWER_FIXED:
1843 if (mbm < 0 || (mbm % 100))
1845 /* TODO: move to cfg80211 when it knows the channel */
1846 if (MBM_TO_DBM(mbm) > chan->max_power)
1848 local->user_power_level = MBM_TO_DBM(mbm);
1852 ieee80211_hw_config(local, changes);
1857 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1859 struct ieee80211_local *local = wiphy_priv(wiphy);
1861 *dbm = local->hw.conf.power_level;
1866 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1871 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1876 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1878 struct ieee80211_local *local = wiphy_priv(wiphy);
1880 drv_rfkill_poll(local);
1883 #ifdef CONFIG_NL80211_TESTMODE
1884 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1886 struct ieee80211_local *local = wiphy_priv(wiphy);
1888 if (!local->ops->testmode_cmd)
1891 return local->ops->testmode_cmd(&local->hw, data, len);
1894 static int ieee80211_testmode_dump(struct wiphy *wiphy,
1895 struct sk_buff *skb,
1896 struct netlink_callback *cb,
1897 void *data, int len)
1899 struct ieee80211_local *local = wiphy_priv(wiphy);
1901 if (!local->ops->testmode_dump)
1904 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1908 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1909 enum ieee80211_smps_mode smps_mode)
1912 enum ieee80211_smps_mode old_req;
1915 lockdep_assert_held(&sdata->u.mgd.mtx);
1917 old_req = sdata->u.mgd.req_smps;
1918 sdata->u.mgd.req_smps = smps_mode;
1920 if (old_req == smps_mode &&
1921 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1925 * If not associated, or current association is not an HT
1926 * association, there's no need to send an action frame.
1928 if (!sdata->u.mgd.associated ||
1929 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
1930 mutex_lock(&sdata->local->iflist_mtx);
1931 ieee80211_recalc_smps(sdata->local);
1932 mutex_unlock(&sdata->local->iflist_mtx);
1936 ap = sdata->u.mgd.associated->bssid;
1938 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1939 if (sdata->u.mgd.powersave)
1940 smps_mode = IEEE80211_SMPS_DYNAMIC;
1942 smps_mode = IEEE80211_SMPS_OFF;
1945 /* send SM PS frame to AP */
1946 err = ieee80211_send_smps_action(sdata, smps_mode,
1949 sdata->u.mgd.req_smps = old_req;
1954 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1955 bool enabled, int timeout)
1957 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1958 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1960 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1963 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1966 if (enabled == sdata->u.mgd.powersave &&
1967 timeout == local->dynamic_ps_forced_timeout)
1970 sdata->u.mgd.powersave = enabled;
1971 local->dynamic_ps_forced_timeout = timeout;
1973 /* no change, but if automatic follow powersave */
1974 mutex_lock(&sdata->u.mgd.mtx);
1975 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1976 mutex_unlock(&sdata->u.mgd.mtx);
1978 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1979 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1981 ieee80211_recalc_ps(local, -1);
1986 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1987 struct net_device *dev,
1988 s32 rssi_thold, u32 rssi_hyst)
1990 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1991 struct ieee80211_vif *vif = &sdata->vif;
1992 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1994 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1995 rssi_hyst == bss_conf->cqm_rssi_hyst)
1998 bss_conf->cqm_rssi_thold = rssi_thold;
1999 bss_conf->cqm_rssi_hyst = rssi_hyst;
2001 /* tell the driver upon association, unless already associated */
2002 if (sdata->u.mgd.associated &&
2003 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2004 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2009 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2010 struct net_device *dev,
2012 const struct cfg80211_bitrate_mask *mask)
2014 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2015 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2018 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2019 ret = drv_set_bitrate_mask(local, sdata, mask);
2024 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
2025 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2026 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2027 sizeof(mask->control[i].mcs));
2033 static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
2034 struct net_device *dev,
2035 struct ieee80211_channel *chan,
2036 enum nl80211_channel_type chantype,
2037 unsigned int duration, u64 *cookie)
2042 lockdep_assert_held(&local->mtx);
2044 if (local->hw_roc_cookie)
2046 /* must be nonzero */
2047 random_cookie = random32() | 1;
2049 *cookie = random_cookie;
2050 local->hw_roc_dev = dev;
2051 local->hw_roc_cookie = random_cookie;
2052 local->hw_roc_channel = chan;
2053 local->hw_roc_channel_type = chantype;
2054 local->hw_roc_duration = duration;
2055 ret = drv_remain_on_channel(local, chan, chantype, duration);
2057 local->hw_roc_channel = NULL;
2058 local->hw_roc_cookie = 0;
2064 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2065 struct net_device *dev,
2066 struct ieee80211_channel *chan,
2067 enum nl80211_channel_type channel_type,
2068 unsigned int duration,
2071 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2072 struct ieee80211_local *local = sdata->local;
2074 if (local->ops->remain_on_channel) {
2077 mutex_lock(&local->mtx);
2078 ret = ieee80211_remain_on_channel_hw(local, dev,
2081 local->hw_roc_for_tx = false;
2082 mutex_unlock(&local->mtx);
2087 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
2091 static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
2096 lockdep_assert_held(&local->mtx);
2098 if (local->hw_roc_cookie != cookie)
2101 ret = drv_cancel_remain_on_channel(local);
2105 local->hw_roc_cookie = 0;
2106 local->hw_roc_channel = NULL;
2108 ieee80211_recalc_idle(local);
2113 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
2114 struct net_device *dev,
2117 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2118 struct ieee80211_local *local = sdata->local;
2120 if (local->ops->cancel_remain_on_channel) {
2123 mutex_lock(&local->mtx);
2124 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2125 mutex_unlock(&local->mtx);
2130 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
2133 static enum work_done_result
2134 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
2137 * Use the data embedded in the work struct for reporting
2138 * here so if the driver mangled the SKB before dropping
2139 * it (which is the only way we really should get here)
2140 * then we don't report mangled data.
2142 * If there was no wait time, then by the time we get here
2143 * the driver will likely not have reported the status yet,
2144 * so in that case userspace will have to deal with it.
2147 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
2148 cfg80211_mgmt_tx_status(wk->sdata->dev,
2149 (unsigned long) wk->offchan_tx.frame,
2150 wk->data, wk->data_len, false, GFP_KERNEL);
2152 return WORK_DONE_DESTROY;
2155 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2156 struct ieee80211_channel *chan, bool offchan,
2157 enum nl80211_channel_type channel_type,
2158 bool channel_type_valid, unsigned int wait,
2159 const u8 *buf, size_t len, bool no_cck,
2160 bool dont_wait_for_ack, u64 *cookie)
2162 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2163 struct ieee80211_local *local = sdata->local;
2164 struct sk_buff *skb;
2165 struct sta_info *sta;
2166 struct ieee80211_work *wk;
2167 const struct ieee80211_mgmt *mgmt = (void *)buf;
2169 bool is_offchan = false;
2171 if (dont_wait_for_ack)
2172 flags = IEEE80211_TX_CTL_NO_ACK;
2174 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2175 IEEE80211_TX_CTL_REQ_TX_STATUS;
2177 /* Check that we are on the requested channel for transmission */
2178 if (chan != local->tmp_channel &&
2179 chan != local->oper_channel)
2181 if (channel_type_valid &&
2182 (channel_type != local->tmp_channel_type &&
2183 channel_type != local->_oper_channel_type))
2186 if (chan == local->hw_roc_channel) {
2187 /* TODO: check channel type? */
2189 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2193 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2195 if (is_offchan && !offchan)
2198 switch (sdata->vif.type) {
2199 case NL80211_IFTYPE_ADHOC:
2200 case NL80211_IFTYPE_AP:
2201 case NL80211_IFTYPE_AP_VLAN:
2202 case NL80211_IFTYPE_P2P_GO:
2203 case NL80211_IFTYPE_MESH_POINT:
2204 if (!ieee80211_is_action(mgmt->frame_control) ||
2205 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2208 sta = sta_info_get(sdata, mgmt->da);
2213 case NL80211_IFTYPE_STATION:
2214 case NL80211_IFTYPE_P2P_CLIENT:
2220 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2223 skb_reserve(skb, local->hw.extra_tx_headroom);
2225 memcpy(skb_put(skb, len), buf, len);
2227 IEEE80211_SKB_CB(skb)->flags = flags;
2229 if (flags & IEEE80211_TX_CTL_TX_OFFCHAN)
2230 IEEE80211_SKB_CB(skb)->hw_queue =
2231 local->hw.offchannel_tx_hw_queue;
2233 skb->dev = sdata->dev;
2235 *cookie = (unsigned long) skb;
2237 if (is_offchan && local->ops->remain_on_channel) {
2238 unsigned int duration;
2241 mutex_lock(&local->mtx);
2243 * If the duration is zero, then the driver
2244 * wouldn't actually do anything. Set it to
2247 * TODO: cancel the off-channel operation
2248 * when we get the SKB's TX status and
2249 * the wait time was zero before.
2254 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2259 mutex_unlock(&local->mtx);
2263 local->hw_roc_for_tx = true;
2264 local->hw_roc_duration = wait;
2267 * queue up frame for transmission after
2268 * ieee80211_ready_on_channel call
2271 /* modify cookie to prevent API mismatches */
2273 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2274 IEEE80211_SKB_CB(skb)->hw_queue =
2275 local->hw.offchannel_tx_hw_queue;
2276 local->hw_roc_skb = skb;
2277 local->hw_roc_skb_for_status = skb;
2278 mutex_unlock(&local->mtx);
2284 * Can transmit right away if the channel was the
2285 * right one and there's no wait involved... If a
2286 * wait is involved, we might otherwise not be on
2287 * the right channel for long enough!
2289 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2290 ieee80211_tx_skb(sdata, skb);
2294 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2300 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2302 wk->chan_type = channel_type;
2304 wk->done = ieee80211_offchan_tx_done;
2305 wk->offchan_tx.frame = skb;
2306 wk->offchan_tx.wait = wait;
2308 memcpy(wk->data, buf, len);
2310 ieee80211_add_work(wk);
2314 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2315 struct net_device *dev,
2318 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2319 struct ieee80211_local *local = sdata->local;
2320 struct ieee80211_work *wk;
2323 mutex_lock(&local->mtx);
2325 if (local->ops->cancel_remain_on_channel) {
2327 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2330 kfree_skb(local->hw_roc_skb);
2331 local->hw_roc_skb = NULL;
2332 local->hw_roc_skb_for_status = NULL;
2335 mutex_unlock(&local->mtx);
2340 list_for_each_entry(wk, &local->work_list, list) {
2341 if (wk->sdata != sdata)
2344 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2347 if (cookie != (unsigned long) wk->offchan_tx.frame)
2350 wk->timeout = jiffies;
2352 ieee80211_queue_work(&local->hw, &local->work_work);
2356 mutex_unlock(&local->mtx);
2361 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2362 struct net_device *dev,
2363 u16 frame_type, bool reg)
2365 struct ieee80211_local *local = wiphy_priv(wiphy);
2367 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2371 local->probe_req_reg++;
2373 local->probe_req_reg--;
2375 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2378 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2380 struct ieee80211_local *local = wiphy_priv(wiphy);
2385 return drv_set_antenna(local, tx_ant, rx_ant);
2388 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2390 struct ieee80211_local *local = wiphy_priv(wiphy);
2392 return drv_get_antenna(local, tx_ant, rx_ant);
2395 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2397 struct ieee80211_local *local = wiphy_priv(wiphy);
2399 return drv_set_ringparam(local, tx, rx);
2402 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2403 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2405 struct ieee80211_local *local = wiphy_priv(wiphy);
2407 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2410 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2411 struct net_device *dev,
2412 struct cfg80211_gtk_rekey_data *data)
2414 struct ieee80211_local *local = wiphy_priv(wiphy);
2415 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2417 if (!local->ops->set_rekey_data)
2420 drv_set_rekey_data(local, sdata, data);
2425 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2427 u8 *pos = (void *)skb_put(skb, 7);
2429 *pos++ = WLAN_EID_EXT_CAPABILITY;
2430 *pos++ = 5; /* len */
2435 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2438 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2440 struct ieee80211_local *local = sdata->local;
2444 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2447 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2448 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2449 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2450 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2455 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2456 u8 *peer, u8 *bssid)
2458 struct ieee80211_tdls_lnkie *lnkid;
2460 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2462 lnkid->ie_type = WLAN_EID_LINK_ID;
2463 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2465 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2466 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2467 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2471 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2472 u8 *peer, u8 action_code, u8 dialog_token,
2473 u16 status_code, struct sk_buff *skb)
2475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2476 struct ieee80211_tdls_data *tf;
2478 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2480 memcpy(tf->da, peer, ETH_ALEN);
2481 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2482 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2483 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2485 switch (action_code) {
2486 case WLAN_TDLS_SETUP_REQUEST:
2487 tf->category = WLAN_CATEGORY_TDLS;
2488 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2490 skb_put(skb, sizeof(tf->u.setup_req));
2491 tf->u.setup_req.dialog_token = dialog_token;
2492 tf->u.setup_req.capability =
2493 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2495 ieee80211_add_srates_ie(&sdata->vif, skb, false);
2496 ieee80211_add_ext_srates_ie(&sdata->vif, skb, false);
2497 ieee80211_tdls_add_ext_capab(skb);
2499 case WLAN_TDLS_SETUP_RESPONSE:
2500 tf->category = WLAN_CATEGORY_TDLS;
2501 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2503 skb_put(skb, sizeof(tf->u.setup_resp));
2504 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2505 tf->u.setup_resp.dialog_token = dialog_token;
2506 tf->u.setup_resp.capability =
2507 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2509 ieee80211_add_srates_ie(&sdata->vif, skb, false);
2510 ieee80211_add_ext_srates_ie(&sdata->vif, skb, false);
2511 ieee80211_tdls_add_ext_capab(skb);
2513 case WLAN_TDLS_SETUP_CONFIRM:
2514 tf->category = WLAN_CATEGORY_TDLS;
2515 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2517 skb_put(skb, sizeof(tf->u.setup_cfm));
2518 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2519 tf->u.setup_cfm.dialog_token = dialog_token;
2521 case WLAN_TDLS_TEARDOWN:
2522 tf->category = WLAN_CATEGORY_TDLS;
2523 tf->action_code = WLAN_TDLS_TEARDOWN;
2525 skb_put(skb, sizeof(tf->u.teardown));
2526 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2528 case WLAN_TDLS_DISCOVERY_REQUEST:
2529 tf->category = WLAN_CATEGORY_TDLS;
2530 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2532 skb_put(skb, sizeof(tf->u.discover_req));
2533 tf->u.discover_req.dialog_token = dialog_token;
2543 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2544 u8 *peer, u8 action_code, u8 dialog_token,
2545 u16 status_code, struct sk_buff *skb)
2547 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2548 struct ieee80211_mgmt *mgmt;
2550 mgmt = (void *)skb_put(skb, 24);
2551 memset(mgmt, 0, 24);
2552 memcpy(mgmt->da, peer, ETH_ALEN);
2553 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2554 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2556 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2557 IEEE80211_STYPE_ACTION);
2559 switch (action_code) {
2560 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2561 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2562 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2563 mgmt->u.action.u.tdls_discover_resp.action_code =
2564 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2565 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2567 mgmt->u.action.u.tdls_discover_resp.capability =
2568 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2570 ieee80211_add_srates_ie(&sdata->vif, skb, false);
2571 ieee80211_add_ext_srates_ie(&sdata->vif, skb, false);
2572 ieee80211_tdls_add_ext_capab(skb);
2581 static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2582 u8 *peer, u8 action_code, u8 dialog_token,
2583 u16 status_code, const u8 *extra_ies,
2584 size_t extra_ies_len)
2586 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2587 struct ieee80211_local *local = sdata->local;
2588 struct ieee80211_tx_info *info;
2589 struct sk_buff *skb = NULL;
2593 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2596 /* make sure we are in managed mode, and associated */
2597 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2598 !sdata->u.mgd.associated)
2601 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2602 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2605 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2606 max(sizeof(struct ieee80211_mgmt),
2607 sizeof(struct ieee80211_tdls_data)) +
2608 50 + /* supported rates */
2611 sizeof(struct ieee80211_tdls_lnkie));
2615 info = IEEE80211_SKB_CB(skb);
2616 skb_reserve(skb, local->hw.extra_tx_headroom);
2618 switch (action_code) {
2619 case WLAN_TDLS_SETUP_REQUEST:
2620 case WLAN_TDLS_SETUP_RESPONSE:
2621 case WLAN_TDLS_SETUP_CONFIRM:
2622 case WLAN_TDLS_TEARDOWN:
2623 case WLAN_TDLS_DISCOVERY_REQUEST:
2624 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2625 action_code, dialog_token,
2627 send_direct = false;
2629 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2630 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2631 dialog_token, status_code,
2644 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2646 /* the TDLS link IE is always added last */
2647 switch (action_code) {
2648 case WLAN_TDLS_SETUP_REQUEST:
2649 case WLAN_TDLS_SETUP_CONFIRM:
2650 case WLAN_TDLS_TEARDOWN:
2651 case WLAN_TDLS_DISCOVERY_REQUEST:
2652 /* we are the initiator */
2653 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2654 sdata->u.mgd.bssid);
2656 case WLAN_TDLS_SETUP_RESPONSE:
2657 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2658 /* we are the responder */
2659 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2660 sdata->u.mgd.bssid);
2668 ieee80211_tx_skb(sdata, skb);
2673 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2674 * we should default to AC_VI.
2676 switch (action_code) {
2677 case WLAN_TDLS_SETUP_REQUEST:
2678 case WLAN_TDLS_SETUP_RESPONSE:
2679 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2683 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2688 /* disable bottom halves when entering the Tx path */
2690 ret = ieee80211_subif_start_xmit(skb, dev);
2700 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2701 u8 *peer, enum nl80211_tdls_operation oper)
2703 struct sta_info *sta;
2704 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2706 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2709 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2712 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2713 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2717 case NL80211_TDLS_ENABLE_LINK:
2719 sta = sta_info_get(sdata, peer);
2725 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
2728 case NL80211_TDLS_DISABLE_LINK:
2729 return sta_info_destroy_addr(sdata, peer);
2730 case NL80211_TDLS_TEARDOWN:
2731 case NL80211_TDLS_SETUP:
2732 case NL80211_TDLS_DISCOVERY_REQ:
2733 /* We don't support in-driver setup/teardown/discovery */
2742 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2743 const u8 *peer, u64 *cookie)
2745 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2746 struct ieee80211_local *local = sdata->local;
2747 struct ieee80211_qos_hdr *nullfunc;
2748 struct sk_buff *skb;
2749 int size = sizeof(*nullfunc);
2752 struct ieee80211_tx_info *info;
2753 struct sta_info *sta;
2756 sta = sta_info_get(sdata, peer);
2758 qos = test_sta_flag(sta, WLAN_STA_WME);
2766 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2767 IEEE80211_STYPE_QOS_NULLFUNC |
2768 IEEE80211_FCTL_FROMDS);
2771 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2772 IEEE80211_STYPE_NULLFUNC |
2773 IEEE80211_FCTL_FROMDS);
2776 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2782 skb_reserve(skb, local->hw.extra_tx_headroom);
2784 nullfunc = (void *) skb_put(skb, size);
2785 nullfunc->frame_control = fc;
2786 nullfunc->duration_id = 0;
2787 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2788 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2789 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2790 nullfunc->seq_ctrl = 0;
2792 info = IEEE80211_SKB_CB(skb);
2794 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2795 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2797 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2800 nullfunc->qos_ctrl = cpu_to_le16(7);
2803 ieee80211_xmit(sdata, skb);
2806 *cookie = (unsigned long) skb;
2810 static struct ieee80211_channel *
2811 ieee80211_wiphy_get_channel(struct wiphy *wiphy,
2812 enum nl80211_channel_type *type)
2814 struct ieee80211_local *local = wiphy_priv(wiphy);
2816 *type = local->_oper_channel_type;
2817 return local->oper_channel;
2821 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
2823 drv_set_wakeup(wiphy_priv(wiphy), enabled);
2827 struct cfg80211_ops mac80211_config_ops = {
2828 .add_virtual_intf = ieee80211_add_iface,
2829 .del_virtual_intf = ieee80211_del_iface,
2830 .change_virtual_intf = ieee80211_change_iface,
2831 .add_key = ieee80211_add_key,
2832 .del_key = ieee80211_del_key,
2833 .get_key = ieee80211_get_key,
2834 .set_default_key = ieee80211_config_default_key,
2835 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
2836 .start_ap = ieee80211_start_ap,
2837 .change_beacon = ieee80211_change_beacon,
2838 .stop_ap = ieee80211_stop_ap,
2839 .add_station = ieee80211_add_station,
2840 .del_station = ieee80211_del_station,
2841 .change_station = ieee80211_change_station,
2842 .get_station = ieee80211_get_station,
2843 .dump_station = ieee80211_dump_station,
2844 .dump_survey = ieee80211_dump_survey,
2845 #ifdef CONFIG_MAC80211_MESH
2846 .add_mpath = ieee80211_add_mpath,
2847 .del_mpath = ieee80211_del_mpath,
2848 .change_mpath = ieee80211_change_mpath,
2849 .get_mpath = ieee80211_get_mpath,
2850 .dump_mpath = ieee80211_dump_mpath,
2851 .update_mesh_config = ieee80211_update_mesh_config,
2852 .get_mesh_config = ieee80211_get_mesh_config,
2853 .join_mesh = ieee80211_join_mesh,
2854 .leave_mesh = ieee80211_leave_mesh,
2856 .change_bss = ieee80211_change_bss,
2857 .set_txq_params = ieee80211_set_txq_params,
2858 .set_channel = ieee80211_set_channel,
2859 .suspend = ieee80211_suspend,
2860 .resume = ieee80211_resume,
2861 .scan = ieee80211_scan,
2862 .sched_scan_start = ieee80211_sched_scan_start,
2863 .sched_scan_stop = ieee80211_sched_scan_stop,
2864 .auth = ieee80211_auth,
2865 .assoc = ieee80211_assoc,
2866 .deauth = ieee80211_deauth,
2867 .disassoc = ieee80211_disassoc,
2868 .join_ibss = ieee80211_join_ibss,
2869 .leave_ibss = ieee80211_leave_ibss,
2870 .set_wiphy_params = ieee80211_set_wiphy_params,
2871 .set_tx_power = ieee80211_set_tx_power,
2872 .get_tx_power = ieee80211_get_tx_power,
2873 .set_wds_peer = ieee80211_set_wds_peer,
2874 .rfkill_poll = ieee80211_rfkill_poll,
2875 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
2876 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
2877 .set_power_mgmt = ieee80211_set_power_mgmt,
2878 .set_bitrate_mask = ieee80211_set_bitrate_mask,
2879 .remain_on_channel = ieee80211_remain_on_channel,
2880 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2881 .mgmt_tx = ieee80211_mgmt_tx,
2882 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
2883 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
2884 .mgmt_frame_register = ieee80211_mgmt_frame_register,
2885 .set_antenna = ieee80211_set_antenna,
2886 .get_antenna = ieee80211_get_antenna,
2887 .set_ringparam = ieee80211_set_ringparam,
2888 .get_ringparam = ieee80211_get_ringparam,
2889 .set_rekey_data = ieee80211_set_rekey_data,
2890 .tdls_oper = ieee80211_tdls_oper,
2891 .tdls_mgmt = ieee80211_tdls_mgmt,
2892 .probe_client = ieee80211_probe_client,
2893 .get_channel = ieee80211_wiphy_get_channel,
2894 .set_noack_map = ieee80211_set_noack_map,
2896 .set_wakeup = ieee80211_set_wakeup,
2898 .get_et_sset_count = ieee80211_get_et_sset_count,
2899 .get_et_stats = ieee80211_get_et_stats,
2900 .get_et_strings = ieee80211_get_et_strings,