Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 TDLS handling code |
| 3 | * |
| 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Copyright 2014, Intel Corporation |
Johannes Berg | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame] | 6 | * Copyright 2014 Intel Mobile Communications GmbH |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 7 | * Copyright 2015 - 2016 Intel Deutschland GmbH |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 8 | * |
| 9 | * This file is GPLv2 as found in COPYING. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/ieee80211.h> |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 13 | #include <linux/log2.h> |
Arik Nemtsov | c887f0d3 | 2014-06-11 17:18:25 +0300 | [diff] [blame] | 14 | #include <net/cfg80211.h> |
Arik Nemtsov | c8ff71e | 2015-07-08 15:41:45 +0300 | [diff] [blame] | 15 | #include <linux/rtnetlink.h> |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 16 | #include "ieee80211_i.h" |
Arik Nemtsov | ee10f2c | 2014-06-11 17:18:27 +0300 | [diff] [blame] | 17 | #include "driver-ops.h" |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 18 | #include "rate.h" |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 19 | |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 20 | /* give usermode some time for retries in setting up the TDLS session */ |
| 21 | #define TDLS_PEER_SETUP_TIMEOUT (15 * HZ) |
| 22 | |
| 23 | void ieee80211_tdls_peer_del_work(struct work_struct *wk) |
| 24 | { |
| 25 | struct ieee80211_sub_if_data *sdata; |
| 26 | struct ieee80211_local *local; |
| 27 | |
| 28 | sdata = container_of(wk, struct ieee80211_sub_if_data, |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 29 | u.mgd.tdls_peer_del_work.work); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 30 | local = sdata->local; |
| 31 | |
| 32 | mutex_lock(&local->mtx); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 33 | if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer)) { |
| 34 | tdls_dbg(sdata, "TDLS del peer %pM\n", sdata->u.mgd.tdls_peer); |
| 35 | sta_info_destroy_addr(sdata, sdata->u.mgd.tdls_peer); |
| 36 | eth_zero_addr(sdata->u.mgd.tdls_peer); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 37 | } |
| 38 | mutex_unlock(&local->mtx); |
| 39 | } |
| 40 | |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 41 | static void ieee80211_tdls_add_ext_capab(struct ieee80211_sub_if_data *sdata, |
Arik Nemtsov | 78632a1 | 2014-11-09 18:50:14 +0200 | [diff] [blame] | 42 | struct sk_buff *skb) |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 43 | { |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 44 | struct ieee80211_local *local = sdata->local; |
Arik Nemtsov | 82c0cc90d | 2015-08-15 22:39:46 +0300 | [diff] [blame] | 45 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Arik Nemtsov | 78632a1 | 2014-11-09 18:50:14 +0200 | [diff] [blame] | 46 | bool chan_switch = local->hw.wiphy->features & |
| 47 | NL80211_FEATURE_TDLS_CHANNEL_SWITCH; |
Arik Nemtsov | 82c0cc90d | 2015-08-15 22:39:46 +0300 | [diff] [blame] | 48 | bool wider_band = ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) && |
| 49 | !ifmgd->tdls_wider_bw_prohibited; |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 50 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
| 51 | struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; |
| 52 | bool vht = sband && sband->vht_cap.vht_supported; |
| 53 | u8 *pos = (void *)skb_put(skb, 10); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 54 | |
| 55 | *pos++ = WLAN_EID_EXT_CAPABILITY; |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 56 | *pos++ = 8; /* len */ |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 57 | *pos++ = 0x0; |
| 58 | *pos++ = 0x0; |
| 59 | *pos++ = 0x0; |
Arik Nemtsov | 78632a1 | 2014-11-09 18:50:14 +0200 | [diff] [blame] | 60 | *pos++ = chan_switch ? WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH : 0; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 61 | *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED; |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 62 | *pos++ = 0; |
| 63 | *pos++ = 0; |
| 64 | *pos++ = (vht && wider_band) ? WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED : 0; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 65 | } |
| 66 | |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 67 | static u8 |
| 68 | ieee80211_tdls_add_subband(struct ieee80211_sub_if_data *sdata, |
| 69 | struct sk_buff *skb, u16 start, u16 end, |
| 70 | u16 spacing) |
| 71 | { |
| 72 | u8 subband_cnt = 0, ch_cnt = 0; |
| 73 | struct ieee80211_channel *ch; |
| 74 | struct cfg80211_chan_def chandef; |
| 75 | int i, subband_start; |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 76 | struct wiphy *wiphy = sdata->local->hw.wiphy; |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 77 | |
| 78 | for (i = start; i <= end; i += spacing) { |
| 79 | if (!ch_cnt) |
| 80 | subband_start = i; |
| 81 | |
| 82 | ch = ieee80211_get_channel(sdata->local->hw.wiphy, i); |
| 83 | if (ch) { |
| 84 | /* we will be active on the channel */ |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 85 | cfg80211_chandef_create(&chandef, ch, |
Arik Nemtsov | 5007589 | 2015-01-07 16:45:07 +0200 | [diff] [blame] | 86 | NL80211_CHAN_NO_HT); |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 87 | if (cfg80211_reg_can_beacon_relax(wiphy, &chandef, |
| 88 | sdata->wdev.iftype)) { |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 89 | ch_cnt++; |
Arik Nemtsov | 5007589 | 2015-01-07 16:45:07 +0200 | [diff] [blame] | 90 | /* |
| 91 | * check if the next channel is also part of |
| 92 | * this allowed range |
| 93 | */ |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 94 | continue; |
| 95 | } |
| 96 | } |
| 97 | |
Arik Nemtsov | 5007589 | 2015-01-07 16:45:07 +0200 | [diff] [blame] | 98 | /* |
| 99 | * we've reached the end of a range, with allowed channels |
| 100 | * found |
| 101 | */ |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 102 | if (ch_cnt) { |
| 103 | u8 *pos = skb_put(skb, 2); |
| 104 | *pos++ = ieee80211_frequency_to_channel(subband_start); |
| 105 | *pos++ = ch_cnt; |
| 106 | |
| 107 | subband_cnt++; |
| 108 | ch_cnt = 0; |
| 109 | } |
| 110 | } |
| 111 | |
Arik Nemtsov | 5007589 | 2015-01-07 16:45:07 +0200 | [diff] [blame] | 112 | /* all channels in the requested range are allowed - add them here */ |
| 113 | if (ch_cnt) { |
| 114 | u8 *pos = skb_put(skb, 2); |
| 115 | *pos++ = ieee80211_frequency_to_channel(subband_start); |
| 116 | *pos++ = ch_cnt; |
| 117 | |
| 118 | subband_cnt++; |
| 119 | } |
| 120 | |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 121 | return subband_cnt; |
| 122 | } |
| 123 | |
| 124 | static void |
| 125 | ieee80211_tdls_add_supp_channels(struct ieee80211_sub_if_data *sdata, |
| 126 | struct sk_buff *skb) |
| 127 | { |
| 128 | /* |
| 129 | * Add possible channels for TDLS. These are channels that are allowed |
| 130 | * to be active. |
| 131 | */ |
| 132 | u8 subband_cnt; |
| 133 | u8 *pos = skb_put(skb, 2); |
| 134 | |
| 135 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 136 | |
| 137 | /* |
| 138 | * 5GHz and 2GHz channels numbers can overlap. Ignore this for now, as |
| 139 | * this doesn't happen in real world scenarios. |
| 140 | */ |
| 141 | |
| 142 | /* 2GHz, with 5MHz spacing */ |
| 143 | subband_cnt = ieee80211_tdls_add_subband(sdata, skb, 2412, 2472, 5); |
| 144 | |
| 145 | /* 5GHz, with 20MHz spacing */ |
| 146 | subband_cnt += ieee80211_tdls_add_subband(sdata, skb, 5000, 5825, 20); |
| 147 | |
| 148 | /* length */ |
| 149 | *pos = 2 * subband_cnt; |
| 150 | } |
| 151 | |
Arik Nemtsov | a38700d | 2015-03-18 08:46:08 +0200 | [diff] [blame] | 152 | static void ieee80211_tdls_add_oper_classes(struct ieee80211_sub_if_data *sdata, |
| 153 | struct sk_buff *skb) |
| 154 | { |
| 155 | u8 *pos; |
| 156 | u8 op_class; |
| 157 | |
| 158 | if (!ieee80211_chandef_to_operating_class(&sdata->vif.bss_conf.chandef, |
| 159 | &op_class)) |
| 160 | return; |
| 161 | |
| 162 | pos = skb_put(skb, 4); |
| 163 | *pos++ = WLAN_EID_SUPPORTED_REGULATORY_CLASSES; |
| 164 | *pos++ = 2; /* len */ |
| 165 | |
| 166 | *pos++ = op_class; |
| 167 | *pos++ = op_class; /* give current operating class as alternate too */ |
| 168 | } |
| 169 | |
Arik Nemtsov | 2cedd87 | 2014-11-09 18:50:13 +0200 | [diff] [blame] | 170 | static void ieee80211_tdls_add_bss_coex_ie(struct sk_buff *skb) |
| 171 | { |
| 172 | u8 *pos = (void *)skb_put(skb, 3); |
| 173 | |
| 174 | *pos++ = WLAN_EID_BSS_COEX_2040; |
| 175 | *pos++ = 1; /* len */ |
| 176 | |
| 177 | *pos++ = WLAN_BSS_COEX_INFORMATION_REQUEST; |
| 178 | } |
| 179 | |
Arik Nemtsov | dd8c0b0 | 2014-07-17 17:14:22 +0300 | [diff] [blame] | 180 | static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata, |
| 181 | u16 status_code) |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 182 | { |
Arik Nemtsov | dd8c0b0 | 2014-07-17 17:14:22 +0300 | [diff] [blame] | 183 | /* The capability will be 0 when sending a failure code */ |
| 184 | if (status_code != 0) |
| 185 | return 0; |
| 186 | |
Johannes Berg | ea1b2b45 | 2015-06-02 20:15:49 +0200 | [diff] [blame] | 187 | if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_2GHZ) { |
| 188 | return WLAN_CAPABILITY_SHORT_SLOT_TIME | |
| 189 | WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 190 | } |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 191 | |
Johannes Berg | ea1b2b45 | 2015-06-02 20:15:49 +0200 | [diff] [blame] | 192 | return 0; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 193 | } |
| 194 | |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 195 | static void ieee80211_tdls_add_link_ie(struct ieee80211_sub_if_data *sdata, |
| 196 | struct sk_buff *skb, const u8 *peer, |
| 197 | bool initiator) |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 198 | { |
| 199 | struct ieee80211_tdls_lnkie *lnkid; |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 200 | const u8 *init_addr, *rsp_addr; |
| 201 | |
| 202 | if (initiator) { |
| 203 | init_addr = sdata->vif.addr; |
| 204 | rsp_addr = peer; |
| 205 | } else { |
| 206 | init_addr = peer; |
| 207 | rsp_addr = sdata->vif.addr; |
| 208 | } |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 209 | |
| 210 | lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie)); |
| 211 | |
| 212 | lnkid->ie_type = WLAN_EID_LINK_ID; |
| 213 | lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2; |
| 214 | |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 215 | memcpy(lnkid->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
| 216 | memcpy(lnkid->init_sta, init_addr, ETH_ALEN); |
| 217 | memcpy(lnkid->resp_sta, rsp_addr, ETH_ALEN); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 218 | } |
| 219 | |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 220 | static void |
| 221 | ieee80211_tdls_add_aid(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) |
| 222 | { |
| 223 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 224 | u8 *pos = (void *)skb_put(skb, 4); |
| 225 | |
| 226 | *pos++ = WLAN_EID_AID; |
| 227 | *pos++ = 2; /* len */ |
| 228 | put_unaligned_le16(ifmgd->aid, pos); |
| 229 | } |
| 230 | |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 231 | /* translate numbering in the WMM parameter IE to the mac80211 notation */ |
| 232 | static enum ieee80211_ac_numbers ieee80211_ac_from_wmm(int ac) |
| 233 | { |
| 234 | switch (ac) { |
| 235 | default: |
| 236 | WARN_ON_ONCE(1); |
| 237 | case 0: |
| 238 | return IEEE80211_AC_BE; |
| 239 | case 1: |
| 240 | return IEEE80211_AC_BK; |
| 241 | case 2: |
| 242 | return IEEE80211_AC_VI; |
| 243 | case 3: |
| 244 | return IEEE80211_AC_VO; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | static u8 ieee80211_wmm_aci_aifsn(int aifsn, bool acm, int aci) |
| 249 | { |
| 250 | u8 ret; |
| 251 | |
| 252 | ret = aifsn & 0x0f; |
| 253 | if (acm) |
| 254 | ret |= 0x10; |
| 255 | ret |= (aci << 5) & 0x60; |
| 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | static u8 ieee80211_wmm_ecw(u16 cw_min, u16 cw_max) |
| 260 | { |
| 261 | return ((ilog2(cw_min + 1) << 0x0) & 0x0f) | |
| 262 | ((ilog2(cw_max + 1) << 0x4) & 0xf0); |
| 263 | } |
| 264 | |
| 265 | static void ieee80211_tdls_add_wmm_param_ie(struct ieee80211_sub_if_data *sdata, |
| 266 | struct sk_buff *skb) |
| 267 | { |
| 268 | struct ieee80211_wmm_param_ie *wmm; |
| 269 | struct ieee80211_tx_queue_params *txq; |
| 270 | int i; |
| 271 | |
| 272 | wmm = (void *)skb_put(skb, sizeof(*wmm)); |
| 273 | memset(wmm, 0, sizeof(*wmm)); |
| 274 | |
| 275 | wmm->element_id = WLAN_EID_VENDOR_SPECIFIC; |
| 276 | wmm->len = sizeof(*wmm) - 2; |
| 277 | |
| 278 | wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 279 | wmm->oui[1] = 0x50; |
| 280 | wmm->oui[2] = 0xf2; |
| 281 | wmm->oui_type = 2; /* WME */ |
| 282 | wmm->oui_subtype = 1; /* WME param */ |
| 283 | wmm->version = 1; /* WME ver */ |
| 284 | wmm->qos_info = 0; /* U-APSD not in use */ |
| 285 | |
| 286 | /* |
| 287 | * Use the EDCA parameters defined for the BSS, or default if the AP |
| 288 | * doesn't support it, as mandated by 802.11-2012 section 10.22.4 |
| 289 | */ |
| 290 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
| 291 | txq = &sdata->tx_conf[ieee80211_ac_from_wmm(i)]; |
| 292 | wmm->ac[i].aci_aifsn = ieee80211_wmm_aci_aifsn(txq->aifs, |
| 293 | txq->acm, i); |
| 294 | wmm->ac[i].cw = ieee80211_wmm_ecw(txq->cw_min, txq->cw_max); |
| 295 | wmm->ac[i].txop_limit = cpu_to_le16(txq->txop); |
| 296 | } |
| 297 | } |
| 298 | |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 299 | static void |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 300 | ieee80211_tdls_chandef_vht_upgrade(struct ieee80211_sub_if_data *sdata, |
| 301 | struct sta_info *sta) |
| 302 | { |
| 303 | /* IEEE802.11ac-2013 Table E-4 */ |
| 304 | u16 centers_80mhz[] = { 5210, 5290, 5530, 5610, 5690, 5775 }; |
| 305 | struct cfg80211_chan_def uc = sta->tdls_chandef; |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 306 | enum nl80211_chan_width max_width = ieee80211_sta_cap_chan_bw(sta); |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 307 | int i; |
| 308 | |
| 309 | /* only support upgrading non-narrow channels up to 80Mhz */ |
| 310 | if (max_width == NL80211_CHAN_WIDTH_5 || |
| 311 | max_width == NL80211_CHAN_WIDTH_10) |
| 312 | return; |
| 313 | |
| 314 | if (max_width > NL80211_CHAN_WIDTH_80) |
| 315 | max_width = NL80211_CHAN_WIDTH_80; |
| 316 | |
| 317 | if (uc.width == max_width) |
| 318 | return; |
| 319 | /* |
| 320 | * Channel usage constrains in the IEEE802.11ac-2013 specification only |
| 321 | * allow expanding a 20MHz channel to 80MHz in a single way. In |
| 322 | * addition, there are no 40MHz allowed channels that are not part of |
| 323 | * the allowed 80MHz range in the 5GHz spectrum (the relevant one here). |
| 324 | */ |
| 325 | for (i = 0; i < ARRAY_SIZE(centers_80mhz); i++) |
| 326 | if (abs(uc.chan->center_freq - centers_80mhz[i]) <= 30) { |
| 327 | uc.center_freq1 = centers_80mhz[i]; |
| 328 | uc.width = NL80211_CHAN_WIDTH_80; |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | if (!uc.center_freq1) |
| 333 | return; |
| 334 | |
| 335 | /* proceed to downgrade the chandef until usable or the same */ |
Arik Nemtsov | db8d997 | 2016-03-02 23:28:31 +0200 | [diff] [blame] | 336 | while (uc.width > max_width || |
Arik Nemtsov | dd55ab5 | 2015-08-15 22:39:48 +0300 | [diff] [blame] | 337 | !cfg80211_reg_can_beacon_relax(sdata->local->hw.wiphy, &uc, |
| 338 | sdata->wdev.iftype)) |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 339 | ieee80211_chandef_downgrade(&uc); |
| 340 | |
| 341 | if (!cfg80211_chandef_identical(&uc, &sta->tdls_chandef)) { |
| 342 | tdls_dbg(sdata, "TDLS ch width upgraded %d -> %d\n", |
| 343 | sta->tdls_chandef.width, uc.width); |
| 344 | |
| 345 | /* |
| 346 | * the station is not yet authorized when BW upgrade is done, |
| 347 | * locking is not required |
| 348 | */ |
| 349 | sta->tdls_chandef = uc; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | static void |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 354 | ieee80211_tdls_add_setup_start_ies(struct ieee80211_sub_if_data *sdata, |
| 355 | struct sk_buff *skb, const u8 *peer, |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 356 | u8 action_code, bool initiator, |
| 357 | const u8 *extra_ies, size_t extra_ies_len) |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 358 | { |
| 359 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
Arik Nemtsov | 40b861a | 2014-07-17 17:14:23 +0300 | [diff] [blame] | 360 | struct ieee80211_local *local = sdata->local; |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 361 | struct ieee80211_supported_band *sband; |
| 362 | struct ieee80211_sta_ht_cap ht_cap; |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 363 | struct ieee80211_sta_vht_cap vht_cap; |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 364 | struct sta_info *sta = NULL; |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 365 | size_t offset = 0, noffset; |
| 366 | u8 *pos; |
| 367 | |
| 368 | ieee80211_add_srates_ie(sdata, skb, false, band); |
| 369 | ieee80211_add_ext_srates_ie(sdata, skb, false, band); |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 370 | ieee80211_tdls_add_supp_channels(sdata, skb); |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 371 | |
| 372 | /* add any custom IEs that go before Extended Capabilities */ |
| 373 | if (extra_ies_len) { |
| 374 | static const u8 before_ext_cap[] = { |
| 375 | WLAN_EID_SUPP_RATES, |
| 376 | WLAN_EID_COUNTRY, |
| 377 | WLAN_EID_EXT_SUPP_RATES, |
| 378 | WLAN_EID_SUPPORTED_CHANNELS, |
| 379 | WLAN_EID_RSN, |
| 380 | }; |
| 381 | noffset = ieee80211_ie_split(extra_ies, extra_ies_len, |
| 382 | before_ext_cap, |
| 383 | ARRAY_SIZE(before_ext_cap), |
| 384 | offset); |
| 385 | pos = skb_put(skb, noffset - offset); |
| 386 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 387 | offset = noffset; |
| 388 | } |
| 389 | |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 390 | ieee80211_tdls_add_ext_capab(sdata, skb); |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 391 | |
Arik Nemtsov | 40b861a | 2014-07-17 17:14:23 +0300 | [diff] [blame] | 392 | /* add the QoS element if we support it */ |
| 393 | if (local->hw.queues >= IEEE80211_NUM_ACS && |
| 394 | action_code != WLAN_PUB_ACTION_TDLS_DISCOVER_RES) |
| 395 | ieee80211_add_wmm_info_ie(skb_put(skb, 9), 0); /* no U-APSD */ |
| 396 | |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 397 | /* add any custom IEs that go before HT capabilities */ |
| 398 | if (extra_ies_len) { |
| 399 | static const u8 before_ht_cap[] = { |
| 400 | WLAN_EID_SUPP_RATES, |
| 401 | WLAN_EID_COUNTRY, |
| 402 | WLAN_EID_EXT_SUPP_RATES, |
| 403 | WLAN_EID_SUPPORTED_CHANNELS, |
| 404 | WLAN_EID_RSN, |
| 405 | WLAN_EID_EXT_CAPABILITY, |
| 406 | WLAN_EID_QOS_CAPA, |
| 407 | WLAN_EID_FAST_BSS_TRANSITION, |
| 408 | WLAN_EID_TIMEOUT_INTERVAL, |
| 409 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 410 | }; |
| 411 | noffset = ieee80211_ie_split(extra_ies, extra_ies_len, |
| 412 | before_ht_cap, |
| 413 | ARRAY_SIZE(before_ht_cap), |
| 414 | offset); |
| 415 | pos = skb_put(skb, noffset - offset); |
| 416 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 417 | offset = noffset; |
| 418 | } |
| 419 | |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 420 | mutex_lock(&local->sta_mtx); |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 421 | |
| 422 | /* we should have the peer STA if we're already responding */ |
| 423 | if (action_code == WLAN_TDLS_SETUP_RESPONSE) { |
| 424 | sta = sta_info_get(sdata, peer); |
| 425 | if (WARN_ON_ONCE(!sta)) { |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 426 | mutex_unlock(&local->sta_mtx); |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 427 | return; |
| 428 | } |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 429 | |
| 430 | sta->tdls_chandef = sdata->vif.bss_conf.chandef; |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 431 | } |
| 432 | |
Arik Nemtsov | a38700d | 2015-03-18 08:46:08 +0200 | [diff] [blame] | 433 | ieee80211_tdls_add_oper_classes(sdata, skb); |
| 434 | |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 435 | /* |
| 436 | * with TDLS we can switch channels, and HT-caps are not necessarily |
| 437 | * the same on all bands. The specification limits the setup to a |
| 438 | * single HT-cap, so use the current band for now. |
| 439 | */ |
| 440 | sband = local->hw.wiphy->bands[band]; |
| 441 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 442 | |
Arik Nemtsov | 070e176 | 2015-03-30 11:16:23 +0300 | [diff] [blame] | 443 | if ((action_code == WLAN_TDLS_SETUP_REQUEST || |
| 444 | action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) && |
| 445 | ht_cap.ht_supported) { |
Johannes Berg | c5309ba | 2015-01-23 11:42:14 +0100 | [diff] [blame] | 446 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 447 | |
Johannes Berg | c5309ba | 2015-01-23 11:42:14 +0100 | [diff] [blame] | 448 | /* disable SMPS in TDLS initiator */ |
| 449 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_DISABLED |
| 450 | << IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 451 | |
| 452 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 453 | ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap); |
| 454 | } else if (action_code == WLAN_TDLS_SETUP_RESPONSE && |
| 455 | ht_cap.ht_supported && sta->sta.ht_cap.ht_supported) { |
Johannes Berg | c5309ba | 2015-01-23 11:42:14 +0100 | [diff] [blame] | 456 | /* the peer caps are already intersected with our own */ |
| 457 | memcpy(&ht_cap, &sta->sta.ht_cap, sizeof(ht_cap)); |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 458 | |
| 459 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 460 | ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap); |
| 461 | } |
| 462 | |
Arik Nemtsov | 2cedd87 | 2014-11-09 18:50:13 +0200 | [diff] [blame] | 463 | if (ht_cap.ht_supported && |
| 464 | (ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 465 | ieee80211_tdls_add_bss_coex_ie(skb); |
| 466 | |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 467 | ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator); |
| 468 | |
| 469 | /* add any custom IEs that go before VHT capabilities */ |
| 470 | if (extra_ies_len) { |
| 471 | static const u8 before_vht_cap[] = { |
| 472 | WLAN_EID_SUPP_RATES, |
| 473 | WLAN_EID_COUNTRY, |
| 474 | WLAN_EID_EXT_SUPP_RATES, |
| 475 | WLAN_EID_SUPPORTED_CHANNELS, |
| 476 | WLAN_EID_RSN, |
| 477 | WLAN_EID_EXT_CAPABILITY, |
| 478 | WLAN_EID_QOS_CAPA, |
| 479 | WLAN_EID_FAST_BSS_TRANSITION, |
| 480 | WLAN_EID_TIMEOUT_INTERVAL, |
| 481 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 482 | WLAN_EID_MULTI_BAND, |
| 483 | }; |
| 484 | noffset = ieee80211_ie_split(extra_ies, extra_ies_len, |
| 485 | before_vht_cap, |
| 486 | ARRAY_SIZE(before_vht_cap), |
| 487 | offset); |
| 488 | pos = skb_put(skb, noffset - offset); |
| 489 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 490 | offset = noffset; |
| 491 | } |
| 492 | |
| 493 | /* build the VHT-cap similarly to the HT-cap */ |
| 494 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
Arik Nemtsov | 070e176 | 2015-03-30 11:16:23 +0300 | [diff] [blame] | 495 | if ((action_code == WLAN_TDLS_SETUP_REQUEST || |
| 496 | action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) && |
| 497 | vht_cap.vht_supported) { |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 498 | ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); |
| 499 | |
| 500 | /* the AID is present only when VHT is implemented */ |
Arik Nemtsov | 070e176 | 2015-03-30 11:16:23 +0300 | [diff] [blame] | 501 | if (action_code == WLAN_TDLS_SETUP_REQUEST) |
| 502 | ieee80211_tdls_add_aid(sdata, skb); |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 503 | |
| 504 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
| 505 | ieee80211_ie_build_vht_cap(pos, &vht_cap, vht_cap.cap); |
| 506 | } else if (action_code == WLAN_TDLS_SETUP_RESPONSE && |
| 507 | vht_cap.vht_supported && sta->sta.vht_cap.vht_supported) { |
| 508 | /* the peer caps are already intersected with our own */ |
| 509 | memcpy(&vht_cap, &sta->sta.vht_cap, sizeof(vht_cap)); |
| 510 | |
| 511 | /* the AID is present only when VHT is implemented */ |
| 512 | ieee80211_tdls_add_aid(sdata, skb); |
| 513 | |
| 514 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
| 515 | ieee80211_ie_build_vht_cap(pos, &vht_cap, vht_cap.cap); |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 516 | |
| 517 | /* |
| 518 | * if both peers support WIDER_BW, we can expand the chandef to |
| 519 | * a wider compatible one, up to 80MHz |
| 520 | */ |
| 521 | if (test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW)) |
| 522 | ieee80211_tdls_chandef_vht_upgrade(sdata, sta); |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 525 | mutex_unlock(&local->sta_mtx); |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 526 | |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 527 | /* add any remaining IEs */ |
| 528 | if (extra_ies_len) { |
| 529 | noffset = extra_ies_len; |
| 530 | pos = skb_put(skb, noffset - offset); |
| 531 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 532 | } |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 533 | |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 534 | } |
| 535 | |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 536 | static void |
| 537 | ieee80211_tdls_add_setup_cfm_ies(struct ieee80211_sub_if_data *sdata, |
| 538 | struct sk_buff *skb, const u8 *peer, |
| 539 | bool initiator, const u8 *extra_ies, |
| 540 | size_t extra_ies_len) |
| 541 | { |
| 542 | struct ieee80211_local *local = sdata->local; |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 543 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 544 | size_t offset = 0, noffset; |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 545 | struct sta_info *sta, *ap_sta; |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 546 | enum ieee80211_band band = ieee80211_get_sdata_band(sdata); |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 547 | u8 *pos; |
| 548 | |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 549 | mutex_lock(&local->sta_mtx); |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 550 | |
| 551 | sta = sta_info_get(sdata, peer); |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 552 | ap_sta = sta_info_get(sdata, ifmgd->bssid); |
| 553 | if (WARN_ON_ONCE(!sta || !ap_sta)) { |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 554 | mutex_unlock(&local->sta_mtx); |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 558 | sta->tdls_chandef = sdata->vif.bss_conf.chandef; |
| 559 | |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 560 | /* add any custom IEs that go before the QoS IE */ |
| 561 | if (extra_ies_len) { |
| 562 | static const u8 before_qos[] = { |
| 563 | WLAN_EID_RSN, |
| 564 | }; |
| 565 | noffset = ieee80211_ie_split(extra_ies, extra_ies_len, |
| 566 | before_qos, |
| 567 | ARRAY_SIZE(before_qos), |
| 568 | offset); |
| 569 | pos = skb_put(skb, noffset - offset); |
| 570 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 571 | offset = noffset; |
| 572 | } |
| 573 | |
| 574 | /* add the QoS param IE if both the peer and we support it */ |
Johannes Berg | a74a8c8 | 2014-07-22 14:50:47 +0200 | [diff] [blame] | 575 | if (local->hw.queues >= IEEE80211_NUM_ACS && sta->sta.wme) |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 576 | ieee80211_tdls_add_wmm_param_ie(sdata, skb); |
| 577 | |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 578 | /* add any custom IEs that go before HT operation */ |
| 579 | if (extra_ies_len) { |
| 580 | static const u8 before_ht_op[] = { |
| 581 | WLAN_EID_RSN, |
| 582 | WLAN_EID_QOS_CAPA, |
| 583 | WLAN_EID_FAST_BSS_TRANSITION, |
| 584 | WLAN_EID_TIMEOUT_INTERVAL, |
| 585 | }; |
| 586 | noffset = ieee80211_ie_split(extra_ies, extra_ies_len, |
| 587 | before_ht_op, |
| 588 | ARRAY_SIZE(before_ht_op), |
| 589 | offset); |
| 590 | pos = skb_put(skb, noffset - offset); |
| 591 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 592 | offset = noffset; |
| 593 | } |
| 594 | |
Arik Nemtsov | 57f255f | 2015-10-25 10:59:34 +0200 | [diff] [blame] | 595 | /* |
| 596 | * if HT support is only added in TDLS, we need an HT-operation IE. |
| 597 | * add the IE as required by IEEE802.11-2012 9.23.3.2. |
| 598 | */ |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 599 | if (!ap_sta->sta.ht_cap.ht_supported && sta->sta.ht_cap.ht_supported) { |
Arik Nemtsov | 57f255f | 2015-10-25 10:59:34 +0200 | [diff] [blame] | 600 | u16 prot = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED | |
| 601 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 602 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
| 603 | |
Arik Nemtsov | 890b787 | 2015-05-07 15:30:41 +0300 | [diff] [blame] | 604 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation)); |
Arik Nemtsov | 890b787 | 2015-05-07 15:30:41 +0300 | [diff] [blame] | 605 | ieee80211_ie_build_ht_oper(pos, &sta->sta.ht_cap, |
Arik Nemtsov | 57f255f | 2015-10-25 10:59:34 +0200 | [diff] [blame] | 606 | &sdata->vif.bss_conf.chandef, prot, |
| 607 | true); |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 608 | } |
| 609 | |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 610 | ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator); |
| 611 | |
| 612 | /* only include VHT-operation if not on the 2.4GHz band */ |
Arik Nemtsov | 890b787 | 2015-05-07 15:30:41 +0300 | [diff] [blame] | 613 | if (band != IEEE80211_BAND_2GHZ && sta->sta.vht_cap.vht_supported) { |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 614 | /* |
| 615 | * if both peers support WIDER_BW, we can expand the chandef to |
| 616 | * a wider compatible one, up to 80MHz |
| 617 | */ |
| 618 | if (test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW)) |
| 619 | ieee80211_tdls_chandef_vht_upgrade(sdata, sta); |
| 620 | |
Arik Nemtsov | 890b787 | 2015-05-07 15:30:41 +0300 | [diff] [blame] | 621 | pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_operation)); |
| 622 | ieee80211_ie_build_vht_oper(pos, &sta->sta.vht_cap, |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 623 | &sta->tdls_chandef); |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 626 | mutex_unlock(&local->sta_mtx); |
Arik Nemtsov | 13cc8a4 | 2014-07-17 17:14:26 +0300 | [diff] [blame] | 627 | |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 628 | /* add any remaining IEs */ |
| 629 | if (extra_ies_len) { |
| 630 | noffset = extra_ies_len; |
| 631 | pos = skb_put(skb, noffset - offset); |
| 632 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 633 | } |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 634 | } |
| 635 | |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 636 | static void |
| 637 | ieee80211_tdls_add_chan_switch_req_ies(struct ieee80211_sub_if_data *sdata, |
| 638 | struct sk_buff *skb, const u8 *peer, |
| 639 | bool initiator, const u8 *extra_ies, |
| 640 | size_t extra_ies_len, u8 oper_class, |
| 641 | struct cfg80211_chan_def *chandef) |
| 642 | { |
| 643 | struct ieee80211_tdls_data *tf; |
| 644 | size_t offset = 0, noffset; |
| 645 | u8 *pos; |
| 646 | |
| 647 | if (WARN_ON_ONCE(!chandef)) |
| 648 | return; |
| 649 | |
| 650 | tf = (void *)skb->data; |
| 651 | tf->u.chan_switch_req.target_channel = |
| 652 | ieee80211_frequency_to_channel(chandef->chan->center_freq); |
| 653 | tf->u.chan_switch_req.oper_class = oper_class; |
| 654 | |
| 655 | if (extra_ies_len) { |
| 656 | static const u8 before_lnkie[] = { |
| 657 | WLAN_EID_SECONDARY_CHANNEL_OFFSET, |
| 658 | }; |
| 659 | noffset = ieee80211_ie_split(extra_ies, extra_ies_len, |
| 660 | before_lnkie, |
| 661 | ARRAY_SIZE(before_lnkie), |
| 662 | offset); |
| 663 | pos = skb_put(skb, noffset - offset); |
| 664 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 665 | offset = noffset; |
| 666 | } |
| 667 | |
| 668 | ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator); |
| 669 | |
| 670 | /* add any remaining IEs */ |
| 671 | if (extra_ies_len) { |
| 672 | noffset = extra_ies_len; |
| 673 | pos = skb_put(skb, noffset - offset); |
| 674 | memcpy(pos, extra_ies + offset, noffset - offset); |
| 675 | } |
| 676 | } |
| 677 | |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 678 | static void |
| 679 | ieee80211_tdls_add_chan_switch_resp_ies(struct ieee80211_sub_if_data *sdata, |
| 680 | struct sk_buff *skb, const u8 *peer, |
| 681 | u16 status_code, bool initiator, |
| 682 | const u8 *extra_ies, |
| 683 | size_t extra_ies_len) |
| 684 | { |
| 685 | if (status_code == 0) |
| 686 | ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator); |
| 687 | |
| 688 | if (extra_ies_len) |
| 689 | memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len); |
| 690 | } |
| 691 | |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 692 | static void ieee80211_tdls_add_ies(struct ieee80211_sub_if_data *sdata, |
| 693 | struct sk_buff *skb, const u8 *peer, |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 694 | u8 action_code, u16 status_code, |
| 695 | bool initiator, const u8 *extra_ies, |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 696 | size_t extra_ies_len, u8 oper_class, |
| 697 | struct cfg80211_chan_def *chandef) |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 698 | { |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 699 | switch (action_code) { |
| 700 | case WLAN_TDLS_SETUP_REQUEST: |
| 701 | case WLAN_TDLS_SETUP_RESPONSE: |
| 702 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 703 | if (status_code == 0) |
| 704 | ieee80211_tdls_add_setup_start_ies(sdata, skb, peer, |
| 705 | action_code, |
| 706 | initiator, |
| 707 | extra_ies, |
| 708 | extra_ies_len); |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 709 | break; |
| 710 | case WLAN_TDLS_SETUP_CONFIRM: |
Arik Nemtsov | 6f7eaa4 | 2014-07-17 17:14:24 +0300 | [diff] [blame] | 711 | if (status_code == 0) |
| 712 | ieee80211_tdls_add_setup_cfm_ies(sdata, skb, peer, |
| 713 | initiator, extra_ies, |
| 714 | extra_ies_len); |
| 715 | break; |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 716 | case WLAN_TDLS_TEARDOWN: |
| 717 | case WLAN_TDLS_DISCOVERY_REQUEST: |
Arik Nemtsov | f09a87d | 2014-07-17 17:14:20 +0300 | [diff] [blame] | 718 | if (extra_ies_len) |
| 719 | memcpy(skb_put(skb, extra_ies_len), extra_ies, |
| 720 | extra_ies_len); |
Arik Nemtsov | 1606ef4 | 2014-07-17 17:14:21 +0300 | [diff] [blame] | 721 | if (status_code == 0 || action_code == WLAN_TDLS_TEARDOWN) |
| 722 | ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator); |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 723 | break; |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 724 | case WLAN_TDLS_CHANNEL_SWITCH_REQUEST: |
| 725 | ieee80211_tdls_add_chan_switch_req_ies(sdata, skb, peer, |
| 726 | initiator, extra_ies, |
| 727 | extra_ies_len, |
| 728 | oper_class, chandef); |
| 729 | break; |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 730 | case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE: |
| 731 | ieee80211_tdls_add_chan_switch_resp_ies(sdata, skb, peer, |
| 732 | status_code, |
| 733 | initiator, extra_ies, |
| 734 | extra_ies_len); |
| 735 | break; |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 736 | } |
| 737 | |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 738 | } |
| 739 | |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 740 | static int |
| 741 | ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 742 | const u8 *peer, u8 action_code, u8 dialog_token, |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 743 | u16 status_code, struct sk_buff *skb) |
| 744 | { |
| 745 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 746 | struct ieee80211_tdls_data *tf; |
| 747 | |
| 748 | tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u)); |
| 749 | |
| 750 | memcpy(tf->da, peer, ETH_ALEN); |
| 751 | memcpy(tf->sa, sdata->vif.addr, ETH_ALEN); |
| 752 | tf->ether_type = cpu_to_be16(ETH_P_TDLS); |
| 753 | tf->payload_type = WLAN_TDLS_SNAP_RFTYPE; |
| 754 | |
Arik Nemtsov | 59cd85c | 2014-09-09 17:11:02 +0300 | [diff] [blame] | 755 | /* network header is after the ethernet header */ |
| 756 | skb_set_network_header(skb, ETH_HLEN); |
| 757 | |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 758 | switch (action_code) { |
| 759 | case WLAN_TDLS_SETUP_REQUEST: |
| 760 | tf->category = WLAN_CATEGORY_TDLS; |
| 761 | tf->action_code = WLAN_TDLS_SETUP_REQUEST; |
| 762 | |
| 763 | skb_put(skb, sizeof(tf->u.setup_req)); |
| 764 | tf->u.setup_req.dialog_token = dialog_token; |
| 765 | tf->u.setup_req.capability = |
Arik Nemtsov | dd8c0b0 | 2014-07-17 17:14:22 +0300 | [diff] [blame] | 766 | cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata, |
| 767 | status_code)); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 768 | break; |
| 769 | case WLAN_TDLS_SETUP_RESPONSE: |
| 770 | tf->category = WLAN_CATEGORY_TDLS; |
| 771 | tf->action_code = WLAN_TDLS_SETUP_RESPONSE; |
| 772 | |
| 773 | skb_put(skb, sizeof(tf->u.setup_resp)); |
| 774 | tf->u.setup_resp.status_code = cpu_to_le16(status_code); |
| 775 | tf->u.setup_resp.dialog_token = dialog_token; |
| 776 | tf->u.setup_resp.capability = |
Arik Nemtsov | dd8c0b0 | 2014-07-17 17:14:22 +0300 | [diff] [blame] | 777 | cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata, |
| 778 | status_code)); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 779 | break; |
| 780 | case WLAN_TDLS_SETUP_CONFIRM: |
| 781 | tf->category = WLAN_CATEGORY_TDLS; |
| 782 | tf->action_code = WLAN_TDLS_SETUP_CONFIRM; |
| 783 | |
| 784 | skb_put(skb, sizeof(tf->u.setup_cfm)); |
| 785 | tf->u.setup_cfm.status_code = cpu_to_le16(status_code); |
| 786 | tf->u.setup_cfm.dialog_token = dialog_token; |
| 787 | break; |
| 788 | case WLAN_TDLS_TEARDOWN: |
| 789 | tf->category = WLAN_CATEGORY_TDLS; |
| 790 | tf->action_code = WLAN_TDLS_TEARDOWN; |
| 791 | |
| 792 | skb_put(skb, sizeof(tf->u.teardown)); |
| 793 | tf->u.teardown.reason_code = cpu_to_le16(status_code); |
| 794 | break; |
| 795 | case WLAN_TDLS_DISCOVERY_REQUEST: |
| 796 | tf->category = WLAN_CATEGORY_TDLS; |
| 797 | tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST; |
| 798 | |
| 799 | skb_put(skb, sizeof(tf->u.discover_req)); |
| 800 | tf->u.discover_req.dialog_token = dialog_token; |
| 801 | break; |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 802 | case WLAN_TDLS_CHANNEL_SWITCH_REQUEST: |
| 803 | tf->category = WLAN_CATEGORY_TDLS; |
| 804 | tf->action_code = WLAN_TDLS_CHANNEL_SWITCH_REQUEST; |
| 805 | |
| 806 | skb_put(skb, sizeof(tf->u.chan_switch_req)); |
| 807 | break; |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 808 | case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE: |
| 809 | tf->category = WLAN_CATEGORY_TDLS; |
| 810 | tf->action_code = WLAN_TDLS_CHANNEL_SWITCH_RESPONSE; |
| 811 | |
| 812 | skb_put(skb, sizeof(tf->u.chan_switch_resp)); |
| 813 | tf->u.chan_switch_resp.status_code = cpu_to_le16(status_code); |
| 814 | break; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 815 | default: |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | static int |
| 823 | ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 824 | const u8 *peer, u8 action_code, u8 dialog_token, |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 825 | u16 status_code, struct sk_buff *skb) |
| 826 | { |
| 827 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 828 | struct ieee80211_mgmt *mgmt; |
| 829 | |
| 830 | mgmt = (void *)skb_put(skb, 24); |
| 831 | memset(mgmt, 0, 24); |
| 832 | memcpy(mgmt->da, peer, ETH_ALEN); |
| 833 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 834 | memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
| 835 | |
| 836 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 837 | IEEE80211_STYPE_ACTION); |
| 838 | |
| 839 | switch (action_code) { |
| 840 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: |
| 841 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp)); |
| 842 | mgmt->u.action.category = WLAN_CATEGORY_PUBLIC; |
| 843 | mgmt->u.action.u.tdls_discover_resp.action_code = |
| 844 | WLAN_PUB_ACTION_TDLS_DISCOVER_RES; |
| 845 | mgmt->u.action.u.tdls_discover_resp.dialog_token = |
| 846 | dialog_token; |
| 847 | mgmt->u.action.u.tdls_discover_resp.capability = |
Arik Nemtsov | dd8c0b0 | 2014-07-17 17:14:22 +0300 | [diff] [blame] | 848 | cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata, |
| 849 | status_code)); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 850 | break; |
| 851 | default: |
| 852 | return -EINVAL; |
| 853 | } |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 858 | static struct sk_buff * |
| 859 | ieee80211_tdls_build_mgmt_packet_data(struct ieee80211_sub_if_data *sdata, |
| 860 | const u8 *peer, u8 action_code, |
| 861 | u8 dialog_token, u16 status_code, |
| 862 | bool initiator, const u8 *extra_ies, |
| 863 | size_t extra_ies_len, u8 oper_class, |
| 864 | struct cfg80211_chan_def *chandef) |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 865 | { |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 866 | struct ieee80211_local *local = sdata->local; |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 867 | struct sk_buff *skb; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 868 | int ret; |
| 869 | |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 870 | skb = netdev_alloc_skb(sdata->dev, |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 871 | local->hw.extra_tx_headroom + |
| 872 | max(sizeof(struct ieee80211_mgmt), |
| 873 | sizeof(struct ieee80211_tdls_data)) + |
| 874 | 50 + /* supported rates */ |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 875 | 10 + /* ext capab */ |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 876 | 26 + /* max(WMM-info, WMM-param) */ |
| 877 | 2 + max(sizeof(struct ieee80211_ht_cap), |
| 878 | sizeof(struct ieee80211_ht_operation)) + |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 879 | 2 + max(sizeof(struct ieee80211_vht_cap), |
| 880 | sizeof(struct ieee80211_vht_operation)) + |
Arik Nemtsov | f0d29cb | 2014-11-09 18:50:12 +0200 | [diff] [blame] | 881 | 50 + /* supported channels */ |
Arik Nemtsov | 2cedd87 | 2014-11-09 18:50:13 +0200 | [diff] [blame] | 882 | 3 + /* 40/20 BSS coex */ |
Arik Nemtsov | fb28ec0 | 2015-03-01 09:10:02 +0200 | [diff] [blame] | 883 | 4 + /* AID */ |
Arik Nemtsov | a38700d | 2015-03-18 08:46:08 +0200 | [diff] [blame] | 884 | 4 + /* oper classes */ |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 885 | extra_ies_len + |
| 886 | sizeof(struct ieee80211_tdls_lnkie)); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 887 | if (!skb) |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 888 | return NULL; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 889 | |
| 890 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 891 | |
| 892 | switch (action_code) { |
| 893 | case WLAN_TDLS_SETUP_REQUEST: |
| 894 | case WLAN_TDLS_SETUP_RESPONSE: |
| 895 | case WLAN_TDLS_SETUP_CONFIRM: |
| 896 | case WLAN_TDLS_TEARDOWN: |
| 897 | case WLAN_TDLS_DISCOVERY_REQUEST: |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 898 | case WLAN_TDLS_CHANNEL_SWITCH_REQUEST: |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 899 | case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE: |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 900 | ret = ieee80211_prep_tdls_encap_data(local->hw.wiphy, |
| 901 | sdata->dev, peer, |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 902 | action_code, dialog_token, |
| 903 | status_code, skb); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 904 | break; |
| 905 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 906 | ret = ieee80211_prep_tdls_direct(local->hw.wiphy, sdata->dev, |
| 907 | peer, action_code, |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 908 | dialog_token, status_code, |
| 909 | skb); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 910 | break; |
| 911 | default: |
| 912 | ret = -ENOTSUPP; |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | if (ret < 0) |
| 917 | goto fail; |
| 918 | |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 919 | ieee80211_tdls_add_ies(sdata, skb, peer, action_code, status_code, |
| 920 | initiator, extra_ies, extra_ies_len, oper_class, |
| 921 | chandef); |
| 922 | return skb; |
| 923 | |
| 924 | fail: |
| 925 | dev_kfree_skb(skb); |
| 926 | return NULL; |
| 927 | } |
| 928 | |
| 929 | static int |
| 930 | ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev, |
| 931 | const u8 *peer, u8 action_code, u8 dialog_token, |
| 932 | u16 status_code, u32 peer_capability, |
| 933 | bool initiator, const u8 *extra_ies, |
| 934 | size_t extra_ies_len, u8 oper_class, |
| 935 | struct cfg80211_chan_def *chandef) |
| 936 | { |
| 937 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 938 | struct sk_buff *skb = NULL; |
| 939 | struct sta_info *sta; |
| 940 | u32 flags = 0; |
| 941 | int ret = 0; |
| 942 | |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 943 | rcu_read_lock(); |
| 944 | sta = sta_info_get(sdata, peer); |
| 945 | |
| 946 | /* infer the initiator if we can, to support old userspace */ |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 947 | switch (action_code) { |
| 948 | case WLAN_TDLS_SETUP_REQUEST: |
Arik Nemtsov | 8b94148 | 2014-10-22 12:32:48 +0300 | [diff] [blame] | 949 | if (sta) { |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 950 | set_sta_flag(sta, WLAN_STA_TDLS_INITIATOR); |
Arik Nemtsov | 8b94148 | 2014-10-22 12:32:48 +0300 | [diff] [blame] | 951 | sta->sta.tdls_initiator = false; |
| 952 | } |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 953 | /* fall-through */ |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 954 | case WLAN_TDLS_SETUP_CONFIRM: |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 955 | case WLAN_TDLS_DISCOVERY_REQUEST: |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 956 | initiator = true; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 957 | break; |
| 958 | case WLAN_TDLS_SETUP_RESPONSE: |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 959 | /* |
| 960 | * In some testing scenarios, we send a request and response. |
| 961 | * Make the last packet sent take effect for the initiator |
| 962 | * value. |
| 963 | */ |
Arik Nemtsov | 8b94148 | 2014-10-22 12:32:48 +0300 | [diff] [blame] | 964 | if (sta) { |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 965 | clear_sta_flag(sta, WLAN_STA_TDLS_INITIATOR); |
Arik Nemtsov | 8b94148 | 2014-10-22 12:32:48 +0300 | [diff] [blame] | 966 | sta->sta.tdls_initiator = true; |
| 967 | } |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 968 | /* fall-through */ |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 969 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 970 | initiator = false; |
Arik Nemtsov | 2fb6b9b | 2014-06-11 17:18:22 +0300 | [diff] [blame] | 971 | break; |
| 972 | case WLAN_TDLS_TEARDOWN: |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 973 | case WLAN_TDLS_CHANNEL_SWITCH_REQUEST: |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 974 | case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE: |
Arik Nemtsov | 2fb6b9b | 2014-06-11 17:18:22 +0300 | [diff] [blame] | 975 | /* any value is ok */ |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 976 | break; |
| 977 | default: |
| 978 | ret = -ENOTSUPP; |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 979 | break; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 980 | } |
| 981 | |
Arik Nemtsov | 46792a2 | 2014-07-17 17:14:19 +0300 | [diff] [blame] | 982 | if (sta && test_sta_flag(sta, WLAN_STA_TDLS_INITIATOR)) |
| 983 | initiator = true; |
Arik Nemtsov | 2fb6b9b | 2014-06-11 17:18:22 +0300 | [diff] [blame] | 984 | |
Arik Nemtsov | 626911c | 2014-07-17 17:14:17 +0300 | [diff] [blame] | 985 | rcu_read_unlock(); |
| 986 | if (ret < 0) |
| 987 | goto fail; |
| 988 | |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 989 | skb = ieee80211_tdls_build_mgmt_packet_data(sdata, peer, action_code, |
| 990 | dialog_token, status_code, |
| 991 | initiator, extra_ies, |
| 992 | extra_ies_len, oper_class, |
| 993 | chandef); |
| 994 | if (!skb) { |
| 995 | ret = -EINVAL; |
| 996 | goto fail; |
| 997 | } |
| 998 | |
| 999 | if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) { |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1000 | ieee80211_tx_skb(sdata, skb); |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise |
| 1006 | * we should default to AC_VI. |
| 1007 | */ |
| 1008 | switch (action_code) { |
| 1009 | case WLAN_TDLS_SETUP_REQUEST: |
| 1010 | case WLAN_TDLS_SETUP_RESPONSE: |
| 1011 | skb_set_queue_mapping(skb, IEEE80211_AC_BK); |
| 1012 | skb->priority = 2; |
| 1013 | break; |
| 1014 | default: |
| 1015 | skb_set_queue_mapping(skb, IEEE80211_AC_VI); |
| 1016 | skb->priority = 5; |
| 1017 | break; |
| 1018 | } |
| 1019 | |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 1020 | /* |
| 1021 | * Set the WLAN_TDLS_TEARDOWN flag to indicate a teardown in progress. |
| 1022 | * Later, if no ACK is returned from peer, we will re-send the teardown |
| 1023 | * packet through the AP. |
| 1024 | */ |
| 1025 | if ((action_code == WLAN_TDLS_TEARDOWN) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1026 | ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 1027 | bool try_resend; /* Should we keep skb for possible resend */ |
| 1028 | |
| 1029 | /* If not sending directly to peer - no point in keeping skb */ |
| 1030 | rcu_read_lock(); |
| 1031 | sta = sta_info_get(sdata, peer); |
| 1032 | try_resend = sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH); |
| 1033 | rcu_read_unlock(); |
| 1034 | |
| 1035 | spin_lock_bh(&sdata->u.mgd.teardown_lock); |
| 1036 | if (try_resend && !sdata->u.mgd.teardown_skb) { |
| 1037 | /* Mark it as requiring TX status callback */ |
| 1038 | flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 1039 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
| 1040 | |
| 1041 | /* |
| 1042 | * skb is copied since mac80211 will later set |
| 1043 | * properties that might not be the same as the AP, |
| 1044 | * such as encryption, QoS, addresses, etc. |
| 1045 | * |
| 1046 | * No problem if skb_copy() fails, so no need to check. |
| 1047 | */ |
| 1048 | sdata->u.mgd.teardown_skb = skb_copy(skb, GFP_ATOMIC); |
| 1049 | sdata->u.mgd.orig_teardown_skb = skb; |
| 1050 | } |
| 1051 | spin_unlock_bh(&sdata->u.mgd.teardown_lock); |
| 1052 | } |
| 1053 | |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1054 | /* disable bottom halves when entering the Tx path */ |
| 1055 | local_bh_disable(); |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 1056 | __ieee80211_subif_start_xmit(skb, dev, flags); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1057 | local_bh_enable(); |
| 1058 | |
| 1059 | return ret; |
| 1060 | |
| 1061 | fail: |
| 1062 | dev_kfree_skb(skb); |
| 1063 | return ret; |
| 1064 | } |
| 1065 | |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1066 | static int |
| 1067 | ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev, |
| 1068 | const u8 *peer, u8 action_code, u8 dialog_token, |
| 1069 | u16 status_code, u32 peer_capability, bool initiator, |
| 1070 | const u8 *extra_ies, size_t extra_ies_len) |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1071 | { |
| 1072 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1073 | struct ieee80211_local *local = sdata->local; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 1074 | enum ieee80211_smps_mode smps_mode = sdata->u.mgd.driver_smps_mode; |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1075 | int ret; |
| 1076 | |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 1077 | /* don't support setup with forced SMPS mode that's not off */ |
| 1078 | if (smps_mode != IEEE80211_SMPS_AUTOMATIC && |
| 1079 | smps_mode != IEEE80211_SMPS_OFF) { |
| 1080 | tdls_dbg(sdata, "Aborting TDLS setup due to SMPS mode %d\n", |
| 1081 | smps_mode); |
| 1082 | return -ENOTSUPP; |
| 1083 | } |
| 1084 | |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1085 | mutex_lock(&local->mtx); |
| 1086 | |
| 1087 | /* we don't support concurrent TDLS peer setups */ |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 1088 | if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer) && |
| 1089 | !ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) { |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1090 | ret = -EBUSY; |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1091 | goto out_unlock; |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1092 | } |
| 1093 | |
Arik Nemtsov | 7adc3e4 | 2014-06-11 17:18:26 +0300 | [diff] [blame] | 1094 | /* |
| 1095 | * make sure we have a STA representing the peer so we drop or buffer |
| 1096 | * non-TDLS-setup frames to the peer. We can't send other packets |
Arik Nemtsov | 6ae32e5 | 2014-07-17 17:14:18 +0300 | [diff] [blame] | 1097 | * during setup through the AP path. |
| 1098 | * Allow error packets to be sent - sometimes we don't even add a STA |
| 1099 | * before failing the setup. |
Arik Nemtsov | 7adc3e4 | 2014-06-11 17:18:26 +0300 | [diff] [blame] | 1100 | */ |
Arik Nemtsov | 6ae32e5 | 2014-07-17 17:14:18 +0300 | [diff] [blame] | 1101 | if (status_code == 0) { |
| 1102 | rcu_read_lock(); |
| 1103 | if (!sta_info_get(sdata, peer)) { |
| 1104 | rcu_read_unlock(); |
| 1105 | ret = -ENOLINK; |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1106 | goto out_unlock; |
Arik Nemtsov | 6ae32e5 | 2014-07-17 17:14:18 +0300 | [diff] [blame] | 1107 | } |
Arik Nemtsov | 7adc3e4 | 2014-06-11 17:18:26 +0300 | [diff] [blame] | 1108 | rcu_read_unlock(); |
Arik Nemtsov | 7adc3e4 | 2014-06-11 17:18:26 +0300 | [diff] [blame] | 1109 | } |
Arik Nemtsov | 7adc3e4 | 2014-06-11 17:18:26 +0300 | [diff] [blame] | 1110 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1111 | ieee80211_flush_queues(local, sdata, false); |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1112 | memcpy(sdata->u.mgd.tdls_peer, peer, ETH_ALEN); |
| 1113 | mutex_unlock(&local->mtx); |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1114 | |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1115 | /* we cannot take the mutex while preparing the setup packet */ |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1116 | ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code, |
| 1117 | dialog_token, status_code, |
Arik Nemtsov | 2fb6b9b | 2014-06-11 17:18:22 +0300 | [diff] [blame] | 1118 | peer_capability, initiator, |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 1119 | extra_ies, extra_ies_len, 0, |
| 1120 | NULL); |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1121 | if (ret < 0) { |
| 1122 | mutex_lock(&local->mtx); |
| 1123 | eth_zero_addr(sdata->u.mgd.tdls_peer); |
| 1124 | mutex_unlock(&local->mtx); |
| 1125 | return ret; |
| 1126 | } |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1127 | |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1128 | ieee80211_queue_delayed_work(&sdata->local->hw, |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 1129 | &sdata->u.mgd.tdls_peer_del_work, |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1130 | TDLS_PEER_SETUP_TIMEOUT); |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1131 | return 0; |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1132 | |
Arik Nemtsov | ae2e9fb | 2015-03-01 09:10:09 +0200 | [diff] [blame] | 1133 | out_unlock: |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1134 | mutex_unlock(&local->mtx); |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1135 | return ret; |
| 1136 | } |
| 1137 | |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1138 | static int |
| 1139 | ieee80211_tdls_mgmt_teardown(struct wiphy *wiphy, struct net_device *dev, |
| 1140 | const u8 *peer, u8 action_code, u8 dialog_token, |
| 1141 | u16 status_code, u32 peer_capability, |
| 1142 | bool initiator, const u8 *extra_ies, |
| 1143 | size_t extra_ies_len) |
| 1144 | { |
| 1145 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1146 | struct ieee80211_local *local = sdata->local; |
| 1147 | struct sta_info *sta; |
| 1148 | int ret; |
| 1149 | |
| 1150 | /* |
| 1151 | * No packets can be transmitted to the peer via the AP during setup - |
| 1152 | * the STA is set as a TDLS peer, but is not authorized. |
| 1153 | * During teardown, we prevent direct transmissions by stopping the |
| 1154 | * queues and flushing all direct packets. |
| 1155 | */ |
| 1156 | ieee80211_stop_vif_queues(local, sdata, |
| 1157 | IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN); |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1158 | ieee80211_flush_queues(local, sdata, false); |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1159 | |
| 1160 | ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code, |
| 1161 | dialog_token, status_code, |
| 1162 | peer_capability, initiator, |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 1163 | extra_ies, extra_ies_len, 0, |
| 1164 | NULL); |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1165 | if (ret < 0) |
| 1166 | sdata_err(sdata, "Failed sending TDLS teardown packet %d\n", |
| 1167 | ret); |
| 1168 | |
| 1169 | /* |
| 1170 | * Remove the STA AUTH flag to force further traffic through the AP. If |
| 1171 | * the STA was unreachable, it was already removed. |
| 1172 | */ |
| 1173 | rcu_read_lock(); |
| 1174 | sta = sta_info_get(sdata, peer); |
| 1175 | if (sta) |
| 1176 | clear_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH); |
| 1177 | rcu_read_unlock(); |
| 1178 | |
| 1179 | ieee80211_wake_vif_queues(local, sdata, |
| 1180 | IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1185 | int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev, |
| 1186 | const u8 *peer, u8 action_code, u8 dialog_token, |
| 1187 | u16 status_code, u32 peer_capability, |
| 1188 | bool initiator, const u8 *extra_ies, |
| 1189 | size_t extra_ies_len) |
| 1190 | { |
| 1191 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1192 | int ret; |
| 1193 | |
| 1194 | if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 1195 | return -ENOTSUPP; |
| 1196 | |
| 1197 | /* make sure we are in managed mode, and associated */ |
| 1198 | if (sdata->vif.type != NL80211_IFTYPE_STATION || |
| 1199 | !sdata->u.mgd.associated) |
| 1200 | return -EINVAL; |
| 1201 | |
| 1202 | switch (action_code) { |
| 1203 | case WLAN_TDLS_SETUP_REQUEST: |
| 1204 | case WLAN_TDLS_SETUP_RESPONSE: |
| 1205 | ret = ieee80211_tdls_mgmt_setup(wiphy, dev, peer, action_code, |
| 1206 | dialog_token, status_code, |
| 1207 | peer_capability, initiator, |
| 1208 | extra_ies, extra_ies_len); |
| 1209 | break; |
| 1210 | case WLAN_TDLS_TEARDOWN: |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1211 | ret = ieee80211_tdls_mgmt_teardown(wiphy, dev, peer, |
| 1212 | action_code, dialog_token, |
| 1213 | status_code, |
| 1214 | peer_capability, initiator, |
| 1215 | extra_ies, extra_ies_len); |
| 1216 | break; |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1217 | case WLAN_TDLS_DISCOVERY_REQUEST: |
Arik Nemtsov | ee10f2c | 2014-06-11 17:18:27 +0300 | [diff] [blame] | 1218 | /* |
| 1219 | * Protect the discovery so we can hear the TDLS discovery |
| 1220 | * response frame. It is transmitted directly and not buffered |
| 1221 | * by the AP. |
| 1222 | */ |
| 1223 | drv_mgd_protect_tdls_discover(sdata->local, sdata); |
| 1224 | /* fall-through */ |
| 1225 | case WLAN_TDLS_SETUP_CONFIRM: |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1226 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: |
| 1227 | /* no special handling */ |
| 1228 | ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, |
| 1229 | action_code, |
| 1230 | dialog_token, |
| 1231 | status_code, |
| 1232 | peer_capability, |
| 1233 | initiator, extra_ies, |
Arik Nemtsov | c273390 | 2014-11-09 18:50:16 +0200 | [diff] [blame] | 1234 | extra_ies_len, 0, NULL); |
Arik Nemtsov | 191dd46 | 2014-06-11 17:18:23 +0300 | [diff] [blame] | 1235 | break; |
| 1236 | default: |
| 1237 | ret = -EOPNOTSUPP; |
| 1238 | break; |
| 1239 | } |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1240 | |
| 1241 | tdls_dbg(sdata, "TDLS mgmt action %d peer %pM status %d\n", |
| 1242 | action_code, peer, ret); |
| 1243 | return ret; |
| 1244 | } |
| 1245 | |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 1246 | static void iee80211_tdls_recalc_chanctx(struct ieee80211_sub_if_data *sdata, |
| 1247 | struct sta_info *sta) |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 1248 | { |
| 1249 | struct ieee80211_local *local = sdata->local; |
| 1250 | struct ieee80211_chanctx_conf *conf; |
| 1251 | struct ieee80211_chanctx *ctx; |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 1252 | enum nl80211_chan_width width; |
| 1253 | struct ieee80211_supported_band *sband; |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 1254 | |
| 1255 | mutex_lock(&local->chanctx_mtx); |
| 1256 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 1257 | lockdep_is_held(&local->chanctx_mtx)); |
| 1258 | if (conf) { |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 1259 | width = conf->def.width; |
| 1260 | sband = local->hw.wiphy->bands[conf->def.chan->band]; |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 1261 | ctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 1262 | ieee80211_recalc_chanctx_chantype(local, ctx); |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 1263 | |
| 1264 | /* if width changed and a peer is given, update its BW */ |
| 1265 | if (width != conf->def.width && sta && |
| 1266 | test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW)) { |
| 1267 | enum ieee80211_sta_rx_bandwidth bw; |
| 1268 | |
| 1269 | bw = ieee80211_chan_width_to_rx_bw(conf->def.width); |
| 1270 | bw = min(bw, ieee80211_sta_cap_rx_bw(sta)); |
| 1271 | if (bw != sta->sta.bandwidth) { |
| 1272 | sta->sta.bandwidth = bw; |
| 1273 | rate_control_rate_update(local, sband, sta, |
| 1274 | IEEE80211_RC_BW_CHANGED); |
| 1275 | /* |
| 1276 | * if a TDLS peer BW was updated, we need to |
| 1277 | * recalc the chandef width again, to get the |
| 1278 | * correct chanctx min_def |
| 1279 | */ |
| 1280 | ieee80211_recalc_chanctx_chantype(local, ctx); |
| 1281 | } |
| 1282 | } |
| 1283 | |
Arik Nemtsov | 0fabfaa | 2015-06-10 20:41:23 +0300 | [diff] [blame] | 1284 | } |
| 1285 | mutex_unlock(&local->chanctx_mtx); |
| 1286 | } |
| 1287 | |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1288 | static int iee80211_tdls_have_ht_peers(struct ieee80211_sub_if_data *sdata) |
| 1289 | { |
| 1290 | struct sta_info *sta; |
| 1291 | bool result = false; |
| 1292 | |
| 1293 | rcu_read_lock(); |
| 1294 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { |
| 1295 | if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || |
| 1296 | !test_sta_flag(sta, WLAN_STA_AUTHORIZED) || |
| 1297 | !test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH) || |
| 1298 | !sta->sta.ht_cap.ht_supported) |
| 1299 | continue; |
| 1300 | result = true; |
| 1301 | break; |
| 1302 | } |
| 1303 | rcu_read_unlock(); |
| 1304 | |
| 1305 | return result; |
| 1306 | } |
| 1307 | |
| 1308 | static void |
| 1309 | iee80211_tdls_recalc_ht_protection(struct ieee80211_sub_if_data *sdata, |
| 1310 | struct sta_info *sta) |
| 1311 | { |
| 1312 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1313 | bool tdls_ht; |
| 1314 | u16 protection = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED | |
| 1315 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 1316 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
| 1317 | u16 opmode; |
| 1318 | |
| 1319 | /* Nothing to do if the BSS connection uses HT */ |
| 1320 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
| 1321 | return; |
| 1322 | |
| 1323 | tdls_ht = (sta && sta->sta.ht_cap.ht_supported) || |
| 1324 | iee80211_tdls_have_ht_peers(sdata); |
| 1325 | |
| 1326 | opmode = sdata->vif.bss_conf.ht_operation_mode; |
| 1327 | |
| 1328 | if (tdls_ht) |
| 1329 | opmode |= protection; |
| 1330 | else |
| 1331 | opmode &= ~protection; |
| 1332 | |
| 1333 | if (opmode == sdata->vif.bss_conf.ht_operation_mode) |
| 1334 | return; |
| 1335 | |
| 1336 | sdata->vif.bss_conf.ht_operation_mode = opmode; |
| 1337 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT); |
| 1338 | } |
| 1339 | |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1340 | int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1341 | const u8 *peer, enum nl80211_tdls_operation oper) |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1342 | { |
| 1343 | struct sta_info *sta; |
| 1344 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1345 | struct ieee80211_local *local = sdata->local; |
| 1346 | int ret; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1347 | |
| 1348 | if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 1349 | return -ENOTSUPP; |
| 1350 | |
| 1351 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1352 | return -EINVAL; |
| 1353 | |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1354 | switch (oper) { |
| 1355 | case NL80211_TDLS_ENABLE_LINK: |
| 1356 | case NL80211_TDLS_DISABLE_LINK: |
| 1357 | break; |
| 1358 | case NL80211_TDLS_TEARDOWN: |
| 1359 | case NL80211_TDLS_SETUP: |
| 1360 | case NL80211_TDLS_DISCOVERY_REQ: |
| 1361 | /* We don't support in-driver setup/teardown/discovery */ |
| 1362 | return -ENOTSUPP; |
| 1363 | } |
| 1364 | |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1365 | /* protect possible bss_conf changes and avoid concurrency in |
| 1366 | * ieee80211_bss_info_change_notify() |
| 1367 | */ |
| 1368 | sdata_lock(sdata); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1369 | mutex_lock(&local->mtx); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1370 | tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer); |
| 1371 | |
| 1372 | switch (oper) { |
| 1373 | case NL80211_TDLS_ENABLE_LINK: |
Arik Nemtsov | c5a7168 | 2015-05-19 14:36:48 +0300 | [diff] [blame] | 1374 | if (sdata->vif.csa_active) { |
| 1375 | tdls_dbg(sdata, "TDLS: disallow link during CSA\n"); |
| 1376 | ret = -EBUSY; |
| 1377 | break; |
| 1378 | } |
| 1379 | |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1380 | mutex_lock(&local->sta_mtx); |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1381 | sta = sta_info_get(sdata, peer); |
| 1382 | if (!sta) { |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1383 | mutex_unlock(&local->sta_mtx); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1384 | ret = -ENOLINK; |
| 1385 | break; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1386 | } |
| 1387 | |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 1388 | iee80211_tdls_recalc_chanctx(sdata, sta); |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1389 | iee80211_tdls_recalc_ht_protection(sdata, sta); |
| 1390 | |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1391 | set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH); |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1392 | mutex_unlock(&local->sta_mtx); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1393 | |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 1394 | WARN_ON_ONCE(is_zero_ether_addr(sdata->u.mgd.tdls_peer) || |
| 1395 | !ether_addr_equal(sdata->u.mgd.tdls_peer, peer)); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1396 | ret = 0; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1397 | break; |
| 1398 | case NL80211_TDLS_DISABLE_LINK: |
Liad Kaufman | bb3f848 | 2014-07-17 17:14:31 +0300 | [diff] [blame] | 1399 | /* |
| 1400 | * The teardown message in ieee80211_tdls_mgmt_teardown() was |
| 1401 | * created while the queues were stopped, so it might still be |
| 1402 | * pending. Before flushing the queues we need to be sure the |
| 1403 | * message is handled by the tasklet handling pending messages, |
| 1404 | * otherwise we might start destroying the station before |
| 1405 | * sending the teardown packet. |
| 1406 | * Note that this only forces the tasklet to flush pendings - |
| 1407 | * not to stop the tasklet from rescheduling itself. |
| 1408 | */ |
| 1409 | tasklet_kill(&local->tx_pending_tasklet); |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1410 | /* flush a potentially queued teardown packet */ |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1411 | ieee80211_flush_queues(local, sdata, false); |
Arik Nemtsov | db67d66 | 2014-06-11 17:18:24 +0300 | [diff] [blame] | 1412 | |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1413 | ret = sta_info_destroy_addr(sdata, peer); |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1414 | |
| 1415 | mutex_lock(&local->sta_mtx); |
| 1416 | iee80211_tdls_recalc_ht_protection(sdata, NULL); |
| 1417 | mutex_unlock(&local->sta_mtx); |
| 1418 | |
Arik Nemtsov | 59021c6 | 2016-03-02 23:28:32 +0200 | [diff] [blame^] | 1419 | iee80211_tdls_recalc_chanctx(sdata, NULL); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1420 | break; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1421 | default: |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1422 | ret = -ENOTSUPP; |
| 1423 | break; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1424 | } |
| 1425 | |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 1426 | if (ret == 0 && ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) { |
| 1427 | cancel_delayed_work(&sdata->u.mgd.tdls_peer_del_work); |
| 1428 | eth_zero_addr(sdata->u.mgd.tdls_peer); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1429 | } |
| 1430 | |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 1431 | if (ret == 0) |
| 1432 | ieee80211_queue_work(&sdata->local->hw, |
| 1433 | &sdata->u.mgd.request_smps_work); |
| 1434 | |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1435 | mutex_unlock(&local->mtx); |
Avri Altman | 22f6689 | 2015-08-18 16:52:07 +0300 | [diff] [blame] | 1436 | sdata_unlock(sdata); |
Arik Nemtsov | 17e6a59 | 2014-06-11 17:18:20 +0300 | [diff] [blame] | 1437 | return ret; |
Arik Nemtsov | 95224fe | 2014-05-01 10:17:28 +0300 | [diff] [blame] | 1438 | } |
Arik Nemtsov | c887f0d3 | 2014-06-11 17:18:25 +0300 | [diff] [blame] | 1439 | |
| 1440 | void ieee80211_tdls_oper_request(struct ieee80211_vif *vif, const u8 *peer, |
| 1441 | enum nl80211_tdls_operation oper, |
| 1442 | u16 reason_code, gfp_t gfp) |
| 1443 | { |
| 1444 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1445 | |
| 1446 | if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) { |
| 1447 | sdata_err(sdata, "Discarding TDLS oper %d - not STA or disconnected\n", |
| 1448 | oper); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
| 1452 | cfg80211_tdls_oper_request(sdata->dev, peer, oper, reason_code, gfp); |
| 1453 | } |
| 1454 | EXPORT_SYMBOL(ieee80211_tdls_oper_request); |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 1455 | |
| 1456 | static void |
| 1457 | iee80211_tdls_add_ch_switch_timing(u8 *buf, u16 switch_time, u16 switch_timeout) |
| 1458 | { |
| 1459 | struct ieee80211_ch_switch_timing *ch_sw; |
| 1460 | |
| 1461 | *buf++ = WLAN_EID_CHAN_SWITCH_TIMING; |
| 1462 | *buf++ = sizeof(struct ieee80211_ch_switch_timing); |
| 1463 | |
| 1464 | ch_sw = (void *)buf; |
| 1465 | ch_sw->switch_time = cpu_to_le16(switch_time); |
| 1466 | ch_sw->switch_timeout = cpu_to_le16(switch_timeout); |
| 1467 | } |
| 1468 | |
| 1469 | /* find switch timing IE in SKB ready for Tx */ |
| 1470 | static const u8 *ieee80211_tdls_find_sw_timing_ie(struct sk_buff *skb) |
| 1471 | { |
| 1472 | struct ieee80211_tdls_data *tf; |
| 1473 | const u8 *ie_start; |
| 1474 | |
| 1475 | /* |
| 1476 | * Get the offset for the new location of the switch timing IE. |
| 1477 | * The SKB network header will now point to the "payload_type" |
| 1478 | * element of the TDLS data frame struct. |
| 1479 | */ |
| 1480 | tf = container_of(skb->data + skb_network_offset(skb), |
| 1481 | struct ieee80211_tdls_data, payload_type); |
| 1482 | ie_start = tf->u.chan_switch_req.variable; |
| 1483 | return cfg80211_find_ie(WLAN_EID_CHAN_SWITCH_TIMING, ie_start, |
| 1484 | skb->len - (ie_start - skb->data)); |
| 1485 | } |
| 1486 | |
| 1487 | static struct sk_buff * |
| 1488 | ieee80211_tdls_ch_sw_tmpl_get(struct sta_info *sta, u8 oper_class, |
| 1489 | struct cfg80211_chan_def *chandef, |
| 1490 | u32 *ch_sw_tm_ie_offset) |
| 1491 | { |
| 1492 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1493 | u8 extra_ies[2 + sizeof(struct ieee80211_sec_chan_offs_ie) + |
| 1494 | 2 + sizeof(struct ieee80211_ch_switch_timing)]; |
| 1495 | int extra_ies_len = 2 + sizeof(struct ieee80211_ch_switch_timing); |
| 1496 | u8 *pos = extra_ies; |
| 1497 | struct sk_buff *skb; |
| 1498 | |
| 1499 | /* |
| 1500 | * if chandef points to a wide channel add a Secondary-Channel |
| 1501 | * Offset information element |
| 1502 | */ |
| 1503 | if (chandef->width == NL80211_CHAN_WIDTH_40) { |
| 1504 | struct ieee80211_sec_chan_offs_ie *sec_chan_ie; |
| 1505 | bool ht40plus; |
| 1506 | |
| 1507 | *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; |
| 1508 | *pos++ = sizeof(*sec_chan_ie); |
| 1509 | sec_chan_ie = (void *)pos; |
| 1510 | |
| 1511 | ht40plus = cfg80211_get_chandef_type(chandef) == |
| 1512 | NL80211_CHAN_HT40PLUS; |
| 1513 | sec_chan_ie->sec_chan_offs = ht40plus ? |
| 1514 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE : |
| 1515 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
| 1516 | pos += sizeof(*sec_chan_ie); |
| 1517 | |
| 1518 | extra_ies_len += 2 + sizeof(struct ieee80211_sec_chan_offs_ie); |
| 1519 | } |
| 1520 | |
| 1521 | /* just set the values to 0, this is a template */ |
| 1522 | iee80211_tdls_add_ch_switch_timing(pos, 0, 0); |
| 1523 | |
| 1524 | skb = ieee80211_tdls_build_mgmt_packet_data(sdata, sta->sta.addr, |
| 1525 | WLAN_TDLS_CHANNEL_SWITCH_REQUEST, |
| 1526 | 0, 0, !sta->sta.tdls_initiator, |
| 1527 | extra_ies, extra_ies_len, |
| 1528 | oper_class, chandef); |
| 1529 | if (!skb) |
| 1530 | return NULL; |
| 1531 | |
| 1532 | skb = ieee80211_build_data_template(sdata, skb, 0); |
| 1533 | if (IS_ERR(skb)) { |
| 1534 | tdls_dbg(sdata, "Failed building TDLS channel switch frame\n"); |
| 1535 | return NULL; |
| 1536 | } |
| 1537 | |
| 1538 | if (ch_sw_tm_ie_offset) { |
| 1539 | const u8 *tm_ie = ieee80211_tdls_find_sw_timing_ie(skb); |
| 1540 | |
| 1541 | if (!tm_ie) { |
| 1542 | tdls_dbg(sdata, "No switch timing IE in TDLS switch\n"); |
| 1543 | dev_kfree_skb_any(skb); |
| 1544 | return NULL; |
| 1545 | } |
| 1546 | |
| 1547 | *ch_sw_tm_ie_offset = tm_ie - skb->data; |
| 1548 | } |
| 1549 | |
| 1550 | tdls_dbg(sdata, |
| 1551 | "TDLS channel switch request template for %pM ch %d width %d\n", |
| 1552 | sta->sta.addr, chandef->chan->center_freq, chandef->width); |
| 1553 | return skb; |
| 1554 | } |
| 1555 | |
| 1556 | int |
| 1557 | ieee80211_tdls_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
| 1558 | const u8 *addr, u8 oper_class, |
| 1559 | struct cfg80211_chan_def *chandef) |
| 1560 | { |
| 1561 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1562 | struct ieee80211_local *local = sdata->local; |
| 1563 | struct sta_info *sta; |
| 1564 | struct sk_buff *skb = NULL; |
| 1565 | u32 ch_sw_tm_ie; |
| 1566 | int ret; |
| 1567 | |
| 1568 | mutex_lock(&local->sta_mtx); |
| 1569 | sta = sta_info_get(sdata, addr); |
| 1570 | if (!sta) { |
| 1571 | tdls_dbg(sdata, |
| 1572 | "Invalid TDLS peer %pM for channel switch request\n", |
| 1573 | addr); |
| 1574 | ret = -ENOENT; |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | if (!test_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH)) { |
| 1579 | tdls_dbg(sdata, "TDLS channel switch unsupported by %pM\n", |
| 1580 | addr); |
| 1581 | ret = -ENOTSUPP; |
| 1582 | goto out; |
| 1583 | } |
| 1584 | |
| 1585 | skb = ieee80211_tdls_ch_sw_tmpl_get(sta, oper_class, chandef, |
| 1586 | &ch_sw_tm_ie); |
| 1587 | if (!skb) { |
| 1588 | ret = -ENOENT; |
| 1589 | goto out; |
| 1590 | } |
| 1591 | |
| 1592 | ret = drv_tdls_channel_switch(local, sdata, &sta->sta, oper_class, |
| 1593 | chandef, skb, ch_sw_tm_ie); |
| 1594 | if (!ret) |
| 1595 | set_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL); |
| 1596 | |
| 1597 | out: |
| 1598 | mutex_unlock(&local->sta_mtx); |
| 1599 | dev_kfree_skb_any(skb); |
| 1600 | return ret; |
| 1601 | } |
| 1602 | |
| 1603 | void |
| 1604 | ieee80211_tdls_cancel_channel_switch(struct wiphy *wiphy, |
| 1605 | struct net_device *dev, |
| 1606 | const u8 *addr) |
| 1607 | { |
| 1608 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1609 | struct ieee80211_local *local = sdata->local; |
| 1610 | struct sta_info *sta; |
| 1611 | |
| 1612 | mutex_lock(&local->sta_mtx); |
| 1613 | sta = sta_info_get(sdata, addr); |
| 1614 | if (!sta) { |
| 1615 | tdls_dbg(sdata, |
| 1616 | "Invalid TDLS peer %pM for channel switch cancel\n", |
| 1617 | addr); |
| 1618 | goto out; |
| 1619 | } |
| 1620 | |
| 1621 | if (!test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) { |
| 1622 | tdls_dbg(sdata, "TDLS channel switch not initiated by %pM\n", |
| 1623 | addr); |
| 1624 | goto out; |
| 1625 | } |
| 1626 | |
| 1627 | drv_tdls_cancel_channel_switch(local, sdata, &sta->sta); |
| 1628 | clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL); |
| 1629 | |
| 1630 | out: |
| 1631 | mutex_unlock(&local->sta_mtx); |
| 1632 | } |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1633 | |
| 1634 | static struct sk_buff * |
| 1635 | ieee80211_tdls_ch_sw_resp_tmpl_get(struct sta_info *sta, |
| 1636 | u32 *ch_sw_tm_ie_offset) |
| 1637 | { |
| 1638 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1639 | struct sk_buff *skb; |
| 1640 | u8 extra_ies[2 + sizeof(struct ieee80211_ch_switch_timing)]; |
| 1641 | |
| 1642 | /* initial timing are always zero in the template */ |
| 1643 | iee80211_tdls_add_ch_switch_timing(extra_ies, 0, 0); |
| 1644 | |
| 1645 | skb = ieee80211_tdls_build_mgmt_packet_data(sdata, sta->sta.addr, |
| 1646 | WLAN_TDLS_CHANNEL_SWITCH_RESPONSE, |
| 1647 | 0, 0, !sta->sta.tdls_initiator, |
| 1648 | extra_ies, sizeof(extra_ies), 0, NULL); |
| 1649 | if (!skb) |
| 1650 | return NULL; |
| 1651 | |
| 1652 | skb = ieee80211_build_data_template(sdata, skb, 0); |
| 1653 | if (IS_ERR(skb)) { |
| 1654 | tdls_dbg(sdata, |
| 1655 | "Failed building TDLS channel switch resp frame\n"); |
| 1656 | return NULL; |
| 1657 | } |
| 1658 | |
| 1659 | if (ch_sw_tm_ie_offset) { |
| 1660 | const u8 *tm_ie = ieee80211_tdls_find_sw_timing_ie(skb); |
| 1661 | |
| 1662 | if (!tm_ie) { |
| 1663 | tdls_dbg(sdata, |
| 1664 | "No switch timing IE in TDLS switch resp\n"); |
| 1665 | dev_kfree_skb_any(skb); |
| 1666 | return NULL; |
| 1667 | } |
| 1668 | |
| 1669 | *ch_sw_tm_ie_offset = tm_ie - skb->data; |
| 1670 | } |
| 1671 | |
| 1672 | tdls_dbg(sdata, "TDLS get channel switch response template for %pM\n", |
| 1673 | sta->sta.addr); |
| 1674 | return skb; |
| 1675 | } |
| 1676 | |
| 1677 | static int |
| 1678 | ieee80211_process_tdls_channel_switch_resp(struct ieee80211_sub_if_data *sdata, |
| 1679 | struct sk_buff *skb) |
| 1680 | { |
| 1681 | struct ieee80211_local *local = sdata->local; |
| 1682 | struct ieee802_11_elems elems; |
| 1683 | struct sta_info *sta; |
| 1684 | struct ieee80211_tdls_data *tf = (void *)skb->data; |
| 1685 | bool local_initiator; |
| 1686 | struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); |
| 1687 | int baselen = offsetof(typeof(*tf), u.chan_switch_resp.variable); |
| 1688 | struct ieee80211_tdls_ch_sw_params params = {}; |
| 1689 | int ret; |
| 1690 | |
| 1691 | params.action_code = WLAN_TDLS_CHANNEL_SWITCH_RESPONSE; |
| 1692 | params.timestamp = rx_status->device_timestamp; |
| 1693 | |
| 1694 | if (skb->len < baselen) { |
| 1695 | tdls_dbg(sdata, "TDLS channel switch resp too short: %d\n", |
| 1696 | skb->len); |
| 1697 | return -EINVAL; |
| 1698 | } |
| 1699 | |
| 1700 | mutex_lock(&local->sta_mtx); |
| 1701 | sta = sta_info_get(sdata, tf->sa); |
| 1702 | if (!sta || !test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH)) { |
| 1703 | tdls_dbg(sdata, "TDLS chan switch from non-peer sta %pM\n", |
| 1704 | tf->sa); |
| 1705 | ret = -EINVAL; |
| 1706 | goto out; |
| 1707 | } |
| 1708 | |
| 1709 | params.sta = &sta->sta; |
| 1710 | params.status = le16_to_cpu(tf->u.chan_switch_resp.status_code); |
| 1711 | if (params.status != 0) { |
| 1712 | ret = 0; |
| 1713 | goto call_drv; |
| 1714 | } |
| 1715 | |
| 1716 | ieee802_11_parse_elems(tf->u.chan_switch_resp.variable, |
| 1717 | skb->len - baselen, false, &elems); |
| 1718 | if (elems.parse_error) { |
| 1719 | tdls_dbg(sdata, "Invalid IEs in TDLS channel switch resp\n"); |
| 1720 | ret = -EINVAL; |
| 1721 | goto out; |
| 1722 | } |
| 1723 | |
| 1724 | if (!elems.ch_sw_timing || !elems.lnk_id) { |
| 1725 | tdls_dbg(sdata, "TDLS channel switch resp - missing IEs\n"); |
| 1726 | ret = -EINVAL; |
| 1727 | goto out; |
| 1728 | } |
| 1729 | |
| 1730 | /* validate the initiator is set correctly */ |
| 1731 | local_initiator = |
| 1732 | !memcmp(elems.lnk_id->init_sta, sdata->vif.addr, ETH_ALEN); |
| 1733 | if (local_initiator == sta->sta.tdls_initiator) { |
| 1734 | tdls_dbg(sdata, "TDLS chan switch invalid lnk-id initiator\n"); |
| 1735 | ret = -EINVAL; |
| 1736 | goto out; |
| 1737 | } |
| 1738 | |
| 1739 | params.switch_time = le16_to_cpu(elems.ch_sw_timing->switch_time); |
| 1740 | params.switch_timeout = le16_to_cpu(elems.ch_sw_timing->switch_timeout); |
| 1741 | |
| 1742 | params.tmpl_skb = |
| 1743 | ieee80211_tdls_ch_sw_resp_tmpl_get(sta, ¶ms.ch_sw_tm_ie); |
| 1744 | if (!params.tmpl_skb) { |
| 1745 | ret = -ENOENT; |
| 1746 | goto out; |
| 1747 | } |
| 1748 | |
| 1749 | call_drv: |
| 1750 | drv_tdls_recv_channel_switch(sdata->local, sdata, ¶ms); |
| 1751 | |
| 1752 | tdls_dbg(sdata, |
| 1753 | "TDLS channel switch response received from %pM status %d\n", |
| 1754 | tf->sa, params.status); |
| 1755 | |
| 1756 | out: |
| 1757 | mutex_unlock(&local->sta_mtx); |
| 1758 | dev_kfree_skb_any(params.tmpl_skb); |
| 1759 | return ret; |
| 1760 | } |
| 1761 | |
| 1762 | static int |
| 1763 | ieee80211_process_tdls_channel_switch_req(struct ieee80211_sub_if_data *sdata, |
| 1764 | struct sk_buff *skb) |
| 1765 | { |
| 1766 | struct ieee80211_local *local = sdata->local; |
| 1767 | struct ieee802_11_elems elems; |
| 1768 | struct cfg80211_chan_def chandef; |
| 1769 | struct ieee80211_channel *chan; |
| 1770 | enum nl80211_channel_type chan_type; |
| 1771 | int freq; |
| 1772 | u8 target_channel, oper_class; |
| 1773 | bool local_initiator; |
| 1774 | struct sta_info *sta; |
| 1775 | enum ieee80211_band band; |
| 1776 | struct ieee80211_tdls_data *tf = (void *)skb->data; |
| 1777 | struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); |
| 1778 | int baselen = offsetof(typeof(*tf), u.chan_switch_req.variable); |
| 1779 | struct ieee80211_tdls_ch_sw_params params = {}; |
| 1780 | int ret = 0; |
| 1781 | |
| 1782 | params.action_code = WLAN_TDLS_CHANNEL_SWITCH_REQUEST; |
| 1783 | params.timestamp = rx_status->device_timestamp; |
| 1784 | |
| 1785 | if (skb->len < baselen) { |
| 1786 | tdls_dbg(sdata, "TDLS channel switch req too short: %d\n", |
| 1787 | skb->len); |
| 1788 | return -EINVAL; |
| 1789 | } |
| 1790 | |
| 1791 | target_channel = tf->u.chan_switch_req.target_channel; |
| 1792 | oper_class = tf->u.chan_switch_req.oper_class; |
| 1793 | |
| 1794 | /* |
| 1795 | * We can't easily infer the channel band. The operating class is |
| 1796 | * ambiguous - there are multiple tables (US/Europe/JP/Global). The |
| 1797 | * solution here is to treat channels with number >14 as 5GHz ones, |
| 1798 | * and specifically check for the (oper_class, channel) combinations |
| 1799 | * where this doesn't hold. These are thankfully unique according to |
| 1800 | * IEEE802.11-2012. |
| 1801 | * We consider only the 2GHz and 5GHz bands and 20MHz+ channels as |
| 1802 | * valid here. |
| 1803 | */ |
| 1804 | if ((oper_class == 112 || oper_class == 2 || oper_class == 3 || |
| 1805 | oper_class == 4 || oper_class == 5 || oper_class == 6) && |
| 1806 | target_channel < 14) |
| 1807 | band = IEEE80211_BAND_5GHZ; |
| 1808 | else |
| 1809 | band = target_channel < 14 ? IEEE80211_BAND_2GHZ : |
| 1810 | IEEE80211_BAND_5GHZ; |
| 1811 | |
| 1812 | freq = ieee80211_channel_to_frequency(target_channel, band); |
| 1813 | if (freq == 0) { |
| 1814 | tdls_dbg(sdata, "Invalid channel in TDLS chan switch: %d\n", |
| 1815 | target_channel); |
| 1816 | return -EINVAL; |
| 1817 | } |
| 1818 | |
| 1819 | chan = ieee80211_get_channel(sdata->local->hw.wiphy, freq); |
| 1820 | if (!chan) { |
| 1821 | tdls_dbg(sdata, |
| 1822 | "Unsupported channel for TDLS chan switch: %d\n", |
| 1823 | target_channel); |
| 1824 | return -EINVAL; |
| 1825 | } |
| 1826 | |
| 1827 | ieee802_11_parse_elems(tf->u.chan_switch_req.variable, |
| 1828 | skb->len - baselen, false, &elems); |
| 1829 | if (elems.parse_error) { |
| 1830 | tdls_dbg(sdata, "Invalid IEs in TDLS channel switch req\n"); |
| 1831 | return -EINVAL; |
| 1832 | } |
| 1833 | |
| 1834 | if (!elems.ch_sw_timing || !elems.lnk_id) { |
| 1835 | tdls_dbg(sdata, "TDLS channel switch req - missing IEs\n"); |
| 1836 | return -EINVAL; |
| 1837 | } |
| 1838 | |
Arik Nemtsov | 42d8d78 | 2015-07-08 15:41:46 +0300 | [diff] [blame] | 1839 | if (!elems.sec_chan_offs) { |
| 1840 | chan_type = NL80211_CHAN_HT20; |
| 1841 | } else { |
| 1842 | switch (elems.sec_chan_offs->sec_chan_offs) { |
| 1843 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 1844 | chan_type = NL80211_CHAN_HT40PLUS; |
| 1845 | break; |
| 1846 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 1847 | chan_type = NL80211_CHAN_HT40MINUS; |
| 1848 | break; |
| 1849 | default: |
| 1850 | chan_type = NL80211_CHAN_HT20; |
| 1851 | break; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | cfg80211_chandef_create(&chandef, chan, chan_type); |
| 1856 | |
| 1857 | /* we will be active on the TDLS link */ |
| 1858 | if (!cfg80211_reg_can_beacon_relax(sdata->local->hw.wiphy, &chandef, |
| 1859 | sdata->wdev.iftype)) { |
| 1860 | tdls_dbg(sdata, "TDLS chan switch to forbidden channel\n"); |
| 1861 | return -EINVAL; |
| 1862 | } |
| 1863 | |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1864 | mutex_lock(&local->sta_mtx); |
| 1865 | sta = sta_info_get(sdata, tf->sa); |
| 1866 | if (!sta || !test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH)) { |
| 1867 | tdls_dbg(sdata, "TDLS chan switch from non-peer sta %pM\n", |
| 1868 | tf->sa); |
| 1869 | ret = -EINVAL; |
| 1870 | goto out; |
| 1871 | } |
| 1872 | |
| 1873 | params.sta = &sta->sta; |
| 1874 | |
| 1875 | /* validate the initiator is set correctly */ |
| 1876 | local_initiator = |
| 1877 | !memcmp(elems.lnk_id->init_sta, sdata->vif.addr, ETH_ALEN); |
| 1878 | if (local_initiator == sta->sta.tdls_initiator) { |
| 1879 | tdls_dbg(sdata, "TDLS chan switch invalid lnk-id initiator\n"); |
| 1880 | ret = -EINVAL; |
| 1881 | goto out; |
| 1882 | } |
| 1883 | |
Arik Nemtsov | 42d8d78 | 2015-07-08 15:41:46 +0300 | [diff] [blame] | 1884 | /* peer should have known better */ |
| 1885 | if (!sta->sta.ht_cap.ht_supported && elems.sec_chan_offs && |
| 1886 | elems.sec_chan_offs->sec_chan_offs) { |
| 1887 | tdls_dbg(sdata, "TDLS chan switch - wide chan unsupported\n"); |
| 1888 | ret = -ENOTSUPP; |
| 1889 | goto out; |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1890 | } |
| 1891 | |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1892 | params.chandef = &chandef; |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1893 | params.switch_time = le16_to_cpu(elems.ch_sw_timing->switch_time); |
| 1894 | params.switch_timeout = le16_to_cpu(elems.ch_sw_timing->switch_timeout); |
| 1895 | |
| 1896 | params.tmpl_skb = |
| 1897 | ieee80211_tdls_ch_sw_resp_tmpl_get(sta, |
| 1898 | ¶ms.ch_sw_tm_ie); |
| 1899 | if (!params.tmpl_skb) { |
| 1900 | ret = -ENOENT; |
| 1901 | goto out; |
| 1902 | } |
| 1903 | |
| 1904 | drv_tdls_recv_channel_switch(sdata->local, sdata, ¶ms); |
| 1905 | |
| 1906 | tdls_dbg(sdata, |
| 1907 | "TDLS ch switch request received from %pM ch %d width %d\n", |
| 1908 | tf->sa, params.chandef->chan->center_freq, |
| 1909 | params.chandef->width); |
| 1910 | out: |
| 1911 | mutex_unlock(&local->sta_mtx); |
| 1912 | dev_kfree_skb_any(params.tmpl_skb); |
| 1913 | return ret; |
| 1914 | } |
| 1915 | |
Arik Nemtsov | c8ff71e | 2015-07-08 15:41:45 +0300 | [diff] [blame] | 1916 | static void |
| 1917 | ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata, |
| 1918 | struct sk_buff *skb) |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1919 | { |
| 1920 | struct ieee80211_tdls_data *tf = (void *)skb->data; |
| 1921 | struct wiphy *wiphy = sdata->local->hw.wiphy; |
| 1922 | |
Arik Nemtsov | c8ff71e | 2015-07-08 15:41:45 +0300 | [diff] [blame] | 1923 | ASSERT_RTNL(); |
| 1924 | |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 1925 | /* make sure the driver supports it */ |
| 1926 | if (!(wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 1927 | return; |
| 1928 | |
| 1929 | /* we want to access the entire packet */ |
| 1930 | if (skb_linearize(skb)) |
| 1931 | return; |
| 1932 | /* |
| 1933 | * The packet/size was already validated by mac80211 Rx path, only look |
| 1934 | * at the action type. |
| 1935 | */ |
| 1936 | switch (tf->action_code) { |
| 1937 | case WLAN_TDLS_CHANNEL_SWITCH_REQUEST: |
| 1938 | ieee80211_process_tdls_channel_switch_req(sdata, skb); |
| 1939 | break; |
| 1940 | case WLAN_TDLS_CHANNEL_SWITCH_RESPONSE: |
| 1941 | ieee80211_process_tdls_channel_switch_resp(sdata, skb); |
| 1942 | break; |
| 1943 | default: |
| 1944 | WARN_ON_ONCE(1); |
| 1945 | return; |
| 1946 | } |
| 1947 | } |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 1948 | |
| 1949 | void ieee80211_teardown_tdls_peers(struct ieee80211_sub_if_data *sdata) |
| 1950 | { |
| 1951 | struct sta_info *sta; |
| 1952 | u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED; |
| 1953 | |
| 1954 | rcu_read_lock(); |
| 1955 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { |
| 1956 | if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || |
| 1957 | !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1958 | continue; |
| 1959 | |
| 1960 | ieee80211_tdls_oper_request(&sdata->vif, sta->sta.addr, |
| 1961 | NL80211_TDLS_TEARDOWN, reason, |
| 1962 | GFP_ATOMIC); |
| 1963 | } |
| 1964 | rcu_read_unlock(); |
| 1965 | } |
Arik Nemtsov | c8ff71e | 2015-07-08 15:41:45 +0300 | [diff] [blame] | 1966 | |
| 1967 | void ieee80211_tdls_chsw_work(struct work_struct *wk) |
| 1968 | { |
| 1969 | struct ieee80211_local *local = |
| 1970 | container_of(wk, struct ieee80211_local, tdls_chsw_work); |
| 1971 | struct ieee80211_sub_if_data *sdata; |
| 1972 | struct sk_buff *skb; |
| 1973 | struct ieee80211_tdls_data *tf; |
| 1974 | |
| 1975 | rtnl_lock(); |
| 1976 | while ((skb = skb_dequeue(&local->skb_queue_tdls_chsw))) { |
| 1977 | tf = (struct ieee80211_tdls_data *)skb->data; |
| 1978 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 1979 | if (!ieee80211_sdata_running(sdata) || |
| 1980 | sdata->vif.type != NL80211_IFTYPE_STATION || |
| 1981 | !ether_addr_equal(tf->da, sdata->vif.addr)) |
| 1982 | continue; |
| 1983 | |
| 1984 | ieee80211_process_tdls_channel_switch(sdata, skb); |
| 1985 | break; |
| 1986 | } |
| 1987 | |
| 1988 | kfree_skb(skb); |
| 1989 | } |
| 1990 | rtnl_unlock(); |
| 1991 | } |