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