Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * IBSS mode implementation |
| 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
| 4 | * Copyright 2004, Instant802 Networks, Inc. |
| 5 | * Copyright 2005, Devicescape Software, Inc. |
| 6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 8 | * Copyright 2009, Johannes Berg <johannes@sipsolutions.net> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 17 | #include <linux/if_ether.h> |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/if_arp.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/rtnetlink.h> |
| 22 | #include <net/mac80211.h> |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 23 | |
| 24 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 25 | #include "driver-ops.h" |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 26 | #include "rate.h" |
| 27 | |
| 28 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 29 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
| 30 | |
| 31 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
| 32 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
| 33 | |
| 34 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 |
| 35 | |
| 36 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 37 | static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
| 38 | const u8 *bssid, const int beacon_int, |
| 39 | struct ieee80211_channel *chan, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 40 | const u32 basic_rates, |
Sujith Manoharan | c13a765 | 2012-10-12 17:35:45 +0530 | [diff] [blame] | 41 | const u16 capability, u64 tsf, |
| 42 | bool creator) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 43 | { |
| 44 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 45 | struct ieee80211_local *local = sdata->local; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 46 | int rates_n = 0, i, ri; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 47 | struct ieee80211_mgmt *mgmt; |
| 48 | u8 *pos; |
| 49 | struct ieee80211_supported_band *sband; |
Johannes Berg | f446d10 | 2009-10-28 15:12:32 +0100 | [diff] [blame] | 50 | struct cfg80211_bss *bss; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 51 | u32 bss_change, rate_flags, rates = 0, rates_added = 0; |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 52 | u8 supp_rates[IEEE80211_MAX_SUPP_RATES]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 53 | struct cfg80211_chan_def chandef; |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 54 | enum nl80211_bss_scan_width scan_width; |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 55 | struct beacon_data *presp; |
| 56 | int frame_len; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 57 | int shift; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 58 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 59 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 60 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 61 | /* Reset own TSF to allow time synchronization work. */ |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 62 | drv_reset_tsf(local, sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 63 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 64 | if (!ether_addr_equal(ifibss->bssid, bssid)) |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 65 | sta_info_flush(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 66 | |
Johannes Berg | 49b5c7f | 2010-04-29 21:34:01 +0200 | [diff] [blame] | 67 | /* if merging, indicate to driver that we leave the old IBSS */ |
| 68 | if (sdata->vif.bss_conf.ibss_joined) { |
| 69 | sdata->vif.bss_conf.ibss_joined = false; |
Sujith Manoharan | c13a765 | 2012-10-12 17:35:45 +0530 | [diff] [blame] | 70 | sdata->vif.bss_conf.ibss_creator = false; |
Johannes Berg | 1852d40 | 2013-03-07 20:22:28 +0100 | [diff] [blame] | 71 | sdata->vif.bss_conf.enable_beacon = false; |
Eliad Peller | 86a2ea4 | 2011-11-08 15:36:59 +0200 | [diff] [blame] | 72 | netif_carrier_off(sdata->dev); |
Johannes Berg | 1852d40 | 2013-03-07 20:22:28 +0100 | [diff] [blame] | 73 | ieee80211_bss_info_change_notify(sdata, |
| 74 | BSS_CHANGED_IBSS | |
| 75 | BSS_CHANGED_BEACON_ENABLED); |
Johannes Berg | 49b5c7f | 2010-04-29 21:34:01 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 78 | presp = rcu_dereference_protected(ifibss->presp, |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 79 | lockdep_is_held(&sdata->wdev.mtx)); |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 80 | rcu_assign_pointer(ifibss->presp, NULL); |
| 81 | if (presp) |
| 82 | kfree_rcu(presp, rcu_head); |
Johannes Berg | 1852d40 | 2013-03-07 20:22:28 +0100 | [diff] [blame] | 83 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 84 | sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 85 | |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 86 | chandef = ifibss->chandef; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 87 | if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chandef)) { |
| 88 | chandef.width = NL80211_CHAN_WIDTH_20; |
| 89 | chandef.center_freq1 = chan->center_freq; |
| 90 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 91 | |
| 92 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 93 | if (ieee80211_vif_use_channel(sdata, &chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 94 | ifibss->fixed_channel ? |
| 95 | IEEE80211_CHANCTX_SHARED : |
| 96 | IEEE80211_CHANCTX_EXCLUSIVE)) { |
| 97 | sdata_info(sdata, "Failed to join IBSS, no channel context\n"); |
| 98 | return; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 99 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 100 | |
| 101 | memcpy(ifibss->bssid, bssid, ETH_ALEN); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 102 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 103 | sband = local->hw.wiphy->bands[chan->band]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 104 | shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 105 | |
| 106 | /* Build IBSS probe response */ |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 107 | frame_len = sizeof(struct ieee80211_hdr_3addr) + |
| 108 | 12 /* struct ieee80211_mgmt.u.beacon */ + |
| 109 | 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ + |
| 110 | 2 + 8 /* max Supported Rates */ + |
| 111 | 3 /* max DS params */ + |
| 112 | 4 /* IBSS params */ + |
| 113 | 2 + (IEEE80211_MAX_SUPP_RATES - 8) + |
| 114 | 2 + sizeof(struct ieee80211_ht_cap) + |
| 115 | 2 + sizeof(struct ieee80211_ht_operation) + |
| 116 | ifibss->ie_len; |
| 117 | presp = kzalloc(sizeof(*presp) + frame_len, GFP_KERNEL); |
| 118 | if (!presp) |
| 119 | return; |
| 120 | |
| 121 | presp->head = (void *)(presp + 1); |
| 122 | |
| 123 | mgmt = (void *) presp->head; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 124 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 125 | IEEE80211_STYPE_PROBE_RESP); |
Johannes Berg | e83e654 | 2012-07-13 16:23:07 +0200 | [diff] [blame] | 126 | eth_broadcast_addr(mgmt->da); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 127 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 128 | memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 129 | mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int); |
Sujith | 707c1b4 | 2009-03-03 10:15:10 +0530 | [diff] [blame] | 130 | mgmt->u.beacon.timestamp = cpu_to_le64(tsf); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 131 | mgmt->u.beacon.capab_info = cpu_to_le16(capability); |
| 132 | |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 133 | pos = (u8 *)mgmt + offsetof(struct ieee80211_mgmt, u.beacon.variable); |
| 134 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 135 | *pos++ = WLAN_EID_SSID; |
| 136 | *pos++ = ifibss->ssid_len; |
| 137 | memcpy(pos, ifibss->ssid, ifibss->ssid_len); |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 138 | pos += ifibss->ssid_len; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 139 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 140 | rate_flags = ieee80211_chandef_rate_flags(&chandef); |
| 141 | for (i = 0; i < sband->n_bitrates; i++) { |
| 142 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) |
| 143 | continue; |
| 144 | |
| 145 | rates |= BIT(i); |
| 146 | rates_n++; |
| 147 | } |
| 148 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 149 | *pos++ = WLAN_EID_SUPP_RATES; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 150 | *pos++ = min_t(int, 8, rates_n); |
| 151 | for (ri = 0; ri < sband->n_bitrates; ri++) { |
| 152 | int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate, |
| 153 | 5 * (1 << shift)); |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 154 | u8 basic = 0; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 155 | if (!(rates & BIT(ri))) |
| 156 | continue; |
| 157 | |
| 158 | if (basic_rates & BIT(ri)) |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 159 | basic = 0x80; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 160 | *pos++ = basic | (u8) rate; |
| 161 | if (++rates_added == 8) |
| 162 | break; |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 163 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 164 | |
| 165 | if (sband->band == IEEE80211_BAND_2GHZ) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 166 | *pos++ = WLAN_EID_DS_PARAMS; |
| 167 | *pos++ = 1; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 168 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 171 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 172 | *pos++ = 2; |
| 173 | /* FIX: set ATIM window based on scan results */ |
| 174 | *pos++ = 0; |
| 175 | *pos++ = 0; |
| 176 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 177 | /* put the remaining rates in WLAN_EID_EXT_SUPP_RATES */ |
| 178 | if (rates_n > 8) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 179 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 180 | *pos++ = rates_n - 8; |
| 181 | for (; ri < sband->n_bitrates; ri++) { |
| 182 | int rate = DIV_ROUND_UP(sband->bitrates[ri].bitrate, |
| 183 | 5 * (1 << shift)); |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 184 | u8 basic = 0; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 185 | if (!(rates & BIT(ri))) |
| 186 | continue; |
| 187 | |
| 188 | if (basic_rates & BIT(ri)) |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 189 | basic = 0x80; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 190 | *pos++ = basic | (u8) rate; |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 191 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 194 | if (ifibss->ie_len) { |
| 195 | memcpy(pos, ifibss->ie, ifibss->ie_len); |
| 196 | pos += ifibss->ie_len; |
| 197 | } |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 198 | |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 199 | /* add HT capability and information IEs */ |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 200 | if (chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 201 | chandef.width != NL80211_CHAN_WIDTH_5 && |
| 202 | chandef.width != NL80211_CHAN_WIDTH_10 && |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 203 | sband->ht_cap.ht_supported) { |
Simon Wunderlich | 822854b | 2013-06-28 10:39:59 +0200 | [diff] [blame] | 204 | struct ieee80211_sta_ht_cap ht_cap; |
| 205 | |
| 206 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 207 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 208 | |
| 209 | pos = ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap); |
Ashok Nagarajan | 0d894ec | 2012-05-07 21:00:29 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Note: According to 802.11n-2009 9.13.3.1, HT Protection |
| 212 | * field and RIFS Mode are reserved in IBSS mode, therefore |
| 213 | * keep them at 0 |
| 214 | */ |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 215 | pos = ieee80211_ie_build_ht_oper(pos, &sband->ht_cap, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 216 | &chandef, 0); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 217 | } |
| 218 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 219 | if (local->hw.queues >= IEEE80211_NUM_ACS) { |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 220 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 221 | *pos++ = 7; /* len */ |
| 222 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 223 | *pos++ = 0x50; |
| 224 | *pos++ = 0xf2; |
| 225 | *pos++ = 2; /* WME */ |
| 226 | *pos++ = 0; /* WME info */ |
| 227 | *pos++ = 1; /* WME ver */ |
| 228 | *pos++ = 0; /* U-APSD no in use */ |
| 229 | } |
| 230 | |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 231 | presp->head_len = pos - presp->head; |
| 232 | if (WARN_ON(presp->head_len > frame_len)) |
| 233 | return; |
| 234 | |
| 235 | rcu_assign_pointer(ifibss->presp, presp); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 236 | |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 237 | sdata->vif.bss_conf.enable_beacon = true; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 238 | sdata->vif.bss_conf.beacon_int = beacon_int; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 239 | sdata->vif.bss_conf.basic_rates = basic_rates; |
Marek Puzyniak | 0ca54f6 | 2013-04-10 13:19:13 +0200 | [diff] [blame] | 240 | sdata->vif.bss_conf.ssid_len = ifibss->ssid_len; |
| 241 | memcpy(sdata->vif.bss_conf.ssid, ifibss->ssid, ifibss->ssid_len); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 242 | bss_change = BSS_CHANGED_BEACON_INT; |
| 243 | bss_change |= ieee80211_reset_erp_info(sdata); |
| 244 | bss_change |= BSS_CHANGED_BSSID; |
| 245 | bss_change |= BSS_CHANGED_BEACON; |
| 246 | bss_change |= BSS_CHANGED_BEACON_ENABLED; |
Teemu Paasikivi | 392cfdb | 2010-06-14 12:55:32 +0300 | [diff] [blame] | 247 | bss_change |= BSS_CHANGED_BASIC_RATES; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 248 | bss_change |= BSS_CHANGED_HT; |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 249 | bss_change |= BSS_CHANGED_IBSS; |
Marek Puzyniak | 0ca54f6 | 2013-04-10 13:19:13 +0200 | [diff] [blame] | 250 | bss_change |= BSS_CHANGED_SSID; |
Simon Wunderlich | 2f91a96 | 2012-12-03 22:21:30 +0100 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * In 5 GHz/802.11a, we can always use short slot time. |
| 254 | * (IEEE 802.11-2012 18.3.8.7) |
| 255 | * |
| 256 | * In 2.4GHz, we must always use long slots in IBSS for compatibility |
| 257 | * reasons. |
| 258 | * (IEEE 802.11-2012 19.4.5) |
| 259 | * |
| 260 | * HT follows these specifications (IEEE 802.11-2012 20.3.18) |
| 261 | */ |
| 262 | sdata->vif.bss_conf.use_short_slot = chan->band == IEEE80211_BAND_5GHZ; |
| 263 | bss_change |= BSS_CHANGED_ERP_SLOT; |
| 264 | |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 265 | sdata->vif.bss_conf.ibss_joined = true; |
Sujith Manoharan | c13a765 | 2012-10-12 17:35:45 +0530 | [diff] [blame] | 266 | sdata->vif.bss_conf.ibss_creator = creator; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 267 | ieee80211_bss_info_change_notify(sdata, bss_change); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 268 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 269 | ieee80211_sta_def_wmm_params(sdata, rates, supp_rates); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 270 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 271 | ifibss->state = IEEE80211_IBSS_MLME_JOINED; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 272 | mod_timer(&ifibss->timer, |
| 273 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 274 | |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 275 | scan_width = cfg80211_chandef_to_scan_width(&chandef); |
| 276 | bss = cfg80211_inform_bss_width_frame(local->hw.wiphy, chan, |
| 277 | scan_width, mgmt, |
| 278 | presp->head_len, 0, GFP_KERNEL); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 279 | cfg80211_put_bss(local->hw.wiphy, bss); |
Eliad Peller | 86a2ea4 | 2011-11-08 15:36:59 +0200 | [diff] [blame] | 280 | netif_carrier_on(sdata->dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 281 | cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 284 | static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
| 285 | struct ieee80211_bss *bss) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 286 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 287 | struct cfg80211_bss *cbss = |
| 288 | container_of((void *)bss, struct cfg80211_bss, priv); |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 289 | struct ieee80211_supported_band *sband; |
| 290 | u32 basic_rates; |
| 291 | int i, j; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 292 | u16 beacon_int = cbss->beacon_interval; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 293 | const struct cfg80211_bss_ies *ies; |
| 294 | u64 tsf; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 295 | u32 rate_flags; |
| 296 | int shift; |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 297 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 298 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 299 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 300 | if (beacon_int < 10) |
| 301 | beacon_int = 10; |
| 302 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 303 | sband = sdata->local->hw.wiphy->bands[cbss->channel->band]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 304 | rate_flags = ieee80211_chandef_rate_flags(&sdata->u.ibss.chandef); |
| 305 | shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 306 | |
| 307 | basic_rates = 0; |
| 308 | |
| 309 | for (i = 0; i < bss->supp_rates_len; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 310 | int rate = bss->supp_rates[i] & 0x7f; |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 311 | bool is_basic = !!(bss->supp_rates[i] & 0x80); |
| 312 | |
| 313 | for (j = 0; j < sband->n_bitrates; j++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 314 | int brate; |
| 315 | if ((rate_flags & sband->bitrates[j].flags) |
| 316 | != rate_flags) |
| 317 | continue; |
| 318 | |
| 319 | brate = DIV_ROUND_UP(sband->bitrates[j].bitrate, |
| 320 | 5 * (1 << shift)); |
| 321 | if (brate == rate) { |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 322 | if (is_basic) |
| 323 | basic_rates |= BIT(j); |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 329 | rcu_read_lock(); |
| 330 | ies = rcu_dereference(cbss->ies); |
| 331 | tsf = ies->tsf; |
| 332 | rcu_read_unlock(); |
| 333 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 334 | __ieee80211_sta_join_ibss(sdata, cbss->bssid, |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 335 | beacon_int, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 336 | cbss->channel, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 337 | basic_rates, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 338 | cbss->capability, |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 339 | tsf, false); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Antonio Quartulli | 52874a5 | 2013-06-18 14:20:40 +0200 | [diff] [blame] | 342 | static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 343 | __acquires(RCU) |
| 344 | { |
| 345 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 346 | u8 addr[ETH_ALEN]; |
| 347 | |
| 348 | memcpy(addr, sta->sta.addr, ETH_ALEN); |
| 349 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 350 | ibss_dbg(sdata, "Adding new IBSS station %pM\n", addr); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 351 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 352 | sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); |
| 353 | sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 354 | /* authorize the station only if the network is not RSN protected. If |
| 355 | * not wait for the userspace to authorize it */ |
| 356 | if (!sta->sdata->u.ibss.control_port) |
| 357 | sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 358 | |
| 359 | rate_control_rate_init(sta); |
| 360 | |
| 361 | /* If it fails, maybe we raced another insertion? */ |
| 362 | if (sta_info_insert_rcu(sta)) |
| 363 | return sta_info_get(sdata, addr); |
| 364 | return sta; |
| 365 | } |
| 366 | |
| 367 | static struct sta_info * |
Antonio Quartulli | 52874a5 | 2013-06-18 14:20:40 +0200 | [diff] [blame] | 368 | ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, const u8 *bssid, |
| 369 | const u8 *addr, u32 supp_rates) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 370 | __acquires(RCU) |
| 371 | { |
| 372 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 373 | struct ieee80211_local *local = sdata->local; |
| 374 | struct sta_info *sta; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 375 | struct ieee80211_chanctx_conf *chanctx_conf; |
Ashok Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 376 | struct ieee80211_supported_band *sband; |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 377 | enum nl80211_bss_scan_width scan_width; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 378 | int band; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 379 | |
| 380 | /* |
| 381 | * XXX: Consider removing the least recently used entry and |
| 382 | * allow new one to be added. |
| 383 | */ |
| 384 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 385 | net_info_ratelimited("%s: No room for a new IBSS STA entry %pM\n", |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 386 | sdata->name, addr); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 387 | rcu_read_lock(); |
| 388 | return NULL; |
| 389 | } |
| 390 | |
| 391 | if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) { |
| 392 | rcu_read_lock(); |
| 393 | return NULL; |
| 394 | } |
| 395 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 396 | if (!ether_addr_equal(bssid, sdata->u.ibss.bssid)) { |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 397 | rcu_read_lock(); |
| 398 | return NULL; |
| 399 | } |
| 400 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 401 | rcu_read_lock(); |
| 402 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 403 | if (WARN_ON_ONCE(!chanctx_conf)) |
| 404 | return NULL; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 405 | band = chanctx_conf->def.chan->band; |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 406 | scan_width = cfg80211_chandef_to_scan_width(&chanctx_conf->def); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 407 | rcu_read_unlock(); |
| 408 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 409 | sta = sta_info_alloc(sdata, addr, GFP_KERNEL); |
| 410 | if (!sta) { |
| 411 | rcu_read_lock(); |
| 412 | return NULL; |
| 413 | } |
| 414 | |
| 415 | sta->last_rx = jiffies; |
| 416 | |
| 417 | /* make sure mandatory rates are always added */ |
Ashok Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 418 | sband = local->hw.wiphy->bands[band]; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 419 | sta->sta.supp_rates[band] = supp_rates | |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 420 | ieee80211_mandatory_rates(sband, scan_width); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 421 | |
Antonio Quartulli | 52874a5 | 2013-06-18 14:20:40 +0200 | [diff] [blame] | 422 | return ieee80211_ibss_finish_sta(sta); |
Antonio Quartulli | 6d810f1 | 2012-01-18 00:10:44 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Antonio Quartulli | 2cc59e7 | 2012-09-07 13:28:53 +0200 | [diff] [blame] | 425 | static void ieee80211_rx_mgmt_deauth_ibss(struct ieee80211_sub_if_data *sdata, |
| 426 | struct ieee80211_mgmt *mgmt, |
| 427 | size_t len) |
| 428 | { |
| 429 | u16 reason = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 430 | |
| 431 | if (len < IEEE80211_DEAUTH_FRAME_LEN) |
| 432 | return; |
| 433 | |
| 434 | ibss_dbg(sdata, "RX DeAuth SA=%pM DA=%pM BSSID=%pM (reason: %d)\n", |
| 435 | mgmt->sa, mgmt->da, mgmt->bssid, reason); |
| 436 | sta_info_destroy_addr(sdata, mgmt->sa); |
| 437 | } |
| 438 | |
Antonio Quartulli | 6d810f1 | 2012-01-18 00:10:44 +0100 | [diff] [blame] | 439 | static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata, |
| 440 | struct ieee80211_mgmt *mgmt, |
| 441 | size_t len) |
| 442 | { |
| 443 | u16 auth_alg, auth_transaction; |
| 444 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 445 | sdata_assert_lock(sdata); |
Antonio Quartulli | 6d810f1 | 2012-01-18 00:10:44 +0100 | [diff] [blame] | 446 | |
| 447 | if (len < 24 + 6) |
| 448 | return; |
| 449 | |
| 450 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 451 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 452 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 453 | ibss_dbg(sdata, |
| 454 | "RX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=%d)\n", |
| 455 | mgmt->sa, mgmt->da, mgmt->bssid, auth_transaction); |
Antonio Quartulli | 7bed205 | 2012-11-25 23:24:27 +0100 | [diff] [blame] | 456 | |
| 457 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) |
| 458 | return; |
| 459 | |
Antonio Quartulli | 2cc59e7 | 2012-09-07 13:28:53 +0200 | [diff] [blame] | 460 | /* |
Antonio Quartulli | 6d810f1 | 2012-01-18 00:10:44 +0100 | [diff] [blame] | 461 | * IEEE 802.11 standard does not require authentication in IBSS |
| 462 | * networks and most implementations do not seem to use it. |
| 463 | * However, try to reply to authentication attempts if someone |
| 464 | * has actually implemented this. |
| 465 | */ |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 466 | ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, 0, NULL, 0, |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 467 | mgmt->sa, sdata->u.ibss.bssid, NULL, 0, 0, 0); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 470 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 471 | struct ieee80211_mgmt *mgmt, size_t len, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 472 | struct ieee80211_rx_status *rx_status, |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 473 | struct ieee802_11_elems *elems) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 474 | { |
| 475 | struct ieee80211_local *local = sdata->local; |
| 476 | int freq; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 477 | struct cfg80211_bss *cbss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 478 | struct ieee80211_bss *bss; |
| 479 | struct sta_info *sta; |
| 480 | struct ieee80211_channel *channel; |
| 481 | u64 beacon_timestamp, rx_timestamp; |
| 482 | u32 supp_rates = 0; |
| 483 | enum ieee80211_band band = rx_status->band; |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 484 | enum nl80211_bss_scan_width scan_width; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 485 | struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; |
| 486 | bool rates_updated = false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 487 | |
Johannes Berg | 1cd8e88 | 2013-03-27 14:30:12 +0100 | [diff] [blame] | 488 | if (elems->ds_params) |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 489 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
| 490 | band); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 491 | else |
| 492 | freq = rx_status->freq; |
| 493 | |
| 494 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 495 | |
| 496 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 497 | return; |
| 498 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 499 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 500 | ether_addr_equal(mgmt->bssid, sdata->u.ibss.bssid)) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 501 | |
| 502 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 503 | sta = sta_info_get(sdata, mgmt->sa); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 504 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 505 | if (elems->supp_rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 506 | supp_rates = ieee80211_sta_get_rates(sdata, elems, |
Ashok Nagarajan | 9ebb61a | 2012-04-02 21:21:21 -0700 | [diff] [blame] | 507 | band, NULL); |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 508 | if (sta) { |
| 509 | u32 prev_rates; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 510 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 511 | prev_rates = sta->sta.supp_rates[band]; |
| 512 | /* make sure mandatory rates are always added */ |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 513 | scan_width = NL80211_BSS_CHAN_WIDTH_20; |
| 514 | if (rx_status->flag & RX_FLAG_5MHZ) |
| 515 | scan_width = NL80211_BSS_CHAN_WIDTH_5; |
| 516 | if (rx_status->flag & RX_FLAG_10MHZ) |
| 517 | scan_width = NL80211_BSS_CHAN_WIDTH_10; |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 518 | |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 519 | sta->sta.supp_rates[band] = supp_rates | |
| 520 | ieee80211_mandatory_rates(sband, |
| 521 | scan_width); |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 522 | if (sta->sta.supp_rates[band] != prev_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 523 | ibss_dbg(sdata, |
| 524 | "updated supp_rates set for %pM based on beacon/probe_resp (0x%x -> 0x%x)\n", |
| 525 | sta->sta.addr, prev_rates, |
| 526 | sta->sta.supp_rates[band]); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 527 | rates_updated = true; |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 528 | } |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 529 | } else { |
| 530 | rcu_read_unlock(); |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 531 | sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid, |
Antonio Quartulli | 52874a5 | 2013-06-18 14:20:40 +0200 | [diff] [blame] | 532 | mgmt->sa, supp_rates); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 533 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 534 | } |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 535 | |
| 536 | if (sta && elems->wmm_info) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 537 | set_sta_flag(sta, WLAN_STA_WME); |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 538 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 539 | if (sta && elems->ht_operation && elems->ht_cap_elem && |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 540 | sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 541 | sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_5 && |
| 542 | sdata->u.ibss.chandef.width != NL80211_CHAN_WIDTH_10) { |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 543 | /* we both use HT */ |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 544 | struct ieee80211_ht_cap htcap_ie; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 545 | struct cfg80211_chan_def chandef; |
| 546 | |
| 547 | ieee80211_ht_oper_to_chandef(channel, |
| 548 | elems->ht_operation, |
| 549 | &chandef); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 550 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 551 | memcpy(&htcap_ie, elems->ht_cap_elem, sizeof(htcap_ie)); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 552 | |
| 553 | /* |
| 554 | * fall back to HT20 if we don't use or use |
| 555 | * the other extension channel |
| 556 | */ |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 557 | if (chandef.center_freq1 != |
| 558 | sdata->u.ibss.chandef.center_freq1) |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 559 | htcap_ie.cap_info &= |
| 560 | cpu_to_le16(~IEEE80211_HT_CAP_SUP_WIDTH_20_40); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 561 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 562 | rates_updated |= ieee80211_ht_cap_ie_to_sta_ht_cap( |
| 563 | sdata, sband, &htcap_ie, sta); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Antonio Quartulli | e687f61 | 2012-08-12 18:24:55 +0200 | [diff] [blame] | 566 | if (sta && rates_updated) { |
| 567 | drv_sta_rc_update(local, sdata, &sta->sta, |
| 568 | IEEE80211_RC_SUPP_RATES_CHANGED); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 569 | rate_control_rate_init(sta); |
Antonio Quartulli | e687f61 | 2012-08-12 18:24:55 +0200 | [diff] [blame] | 570 | } |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 571 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 572 | rcu_read_unlock(); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 576 | channel); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 577 | if (!bss) |
| 578 | return; |
| 579 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 580 | cbss = container_of((void *)bss, struct cfg80211_bss, priv); |
| 581 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 582 | /* same for beacon and probe response */ |
| 583 | beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 584 | |
| 585 | /* check if we need to merge IBSS */ |
| 586 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 587 | /* we use a fixed BSSID */ |
Benoit Papillault | a98bfec | 2010-01-17 22:45:24 +0100 | [diff] [blame] | 588 | if (sdata->u.ibss.fixed_bssid) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 589 | goto put_bss; |
| 590 | |
| 591 | /* not an IBSS */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 592 | if (!(cbss->capability & WLAN_CAPABILITY_IBSS)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 593 | goto put_bss; |
| 594 | |
| 595 | /* different channel */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 596 | if (sdata->u.ibss.fixed_channel && |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 597 | sdata->u.ibss.chandef.chan != cbss->channel) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 598 | goto put_bss; |
| 599 | |
| 600 | /* different SSID */ |
| 601 | if (elems->ssid_len != sdata->u.ibss.ssid_len || |
| 602 | memcmp(elems->ssid, sdata->u.ibss.ssid, |
| 603 | sdata->u.ibss.ssid_len)) |
| 604 | goto put_bss; |
| 605 | |
Alina Friedrichsen | 34e8f08 | 2009-02-22 00:07:28 +0100 | [diff] [blame] | 606 | /* same BSSID */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 607 | if (ether_addr_equal(cbss->bssid, sdata->u.ibss.bssid)) |
Alina Friedrichsen | 34e8f08 | 2009-02-22 00:07:28 +0100 | [diff] [blame] | 608 | goto put_bss; |
| 609 | |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 610 | if (ieee80211_have_rx_timestamp(rx_status)) { |
| 611 | /* time when timestamp field was received */ |
| 612 | rx_timestamp = |
| 613 | ieee80211_calculate_rx_timestamp(local, rx_status, |
| 614 | len + FCS_LEN, 24); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 615 | } else { |
| 616 | /* |
| 617 | * second best option: get current TSF |
| 618 | * (will return -1 if not supported) |
| 619 | */ |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 620 | rx_timestamp = drv_get_tsf(local, sdata); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 621 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 622 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 623 | ibss_dbg(sdata, |
| 624 | "RX beacon SA=%pM BSSID=%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", |
| 625 | mgmt->sa, mgmt->bssid, |
| 626 | (unsigned long long)rx_timestamp, |
| 627 | (unsigned long long)beacon_timestamp, |
| 628 | (unsigned long long)(rx_timestamp - beacon_timestamp), |
| 629 | jiffies); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 630 | |
| 631 | if (beacon_timestamp > rx_timestamp) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 632 | ibss_dbg(sdata, |
| 633 | "beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n", |
| 634 | mgmt->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 635 | ieee80211_sta_join_ibss(sdata, bss); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 636 | supp_rates = ieee80211_sta_get_rates(sdata, elems, band, NULL); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 637 | ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, |
Antonio Quartulli | 52874a5 | 2013-06-18 14:20:40 +0200 | [diff] [blame] | 638 | supp_rates); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 639 | rcu_read_unlock(); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | put_bss: |
| 643 | ieee80211_rx_bss_put(local, bss); |
| 644 | } |
| 645 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 646 | void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata, |
| 647 | const u8 *bssid, const u8 *addr, |
| 648 | u32 supp_rates) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 649 | { |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 650 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 651 | struct ieee80211_local *local = sdata->local; |
| 652 | struct sta_info *sta; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 653 | struct ieee80211_chanctx_conf *chanctx_conf; |
Ashok Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 654 | struct ieee80211_supported_band *sband; |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 655 | enum nl80211_bss_scan_width scan_width; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 656 | int band; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 657 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 658 | /* |
| 659 | * XXX: Consider removing the least recently used entry and |
| 660 | * allow new one to be added. |
| 661 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 662 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 663 | net_info_ratelimited("%s: No room for a new IBSS STA entry %pM\n", |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 664 | sdata->name, addr); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 665 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 666 | } |
| 667 | |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 668 | if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 669 | return; |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 670 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 671 | if (!ether_addr_equal(bssid, sdata->u.ibss.bssid)) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 672 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 673 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 674 | rcu_read_lock(); |
| 675 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 676 | if (WARN_ON_ONCE(!chanctx_conf)) { |
| 677 | rcu_read_unlock(); |
| 678 | return; |
| 679 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 680 | band = chanctx_conf->def.chan->band; |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 681 | scan_width = cfg80211_chandef_to_scan_width(&chanctx_conf->def); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 682 | rcu_read_unlock(); |
| 683 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 684 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 685 | if (!sta) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 686 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 687 | |
Rajkumar Manoharan | c8716d9 | 2010-10-23 10:59:57 +0530 | [diff] [blame] | 688 | sta->last_rx = jiffies; |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 689 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 690 | /* make sure mandatory rates are always added */ |
Ashok Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 691 | sband = local->hw.wiphy->bands[band]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 692 | sta->sta.supp_rates[band] = supp_rates | |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 693 | ieee80211_mandatory_rates(sband, scan_width); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 694 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 695 | spin_lock(&ifibss->incomplete_lock); |
| 696 | list_add(&sta->list, &ifibss->incomplete_stations); |
| 697 | spin_unlock(&ifibss->incomplete_lock); |
| 698 | ieee80211_queue_work(&local->hw, &sdata->work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
| 702 | { |
| 703 | struct ieee80211_local *local = sdata->local; |
| 704 | int active = 0; |
| 705 | struct sta_info *sta; |
| 706 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 707 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 708 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 709 | rcu_read_lock(); |
| 710 | |
| 711 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 712 | if (sta->sdata == sdata && |
| 713 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 714 | jiffies)) { |
| 715 | active++; |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | rcu_read_unlock(); |
| 721 | |
| 722 | return active; |
| 723 | } |
| 724 | |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 725 | /* |
| 726 | * This function is called with state == IEEE80211_IBSS_MLME_JOINED |
| 727 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 728 | |
| 729 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) |
| 730 | { |
| 731 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 732 | enum nl80211_bss_scan_width scan_width; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 733 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 734 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 735 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 736 | mod_timer(&ifibss->timer, |
| 737 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 738 | |
| 739 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 740 | |
Sujith | 450aae3 | 2009-11-02 12:33:23 +0530 | [diff] [blame] | 741 | if (time_before(jiffies, ifibss->last_scan_completed + |
| 742 | IEEE80211_IBSS_MERGE_INTERVAL)) |
| 743 | return; |
| 744 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 745 | if (ieee80211_sta_active_ibss(sdata)) |
| 746 | return; |
| 747 | |
John W. Linville | c037b83 | 2012-01-30 15:28:11 -0500 | [diff] [blame] | 748 | if (ifibss->fixed_channel) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 749 | return; |
| 750 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 751 | sdata_info(sdata, |
| 752 | "No active IBSS STAs - trying to scan for other IBSS networks with same SSID (merge)\n"); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 753 | |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 754 | scan_width = cfg80211_chandef_to_scan_width(&ifibss->chandef); |
Stanislaw Gruszka | 34bcf71 | 2012-12-11 10:48:23 +0100 | [diff] [blame] | 755 | ieee80211_request_ibss_scan(sdata, ifibss->ssid, ifibss->ssid_len, |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 756 | NULL, scan_width); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 757 | } |
| 758 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 759 | static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 760 | { |
| 761 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 762 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 763 | u16 capability; |
| 764 | int i; |
| 765 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 766 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 767 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 768 | if (ifibss->fixed_bssid) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 769 | memcpy(bssid, ifibss->bssid, ETH_ALEN); |
| 770 | } else { |
| 771 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 772 | * own MAC address to make sure that devices that do not have proper |
| 773 | * random number generator get different BSSID. */ |
| 774 | get_random_bytes(bssid, ETH_ALEN); |
| 775 | for (i = 0; i < ETH_ALEN; i++) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 776 | bssid[i] ^= sdata->vif.addr[i]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 777 | bssid[0] &= ~0x01; |
| 778 | bssid[0] |= 0x02; |
| 779 | } |
| 780 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 781 | sdata_info(sdata, "Creating new IBSS network, BSSID %pM\n", bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 782 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 783 | capability = WLAN_CAPABILITY_IBSS; |
| 784 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 785 | if (ifibss->privacy) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 786 | capability |= WLAN_CAPABILITY_PRIVACY; |
| 787 | else |
| 788 | sdata->drop_unencrypted = 0; |
| 789 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 790 | __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int, |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 791 | ifibss->chandef.chan, ifibss->basic_rates, |
Sujith Manoharan | c13a765 | 2012-10-12 17:35:45 +0530 | [diff] [blame] | 792 | capability, 0, true); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 793 | } |
| 794 | |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 795 | /* |
| 796 | * This function is called with state == IEEE80211_IBSS_MLME_SEARCH |
| 797 | */ |
| 798 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 799 | static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 800 | { |
| 801 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 802 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 803 | struct cfg80211_bss *cbss; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 804 | struct ieee80211_channel *chan = NULL; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 805 | const u8 *bssid = NULL; |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 806 | enum nl80211_bss_scan_width scan_width; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 807 | int active_ibss; |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 808 | u16 capability; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 809 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 810 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 811 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 812 | active_ibss = ieee80211_sta_active_ibss(sdata); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 813 | ibss_dbg(sdata, "sta_find_ibss (active_ibss=%d)\n", active_ibss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 814 | |
| 815 | if (active_ibss) |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 816 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 817 | |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 818 | capability = WLAN_CAPABILITY_IBSS; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 819 | if (ifibss->privacy) |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 820 | capability |= WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 821 | if (ifibss->fixed_bssid) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 822 | bssid = ifibss->bssid; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 823 | if (ifibss->fixed_channel) |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 824 | chan = ifibss->chandef.chan; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 825 | if (!is_zero_ether_addr(ifibss->bssid)) |
| 826 | bssid = ifibss->bssid; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 827 | cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid, |
| 828 | ifibss->ssid, ifibss->ssid_len, |
| 829 | WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY, |
| 830 | capability); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 831 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 832 | if (cbss) { |
| 833 | struct ieee80211_bss *bss; |
| 834 | |
| 835 | bss = (void *)cbss->priv; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 836 | ibss_dbg(sdata, |
| 837 | "sta_find_ibss: selected %pM current %pM\n", |
| 838 | cbss->bssid, ifibss->bssid); |
| 839 | sdata_info(sdata, |
| 840 | "Selected IBSS BSSID %pM based on configured SSID\n", |
| 841 | cbss->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 842 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 843 | ieee80211_sta_join_ibss(sdata, bss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 844 | ieee80211_rx_bss_put(local, bss); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 845 | return; |
Reinette Chatre | d419b9f | 2009-10-19 14:55:37 -0700 | [diff] [blame] | 846 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 847 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 848 | ibss_dbg(sdata, "sta_find_ibss: did not try to join ibss\n"); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 849 | |
| 850 | /* Selected IBSS not found in current scan results - try to scan */ |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 851 | if (time_after(jiffies, ifibss->last_scan_completed + |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 852 | IEEE80211_SCAN_INTERVAL)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 853 | sdata_info(sdata, "Trigger new scan to find an IBSS to join\n"); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 854 | |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 855 | scan_width = cfg80211_chandef_to_scan_width(&ifibss->chandef); |
Stanislaw Gruszka | 34bcf71 | 2012-12-11 10:48:23 +0100 | [diff] [blame] | 856 | ieee80211_request_ibss_scan(sdata, ifibss->ssid, |
Simon Wunderlich | 7ca15a0 | 2013-07-08 16:55:56 +0200 | [diff] [blame^] | 857 | ifibss->ssid_len, chan, |
| 858 | scan_width); |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 859 | } else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 860 | int interval = IEEE80211_SCAN_INTERVAL; |
| 861 | |
| 862 | if (time_after(jiffies, ifibss->ibss_join_req + |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 863 | IEEE80211_IBSS_JOIN_TIMEOUT)) |
| 864 | ieee80211_sta_create_ibss(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 865 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 866 | mod_timer(&ifibss->timer, |
| 867 | round_jiffies(jiffies + interval)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 868 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 872 | struct sk_buff *req) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 873 | { |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 874 | struct ieee80211_mgmt *mgmt = (void *)req->data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 875 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 876 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 877 | int tx_last_beacon, len = req->len; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 878 | struct sk_buff *skb; |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 879 | struct beacon_data *presp; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 880 | u8 *pos, *end; |
| 881 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 882 | sdata_assert_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 883 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 884 | presp = rcu_dereference_protected(ifibss->presp, |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 885 | lockdep_is_held(&sdata->wdev.mtx)); |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 886 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 887 | if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 888 | len < 24 + 2 || !presp) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 889 | return; |
| 890 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 891 | tx_last_beacon = drv_tx_last_beacon(local); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 892 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 893 | ibss_dbg(sdata, |
| 894 | "RX ProbeReq SA=%pM DA=%pM BSSID=%pM (tx_last_beacon=%d)\n", |
| 895 | mgmt->sa, mgmt->da, mgmt->bssid, tx_last_beacon); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 896 | |
Felix Fietkau | 1ed7648 | 2011-03-24 19:46:18 +0100 | [diff] [blame] | 897 | if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 898 | return; |
| 899 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 900 | if (!ether_addr_equal(mgmt->bssid, ifibss->bssid) && |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 901 | !is_broadcast_ether_addr(mgmt->bssid)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 902 | return; |
| 903 | |
| 904 | end = ((u8 *) mgmt) + len; |
| 905 | pos = mgmt->u.probe_req.variable; |
| 906 | if (pos[0] != WLAN_EID_SSID || |
| 907 | pos + 2 + pos[1] > end) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 908 | ibss_dbg(sdata, "Invalid SSID IE in ProbeReq from %pM\n", |
| 909 | mgmt->sa); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | if (pos[1] != 0 && |
| 913 | (pos[1] != ifibss->ssid_len || |
Benoit Papillault | 0da780c | 2010-02-05 01:21:03 +0100 | [diff] [blame] | 914 | memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 915 | /* Ignore ProbeReq for foreign SSID */ |
| 916 | return; |
| 917 | } |
| 918 | |
| 919 | /* Reply with ProbeResp */ |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 920 | skb = dev_alloc_skb(local->tx_headroom + presp->head_len); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 921 | if (!skb) |
| 922 | return; |
| 923 | |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 924 | skb_reserve(skb, local->tx_headroom); |
| 925 | memcpy(skb_put(skb, presp->head_len), presp->head, presp->head_len); |
| 926 | |
| 927 | memcpy(((struct ieee80211_mgmt *) skb->data)->da, mgmt->sa, ETH_ALEN); |
| 928 | ibss_dbg(sdata, "Sending ProbeResp to %pM\n", mgmt->sa); |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 929 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 930 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 931 | } |
| 932 | |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 933 | static |
| 934 | void ieee80211_rx_mgmt_probe_beacon(struct ieee80211_sub_if_data *sdata, |
| 935 | struct ieee80211_mgmt *mgmt, size_t len, |
| 936 | struct ieee80211_rx_status *rx_status) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 937 | { |
| 938 | size_t baselen; |
| 939 | struct ieee802_11_elems elems; |
| 940 | |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 941 | BUILD_BUG_ON(offsetof(typeof(mgmt->u.probe_resp), variable) != |
| 942 | offsetof(typeof(mgmt->u.beacon), variable)); |
| 943 | |
| 944 | /* |
| 945 | * either beacon or probe_resp but the variable field is at the |
| 946 | * same offset |
| 947 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 948 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 949 | if (baselen > len) |
| 950 | return; |
| 951 | |
| 952 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
Johannes Berg | b2e506b | 2013-03-26 14:54:16 +0100 | [diff] [blame] | 953 | false, &elems); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 954 | |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 955 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 956 | } |
| 957 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 958 | void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 959 | struct sk_buff *skb) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 960 | { |
| 961 | struct ieee80211_rx_status *rx_status; |
| 962 | struct ieee80211_mgmt *mgmt; |
| 963 | u16 fc; |
| 964 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 965 | rx_status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 966 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 967 | fc = le16_to_cpu(mgmt->frame_control); |
| 968 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 969 | sdata_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 970 | |
Tim Harvey | c926d00 | 2010-12-09 10:43:13 -0800 | [diff] [blame] | 971 | if (!sdata->u.ibss.ssid_len) |
| 972 | goto mgmt_out; /* not ready to merge yet */ |
| 973 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 974 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 975 | case IEEE80211_STYPE_PROBE_REQ: |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 976 | ieee80211_rx_mgmt_probe_req(sdata, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 977 | break; |
| 978 | case IEEE80211_STYPE_PROBE_RESP: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 979 | case IEEE80211_STYPE_BEACON: |
Emmanuel Grumbach | d45c417 | 2012-12-10 16:19:13 +0200 | [diff] [blame] | 980 | ieee80211_rx_mgmt_probe_beacon(sdata, mgmt, skb->len, |
| 981 | rx_status); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 982 | break; |
| 983 | case IEEE80211_STYPE_AUTH: |
| 984 | ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len); |
| 985 | break; |
Antonio Quartulli | 2cc59e7 | 2012-09-07 13:28:53 +0200 | [diff] [blame] | 986 | case IEEE80211_STYPE_DEAUTH: |
| 987 | ieee80211_rx_mgmt_deauth_ibss(sdata, mgmt, skb->len); |
| 988 | break; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 989 | } |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 990 | |
Tim Harvey | c926d00 | 2010-12-09 10:43:13 -0800 | [diff] [blame] | 991 | mgmt_out: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 992 | sdata_unlock(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 993 | } |
| 994 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 995 | void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 996 | { |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 997 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 998 | struct sta_info *sta; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 999 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1000 | sdata_lock(sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1001 | |
| 1002 | /* |
| 1003 | * Work could be scheduled after scan or similar |
| 1004 | * when we aren't even joined (or trying) with a |
| 1005 | * network. |
| 1006 | */ |
| 1007 | if (!ifibss->ssid_len) |
| 1008 | goto out; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1009 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1010 | spin_lock_bh(&ifibss->incomplete_lock); |
| 1011 | while (!list_empty(&ifibss->incomplete_stations)) { |
| 1012 | sta = list_first_entry(&ifibss->incomplete_stations, |
| 1013 | struct sta_info, list); |
| 1014 | list_del(&sta->list); |
| 1015 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 1016 | |
Antonio Quartulli | 52874a5 | 2013-06-18 14:20:40 +0200 | [diff] [blame] | 1017 | ieee80211_ibss_finish_sta(sta); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1018 | rcu_read_unlock(); |
| 1019 | spin_lock_bh(&ifibss->incomplete_lock); |
| 1020 | } |
| 1021 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 1022 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1023 | switch (ifibss->state) { |
| 1024 | case IEEE80211_IBSS_MLME_SEARCH: |
| 1025 | ieee80211_sta_find_ibss(sdata); |
| 1026 | break; |
| 1027 | case IEEE80211_IBSS_MLME_JOINED: |
| 1028 | ieee80211_sta_merge_ibss(sdata); |
| 1029 | break; |
| 1030 | default: |
| 1031 | WARN_ON(1); |
| 1032 | break; |
| 1033 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1034 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1035 | out: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1036 | sdata_unlock(sdata); |
Johannes Berg | 3a4d4aa | 2010-05-26 16:41:40 +0200 | [diff] [blame] | 1037 | } |
| 1038 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1039 | static void ieee80211_ibss_timer(unsigned long data) |
| 1040 | { |
| 1041 | struct ieee80211_sub_if_data *sdata = |
| 1042 | (struct ieee80211_sub_if_data *) data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1043 | |
Stanislaw Gruszka | a618294 | 2013-02-28 10:55:28 +0100 | [diff] [blame] | 1044 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 1048 | { |
| 1049 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 1050 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1051 | setup_timer(&ifibss->timer, ieee80211_ibss_timer, |
| 1052 | (unsigned long) sdata); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1053 | INIT_LIST_HEAD(&ifibss->incomplete_stations); |
| 1054 | spin_lock_init(&ifibss->incomplete_lock); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /* scan finished notification */ |
| 1058 | void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) |
| 1059 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1060 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1061 | |
Johannes Berg | 29b4a4f | 2009-04-21 00:30:49 +0200 | [diff] [blame] | 1062 | mutex_lock(&local->iflist_mtx); |
| 1063 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1064 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 1065 | continue; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1066 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC) |
| 1067 | continue; |
| 1068 | sdata->u.ibss.last_scan_completed = jiffies; |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1069 | ieee80211_queue_work(&local->hw, &sdata->work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1070 | } |
Johannes Berg | 29b4a4f | 2009-04-21 00:30:49 +0200 | [diff] [blame] | 1071 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1074 | int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, |
| 1075 | struct cfg80211_ibss_params *params) |
| 1076 | { |
Simon Wunderlich | ff3cc5f | 2011-11-30 16:56:33 +0100 | [diff] [blame] | 1077 | u32 changed = 0; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 1078 | u32 rate_flags; |
| 1079 | struct ieee80211_supported_band *sband; |
| 1080 | int i; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1081 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1082 | if (params->bssid) { |
| 1083 | memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN); |
| 1084 | sdata->u.ibss.fixed_bssid = true; |
| 1085 | } else |
| 1086 | sdata->u.ibss.fixed_bssid = false; |
| 1087 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1088 | sdata->u.ibss.privacy = params->privacy; |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 1089 | sdata->u.ibss.control_port = params->control_port; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 1090 | sdata->u.ibss.basic_rates = params->basic_rates; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 1091 | |
| 1092 | /* fix basic_rates if channel does not support these rates */ |
| 1093 | rate_flags = ieee80211_chandef_rate_flags(¶ms->chandef); |
| 1094 | sband = sdata->local->hw.wiphy->bands[params->chandef.chan->band]; |
| 1095 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1096 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) |
| 1097 | sdata->u.ibss.basic_rates &= ~BIT(i); |
| 1098 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 1099 | memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate, |
| 1100 | sizeof(params->mcast_rate)); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1101 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1102 | sdata->vif.bss_conf.beacon_int = params->beacon_interval; |
| 1103 | |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 1104 | sdata->u.ibss.chandef = params->chandef; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1105 | sdata->u.ibss.fixed_channel = params->channel_fixed; |
| 1106 | |
| 1107 | if (params->ie) { |
| 1108 | sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len, |
| 1109 | GFP_KERNEL); |
| 1110 | if (sdata->u.ibss.ie) |
| 1111 | sdata->u.ibss.ie_len = params->ie_len; |
| 1112 | } |
| 1113 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1114 | sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; |
| 1115 | sdata->u.ibss.ibss_join_req = jiffies; |
| 1116 | |
Antonio Quartulli | badecb0 | 2012-10-26 18:54:25 +0200 | [diff] [blame] | 1117 | memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len); |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 1118 | sdata->u.ibss.ssid_len = params->ssid_len; |
| 1119 | |
Simon Wunderlich | 822854b | 2013-06-28 10:39:59 +0200 | [diff] [blame] | 1120 | memcpy(&sdata->u.ibss.ht_capa, ¶ms->ht_capa, |
| 1121 | sizeof(sdata->u.ibss.ht_capa)); |
| 1122 | memcpy(&sdata->u.ibss.ht_capa_mask, ¶ms->ht_capa_mask, |
| 1123 | sizeof(sdata->u.ibss.ht_capa_mask)); |
| 1124 | |
Simon Wunderlich | ff3cc5f | 2011-11-30 16:56:33 +0100 | [diff] [blame] | 1125 | /* |
| 1126 | * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is |
| 1127 | * reserved, but an HT STA shall protect HT transmissions as though |
| 1128 | * the HT Protection field were set to non-HT mixed mode. |
| 1129 | * |
| 1130 | * In an IBSS, the RIFS Mode field of the HT Operation element is |
| 1131 | * also reserved, but an HT STA shall operate as though this field |
| 1132 | * were set to 1. |
| 1133 | */ |
| 1134 | |
| 1135 | sdata->vif.bss_conf.ht_operation_mode |= |
| 1136 | IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED |
| 1137 | | IEEE80211_HT_PARAM_RIFS_MODE; |
| 1138 | |
| 1139 | changed |= BSS_CHANGED_HT; |
| 1140 | ieee80211_bss_info_change_notify(sdata, changed); |
| 1141 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 1142 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 1143 | sdata->needed_rx_chains = sdata->local->rx_chains; |
| 1144 | |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 1145 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
| 1150 | int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata) |
| 1151 | { |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1152 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 1153 | struct ieee80211_local *local = sdata->local; |
| 1154 | struct cfg80211_bss *cbss; |
| 1155 | u16 capability; |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1156 | int active_ibss; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1157 | struct sta_info *sta; |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 1158 | struct beacon_data *presp; |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1159 | |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1160 | active_ibss = ieee80211_sta_active_ibss(sdata); |
| 1161 | |
| 1162 | if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) { |
| 1163 | capability = WLAN_CAPABILITY_IBSS; |
| 1164 | |
| 1165 | if (ifibss->privacy) |
| 1166 | capability |= WLAN_CAPABILITY_PRIVACY; |
| 1167 | |
Simon Wunderlich | 3aede78 | 2013-05-16 13:00:36 +0200 | [diff] [blame] | 1168 | cbss = cfg80211_get_bss(local->hw.wiphy, ifibss->chandef.chan, |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1169 | ifibss->bssid, ifibss->ssid, |
| 1170 | ifibss->ssid_len, WLAN_CAPABILITY_IBSS | |
| 1171 | WLAN_CAPABILITY_PRIVACY, |
| 1172 | capability); |
| 1173 | |
| 1174 | if (cbss) { |
| 1175 | cfg80211_unlink_bss(local->hw.wiphy, cbss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 1176 | cfg80211_put_bss(local->hw.wiphy, cbss); |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1177 | } |
| 1178 | } |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1179 | |
Simon Wunderlich | b78a493 | 2012-11-13 18:43:03 +0100 | [diff] [blame] | 1180 | ifibss->state = IEEE80211_IBSS_MLME_SEARCH; |
| 1181 | memset(ifibss->bssid, 0, ETH_ALEN); |
| 1182 | ifibss->ssid_len = 0; |
| 1183 | |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 1184 | sta_info_flush(sdata); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1185 | |
| 1186 | spin_lock_bh(&ifibss->incomplete_lock); |
| 1187 | while (!list_empty(&ifibss->incomplete_stations)) { |
| 1188 | sta = list_first_entry(&ifibss->incomplete_stations, |
| 1189 | struct sta_info, list); |
| 1190 | list_del(&sta->list); |
| 1191 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 1192 | |
| 1193 | sta_info_free(local, sta); |
| 1194 | spin_lock_bh(&ifibss->incomplete_lock); |
| 1195 | } |
| 1196 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 1197 | |
Eliad Peller | 86a2ea4 | 2011-11-08 15:36:59 +0200 | [diff] [blame] | 1198 | netif_carrier_off(sdata->dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1199 | |
| 1200 | /* remove beacon */ |
| 1201 | kfree(sdata->u.ibss.ie); |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 1202 | presp = rcu_dereference_protected(ifibss->presp, |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1203 | lockdep_is_held(&sdata->wdev.mtx)); |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 1204 | RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); |
Simon Wunderlich | 822854b | 2013-06-28 10:39:59 +0200 | [diff] [blame] | 1205 | |
| 1206 | /* on the next join, re-program HT parameters */ |
| 1207 | memset(&ifibss->ht_capa, 0, sizeof(ifibss->ht_capa)); |
| 1208 | memset(&ifibss->ht_capa_mask, 0, sizeof(ifibss->ht_capa_mask)); |
| 1209 | |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 1210 | sdata->vif.bss_conf.ibss_joined = false; |
Sujith Manoharan | c13a765 | 2012-10-12 17:35:45 +0530 | [diff] [blame] | 1211 | sdata->vif.bss_conf.ibss_creator = false; |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1212 | sdata->vif.bss_conf.enable_beacon = false; |
Marek Puzyniak | 0ca54f6 | 2013-04-10 13:19:13 +0200 | [diff] [blame] | 1213 | sdata->vif.bss_conf.ssid_len = 0; |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1214 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 1215 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | |
| 1216 | BSS_CHANGED_IBSS); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1217 | synchronize_rcu(); |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 1218 | kfree(presp); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1219 | |
Johannes Berg | 35f20c1 | 2010-06-10 10:21:30 +0200 | [diff] [blame] | 1220 | skb_queue_purge(&sdata->skb_queue); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1221 | |
Johannes Berg | bc05d19 | 2010-07-21 10:52:40 +0200 | [diff] [blame] | 1222 | del_timer_sync(&sdata->u.ibss.timer); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1223 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1224 | return 0; |
| 1225 | } |