1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * IBSS mode implementation 4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi> 5 * Copyright 2004, Instant802 Networks, Inc. 6 * Copyright 2005, Devicescape Software, Inc. 7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net> 9 * Copyright 2009, Johannes Berg <johannes@sipsolutions.net> 10 * Copyright 2013-2014 Intel Mobile Communications GmbH 11 * Copyright(c) 2016 Intel Deutschland GmbH 12 * Copyright(c) 2018-2026 Intel Corporation 13 */ 14 15 #include <linux/delay.h> 16 #include <linux/slab.h> 17 #include <linux/if_ether.h> 18 #include <linux/skbuff.h> 19 #include <linux/if_arp.h> 20 #include <linux/etherdevice.h> 21 #include <linux/rtnetlink.h> 22 #include <net/mac80211.h> 23 24 #include "ieee80211_i.h" 25 #include "driver-ops.h" 26 #include "rate.h" 27 28 #define IEEE80211_SCAN_INTERVAL (2 * HZ) 29 #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) 30 31 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) 32 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) 33 #define IEEE80211_IBSS_RSN_INACTIVITY_LIMIT (10 * HZ) 34 35 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 36 37 static struct beacon_data * 38 ieee80211_ibss_build_presp(struct ieee80211_sub_if_data *sdata, 39 const int beacon_int, const u32 basic_rates, 40 const u16 capability, u64 tsf, 41 struct cfg80211_chan_def *chandef, 42 bool *have_higher_than_11mbit, 43 struct cfg80211_csa_settings *csa_settings) 44 { 45 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 46 struct ieee80211_local *local = sdata->local; 47 int rates_n = 0, i, ri; 48 struct ieee80211_mgmt *mgmt; 49 u8 *pos; 50 struct ieee80211_supported_band *sband; 51 u32 rates = 0, rates_added = 0; 52 struct beacon_data *presp; 53 int frame_len; 54 55 /* Build IBSS probe response */ 56 frame_len = sizeof(struct ieee80211_hdr_3addr) + 57 12 /* struct ieee80211_mgmt.u.beacon */ + 58 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ + 59 2 + 8 /* max Supported Rates */ + 60 3 /* max DS params */ + 61 4 /* IBSS params */ + 62 5 /* Channel Switch Announcement */ + 63 2 + (IEEE80211_MAX_SUPP_RATES - 8) + 64 2 + sizeof(struct ieee80211_ht_cap) + 65 2 + sizeof(struct ieee80211_ht_operation) + 66 2 + sizeof(struct ieee80211_vht_cap) + 67 2 + sizeof(struct ieee80211_vht_operation) + 68 ifibss->ie_len; 69 presp = kzalloc(sizeof(*presp) + frame_len, GFP_KERNEL); 70 if (!presp) 71 return NULL; 72 73 presp->head = (void *)(presp + 1); 74 75 mgmt = (void *) presp->head; 76 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 77 IEEE80211_STYPE_PROBE_RESP); 78 eth_broadcast_addr(mgmt->da); 79 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 80 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); 81 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int); 82 mgmt->u.beacon.timestamp = cpu_to_le64(tsf); 83 mgmt->u.beacon.capab_info = cpu_to_le16(capability); 84 85 pos = (u8 *)mgmt + offsetof(struct ieee80211_mgmt, u.beacon.variable); 86 87 *pos++ = WLAN_EID_SSID; 88 *pos++ = ifibss->ssid_len; 89 memcpy(pos, ifibss->ssid, ifibss->ssid_len); 90 pos += ifibss->ssid_len; 91 92 sband = local->hw.wiphy->bands[chandef->chan->band]; 93 rates_n = 0; 94 if (have_higher_than_11mbit) 95 *have_higher_than_11mbit = false; 96 97 for (i = 0; i < sband->n_bitrates; i++) { 98 if (sband->bitrates[i].bitrate > 110 && 99 have_higher_than_11mbit) 100 *have_higher_than_11mbit = true; 101 102 rates |= BIT(i); 103 rates_n++; 104 } 105 106 *pos++ = WLAN_EID_SUPP_RATES; 107 *pos++ = min_t(int, 8, rates_n); 108 for (ri = 0; ri < sband->n_bitrates; ri++) { 109 int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate, 5); 110 u8 basic = 0; 111 if (!(rates & BIT(ri))) 112 continue; 113 114 if (basic_rates & BIT(ri)) 115 basic = 0x80; 116 *pos++ = basic | (u8) rate; 117 if (++rates_added == 8) { 118 ri++; /* continue at next rate for EXT_SUPP_RATES */ 119 break; 120 } 121 } 122 123 if (sband->band == NL80211_BAND_2GHZ) { 124 *pos++ = WLAN_EID_DS_PARAMS; 125 *pos++ = 1; 126 *pos++ = ieee80211_frequency_to_channel( 127 chandef->chan->center_freq); 128 } 129 130 *pos++ = WLAN_EID_IBSS_PARAMS; 131 *pos++ = 2; 132 /* FIX: set ATIM window based on scan results */ 133 *pos++ = 0; 134 *pos++ = 0; 135 136 if (csa_settings) { 137 *pos++ = WLAN_EID_CHANNEL_SWITCH; 138 *pos++ = 3; 139 *pos++ = csa_settings->block_tx ? 1 : 0; 140 *pos++ = ieee80211_frequency_to_channel( 141 csa_settings->chandef.chan->center_freq); 142 presp->cntdwn_counter_offsets[0] = (pos - presp->head); 143 *pos++ = csa_settings->count; 144 presp->cntdwn_current_counter = csa_settings->count; 145 } 146 147 /* put the remaining rates in WLAN_EID_EXT_SUPP_RATES */ 148 if (rates_n > 8) { 149 *pos++ = WLAN_EID_EXT_SUPP_RATES; 150 *pos++ = rates_n - 8; 151 for (; ri < sband->n_bitrates; ri++) { 152 int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate, 5); 153 u8 basic = 0; 154 if (!(rates & BIT(ri))) 155 continue; 156 157 if (basic_rates & BIT(ri)) 158 basic = 0x80; 159 *pos++ = basic | (u8) rate; 160 } 161 } 162 163 if (ifibss->ie_len) { 164 memcpy(pos, ifibss->ie, ifibss->ie_len); 165 pos += ifibss->ie_len; 166 } 167 168 /* add HT capability and information IEs */ 169 if (chandef->width != NL80211_CHAN_WIDTH_20_NOHT && 170 chandef->width != NL80211_CHAN_WIDTH_5 && 171 chandef->width != NL80211_CHAN_WIDTH_10 && 172 sband->ht_cap.ht_supported) { 173 struct ieee80211_sta_ht_cap ht_cap; 174 175 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); 176 ieee80211_apply_htcap_overrides(sdata, &ht_cap); 177 178 pos = ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap); 179 /* 180 * Note: According to 802.11n-2009 9.13.3.1, HT Protection 181 * field and RIFS Mode are reserved in IBSS mode, therefore 182 * keep them at 0 183 */ 184 pos = ieee80211_ie_build_ht_oper(pos, &sband->ht_cap, 185 chandef, 0, false); 186 187 /* add VHT capability and information IEs */ 188 if (chandef->width != NL80211_CHAN_WIDTH_20 && 189 chandef->width != NL80211_CHAN_WIDTH_40 && 190 sband->vht_cap.vht_supported) { 191 pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, 192 sband->vht_cap.cap); 193 pos = ieee80211_ie_build_vht_oper(pos, &sband->vht_cap, 194 chandef); 195 } 196 } 197 198 if (local->hw.queues >= IEEE80211_NUM_ACS) 199 pos = ieee80211_add_wmm_info_ie(pos, 0); /* U-APSD not in use */ 200 201 presp->head_len = pos - presp->head; 202 if (WARN_ON(presp->head_len > frame_len)) 203 goto error; 204 205 return presp; 206 error: 207 kfree(presp); 208 return NULL; 209 } 210 211 static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 212 const u8 *bssid, const int beacon_int, 213 struct cfg80211_chan_def *req_chandef, 214 const u32 basic_rates, 215 const u16 capability, u64 tsf, 216 bool creator) 217 { 218 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 219 struct ieee80211_local *local = sdata->local; 220 struct ieee80211_mgmt *mgmt; 221 struct cfg80211_bss *bss; 222 u64 bss_change; 223 struct ieee80211_chan_req chanreq = {}; 224 struct ieee80211_channel *chan; 225 struct beacon_data *presp; 226 struct cfg80211_inform_bss bss_meta = {}; 227 bool have_higher_than_11mbit; 228 bool radar_required; 229 int err; 230 231 lockdep_assert_wiphy(local->hw.wiphy); 232 233 /* Reset own TSF to allow time synchronization work. */ 234 drv_reset_tsf(local, sdata); 235 236 if (!ether_addr_equal(ifibss->bssid, bssid)) 237 sta_info_flush(sdata, -1); 238 239 /* if merging, indicate to driver that we leave the old IBSS */ 240 if (sdata->vif.cfg.ibss_joined) { 241 sdata->vif.cfg.ibss_joined = false; 242 sdata->vif.cfg.ibss_creator = false; 243 sdata->vif.bss_conf.enable_beacon = false; 244 netif_carrier_off(sdata->dev); 245 synchronize_net(); 246 ieee80211_bss_info_change_notify(sdata, 247 BSS_CHANGED_IBSS | 248 BSS_CHANGED_BEACON_ENABLED); 249 drv_leave_ibss(local, sdata); 250 } 251 252 presp = sdata_dereference(ifibss->presp, sdata); 253 RCU_INIT_POINTER(ifibss->presp, NULL); 254 if (presp) 255 kfree_rcu(presp, rcu_head); 256 257 /* make a copy of the chandef, it could be modified below. */ 258 chanreq.oper = *req_chandef; 259 chan = chanreq.oper.chan; 260 if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chanreq.oper, 261 NL80211_IFTYPE_ADHOC)) { 262 if (chanreq.oper.width == NL80211_CHAN_WIDTH_5 || 263 chanreq.oper.width == NL80211_CHAN_WIDTH_10 || 264 chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT || 265 chanreq.oper.width == NL80211_CHAN_WIDTH_20) { 266 sdata_info(sdata, 267 "Failed to join IBSS, beacons forbidden\n"); 268 return; 269 } 270 chanreq.oper.width = NL80211_CHAN_WIDTH_20; 271 chanreq.oper.center_freq1 = chan->center_freq; 272 /* check again for downgraded chandef */ 273 if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chanreq.oper, 274 NL80211_IFTYPE_ADHOC)) { 275 sdata_info(sdata, 276 "Failed to join IBSS, beacons forbidden\n"); 277 return; 278 } 279 } 280 281 err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy, 282 &chanreq.oper, NL80211_IFTYPE_ADHOC); 283 if (err < 0) { 284 sdata_info(sdata, 285 "Failed to join IBSS, invalid chandef\n"); 286 return; 287 } 288 if (err > 0 && !ifibss->userspace_handles_dfs) { 289 sdata_info(sdata, 290 "Failed to join IBSS, DFS channel without control program\n"); 291 return; 292 } 293 294 radar_required = err; 295 296 if (ieee80211_link_use_channel(&sdata->deflink, &chanreq, 297 ifibss->fixed_channel ? 298 IEEE80211_CHANCTX_SHARED : 299 IEEE80211_CHANCTX_EXCLUSIVE)) { 300 sdata_info(sdata, "Failed to join IBSS, no channel context\n"); 301 return; 302 } 303 sdata->deflink.radar_required = radar_required; 304 305 memcpy(ifibss->bssid, bssid, ETH_ALEN); 306 307 presp = ieee80211_ibss_build_presp(sdata, beacon_int, basic_rates, 308 capability, tsf, &chanreq.oper, 309 &have_higher_than_11mbit, NULL); 310 if (!presp) 311 return; 312 313 rcu_assign_pointer(ifibss->presp, presp); 314 mgmt = (void *)presp->head; 315 316 sdata->vif.bss_conf.enable_beacon = true; 317 sdata->vif.bss_conf.beacon_int = beacon_int; 318 sdata->vif.bss_conf.basic_rates = basic_rates; 319 sdata->vif.cfg.ssid_len = ifibss->ssid_len; 320 memcpy(sdata->vif.cfg.ssid, ifibss->ssid, ifibss->ssid_len); 321 bss_change = BSS_CHANGED_BEACON_INT; 322 bss_change |= ieee80211_reset_erp_info(sdata); 323 bss_change |= BSS_CHANGED_BSSID; 324 bss_change |= BSS_CHANGED_BEACON; 325 bss_change |= BSS_CHANGED_BEACON_ENABLED; 326 bss_change |= BSS_CHANGED_BASIC_RATES; 327 bss_change |= BSS_CHANGED_HT; 328 bss_change |= BSS_CHANGED_IBSS; 329 bss_change |= BSS_CHANGED_SSID; 330 331 /* 332 * In 5 GHz/802.11a, we can always use short slot time. 333 * (IEEE 802.11-2012 18.3.8.7) 334 * 335 * In 2.4GHz, we must always use long slots in IBSS for compatibility 336 * reasons. 337 * (IEEE 802.11-2012 19.4.5) 338 * 339 * HT follows these specifications (IEEE 802.11-2012 20.3.18) 340 */ 341 sdata->vif.bss_conf.use_short_slot = chan->band == NL80211_BAND_5GHZ; 342 bss_change |= BSS_CHANGED_ERP_SLOT; 343 344 /* cf. IEEE 802.11 9.2.12 */ 345 sdata->deflink.operating_11g_mode = 346 chan->band == NL80211_BAND_2GHZ && have_higher_than_11mbit; 347 348 ieee80211_set_wmm_default(&sdata->deflink, true, false); 349 350 sdata->vif.cfg.ibss_joined = true; 351 sdata->vif.cfg.ibss_creator = creator; 352 353 err = drv_join_ibss(local, sdata); 354 if (err) { 355 sdata->vif.cfg.ibss_joined = false; 356 sdata->vif.cfg.ibss_creator = false; 357 sdata->vif.bss_conf.enable_beacon = false; 358 sdata->vif.cfg.ssid_len = 0; 359 RCU_INIT_POINTER(ifibss->presp, NULL); 360 kfree_rcu(presp, rcu_head); 361 ieee80211_link_release_channel(&sdata->deflink); 362 sdata_info(sdata, "Failed to join IBSS, driver failure: %d\n", 363 err); 364 return; 365 } 366 367 ieee80211_bss_info_change_notify(sdata, bss_change); 368 369 ifibss->state = IEEE80211_IBSS_MLME_JOINED; 370 mod_timer(&ifibss->timer, 371 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); 372 373 bss_meta.chan = chan; 374 bss = cfg80211_inform_bss_frame_data(local->hw.wiphy, &bss_meta, mgmt, 375 presp->head_len, GFP_KERNEL); 376 377 cfg80211_put_bss(local->hw.wiphy, bss); 378 netif_carrier_on(sdata->dev); 379 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, chan, GFP_KERNEL); 380 } 381 382 static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 383 struct ieee80211_bss *bss) 384 { 385 struct cfg80211_bss *cbss = 386 container_of((void *)bss, struct cfg80211_bss, priv); 387 struct ieee80211_supported_band *sband; 388 struct cfg80211_chan_def chandef; 389 u32 basic_rates; 390 int i, j; 391 u16 beacon_int = cbss->beacon_interval; 392 const struct cfg80211_bss_ies *ies; 393 enum nl80211_channel_type chan_type; 394 u64 tsf; 395 396 lockdep_assert_wiphy(sdata->local->hw.wiphy); 397 398 if (beacon_int < 10) 399 beacon_int = 10; 400 401 switch (sdata->u.ibss.chandef.width) { 402 case NL80211_CHAN_WIDTH_20_NOHT: 403 case NL80211_CHAN_WIDTH_20: 404 case NL80211_CHAN_WIDTH_40: 405 chan_type = cfg80211_get_chandef_type(&sdata->u.ibss.chandef); 406 cfg80211_chandef_create(&chandef, cbss->channel, chan_type); 407 break; 408 case NL80211_CHAN_WIDTH_5: 409 case NL80211_CHAN_WIDTH_10: 410 cfg80211_chandef_create(&chandef, cbss->channel, 411 NL80211_CHAN_NO_HT); 412 chandef.width = sdata->u.ibss.chandef.width; 413 break; 414 case NL80211_CHAN_WIDTH_80: 415 case NL80211_CHAN_WIDTH_80P80: 416 case NL80211_CHAN_WIDTH_160: 417 chandef = sdata->u.ibss.chandef; 418 chandef.chan = cbss->channel; 419 break; 420 default: 421 /* fall back to 20 MHz for unsupported modes */ 422 cfg80211_chandef_create(&chandef, cbss->channel, 423 NL80211_CHAN_NO_HT); 424 break; 425 } 426 427 sband = sdata->local->hw.wiphy->bands[cbss->channel->band]; 428 429 basic_rates = 0; 430 431 for (i = 0; i < bss->supp_rates_len; i++) { 432 int rate = bss->supp_rates[i] & 0x7f; 433 bool is_basic = !!(bss->supp_rates[i] & 0x80); 434 435 for (j = 0; j < sband->n_bitrates; j++) { 436 int brate; 437 438 brate = DIV_ROUND_UP(sband->bitrates[j].bitrate, 5); 439 if (brate == rate) { 440 if (is_basic) 441 basic_rates |= BIT(j); 442 break; 443 } 444 } 445 } 446 447 rcu_read_lock(); 448 ies = rcu_dereference(cbss->ies); 449 tsf = ies->tsf; 450 rcu_read_unlock(); 451 452 __ieee80211_sta_join_ibss(sdata, cbss->bssid, 453 beacon_int, 454 &chandef, 455 basic_rates, 456 cbss->capability, 457 tsf, false); 458 } 459 460 int ieee80211_ibss_csa_beacon(struct ieee80211_sub_if_data *sdata, 461 struct cfg80211_csa_settings *csa_settings, 462 u64 *changed) 463 { 464 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 465 struct beacon_data *presp, *old_presp; 466 struct cfg80211_bss *cbss; 467 const struct cfg80211_bss_ies *ies; 468 u16 capability = WLAN_CAPABILITY_IBSS; 469 u64 tsf; 470 471 lockdep_assert_wiphy(sdata->local->hw.wiphy); 472 473 if (ifibss->privacy) 474 capability |= WLAN_CAPABILITY_PRIVACY; 475 476 cbss = cfg80211_get_bss(sdata->local->hw.wiphy, ifibss->chandef.chan, 477 ifibss->bssid, ifibss->ssid, 478 ifibss->ssid_len, IEEE80211_BSS_TYPE_IBSS, 479 IEEE80211_PRIVACY(ifibss->privacy)); 480 481 if (unlikely(!cbss)) 482 return -EINVAL; 483 484 rcu_read_lock(); 485 ies = rcu_dereference(cbss->ies); 486 tsf = ies->tsf; 487 rcu_read_unlock(); 488 cfg80211_put_bss(sdata->local->hw.wiphy, cbss); 489 490 old_presp = sdata_dereference(ifibss->presp, sdata); 491 492 presp = ieee80211_ibss_build_presp(sdata, 493 sdata->vif.bss_conf.beacon_int, 494 sdata->vif.bss_conf.basic_rates, 495 capability, tsf, &ifibss->chandef, 496 NULL, csa_settings); 497 if (!presp) 498 return -ENOMEM; 499 500 rcu_assign_pointer(ifibss->presp, presp); 501 if (old_presp) 502 kfree_rcu(old_presp, rcu_head); 503 504 *changed |= BSS_CHANGED_BEACON; 505 return 0; 506 } 507 508 int ieee80211_ibss_finish_csa(struct ieee80211_sub_if_data *sdata, u64 *changed) 509 { 510 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 511 struct cfg80211_bss *cbss; 512 513 lockdep_assert_wiphy(sdata->local->hw.wiphy); 514 515 /* When not connected/joined, sending CSA doesn't make sense. */ 516 if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) 517 return -ENOLINK; 518 519 /* update cfg80211 bss information with the new channel */ 520 if (!is_zero_ether_addr(ifibss->bssid)) { 521 cbss = cfg80211_get_bss(sdata->local->hw.wiphy, 522 ifibss->chandef.chan, 523 ifibss->bssid, ifibss->ssid, 524 ifibss->ssid_len, 525 IEEE80211_BSS_TYPE_IBSS, 526 IEEE80211_PRIVACY(ifibss->privacy)); 527 /* XXX: should not really modify cfg80211 data */ 528 if (cbss) { 529 cbss->channel = sdata->deflink.csa.chanreq.oper.chan; 530 cfg80211_put_bss(sdata->local->hw.wiphy, cbss); 531 } 532 } 533 534 ifibss->chandef = sdata->deflink.csa.chanreq.oper; 535 536 /* generate the beacon */ 537 return ieee80211_ibss_csa_beacon(sdata, NULL, changed); 538 } 539 540 void ieee80211_ibss_stop(struct ieee80211_sub_if_data *sdata) 541 { 542 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 543 544 wiphy_work_cancel(sdata->local->hw.wiphy, 545 &ifibss->csa_connection_drop_work); 546 } 547 548 static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta) 549 __acquires(RCU) 550 { 551 struct ieee80211_sub_if_data *sdata = sta->sdata; 552 u8 addr[ETH_ALEN]; 553 554 memcpy(addr, sta->sta.addr, ETH_ALEN); 555 556 ibss_dbg(sdata, "Adding new IBSS station %pM\n", addr); 557 558 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); 559 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); 560 /* authorize the station only if the network is not RSN protected. If 561 * not wait for the userspace to authorize it */ 562 if (!sta->sdata->u.ibss.control_port) 563 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED); 564 565 rate_control_rate_init(&sta->deflink); 566 567 /* If it fails, maybe we raced another insertion? */ 568 if (sta_info_insert_rcu(sta)) 569 return sta_info_get(sdata, addr); 570 return sta; 571 } 572 573 static struct sta_info * 574 ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, const u8 *bssid, 575 const u8 *addr, u32 supp_rates) 576 __acquires(RCU) 577 { 578 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 579 struct ieee80211_local *local = sdata->local; 580 struct sta_info *sta; 581 struct ieee80211_chanctx_conf *chanctx_conf; 582 struct ieee80211_supported_band *sband; 583 int band; 584 585 /* 586 * XXX: Consider removing the least recently used entry and 587 * allow new one to be added. 588 */ 589 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { 590 net_info_ratelimited("%s: No room for a new IBSS STA entry %pM\n", 591 sdata->name, addr); 592 rcu_read_lock(); 593 return NULL; 594 } 595 596 if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) { 597 rcu_read_lock(); 598 return NULL; 599 } 600 601 if (!ether_addr_equal(bssid, sdata->u.ibss.bssid)) { 602 rcu_read_lock(); 603 return NULL; 604 } 605 606 rcu_read_lock(); 607 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 608 if (WARN_ON_ONCE(!chanctx_conf)) 609 return NULL; 610 band = chanctx_conf->def.chan->band; 611 rcu_read_unlock(); 612 613 sta = sta_info_alloc(sdata, addr, GFP_KERNEL); 614 if (!sta) { 615 rcu_read_lock(); 616 return NULL; 617 } 618 619 /* make sure mandatory rates are always added */ 620 sband = local->hw.wiphy->bands[band]; 621 sta->sta.deflink.supp_rates[band] = supp_rates | 622 ieee80211_mandatory_rates(sband); 623 624 return ieee80211_ibss_finish_sta(sta); 625 } 626 627 static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) 628 { 629 struct ieee80211_local *local = sdata->local; 630 int active = 0; 631 struct sta_info *sta; 632 633 lockdep_assert_wiphy(sdata->local->hw.wiphy); 634 635 rcu_read_lock(); 636 637 list_for_each_entry_rcu(sta, &local->sta_list, list) { 638 unsigned long last_active = ieee80211_sta_last_active(sta, -1); 639 640 if (sta->sdata == sdata && 641 time_is_after_jiffies(last_active + 642 IEEE80211_IBSS_MERGE_INTERVAL)) { 643 active++; 644 break; 645 } 646 } 647 648 rcu_read_unlock(); 649 650 return active; 651 } 652 653 static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata) 654 { 655 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 656 struct ieee80211_local *local = sdata->local; 657 struct cfg80211_bss *cbss; 658 struct beacon_data *presp; 659 struct sta_info *sta; 660 661 lockdep_assert_wiphy(local->hw.wiphy); 662 663 if (!is_zero_ether_addr(ifibss->bssid)) { 664 cbss = cfg80211_get_bss(local->hw.wiphy, ifibss->chandef.chan, 665 ifibss->bssid, ifibss->ssid, 666 ifibss->ssid_len, 667 IEEE80211_BSS_TYPE_IBSS, 668 IEEE80211_PRIVACY(ifibss->privacy)); 669 670 if (cbss) { 671 cfg80211_unlink_bss(local->hw.wiphy, cbss); 672 cfg80211_put_bss(sdata->local->hw.wiphy, cbss); 673 } 674 } 675 676 ifibss->state = IEEE80211_IBSS_MLME_SEARCH; 677 678 sta_info_flush(sdata, -1); 679 680 spin_lock_bh(&ifibss->incomplete_lock); 681 while (!list_empty(&ifibss->incomplete_stations)) { 682 sta = list_first_entry(&ifibss->incomplete_stations, 683 struct sta_info, list); 684 list_del(&sta->list); 685 spin_unlock_bh(&ifibss->incomplete_lock); 686 687 sta_info_free(local, sta); 688 spin_lock_bh(&ifibss->incomplete_lock); 689 } 690 spin_unlock_bh(&ifibss->incomplete_lock); 691 692 netif_carrier_off(sdata->dev); 693 694 sdata->vif.cfg.ibss_joined = false; 695 sdata->vif.cfg.ibss_creator = false; 696 sdata->vif.bss_conf.enable_beacon = false; 697 sdata->vif.cfg.ssid_len = 0; 698 699 /* remove beacon */ 700 presp = sdata_dereference(ifibss->presp, sdata); 701 RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); 702 if (presp) 703 kfree_rcu(presp, rcu_head); 704 705 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); 706 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | 707 BSS_CHANGED_IBSS); 708 drv_leave_ibss(local, sdata); 709 ieee80211_link_release_channel(&sdata->deflink); 710 } 711 712 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy, 713 struct wiphy_work *work) 714 { 715 struct ieee80211_sub_if_data *sdata = 716 container_of(work, struct ieee80211_sub_if_data, 717 u.ibss.csa_connection_drop_work); 718 719 ieee80211_ibss_disconnect(sdata); 720 synchronize_rcu(); 721 skb_queue_purge(&sdata->skb_queue); 722 723 /* trigger a scan to find another IBSS network to join */ 724 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); 725 } 726 727 static void ieee80211_ibss_csa_mark_radar(struct ieee80211_sub_if_data *sdata) 728 { 729 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 730 int err; 731 732 /* if the current channel is a DFS channel, mark the channel as 733 * unavailable. 734 */ 735 err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy, 736 &ifibss->chandef, 737 NL80211_IFTYPE_ADHOC); 738 if (err > 0) 739 cfg80211_radar_event(sdata->local->hw.wiphy, &ifibss->chandef, 740 GFP_ATOMIC); 741 } 742 743 static bool 744 ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata, 745 struct ieee802_11_elems *elems, 746 bool beacon) 747 { 748 struct cfg80211_csa_settings params; 749 struct ieee80211_csa_ie csa_ie; 750 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 751 enum nl80211_channel_type ch_type; 752 int err; 753 struct ieee80211_conn_settings conn = { 754 .mode = IEEE80211_CONN_MODE_HT, 755 .bw_limit = IEEE80211_CONN_BW_LIMIT_40, 756 }; 757 u32 vht_cap_info = 0; 758 759 lockdep_assert_wiphy(sdata->local->hw.wiphy); 760 761 switch (ifibss->chandef.width) { 762 case NL80211_CHAN_WIDTH_5: 763 case NL80211_CHAN_WIDTH_10: 764 case NL80211_CHAN_WIDTH_20_NOHT: 765 conn.mode = IEEE80211_CONN_MODE_LEGACY; 766 fallthrough; 767 case NL80211_CHAN_WIDTH_20: 768 conn.bw_limit = IEEE80211_CONN_BW_LIMIT_20; 769 break; 770 default: 771 break; 772 } 773 774 if (elems->vht_cap_elem) 775 vht_cap_info = le32_to_cpu(elems->vht_cap_elem->vht_cap_info); 776 777 memset(¶ms, 0, sizeof(params)); 778 err = ieee80211_parse_ch_switch_ie(sdata, elems, 779 ifibss->chandef.chan->band, 780 vht_cap_info, &conn, 781 ifibss->bssid, false, 782 &csa_ie); 783 /* can't switch to destination channel, fail */ 784 if (err < 0) 785 goto disconnect; 786 787 /* did not contain a CSA */ 788 if (err) 789 return false; 790 791 /* channel switch is not supported, disconnect */ 792 if (!(sdata->local->hw.wiphy->flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 793 goto disconnect; 794 795 params.count = csa_ie.count; 796 params.chandef = csa_ie.chanreq.oper; 797 798 switch (ifibss->chandef.width) { 799 case NL80211_CHAN_WIDTH_20_NOHT: 800 case NL80211_CHAN_WIDTH_20: 801 case NL80211_CHAN_WIDTH_40: 802 /* keep our current HT mode (HT20/HT40+/HT40-), even if 803 * another mode has been announced. The mode is not adopted 804 * within the beacon while doing CSA and we should therefore 805 * keep the mode which we announce. 806 */ 807 ch_type = cfg80211_get_chandef_type(&ifibss->chandef); 808 cfg80211_chandef_create(¶ms.chandef, params.chandef.chan, 809 ch_type); 810 break; 811 case NL80211_CHAN_WIDTH_5: 812 case NL80211_CHAN_WIDTH_10: 813 if (params.chandef.width != ifibss->chandef.width) { 814 sdata_info(sdata, 815 "IBSS %pM received channel switch from incompatible channel width (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n", 816 ifibss->bssid, 817 params.chandef.chan->center_freq, 818 params.chandef.width, 819 params.chandef.center_freq1, 820 params.chandef.center_freq2); 821 goto disconnect; 822 } 823 break; 824 default: 825 /* should not happen, conn_flags should prevent VHT modes. */ 826 WARN_ON(1); 827 goto disconnect; 828 } 829 830 if (!cfg80211_reg_can_beacon(sdata->local->hw.wiphy, ¶ms.chandef, 831 NL80211_IFTYPE_ADHOC)) { 832 sdata_info(sdata, 833 "IBSS %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n", 834 ifibss->bssid, 835 params.chandef.chan->center_freq, 836 params.chandef.width, 837 params.chandef.center_freq1, 838 params.chandef.center_freq2); 839 goto disconnect; 840 } 841 842 err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy, 843 ¶ms.chandef, 844 NL80211_IFTYPE_ADHOC); 845 if (err < 0) 846 goto disconnect; 847 if (err > 0 && !ifibss->userspace_handles_dfs) { 848 /* IBSS-DFS only allowed with a control program */ 849 goto disconnect; 850 } 851 852 params.radar_required = err; 853 854 if (cfg80211_chandef_identical(¶ms.chandef, 855 &sdata->vif.bss_conf.chanreq.oper)) { 856 ibss_dbg(sdata, 857 "received csa with an identical chandef, ignoring\n"); 858 return true; 859 } 860 861 /* all checks done, now perform the channel switch. */ 862 ibss_dbg(sdata, 863 "received channel switch announcement to go to channel %d MHz\n", 864 params.chandef.chan->center_freq); 865 866 params.block_tx = !!csa_ie.mode; 867 868 if (ieee80211_channel_switch(sdata->local->hw.wiphy, sdata->dev, 869 ¶ms)) 870 goto disconnect; 871 872 ieee80211_ibss_csa_mark_radar(sdata); 873 874 return true; 875 disconnect: 876 ibss_dbg(sdata, "Can't handle channel switch, disconnect\n"); 877 wiphy_work_queue(sdata->local->hw.wiphy, 878 &ifibss->csa_connection_drop_work); 879 880 ieee80211_ibss_csa_mark_radar(sdata); 881 882 return true; 883 } 884 885 static void 886 ieee80211_rx_mgmt_spectrum_mgmt(struct ieee80211_sub_if_data *sdata, 887 struct ieee80211_mgmt *mgmt, size_t len, 888 struct ieee80211_rx_status *rx_status, 889 struct ieee802_11_elems *elems) 890 { 891 if (len < IEEE80211_MIN_ACTION_SIZE(chan_switch)) 892 return; 893 894 /* CSA is the only action we handle for now */ 895 if (mgmt->u.action.action_code != WLAN_ACTION_SPCT_CHL_SWITCH) 896 return; 897 898 if (!sdata->vif.bss_conf.csa_active) 899 ieee80211_ibss_process_chanswitch(sdata, elems, false); 900 } 901 902 static void ieee80211_rx_mgmt_deauth_ibss(struct ieee80211_sub_if_data *sdata, 903 struct ieee80211_mgmt *mgmt, 904 size_t len) 905 { 906 u16 reason = le16_to_cpu(mgmt->u.deauth.reason_code); 907 908 if (len < IEEE80211_DEAUTH_FRAME_LEN) 909 return; 910 911 ibss_dbg(sdata, "RX DeAuth SA=%pM DA=%pM\n", mgmt->sa, mgmt->da); 912 ibss_dbg(sdata, "\tBSSID=%pM (reason: %d)\n", mgmt->bssid, reason); 913 sta_info_destroy_addr(sdata, mgmt->sa); 914 } 915 916 static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata, 917 struct ieee80211_mgmt *mgmt, 918 size_t len) 919 { 920 u16 auth_alg, auth_transaction; 921 922 lockdep_assert_wiphy(sdata->local->hw.wiphy); 923 924 if (len < 24 + 6) 925 return; 926 927 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); 928 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 929 930 ibss_dbg(sdata, "RX Auth SA=%pM DA=%pM\n", mgmt->sa, mgmt->da); 931 ibss_dbg(sdata, "\tBSSID=%pM (auth_transaction=%d)\n", 932 mgmt->bssid, auth_transaction); 933 934 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) 935 return; 936 937 /* 938 * IEEE 802.11 standard does not require authentication in IBSS 939 * networks and most implementations do not seem to use it. 940 * However, try to reply to authentication attempts if someone 941 * has actually implemented this. 942 */ 943 ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, 0, NULL, 0, 944 mgmt->sa, sdata->u.ibss.bssid, NULL, 0, 0, 0); 945 } 946 947 static void ieee80211_update_sta_info(struct ieee80211_sub_if_data *sdata, 948 struct ieee80211_mgmt *mgmt, size_t len, 949 struct ieee80211_rx_status *rx_status, 950 struct ieee802_11_elems *elems, 951 struct ieee80211_channel *channel) 952 { 953 struct sta_info *sta; 954 enum nl80211_band band = rx_status->band; 955 struct ieee80211_local *local = sdata->local; 956 struct ieee80211_supported_band *sband; 957 bool rates_updated = false; 958 u32 supp_rates = 0; 959 960 if (sdata->vif.type != NL80211_IFTYPE_ADHOC) 961 return; 962 963 if (!ether_addr_equal(mgmt->bssid, sdata->u.ibss.bssid)) 964 return; 965 966 sband = local->hw.wiphy->bands[band]; 967 if (WARN_ON(!sband)) 968 return; 969 970 rcu_read_lock(); 971 sta = sta_info_get(sdata, mgmt->sa); 972 973 if (elems->supp_rates) { 974 supp_rates = ieee80211_sta_get_rates(sdata, elems, 975 band, NULL); 976 if (sta) { 977 u32 prev_rates; 978 979 prev_rates = sta->sta.deflink.supp_rates[band]; 980 981 sta->sta.deflink.supp_rates[band] = supp_rates | 982 ieee80211_mandatory_rates(sband); 983 if (sta->sta.deflink.supp_rates[band] != prev_rates) { 984 ibss_dbg(sdata, 985 "updated supp_rates set for %pM based on beacon/probe_resp (0x%x -> 0x%x)\n", 986 sta->sta.addr, prev_rates, 987 sta->sta.deflink.supp_rates[band]); 988 rates_updated = true; 989 } 990 } else { 991 rcu_read_unlock(); 992 sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid, 993 mgmt->sa, supp_rates); 994 } 995 } 996 997 if (sta && !sta->sta.wme && 998 (elems->wmm_info || elems->s1g_capab) && 999 local->hw.queues >= IEEE80211_NUM_ACS) { 1000 sta->sta.wme = true; 1001 ieee80211_check_fast_xmit(sta); 1002 } 1003 1004 if (sta && elems->ht_operation && elems->ht_cap_elem && 1005 sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 1006 sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_5 && 1007 sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_10) { 1008 /* we both use HT */ 1009 struct ieee80211_ht_cap htcap_ie; 1010 struct cfg80211_chan_def chandef; 1011 enum ieee80211_sta_rx_bandwidth bw = sta->sta.deflink.bandwidth; 1012 1013 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 1014 ieee80211_chandef_ht_oper(elems->ht_operation, &chandef); 1015 1016 memcpy(&htcap_ie, elems->ht_cap_elem, sizeof(htcap_ie)); 1017 rates_updated |= ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, 1018 &sband->ht_cap, 1019 &htcap_ie, 1020 &sta->deflink); 1021 1022 if (elems->vht_operation && elems->vht_cap_elem && 1023 sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_20 && 1024 sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_40) { 1025 /* we both use VHT */ 1026 struct ieee80211_vht_cap cap_ie; 1027 struct ieee80211_sta_vht_cap cap = sta->sta.deflink.vht_cap; 1028 u32 vht_cap_info = 1029 le32_to_cpu(elems->vht_cap_elem->vht_cap_info); 1030 1031 ieee80211_chandef_vht_oper(&local->hw, vht_cap_info, 1032 elems->vht_operation, 1033 elems->ht_operation, 1034 &chandef); 1035 memcpy(&cap_ie, elems->vht_cap_elem, sizeof(cap_ie)); 1036 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, 1037 &sband->vht_cap, 1038 &cap_ie, NULL, 1039 &sta->deflink); 1040 if (memcmp(&cap, &sta->sta.deflink.vht_cap, sizeof(cap))) 1041 rates_updated |= true; 1042 } 1043 1044 if (bw != sta->sta.deflink.bandwidth) 1045 rates_updated |= true; 1046 1047 if (!cfg80211_chandef_compatible(&sdata->u.ibss.chandef, 1048 &chandef)) 1049 WARN_ON_ONCE(1); 1050 } 1051 1052 if (sta && rates_updated) { 1053 u32 changed = IEEE80211_RC_SUPP_RATES_CHANGED; 1054 u8 rx_nss = sta->sta.deflink.rx_nss; 1055 1056 /* Force rx_nss recalculation */ 1057 sta->sta.deflink.rx_nss = 0; 1058 rate_control_rate_init(&sta->deflink); 1059 if (sta->sta.deflink.rx_nss != rx_nss) 1060 changed |= IEEE80211_RC_NSS_CHANGED; 1061 1062 drv_link_sta_rc_update(local, sdata, &sta->sta.deflink, 1063 changed); 1064 } 1065 1066 rcu_read_unlock(); 1067 } 1068 1069 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 1070 struct ieee80211_mgmt *mgmt, size_t len, 1071 struct ieee80211_rx_status *rx_status, 1072 struct ieee802_11_elems *elems) 1073 { 1074 struct ieee80211_local *local = sdata->local; 1075 struct cfg80211_bss *cbss; 1076 struct ieee80211_bss *bss; 1077 struct ieee80211_channel *channel; 1078 u64 beacon_timestamp, rx_timestamp; 1079 u32 supp_rates = 0; 1080 enum nl80211_band band = rx_status->band; 1081 1082 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq); 1083 if (!channel) 1084 return; 1085 1086 ieee80211_update_sta_info(sdata, mgmt, len, rx_status, elems, channel); 1087 1088 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); 1089 if (!bss) 1090 return; 1091 1092 cbss = container_of((void *)bss, struct cfg80211_bss, priv); 1093 1094 /* same for beacon and probe response */ 1095 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); 1096 1097 /* check if we need to merge IBSS */ 1098 1099 /* not an IBSS */ 1100 if (!(cbss->capability & WLAN_CAPABILITY_IBSS)) 1101 goto put_bss; 1102 1103 /* different channel */ 1104 if (sdata->u.ibss.fixed_channel && 1105 sdata->u.ibss.chandef.chan != cbss->channel) 1106 goto put_bss; 1107 1108 /* different SSID */ 1109 if (elems->ssid_len != sdata->u.ibss.ssid_len || 1110 memcmp(elems->ssid, sdata->u.ibss.ssid, 1111 sdata->u.ibss.ssid_len)) 1112 goto put_bss; 1113 1114 /* process channel switch */ 1115 if (sdata->vif.bss_conf.csa_active || 1116 ieee80211_ibss_process_chanswitch(sdata, elems, true)) 1117 goto put_bss; 1118 1119 /* same BSSID */ 1120 if (ether_addr_equal(cbss->bssid, sdata->u.ibss.bssid)) 1121 goto put_bss; 1122 1123 /* we use a fixed BSSID */ 1124 if (sdata->u.ibss.fixed_bssid) 1125 goto put_bss; 1126 1127 if (ieee80211_have_rx_timestamp(rx_status)) { 1128 /* time when timestamp field was received */ 1129 rx_timestamp = 1130 ieee80211_calculate_rx_timestamp(&local->hw, rx_status, 1131 len + FCS_LEN, 24); 1132 } else { 1133 /* 1134 * second best option: get current TSF 1135 * (will return -1 if not supported) 1136 */ 1137 rx_timestamp = drv_get_tsf(local, sdata); 1138 } 1139 1140 ibss_dbg(sdata, "RX beacon SA=%pM BSSID=%pM TSF=0x%llx\n", 1141 mgmt->sa, mgmt->bssid, 1142 (unsigned long long)rx_timestamp); 1143 ibss_dbg(sdata, "\tBCN=0x%llx diff=%lld @%lu\n", 1144 (unsigned long long)beacon_timestamp, 1145 (unsigned long long)(rx_timestamp - beacon_timestamp), 1146 jiffies); 1147 1148 if (beacon_timestamp > rx_timestamp) { 1149 ibss_dbg(sdata, 1150 "beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n", 1151 mgmt->bssid); 1152 ieee80211_sta_join_ibss(sdata, bss); 1153 supp_rates = ieee80211_sta_get_rates(sdata, elems, band, NULL); 1154 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, 1155 supp_rates); 1156 rcu_read_unlock(); 1157 } 1158 1159 put_bss: 1160 ieee80211_rx_bss_put(local, bss); 1161 } 1162 1163 void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata, 1164 const u8 *bssid, const u8 *addr, 1165 u32 supp_rates) 1166 { 1167 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1168 struct ieee80211_local *local = sdata->local; 1169 struct sta_info *sta; 1170 struct ieee80211_chanctx_conf *chanctx_conf; 1171 struct ieee80211_supported_band *sband; 1172 int band; 1173 1174 /* 1175 * XXX: Consider removing the least recently used entry and 1176 * allow new one to be added. 1177 */ 1178 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { 1179 net_info_ratelimited("%s: No room for a new IBSS STA entry %pM\n", 1180 sdata->name, addr); 1181 return; 1182 } 1183 1184 if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) 1185 return; 1186 1187 if (!ether_addr_equal(bssid, sdata->u.ibss.bssid)) 1188 return; 1189 1190 rcu_read_lock(); 1191 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 1192 if (WARN_ON_ONCE(!chanctx_conf)) { 1193 rcu_read_unlock(); 1194 return; 1195 } 1196 band = chanctx_conf->def.chan->band; 1197 rcu_read_unlock(); 1198 1199 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); 1200 if (!sta) 1201 return; 1202 1203 /* make sure mandatory rates are always added */ 1204 sband = local->hw.wiphy->bands[band]; 1205 sta->sta.deflink.supp_rates[band] = supp_rates | 1206 ieee80211_mandatory_rates(sband); 1207 1208 spin_lock(&ifibss->incomplete_lock); 1209 list_add(&sta->list, &ifibss->incomplete_stations); 1210 spin_unlock(&ifibss->incomplete_lock); 1211 wiphy_work_queue(local->hw.wiphy, &sdata->work); 1212 } 1213 1214 static void ieee80211_ibss_sta_expire(struct ieee80211_sub_if_data *sdata) 1215 { 1216 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1217 struct ieee80211_local *local = sdata->local; 1218 struct sta_info *sta, *tmp; 1219 unsigned long exp_time = IEEE80211_IBSS_INACTIVITY_LIMIT; 1220 unsigned long exp_rsn = IEEE80211_IBSS_RSN_INACTIVITY_LIMIT; 1221 1222 lockdep_assert_wiphy(local->hw.wiphy); 1223 1224 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 1225 unsigned long last_active = ieee80211_sta_last_active(sta, -1); 1226 1227 if (sdata != sta->sdata) 1228 continue; 1229 1230 if (time_is_before_jiffies(last_active + exp_time) || 1231 (time_is_before_jiffies(last_active + exp_rsn) && 1232 sta->sta_state != IEEE80211_STA_AUTHORIZED)) { 1233 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 1234 1235 sta_dbg(sta->sdata, "expiring inactive %sSTA %pM\n", 1236 sta->sta_state != IEEE80211_STA_AUTHORIZED ? 1237 "not authorized " : "", sta->sta.addr); 1238 1239 ieee80211_send_deauth_disassoc(sdata, sta->sta.addr, 1240 ifibss->bssid, 1241 IEEE80211_STYPE_DEAUTH, 1242 WLAN_REASON_DEAUTH_LEAVING, 1243 true, frame_buf); 1244 WARN_ON(__sta_info_destroy(sta)); 1245 } 1246 } 1247 } 1248 1249 /* 1250 * This function is called with state == IEEE80211_IBSS_MLME_JOINED 1251 */ 1252 1253 static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) 1254 { 1255 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1256 1257 lockdep_assert_wiphy(sdata->local->hw.wiphy); 1258 1259 mod_timer(&ifibss->timer, 1260 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); 1261 1262 ieee80211_ibss_sta_expire(sdata); 1263 1264 if (time_before(jiffies, ifibss->last_scan_completed + 1265 IEEE80211_IBSS_MERGE_INTERVAL)) 1266 return; 1267 1268 if (ieee80211_sta_active_ibss(sdata)) 1269 return; 1270 1271 if (ifibss->fixed_channel) 1272 return; 1273 1274 sdata_info(sdata, 1275 "No active IBSS STAs - trying to scan for other IBSS networks with same SSID (merge)\n"); 1276 1277 ieee80211_request_ibss_scan(sdata, ifibss->ssid, ifibss->ssid_len, 1278 NULL, 0); 1279 } 1280 1281 static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) 1282 { 1283 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1284 u8 bssid[ETH_ALEN]; 1285 u16 capability; 1286 int i; 1287 1288 lockdep_assert_wiphy(sdata->local->hw.wiphy); 1289 1290 if (ifibss->fixed_bssid) { 1291 memcpy(bssid, ifibss->bssid, ETH_ALEN); 1292 } else { 1293 /* Generate random, not broadcast, locally administered BSSID. Mix in 1294 * own MAC address to make sure that devices that do not have proper 1295 * random number generator get different BSSID. */ 1296 get_random_bytes(bssid, ETH_ALEN); 1297 for (i = 0; i < ETH_ALEN; i++) 1298 bssid[i] ^= sdata->vif.addr[i]; 1299 bssid[0] &= ~0x01; 1300 bssid[0] |= 0x02; 1301 } 1302 1303 sdata_info(sdata, "Creating new IBSS network, BSSID %pM\n", bssid); 1304 1305 capability = WLAN_CAPABILITY_IBSS; 1306 1307 if (ifibss->privacy) 1308 capability |= WLAN_CAPABILITY_PRIVACY; 1309 1310 __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int, 1311 &ifibss->chandef, ifibss->basic_rates, 1312 capability, 0, true); 1313 } 1314 1315 static unsigned int ibss_setup_channels(struct wiphy *wiphy, 1316 struct ieee80211_channel **channels, 1317 unsigned int channels_max, 1318 u32 center_freq, u32 width) 1319 { 1320 struct ieee80211_channel *chan = NULL; 1321 unsigned int n_chan = 0; 1322 u32 start_freq, end_freq, freq; 1323 1324 if (width <= 20) { 1325 start_freq = center_freq; 1326 end_freq = center_freq; 1327 } else { 1328 start_freq = center_freq - width / 2 + 10; 1329 end_freq = center_freq + width / 2 - 10; 1330 } 1331 1332 for (freq = start_freq; freq <= end_freq; freq += 20) { 1333 chan = ieee80211_get_channel(wiphy, freq); 1334 if (!chan) 1335 continue; 1336 if (n_chan >= channels_max) 1337 return n_chan; 1338 1339 channels[n_chan] = chan; 1340 n_chan++; 1341 } 1342 1343 return n_chan; 1344 } 1345 1346 static unsigned int 1347 ieee80211_ibss_setup_scan_channels(struct wiphy *wiphy, 1348 const struct cfg80211_chan_def *chandef, 1349 struct ieee80211_channel **channels, 1350 unsigned int channels_max) 1351 { 1352 unsigned int n_chan = 0; 1353 u32 width, cf1, cf2 = 0; 1354 1355 switch (chandef->width) { 1356 case NL80211_CHAN_WIDTH_40: 1357 width = 40; 1358 break; 1359 case NL80211_CHAN_WIDTH_80P80: 1360 cf2 = chandef->center_freq2; 1361 fallthrough; 1362 case NL80211_CHAN_WIDTH_80: 1363 width = 80; 1364 break; 1365 case NL80211_CHAN_WIDTH_160: 1366 width = 160; 1367 break; 1368 default: 1369 width = 20; 1370 break; 1371 } 1372 1373 cf1 = chandef->center_freq1; 1374 1375 n_chan = ibss_setup_channels(wiphy, channels, channels_max, cf1, width); 1376 1377 if (cf2) 1378 n_chan += ibss_setup_channels(wiphy, &channels[n_chan], 1379 channels_max - n_chan, cf2, 1380 width); 1381 1382 return n_chan; 1383 } 1384 1385 /* 1386 * This function is called with state == IEEE80211_IBSS_MLME_SEARCH 1387 */ 1388 1389 static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) 1390 { 1391 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1392 struct ieee80211_local *local = sdata->local; 1393 struct cfg80211_bss *cbss; 1394 struct ieee80211_channel *chan = NULL; 1395 const u8 *bssid = NULL; 1396 int active_ibss; 1397 1398 lockdep_assert_wiphy(sdata->local->hw.wiphy); 1399 1400 active_ibss = ieee80211_sta_active_ibss(sdata); 1401 ibss_dbg(sdata, "sta_find_ibss (active_ibss=%d)\n", active_ibss); 1402 1403 if (active_ibss) 1404 return; 1405 1406 if (ifibss->fixed_bssid) 1407 bssid = ifibss->bssid; 1408 if (ifibss->fixed_channel) 1409 chan = ifibss->chandef.chan; 1410 if (!is_zero_ether_addr(ifibss->bssid)) 1411 bssid = ifibss->bssid; 1412 cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid, 1413 ifibss->ssid, ifibss->ssid_len, 1414 IEEE80211_BSS_TYPE_IBSS, 1415 IEEE80211_PRIVACY(ifibss->privacy)); 1416 1417 if (cbss) { 1418 struct ieee80211_bss *bss; 1419 1420 bss = (void *)cbss->priv; 1421 ibss_dbg(sdata, 1422 "sta_find_ibss: selected %pM current %pM\n", 1423 cbss->bssid, ifibss->bssid); 1424 sdata_info(sdata, 1425 "Selected IBSS BSSID %pM based on configured SSID\n", 1426 cbss->bssid); 1427 1428 ieee80211_sta_join_ibss(sdata, bss); 1429 ieee80211_rx_bss_put(local, bss); 1430 return; 1431 } 1432 1433 /* if a fixed bssid and a fixed freq have been provided create the IBSS 1434 * directly and do not waste time scanning 1435 */ 1436 if (ifibss->fixed_bssid && ifibss->fixed_channel) { 1437 sdata_info(sdata, "Created IBSS using preconfigured BSSID %pM\n", 1438 bssid); 1439 ieee80211_sta_create_ibss(sdata); 1440 return; 1441 } 1442 1443 1444 ibss_dbg(sdata, "sta_find_ibss: did not try to join ibss\n"); 1445 1446 /* Selected IBSS not found in current scan results - try to scan */ 1447 if (time_after(jiffies, ifibss->last_scan_completed + 1448 IEEE80211_SCAN_INTERVAL)) { 1449 struct ieee80211_channel *channels[8]; 1450 unsigned int num; 1451 1452 sdata_info(sdata, "Trigger new scan to find an IBSS to join\n"); 1453 1454 if (ifibss->fixed_channel) { 1455 num = ieee80211_ibss_setup_scan_channels(local->hw.wiphy, 1456 &ifibss->chandef, 1457 channels, 1458 ARRAY_SIZE(channels)); 1459 ieee80211_request_ibss_scan(sdata, ifibss->ssid, 1460 ifibss->ssid_len, channels, 1461 num); 1462 } else { 1463 ieee80211_request_ibss_scan(sdata, ifibss->ssid, 1464 ifibss->ssid_len, NULL, 0); 1465 } 1466 } else { 1467 int interval = IEEE80211_SCAN_INTERVAL; 1468 1469 if (time_after(jiffies, ifibss->ibss_join_req + 1470 IEEE80211_IBSS_JOIN_TIMEOUT)) 1471 ieee80211_sta_create_ibss(sdata); 1472 1473 mod_timer(&ifibss->timer, 1474 round_jiffies(jiffies + interval)); 1475 } 1476 } 1477 1478 static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, 1479 struct sk_buff *req) 1480 { 1481 struct ieee80211_mgmt *mgmt = (void *)req->data; 1482 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1483 struct ieee80211_local *local = sdata->local; 1484 int tx_last_beacon, len = req->len; 1485 struct sk_buff *skb; 1486 struct beacon_data *presp; 1487 u8 *pos, *end; 1488 1489 lockdep_assert_wiphy(sdata->local->hw.wiphy); 1490 1491 presp = sdata_dereference(ifibss->presp, sdata); 1492 1493 if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || 1494 len < 24 + 2 || !presp) 1495 return; 1496 1497 tx_last_beacon = drv_tx_last_beacon(local); 1498 1499 ibss_dbg(sdata, "RX ProbeReq SA=%pM DA=%pM\n", mgmt->sa, mgmt->da); 1500 ibss_dbg(sdata, "\tBSSID=%pM (tx_last_beacon=%d)\n", 1501 mgmt->bssid, tx_last_beacon); 1502 1503 if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da)) 1504 return; 1505 1506 if (!ether_addr_equal(mgmt->bssid, ifibss->bssid) && 1507 !is_broadcast_ether_addr(mgmt->bssid)) 1508 return; 1509 1510 end = ((u8 *) mgmt) + len; 1511 pos = mgmt->u.probe_req.variable; 1512 if (pos[0] != WLAN_EID_SSID || 1513 pos + 2 + pos[1] > end) { 1514 ibss_dbg(sdata, "Invalid SSID IE in ProbeReq from %pM\n", 1515 mgmt->sa); 1516 return; 1517 } 1518 if (pos[1] != 0 && 1519 (pos[1] != ifibss->ssid_len || 1520 memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) { 1521 /* Ignore ProbeReq for foreign SSID */ 1522 return; 1523 } 1524 1525 /* Reply with ProbeResp */ 1526 skb = dev_alloc_skb(local->tx_headroom + presp->head_len); 1527 if (!skb) 1528 return; 1529 1530 skb_reserve(skb, local->tx_headroom); 1531 skb_put_data(skb, presp->head, presp->head_len); 1532 1533 memcpy(((struct ieee80211_mgmt *) skb->data)->da, mgmt->sa, ETH_ALEN); 1534 ibss_dbg(sdata, "Sending ProbeResp to %pM\n", mgmt->sa); 1535 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 1536 1537 /* avoid excessive retries for probe request to wildcard SSIDs */ 1538 if (pos[1] == 0) 1539 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_NO_ACK; 1540 1541 ieee80211_tx_skb(sdata, skb); 1542 } 1543 1544 static 1545 void ieee80211_rx_mgmt_probe_beacon(struct ieee80211_sub_if_data *sdata, 1546 struct ieee80211_mgmt *mgmt, size_t len, 1547 struct ieee80211_rx_status *rx_status) 1548 { 1549 size_t baselen; 1550 struct ieee802_11_elems *elems; 1551 u16 type; 1552 1553 BUILD_BUG_ON(offsetof(typeof(mgmt->u.probe_resp), variable) != 1554 offsetof(typeof(mgmt->u.beacon), variable)); 1555 1556 /* 1557 * either beacon or probe_resp but the variable field is at the 1558 * same offset 1559 */ 1560 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 1561 if (baselen > len) 1562 return; 1563 1564 type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE; 1565 elems = ieee802_11_parse_elems(mgmt->u.probe_resp.variable, 1566 len - baselen, type, NULL); 1567 1568 if (elems) { 1569 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, elems); 1570 kfree(elems); 1571 } 1572 } 1573 1574 void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 1575 struct sk_buff *skb) 1576 { 1577 struct ieee80211_rx_status *rx_status; 1578 struct ieee80211_mgmt *mgmt; 1579 u16 fc; 1580 struct ieee802_11_elems *elems; 1581 int ies_len; 1582 1583 rx_status = IEEE80211_SKB_RXCB(skb); 1584 mgmt = (struct ieee80211_mgmt *) skb->data; 1585 fc = le16_to_cpu(mgmt->frame_control); 1586 1587 if (!sdata->u.ibss.ssid_len) 1588 return; /* not ready to merge yet */ 1589 1590 switch (fc & IEEE80211_FCTL_STYPE) { 1591 case IEEE80211_STYPE_PROBE_REQ: 1592 ieee80211_rx_mgmt_probe_req(sdata, skb); 1593 break; 1594 case IEEE80211_STYPE_PROBE_RESP: 1595 case IEEE80211_STYPE_BEACON: 1596 ieee80211_rx_mgmt_probe_beacon(sdata, mgmt, skb->len, 1597 rx_status); 1598 break; 1599 case IEEE80211_STYPE_AUTH: 1600 ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len); 1601 break; 1602 case IEEE80211_STYPE_DEAUTH: 1603 ieee80211_rx_mgmt_deauth_ibss(sdata, mgmt, skb->len); 1604 break; 1605 case IEEE80211_STYPE_ACTION: 1606 switch (mgmt->u.action.category) { 1607 case WLAN_CATEGORY_SPECTRUM_MGMT: 1608 ies_len = skb->len - 1609 offsetof(struct ieee80211_mgmt, 1610 u.action.chan_switch.variable); 1611 1612 if (ies_len < 0) 1613 break; 1614 1615 elems = ieee802_11_parse_elems(mgmt->u.action.chan_switch.variable, 1616 ies_len, 1617 IEEE80211_FTYPE_MGMT | 1618 IEEE80211_STYPE_ACTION, 1619 NULL); 1620 1621 if (elems && !elems->parse_error) 1622 ieee80211_rx_mgmt_spectrum_mgmt(sdata, mgmt, 1623 skb->len, 1624 rx_status, 1625 elems); 1626 kfree(elems); 1627 break; 1628 } 1629 } 1630 } 1631 1632 void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata) 1633 { 1634 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1635 struct sta_info *sta; 1636 1637 /* 1638 * Work could be scheduled after scan or similar 1639 * when we aren't even joined (or trying) with a 1640 * network. 1641 */ 1642 if (!ifibss->ssid_len) 1643 return; 1644 1645 spin_lock_bh(&ifibss->incomplete_lock); 1646 while (!list_empty(&ifibss->incomplete_stations)) { 1647 sta = list_first_entry(&ifibss->incomplete_stations, 1648 struct sta_info, list); 1649 list_del(&sta->list); 1650 spin_unlock_bh(&ifibss->incomplete_lock); 1651 1652 ieee80211_ibss_finish_sta(sta); 1653 rcu_read_unlock(); 1654 spin_lock_bh(&ifibss->incomplete_lock); 1655 } 1656 spin_unlock_bh(&ifibss->incomplete_lock); 1657 1658 switch (ifibss->state) { 1659 case IEEE80211_IBSS_MLME_SEARCH: 1660 ieee80211_sta_find_ibss(sdata); 1661 break; 1662 case IEEE80211_IBSS_MLME_JOINED: 1663 ieee80211_sta_merge_ibss(sdata); 1664 break; 1665 default: 1666 WARN_ON(1); 1667 break; 1668 } 1669 } 1670 1671 static void ieee80211_ibss_timer(struct timer_list *t) 1672 { 1673 struct ieee80211_sub_if_data *sdata = 1674 timer_container_of(sdata, t, u.ibss.timer); 1675 1676 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); 1677 } 1678 1679 void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) 1680 { 1681 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1682 1683 timer_setup(&ifibss->timer, ieee80211_ibss_timer, 0); 1684 INIT_LIST_HEAD(&ifibss->incomplete_stations); 1685 spin_lock_init(&ifibss->incomplete_lock); 1686 wiphy_work_init(&ifibss->csa_connection_drop_work, 1687 ieee80211_csa_connection_drop_work); 1688 } 1689 1690 /* scan finished notification */ 1691 void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) 1692 { 1693 struct ieee80211_sub_if_data *sdata; 1694 1695 lockdep_assert_wiphy(local->hw.wiphy); 1696 1697 list_for_each_entry(sdata, &local->interfaces, list) { 1698 if (!ieee80211_sdata_running(sdata)) 1699 continue; 1700 if (sdata->vif.type != NL80211_IFTYPE_ADHOC) 1701 continue; 1702 sdata->u.ibss.last_scan_completed = jiffies; 1703 } 1704 } 1705 1706 int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, 1707 struct cfg80211_ibss_params *params) 1708 { 1709 u64 changed = 0; 1710 enum ieee80211_chanctx_mode chanmode; 1711 struct ieee80211_local *local = sdata->local; 1712 int radar_detect_width = 0; 1713 int ret; 1714 1715 lockdep_assert_wiphy(local->hw.wiphy); 1716 1717 if (params->chandef.chan->freq_offset) { 1718 /* this may work, but is untested */ 1719 return -EOPNOTSUPP; 1720 } 1721 1722 ret = cfg80211_chandef_dfs_required(local->hw.wiphy, 1723 ¶ms->chandef, 1724 sdata->wdev.iftype); 1725 if (ret < 0) 1726 return ret; 1727 1728 if (ret > 0) { 1729 if (!params->userspace_handles_dfs) 1730 return -EINVAL; 1731 radar_detect_width = BIT(params->chandef.width); 1732 } 1733 1734 chanmode = (params->channel_fixed && !ret) ? 1735 IEEE80211_CHANCTX_SHARED : IEEE80211_CHANCTX_EXCLUSIVE; 1736 1737 ret = ieee80211_check_combinations(sdata, ¶ms->chandef, chanmode, 1738 radar_detect_width, -1); 1739 if (ret < 0) 1740 return ret; 1741 1742 if (params->bssid) { 1743 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN); 1744 sdata->u.ibss.fixed_bssid = true; 1745 } else 1746 sdata->u.ibss.fixed_bssid = false; 1747 1748 sdata->u.ibss.privacy = params->privacy; 1749 sdata->u.ibss.control_port = params->control_port; 1750 sdata->u.ibss.userspace_handles_dfs = params->userspace_handles_dfs; 1751 sdata->u.ibss.basic_rates = params->basic_rates; 1752 sdata->u.ibss.last_scan_completed = jiffies; 1753 1754 /* fix basic_rates if channel does not support these rates */ 1755 memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate, 1756 sizeof(params->mcast_rate)); 1757 1758 sdata->vif.bss_conf.beacon_int = params->beacon_interval; 1759 1760 sdata->u.ibss.chandef = params->chandef; 1761 sdata->u.ibss.fixed_channel = params->channel_fixed; 1762 1763 if (params->ie) { 1764 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len, 1765 GFP_KERNEL); 1766 if (sdata->u.ibss.ie) 1767 sdata->u.ibss.ie_len = params->ie_len; 1768 } 1769 1770 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; 1771 sdata->u.ibss.ibss_join_req = jiffies; 1772 1773 memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len); 1774 sdata->u.ibss.ssid_len = params->ssid_len; 1775 1776 memcpy(&sdata->u.ibss.ht_capa, ¶ms->ht_capa, 1777 sizeof(sdata->u.ibss.ht_capa)); 1778 memcpy(&sdata->u.ibss.ht_capa_mask, ¶ms->ht_capa_mask, 1779 sizeof(sdata->u.ibss.ht_capa_mask)); 1780 1781 /* 1782 * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is 1783 * reserved, but an HT STA shall protect HT transmissions as though 1784 * the HT Protection field were set to non-HT mixed mode. 1785 * 1786 * In an IBSS, the RIFS Mode field of the HT Operation element is 1787 * also reserved, but an HT STA shall operate as though this field 1788 * were set to 1. 1789 */ 1790 1791 sdata->vif.bss_conf.ht_operation_mode |= 1792 IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 1793 | IEEE80211_HT_PARAM_RIFS_MODE; 1794 1795 changed |= BSS_CHANGED_HT | BSS_CHANGED_MCAST_RATE; 1796 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); 1797 1798 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; 1799 sdata->deflink.needed_rx_chains = local->rx_chains; 1800 sdata->control_port_over_nl80211 = params->control_port_over_nl80211; 1801 1802 wiphy_work_queue(local->hw.wiphy, &sdata->work); 1803 1804 return 0; 1805 } 1806 1807 int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata) 1808 { 1809 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 1810 1811 ifibss->ssid_len = 0; 1812 ieee80211_ibss_disconnect(sdata); 1813 eth_zero_addr(ifibss->bssid); 1814 1815 /* remove beacon */ 1816 kfree(sdata->u.ibss.ie); 1817 sdata->u.ibss.ie = NULL; 1818 sdata->u.ibss.ie_len = 0; 1819 1820 /* on the next join, re-program HT parameters */ 1821 memset(&ifibss->ht_capa, 0, sizeof(ifibss->ht_capa)); 1822 memset(&ifibss->ht_capa_mask, 0, sizeof(ifibss->ht_capa_mask)); 1823 1824 synchronize_rcu(); 1825 1826 skb_queue_purge(&sdata->skb_queue); 1827 1828 timer_delete_sync(&sdata->u.ibss.timer); 1829 1830 return 0; 1831 } 1832