blob: 16271c2300e9b2062bd94410c80d3287d13ba6de [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
18
19#include <linux/kernel.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020020#include <linux/etherdevice.h>
Hante Meuleman68ca3952014-02-25 20:30:26 +010021#include <linux/module.h>
Franky Lin1bacb042014-06-21 12:11:16 +020022#include <linux/vmalloc.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020023#include <net/cfg80211.h>
Arend van Sprielcbaa1772012-08-30 19:43:02 +020024#include <net/netlink.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020025
26#include <brcmu_utils.h>
27#include <defs.h>
28#include <brcmu_wifi.h>
Hante Meuleman122d3d02014-10-28 14:56:18 +010029#include "core.h"
Hante Meulemana8e8ed32014-10-28 14:56:13 +010030#include "debug.h"
Arend van Spriel40c1c242013-04-05 10:57:44 +020031#include "tracepoint.h"
Hante Meuleman7a5c1f62013-02-08 15:53:44 +010032#include "fwil_types.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010033#include "p2p.h"
Piotr Haber61730d42013-04-23 12:53:12 +020034#include "btcoex.h"
Hante Meulemanbfe81972014-10-28 14:56:16 +010035#include "cfg80211.h"
Arend van Sprielc08437b2014-07-12 08:49:39 +020036#include "feature.h"
Hante Meuleman81f5dcb2012-10-22 10:36:14 -070037#include "fwil.h"
Hante Meuleman8851cce2014-07-30 13:20:02 +020038#include "proto.h"
Franky Lin1bacb042014-06-21 12:11:16 +020039#include "vendor.h"
Hante Meulemand14f78b2014-10-28 14:56:14 +010040#include "bus.h"
Hante Meuleman6b89dcb2014-12-21 12:43:52 +010041#include "common.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020042
Arend van Spriele5806072012-09-19 22:21:08 +020043#define BRCMF_SCAN_IE_LEN_MAX 2048
44#define BRCMF_PNO_VERSION 2
45#define BRCMF_PNO_TIME 30
46#define BRCMF_PNO_REPEAT 4
47#define BRCMF_PNO_FREQ_EXPO_MAX 3
48#define BRCMF_PNO_MAX_PFN_COUNT 16
49#define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
50#define BRCMF_PNO_HIDDEN_BIT 2
51#define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
52#define BRCMF_PNO_SCAN_COMPLETE 1
53#define BRCMF_PNO_SCAN_INCOMPLETE 0
54
Hante Meuleman1a873342012-09-27 14:17:54 +020055#define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
56#define WPA_OUI_TYPE 1
57#define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
58#define WME_OUI_TYPE 2
Hante Meuleman89286dc2013-02-08 15:53:46 +010059#define WPS_OUI_TYPE 4
Hante Meuleman1a873342012-09-27 14:17:54 +020060
61#define VS_IE_FIXED_HDR_LEN 6
62#define WPA_IE_VERSION_LEN 2
63#define WPA_IE_MIN_OUI_LEN 4
64#define WPA_IE_SUITE_COUNT_LEN 2
65
66#define WPA_CIPHER_NONE 0 /* None */
67#define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
68#define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
69#define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
70#define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
71
72#define RSN_AKM_NONE 0 /* None (IBSS) */
73#define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
74#define RSN_AKM_PSK 2 /* Pre-shared Key */
Hante Meuleman240d61a2016-02-17 11:27:10 +010075#define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */
76#define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */
Hante Meuleman1a873342012-09-27 14:17:54 +020077#define RSN_CAP_LEN 2 /* Length of RSN capabilities */
Hante Meuleman240d61a2016-02-17 11:27:10 +010078#define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3))
79#define RSN_CAP_MFPR_MASK BIT(6)
80#define RSN_CAP_MFPC_MASK BIT(7)
81#define RSN_PMKID_COUNT_LEN 2
Hante Meuleman1a873342012-09-27 14:17:54 +020082
83#define VNDR_IE_CMD_LEN 4 /* length of the set command
84 * string :"add", "del" (+ NUL)
85 */
86#define VNDR_IE_COUNT_OFFSET 4
87#define VNDR_IE_PKTFLAG_OFFSET 8
88#define VNDR_IE_VSIE_OFFSET 12
89#define VNDR_IE_HDR_SIZE 12
Arend van Spriel9f440b72013-02-08 15:53:36 +010090#define VNDR_IE_PARSE_LIMIT 5
Hante Meuleman1a873342012-09-27 14:17:54 +020091
92#define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
93#define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
Hante Meuleman04012892012-09-27 14:17:49 +020094
Hante Meuleman89286dc2013-02-08 15:53:46 +010095#define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
96#define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
97#define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
98
Hante Meuleman1678ba82015-12-10 13:43:00 +010099#define BRCMF_SCAN_CHANNEL_TIME 40
100#define BRCMF_SCAN_UNASSOC_TIME 40
101#define BRCMF_SCAN_PASSIVE_TIME 120
102
Hante Meuleman3021ad92016-01-05 11:05:45 +0100103#define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000)
104
Arend van Spriel5b435de2011-10-05 13:19:03 +0200105#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
106 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
107
Arend van Sprielce81e312012-10-22 13:55:37 -0700108static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200109{
Arend van Sprielc1179032012-10-22 13:55:33 -0700110 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100111 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
112 vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200113 return false;
114 }
115 return true;
116}
117
Arend van Spriel5b435de2011-10-05 13:19:03 +0200118#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
119#define RATETAB_ENT(_rateid, _flags) \
120 { \
121 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
122 .hw_value = (_rateid), \
123 .flags = (_flags), \
124 }
125
126static struct ieee80211_rate __wl_rates[] = {
127 RATETAB_ENT(BRCM_RATE_1M, 0),
128 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
129 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
130 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
131 RATETAB_ENT(BRCM_RATE_6M, 0),
132 RATETAB_ENT(BRCM_RATE_9M, 0),
133 RATETAB_ENT(BRCM_RATE_12M, 0),
134 RATETAB_ENT(BRCM_RATE_18M, 0),
135 RATETAB_ENT(BRCM_RATE_24M, 0),
136 RATETAB_ENT(BRCM_RATE_36M, 0),
137 RATETAB_ENT(BRCM_RATE_48M, 0),
138 RATETAB_ENT(BRCM_RATE_54M, 0),
139};
140
Arend van Spriel5b435de2011-10-05 13:19:03 +0200141#define wl_g_rates (__wl_rates + 0)
Arend van Spriel58de92d2015-04-14 20:10:24 +0200142#define wl_g_rates_size ARRAY_SIZE(__wl_rates)
143#define wl_a_rates (__wl_rates + 4)
144#define wl_a_rates_size (wl_g_rates_size - 4)
145
146#define CHAN2G(_channel, _freq) { \
Johannes Berg57fbcce2016-04-12 15:56:15 +0200147 .band = NL80211_BAND_2GHZ, \
Arend van Spriel58de92d2015-04-14 20:10:24 +0200148 .center_freq = (_freq), \
149 .hw_value = (_channel), \
150 .flags = IEEE80211_CHAN_DISABLED, \
151 .max_antenna_gain = 0, \
152 .max_power = 30, \
153}
154
155#define CHAN5G(_channel) { \
Johannes Berg57fbcce2016-04-12 15:56:15 +0200156 .band = NL80211_BAND_5GHZ, \
Arend van Spriel58de92d2015-04-14 20:10:24 +0200157 .center_freq = 5000 + (5 * (_channel)), \
158 .hw_value = (_channel), \
159 .flags = IEEE80211_CHAN_DISABLED, \
160 .max_antenna_gain = 0, \
161 .max_power = 30, \
162}
163
164static struct ieee80211_channel __wl_2ghz_channels[] = {
165 CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427),
166 CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447),
167 CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467),
168 CHAN2G(13, 2472), CHAN2G(14, 2484)
169};
170
171static struct ieee80211_channel __wl_5ghz_channels[] = {
172 CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42),
173 CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56),
174 CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108),
175 CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128),
176 CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149),
177 CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165)
178};
Arend van Spriel5b435de2011-10-05 13:19:03 +0200179
Arend van Sprielb48d8912014-07-12 08:49:41 +0200180/* Band templates duplicated per wiphy. The channel info
Arend van Spriel58de92d2015-04-14 20:10:24 +0200181 * above is added to the band during setup.
Arend van Sprielb48d8912014-07-12 08:49:41 +0200182 */
183static const struct ieee80211_supported_band __wl_band_2ghz = {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200184 .band = NL80211_BAND_2GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200185 .bitrates = wl_g_rates,
186 .n_bitrates = wl_g_rates_size,
187};
188
Arend van Spriel58de92d2015-04-14 20:10:24 +0200189static const struct ieee80211_supported_band __wl_band_5ghz = {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200190 .band = NL80211_BAND_5GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200191 .bitrates = wl_a_rates,
192 .n_bitrates = wl_a_rates_size,
193};
194
Hante Meulemand48200b2013-04-03 12:40:29 +0200195/* This is to override regulatory domains defined in cfg80211 module (reg.c)
196 * By default world regulatory domain defined in reg.c puts the flags
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200197 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
198 * With respect to these flags, wpa_supplicant doesn't * start p2p
199 * operations on 5GHz channels. All the changes in world regulatory
Hante Meulemand48200b2013-04-03 12:40:29 +0200200 * domain are to be done here.
201 */
202static const struct ieee80211_regdomain brcmf_regdom = {
203 .n_reg_rules = 4,
204 .alpha2 = "99",
205 .reg_rules = {
206 /* IEEE 802.11b/g, channels 1..11 */
207 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
208 /* If any */
209 /* IEEE 802.11 channel 14 - Only JP enables
210 * this and for 802.11b only
211 */
212 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
213 /* IEEE 802.11a, channel 36..64 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200214 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
Hante Meulemand48200b2013-04-03 12:40:29 +0200215 /* IEEE 802.11a, channel 100..165 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200216 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200217};
218
Hante Meuleman240d61a2016-02-17 11:27:10 +0100219/* Note: brcmf_cipher_suites is an array of int defining which cipher suites
220 * are supported. A pointer to this array and the number of entries is passed
221 * on to upper layers. AES_CMAC defines whether or not the driver supports MFP.
222 * So the cipher suite AES_CMAC has to be the last one in the array, and when
223 * device does not support MFP then the number of suites will be decreased by 1
224 */
225static const u32 brcmf_cipher_suites[] = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200226 WLAN_CIPHER_SUITE_WEP40,
227 WLAN_CIPHER_SUITE_WEP104,
228 WLAN_CIPHER_SUITE_TKIP,
229 WLAN_CIPHER_SUITE_CCMP,
Hante Meuleman240d61a2016-02-17 11:27:10 +0100230 /* Keep as last entry: */
231 WLAN_CIPHER_SUITE_AES_CMAC
Arend van Spriel5b435de2011-10-05 13:19:03 +0200232};
233
Hante Meuleman1a873342012-09-27 14:17:54 +0200234/* Vendor specific ie. id = 221, oui and type defines exact ie */
235struct brcmf_vs_tlv {
236 u8 id;
237 u8 len;
238 u8 oui[3];
239 u8 oui_type;
240};
241
242struct parsed_vndr_ie_info {
243 u8 *ie_ptr;
244 u32 ie_len; /* total length including id & length field */
245 struct brcmf_vs_tlv vndrie;
246};
247
248struct parsed_vndr_ies {
249 u32 count;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100250 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
Hante Meuleman1a873342012-09-27 14:17:54 +0200251};
252
Arend van Spriel7705ba62016-04-17 16:44:58 +0200253static u8 nl80211_band_to_fwil(enum nl80211_band band)
254{
255 switch (band) {
256 case NL80211_BAND_2GHZ:
257 return WLC_BAND_2G;
258 case NL80211_BAND_5GHZ:
259 return WLC_BAND_5G;
260 default:
261 WARN_ON(1);
262 break;
263 }
264 return 0;
265}
266
Arend van Spriel5a394eb2014-05-27 12:56:15 +0200267static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
268 struct cfg80211_chan_def *ch)
Arend van Spriel600a8972014-05-12 10:47:39 +0200269{
270 struct brcmu_chan ch_inf;
271 s32 primary_offset;
272
273 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
274 ch->chan->center_freq, ch->center_freq1, ch->width);
275 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
Rafał Miłecki36e80722016-01-20 16:46:04 +0100276 primary_offset = ch->chan->center_freq - ch->center_freq1;
Arend van Spriel600a8972014-05-12 10:47:39 +0200277 switch (ch->width) {
278 case NL80211_CHAN_WIDTH_20:
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100279 case NL80211_CHAN_WIDTH_20_NOHT:
Arend van Spriel600a8972014-05-12 10:47:39 +0200280 ch_inf.bw = BRCMU_CHAN_BW_20;
281 WARN_ON(primary_offset != 0);
282 break;
283 case NL80211_CHAN_WIDTH_40:
284 ch_inf.bw = BRCMU_CHAN_BW_40;
Rafał Miłecki36e80722016-01-20 16:46:04 +0100285 if (primary_offset > 0)
Arend van Spriel600a8972014-05-12 10:47:39 +0200286 ch_inf.sb = BRCMU_CHAN_SB_U;
287 else
288 ch_inf.sb = BRCMU_CHAN_SB_L;
289 break;
290 case NL80211_CHAN_WIDTH_80:
291 ch_inf.bw = BRCMU_CHAN_BW_80;
Rafał Miłecki36e80722016-01-20 16:46:04 +0100292 if (primary_offset == -30)
293 ch_inf.sb = BRCMU_CHAN_SB_LL;
294 else if (primary_offset == -10)
295 ch_inf.sb = BRCMU_CHAN_SB_LU;
296 else if (primary_offset == 10)
297 ch_inf.sb = BRCMU_CHAN_SB_UL;
298 else
299 ch_inf.sb = BRCMU_CHAN_SB_UU;
Arend van Spriel600a8972014-05-12 10:47:39 +0200300 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100301 case NL80211_CHAN_WIDTH_80P80:
302 case NL80211_CHAN_WIDTH_160:
303 case NL80211_CHAN_WIDTH_5:
304 case NL80211_CHAN_WIDTH_10:
Arend van Spriel600a8972014-05-12 10:47:39 +0200305 default:
306 WARN_ON_ONCE(1);
307 }
308 switch (ch->chan->band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200309 case NL80211_BAND_2GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200310 ch_inf.band = BRCMU_CHAN_BAND_2G;
311 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200312 case NL80211_BAND_5GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200313 ch_inf.band = BRCMU_CHAN_BAND_5G;
314 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200315 case NL80211_BAND_60GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200316 default:
317 WARN_ON_ONCE(1);
318 }
319 d11inf->encchspec(&ch_inf);
320
321 return ch_inf.chspec;
322}
323
Franky Lin83cf17a2013-04-11 13:28:50 +0200324u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
325 struct ieee80211_channel *ch)
Arend van Spriel6e186162012-10-22 10:36:22 -0700326{
Franky Lin83cf17a2013-04-11 13:28:50 +0200327 struct brcmu_chan ch_inf;
Arend van Spriel6e186162012-10-22 10:36:22 -0700328
Franky Lin83cf17a2013-04-11 13:28:50 +0200329 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
330 ch_inf.bw = BRCMU_CHAN_BW_20;
331 d11inf->encchspec(&ch_inf);
Arend van Spriel6e186162012-10-22 10:36:22 -0700332
Franky Lin83cf17a2013-04-11 13:28:50 +0200333 return ch_inf.chspec;
Arend van Spriel6e186162012-10-22 10:36:22 -0700334}
335
Hante Meuleman89286dc2013-02-08 15:53:46 +0100336/* Traverse a string of 1-byte tag/1-byte length/variable-length value
337 * triples, returning a pointer to the substring whose first element
338 * matches tag
339 */
Johannes Berg4b5800f2014-01-15 14:55:59 +0100340const struct brcmf_tlv *
341brcmf_parse_tlvs(const void *buf, int buflen, uint key)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100342{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100343 const struct brcmf_tlv *elt = buf;
344 int totlen = buflen;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100345
346 /* find tagged parameter */
347 while (totlen >= TLV_HDR_LEN) {
348 int len = elt->len;
349
350 /* validate remaining totlen */
351 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
352 return elt;
353
354 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
355 totlen -= (len + TLV_HDR_LEN);
356 }
357
358 return NULL;
359}
360
361/* Is any of the tlvs the expected entry? If
362 * not update the tlvs buffer pointer/length.
363 */
364static bool
Johannes Berg4b5800f2014-01-15 14:55:59 +0100365brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
366 const u8 *oui, u32 oui_len, u8 type)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100367{
368 /* If the contents match the OUI and the type */
369 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
370 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
371 type == ie[TLV_BODY_OFF + oui_len]) {
372 return true;
373 }
374
375 if (tlvs == NULL)
376 return false;
377 /* point to the next ie */
378 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
379 /* calculate the length of the rest of the buffer */
380 *tlvs_len -= (int)(ie - *tlvs);
381 /* update the pointer to the start of the buffer */
382 *tlvs = ie;
383
384 return false;
385}
386
387static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100388brcmf_find_wpaie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100389{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100390 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100391
392 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
Johannes Berg4b5800f2014-01-15 14:55:59 +0100393 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
Hante Meuleman89286dc2013-02-08 15:53:46 +0100394 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
395 return (struct brcmf_vs_tlv *)ie;
396 }
397 return NULL;
398}
399
400static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100401brcmf_find_wpsie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100402{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100403 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100404
405 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
406 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
407 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
408 return (struct brcmf_vs_tlv *)ie;
409 }
410 return NULL;
411}
412
Arend van Spriel39504a22015-08-20 22:06:05 +0200413static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
414 struct brcmf_cfg80211_vif *vif,
415 enum nl80211_iftype new_type)
416{
417 int iftype_num[NUM_NL80211_IFTYPES];
418 struct brcmf_cfg80211_vif *pos;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100419 bool check_combos = false;
420 int ret = 0;
Arend van Spriel39504a22015-08-20 22:06:05 +0200421
422 memset(&iftype_num[0], 0, sizeof(iftype_num));
423 list_for_each_entry(pos, &cfg->vif_list, list)
Arend van Spriel353c46a2015-12-10 13:43:06 +0100424 if (pos == vif) {
Arend van Spriel39504a22015-08-20 22:06:05 +0200425 iftype_num[new_type]++;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100426 } else {
427 /* concurrent interfaces so need check combinations */
428 check_combos = true;
Arend van Spriel39504a22015-08-20 22:06:05 +0200429 iftype_num[pos->wdev.iftype]++;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100430 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200431
Arend van Spriel353c46a2015-12-10 13:43:06 +0100432 if (check_combos)
433 ret = cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
434
435 return ret;
Arend van Spriel39504a22015-08-20 22:06:05 +0200436}
437
438static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
439 enum nl80211_iftype new_type)
440{
441 int iftype_num[NUM_NL80211_IFTYPES];
442 struct brcmf_cfg80211_vif *pos;
443
444 memset(&iftype_num[0], 0, sizeof(iftype_num));
445 list_for_each_entry(pos, &cfg->vif_list, list)
446 iftype_num[pos->wdev.iftype]++;
447
448 iftype_num[new_type]++;
449 return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
450}
Hante Meuleman89286dc2013-02-08 15:53:46 +0100451
Arend van Spriel5b435de2011-10-05 13:19:03 +0200452static void convert_key_from_CPU(struct brcmf_wsec_key *key,
453 struct brcmf_wsec_key_le *key_le)
454{
455 key_le->index = cpu_to_le32(key->index);
456 key_le->len = cpu_to_le32(key->len);
457 key_le->algo = cpu_to_le32(key->algo);
458 key_le->flags = cpu_to_le32(key->flags);
459 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
460 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
461 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
462 memcpy(key_le->data, key->data, sizeof(key->data));
463 memcpy(key_le->ea, key->ea, sizeof(key->ea));
464}
465
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200466static int
Hante Meuleman118eb302014-12-21 12:43:49 +0100467send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200468{
469 int err;
470 struct brcmf_wsec_key_le key_le;
471
472 convert_key_from_CPU(key, &key_le);
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200473
Hante Meuleman118eb302014-12-21 12:43:49 +0100474 brcmf_netdev_wait_pend8021x(ifp);
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700475
Hante Meuleman118eb302014-12-21 12:43:49 +0100476 err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700477 sizeof(key_le));
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200478
Arend van Spriel5b435de2011-10-05 13:19:03 +0200479 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +0100480 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200481 return err;
482}
483
Hante Meulemanb3657452013-05-27 21:09:53 +0200484static s32
Franky Lin52f22fb2016-02-17 11:26:55 +0100485brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable)
Hante Meulemanb3657452013-05-27 21:09:53 +0200486{
487 s32 err;
488 u32 mode;
489
490 if (enable)
491 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
492 else
493 mode = 0;
494
495 /* Try to set and enable ARP offload feature, this may fail, then it */
496 /* is simply not supported and err 0 will be returned */
497 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
498 if (err) {
499 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
500 mode, err);
501 err = 0;
502 } else {
503 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
504 if (err) {
505 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
506 enable, err);
507 err = 0;
508 } else
509 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
510 enable, mode);
511 }
512
Franky Lin52f22fb2016-02-17 11:26:55 +0100513 err = brcmf_fil_iovar_int_set(ifp, "ndoe", enable);
514 if (err) {
515 brcmf_dbg(TRACE, "failed to configure (%d) ND offload err = %d\n",
516 enable, err);
517 err = 0;
518 } else
519 brcmf_dbg(TRACE, "successfully configured (%d) ND offload to 0x%x\n",
520 enable, mode);
521
Hante Meulemanb3657452013-05-27 21:09:53 +0200522 return err;
523}
524
Hante Meuleman8851cce2014-07-30 13:20:02 +0200525static void
526brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
527{
Arend van Spriel8f2b4592014-09-11 22:51:32 +0200528 struct brcmf_cfg80211_vif *vif;
529 struct brcmf_if *ifp;
530
531 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
532 ifp = vif->ifp;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200533
534 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
535 (wdev->iftype == NL80211_IFTYPE_AP) ||
536 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
537 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
538 ADDR_DIRECT);
539 else
540 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
541 ADDR_INDIRECT);
542}
543
Rafał Miłeckid02fb8f2016-05-26 01:44:27 +0200544static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr)
545{
546 int bsscfgidx;
547
548 for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) {
549 /* bsscfgidx 1 is reserved for legacy P2P */
550 if (bsscfgidx == 1)
551 continue;
552 if (!drvr->iflist[bsscfgidx])
553 return bsscfgidx;
554 }
555
556 return -ENOMEM;
557}
558
Hante Meulemana44aa402014-12-03 21:05:33 +0100559static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
560{
561 struct brcmf_mbss_ssid_le mbss_ssid_le;
562 int bsscfgidx;
563 int err;
564
565 memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
Rafał Miłeckid02fb8f2016-05-26 01:44:27 +0200566 bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr);
Hante Meulemana44aa402014-12-03 21:05:33 +0100567 if (bsscfgidx < 0)
568 return bsscfgidx;
569
570 mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
571 mbss_ssid_le.SSID_len = cpu_to_le32(5);
572 sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
573
574 err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
575 sizeof(mbss_ssid_le));
576 if (err < 0)
577 brcmf_err("setting ssid failed %d\n", err);
578
579 return err;
580}
581
582/**
583 * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
584 *
585 * @wiphy: wiphy device of new interface.
586 * @name: name of the new interface.
587 * @flags: not used.
588 * @params: contains mac address for AP device.
589 */
590static
591struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
592 u32 *flags, struct vif_params *params)
593{
594 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
595 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
596 struct brcmf_cfg80211_vif *vif;
597 int err;
598
599 if (brcmf_cfg80211_vif_event_armed(cfg))
600 return ERR_PTR(-EBUSY);
601
602 brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
603
604 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false);
605 if (IS_ERR(vif))
606 return (struct wireless_dev *)vif;
607
608 brcmf_cfg80211_arm_vif_event(cfg, vif);
609
610 err = brcmf_cfg80211_request_ap_if(ifp);
611 if (err) {
612 brcmf_cfg80211_arm_vif_event(cfg, NULL);
613 goto fail;
614 }
615
616 /* wait for firmware event */
Arend van Spriela9eb0c42016-02-17 11:26:50 +0100617 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD,
618 BRCMF_VIF_EVENT_TIMEOUT);
Hante Meulemana44aa402014-12-03 21:05:33 +0100619 brcmf_cfg80211_arm_vif_event(cfg, NULL);
620 if (!err) {
621 brcmf_err("timeout occurred\n");
622 err = -EIO;
623 goto fail;
624 }
625
626 /* interface created in firmware */
627 ifp = vif->ifp;
628 if (!ifp) {
629 brcmf_err("no if pointer provided\n");
630 err = -ENOENT;
631 goto fail;
632 }
633
634 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
635 err = brcmf_net_attach(ifp, true);
636 if (err) {
637 brcmf_err("Registering netdevice failed\n");
638 goto fail;
639 }
640
641 return &ifp->vif->wdev;
642
643fail:
644 brcmf_free_vif(vif);
645 return ERR_PTR(err);
646}
647
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100648static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
649{
650 enum nl80211_iftype iftype;
651
652 iftype = vif->wdev.iftype;
653 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
654}
655
656static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
657{
658 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
659}
660
Arend van Spriel9f440b72013-02-08 15:53:36 +0100661static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
662 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100663 unsigned char name_assign_type,
Arend van Spriel9f440b72013-02-08 15:53:36 +0100664 enum nl80211_iftype type,
665 u32 *flags,
666 struct vif_params *params)
667{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200668 struct wireless_dev *wdev;
Arend van Spriel39504a22015-08-20 22:06:05 +0200669 int err;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200670
Arend van Spriel9f440b72013-02-08 15:53:36 +0100671 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
Arend van Spriel39504a22015-08-20 22:06:05 +0200672 err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
673 if (err) {
674 brcmf_err("iface validation failed: err=%d\n", err);
675 return ERR_PTR(err);
676 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100677 switch (type) {
678 case NL80211_IFTYPE_ADHOC:
679 case NL80211_IFTYPE_STATION:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100680 case NL80211_IFTYPE_AP_VLAN:
681 case NL80211_IFTYPE_WDS:
682 case NL80211_IFTYPE_MONITOR:
683 case NL80211_IFTYPE_MESH_POINT:
684 return ERR_PTR(-EOPNOTSUPP);
Hante Meulemana44aa402014-12-03 21:05:33 +0100685 case NL80211_IFTYPE_AP:
686 wdev = brcmf_ap_add_vif(wiphy, name, flags, params);
687 if (!IS_ERR(wdev))
688 brcmf_cfg80211_update_proto_addr_mode(wdev);
689 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100690 case NL80211_IFTYPE_P2P_CLIENT:
691 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200692 case NL80211_IFTYPE_P2P_DEVICE:
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100693 wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, flags, params);
Hante Meuleman8851cce2014-07-30 13:20:02 +0200694 if (!IS_ERR(wdev))
695 brcmf_cfg80211_update_proto_addr_mode(wdev);
696 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100697 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100698 default:
699 return ERR_PTR(-EINVAL);
700 }
701}
702
Daniel Kim5e787f72014-06-21 12:11:18 +0200703static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
704{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200705 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200706 brcmf_set_mpc(ifp, mpc);
707}
708
Arend van Sprielf96aa072013-04-05 10:57:48 +0200709void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100710{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100711 s32 err = 0;
712
713 if (check_vif_up(ifp->vif)) {
714 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
715 if (err) {
716 brcmf_err("fail to set mpc\n");
717 return;
718 }
719 brcmf_dbg(INFO, "MPC : %d\n", mpc);
720 }
721}
722
Arend van Spriela0f472a2013-04-05 10:57:49 +0200723s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
724 struct brcmf_if *ifp, bool aborted,
725 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100726{
727 struct brcmf_scan_params_le params_le;
728 struct cfg80211_scan_request *scan_request;
729 s32 err = 0;
730
731 brcmf_dbg(SCAN, "Enter\n");
732
733 /* clear scan request, because the FW abort can cause a second call */
734 /* to this functon and might cause a double cfg80211_scan_done */
735 scan_request = cfg->scan_request;
736 cfg->scan_request = NULL;
737
738 if (timer_pending(&cfg->escan_timeout))
739 del_timer_sync(&cfg->escan_timeout);
740
741 if (fw_abort) {
742 /* Do a scan abort to stop the driver's scan engine */
743 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
744 memset(&params_le, 0, sizeof(params_le));
Joe Perches93803b32015-03-02 19:54:49 -0800745 eth_broadcast_addr(params_le.bssid);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100746 params_le.bss_type = DOT11_BSSTYPE_ANY;
747 params_le.scan_type = 0;
748 params_le.channel_num = cpu_to_le32(1);
749 params_le.nprobes = cpu_to_le32(1);
750 params_le.active_time = cpu_to_le32(-1);
751 params_le.passive_time = cpu_to_le32(-1);
752 params_le.home_time = cpu_to_le32(-1);
753 /* Scan is aborted by setting channel_list[0] to -1 */
754 params_le.channel_list[0] = cpu_to_le16(-1);
755 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200756 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100757 &params_le, sizeof(params_le));
758 if (err)
759 brcmf_err("Scan abort failed\n");
760 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200761
Daniel Kim5e787f72014-06-21 12:11:18 +0200762 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200763
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100764 /*
765 * e-scan can be initiated by scheduled scan
766 * which takes precedence.
767 */
768 if (cfg->sched_escan) {
769 brcmf_dbg(SCAN, "scheduled scan completed\n");
770 cfg->sched_escan = false;
771 if (!aborted)
772 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100773 } else if (scan_request) {
774 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
775 aborted ? "Aborted" : "Done");
776 cfg80211_scan_done(scan_request, aborted);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100777 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100778 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
779 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100780
781 return err;
782}
783
Arend van Spriel9f440b72013-02-08 15:53:36 +0100784static
785int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
786{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100787 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
788 struct net_device *ndev = wdev->netdev;
789
790 /* vif event pending in firmware */
791 if (brcmf_cfg80211_vif_event_armed(cfg))
792 return -EBUSY;
793
794 if (ndev) {
795 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200796 cfg->escan_info.ifp == netdev_priv(ndev))
797 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
798 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100799
800 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
801 }
802
Arend van Spriel9f440b72013-02-08 15:53:36 +0100803 switch (wdev->iftype) {
804 case NL80211_IFTYPE_ADHOC:
805 case NL80211_IFTYPE_STATION:
806 case NL80211_IFTYPE_AP:
807 case NL80211_IFTYPE_AP_VLAN:
808 case NL80211_IFTYPE_WDS:
809 case NL80211_IFTYPE_MONITOR:
810 case NL80211_IFTYPE_MESH_POINT:
811 return -EOPNOTSUPP;
812 case NL80211_IFTYPE_P2P_CLIENT:
813 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200814 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100815 return brcmf_p2p_del_vif(wiphy, wdev);
816 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100817 default:
818 return -EINVAL;
819 }
820 return -EOPNOTSUPP;
821}
822
Arend van Spriel5b435de2011-10-05 13:19:03 +0200823static s32
824brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
825 enum nl80211_iftype type, u32 *flags,
826 struct vif_params *params)
827{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100828 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700829 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100830 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200831 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200832 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200833 s32 err = 0;
834
Hante Meuleman37a869e2015-10-29 20:33:17 +0100835 brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx,
836 type);
Hante Meuleman178e9ef2015-09-18 22:08:11 +0200837
838 /* WAR: There are a number of p2p interface related problems which
839 * need to be handled initially (before doing the validate).
840 * wpa_supplicant tends to do iface changes on p2p device/client/go
841 * which are not always possible/allowed. However we need to return
842 * OK otherwise the wpa_supplicant wont start. The situation differs
843 * on configuration and setup (p2pon=1 module param). The first check
844 * is to see if the request is a change to station for p2p iface.
845 */
846 if ((type == NL80211_IFTYPE_STATION) &&
847 ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
848 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) ||
849 (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) {
850 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
851 /* Now depending on whether module param p2pon=1 was used the
852 * response needs to be either 0 or EOPNOTSUPP. The reason is
853 * that if p2pon=1 is used, but a newer supplicant is used then
854 * we should return an error, as this combination wont work.
855 * In other situations 0 is returned and supplicant will start
856 * normally. It will give a trace in cfg80211, but it is the
857 * only way to get it working. Unfortunately this will result
858 * in situation where we wont support new supplicant in
859 * combination with module param p2pon=1, but that is the way
860 * it is. If the user tries this then unloading of driver might
861 * fail/lock.
862 */
863 if (cfg->p2p.p2pdev_dynamically)
864 return -EOPNOTSUPP;
865 else
866 return 0;
867 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200868 err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
869 if (err) {
870 brcmf_err("iface validation failed: err=%d\n", err);
871 return err;
872 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200873 switch (type) {
874 case NL80211_IFTYPE_MONITOR:
875 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100876 brcmf_err("type (%d) : currently we do not support this type\n",
877 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200878 return -EOPNOTSUPP;
879 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200880 infra = 0;
881 break;
882 case NL80211_IFTYPE_STATION:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200883 infra = 1;
884 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200885 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100886 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200887 ap = 1;
888 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200889 default:
890 err = -EINVAL;
891 goto done;
892 }
893
Hante Meuleman1a873342012-09-27 14:17:54 +0200894 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100895 if (type == NL80211_IFTYPE_P2P_GO) {
896 brcmf_dbg(INFO, "IF Type = P2P GO\n");
897 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
898 }
899 if (!err) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100900 brcmf_dbg(INFO, "IF Type = AP\n");
901 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200902 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100903 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200904 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100905 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200906 err = -EAGAIN;
907 goto done;
908 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100909 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100910 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200911 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200912 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200913
Hante Meuleman8851cce2014-07-30 13:20:02 +0200914 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
915
Arend van Spriel5b435de2011-10-05 13:19:03 +0200916done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100917 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200918
919 return err;
920}
921
Franky Lin83cf17a2013-04-11 13:28:50 +0200922static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
923 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200924 struct cfg80211_scan_request *request)
925{
926 u32 n_ssids;
927 u32 n_channels;
928 s32 i;
929 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200930 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200931 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200932 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200933
Joe Perches93803b32015-03-02 19:54:49 -0800934 eth_broadcast_addr(params_le->bssid);
Hante Meulemane756af52012-09-11 21:18:52 +0200935 params_le->bss_type = DOT11_BSSTYPE_ANY;
936 params_le->scan_type = 0;
937 params_le->channel_num = 0;
938 params_le->nprobes = cpu_to_le32(-1);
939 params_le->active_time = cpu_to_le32(-1);
940 params_le->passive_time = cpu_to_le32(-1);
941 params_le->home_time = cpu_to_le32(-1);
942 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
943
944 /* if request is null exit so it will be all channel broadcast scan */
945 if (!request)
946 return;
947
948 n_ssids = request->n_ssids;
949 n_channels = request->n_channels;
950 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100951 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
952 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200953 if (n_channels > 0) {
954 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200955 chanspec = channel_to_chanspec(&cfg->d11inf,
956 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100957 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
958 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200959 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200960 }
961 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100962 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200963 }
964 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100965 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200966 if (n_ssids > 0) {
967 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
968 n_channels * sizeof(u16);
969 offset = roundup(offset, sizeof(u32));
970 ptr = (char *)params_le + offset;
971 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +0200972 memset(&ssid_le, 0, sizeof(ssid_le));
973 ssid_le.SSID_len =
974 cpu_to_le32(request->ssids[i].ssid_len);
975 memcpy(ssid_le.SSID, request->ssids[i].ssid,
976 request->ssids[i].ssid_len);
977 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100978 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +0200979 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100980 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
981 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +0200982 memcpy(ptr, &ssid_le, sizeof(ssid_le));
983 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +0200984 }
985 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100986 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200987 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100988 brcmf_dbg(SCAN, "SSID %s len=%d\n",
989 params_le->ssid_le.SSID,
990 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200991 params_le->ssid_le.SSID_len =
992 cpu_to_le32(request->ssids->ssid_len);
993 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
994 request->ssids->ssid_len);
995 }
996 }
997 /* Adding mask to channel numbers */
998 params_le->channel_num =
999 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
1000 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
1001}
1002
1003static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001004brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemanc4958102015-11-25 11:32:41 +01001005 struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +02001006{
1007 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
1008 offsetof(struct brcmf_escan_params_le, params_le);
1009 struct brcmf_escan_params_le *params;
1010 s32 err = 0;
1011
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001012 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001013
1014 if (request != NULL) {
1015 /* Allocate space for populating ssids in struct */
1016 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
1017
1018 /* Allocate space for populating ssids in struct */
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001019 params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids;
Hante Meulemane756af52012-09-11 21:18:52 +02001020 }
1021
1022 params = kzalloc(params_size, GFP_KERNEL);
1023 if (!params) {
1024 err = -ENOMEM;
1025 goto exit;
1026 }
1027 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +02001028 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +02001029 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
Hante Meulemanc4958102015-11-25 11:32:41 +01001030 params->action = cpu_to_le16(WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +02001031 params->sync_id = cpu_to_le16(0x1234);
1032
Arend van Spriela0f472a2013-04-05 10:57:49 +02001033 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +02001034 if (err) {
1035 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001036 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001037 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001038 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001039 }
1040
1041 kfree(params);
1042exit:
1043 return err;
1044}
1045
1046static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001047brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
Arend van Spriela0f472a2013-04-05 10:57:49 +02001048 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +02001049{
1050 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001051 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001052 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001053 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +02001054
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001055 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001056 escan->ifp = ifp;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001057 escan->wiphy = wiphy;
1058 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001059 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +02001060 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001061 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001062 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001063 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001064 return err;
1065 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001066 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001067 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02001068 results->version = 0;
1069 results->count = 0;
1070 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
1071
Hante Meulemanc4958102015-11-25 11:32:41 +01001072 err = escan->run(cfg, ifp, request);
Hante Meulemane756af52012-09-11 21:18:52 +02001073 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +02001074 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001075 return err;
1076}
1077
1078static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001079brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +02001080 struct cfg80211_scan_request *request,
1081 struct cfg80211_ssid *this_ssid)
1082{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001083 struct brcmf_if *ifp = vif->ifp;
1084 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +02001085 struct cfg80211_ssid *ssids;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001086 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001087 bool escan_req;
1088 bool spec_scan;
1089 s32 err;
Hante Meuleman675f5d82015-12-10 13:43:01 +01001090 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +02001091 u32 SSID_len;
1092
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001093 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001094
Arend van Sprielc1179032012-10-22 13:55:33 -07001095 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001096 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001097 return -EAGAIN;
1098 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001099 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001100 brcmf_err("Scanning being aborted: status (%lu)\n",
1101 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001102 return -EAGAIN;
1103 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02001104 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
1105 brcmf_err("Scanning suppressed: status (%lu)\n",
1106 cfg->scan_status);
1107 return -EAGAIN;
1108 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001109 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001110 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +02001111 return -EAGAIN;
1112 }
1113
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001114 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001115 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
1116 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001117
Hante Meulemane756af52012-09-11 21:18:52 +02001118 escan_req = false;
1119 if (request) {
1120 /* scan bss */
1121 ssids = request->ssids;
1122 escan_req = true;
1123 } else {
1124 /* scan in ibss */
1125 /* we don't do escan in ibss */
1126 ssids = this_ssid;
1127 }
1128
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001129 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -07001130 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001131 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +01001132 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001133 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001134 if (err)
1135 goto scan_out;
1136
Arend van Spriela0f472a2013-04-05 10:57:49 +02001137 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -08001138 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +02001139 goto scan_out;
1140 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001141 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
1142 ssids->ssid, ssids->ssid_len);
Hante Meuleman675f5d82015-12-10 13:43:01 +01001143 memset(&ssid_le, 0, sizeof(ssid_le));
1144 SSID_len = min_t(u8, sizeof(ssid_le.SSID), ssids->ssid_len);
1145 ssid_le.SSID_len = cpu_to_le32(0);
Hante Meulemane756af52012-09-11 21:18:52 +02001146 spec_scan = false;
1147 if (SSID_len) {
Hante Meuleman675f5d82015-12-10 13:43:01 +01001148 memcpy(ssid_le.SSID, ssids->ssid, SSID_len);
1149 ssid_le.SSID_len = cpu_to_le32(SSID_len);
Hante Meulemane756af52012-09-11 21:18:52 +02001150 spec_scan = true;
1151 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001152 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001153
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001154 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -07001155 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001156 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001157 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001158 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001159 goto scan_out;
1160 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001161 brcmf_scan_config_mpc(ifp, 0);
Hante Meuleman675f5d82015-12-10 13:43:01 +01001162 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &ssid_le,
1163 sizeof(ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001164 if (err) {
1165 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001166 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
Hante Meuleman675f5d82015-12-10 13:43:01 +01001167 ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001168 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001169 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001170
Daniel Kim5e787f72014-06-21 12:11:18 +02001171 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001172 goto scan_out;
1173 }
1174 }
1175
Hante Meuleman661fa952015-02-06 18:36:47 +01001176 /* Arm scan timeout timer */
1177 mod_timer(&cfg->escan_timeout, jiffies +
Hante Meulemand5367332016-02-17 11:26:51 +01001178 BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
Hante Meuleman661fa952015-02-06 18:36:47 +01001179
Hante Meulemane756af52012-09-11 21:18:52 +02001180 return 0;
1181
1182scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001183 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001184 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001185 return err;
1186}
1187
Arend van Spriel5b435de2011-10-05 13:19:03 +02001188static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001189brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001190{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001191 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001192 s32 err = 0;
1193
Arend van Sprield96b8012012-12-05 15:26:02 +01001194 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001195 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1196 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001197 return -EIO;
1198
Arend van Spriela0f472a2013-04-05 10:57:49 +02001199 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001200
Arend van Spriel5b435de2011-10-05 13:19:03 +02001201 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001202 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001203
Arend van Sprield96b8012012-12-05 15:26:02 +01001204 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001205 return err;
1206}
1207
1208static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1209{
1210 s32 err = 0;
1211
Arend van Sprielac24be62012-10-22 10:36:23 -07001212 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1213 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001214 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001215 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001216
1217 return err;
1218}
1219
1220static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1221{
1222 s32 err = 0;
1223
Arend van Sprielac24be62012-10-22 10:36:23 -07001224 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1225 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001226 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001227 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001228
1229 return err;
1230}
1231
1232static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1233{
1234 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001235 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001236
Arend van Sprielac24be62012-10-22 10:36:23 -07001237 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001238 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001239 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001240 return err;
1241 }
1242 return err;
1243}
1244
1245static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1246{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001247 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1248 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001249 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001250 s32 err = 0;
1251
Arend van Sprield96b8012012-12-05 15:26:02 +01001252 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001253 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001254 return -EIO;
1255
1256 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001257 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1258 cfg->conf->rts_threshold = wiphy->rts_threshold;
1259 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001260 if (!err)
1261 goto done;
1262 }
1263 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001264 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1265 cfg->conf->frag_threshold = wiphy->frag_threshold;
1266 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001267 if (!err)
1268 goto done;
1269 }
1270 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001271 && (cfg->conf->retry_long != wiphy->retry_long)) {
1272 cfg->conf->retry_long = wiphy->retry_long;
1273 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001274 if (!err)
1275 goto done;
1276 }
1277 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001278 && (cfg->conf->retry_short != wiphy->retry_short)) {
1279 cfg->conf->retry_short = wiphy->retry_short;
1280 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001281 if (!err)
1282 goto done;
1283 }
1284
1285done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001286 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001287 return err;
1288}
1289
Arend van Spriel5b435de2011-10-05 13:19:03 +02001290static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1291{
1292 memset(prof, 0, sizeof(*prof));
1293}
1294
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001295static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
1296{
1297 u16 reason;
1298
1299 switch (e->event_code) {
1300 case BRCMF_E_DEAUTH:
1301 case BRCMF_E_DEAUTH_IND:
1302 case BRCMF_E_DISASSOC_IND:
1303 reason = e->reason;
1304 break;
1305 case BRCMF_E_LINK:
1306 default:
1307 reason = 0;
1308 break;
1309 }
1310 return reason;
1311}
1312
1313static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001314{
Piotr Haber61730d42013-04-23 12:53:12 +02001315 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001316 s32 err = 0;
1317
Arend van Sprield96b8012012-12-05 15:26:02 +01001318 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001319
Hante Meulemanb0a79082015-12-10 13:43:07 +01001320 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001321 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001322 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001323 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001324 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001325 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001326 }
Hante Meulemanb0a79082015-12-10 13:43:07 +01001327 if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) ||
1328 (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT))
1329 cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
1330 true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001331 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001332 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001333 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1334 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001335 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001336}
1337
1338static s32
1339brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1340 struct cfg80211_ibss_params *params)
1341{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001342 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001343 struct brcmf_if *ifp = netdev_priv(ndev);
1344 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001345 struct brcmf_join_params join_params;
1346 size_t join_params_size = 0;
1347 s32 err = 0;
1348 s32 wsec = 0;
1349 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001350 u16 chanspec;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001351 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001352
Arend van Sprield96b8012012-12-05 15:26:02 +01001353 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001354 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001355 return -EIO;
1356
1357 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001358 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001359 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001360 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001361 return -EOPNOTSUPP;
1362 }
1363
Arend van Sprielc1179032012-10-22 13:55:33 -07001364 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001365
1366 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001367 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001368 else
Arend van Spriel16886732012-12-05 15:26:04 +01001369 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001370
Johannes Berg683b6d32012-11-08 21:25:48 +01001371 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001372 brcmf_dbg(CONN, "channel: %d\n",
1373 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001374 else
Arend van Spriel16886732012-12-05 15:26:04 +01001375 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001376
1377 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001378 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001379 else
Arend van Spriel16886732012-12-05 15:26:04 +01001380 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001381
1382 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001383 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001384 else
Arend van Spriel16886732012-12-05 15:26:04 +01001385 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001386
1387 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001388 brcmf_dbg(CONN, "beacon interval: %d\n",
1389 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001390 else
Arend van Spriel16886732012-12-05 15:26:04 +01001391 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001392
1393 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001394 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001395 else
Arend van Spriel16886732012-12-05 15:26:04 +01001396 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001397
1398 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001399 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001400 else
Arend van Spriel16886732012-12-05 15:26:04 +01001401 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001402
1403 /* Configure Privacy for starter */
1404 if (params->privacy)
1405 wsec |= WEP_ENABLED;
1406
Arend van Sprielc1179032012-10-22 13:55:33 -07001407 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001408 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001409 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001410 goto done;
1411 }
1412
1413 /* Configure Beacon Interval for starter */
1414 if (params->beacon_interval)
1415 bcnprd = params->beacon_interval;
1416 else
1417 bcnprd = 100;
1418
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001419 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001420 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001421 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001422 goto done;
1423 }
1424
1425 /* Configure required join parameter */
1426 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1427
1428 /* SSID */
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001429 ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN);
1430 memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len);
1431 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001432 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001433
1434 /* BSSID */
1435 if (params->bssid) {
1436 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001437 join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001438 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001439 } else {
Joe Perches93803b32015-03-02 19:54:49 -08001440 eth_broadcast_addr(join_params.params_le.bssid);
1441 eth_zero_addr(profile->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001442 }
1443
Arend van Spriel5b435de2011-10-05 13:19:03 +02001444 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001445 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001446 u32 target_channel;
1447
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001448 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001449 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001450 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001451 if (params->channel_fixed) {
1452 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001453 chanspec = chandef_to_chanspec(&cfg->d11inf,
1454 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001455 join_params.params_le.chanspec_list[0] =
1456 cpu_to_le16(chanspec);
1457 join_params.params_le.chanspec_num = cpu_to_le32(1);
1458 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001459 }
1460
1461 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001462 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001463 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001464 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001465 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001466 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001467 goto done;
1468 }
1469 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001470 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001471
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001472 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001473
1474
Arend van Sprielc1179032012-10-22 13:55:33 -07001475 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001476 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001477 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001478 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001479 goto done;
1480 }
1481
1482done:
1483 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001484 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001485 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001486 return err;
1487}
1488
1489static s32
1490brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1491{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001492 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001493
Arend van Sprield96b8012012-12-05 15:26:02 +01001494 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman6a98d642016-01-02 09:41:40 +01001495 if (!check_vif_up(ifp->vif)) {
1496 /* When driver is being unloaded, it can end up here. If an
1497 * error is returned then later on a debug trace in the wireless
1498 * core module will be printed. To avoid this 0 is returned.
1499 */
1500 return 0;
1501 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001502
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001503 brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01001504 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001505
Arend van Sprield96b8012012-12-05 15:26:02 +01001506 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001507
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001508 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001509}
1510
1511static s32 brcmf_set_wpa_version(struct net_device *ndev,
1512 struct cfg80211_connect_params *sme)
1513{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001514 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001515 struct brcmf_cfg80211_security *sec;
1516 s32 val = 0;
1517 s32 err = 0;
1518
1519 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1520 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1521 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1522 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1523 else
1524 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001525 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001526 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001527 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001528 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001529 return err;
1530 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001531 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001532 sec->wpa_versions = sme->crypto.wpa_versions;
1533 return err;
1534}
1535
1536static s32 brcmf_set_auth_type(struct net_device *ndev,
1537 struct cfg80211_connect_params *sme)
1538{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001539 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001540 struct brcmf_cfg80211_security *sec;
1541 s32 val = 0;
1542 s32 err = 0;
1543
1544 switch (sme->auth_type) {
1545 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1546 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001547 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001548 break;
1549 case NL80211_AUTHTYPE_SHARED_KEY:
1550 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001551 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001552 break;
1553 case NL80211_AUTHTYPE_AUTOMATIC:
1554 val = 2;
Arend van Spriel16886732012-12-05 15:26:04 +01001555 brcmf_dbg(CONN, "automatic\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001556 break;
1557 case NL80211_AUTHTYPE_NETWORK_EAP:
Arend van Spriel16886732012-12-05 15:26:04 +01001558 brcmf_dbg(CONN, "network eap\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001559 default:
1560 val = 2;
Arend van Spriel57d6e912012-12-05 15:26:00 +01001561 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001562 break;
1563 }
1564
Hante Meuleman89286dc2013-02-08 15:53:46 +01001565 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001566 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001567 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001568 return err;
1569 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001570 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001571 sec->auth_type = sme->auth_type;
1572 return err;
1573}
1574
1575static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001576brcmf_set_wsec_mode(struct net_device *ndev,
Hante Meuleman240d61a2016-02-17 11:27:10 +01001577 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001578{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001579 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001580 struct brcmf_cfg80211_security *sec;
1581 s32 pval = 0;
1582 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001583 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001584 s32 err = 0;
1585
1586 if (sme->crypto.n_ciphers_pairwise) {
1587 switch (sme->crypto.ciphers_pairwise[0]) {
1588 case WLAN_CIPHER_SUITE_WEP40:
1589 case WLAN_CIPHER_SUITE_WEP104:
1590 pval = WEP_ENABLED;
1591 break;
1592 case WLAN_CIPHER_SUITE_TKIP:
1593 pval = TKIP_ENABLED;
1594 break;
1595 case WLAN_CIPHER_SUITE_CCMP:
1596 pval = AES_ENABLED;
1597 break;
1598 case WLAN_CIPHER_SUITE_AES_CMAC:
1599 pval = AES_ENABLED;
1600 break;
1601 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001602 brcmf_err("invalid cipher pairwise (%d)\n",
1603 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001604 return -EINVAL;
1605 }
1606 }
1607 if (sme->crypto.cipher_group) {
1608 switch (sme->crypto.cipher_group) {
1609 case WLAN_CIPHER_SUITE_WEP40:
1610 case WLAN_CIPHER_SUITE_WEP104:
1611 gval = WEP_ENABLED;
1612 break;
1613 case WLAN_CIPHER_SUITE_TKIP:
1614 gval = TKIP_ENABLED;
1615 break;
1616 case WLAN_CIPHER_SUITE_CCMP:
1617 gval = AES_ENABLED;
1618 break;
1619 case WLAN_CIPHER_SUITE_AES_CMAC:
1620 gval = AES_ENABLED;
1621 break;
1622 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001623 brcmf_err("invalid cipher group (%d)\n",
1624 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001625 return -EINVAL;
1626 }
1627 }
1628
Arend van Spriel16886732012-12-05 15:26:04 +01001629 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001630 /* In case of privacy, but no security and WPS then simulate */
1631 /* setting AES. WPS-2.0 allows no security */
1632 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1633 sme->privacy)
1634 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001635
Hante Meuleman240d61a2016-02-17 11:27:10 +01001636 wsec = pval | gval;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001637 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001638 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001639 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001640 return err;
1641 }
1642
Arend van Spriel06bb1232012-09-27 14:17:56 +02001643 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001644 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1645 sec->cipher_group = sme->crypto.cipher_group;
1646
1647 return err;
1648}
1649
1650static s32
1651brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1652{
Hante Meuleman240d61a2016-02-17 11:27:10 +01001653 struct brcmf_if *ifp = netdev_priv(ndev);
1654 s32 val;
1655 s32 err;
1656 const struct brcmf_tlv *rsn_ie;
1657 const u8 *ie;
1658 u32 ie_len;
1659 u32 offset;
1660 u16 rsn_cap;
1661 u32 mfp;
1662 u16 count;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001663
Hante Meuleman240d61a2016-02-17 11:27:10 +01001664 if (!sme->crypto.n_akm_suites)
1665 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001666
Hante Meuleman240d61a2016-02-17 11:27:10 +01001667 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val);
1668 if (err) {
1669 brcmf_err("could not get wpa_auth (%d)\n", err);
1670 return err;
1671 }
1672 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1673 switch (sme->crypto.akm_suites[0]) {
1674 case WLAN_AKM_SUITE_8021X:
1675 val = WPA_AUTH_UNSPECIFIED;
1676 break;
1677 case WLAN_AKM_SUITE_PSK:
1678 val = WPA_AUTH_PSK;
1679 break;
1680 default:
1681 brcmf_err("invalid cipher group (%d)\n",
1682 sme->crypto.cipher_group);
1683 return -EINVAL;
1684 }
1685 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1686 switch (sme->crypto.akm_suites[0]) {
1687 case WLAN_AKM_SUITE_8021X:
1688 val = WPA2_AUTH_UNSPECIFIED;
1689 break;
1690 case WLAN_AKM_SUITE_8021X_SHA256:
1691 val = WPA2_AUTH_1X_SHA256;
1692 break;
1693 case WLAN_AKM_SUITE_PSK_SHA256:
1694 val = WPA2_AUTH_PSK_SHA256;
1695 break;
1696 case WLAN_AKM_SUITE_PSK:
1697 val = WPA2_AUTH_PSK;
1698 break;
1699 default:
1700 brcmf_err("invalid cipher group (%d)\n",
1701 sme->crypto.cipher_group);
1702 return -EINVAL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001703 }
1704 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01001705
1706 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
1707 goto skip_mfp_config;
1708 /* The MFP mode (1 or 2) needs to be determined, parse IEs. The
1709 * IE will not be verified, just a quick search for MFP config
1710 */
1711 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len,
1712 WLAN_EID_RSN);
1713 if (!rsn_ie)
1714 goto skip_mfp_config;
1715 ie = (const u8 *)rsn_ie;
1716 ie_len = rsn_ie->len + TLV_HDR_LEN;
1717 /* Skip unicast suite */
1718 offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN;
1719 if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
1720 goto skip_mfp_config;
1721 /* Skip multicast suite */
1722 count = ie[offset] + (ie[offset + 1] << 8);
1723 offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
1724 if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
1725 goto skip_mfp_config;
1726 /* Skip auth key management suite(s) */
1727 count = ie[offset] + (ie[offset + 1] << 8);
1728 offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
1729 if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len)
1730 goto skip_mfp_config;
1731 /* Ready to read capabilities */
1732 mfp = BRCMF_MFP_NONE;
1733 rsn_cap = ie[offset] + (ie[offset + 1] << 8);
1734 if (rsn_cap & RSN_CAP_MFPR_MASK)
1735 mfp = BRCMF_MFP_REQUIRED;
1736 else if (rsn_cap & RSN_CAP_MFPC_MASK)
1737 mfp = BRCMF_MFP_CAPABLE;
1738 brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp);
1739
1740skip_mfp_config:
1741 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
1742 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
1743 if (err) {
1744 brcmf_err("could not set wpa_auth (%d)\n", err);
1745 return err;
1746 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001747
1748 return err;
1749}
1750
1751static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001752brcmf_set_sharedkey(struct net_device *ndev,
1753 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001754{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001755 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001756 struct brcmf_cfg80211_security *sec;
1757 struct brcmf_wsec_key key;
1758 s32 val;
1759 s32 err = 0;
1760
Arend van Spriel16886732012-12-05 15:26:04 +01001761 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001762
Roland Vossena718e2f2011-10-12 20:51:24 +02001763 if (sme->key_len == 0)
1764 return 0;
1765
Arend van Spriel06bb1232012-09-27 14:17:56 +02001766 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001767 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1768 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001769
1770 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1771 return 0;
1772
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001773 if (!(sec->cipher_pairwise &
1774 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1775 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001776
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001777 memset(&key, 0, sizeof(key));
1778 key.len = (u32) sme->key_len;
1779 key.index = (u32) sme->key_idx;
1780 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001781 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001782 return -EINVAL;
1783 }
1784 memcpy(key.data, sme->key, key.len);
1785 key.flags = BRCMF_PRIMARY_KEY;
1786 switch (sec->cipher_pairwise) {
1787 case WLAN_CIPHER_SUITE_WEP40:
1788 key.algo = CRYPTO_ALGO_WEP1;
1789 break;
1790 case WLAN_CIPHER_SUITE_WEP104:
1791 key.algo = CRYPTO_ALGO_WEP128;
1792 break;
1793 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001794 brcmf_err("Invalid algorithm (%d)\n",
1795 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001796 return -EINVAL;
1797 }
1798 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001799 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1800 key.len, key.index, key.algo);
1801 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Hante Meuleman118eb302014-12-21 12:43:49 +01001802 err = send_key_to_dongle(netdev_priv(ndev), &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001803 if (err)
1804 return err;
1805
1806 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001807 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001808 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001809 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001810 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001811 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001812 }
1813 return err;
1814}
1815
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001816static
1817enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1818 enum nl80211_auth_type type)
1819{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001820 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1821 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1822 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1823 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001824 }
1825 return type;
1826}
1827
Arend van Spriel7705ba62016-04-17 16:44:58 +02001828static void brcmf_set_join_pref(struct brcmf_if *ifp,
1829 struct cfg80211_bss_selection *bss_select)
1830{
1831 struct brcmf_join_pref_params join_pref_params[2];
1832 enum nl80211_band band;
1833 int err, i = 0;
1834
1835 join_pref_params[i].len = 2;
1836 join_pref_params[i].rssi_gain = 0;
1837
1838 if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF)
1839 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO);
1840
1841 switch (bss_select->behaviour) {
1842 case __NL80211_BSS_SELECT_ATTR_INVALID:
1843 brcmf_c_set_joinpref_default(ifp);
1844 return;
1845 case NL80211_BSS_SELECT_ATTR_BAND_PREF:
1846 join_pref_params[i].type = BRCMF_JOIN_PREF_BAND;
1847 band = bss_select->param.band_pref;
1848 join_pref_params[i].band = nl80211_band_to_fwil(band);
1849 i++;
1850 break;
1851 case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST:
1852 join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA;
1853 band = bss_select->param.adjust.band;
1854 join_pref_params[i].band = nl80211_band_to_fwil(band);
1855 join_pref_params[i].rssi_gain = bss_select->param.adjust.delta;
1856 i++;
1857 break;
1858 case NL80211_BSS_SELECT_ATTR_RSSI:
1859 default:
1860 break;
1861 }
1862 join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI;
1863 join_pref_params[i].len = 2;
1864 join_pref_params[i].rssi_gain = 0;
1865 join_pref_params[i].band = 0;
1866 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
1867 sizeof(join_pref_params));
1868 if (err)
1869 brcmf_err("Set join_pref error (%d)\n", err);
1870}
1871
Arend van Spriel5b435de2011-10-05 13:19:03 +02001872static s32
1873brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001874 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001875{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001876 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001877 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001878 struct ieee80211_channel *chan = sme->channel;
1879 struct brcmf_join_params join_params;
1880 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001881 const struct brcmf_tlv *rsn_ie;
1882 const struct brcmf_vs_tlv *wpa_ie;
1883 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001884 u32 ie_len;
1885 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001886 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001887 s32 err = 0;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001888 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001889
Arend van Sprield96b8012012-12-05 15:26:02 +01001890 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001891 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001892 return -EIO;
1893
1894 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001895 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001896 return -EOPNOTSUPP;
1897 }
1898
Hante Meuleman89286dc2013-02-08 15:53:46 +01001899 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1900 /* A normal (non P2P) connection request setup. */
1901 ie = NULL;
1902 ie_len = 0;
1903 /* find the WPA_IE */
1904 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1905 if (wpa_ie) {
1906 ie = wpa_ie;
1907 ie_len = wpa_ie->len + TLV_HDR_LEN;
1908 } else {
1909 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001910 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1911 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001912 WLAN_EID_RSN);
1913 if (rsn_ie) {
1914 ie = rsn_ie;
1915 ie_len = rsn_ie->len + TLV_HDR_LEN;
1916 }
1917 }
1918 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1919 }
1920
1921 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1922 sme->ie, sme->ie_len);
1923 if (err)
1924 brcmf_err("Set Assoc REQ IE Failed\n");
1925 else
1926 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1927
Arend van Sprielc1179032012-10-22 13:55:33 -07001928 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001929
1930 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001931 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001932 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001933 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001934 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1935 cfg->channel, chan->center_freq, chanspec);
1936 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001937 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001938 chanspec = 0;
1939 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001940
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001941 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001942
1943 err = brcmf_set_wpa_version(ndev, sme);
1944 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001945 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001946 goto done;
1947 }
1948
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001949 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001950 err = brcmf_set_auth_type(ndev, sme);
1951 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001952 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001953 goto done;
1954 }
1955
Hante Meuleman240d61a2016-02-17 11:27:10 +01001956 err = brcmf_set_wsec_mode(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001957 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001958 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001959 goto done;
1960 }
1961
1962 err = brcmf_set_key_mgmt(ndev, sme);
1963 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001964 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001965 goto done;
1966 }
1967
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001968 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001969 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001970 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001971 goto done;
1972 }
1973
Hante Meuleman89286dc2013-02-08 15:53:46 +01001974 /* Join with specific BSSID and cached SSID
1975 * If SSID is zero join based on BSSID only
1976 */
1977 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1978 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1979 if (cfg->channel)
1980 join_params_size += sizeof(u16);
1981 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1982 if (ext_join_params == NULL) {
1983 err = -ENOMEM;
1984 goto done;
1985 }
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001986 ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN);
1987 ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len);
1988 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len);
1989 if (ssid_len < IEEE80211_MAX_SSID_LEN)
1990 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n",
1991 ext_join_params->ssid_le.SSID, ssid_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001992
Hante Meuleman89286dc2013-02-08 15:53:46 +01001993 /* Set up join scan parameters */
1994 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001995 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1996
1997 if (sme->bssid)
1998 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1999 else
Joe Perches93803b32015-03-02 19:54:49 -08002000 eth_broadcast_addr(ext_join_params->assoc_le.bssid);
Hante Meuleman89286dc2013-02-08 15:53:46 +01002001
2002 if (cfg->channel) {
2003 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
2004
2005 ext_join_params->assoc_le.chanspec_list[0] =
2006 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01002007 /* Increase dwell time to receive probe response or detect
2008 * beacon from target AP at a noisy air only during connect
2009 * command.
2010 */
2011 ext_join_params->scan_le.active_time =
2012 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
2013 ext_join_params->scan_le.passive_time =
2014 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
2015 /* To sync with presence period of VSDB GO send probe request
2016 * more frequently. Probe request will be stopped when it gets
2017 * probe response from target AP/GO.
2018 */
2019 ext_join_params->scan_le.nprobes =
2020 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
2021 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
2022 } else {
2023 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
2024 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
2025 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01002026 }
2027
Arend van Spriel7705ba62016-04-17 16:44:58 +02002028 brcmf_set_join_pref(ifp, &sme->bss_select);
2029
Hante Meuleman89286dc2013-02-08 15:53:46 +01002030 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
2031 join_params_size);
2032 kfree(ext_join_params);
2033 if (!err)
2034 /* This is it. join command worked, we are done */
2035 goto done;
2036
2037 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002038 memset(&join_params, 0, sizeof(join_params));
2039 join_params_size = sizeof(join_params.ssid_le);
2040
Hante Meulemane9a6ca82015-11-25 11:32:37 +01002041 memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len);
2042 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002043
Hante Meuleman89286dc2013-02-08 15:53:46 +01002044 if (sme->bssid)
2045 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
2046 else
Joe Perches93803b32015-03-02 19:54:49 -08002047 eth_broadcast_addr(join_params.params_le.bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002048
Hante Meuleman17012612013-02-06 18:40:44 +01002049 if (cfg->channel) {
2050 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
2051 join_params.params_le.chanspec_num = cpu_to_le32(1);
2052 join_params_size += sizeof(join_params.params_le);
2053 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002054 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002055 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002056 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01002057 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002058
2059done:
2060 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07002061 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01002062 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002063 return err;
2064}
2065
2066static s32
2067brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2068 u16 reason_code)
2069{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002070 struct brcmf_if *ifp = netdev_priv(ndev);
2071 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002072 struct brcmf_scb_val_le scbval;
2073 s32 err = 0;
2074
Arend van Sprield96b8012012-12-05 15:26:02 +01002075 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
Arend van Sprielce81e312012-10-22 13:55:37 -07002076 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002077 return -EIO;
2078
Arend van Sprielc1179032012-10-22 13:55:33 -07002079 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel4f3fff12014-11-20 22:27:02 +01002080 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Johannes Berg80279fb2015-05-22 16:22:20 +02002081 cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002082
Arend van Spriel06bb1232012-09-27 14:17:56 +02002083 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002084 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07002085 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07002086 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002087 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002088 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002089
Arend van Sprield96b8012012-12-05 15:26:02 +01002090 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002091 return err;
2092}
2093
2094static s32
Johannes Bergc8442112012-10-24 10:17:18 +02002095brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05002096 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002097{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002098 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002099 struct net_device *ndev = cfg_to_ndev(cfg);
2100 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002101 s32 err;
2102 s32 disable;
2103 u32 qdbm = 127;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002104
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002105 brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm);
Arend van Sprielce81e312012-10-22 13:55:37 -07002106 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002107 return -EIO;
2108
2109 switch (type) {
2110 case NL80211_TX_POWER_AUTOMATIC:
2111 break;
2112 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02002113 case NL80211_TX_POWER_FIXED:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002114 if (mbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002115 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002116 err = -EINVAL;
2117 goto done;
2118 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002119 qdbm = MBM_TO_DBM(4 * mbm);
2120 if (qdbm > 127)
2121 qdbm = 127;
2122 qdbm |= WL_TXPWR_OVERRIDE;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002123 break;
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002124 default:
2125 brcmf_err("Unsupported type %d\n", type);
2126 err = -EINVAL;
2127 goto done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002128 }
2129 /* Make sure radio is off or on as far as software is concerned */
2130 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07002131 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002132 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002133 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002134
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002135 err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002136 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002137 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002138
2139done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002140 brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002141 return err;
2142}
2143
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002144static s32
2145brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2146 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002147{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002148 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002149 struct net_device *ndev = cfg_to_ndev(cfg);
2150 struct brcmf_if *ifp = netdev_priv(ndev);
2151 s32 qdbm = 0;
2152 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002153
Arend van Sprield96b8012012-12-05 15:26:02 +01002154 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002155 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002156 return -EIO;
2157
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002158 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002159 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002160 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002161 goto done;
2162 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002163 *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002164
2165done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002166 brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002167 return err;
2168}
2169
2170static s32
2171brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002172 u8 key_idx, bool unicast, bool multicast)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002173{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002174 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002175 u32 index;
2176 u32 wsec;
2177 s32 err = 0;
2178
Arend van Sprield96b8012012-12-05 15:26:02 +01002179 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002180 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002181 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002182 return -EIO;
2183
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002184 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002185 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002186 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002187 goto done;
2188 }
2189
2190 if (wsec & WEP_ENABLED) {
2191 /* Just select a new current key */
2192 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002193 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07002194 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002195 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002196 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002197 }
2198done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002199 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002200 return err;
2201}
2202
2203static s32
Hante Meuleman219e0f72016-02-17 11:27:09 +01002204brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2205 u8 key_idx, bool pairwise, const u8 *mac_addr)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002206{
Hante Meuleman992f6062013-04-02 21:06:17 +02002207 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman240d61a2016-02-17 11:27:10 +01002208 struct brcmf_wsec_key *key;
2209 s32 err;
Hante Meuleman219e0f72016-02-17 11:27:09 +01002210
2211 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman240d61a2016-02-17 11:27:10 +01002212 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2213
Hante Meuleman219e0f72016-02-17 11:27:09 +01002214 if (!check_vif_up(ifp->vif))
2215 return -EIO;
2216
2217 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2218 /* we ignore this key index in this case */
2219 return -EINVAL;
2220 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002221
Hante Meuleman240d61a2016-02-17 11:27:10 +01002222 key = &ifp->vif->profile.key[key_idx];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002223
Hante Meuleman240d61a2016-02-17 11:27:10 +01002224 if (key->algo == CRYPTO_ALGO_OFF) {
2225 brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n");
2226 return -EINVAL;
2227 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002228
Hante Meuleman240d61a2016-02-17 11:27:10 +01002229 memset(key, 0, sizeof(*key));
2230 key->index = (u32)key_idx;
2231 key->flags = BRCMF_PRIMARY_KEY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002232
Hante Meuleman240d61a2016-02-17 11:27:10 +01002233 /* Clear the key/index */
2234 err = send_key_to_dongle(ifp, key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002235
Hante Meuleman219e0f72016-02-17 11:27:09 +01002236 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002237 return err;
2238}
2239
2240static s32
2241brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman240d61a2016-02-17 11:27:10 +01002242 u8 key_idx, bool pairwise, const u8 *mac_addr,
2243 struct key_params *params)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002244{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002245 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman118eb302014-12-21 12:43:49 +01002246 struct brcmf_wsec_key *key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002247 s32 val;
2248 s32 wsec;
Hante Meuleman219e0f72016-02-17 11:27:09 +01002249 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002250 u8 keybuf[8];
Hante Meuleman219e0f72016-02-17 11:27:09 +01002251 bool ext_key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002252
Arend van Sprield96b8012012-12-05 15:26:02 +01002253 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002254 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002255 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002256 return -EIO;
2257
Hante Meuleman118eb302014-12-21 12:43:49 +01002258 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2259 /* we ignore this key index in this case */
2260 brcmf_err("invalid key index (%d)\n", key_idx);
2261 return -EINVAL;
2262 }
2263
Hante Meuleman219e0f72016-02-17 11:27:09 +01002264 if (params->key_len == 0)
2265 return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise,
2266 mac_addr);
2267
2268 if (params->key_len > sizeof(key->data)) {
2269 brcmf_err("Too long key length (%u)\n", params->key_len);
2270 return -EINVAL;
2271 }
2272
2273 ext_key = false;
2274 if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2275 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
2276 brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr);
2277 ext_key = true;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002278 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002279
Hante Meuleman118eb302014-12-21 12:43:49 +01002280 key = &ifp->vif->profile.key[key_idx];
2281 memset(key, 0, sizeof(*key));
Hante Meuleman219e0f72016-02-17 11:27:09 +01002282 if ((ext_key) && (!is_multicast_ether_addr(mac_addr)))
2283 memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN);
Hante Meuleman118eb302014-12-21 12:43:49 +01002284 key->len = params->key_len;
2285 key->index = key_idx;
Hante Meuleman118eb302014-12-21 12:43:49 +01002286 memcpy(key->data, params->key, key->len);
Hante Meuleman219e0f72016-02-17 11:27:09 +01002287 if (!ext_key)
2288 key->flags = BRCMF_PRIMARY_KEY;
Hante Meuleman118eb302014-12-21 12:43:49 +01002289
Arend van Spriel5b435de2011-10-05 13:19:03 +02002290 switch (params->cipher) {
2291 case WLAN_CIPHER_SUITE_WEP40:
Hante Meuleman118eb302014-12-21 12:43:49 +01002292 key->algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002293 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002294 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002295 break;
2296 case WLAN_CIPHER_SUITE_WEP104:
Hante Meuleman118eb302014-12-21 12:43:49 +01002297 key->algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002298 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002299 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002300 break;
2301 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002302 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002303 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman118eb302014-12-21 12:43:49 +01002304 memcpy(keybuf, &key->data[24], sizeof(keybuf));
2305 memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
2306 memcpy(&key->data[16], keybuf, sizeof(keybuf));
Hante Meuleman1a873342012-09-27 14:17:54 +02002307 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002308 key->algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002309 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002310 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002311 break;
2312 case WLAN_CIPHER_SUITE_AES_CMAC:
Hante Meuleman118eb302014-12-21 12:43:49 +01002313 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002314 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002315 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002316 break;
2317 case WLAN_CIPHER_SUITE_CCMP:
Hante Meuleman118eb302014-12-21 12:43:49 +01002318 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002319 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002320 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002321 break;
2322 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002323 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002324 err = -EINVAL;
2325 goto done;
2326 }
2327
Hante Meuleman118eb302014-12-21 12:43:49 +01002328 err = send_key_to_dongle(ifp, key);
Hante Meuleman219e0f72016-02-17 11:27:09 +01002329 if (ext_key || err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002330 goto done;
2331
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002332 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002333 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002334 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002335 goto done;
2336 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002337 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002338 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002339 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002340 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002341 goto done;
2342 }
2343
Arend van Spriel5b435de2011-10-05 13:19:03 +02002344done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002345 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002346 return err;
2347}
2348
2349static s32
Hante Meuleman240d61a2016-02-17 11:27:10 +01002350brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, u8 key_idx,
2351 bool pairwise, const u8 *mac_addr, void *cookie,
2352 void (*callback)(void *cookie,
2353 struct key_params *params))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002354{
2355 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002356 struct brcmf_if *ifp = netdev_priv(ndev);
2357 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002358 struct brcmf_cfg80211_security *sec;
2359 s32 wsec;
2360 s32 err = 0;
2361
Arend van Sprield96b8012012-12-05 15:26:02 +01002362 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002363 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002364 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002365 return -EIO;
2366
2367 memset(&params, 0, sizeof(params));
2368
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002369 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002370 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002371 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002372 /* Ignore this error, may happen during DISASSOC */
2373 err = -EAGAIN;
2374 goto done;
2375 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002376 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002377 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002378 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2379 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002380 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002381 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2382 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002383 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002384 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002385 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002386 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002387 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002388 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002389 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002390 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002391 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002392 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002393 err = -EINVAL;
2394 goto done;
2395 }
2396 callback(cookie, &params);
2397
2398done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002399 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002400 return err;
2401}
2402
2403static s32
2404brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
Hante Meuleman240d61a2016-02-17 11:27:10 +01002405 struct net_device *ndev, u8 key_idx)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002406{
Hante Meuleman240d61a2016-02-17 11:27:10 +01002407 struct brcmf_if *ifp = netdev_priv(ndev);
2408
2409 brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx);
2410
2411 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
2412 return 0;
2413
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002414 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002415
2416 return -EOPNOTSUPP;
2417}
2418
Hante Meuleman118eb302014-12-21 12:43:49 +01002419static void
2420brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
2421{
2422 s32 err;
2423 u8 key_idx;
2424 struct brcmf_wsec_key *key;
2425 s32 wsec;
2426
2427 for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
2428 key = &ifp->vif->profile.key[key_idx];
2429 if ((key->algo == CRYPTO_ALGO_WEP1) ||
2430 (key->algo == CRYPTO_ALGO_WEP128))
2431 break;
2432 }
2433 if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
2434 return;
2435
2436 err = send_key_to_dongle(ifp, key);
2437 if (err) {
2438 brcmf_err("Setting WEP key failed (%d)\n", err);
2439 return;
2440 }
2441 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2442 if (err) {
2443 brcmf_err("get wsec error (%d)\n", err);
2444 return;
2445 }
2446 wsec |= WEP_ENABLED;
2447 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2448 if (err)
2449 brcmf_err("set wsec error (%d)\n", err);
2450}
2451
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002452static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si)
2453{
2454 struct nl80211_sta_flag_update *sfu;
2455
2456 brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags);
2457 si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS);
2458 sfu = &si->sta_flags;
2459 sfu->mask = BIT(NL80211_STA_FLAG_WME) |
2460 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2461 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2462 BIT(NL80211_STA_FLAG_AUTHORIZED);
2463 if (fw_sta_flags & BRCMF_STA_WME)
2464 sfu->set |= BIT(NL80211_STA_FLAG_WME);
2465 if (fw_sta_flags & BRCMF_STA_AUTHE)
2466 sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2467 if (fw_sta_flags & BRCMF_STA_ASSOC)
2468 sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2469 if (fw_sta_flags & BRCMF_STA_AUTHO)
2470 sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2471}
2472
2473static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si)
2474{
2475 struct {
2476 __le32 len;
2477 struct brcmf_bss_info_le bss_le;
2478 } *buf;
2479 u16 capability;
2480 int err;
2481
2482 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2483 if (!buf)
2484 return;
2485
2486 buf->len = cpu_to_le32(WL_BSS_INFO_MAX);
2487 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf,
2488 WL_BSS_INFO_MAX);
2489 if (err) {
2490 brcmf_err("Failed to get bss info (%d)\n", err);
2491 return;
2492 }
2493 si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
2494 si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period);
2495 si->bss_param.dtim_period = buf->bss_le.dtim_period;
2496 capability = le16_to_cpu(buf->bss_le.capability);
2497 if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT)
2498 si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2499 if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2500 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2501 if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2502 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2503}
2504
Arend van Spriel5b435de2011-10-05 13:19:03 +02002505static s32
Hante Meuleman3f5893d2016-01-02 09:41:37 +01002506brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp,
2507 struct station_info *sinfo)
2508{
2509 struct brcmf_scb_val_le scbval;
2510 struct brcmf_pktcnt_le pktcnt;
2511 s32 err;
2512 u32 rate;
2513 u32 rssi;
2514
2515 /* Get the current tx rate */
2516 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
2517 if (err < 0) {
2518 brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err);
2519 return err;
2520 }
2521 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
2522 sinfo->txrate.legacy = rate * 5;
2523
2524 memset(&scbval, 0, sizeof(scbval));
2525 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval,
2526 sizeof(scbval));
2527 if (err) {
2528 brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err);
2529 return err;
2530 }
2531 rssi = le32_to_cpu(scbval.val);
2532 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2533 sinfo->signal = rssi;
2534
2535 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt,
2536 sizeof(pktcnt));
2537 if (err) {
2538 brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err);
2539 return err;
2540 }
2541 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS) |
2542 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
2543 BIT(NL80211_STA_INFO_TX_PACKETS) |
2544 BIT(NL80211_STA_INFO_TX_FAILED);
2545 sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt);
2546 sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt);
2547 sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt);
2548 sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt);
2549
2550 return 0;
2551}
2552
2553static s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02002554brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002555 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002556{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002557 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002558 s32 err = 0;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002559 struct brcmf_sta_info_le sta_info_le;
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002560 u32 sta_flags;
2561 u32 is_tdls_peer;
Hante Meulemancae355d2015-10-08 20:33:17 +02002562 s32 total_rssi;
2563 s32 count_rssi;
2564 u32 i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002565
Arend van Sprield96b8012012-12-05 15:26:02 +01002566 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002567 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002568 return -EIO;
2569
Hante Meuleman3f5893d2016-01-02 09:41:37 +01002570 if (brcmf_is_ibssmode(ifp->vif))
2571 return brcmf_cfg80211_get_station_ibss(ifp, sinfo);
2572
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002573 memset(&sta_info_le, 0, sizeof(sta_info_le));
2574 memcpy(&sta_info_le, mac, ETH_ALEN);
2575 err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info",
2576 &sta_info_le,
2577 sizeof(sta_info_le));
2578 is_tdls_peer = !err;
2579 if (err) {
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002580 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002581 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002582 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002583 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002584 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002585 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002586 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002587 }
2588 brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver));
2589 sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME);
2590 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2591 sta_flags = le32_to_cpu(sta_info_le.flags);
2592 brcmf_convert_sta_flags(sta_flags, sinfo);
2593 sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2594 if (is_tdls_peer)
2595 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2596 else
2597 sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2598 if (sta_flags & BRCMF_STA_ASSOC) {
2599 sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
2600 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
2601 brcmf_fill_bss_param(ifp, sinfo);
2602 }
2603 if (sta_flags & BRCMF_STA_SCBSTATS) {
2604 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
2605 sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures);
2606 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
2607 sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts);
2608 sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts);
2609 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
2610 sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts);
2611 sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts);
2612 if (sinfo->tx_packets) {
Johannes Berg319090b2014-11-17 14:08:11 +01002613 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002614 sinfo->txrate.legacy =
2615 le32_to_cpu(sta_info_le.tx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002616 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002617 if (sinfo->rx_packets) {
2618 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002619 sinfo->rxrate.legacy =
2620 le32_to_cpu(sta_info_le.rx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002621 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002622 if (le16_to_cpu(sta_info_le.ver) >= 4) {
2623 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES);
2624 sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes);
2625 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES);
2626 sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes);
2627 }
Hante Meulemancae355d2015-10-08 20:33:17 +02002628 total_rssi = 0;
2629 count_rssi = 0;
2630 for (i = 0; i < BRCMF_ANT_MAX; i++) {
2631 if (sta_info_le.rssi[i]) {
2632 sinfo->chain_signal_avg[count_rssi] =
2633 sta_info_le.rssi[i];
2634 sinfo->chain_signal[count_rssi] =
2635 sta_info_le.rssi[i];
2636 total_rssi += sta_info_le.rssi[i];
2637 count_rssi++;
2638 }
2639 }
2640 if (count_rssi) {
2641 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
2642 sinfo->chains = count_rssi;
2643
2644 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2645 total_rssi /= count_rssi;
2646 sinfo->signal = total_rssi;
2647 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002648 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002649done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002650 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002651 return err;
2652}
2653
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02002654static int
2655brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
2656 int idx, u8 *mac, struct station_info *sinfo)
2657{
2658 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2659 struct brcmf_if *ifp = netdev_priv(ndev);
2660 s32 err;
2661
2662 brcmf_dbg(TRACE, "Enter, idx %d\n", idx);
2663
2664 if (idx == 0) {
2665 cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST);
2666 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST,
2667 &cfg->assoclist,
2668 sizeof(cfg->assoclist));
2669 if (err) {
2670 brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n",
2671 err);
2672 cfg->assoclist.count = 0;
2673 return -EOPNOTSUPP;
2674 }
2675 }
2676 if (idx < le32_to_cpu(cfg->assoclist.count)) {
2677 memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN);
2678 return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo);
2679 }
2680 return -ENOENT;
2681}
2682
Arend van Spriel5b435de2011-10-05 13:19:03 +02002683static s32
2684brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2685 bool enabled, s32 timeout)
2686{
2687 s32 pm;
2688 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002689 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002690 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002691
Arend van Sprield96b8012012-12-05 15:26:02 +01002692 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002693
2694 /*
2695 * Powersave enable/disable request is coming from the
2696 * cfg80211 even before the interface is up. In that
2697 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002698 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002699 * FW later while initializing the dongle
2700 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002701 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002702 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002703
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002704 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002705 goto done;
2706 }
2707
2708 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002709 /* Do not enable the power save after assoc if it is a p2p interface */
2710 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2711 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2712 pm = PM_OFF;
2713 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002714 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002715
Arend van Sprielc1179032012-10-22 13:55:33 -07002716 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002717 if (err) {
2718 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002719 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002720 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002721 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002722 }
2723done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002724 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002725 return err;
2726}
2727
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002728static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002729 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002730{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002731 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002732 struct ieee80211_channel *notify_channel;
2733 struct cfg80211_bss *bss;
2734 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002735 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002736 u16 channel;
2737 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002738 u16 notify_capability;
2739 u16 notify_interval;
2740 u8 *notify_ie;
2741 size_t notify_ielen;
2742 s32 notify_signal;
2743
2744 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002745 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002746 return 0;
2747 }
2748
Franky Lin83cf17a2013-04-11 13:28:50 +02002749 if (!bi->ctl_ch) {
2750 ch.chspec = le16_to_cpu(bi->chanspec);
2751 cfg->d11inf.decchspec(&ch);
2752 bi->ctl_ch = ch.chnum;
2753 }
2754 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002755
2756 if (channel <= CH_MAX_2G_CHANNEL)
Johannes Berg57fbcce2016-04-12 15:56:15 +02002757 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002758 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02002759 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002760
2761 freq = ieee80211_channel_to_frequency(channel, band->band);
2762 notify_channel = ieee80211_get_channel(wiphy, freq);
2763
Arend van Spriel5b435de2011-10-05 13:19:03 +02002764 notify_capability = le16_to_cpu(bi->capability);
2765 notify_interval = le16_to_cpu(bi->beacon_period);
2766 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2767 notify_ielen = le32_to_cpu(bi->ie_length);
2768 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2769
Arend van Spriel16886732012-12-05 15:26:04 +01002770 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2771 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2772 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2773 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2774 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002775
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002776 bss = cfg80211_inform_bss(wiphy, notify_channel,
2777 CFG80211_BSS_FTYPE_UNKNOWN,
2778 (const u8 *)bi->BSSID,
2779 0, notify_capability,
2780 notify_interval, notify_ie,
2781 notify_ielen, notify_signal,
2782 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002783
Franky Line78946e2011-11-10 20:30:34 +01002784 if (!bss)
2785 return -ENOMEM;
2786
Johannes Berg5b112d32013-02-01 01:49:58 +01002787 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002788
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002789 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002790}
2791
Roland Vossen6f09be02011-10-18 14:03:02 +02002792static struct brcmf_bss_info_le *
2793next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2794{
2795 if (bss == NULL)
2796 return list->bss_info_le;
2797 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2798 le32_to_cpu(bss->length));
2799}
2800
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002801static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002802{
2803 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002804 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002805 s32 err = 0;
2806 int i;
2807
Hante Meulemanef8596e2014-09-30 10:23:13 +02002808 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002809 if (bss_list->count != 0 &&
2810 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002811 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2812 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002813 return -EOPNOTSUPP;
2814 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002815 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002816 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002817 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002818 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002819 if (err)
2820 break;
2821 }
2822 return err;
2823}
2824
Hante Meulemanb0a79082015-12-10 13:43:07 +01002825static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg,
2826 struct net_device *ndev, const u8 *bssid)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002827{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002828 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002829 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002830 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002831 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002832 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002833 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002834 u8 *buf = NULL;
2835 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002836 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002837 u16 notify_capability;
2838 u16 notify_interval;
2839 u8 *notify_ie;
2840 size_t notify_ielen;
2841 s32 notify_signal;
2842
Arend van Sprield96b8012012-12-05 15:26:02 +01002843 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002844
2845 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2846 if (buf == NULL) {
2847 err = -ENOMEM;
2848 goto CleanUp;
2849 }
2850
2851 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2852
Arend van Sprielac24be62012-10-22 10:36:23 -07002853 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2854 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002855 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002856 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002857 goto CleanUp;
2858 }
2859
Roland Vossend34bf642011-10-18 14:03:01 +02002860 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002861
Franky Lin83cf17a2013-04-11 13:28:50 +02002862 ch.chspec = le16_to_cpu(bi->chanspec);
2863 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002864
Franky Lin83cf17a2013-04-11 13:28:50 +02002865 if (ch.band == BRCMU_CHAN_BAND_2G)
Johannes Berg57fbcce2016-04-12 15:56:15 +02002866 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002867 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02002868 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002869
Franky Lin83cf17a2013-04-11 13:28:50 +02002870 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Hante Meulemanb0a79082015-12-10 13:43:07 +01002871 cfg->channel = freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002872 notify_channel = ieee80211_get_channel(wiphy, freq);
2873
Arend van Spriel5b435de2011-10-05 13:19:03 +02002874 notify_capability = le16_to_cpu(bi->capability);
2875 notify_interval = le16_to_cpu(bi->beacon_period);
2876 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2877 notify_ielen = le32_to_cpu(bi->ie_length);
2878 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2879
Franky Lin83cf17a2013-04-11 13:28:50 +02002880 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002881 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2882 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2883 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002884
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002885 bss = cfg80211_inform_bss(wiphy, notify_channel,
2886 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2887 notify_capability, notify_interval,
2888 notify_ie, notify_ielen, notify_signal,
2889 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002890
Franky Line78946e2011-11-10 20:30:34 +01002891 if (!bss) {
2892 err = -ENOMEM;
2893 goto CleanUp;
2894 }
2895
Johannes Berg5b112d32013-02-01 01:49:58 +01002896 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002897
Arend van Spriel5b435de2011-10-05 13:19:03 +02002898CleanUp:
2899
2900 kfree(buf);
2901
Arend van Sprield96b8012012-12-05 15:26:02 +01002902 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002903
2904 return err;
2905}
2906
Hante Meuleman89286dc2013-02-08 15:53:46 +01002907static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2908 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002909{
Roland Vossend34bf642011-10-18 14:03:01 +02002910 struct brcmf_bss_info_le *bi;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002911 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002912 u16 beacon_interval;
2913 u8 dtim_period;
2914 size_t ie_len;
2915 u8 *ie;
2916 s32 err = 0;
2917
Arend van Sprield96b8012012-12-05 15:26:02 +01002918 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002919 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002920 return err;
2921
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002922 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002923 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002924 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002925 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002926 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002927 goto update_bss_info_out;
2928 }
2929
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002930 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2931 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002932 if (err)
2933 goto update_bss_info_out;
2934
2935 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2936 ie_len = le32_to_cpu(bi->ie_length);
2937 beacon_interval = le16_to_cpu(bi->beacon_period);
2938
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002939 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002940 if (tim)
2941 dtim_period = tim->data[1];
2942 else {
2943 /*
2944 * active scan was done so we could not get dtim
2945 * information out of probe response.
2946 * so we speficially query dtim information to dongle.
2947 */
2948 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002949 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002950 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002951 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002952 goto update_bss_info_out;
2953 }
2954 dtim_period = (u8)var;
2955 }
2956
Arend van Spriel5b435de2011-10-05 13:19:03 +02002957update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01002958 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002959 return err;
2960}
2961
Hante Meuleman18e2f612013-02-08 15:53:49 +01002962void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002963{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002964 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002965
Arend van Sprielc1179032012-10-22 13:55:33 -07002966 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Hante Meulemanf07998952012-11-05 16:22:13 -08002967 if (cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02002968 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002969 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02002970 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002971 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2972 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002973}
2974
Hante Meulemane756af52012-09-11 21:18:52 +02002975static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2976{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002977 struct brcmf_cfg80211_info *cfg =
2978 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02002979 escan_timeout_work);
2980
Hante Meulemanef8596e2014-09-30 10:23:13 +02002981 brcmf_inform_bss(cfg);
Arend van Spriela0f472a2013-04-05 10:57:49 +02002982 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02002983}
2984
2985static void brcmf_escan_timeout(unsigned long data)
2986{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002987 struct brcmf_cfg80211_info *cfg =
2988 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02002989
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002990 if (cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002991 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08002992 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02002993 }
2994}
2995
2996static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02002997brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2998 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02002999 struct brcmf_bss_info_le *bss_info_le)
3000{
Franky Lin83cf17a2013-04-11 13:28:50 +02003001 struct brcmu_chan ch_bss, ch_bss_info_le;
3002
3003 ch_bss.chspec = le16_to_cpu(bss->chanspec);
3004 cfg->d11inf.decchspec(&ch_bss);
3005 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
3006 cfg->d11inf.decchspec(&ch_bss_info_le);
3007
Hante Meulemane756af52012-09-11 21:18:52 +02003008 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02003009 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02003010 bss_info_le->SSID_len == bss->SSID_len &&
3011 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01003012 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
3013 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02003014 s16 bss_rssi = le16_to_cpu(bss->RSSI);
3015 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
3016
Hante Meulemane756af52012-09-11 21:18:52 +02003017 /* preserve max RSSI if the measurements are
3018 * both on-channel or both off-channel
3019 */
Arend van Spriel029591f2012-09-19 22:21:06 +02003020 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02003021 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01003022 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
3023 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02003024 /* preserve the on-channel rssi measurement
3025 * if the new measurement is off channel
3026 */
3027 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01003028 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02003029 }
3030 return 1;
3031 }
3032 return 0;
3033}
3034
3035static s32
Arend van Spriel19937322012-11-05 16:22:32 -08003036brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02003037 const struct brcmf_event_msg *e, void *data)
3038{
Arend van Spriel19937322012-11-05 16:22:32 -08003039 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02003040 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02003041 struct brcmf_escan_result_le *escan_result_le;
3042 struct brcmf_bss_info_le *bss_info_le;
3043 struct brcmf_bss_info_le *bss = NULL;
3044 u32 bi_length;
3045 struct brcmf_scan_results *list;
3046 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02003047 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02003048
Arend van Spriel5c36b992012-11-14 18:46:05 -08003049 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02003050
Arend van Spriela0f472a2013-04-05 10:57:49 +02003051 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Hante Meuleman37a869e2015-10-29 20:33:17 +01003052 brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx);
Hante Meulemane756af52012-09-11 21:18:52 +02003053 return -EPERM;
3054 }
3055
3056 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003057 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003058 escan_result_le = (struct brcmf_escan_result_le *) data;
3059 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003060 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003061 goto exit;
3062 }
Hante Meulemane756af52012-09-11 21:18:52 +02003063 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003064 brcmf_err("Invalid bss_count %d: ignoring\n",
3065 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02003066 goto exit;
3067 }
3068 bss_info_le = &escan_result_le->bss_info_le;
3069
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003070 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
3071 goto exit;
3072
3073 if (!cfg->scan_request) {
3074 brcmf_dbg(SCAN, "result without cfg80211 request\n");
3075 goto exit;
3076 }
3077
Hante Meulemane756af52012-09-11 21:18:52 +02003078 bi_length = le32_to_cpu(bss_info_le->length);
3079 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
3080 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003081 brcmf_err("Invalid bss_info length %d: ignoring\n",
3082 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02003083 goto exit;
3084 }
3085
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003086 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02003087 BIT(NL80211_IFTYPE_ADHOC))) {
3088 if (le16_to_cpu(bss_info_le->capability) &
3089 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003090 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003091 goto exit;
3092 }
3093 }
3094
3095 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003096 cfg->escan_info.escan_buf;
Hante Meulemand5367332016-02-17 11:26:51 +01003097 if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003098 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003099 goto exit;
3100 }
3101
3102 for (i = 0; i < list->count; i++) {
3103 bss = bss ? (struct brcmf_bss_info_le *)
3104 ((unsigned char *)bss +
3105 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02003106 if (brcmf_compare_update_same_bss(cfg, bss,
3107 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02003108 goto exit;
3109 }
Hante Meulemand5367332016-02-17 11:26:51 +01003110 memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le,
3111 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02003112 list->version = le32_to_cpu(bss_info_le->version);
3113 list->buflen += bi_length;
3114 list->count++;
3115 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003116 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003117 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
3118 goto exit;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003119 if (cfg->scan_request) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003120 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02003121 aborted = status != BRCMF_E_STATUS_SUCCESS;
Hante Meulemanef8596e2014-09-30 10:23:13 +02003122 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
Hante Meulemane756af52012-09-11 21:18:52 +02003123 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003124 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
3125 status);
Hante Meulemane756af52012-09-11 21:18:52 +02003126 }
3127exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003128 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02003129}
3130
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003131static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02003132{
Arend van Spriel5c36b992012-11-14 18:46:05 -08003133 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
3134 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08003135 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
3136 /* Init scan_timeout timer */
3137 init_timer(&cfg->escan_timeout);
3138 cfg->escan_timeout.data = (unsigned long) cfg;
3139 cfg->escan_timeout.function = brcmf_escan_timeout;
3140 INIT_WORK(&cfg->escan_timeout_work,
3141 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02003142}
3143
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003144/* PFN result doesn't have all the info which are required by the supplicant
3145 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3146 * via wl_inform_single_bss in the required format. Escan does require the
3147 * scan request in the form of cfg80211_scan_request. For timebeing, create
3148 * cfg80211_scan_request one out of the received PNO event.
3149 */
3150static s32
3151brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
3152 const struct brcmf_event_msg *e, void *data)
3153{
3154 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3155 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3156 struct cfg80211_scan_request *request = NULL;
3157 struct cfg80211_ssid *ssid = NULL;
3158 struct ieee80211_channel *channel = NULL;
3159 struct wiphy *wiphy = cfg_to_wiphy(cfg);
3160 int err = 0;
3161 int channel_req = 0;
3162 int band = 0;
3163 struct brcmf_pno_scanresults_le *pfn_result;
3164 u32 result_count;
3165 u32 status;
3166
3167 brcmf_dbg(SCAN, "Enter\n");
3168
Hante Meuleman0aedbca2016-02-17 11:26:54 +01003169 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3170 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3171 return 0;
3172 }
3173
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003174 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3175 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
3176 return 0;
3177 }
3178
3179 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3180 result_count = le32_to_cpu(pfn_result->count);
3181 status = le32_to_cpu(pfn_result->status);
3182
3183 /* PFN event is limited to fit 512 bytes so we may get
3184 * multiple NET_FOUND events. For now place a warning here.
3185 */
3186 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
3187 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
3188 if (result_count > 0) {
3189 int i;
3190
3191 request = kzalloc(sizeof(*request), GFP_KERNEL);
3192 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3193 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
3194 if (!request || !ssid || !channel) {
3195 err = -ENOMEM;
3196 goto out_err;
3197 }
3198
3199 request->wiphy = wiphy;
3200 data += sizeof(struct brcmf_pno_scanresults_le);
3201 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3202
3203 for (i = 0; i < result_count; i++) {
3204 netinfo = &netinfo_start[i];
3205 if (!netinfo) {
3206 brcmf_err("Invalid netinfo ptr. index: %d\n",
3207 i);
3208 err = -EINVAL;
3209 goto out_err;
3210 }
3211
3212 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3213 netinfo->SSID, netinfo->channel);
3214 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3215 ssid[i].ssid_len = netinfo->SSID_len;
3216 request->n_ssids++;
3217
3218 channel_req = netinfo->channel;
3219 if (channel_req <= CH_MAX_2G_CHANNEL)
3220 band = NL80211_BAND_2GHZ;
3221 else
3222 band = NL80211_BAND_5GHZ;
3223 channel[i].center_freq =
3224 ieee80211_channel_to_frequency(channel_req,
3225 band);
3226 channel[i].band = band;
3227 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3228 request->channels[i] = &channel[i];
3229 request->n_channels++;
3230 }
3231
3232 /* assign parsed ssid array */
3233 if (request->n_ssids)
3234 request->ssids = &ssid[0];
3235
3236 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3237 /* Abort any on-going scan */
3238 brcmf_abort_scanning(cfg);
3239 }
3240
3241 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3242 cfg->escan_info.run = brcmf_run_escan;
3243 err = brcmf_do_escan(cfg, wiphy, ifp, request);
3244 if (err) {
3245 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3246 goto out_err;
3247 }
3248 cfg->sched_escan = true;
3249 cfg->scan_request = request;
3250 } else {
3251 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3252 goto out_err;
3253 }
3254
3255 kfree(ssid);
3256 kfree(channel);
3257 kfree(request);
3258 return 0;
3259
3260out_err:
3261 kfree(ssid);
3262 kfree(channel);
3263 kfree(request);
3264 cfg80211_sched_scan_stopped(wiphy);
3265 return err;
3266}
3267
3268static int brcmf_dev_pno_clean(struct net_device *ndev)
3269{
3270 int ret;
3271
3272 /* Disable pfn */
3273 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
3274 if (ret == 0) {
3275 /* clear pfn */
3276 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3277 NULL, 0);
3278 }
3279 if (ret < 0)
3280 brcmf_err("failed code %d\n", ret);
3281
3282 return ret;
3283}
3284
3285static int brcmf_dev_pno_config(struct brcmf_if *ifp,
3286 struct cfg80211_sched_scan_request *request)
3287{
3288 struct brcmf_pno_param_le pfn_param;
3289 struct brcmf_pno_macaddr_le pfn_mac;
3290 s32 err;
3291 u8 *mac_mask;
3292 int i;
3293
3294 memset(&pfn_param, 0, sizeof(pfn_param));
3295 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3296
3297 /* set extra pno params */
3298 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3299 pfn_param.repeat = BRCMF_PNO_REPEAT;
3300 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3301
3302 /* set up pno scan fr */
3303 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3304
3305 err = brcmf_fil_iovar_data_set(ifp, "pfn_set", &pfn_param,
3306 sizeof(pfn_param));
3307 if (err) {
3308 brcmf_err("pfn_set failed, err=%d\n", err);
3309 return err;
3310 }
3311
3312 /* Find out if mac randomization should be turned on */
3313 if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR))
3314 return 0;
3315
3316 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
3317 pfn_mac.flags = BRCMF_PFN_MAC_OUI_ONLY | BRCMF_PFN_SET_MAC_UNASSOC;
3318
3319 memcpy(pfn_mac.mac, request->mac_addr, ETH_ALEN);
3320 mac_mask = request->mac_addr_mask;
3321 for (i = 0; i < ETH_ALEN; i++) {
3322 pfn_mac.mac[i] &= mac_mask[i];
3323 pfn_mac.mac[i] |= get_random_int() & ~(mac_mask[i]);
3324 }
3325 /* Clear multi bit */
3326 pfn_mac.mac[0] &= 0xFE;
3327 /* Set locally administered */
3328 pfn_mac.mac[0] |= 0x02;
3329
3330 err = brcmf_fil_iovar_data_set(ifp, "pfn_macaddr", &pfn_mac,
3331 sizeof(pfn_mac));
3332 if (err)
3333 brcmf_err("pfn_macaddr failed, err=%d\n", err);
3334
3335 return err;
3336}
3337
3338static int
3339brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3340 struct net_device *ndev,
3341 struct cfg80211_sched_scan_request *request)
3342{
3343 struct brcmf_if *ifp = netdev_priv(ndev);
3344 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
3345 struct brcmf_pno_net_param_le pfn;
3346 int i;
3347 int ret = 0;
3348
3349 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
3350 request->n_match_sets, request->n_ssids);
3351 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3352 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
3353 return -EAGAIN;
3354 }
3355 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3356 brcmf_err("Scanning suppressed: status (%lu)\n",
3357 cfg->scan_status);
3358 return -EAGAIN;
3359 }
3360
3361 if (!request->n_ssids || !request->n_match_sets) {
3362 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
3363 request->n_ssids);
3364 return -EINVAL;
3365 }
3366
3367 if (request->n_ssids > 0) {
3368 for (i = 0; i < request->n_ssids; i++) {
3369 /* Active scan req for ssids */
3370 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3371 request->ssids[i].ssid);
3372
3373 /* match_set ssids is a supert set of n_ssid list,
3374 * so we need not add these set separately.
3375 */
3376 }
3377 }
3378
3379 if (request->n_match_sets > 0) {
3380 /* clean up everything */
3381 ret = brcmf_dev_pno_clean(ndev);
3382 if (ret < 0) {
3383 brcmf_err("failed error=%d\n", ret);
3384 return ret;
3385 }
3386
3387 /* configure pno */
3388 if (brcmf_dev_pno_config(ifp, request))
3389 return -EINVAL;
3390
3391 /* configure each match set */
3392 for (i = 0; i < request->n_match_sets; i++) {
3393 struct cfg80211_ssid *ssid;
3394 u32 ssid_len;
3395
3396 ssid = &request->match_sets[i].ssid;
3397 ssid_len = ssid->ssid_len;
3398
3399 if (!ssid_len) {
3400 brcmf_err("skip broadcast ssid\n");
3401 continue;
3402 }
3403 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3404 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3405 pfn.wsec = cpu_to_le32(0);
3406 pfn.infra = cpu_to_le32(1);
3407 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3408 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3409 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
3410 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
3411 sizeof(pfn));
3412 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3413 ret == 0 ? "set" : "failed", ssid->ssid);
3414 }
3415 /* Enable the PNO */
3416 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
3417 brcmf_err("PNO enable failed!! ret=%d\n", ret);
3418 return -EINVAL;
3419 }
3420 } else {
3421 return -EINVAL;
3422 }
3423
3424 return 0;
3425}
3426
3427static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3428 struct net_device *ndev)
3429{
3430 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3431
3432 brcmf_dbg(SCAN, "enter\n");
3433 brcmf_dev_pno_clean(ndev);
3434 if (cfg->sched_escan)
3435 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
3436 return 0;
3437}
3438
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05003439static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003440{
3441 if (ms < 1000 / HZ) {
3442 cond_resched();
3443 mdelay(ms);
3444 } else {
3445 msleep(ms);
3446 }
3447}
3448
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003449static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
3450 u8 *pattern, u32 patternsize, u8 *mask,
3451 u32 packet_offset)
3452{
3453 struct brcmf_fil_wowl_pattern_le *filter;
3454 u32 masksize;
3455 u32 patternoffset;
3456 u8 *buf;
3457 u32 bufsize;
3458 s32 ret;
3459
3460 masksize = (patternsize + 7) / 8;
3461 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
3462
3463 bufsize = sizeof(*filter) + patternsize + masksize;
3464 buf = kzalloc(bufsize, GFP_KERNEL);
3465 if (!buf)
3466 return -ENOMEM;
3467 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
3468
3469 memcpy(filter->cmd, cmd, 4);
3470 filter->masksize = cpu_to_le32(masksize);
3471 filter->offset = cpu_to_le32(packet_offset);
3472 filter->patternoffset = cpu_to_le32(patternoffset);
3473 filter->patternsize = cpu_to_le32(patternsize);
3474 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
3475
3476 if ((mask) && (masksize))
3477 memcpy(buf + sizeof(*filter), mask, masksize);
3478 if ((pattern) && (patternsize))
3479 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
3480
3481 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
3482
3483 kfree(buf);
3484 return ret;
3485}
3486
Hante Meuleman3021ad92016-01-05 11:05:45 +01003487static s32
3488brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
3489 void *data)
3490{
3491 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3492 struct brcmf_pno_scanresults_le *pfn_result;
3493 struct brcmf_pno_net_info_le *netinfo;
3494
3495 brcmf_dbg(SCAN, "Enter\n");
3496
Hante Meuleman0aedbca2016-02-17 11:26:54 +01003497 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3498 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3499 return 0;
3500 }
3501
Hante Meuleman3021ad92016-01-05 11:05:45 +01003502 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3503
3504 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3505 brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n");
3506 return 0;
3507 }
3508
3509 if (le32_to_cpu(pfn_result->count) < 1) {
3510 brcmf_err("Invalid result count, expected 1 (%d)\n",
3511 le32_to_cpu(pfn_result->count));
3512 return -EINVAL;
3513 }
3514
3515 data += sizeof(struct brcmf_pno_scanresults_le);
3516 netinfo = (struct brcmf_pno_net_info_le *)data;
3517 memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
3518 cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
3519 cfg->wowl.nd->n_channels = 1;
3520 cfg->wowl.nd->channels[0] =
3521 ieee80211_channel_to_frequency(netinfo->channel,
3522 netinfo->channel <= CH_MAX_2G_CHANNEL ?
3523 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
3524 cfg->wowl.nd_info->n_matches = 1;
3525 cfg->wowl.nd_info->matches[0] = cfg->wowl.nd;
3526
3527 /* Inform (the resume task) that the net detect information was recvd */
3528 cfg->wowl.nd_data_completed = true;
3529 wake_up(&cfg->wowl.nd_data_wait);
3530
3531 return 0;
3532}
3533
Hante Meulemanaeb64222015-10-29 20:33:19 +01003534#ifdef CONFIG_PM
3535
3536static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3537{
Hante Meuleman3021ad92016-01-05 11:05:45 +01003538 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemanaeb64222015-10-29 20:33:19 +01003539 struct brcmf_wowl_wakeind_le wake_ind_le;
3540 struct cfg80211_wowlan_wakeup wakeup_data;
3541 struct cfg80211_wowlan_wakeup *wakeup;
3542 u32 wakeind;
3543 s32 err;
Hante Meuleman3021ad92016-01-05 11:05:45 +01003544 int timeout;
Hante Meulemanaeb64222015-10-29 20:33:19 +01003545
3546 err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
3547 sizeof(wake_ind_le));
Hante Meuleman3021ad92016-01-05 11:05:45 +01003548 if (err) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003549 brcmf_err("Get wowl_wakeind failed, err = %d\n", err);
3550 return;
3551 }
3552
3553 wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
3554 if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
Hante Meuleman3021ad92016-01-05 11:05:45 +01003555 BRCMF_WOWL_RETR | BRCMF_WOWL_NET |
3556 BRCMF_WOWL_PFN_FOUND)) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003557 wakeup = &wakeup_data;
3558 memset(&wakeup_data, 0, sizeof(wakeup_data));
3559 wakeup_data.pattern_idx = -1;
3560
3561 if (wakeind & BRCMF_WOWL_MAGIC) {
3562 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
3563 wakeup_data.magic_pkt = true;
3564 }
3565 if (wakeind & BRCMF_WOWL_DIS) {
3566 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
3567 wakeup_data.disconnect = true;
3568 }
3569 if (wakeind & BRCMF_WOWL_BCN) {
3570 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
3571 wakeup_data.disconnect = true;
3572 }
3573 if (wakeind & BRCMF_WOWL_RETR) {
3574 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
3575 wakeup_data.disconnect = true;
3576 }
3577 if (wakeind & BRCMF_WOWL_NET) {
3578 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
3579 /* For now always map to pattern 0, no API to get
3580 * correct information available at the moment.
3581 */
3582 wakeup_data.pattern_idx = 0;
3583 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003584 if (wakeind & BRCMF_WOWL_PFN_FOUND) {
3585 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n");
3586 timeout = wait_event_timeout(cfg->wowl.nd_data_wait,
3587 cfg->wowl.nd_data_completed,
3588 BRCMF_ND_INFO_TIMEOUT);
3589 if (!timeout)
3590 brcmf_err("No result for wowl net detect\n");
3591 else
3592 wakeup_data.net_detect = cfg->wowl.nd_info;
3593 }
Hante Meuleman5c22fb82016-02-17 11:27:03 +01003594 if (wakeind & BRCMF_WOWL_GTK_FAILURE) {
3595 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n");
3596 wakeup_data.gtk_rekey_failure = true;
3597 }
Hante Meulemanaeb64222015-10-29 20:33:19 +01003598 } else {
3599 wakeup = NULL;
3600 }
3601 cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
3602}
3603
3604#else
3605
3606static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3607{
3608}
3609
3610#endif /* CONFIG_PM */
3611
Arend van Spriel5b435de2011-10-05 13:19:03 +02003612static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
3613{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003614 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3615 struct net_device *ndev = cfg_to_ndev(cfg);
3616 struct brcmf_if *ifp = netdev_priv(ndev);
3617
Arend van Sprield96b8012012-12-05 15:26:02 +01003618 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003619
Hante Meuleman3021ad92016-01-05 11:05:45 +01003620 if (cfg->wowl.active) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003621 brcmf_report_wowl_wakeind(wiphy, ifp);
3622 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
3623 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meuleman73ef9e62016-02-17 11:27:05 +01003624 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
3625 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003626 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
Hante Meuleman3021ad92016-01-05 11:05:45 +01003627 cfg->wowl.pre_pmmode);
3628 cfg->wowl.active = false;
3629 if (cfg->wowl.nd_enabled) {
3630 brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev);
3631 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3632 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3633 brcmf_notify_sched_scan_results);
3634 cfg->wowl.nd_enabled = false;
3635 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003636 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003637 return 0;
3638}
3639
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003640static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
3641 struct brcmf_if *ifp,
3642 struct cfg80211_wowlan *wowl)
3643{
3644 u32 wowl_config;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003645 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003646
3647 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
3648
Hante Meuleman73ef9e62016-02-17 11:27:05 +01003649 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
3650 brcmf_configure_arp_nd_offload(ifp, false);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003651 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003652 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
3653
3654 wowl_config = 0;
3655 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003656 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003657 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003658 wowl_config |= BRCMF_WOWL_MAGIC;
3659 if ((wowl->patterns) && (wowl->n_patterns)) {
3660 wowl_config |= BRCMF_WOWL_NET;
3661 for (i = 0; i < wowl->n_patterns; i++) {
3662 brcmf_config_wowl_pattern(ifp, "add",
3663 (u8 *)wowl->patterns[i].pattern,
3664 wowl->patterns[i].pattern_len,
3665 (u8 *)wowl->patterns[i].mask,
3666 wowl->patterns[i].pkt_offset);
3667 }
3668 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003669 if (wowl->nd_config) {
3670 brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev,
3671 wowl->nd_config);
3672 wowl_config |= BRCMF_WOWL_PFN_FOUND;
3673
3674 cfg->wowl.nd_data_completed = false;
3675 cfg->wowl.nd_enabled = true;
3676 /* Now reroute the event for PFN to the wowl function. */
3677 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3678 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3679 brcmf_wowl_nd_results);
3680 }
Hante Meuleman5c22fb82016-02-17 11:27:03 +01003681 if (wowl->gtk_rekey_failure)
3682 wowl_config |= BRCMF_WOWL_GTK_FAILURE;
Hante Meuleman3021ad92016-01-05 11:05:45 +01003683 if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
3684 wowl_config |= BRCMF_WOWL_UNASSOC;
3685
Hante Meuleman28b285a2016-04-11 11:35:22 +02003686 brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", "clear",
3687 sizeof(struct brcmf_wowl_wakeind_le));
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003688 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
3689 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
3690 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003691 cfg->wowl.active = true;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003692}
3693
Arend van Spriel5b435de2011-10-05 13:19:03 +02003694static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003695 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003696{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003697 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3698 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003699 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07003700 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003701
Arend van Sprield96b8012012-12-05 15:26:02 +01003702 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003703
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003704 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07003705 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02003706 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003707 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07003708 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003709
Hante Meuleman3021ad92016-01-05 11:05:45 +01003710 /* Stop scheduled scan */
3711 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
3712 brcmf_cfg80211_sched_scan_stop(wiphy, ndev);
3713
Arend van Spriel7d641072012-10-22 13:55:39 -07003714 /* end any scanning */
3715 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003716 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003717
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003718 if (wowl == NULL) {
3719 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
3720 list_for_each_entry(vif, &cfg->vif_list, list) {
3721 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
3722 continue;
3723 /* While going to suspend if associated with AP
3724 * disassociate from AP to save power while system is
3725 * in suspended state
3726 */
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01003727 brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003728 /* Make sure WPA_Supplicant receives all the event
3729 * generated due to DISASSOC call to the fw to keep
3730 * the state fw and WPA_Supplicant state consistent
3731 */
3732 brcmf_delay(500);
3733 }
3734 /* Configure MPC */
3735 brcmf_set_mpc(ifp, 1);
3736
3737 } else {
3738 /* Configure WOWL paramaters */
3739 brcmf_configure_wowl(cfg, ifp, wowl);
3740 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003741
Arend van Spriel7d641072012-10-22 13:55:39 -07003742exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01003743 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07003744 /* clear any scanning activity */
3745 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003746 return 0;
3747}
3748
3749static __used s32
Hante Meuleman6c404f32015-12-10 13:43:03 +01003750brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003751{
Hante Meuleman6c404f32015-12-10 13:43:03 +01003752 struct brcmf_pmk_list_le *pmk_list;
3753 int i;
3754 u32 npmk;
3755 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003756
Hante Meuleman6c404f32015-12-10 13:43:03 +01003757 pmk_list = &cfg->pmk_list;
3758 npmk = le32_to_cpu(pmk_list->npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003759
Hante Meuleman6c404f32015-12-10 13:43:03 +01003760 brcmf_dbg(CONN, "No of elements %d\n", npmk);
3761 for (i = 0; i < npmk; i++)
3762 brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003763
Hante Meuleman6c404f32015-12-10 13:43:03 +01003764 err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list,
3765 sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02003766
3767 return err;
3768}
3769
3770static s32
3771brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3772 struct cfg80211_pmksa *pmksa)
3773{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003774 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003775 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003776 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3777 s32 err;
3778 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003779
Arend van Sprield96b8012012-12-05 15:26:02 +01003780 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003781 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003782 return -EIO;
3783
Hante Meuleman6c404f32015-12-10 13:43:03 +01003784 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3785 for (i = 0; i < npmk; i++)
3786 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003787 break;
Hante Meuleman6c404f32015-12-10 13:43:03 +01003788 if (i < BRCMF_MAXPMKID) {
3789 memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN);
3790 memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
3791 if (i == npmk) {
3792 npmk++;
3793 cfg->pmk_list.npmk = cpu_to_le32(npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003794 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003795 } else {
3796 brcmf_err("Too many PMKSA entries cached %d\n", npmk);
3797 return -EINVAL;
3798 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003799
Hante Meuleman6c404f32015-12-10 13:43:03 +01003800 brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid);
3801 for (i = 0; i < WLAN_PMKID_LEN; i += 4)
3802 brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i],
3803 pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2],
3804 pmk[npmk].pmkid[i + 3]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003805
Hante Meuleman6c404f32015-12-10 13:43:03 +01003806 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003807
Arend van Sprield96b8012012-12-05 15:26:02 +01003808 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003809 return err;
3810}
3811
3812static s32
3813brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman6c404f32015-12-10 13:43:03 +01003814 struct cfg80211_pmksa *pmksa)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003815{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003816 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003817 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003818 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3819 s32 err;
3820 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003821
Arend van Sprield96b8012012-12-05 15:26:02 +01003822 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003823 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003824 return -EIO;
3825
Hante Meuleman6c404f32015-12-10 13:43:03 +01003826 brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", &pmksa->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003827
Hante Meuleman6c404f32015-12-10 13:43:03 +01003828 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3829 for (i = 0; i < npmk; i++)
3830 if (!memcmp(&pmksa->bssid, &pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003831 break;
3832
Hante Meuleman6c404f32015-12-10 13:43:03 +01003833 if ((npmk > 0) && (i < npmk)) {
3834 for (; i < (npmk - 1); i++) {
3835 memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN);
3836 memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003837 WLAN_PMKID_LEN);
3838 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003839 memset(&pmk[i], 0, sizeof(*pmk));
3840 cfg->pmk_list.npmk = cpu_to_le32(npmk - 1);
3841 } else {
3842 brcmf_err("Cache entry not found\n");
3843 return -EINVAL;
3844 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003845
Hante Meuleman6c404f32015-12-10 13:43:03 +01003846 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003847
Arend van Sprield96b8012012-12-05 15:26:02 +01003848 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003849 return err;
3850
3851}
3852
3853static s32
3854brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3855{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003856 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003857 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003858 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003859
Arend van Sprield96b8012012-12-05 15:26:02 +01003860 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003861 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003862 return -EIO;
3863
Hante Meuleman6c404f32015-12-10 13:43:03 +01003864 memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list));
3865 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003866
Arend van Sprield96b8012012-12-05 15:26:02 +01003867 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003868 return err;
3869
3870}
3871
Hante Meuleman1f170112013-02-06 18:40:38 +01003872static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003873{
3874 s32 err;
3875
3876 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003877 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003878 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003879 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003880 return err;
3881 }
3882 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003883 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003884 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003885 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003886 return err;
3887 }
3888 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003889 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003890 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003891 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003892 return err;
3893 }
3894
3895 return 0;
3896}
3897
3898static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3899{
3900 if (is_rsn_ie)
3901 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3902
3903 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3904}
3905
3906static s32
Hante Meulemana44aa402014-12-03 21:05:33 +01003907brcmf_configure_wpaie(struct brcmf_if *ifp,
Johannes Berg4b5800f2014-01-15 14:55:59 +01003908 const struct brcmf_vs_tlv *wpa_ie,
3909 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003910{
3911 u32 auth = 0; /* d11 open authentication */
3912 u16 count;
3913 s32 err = 0;
Hante Meuleman240d61a2016-02-17 11:27:10 +01003914 s32 len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003915 u32 i;
3916 u32 wsec;
3917 u32 pval = 0;
3918 u32 gval = 0;
3919 u32 wpa_auth = 0;
3920 u32 offset;
3921 u8 *data;
3922 u16 rsn_cap;
3923 u32 wme_bss_disable;
Hante Meuleman240d61a2016-02-17 11:27:10 +01003924 u32 mfp;
Hante Meuleman1a873342012-09-27 14:17:54 +02003925
Arend van Sprield96b8012012-12-05 15:26:02 +01003926 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003927 if (wpa_ie == NULL)
3928 goto exit;
3929
3930 len = wpa_ie->len + TLV_HDR_LEN;
3931 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003932 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003933 if (!is_rsn_ie)
3934 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003935 else
3936 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003937
3938 /* check for multicast cipher suite */
3939 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3940 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003941 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003942 goto exit;
3943 }
3944
3945 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3946 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003947 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003948 goto exit;
3949 }
3950 offset += TLV_OUI_LEN;
3951
3952 /* pick up multicast cipher */
3953 switch (data[offset]) {
3954 case WPA_CIPHER_NONE:
3955 gval = 0;
3956 break;
3957 case WPA_CIPHER_WEP_40:
3958 case WPA_CIPHER_WEP_104:
3959 gval = WEP_ENABLED;
3960 break;
3961 case WPA_CIPHER_TKIP:
3962 gval = TKIP_ENABLED;
3963 break;
3964 case WPA_CIPHER_AES_CCM:
3965 gval = AES_ENABLED;
3966 break;
3967 default:
3968 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003969 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003970 goto exit;
3971 }
3972
3973 offset++;
3974 /* walk thru unicast cipher list and pick up what we recognize */
3975 count = data[offset] + (data[offset + 1] << 8);
3976 offset += WPA_IE_SUITE_COUNT_LEN;
3977 /* Check for unicast suite(s) */
3978 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3979 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003980 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003981 goto exit;
3982 }
3983 for (i = 0; i < count; i++) {
3984 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3985 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003986 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003987 goto exit;
3988 }
3989 offset += TLV_OUI_LEN;
3990 switch (data[offset]) {
3991 case WPA_CIPHER_NONE:
3992 break;
3993 case WPA_CIPHER_WEP_40:
3994 case WPA_CIPHER_WEP_104:
3995 pval |= WEP_ENABLED;
3996 break;
3997 case WPA_CIPHER_TKIP:
3998 pval |= TKIP_ENABLED;
3999 break;
4000 case WPA_CIPHER_AES_CCM:
4001 pval |= AES_ENABLED;
4002 break;
4003 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01004004 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004005 }
4006 offset++;
4007 }
4008 /* walk thru auth management suite list and pick up what we recognize */
4009 count = data[offset] + (data[offset + 1] << 8);
4010 offset += WPA_IE_SUITE_COUNT_LEN;
4011 /* Check for auth key management suite(s) */
4012 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
4013 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01004014 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004015 goto exit;
4016 }
4017 for (i = 0; i < count; i++) {
4018 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
4019 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01004020 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004021 goto exit;
4022 }
4023 offset += TLV_OUI_LEN;
4024 switch (data[offset]) {
4025 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01004026 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004027 wpa_auth |= WPA_AUTH_NONE;
4028 break;
4029 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01004030 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004031 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
4032 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
4033 break;
4034 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01004035 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004036 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
4037 (wpa_auth |= WPA_AUTH_PSK);
4038 break;
Hante Meuleman240d61a2016-02-17 11:27:10 +01004039 case RSN_AKM_SHA256_PSK:
4040 brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n");
4041 wpa_auth |= WPA2_AUTH_PSK_SHA256;
4042 break;
4043 case RSN_AKM_SHA256_1X:
4044 brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n");
4045 wpa_auth |= WPA2_AUTH_1X_SHA256;
4046 break;
Hante Meuleman1a873342012-09-27 14:17:54 +02004047 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01004048 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004049 }
4050 offset++;
4051 }
4052
Hante Meuleman240d61a2016-02-17 11:27:10 +01004053 mfp = BRCMF_MFP_NONE;
Hante Meuleman1a873342012-09-27 14:17:54 +02004054 if (is_rsn_ie) {
4055 wme_bss_disable = 1;
4056 if ((offset + RSN_CAP_LEN) <= len) {
4057 rsn_cap = data[offset] + (data[offset + 1] << 8);
4058 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
4059 wme_bss_disable = 0;
Hante Meuleman240d61a2016-02-17 11:27:10 +01004060 if (rsn_cap & RSN_CAP_MFPR_MASK) {
4061 brcmf_dbg(TRACE, "MFP Required\n");
4062 mfp = BRCMF_MFP_REQUIRED;
4063 /* Firmware only supports mfp required in
4064 * combination with WPA2_AUTH_PSK_SHA256 or
4065 * WPA2_AUTH_1X_SHA256.
4066 */
4067 if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 |
4068 WPA2_AUTH_1X_SHA256))) {
4069 err = -EINVAL;
4070 goto exit;
4071 }
4072 /* Firmware has requirement that WPA2_AUTH_PSK/
4073 * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI
4074 * is to be included in the rsn ie.
4075 */
4076 if (wpa_auth & WPA2_AUTH_PSK_SHA256)
4077 wpa_auth |= WPA2_AUTH_PSK;
4078 else if (wpa_auth & WPA2_AUTH_1X_SHA256)
4079 wpa_auth |= WPA2_AUTH_UNSPECIFIED;
4080 } else if (rsn_cap & RSN_CAP_MFPC_MASK) {
4081 brcmf_dbg(TRACE, "MFP Capable\n");
4082 mfp = BRCMF_MFP_CAPABLE;
4083 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004084 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01004085 offset += RSN_CAP_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02004086 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07004087 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004088 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02004089 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004090 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004091 goto exit;
4092 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01004093
4094 /* Skip PMKID cnt as it is know to be 0 for AP. */
4095 offset += RSN_PMKID_COUNT_LEN;
4096
4097 /* See if there is BIP wpa suite left for MFP */
4098 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) &&
4099 ((offset + WPA_IE_MIN_OUI_LEN) <= len)) {
4100 err = brcmf_fil_bsscfg_data_set(ifp, "bip",
4101 &data[offset],
4102 WPA_IE_MIN_OUI_LEN);
4103 if (err < 0) {
4104 brcmf_err("bip error %d\n", err);
4105 goto exit;
4106 }
4107 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004108 }
4109 /* FOR WPS , set SES_OW_ENABLED */
4110 wsec = (pval | gval | SES_OW_ENABLED);
4111
4112 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07004113 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02004114 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004115 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004116 goto exit;
4117 }
4118 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07004119 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004120 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004121 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004122 goto exit;
4123 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01004124 /* Configure MFP, this needs to go after wsec otherwise the wsec command
4125 * will overwrite the values set by MFP
4126 */
4127 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) {
4128 err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp);
4129 if (err < 0) {
4130 brcmf_err("mfp error %d\n", err);
4131 goto exit;
4132 }
4133 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004134 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07004135 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02004136 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004137 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004138 goto exit;
4139 }
4140
4141exit:
4142 return err;
4143}
4144
4145static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08004146brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02004147 struct parsed_vndr_ies *vndr_ies)
4148{
Hante Meuleman1a873342012-09-27 14:17:54 +02004149 struct brcmf_vs_tlv *vndrie;
4150 struct brcmf_tlv *ie;
4151 struct parsed_vndr_ie_info *parsed_info;
4152 s32 remaining_len;
4153
4154 remaining_len = (s32)vndr_ie_len;
4155 memset(vndr_ies, 0, sizeof(*vndr_ies));
4156
4157 ie = (struct brcmf_tlv *)vndr_ie_buf;
4158 while (ie) {
4159 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
4160 goto next;
4161 vndrie = (struct brcmf_vs_tlv *)ie;
4162 /* len should be bigger than OUI length + one */
4163 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004164 brcmf_err("invalid vndr ie. length is too small %d\n",
4165 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004166 goto next;
4167 }
4168 /* if wpa or wme ie, do not add ie */
4169 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
4170 ((vndrie->oui_type == WPA_OUI_TYPE) ||
4171 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004172 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004173 goto next;
4174 }
4175
4176 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
4177
4178 /* save vndr ie information */
4179 parsed_info->ie_ptr = (char *)vndrie;
4180 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
4181 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
4182
4183 vndr_ies->count++;
4184
Arend van Sprield96b8012012-12-05 15:26:02 +01004185 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
4186 parsed_info->vndrie.oui[0],
4187 parsed_info->vndrie.oui[1],
4188 parsed_info->vndrie.oui[2],
4189 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02004190
Arend van Spriel9f440b72013-02-08 15:53:36 +01004191 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02004192 break;
4193next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004194 remaining_len -= (ie->len + TLV_HDR_LEN);
4195 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02004196 ie = NULL;
4197 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004198 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
4199 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02004200 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004201 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004202}
4203
4204static u32
4205brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
4206{
4207
Hante Meuleman1a873342012-09-27 14:17:54 +02004208 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
4209 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
4210
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304211 put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004212
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304213 put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004214
4215 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
4216
4217 return ie_len + VNDR_IE_HDR_SIZE;
4218}
4219
Arend van Spriel1332e262012-11-05 16:22:18 -08004220s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
4221 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02004222{
Arend van Spriel1332e262012-11-05 16:22:18 -08004223 struct brcmf_if *ifp;
4224 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004225 s32 err = 0;
4226 u8 *iovar_ie_buf;
4227 u8 *curr_ie_buf;
4228 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004229 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07004230 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004231 u32 del_add_ie_buf_len = 0;
4232 u32 total_ie_buf_len = 0;
4233 u32 parsed_ie_buf_len = 0;
4234 struct parsed_vndr_ies old_vndr_ies;
4235 struct parsed_vndr_ies new_vndr_ies;
4236 struct parsed_vndr_ie_info *vndrie_info;
4237 s32 i;
4238 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004239 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004240
Arend van Spriel1332e262012-11-05 16:22:18 -08004241 if (!vif)
4242 return -ENODEV;
4243 ifp = vif->ifp;
4244 saved_ie = &vif->saved_ie;
4245
Hante Meuleman37a869e2015-10-29 20:33:17 +01004246 brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
4247 pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02004248 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4249 if (!iovar_ie_buf)
4250 return -ENOMEM;
4251 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01004252 switch (pktflag) {
4253 case BRCMF_VNDR_IE_PRBREQ_FLAG:
4254 mgmt_ie_buf = saved_ie->probe_req_ie;
4255 mgmt_ie_len = &saved_ie->probe_req_ie_len;
4256 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
4257 break;
4258 case BRCMF_VNDR_IE_PRBRSP_FLAG:
4259 mgmt_ie_buf = saved_ie->probe_res_ie;
4260 mgmt_ie_len = &saved_ie->probe_res_ie_len;
4261 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
4262 break;
4263 case BRCMF_VNDR_IE_BEACON_FLAG:
4264 mgmt_ie_buf = saved_ie->beacon_ie;
4265 mgmt_ie_len = &saved_ie->beacon_ie_len;
4266 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
4267 break;
4268 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
4269 mgmt_ie_buf = saved_ie->assoc_req_ie;
4270 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
4271 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
4272 break;
4273 default:
4274 err = -EPERM;
4275 brcmf_err("not suitable type\n");
4276 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004277 }
4278
4279 if (vndr_ie_len > mgmt_ie_buf_len) {
4280 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01004281 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004282 goto exit;
4283 }
4284
4285 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
4286 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
4287 ptr = curr_ie_buf;
4288 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
4289 for (i = 0; i < new_vndr_ies.count; i++) {
4290 vndrie_info = &new_vndr_ies.ie_info[i];
4291 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
4292 vndrie_info->ie_len);
4293 parsed_ie_buf_len += vndrie_info->ie_len;
4294 }
4295 }
4296
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004297 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004298 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
4299 (memcmp(mgmt_ie_buf, curr_ie_buf,
4300 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004301 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004302 goto exit;
4303 }
4304
4305 /* parse old vndr_ie */
4306 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
4307
4308 /* make a command to delete old ie */
4309 for (i = 0; i < old_vndr_ies.count; i++) {
4310 vndrie_info = &old_vndr_ies.ie_info[i];
4311
Arend van Sprield96b8012012-12-05 15:26:02 +01004312 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
4313 vndrie_info->vndrie.id,
4314 vndrie_info->vndrie.len,
4315 vndrie_info->vndrie.oui[0],
4316 vndrie_info->vndrie.oui[1],
4317 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004318
4319 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4320 vndrie_info->ie_ptr,
4321 vndrie_info->ie_len,
4322 "del");
4323 curr_ie_buf += del_add_ie_buf_len;
4324 total_ie_buf_len += del_add_ie_buf_len;
4325 }
4326 }
4327
4328 *mgmt_ie_len = 0;
4329 /* Add if there is any extra IE */
4330 if (mgmt_ie_buf && parsed_ie_buf_len) {
4331 ptr = mgmt_ie_buf;
4332
4333 remained_buf_len = mgmt_ie_buf_len;
4334
4335 /* make a command to add new ie */
4336 for (i = 0; i < new_vndr_ies.count; i++) {
4337 vndrie_info = &new_vndr_ies.ie_info[i];
4338
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004339 /* verify remained buf size before copy data */
4340 if (remained_buf_len < (vndrie_info->vndrie.len +
4341 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004342 brcmf_err("no space in mgmt_ie_buf: len left %d",
4343 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004344 break;
4345 }
4346 remained_buf_len -= (vndrie_info->ie_len +
4347 VNDR_IE_VSIE_OFFSET);
4348
Arend van Sprield96b8012012-12-05 15:26:02 +01004349 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
4350 vndrie_info->vndrie.id,
4351 vndrie_info->vndrie.len,
4352 vndrie_info->vndrie.oui[0],
4353 vndrie_info->vndrie.oui[1],
4354 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004355
4356 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4357 vndrie_info->ie_ptr,
4358 vndrie_info->ie_len,
4359 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02004360
4361 /* save the parsed IE in wl struct */
4362 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
4363 vndrie_info->ie_len);
4364 *mgmt_ie_len += vndrie_info->ie_len;
4365
4366 curr_ie_buf += del_add_ie_buf_len;
4367 total_ie_buf_len += del_add_ie_buf_len;
4368 }
4369 }
4370 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004371 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004372 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004373 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004374 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004375 }
4376
4377exit:
4378 kfree(iovar_ie_buf);
4379 return err;
4380}
4381
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004382s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
4383{
4384 s32 pktflags[] = {
4385 BRCMF_VNDR_IE_PRBREQ_FLAG,
4386 BRCMF_VNDR_IE_PRBRSP_FLAG,
4387 BRCMF_VNDR_IE_BEACON_FLAG
4388 };
4389 int i;
4390
4391 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
4392 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
4393
4394 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
4395 return 0;
4396}
4397
Hante Meuleman1a873342012-09-27 14:17:54 +02004398static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01004399brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
4400 struct cfg80211_beacon_data *beacon)
4401{
4402 s32 err;
4403
4404 /* Set Beacon IEs to FW */
4405 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
4406 beacon->tail, beacon->tail_len);
4407 if (err) {
4408 brcmf_err("Set Beacon IE Failed\n");
4409 return err;
4410 }
4411 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
4412
4413 /* Set Probe Response IEs to FW */
4414 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
4415 beacon->proberesp_ies,
4416 beacon->proberesp_ies_len);
4417 if (err)
4418 brcmf_err("Set Probe Resp IE Failed\n");
4419 else
4420 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
4421
4422 return err;
4423}
4424
4425static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02004426brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
4427 struct cfg80211_ap_settings *settings)
4428{
4429 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02004430 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07004431 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01004432 const struct brcmf_tlv *ssid_ie;
Arend van Spriel98027762014-12-21 12:43:53 +01004433 const struct brcmf_tlv *country_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004434 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02004435 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01004436 const struct brcmf_tlv *rsn_ie;
4437 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004438 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01004439 enum nl80211_iftype dev_role;
4440 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02004441 u16 chanspec;
Hante Meulemana44aa402014-12-03 21:05:33 +01004442 bool mbss;
Arend van Spriel98027762014-12-21 12:43:53 +01004443 int is_11d;
Hante Meuleman1a873342012-09-27 14:17:54 +02004444
Arend van Spriel06c01582014-05-12 10:47:37 +02004445 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
4446 settings->chandef.chan->hw_value,
4447 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02004448 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01004449 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
4450 settings->ssid, settings->ssid_len, settings->auth_type,
4451 settings->inactivity_timeout);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004452 dev_role = ifp->vif->wdev.iftype;
Hante Meulemana44aa402014-12-03 21:05:33 +01004453 mbss = ifp->vif->mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02004454
Arend van Spriel98027762014-12-21 12:43:53 +01004455 /* store current 11d setting */
4456 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d);
4457 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4458 settings->beacon.tail_len,
4459 WLAN_EID_COUNTRY);
4460 is_11d = country_ie ? 1 : 0;
4461
Hante Meuleman1a873342012-09-27 14:17:54 +02004462 memset(&ssid_le, 0, sizeof(ssid_le));
4463 if (settings->ssid == NULL || settings->ssid_len == 0) {
4464 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
4465 ssid_ie = brcmf_parse_tlvs(
4466 (u8 *)&settings->beacon.head[ie_offset],
4467 settings->beacon.head_len - ie_offset,
4468 WLAN_EID_SSID);
4469 if (!ssid_ie)
4470 return -EINVAL;
4471
4472 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
4473 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01004474 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02004475 } else {
4476 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
4477 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
4478 }
4479
Hante Meulemana44aa402014-12-03 21:05:33 +01004480 if (!mbss) {
4481 brcmf_set_mpc(ifp, 0);
Franky Lin52f22fb2016-02-17 11:26:55 +01004482 brcmf_configure_arp_nd_offload(ifp, false);
Hante Meulemana44aa402014-12-03 21:05:33 +01004483 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004484
4485 /* find the RSN_IE */
4486 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4487 settings->beacon.tail_len, WLAN_EID_RSN);
4488
4489 /* find the WPA_IE */
4490 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
4491 settings->beacon.tail_len);
4492
Hante Meuleman1a873342012-09-27 14:17:54 +02004493 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004494 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004495 if (wpa_ie != NULL) {
4496 /* WPA IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004497 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02004498 if (err < 0)
4499 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004500 } else {
Hante Meulemana44aa402014-12-03 21:05:33 +01004501 struct brcmf_vs_tlv *tmp_ie;
4502
4503 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
4504
Hante Meuleman1a873342012-09-27 14:17:54 +02004505 /* RSN IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004506 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004507 if (err < 0)
4508 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004509 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004510 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01004511 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01004512 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02004513 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004514
Hante Meulemana0f07952013-02-08 15:53:47 +01004515 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02004516
Hante Meulemana44aa402014-12-03 21:05:33 +01004517 if (!mbss) {
4518 chanspec = chandef_to_chanspec(&cfg->d11inf,
4519 &settings->chandef);
4520 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004521 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004522 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4523 chanspec, err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004524 goto exit;
4525 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004526
Arend van Spriel98027762014-12-21 12:43:53 +01004527 if (is_11d != ifp->vif->is_11d) {
4528 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4529 is_11d);
4530 if (err < 0) {
4531 brcmf_err("Regulatory Set Error, %d\n", err);
4532 goto exit;
4533 }
4534 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004535 if (settings->beacon_interval) {
4536 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
4537 settings->beacon_interval);
4538 if (err < 0) {
4539 brcmf_err("Beacon Interval Set Error, %d\n",
4540 err);
4541 goto exit;
4542 }
4543 }
4544 if (settings->dtim_period) {
4545 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
4546 settings->dtim_period);
4547 if (err < 0) {
4548 brcmf_err("DTIM Interval Set Error, %d\n", err);
4549 goto exit;
4550 }
4551 }
4552
Hante Meuleman8abffd82015-10-29 20:33:16 +01004553 if ((dev_role == NL80211_IFTYPE_AP) &&
4554 ((ifp->ifidx == 0) ||
4555 !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004556 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4557 if (err < 0) {
4558 brcmf_err("BRCMF_C_DOWN error %d\n", err);
4559 goto exit;
4560 }
4561 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
4562 }
4563
4564 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02004565 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004566 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004567 goto exit;
4568 }
Arend van Spriel98027762014-12-21 12:43:53 +01004569 } else if (WARN_ON(is_11d != ifp->vif->is_11d)) {
4570 /* Multiple-BSS should use same 11d configuration */
4571 err = -EINVAL;
4572 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004573 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004574 if (dev_role == NL80211_IFTYPE_AP) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004575 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
4576 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
4577
Hante Meulemana0f07952013-02-08 15:53:47 +01004578 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
4579 if (err < 0) {
4580 brcmf_err("setting AP mode failed %d\n", err);
4581 goto exit;
4582 }
4583 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4584 if (err < 0) {
4585 brcmf_err("BRCMF_C_UP error (%d)\n", err);
4586 goto exit;
4587 }
Hante Meuleman118eb302014-12-21 12:43:49 +01004588 /* On DOWN the firmware removes the WEP keys, reconfigure
4589 * them if they were set.
4590 */
4591 brcmf_cfg80211_reconfigure_wep(ifp);
Hante Meulemana0f07952013-02-08 15:53:47 +01004592
4593 memset(&join_params, 0, sizeof(join_params));
4594 /* join parameters starts with ssid */
4595 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
4596 /* create softap */
4597 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4598 &join_params, sizeof(join_params));
4599 if (err < 0) {
4600 brcmf_err("SET SSID error (%d)\n", err);
4601 goto exit;
4602 }
4603 brcmf_dbg(TRACE, "AP mode configuration complete\n");
4604 } else {
4605 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
4606 sizeof(ssid_le));
4607 if (err < 0) {
4608 brcmf_err("setting ssid failed %d\n", err);
4609 goto exit;
4610 }
Hante Meuleman37a869e2015-10-29 20:33:17 +01004611 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meulemana0f07952013-02-08 15:53:47 +01004612 bss_enable.enable = cpu_to_le32(1);
4613 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4614 sizeof(bss_enable));
4615 if (err < 0) {
4616 brcmf_err("bss_enable config failed %d\n", err);
4617 goto exit;
4618 }
4619
4620 brcmf_dbg(TRACE, "GO mode configuration complete\n");
4621 }
Arend van Sprielc1179032012-10-22 13:55:33 -07004622 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004623 brcmf_net_setcarrier(ifp, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004624
4625exit:
Hante Meulemana44aa402014-12-03 21:05:33 +01004626 if ((err) && (!mbss)) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02004627 brcmf_set_mpc(ifp, 1);
Franky Lin52f22fb2016-02-17 11:26:55 +01004628 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meulemanb3657452013-05-27 21:09:53 +02004629 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004630 return err;
4631}
4632
4633static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
4634{
Arend van Sprielc1179032012-10-22 13:55:33 -07004635 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004636 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01004637 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02004638 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02004639
Arend van Sprield96b8012012-12-05 15:26:02 +01004640 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004641
Hante Meuleman426d0a52013-02-08 15:53:53 +01004642 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004643 /* Due to most likely deauths outstanding we sleep */
4644 /* first to make sure they get processed by fw. */
4645 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004646
Hante Meulemana44aa402014-12-03 21:05:33 +01004647 if (ifp->vif->mbss) {
4648 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4649 return err;
4650 }
4651
Hante Meuleman5c33a942013-04-02 21:06:18 +02004652 memset(&join_params, 0, sizeof(join_params));
4653 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4654 &join_params, sizeof(join_params));
4655 if (err < 0)
4656 brcmf_err("SET SSID error (%d)\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004657 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004658 if (err < 0)
Hante Meulemana44aa402014-12-03 21:05:33 +01004659 brcmf_err("BRCMF_C_DOWN error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004660 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4661 if (err < 0)
4662 brcmf_err("setting AP mode failed %d\n", err);
4663 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4664 if (err < 0)
4665 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004666 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
4667 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
Arend van Spriel98027762014-12-21 12:43:53 +01004668 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4669 ifp->vif->is_11d);
4670 if (err < 0)
4671 brcmf_err("restoring REGULATORY setting failed %d\n",
4672 err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004673 /* Bring device back up so it can be used again */
4674 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4675 if (err < 0)
4676 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004677 } else {
Hante Meuleman37a869e2015-10-29 20:33:17 +01004678 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004679 bss_enable.enable = cpu_to_le32(0);
4680 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4681 sizeof(bss_enable));
4682 if (err < 0)
4683 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004684 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02004685 brcmf_set_mpc(ifp, 1);
Franky Lin52f22fb2016-02-17 11:26:55 +01004686 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004687 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004688 brcmf_net_setcarrier(ifp, false);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004689
Hante Meuleman1a873342012-09-27 14:17:54 +02004690 return err;
4691}
4692
Hante Meulemana0f07952013-02-08 15:53:47 +01004693static s32
4694brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4695 struct cfg80211_beacon_data *info)
4696{
Hante Meulemana0f07952013-02-08 15:53:47 +01004697 struct brcmf_if *ifp = netdev_priv(ndev);
4698 s32 err;
4699
4700 brcmf_dbg(TRACE, "Enter\n");
4701
Hante Meulemana0f07952013-02-08 15:53:47 +01004702 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4703
4704 return err;
4705}
4706
Hante Meuleman1a873342012-09-27 14:17:54 +02004707static int
4708brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03004709 struct station_del_parameters *params)
Hante Meuleman1a873342012-09-27 14:17:54 +02004710{
Hante Meulemana0f07952013-02-08 15:53:47 +01004711 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02004712 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004713 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02004714 s32 err;
4715
Jouni Malinen89c771e2014-10-10 20:52:40 +03004716 if (!params->mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02004717 return -EFAULT;
4718
Jouni Malinen89c771e2014-10-10 20:52:40 +03004719 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02004720
Hante Meulemana0f07952013-02-08 15:53:47 +01004721 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4722 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07004723 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02004724 return -EIO;
4725
Jouni Malinen89c771e2014-10-10 20:52:40 +03004726 memcpy(&scbval.ea, params->mac, ETH_ALEN);
Rafał Miłeckiba8b6ae2015-02-08 11:51:47 +01004727 scbval.val = cpu_to_le32(params->reason_code);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004728 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004729 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02004730 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004731 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01004732
Arend van Sprield96b8012012-12-05 15:26:02 +01004733 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004734 return err;
4735}
4736
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004737static int
4738brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
4739 const u8 *mac, struct station_parameters *params)
4740{
4741 struct brcmf_if *ifp = netdev_priv(ndev);
4742 s32 err;
4743
4744 brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
4745 params->sta_flags_mask, params->sta_flags_set);
4746
4747 /* Ignore all 00 MAC */
4748 if (is_zero_ether_addr(mac))
4749 return 0;
4750
4751 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4752 return 0;
4753
4754 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
4755 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
4756 (void *)mac, ETH_ALEN);
4757 else
4758 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
4759 (void *)mac, ETH_ALEN);
4760 if (err < 0)
4761 brcmf_err("Setting SCB (de-)authorize failed, %d\n", err);
4762
4763 return err;
4764}
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004765
4766static void
4767brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4768 struct wireless_dev *wdev,
4769 u16 frame_type, bool reg)
4770{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004771 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004772 u16 mgmt_type;
4773
4774 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4775
4776 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004777 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004778 if (reg)
4779 vif->mgmt_rx_reg |= BIT(mgmt_type);
4780 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01004781 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004782}
4783
4784
4785static int
4786brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004787 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004788{
4789 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004790 struct ieee80211_channel *chan = params->chan;
4791 const u8 *buf = params->buf;
4792 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004793 const struct ieee80211_mgmt *mgmt;
4794 struct brcmf_cfg80211_vif *vif;
4795 s32 err = 0;
4796 s32 ie_offset;
4797 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004798 struct brcmf_fil_action_frame_le *action_frame;
4799 struct brcmf_fil_af_params_le *af_params;
4800 bool ack;
4801 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004802 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004803
4804 brcmf_dbg(TRACE, "Enter\n");
4805
4806 *cookie = 0;
4807
4808 mgmt = (const struct ieee80211_mgmt *)buf;
4809
Hante Meulemana0f07952013-02-08 15:53:47 +01004810 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4811 brcmf_err("Driver only allows MGMT packet type\n");
4812 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004813 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004814
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004815 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4816
Hante Meulemana0f07952013-02-08 15:53:47 +01004817 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4818 /* Right now the only reason to get a probe response */
4819 /* is for p2p listen response or for p2p GO from */
4820 /* wpa_supplicant. Unfortunately the probe is send */
4821 /* on primary ndev, while dongle wants it on the p2p */
4822 /* vif. Since this is only reason for a probe */
4823 /* response to be sent, the vif is taken from cfg. */
4824 /* If ever desired to send proberesp for non p2p */
4825 /* response then data should be checked for */
4826 /* "DIRECT-". Note in future supplicant will take */
4827 /* dedicated p2p wdev to do this and then this 'hack'*/
4828 /* is not needed anymore. */
4829 ie_offset = DOT11_MGMT_HDR_LEN +
4830 DOT11_BCN_PRB_FIXED_LEN;
4831 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004832 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4833 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4834 err = brcmf_vif_set_mgmt_ie(vif,
4835 BRCMF_VNDR_IE_PRBRSP_FLAG,
4836 &buf[ie_offset],
4837 ie_len);
4838 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4839 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004840 } else if (ieee80211_is_action(mgmt->frame_control)) {
4841 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4842 if (af_params == NULL) {
4843 brcmf_err("unable to allocate frame\n");
4844 err = -ENOMEM;
4845 goto exit;
4846 }
4847 action_frame = &af_params->action_frame;
4848 /* Add the packet Id */
4849 action_frame->packet_id = cpu_to_le32(*cookie);
4850 /* Add BSSID */
4851 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4852 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4853 /* Add the length exepted for 802.11 header */
4854 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004855 /* Add the channel. Use the one specified as parameter if any or
4856 * the current one (got from the firmware) otherwise
4857 */
4858 if (chan)
4859 freq = chan->center_freq;
4860 else
4861 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4862 &freq);
4863 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004864 af_params->channel = cpu_to_le32(chan_nr);
4865
4866 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4867 le16_to_cpu(action_frame->len));
4868
4869 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004870 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004871
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004872 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004873 af_params);
4874
4875 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4876 GFP_KERNEL);
4877 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004878 } else {
4879 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4880 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4881 }
4882
Hante Meuleman18e2f612013-02-08 15:53:49 +01004883exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004884 return err;
4885}
4886
4887
4888static int
4889brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4890 struct wireless_dev *wdev,
4891 u64 cookie)
4892{
4893 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4894 struct brcmf_cfg80211_vif *vif;
4895 int err = 0;
4896
4897 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4898
4899 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4900 if (vif == NULL) {
4901 brcmf_err("No p2p device available for probe response\n");
4902 err = -ENODEV;
4903 goto exit;
4904 }
4905 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4906exit:
4907 return err;
4908}
4909
Piotr Haber61730d42013-04-23 12:53:12 +02004910static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4911 struct wireless_dev *wdev,
4912 enum nl80211_crit_proto_id proto,
4913 u16 duration)
4914{
4915 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4916 struct brcmf_cfg80211_vif *vif;
4917
4918 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4919
4920 /* only DHCP support for now */
4921 if (proto != NL80211_CRIT_PROTO_DHCP)
4922 return -EINVAL;
4923
4924 /* suppress and abort scanning */
4925 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4926 brcmf_abort_scanning(cfg);
4927
4928 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4929}
4930
4931static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4932 struct wireless_dev *wdev)
4933{
4934 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4935 struct brcmf_cfg80211_vif *vif;
4936
4937 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4938
4939 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4940 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4941}
4942
Hante Meuleman70b7d942014-07-30 13:20:07 +02004943static s32
4944brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4945 const struct brcmf_event_msg *e, void *data)
4946{
4947 switch (e->reason) {
4948 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4949 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4950 break;
4951 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4952 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4953 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4954 break;
4955 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4956 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4957 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4958 break;
4959 }
4960
4961 return 0;
4962}
4963
Arend van Spriel89c2f382013-08-10 12:27:25 +02004964static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4965{
4966 int ret;
4967
4968 switch (oper) {
4969 case NL80211_TDLS_DISCOVERY_REQ:
4970 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4971 break;
4972 case NL80211_TDLS_SETUP:
4973 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4974 break;
4975 case NL80211_TDLS_TEARDOWN:
4976 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4977 break;
4978 default:
4979 brcmf_err("unsupported operation: %d\n", oper);
4980 ret = -EOPNOTSUPP;
4981 }
4982 return ret;
4983}
4984
4985static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004986 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004987 enum nl80211_tdls_operation oper)
4988{
4989 struct brcmf_if *ifp;
4990 struct brcmf_tdls_iovar_le info;
4991 int ret = 0;
4992
4993 ret = brcmf_convert_nl80211_tdls_oper(oper);
4994 if (ret < 0)
4995 return ret;
4996
4997 ifp = netdev_priv(ndev);
4998 memset(&info, 0, sizeof(info));
4999 info.mode = (u8)ret;
5000 if (peer)
5001 memcpy(info.ea, peer, ETH_ALEN);
5002
5003 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
5004 &info, sizeof(info));
5005 if (ret < 0)
5006 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
5007
5008 return ret;
5009}
5010
Hante Meuleman5c22fb82016-02-17 11:27:03 +01005011#ifdef CONFIG_PM
5012static int
5013brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev,
5014 struct cfg80211_gtk_rekey_data *gtk)
5015{
5016 struct brcmf_if *ifp = netdev_priv(ndev);
5017 struct brcmf_gtk_keyinfo_le gtk_le;
5018 int ret;
5019
5020 brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx);
5021
5022 memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck));
5023 memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek));
5024 memcpy(gtk_le.replay_counter, gtk->replay_ctr,
5025 sizeof(gtk_le.replay_counter));
5026
5027 ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", &gtk_le,
5028 sizeof(gtk_le));
5029 if (ret < 0)
5030 brcmf_err("gtk_key_info iovar failed: ret=%d\n", ret);
5031
5032 return ret;
5033}
5034#endif
5035
5036static struct cfg80211_ops brcmf_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01005037 .add_virtual_intf = brcmf_cfg80211_add_iface,
5038 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005039 .change_virtual_intf = brcmf_cfg80211_change_iface,
5040 .scan = brcmf_cfg80211_scan,
5041 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
5042 .join_ibss = brcmf_cfg80211_join_ibss,
5043 .leave_ibss = brcmf_cfg80211_leave_ibss,
5044 .get_station = brcmf_cfg80211_get_station,
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02005045 .dump_station = brcmf_cfg80211_dump_station,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005046 .set_tx_power = brcmf_cfg80211_set_tx_power,
5047 .get_tx_power = brcmf_cfg80211_get_tx_power,
5048 .add_key = brcmf_cfg80211_add_key,
5049 .del_key = brcmf_cfg80211_del_key,
5050 .get_key = brcmf_cfg80211_get_key,
5051 .set_default_key = brcmf_cfg80211_config_default_key,
5052 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
5053 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005054 .connect = brcmf_cfg80211_connect,
5055 .disconnect = brcmf_cfg80211_disconnect,
5056 .suspend = brcmf_cfg80211_suspend,
5057 .resume = brcmf_cfg80211_resume,
5058 .set_pmksa = brcmf_cfg80211_set_pmksa,
5059 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02005060 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02005061 .start_ap = brcmf_cfg80211_start_ap,
5062 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01005063 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02005064 .del_station = brcmf_cfg80211_del_station,
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01005065 .change_station = brcmf_cfg80211_change_station,
Arend van Spriele5806072012-09-19 22:21:08 +02005066 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
5067 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005068 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
5069 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
5070 .remain_on_channel = brcmf_p2p_remain_on_channel,
5071 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02005072 .start_p2p_device = brcmf_p2p_start_device,
5073 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02005074 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
5075 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02005076 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005077};
5078
Arend van Spriel3eacf862012-10-22 13:55:30 -07005079struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01005080 enum nl80211_iftype type,
5081 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005082{
Hante Meulemana44aa402014-12-03 21:05:33 +01005083 struct brcmf_cfg80211_vif *vif_walk;
Arend van Spriel3eacf862012-10-22 13:55:30 -07005084 struct brcmf_cfg80211_vif *vif;
Hante Meulemana44aa402014-12-03 21:05:33 +01005085 bool mbss;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005086
Arend van Spriel33a6b152013-02-08 15:53:39 +01005087 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01005088 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07005089 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
5090 if (!vif)
5091 return ERR_PTR(-ENOMEM);
5092
5093 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005094 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07005095
Arend van Spriel3eacf862012-10-22 13:55:30 -07005096 vif->pm_block = pm_block;
Arend van Spriel3eacf862012-10-22 13:55:30 -07005097
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07005098 brcmf_init_prof(&vif->profile);
5099
Hante Meulemana44aa402014-12-03 21:05:33 +01005100 if (type == NL80211_IFTYPE_AP) {
5101 mbss = false;
5102 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
5103 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
5104 mbss = true;
5105 break;
5106 }
5107 }
5108 vif->mbss = mbss;
5109 }
5110
Arend van Spriel3eacf862012-10-22 13:55:30 -07005111 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07005112 return vif;
5113}
5114
Arend van Spriel427dec52014-01-06 12:40:47 +01005115void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07005116{
Arend van Spriel3eacf862012-10-22 13:55:30 -07005117 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07005118 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005119}
5120
Arend van Spriel9df4d542014-01-06 12:40:49 +01005121void brcmf_cfg80211_free_netdev(struct net_device *ndev)
5122{
5123 struct brcmf_cfg80211_vif *vif;
5124 struct brcmf_if *ifp;
5125
5126 ifp = netdev_priv(ndev);
5127 vif = ifp->vif;
5128
Arend van Spriel95ef1232015-08-26 22:15:04 +02005129 if (vif)
5130 brcmf_free_vif(vif);
Arend van Spriel9df4d542014-01-06 12:40:49 +01005131 free_netdev(ndev);
5132}
5133
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005134static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005135{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005136 u32 event = e->event_code;
5137 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005138
5139 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005140 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005141 return true;
5142 }
5143
5144 return false;
5145}
5146
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005147static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005148{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005149 u32 event = e->event_code;
5150 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005151
Hante Meuleman68ca3952014-02-25 20:30:26 +01005152 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
5153 (event == BRCMF_E_DISASSOC_IND) ||
5154 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01005155 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005156 return true;
5157 }
5158 return false;
5159}
5160
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005161static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005162 const struct brcmf_event_msg *e)
5163{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005164 u32 event = e->event_code;
5165 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005166
5167 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005168 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
5169 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005170 return true;
5171 }
5172
5173 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005174 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005175 return true;
5176 }
5177
5178 return false;
5179}
5180
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005181static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005182{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005183 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005184
5185 kfree(conn_info->req_ie);
5186 conn_info->req_ie = NULL;
5187 conn_info->req_ie_len = 0;
5188 kfree(conn_info->resp_ie);
5189 conn_info->resp_ie = NULL;
5190 conn_info->resp_ie_len = 0;
5191}
5192
Hante Meuleman89286dc2013-02-08 15:53:46 +01005193static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
5194 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005195{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005196 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005197 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005198 u32 req_len;
5199 u32 resp_len;
5200 s32 err = 0;
5201
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005202 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005203
Arend van Sprielac24be62012-10-22 10:36:23 -07005204 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
5205 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005206 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005207 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005208 return err;
5209 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005210 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005211 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005212 req_len = le32_to_cpu(assoc_info->req_len);
5213 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005214 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005215 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005216 cfg->extra_buf,
5217 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005218 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005219 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005220 return err;
5221 }
5222 conn_info->req_ie_len = req_len;
5223 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005224 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005225 GFP_KERNEL);
5226 } else {
5227 conn_info->req_ie_len = 0;
5228 conn_info->req_ie = NULL;
5229 }
5230 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005231 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005232 cfg->extra_buf,
5233 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005234 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005235 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005236 return err;
5237 }
5238 conn_info->resp_ie_len = resp_len;
5239 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005240 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005241 GFP_KERNEL);
5242 } else {
5243 conn_info->resp_ie_len = 0;
5244 conn_info->resp_ie = NULL;
5245 }
Arend van Spriel16886732012-12-05 15:26:04 +01005246 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
5247 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005248
5249 return err;
5250}
5251
5252static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005253brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005254 struct net_device *ndev,
5255 const struct brcmf_event_msg *e)
5256{
Arend van Sprielc1179032012-10-22 13:55:33 -07005257 struct brcmf_if *ifp = netdev_priv(ndev);
5258 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005259 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
5260 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07005261 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005262 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07005263 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02005264 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005265 u32 freq;
5266 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07005267 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005268
Arend van Sprield96b8012012-12-05 15:26:02 +01005269 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005270
Hante Meuleman89286dc2013-02-08 15:53:46 +01005271 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005272 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005273 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005274
Franky Lina180b832012-10-10 11:13:09 -07005275 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
5276 if (buf == NULL) {
5277 err = -ENOMEM;
5278 goto done;
5279 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02005280
Franky Lina180b832012-10-10 11:13:09 -07005281 /* data sent to dongle has to be little endian */
5282 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07005283 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07005284 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07005285
5286 if (err)
5287 goto done;
5288
5289 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02005290 ch.chspec = le16_to_cpu(bi->chanspec);
5291 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005292
Franky Lin83cf17a2013-04-11 13:28:50 +02005293 if (ch.band == BRCMU_CHAN_BAND_2G)
Johannes Berg57fbcce2016-04-12 15:56:15 +02005294 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005295 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02005296 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005297
Franky Lin83cf17a2013-04-11 13:28:50 +02005298 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005299 notify_channel = ieee80211_get_channel(wiphy, freq);
5300
Franky Lina180b832012-10-10 11:13:09 -07005301done:
5302 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02005303 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005304 conn_info->req_ie, conn_info->req_ie_len,
5305 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005306 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005307
Arend van Sprielc1179032012-10-22 13:55:33 -07005308 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01005309 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005310 return err;
5311}
5312
5313static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005314brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005315 struct net_device *ndev, const struct brcmf_event_msg *e,
5316 bool completed)
5317{
Arend van Sprielc1179032012-10-22 13:55:33 -07005318 struct brcmf_if *ifp = netdev_priv(ndev);
5319 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005320 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005321
Arend van Sprield96b8012012-12-05 15:26:02 +01005322 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005323
Arend van Sprielc1179032012-10-22 13:55:33 -07005324 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5325 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02005326 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01005327 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005328 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005329 brcmf_update_bss_info(cfg, ifp);
5330 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5331 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005332 }
5333 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02005334 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005335 conn_info->req_ie,
5336 conn_info->req_ie_len,
5337 conn_info->resp_ie,
5338 conn_info->resp_ie_len,
5339 completed ? WLAN_STATUS_SUCCESS :
5340 WLAN_STATUS_AUTH_TIMEOUT,
5341 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005342 brcmf_dbg(CONN, "Report connect result - connection %s\n",
5343 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005344 }
Arend van Sprield96b8012012-12-05 15:26:02 +01005345 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005346 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005347}
5348
5349static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005350brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02005351 struct net_device *ndev,
5352 const struct brcmf_event_msg *e, void *data)
5353{
Hante Meulemana44aa402014-12-03 21:05:33 +01005354 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman7ee29602013-02-06 18:40:43 +01005355 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005356 u32 event = e->event_code;
5357 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02005358 struct station_info sinfo;
5359
Arend van Spriel16886732012-12-05 15:26:04 +01005360 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005361 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
5362 ndev != cfg_to_ndev(cfg)) {
5363 brcmf_dbg(CONN, "AP mode link down\n");
5364 complete(&cfg->vif_disabled);
Hante Meulemana44aa402014-12-03 21:05:33 +01005365 if (ifp->vif->mbss)
Arend van Sprielee6e3a32015-08-26 22:14:55 +02005366 brcmf_remove_interface(ifp);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005367 return 0;
5368 }
Hante Meuleman1a873342012-09-27 14:17:54 +02005369
Hante Meuleman1a873342012-09-27 14:17:54 +02005370 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01005371 (reason == BRCMF_E_STATUS_SUCCESS)) {
5372 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02005373 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005374 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02005375 return -EINVAL;
5376 }
5377 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005378 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02005379 generation++;
5380 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005381 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005382 } else if ((event == BRCMF_E_DISASSOC_IND) ||
5383 (event == BRCMF_E_DEAUTH_IND) ||
5384 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01005385 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005386 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01005387 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02005388}
5389
5390static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005391brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005392 const struct brcmf_event_msg *e, void *data)
5393{
Arend van Spriel19937322012-11-05 16:22:32 -08005394 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5395 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07005396 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005397 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005398 s32 err = 0;
5399
Hante Meuleman8851cce2014-07-30 13:20:02 +02005400 if ((e->event_code == BRCMF_E_DEAUTH) ||
5401 (e->event_code == BRCMF_E_DEAUTH_IND) ||
5402 (e->event_code == BRCMF_E_DISASSOC_IND) ||
5403 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
5404 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5405 }
5406
Arend van Spriel967fe2c2014-03-15 17:18:21 +01005407 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005408 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005409 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005410 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005411 if (brcmf_is_ibssmode(ifp->vif)) {
Hante Meulemanb0a79082015-12-10 13:43:07 +01005412 brcmf_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005413 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005414 memcpy(profile->bssid, e->addr, ETH_ALEN);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005415 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07005416 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5417 &ifp->vif->sme_state);
5418 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5419 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005420 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005421 brcmf_bss_connect_done(cfg, ndev, e, true);
Hante Meuleman92121e62015-10-08 20:33:21 +02005422 brcmf_net_setcarrier(ifp, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005423 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005424 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005425 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005426 brcmf_bss_connect_done(cfg, ndev, e, false);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01005427 brcmf_link_down(ifp->vif,
5428 brcmf_map_fw_linkdown_reason(e));
5429 brcmf_init_prof(ndev_to_prof(ndev));
5430 if (ndev != cfg_to_ndev(cfg))
5431 complete(&cfg->vif_disabled);
5432 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005433 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005434 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005435 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07005436 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5437 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005438 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005439 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005440 }
5441
5442 return err;
5443}
5444
5445static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005446brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005447 const struct brcmf_event_msg *e, void *data)
5448{
Arend van Spriel19937322012-11-05 16:22:32 -08005449 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005450 u32 event = e->event_code;
5451 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005452
5453 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07005454 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08005455 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005456 else
Arend van Spriel19937322012-11-05 16:22:32 -08005457 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005458 }
5459
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005460 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005461}
5462
5463static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005464brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005465 const struct brcmf_event_msg *e, void *data)
5466{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005467 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005468 enum nl80211_key_type key_type;
5469
5470 if (flags & BRCMF_EVENT_MSG_GROUP)
5471 key_type = NL80211_KEYTYPE_GROUP;
5472 else
5473 key_type = NL80211_KEYTYPE_PAIRWISE;
5474
Arend van Spriel19937322012-11-05 16:22:32 -08005475 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005476 NULL, GFP_KERNEL);
5477
5478 return 0;
5479}
5480
Arend van Sprield3c0b632013-02-08 15:53:37 +01005481static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
5482 const struct brcmf_event_msg *e, void *data)
5483{
5484 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5485 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
5486 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5487 struct brcmf_cfg80211_vif *vif;
5488
Hante Meuleman37a869e2015-10-29 20:33:17 +01005489 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
Arend van Sprield3c0b632013-02-08 15:53:37 +01005490 ifevent->action, ifevent->flags, ifevent->ifidx,
Hante Meuleman37a869e2015-10-29 20:33:17 +01005491 ifevent->bsscfgidx);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005492
Arend van Sprield3c0b632013-02-08 15:53:37 +01005493 mutex_lock(&event->vif_event_lock);
5494 event->action = ifevent->action;
5495 vif = event->vif;
5496
5497 switch (ifevent->action) {
5498 case BRCMF_E_IF_ADD:
5499 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08005500 if (!cfg->vif_event.vif) {
5501 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005502 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08005503 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005504
5505 ifp->vif = vif;
5506 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02005507 if (ifp->ndev) {
5508 vif->wdev.netdev = ifp->ndev;
5509 ifp->ndev->ieee80211_ptr = &vif->wdev;
5510 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
5511 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005512 mutex_unlock(&event->vif_event_lock);
5513 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01005514 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01005515
5516 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01005517 mutex_unlock(&event->vif_event_lock);
5518 /* event may not be upon user request */
5519 if (brcmf_cfg80211_vif_event_armed(cfg))
5520 wake_up(&event->vif_wq);
5521 return 0;
5522
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01005523 case BRCMF_E_IF_CHANGE:
5524 mutex_unlock(&event->vif_event_lock);
5525 wake_up(&event->vif_wq);
5526 return 0;
5527
Arend van Sprield3c0b632013-02-08 15:53:37 +01005528 default:
5529 mutex_unlock(&event->vif_event_lock);
5530 break;
5531 }
5532 return -EINVAL;
5533}
5534
Arend van Spriel5b435de2011-10-05 13:19:03 +02005535static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
5536{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005537 conf->frag_threshold = (u32)-1;
5538 conf->rts_threshold = (u32)-1;
5539 conf->retry_short = (u32)-1;
5540 conf->retry_long = (u32)-1;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005541}
5542
Arend van Spriel5c36b992012-11-14 18:46:05 -08005543static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005544{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005545 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
5546 brcmf_notify_connect_status);
5547 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
5548 brcmf_notify_connect_status);
5549 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
5550 brcmf_notify_connect_status);
5551 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
5552 brcmf_notify_connect_status);
5553 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
5554 brcmf_notify_connect_status);
5555 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
5556 brcmf_notify_connect_status);
5557 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
5558 brcmf_notify_roaming_status);
5559 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
5560 brcmf_notify_mic_status);
5561 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
5562 brcmf_notify_connect_status);
5563 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
5564 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005565 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
5566 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005567 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005568 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005569 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
5570 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01005571 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
5572 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01005573 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
5574 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005575 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
5576 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005577}
5578
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005579static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005580{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005581 kfree(cfg->conf);
5582 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005583 kfree(cfg->extra_buf);
5584 cfg->extra_buf = NULL;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005585 kfree(cfg->wowl.nd);
5586 cfg->wowl.nd = NULL;
5587 kfree(cfg->wowl.nd_info);
5588 cfg->wowl.nd_info = NULL;
Hante Meulemand5367332016-02-17 11:26:51 +01005589 kfree(cfg->escan_info.escan_buf);
5590 cfg->escan_info.escan_buf = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005591}
5592
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005593static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005594{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005595 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
5596 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005597 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005598 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
5599 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005600 goto init_priv_mem_out;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005601 cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL);
5602 if (!cfg->wowl.nd)
5603 goto init_priv_mem_out;
5604 cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) +
5605 sizeof(struct cfg80211_wowlan_nd_match *),
5606 GFP_KERNEL);
5607 if (!cfg->wowl.nd_info)
5608 goto init_priv_mem_out;
Hante Meulemand5367332016-02-17 11:26:51 +01005609 cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL);
5610 if (!cfg->escan_info.escan_buf)
5611 goto init_priv_mem_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005612
5613 return 0;
5614
5615init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005616 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005617
5618 return -ENOMEM;
5619}
5620
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005621static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005622{
5623 s32 err = 0;
5624
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005625 cfg->scan_request = NULL;
5626 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01005627 cfg->active_scan = true; /* we do active scan per default */
5628 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005629 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005630 if (err)
5631 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005632 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005633 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005634 brcmf_init_escan(cfg);
5635 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005636 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005637 return err;
5638}
5639
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005640static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005641{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005642 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005643 brcmf_abort_scanning(cfg);
5644 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005645}
5646
Arend van Sprield3c0b632013-02-08 15:53:37 +01005647static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
5648{
5649 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005650 mutex_init(&event->vif_event_lock);
5651}
5652
Hante Meuleman1119e232015-11-25 11:32:42 +01005653static s32 brcmf_dongle_roam(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005654{
Hante Meuleman1119e232015-11-25 11:32:42 +01005655 s32 err;
5656 u32 bcn_timeout;
Arend van Sprielf588bc02011-10-12 20:51:22 +02005657 __le32 roamtrigger[2];
5658 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005659
Hante Meuleman1119e232015-11-25 11:32:42 +01005660 /* Configure beacon timeout value based upon roaming setting */
Hante Meuleman7d34b052016-01-02 09:41:41 +01005661 if (ifp->drvr->settings->roamoff)
Hante Meuleman1119e232015-11-25 11:32:42 +01005662 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF;
5663 else
5664 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON;
5665 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
5666 if (err) {
5667 brcmf_err("bcn_timeout error (%d)\n", err);
5668 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005669 }
5670
Hante Meuleman1119e232015-11-25 11:32:42 +01005671 /* Enable/Disable built-in roaming to allow supplicant to take care of
5672 * roaming.
Arend van Spriel5b435de2011-10-05 13:19:03 +02005673 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005674 brcmf_dbg(INFO, "Internal Roaming = %s\n",
Hante Meuleman7d34b052016-01-02 09:41:41 +01005675 ifp->drvr->settings->roamoff ? "Off" : "On");
5676 err = brcmf_fil_iovar_int_set(ifp, "roam_off",
5677 ifp->drvr->settings->roamoff);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005678 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005679 brcmf_err("roam_off error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005680 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005681 }
5682
Arend van Sprielf588bc02011-10-12 20:51:22 +02005683 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
5684 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005685 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005686 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005687 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005688 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005689 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005690 }
5691
Arend van Sprielf588bc02011-10-12 20:51:22 +02005692 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
5693 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005694 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005695 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005696 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005697 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005698 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005699 }
5700
Hante Meuleman1119e232015-11-25 11:32:42 +01005701roam_setup_done:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005702 return err;
5703}
5704
5705static s32
Hante Meuleman1678ba82015-12-10 13:43:00 +01005706brcmf_dongle_scantime(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005707{
5708 s32 err = 0;
5709
Arend van Sprielac24be62012-10-22 10:36:23 -07005710 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005711 BRCMF_SCAN_CHANNEL_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005712 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005713 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005714 goto dongle_scantime_out;
5715 }
Arend van Sprielac24be62012-10-22 10:36:23 -07005716 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005717 BRCMF_SCAN_UNASSOC_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005718 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005719 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005720 goto dongle_scantime_out;
5721 }
5722
Arend van Sprielac24be62012-10-22 10:36:23 -07005723 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005724 BRCMF_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005725 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005726 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005727 goto dongle_scantime_out;
5728 }
5729
5730dongle_scantime_out:
5731 return err;
5732}
5733
Arend van Sprielb48d8912014-07-12 08:49:41 +02005734static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5735 struct brcmu_chan *ch)
5736{
5737 u32 ht40_flag;
5738
5739 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5740 if (ch->sb == BRCMU_CHAN_SB_U) {
5741 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5742 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5743 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5744 } else {
5745 /* It should be one of
5746 * IEEE80211_CHAN_NO_HT40 or
5747 * IEEE80211_CHAN_NO_HT40PLUS
5748 */
5749 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5750 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5751 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5752 }
5753}
5754
5755static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5756 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005757{
5758 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005759 struct ieee80211_supported_band *band;
5760 struct ieee80211_channel *channel;
5761 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005762 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005763 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005764 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005765 u8 *pbuf;
5766 u32 i, j;
5767 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005768 u32 chaninfo;
Hante Meulemand48200b2013-04-03 12:40:29 +02005769 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02005770
5771 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5772
5773 if (pbuf == NULL)
5774 return -ENOMEM;
5775
5776 list = (struct brcmf_chanspec_list *)pbuf;
5777
5778 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5779 BRCMF_DCMD_MEDLEN);
5780 if (err) {
5781 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005782 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005783 }
5784
Arend van Sprielb48d8912014-07-12 08:49:41 +02005785 wiphy = cfg_to_wiphy(cfg);
Johannes Berg57fbcce2016-04-12 15:56:15 +02005786 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel58de92d2015-04-14 20:10:24 +02005787 if (band)
5788 for (i = 0; i < band->n_channels; i++)
5789 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Johannes Berg57fbcce2016-04-12 15:56:15 +02005790 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel58de92d2015-04-14 20:10:24 +02005791 if (band)
5792 for (i = 0; i < band->n_channels; i++)
5793 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Hante Meulemand48200b2013-04-03 12:40:29 +02005794
5795 total = le32_to_cpu(list->count);
5796 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005797 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5798 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005799
Franky Lin83cf17a2013-04-11 13:28:50 +02005800 if (ch.band == BRCMU_CHAN_BAND_2G) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02005801 band = wiphy->bands[NL80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005802 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02005803 band = wiphy->bands[NL80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005804 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005805 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005806 continue;
5807 }
Arend van Spriel58de92d2015-04-14 20:10:24 +02005808 if (!band)
5809 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005810 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005811 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005812 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005813 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005814 ch.bw == BRCMU_CHAN_BW_80)
5815 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005816
5817 channel = band->channels;
5818 index = band->n_channels;
5819 for (j = 0; j < band->n_channels; j++) {
5820 if (channel[j].hw_value == ch.chnum) {
5821 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005822 break;
5823 }
5824 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005825 channel[index].center_freq =
5826 ieee80211_channel_to_frequency(ch.chnum, band->band);
5827 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005828
Arend van Sprielb48d8912014-07-12 08:49:41 +02005829 /* assuming the chanspecs order is HT20,
5830 * HT40 upper, HT40 lower, and VHT80.
5831 */
5832 if (ch.bw == BRCMU_CHAN_BW_80) {
5833 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5834 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5835 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5836 } else {
Arend van Spriel58de92d2015-04-14 20:10:24 +02005837 /* enable the channel and disable other bandwidths
5838 * for now as mentioned order assure they are enabled
5839 * for subsequent chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005840 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005841 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5842 IEEE80211_CHAN_NO_80MHZ;
5843 ch.bw = BRCMU_CHAN_BW_20;
5844 cfg->d11inf.encchspec(&ch);
5845 chaninfo = ch.chspec;
5846 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5847 &chaninfo);
5848 if (!err) {
5849 if (chaninfo & WL_CHAN_RADAR)
5850 channel[index].flags |=
5851 (IEEE80211_CHAN_RADAR |
5852 IEEE80211_CHAN_NO_IR);
5853 if (chaninfo & WL_CHAN_PASSIVE)
5854 channel[index].flags |=
5855 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005856 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005857 }
5858 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005859
Arend van Sprielb48d8912014-07-12 08:49:41 +02005860fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005861 kfree(pbuf);
5862 return err;
5863}
5864
Arend van Sprielb48d8912014-07-12 08:49:41 +02005865static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005866{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005867 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5868 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005869 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005870 struct brcmf_chanspec_list *list;
5871 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005872 u32 val;
5873 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005874 struct brcmu_chan ch;
5875 u32 num_chan;
5876 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005877
5878 /* verify support for bw_cap command */
5879 val = WLC_BAND_5G;
5880 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5881
5882 if (!err) {
5883 /* only set 2G bandwidth using bw_cap command */
5884 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5885 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5886 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5887 sizeof(band_bwcap));
5888 } else {
5889 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5890 val = WLC_N_BW_40ALL;
5891 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5892 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005893
5894 if (!err) {
5895 /* update channel info in 2G band */
5896 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5897
5898 if (pbuf == NULL)
5899 return -ENOMEM;
5900
5901 ch.band = BRCMU_CHAN_BAND_2G;
5902 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005903 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005904 ch.chnum = 0;
5905 cfg->d11inf.encchspec(&ch);
5906
5907 /* pass encoded chanspec in query */
5908 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5909
5910 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5911 BRCMF_DCMD_MEDLEN);
5912 if (err) {
5913 brcmf_err("get chanspecs error (%d)\n", err);
5914 kfree(pbuf);
5915 return err;
5916 }
5917
Johannes Berg57fbcce2016-04-12 15:56:15 +02005918 band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ];
Arend van Sprielb48d8912014-07-12 08:49:41 +02005919 list = (struct brcmf_chanspec_list *)pbuf;
5920 num_chan = le32_to_cpu(list->count);
5921 for (i = 0; i < num_chan; i++) {
5922 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5923 cfg->d11inf.decchspec(&ch);
5924 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5925 continue;
5926 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5927 continue;
5928 for (j = 0; j < band->n_channels; j++) {
5929 if (band->channels[j].hw_value == ch.chnum)
5930 break;
5931 }
5932 if (WARN_ON(j == band->n_channels))
5933 continue;
5934
5935 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5936 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005937 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005938 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005939 return err;
5940}
5941
Arend van Spriel2375d972014-01-06 12:40:41 +01005942static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5943{
5944 u32 band, mimo_bwcap;
5945 int err;
5946
5947 band = WLC_BAND_2G;
5948 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5949 if (!err) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02005950 bw_cap[NL80211_BAND_2GHZ] = band;
Arend van Spriel2375d972014-01-06 12:40:41 +01005951 band = WLC_BAND_5G;
5952 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5953 if (!err) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02005954 bw_cap[NL80211_BAND_5GHZ] = band;
Arend van Spriel2375d972014-01-06 12:40:41 +01005955 return;
5956 }
5957 WARN_ON(1);
5958 return;
5959 }
5960 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5961 mimo_bwcap = 0;
5962 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5963 if (err)
5964 /* assume 20MHz if firmware does not give a clue */
5965 mimo_bwcap = WLC_N_BW_20ALL;
5966
5967 switch (mimo_bwcap) {
5968 case WLC_N_BW_40ALL:
Johannes Berg57fbcce2016-04-12 15:56:15 +02005969 bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
Arend van Spriel2375d972014-01-06 12:40:41 +01005970 /* fall-thru */
5971 case WLC_N_BW_20IN2G_40IN5G:
Johannes Berg57fbcce2016-04-12 15:56:15 +02005972 bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
Arend van Spriel2375d972014-01-06 12:40:41 +01005973 /* fall-thru */
5974 case WLC_N_BW_20ALL:
Johannes Berg57fbcce2016-04-12 15:56:15 +02005975 bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5976 bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
Arend van Spriel2375d972014-01-06 12:40:41 +01005977 break;
5978 default:
5979 brcmf_err("invalid mimo_bw_cap value\n");
5980 }
5981}
Hante Meulemand48200b2013-04-03 12:40:29 +02005982
Arend van Spriel18d6c532014-05-12 10:47:35 +02005983static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5984 u32 bw_cap[2], u32 nchain)
5985{
5986 band->ht_cap.ht_supported = true;
5987 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5988 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5989 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5990 }
5991 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5992 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5993 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5994 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5995 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5996 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5997}
5998
5999static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
6000{
6001 u16 mcs_map;
6002 int i;
6003
6004 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
6005 mcs_map = (mcs_map << 2) | supp;
6006
6007 return cpu_to_le16(mcs_map);
6008}
6009
6010static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006011 u32 bw_cap[2], u32 nchain, u32 txstreams,
6012 u32 txbf_bfe_cap, u32 txbf_bfr_cap)
Arend van Spriel18d6c532014-05-12 10:47:35 +02006013{
6014 __le16 mcs_map;
6015
6016 /* not allowed in 2.4G band */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006017 if (band->band == NL80211_BAND_2GHZ)
Arend van Spriel18d6c532014-05-12 10:47:35 +02006018 return;
6019
6020 band->vht_cap.vht_supported = true;
6021 /* 80MHz is mandatory */
6022 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
6023 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
6024 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
6025 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
6026 }
6027 /* all support 256-QAM */
6028 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
6029 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
6030 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006031
6032 /* Beamforming support information */
6033 if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP)
6034 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
6035 if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP)
6036 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
6037 if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP)
6038 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
6039 if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP)
6040 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
6041
6042 if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) {
6043 band->vht_cap.cap |=
6044 (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
6045 band->vht_cap.cap |= ((txstreams - 1) <<
6046 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
6047 band->vht_cap.cap |=
6048 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
6049 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02006050}
6051
Arend van Sprielb48d8912014-07-12 08:49:41 +02006052static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006053{
Arend van Sprielb48d8912014-07-12 08:49:41 +02006054 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07006055 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02006056 u32 nmode = 0;
6057 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006058 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01006059 u32 rxchain;
6060 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006061 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02006062 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01006063 struct ieee80211_supported_band *band;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006064 u32 txstreams = 0;
6065 u32 txbf_bfe_cap = 0;
6066 u32 txbf_bfr_cap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006067
Arend van Spriel18d6c532014-05-12 10:47:35 +02006068 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02006069 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
6070 if (err) {
6071 brcmf_err("nmode error (%d)\n", err);
6072 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01006073 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02006074 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02006075 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
Johannes Berg57fbcce2016-04-12 15:56:15 +02006076 nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ],
6077 bw_cap[NL80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02006078
Daniel Kim4aca7a12014-02-25 20:30:36 +01006079 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
6080 if (err) {
6081 brcmf_err("rxchain error (%d)\n", err);
6082 nchain = 1;
6083 } else {
6084 for (nchain = 0; rxchain; nchain++)
6085 rxchain = rxchain & (rxchain - 1);
6086 }
6087 brcmf_dbg(INFO, "nchain=%d\n", nchain);
6088
Arend van Sprielb48d8912014-07-12 08:49:41 +02006089 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02006090 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006091 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02006092 return err;
6093 }
6094
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006095 if (vhtmode) {
6096 (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams);
6097 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap",
6098 &txbf_bfe_cap);
6099 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap",
6100 &txbf_bfr_cap);
6101 }
6102
Arend van Sprielb48d8912014-07-12 08:49:41 +02006103 wiphy = cfg_to_wiphy(cfg);
6104 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
6105 band = wiphy->bands[i];
6106 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01006107 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02006108
Arend van Spriel18d6c532014-05-12 10:47:35 +02006109 if (nmode)
6110 brcmf_update_ht_cap(band, bw_cap, nchain);
6111 if (vhtmode)
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006112 brcmf_update_vht_cap(band, bw_cap, nchain, txstreams,
6113 txbf_bfe_cap, txbf_bfr_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02006114 }
6115
Arend van Sprielb48d8912014-07-12 08:49:41 +02006116 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006117}
6118
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006119static const struct ieee80211_txrx_stypes
6120brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
6121 [NL80211_IFTYPE_STATION] = {
6122 .tx = 0xffff,
6123 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
6124 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
6125 },
6126 [NL80211_IFTYPE_P2P_CLIENT] = {
6127 .tx = 0xffff,
6128 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
6129 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
6130 },
6131 [NL80211_IFTYPE_P2P_GO] = {
6132 .tx = 0xffff,
6133 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
6134 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
6135 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
6136 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
6137 BIT(IEEE80211_STYPE_AUTH >> 4) |
6138 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
6139 BIT(IEEE80211_STYPE_ACTION >> 4)
6140 },
6141 [NL80211_IFTYPE_P2P_DEVICE] = {
6142 .tx = 0xffff,
6143 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
6144 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
6145 }
6146};
6147
Arend van Spriel0882dda2015-08-20 22:06:03 +02006148/**
6149 * brcmf_setup_ifmodes() - determine interface modes and combinations.
6150 *
6151 * @wiphy: wiphy object.
6152 * @ifp: interface object needed for feat module api.
6153 *
6154 * The interface modes and combinations are determined dynamically here
6155 * based on firmware functionality.
6156 *
6157 * no p2p and no mbss:
6158 *
6159 * #STA <= 1, #AP <= 1, channels = 1, 2 total
6160 *
6161 * no p2p and mbss:
6162 *
6163 * #STA <= 1, #AP <= 1, channels = 1, 2 total
6164 * #AP <= 4, matching BI, channels = 1, 4 total
6165 *
6166 * p2p, no mchan, and mbss:
6167 *
6168 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
6169 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
6170 * #AP <= 4, matching BI, channels = 1, 4 total
6171 *
6172 * p2p, mchan, and mbss:
6173 *
6174 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
6175 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
6176 * #AP <= 4, matching BI, channels = 1, 4 total
6177 */
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006178static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
6179{
6180 struct ieee80211_iface_combination *combo = NULL;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006181 struct ieee80211_iface_limit *c0_limits = NULL;
6182 struct ieee80211_iface_limit *p2p_limits = NULL;
6183 struct ieee80211_iface_limit *mbss_limits = NULL;
6184 bool mbss, p2p;
6185 int i, c, n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006186
Arend van Spriel0882dda2015-08-20 22:06:03 +02006187 mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
6188 p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
6189
6190 n_combos = 1 + !!p2p + !!mbss;
6191 combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006192 if (!combo)
6193 goto err;
6194
Arend van Spriel0882dda2015-08-20 22:06:03 +02006195 c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
6196 if (!c0_limits)
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006197 goto err;
6198
Arend van Spriel0882dda2015-08-20 22:06:03 +02006199 if (p2p) {
6200 p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
6201 if (!p2p_limits)
6202 goto err;
6203 }
6204
6205 if (mbss) {
6206 mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
6207 if (!mbss_limits)
6208 goto err;
6209 }
6210
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006211 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
6212 BIT(NL80211_IFTYPE_ADHOC) |
6213 BIT(NL80211_IFTYPE_AP);
6214
Arend van Spriel0882dda2015-08-20 22:06:03 +02006215 c = 0;
6216 i = 0;
6217 combo[c].num_different_channels = 1;
6218 c0_limits[i].max = 1;
6219 c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6220 if (p2p) {
6221 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
6222 combo[c].num_different_channels = 2;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006223 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
6224 BIT(NL80211_IFTYPE_P2P_GO) |
6225 BIT(NL80211_IFTYPE_P2P_DEVICE);
Arend van Spriel0882dda2015-08-20 22:06:03 +02006226 c0_limits[i].max = 1;
6227 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6228 c0_limits[i].max = 1;
6229 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
6230 BIT(NL80211_IFTYPE_P2P_GO);
6231 } else {
6232 c0_limits[i].max = 1;
6233 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006234 }
Arend van Spriel0882dda2015-08-20 22:06:03 +02006235 combo[c].max_interfaces = i;
6236 combo[c].n_limits = i;
6237 combo[c].limits = c0_limits;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006238
Arend van Spriel0882dda2015-08-20 22:06:03 +02006239 if (p2p) {
6240 c++;
6241 i = 0;
6242 combo[c].num_different_channels = 1;
6243 p2p_limits[i].max = 1;
6244 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6245 p2p_limits[i].max = 1;
6246 p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
6247 p2p_limits[i].max = 1;
6248 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
6249 p2p_limits[i].max = 1;
6250 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6251 combo[c].max_interfaces = i;
6252 combo[c].n_limits = i;
6253 combo[c].limits = p2p_limits;
6254 }
6255
6256 if (mbss) {
6257 c++;
6258 combo[c].beacon_int_infra_match = true;
6259 combo[c].num_different_channels = 1;
6260 mbss_limits[0].max = 4;
6261 mbss_limits[0].types = BIT(NL80211_IFTYPE_AP);
6262 combo[c].max_interfaces = 4;
6263 combo[c].n_limits = 1;
6264 combo[c].limits = mbss_limits;
6265 }
6266 wiphy->n_iface_combinations = n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006267 wiphy->iface_combinations = combo;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006268 return 0;
6269
6270err:
Arend van Spriel0882dda2015-08-20 22:06:03 +02006271 kfree(c0_limits);
6272 kfree(p2p_limits);
6273 kfree(mbss_limits);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006274 kfree(combo);
6275 return -ENOMEM;
6276}
6277
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006278static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
6279{
6280 /* scheduled scan settings */
6281 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
6282 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
6283 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
6284 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
6285}
6286
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006287#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006288static struct wiphy_wowlan_support brcmf_wowlan_support = {
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006289 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01006290 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
6291 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
6292 .pattern_min_len = 1,
6293 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006294};
6295#endif
6296
Hante Meuleman3021ad92016-01-05 11:05:45 +01006297static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp)
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006298{
6299#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006300 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman3021ad92016-01-05 11:05:45 +01006301
6302 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006303 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) {
6304 brcmf_wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT;
6305 init_waitqueue_head(&cfg->wowl.nd_data_wait);
Hante Meuleman3021ad92016-01-05 11:05:45 +01006306 }
6307 }
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006308 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) {
6309 brcmf_wowlan_support.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY;
6310 brcmf_wowlan_support.flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE;
6311 }
6312
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006313 wiphy->wowlan = &brcmf_wowlan_support;
6314#endif
6315}
6316
Arend van Sprielb48d8912014-07-12 08:49:41 +02006317static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006318{
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006319 struct brcmf_pub *drvr = ifp->drvr;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006320 const struct ieee80211_iface_combination *combo;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006321 struct ieee80211_supported_band *band;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006322 u16 max_interfaces = 0;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006323 __le32 bandlist[3];
6324 u32 n_bands;
6325 int err, i;
6326
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006327 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
6328 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
Hante Meuleman6c404f32015-12-10 13:43:03 +01006329 wiphy->max_num_pmkids = BRCMF_MAXPMKID;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006330
6331 err = brcmf_setup_ifmodes(wiphy, ifp);
6332 if (err)
6333 return err;
6334
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006335 for (i = 0, combo = wiphy->iface_combinations;
6336 i < wiphy->n_iface_combinations; i++, combo++) {
6337 max_interfaces = max(max_interfaces, combo->max_interfaces);
6338 }
6339
6340 for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
6341 i++) {
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006342 u8 *addr = drvr->addresses[i].addr;
6343
6344 memcpy(addr, drvr->mac, ETH_ALEN);
6345 if (i) {
6346 addr[0] |= BIT(1);
6347 addr[ETH_ALEN - 1] ^= i;
6348 }
6349 }
6350 wiphy->addresses = drvr->addresses;
6351 wiphy->n_addresses = i;
6352
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006353 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
Hante Meuleman240d61a2016-02-17 11:27:10 +01006354 wiphy->cipher_suites = brcmf_cipher_suites;
6355 wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites);
6356 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
6357 wiphy->n_cipher_suites--;
Arend van Spriel7705ba62016-04-17 16:44:58 +02006358 wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) |
6359 BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) |
6360 BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST);
6361
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006362 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
6363 WIPHY_FLAG_OFFCHAN_TX |
Hante Meulemana7b82d42015-12-10 13:43:04 +01006364 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6365 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS))
6366 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman7d34b052016-01-02 09:41:41 +01006367 if (!ifp->drvr->settings->roamoff)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006368 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
6369 wiphy->mgmt_stypes = brcmf_txrx_stypes;
6370 wiphy->max_remain_on_channel_duration = 5000;
Arend van Spriel7a7a87d2015-04-14 20:10:27 +02006371 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
6372 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006373
6374 /* vendor commands/events support */
6375 wiphy->vendor_commands = brcmf_vendor_cmds;
6376 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
6377
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006378 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
Hante Meuleman3021ad92016-01-05 11:05:45 +01006379 brcmf_wiphy_wowl_params(wiphy, ifp);
Arend van Spriel58de92d2015-04-14 20:10:24 +02006380 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
6381 sizeof(bandlist));
6382 if (err) {
6383 brcmf_err("could not obtain band info: err=%d\n", err);
6384 return err;
6385 }
6386 /* first entry in bandlist is number of bands */
6387 n_bands = le32_to_cpu(bandlist[0]);
6388 for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
6389 if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
6390 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
6391 GFP_KERNEL);
6392 if (!band)
6393 return -ENOMEM;
6394
6395 band->channels = kmemdup(&__wl_2ghz_channels,
6396 sizeof(__wl_2ghz_channels),
6397 GFP_KERNEL);
6398 if (!band->channels) {
6399 kfree(band);
6400 return -ENOMEM;
6401 }
6402
6403 band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
Johannes Berg57fbcce2016-04-12 15:56:15 +02006404 wiphy->bands[NL80211_BAND_2GHZ] = band;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006405 }
6406 if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
6407 band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
6408 GFP_KERNEL);
6409 if (!band)
6410 return -ENOMEM;
6411
6412 band->channels = kmemdup(&__wl_5ghz_channels,
6413 sizeof(__wl_5ghz_channels),
6414 GFP_KERNEL);
6415 if (!band->channels) {
6416 kfree(band);
6417 return -ENOMEM;
6418 }
6419
6420 band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
Johannes Berg57fbcce2016-04-12 15:56:15 +02006421 wiphy->bands[NL80211_BAND_5GHZ] = band;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006422 }
6423 }
6424 err = brcmf_setup_wiphybands(wiphy);
6425 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006426}
6427
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006428static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006429{
6430 struct net_device *ndev;
6431 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01006432 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006433 s32 power_mode;
6434 s32 err = 0;
6435
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006436 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006437 return err;
6438
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006439 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006440 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01006441 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006442
Hante Meuleman40a23292013-01-02 15:22:51 +01006443 /* make sure RF is ready for work */
6444 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
6445
Hante Meuleman1678ba82015-12-10 13:43:00 +01006446 brcmf_dongle_scantime(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006447
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006448 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01006449 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006450 if (err)
6451 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01006452 brcmf_dbg(INFO, "power save set to %s\n",
6453 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02006454
Hante Meuleman1119e232015-11-25 11:32:42 +01006455 err = brcmf_dongle_roam(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006456 if (err)
6457 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07006458 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
6459 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01006460 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006461 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006462
Franky Lin52f22fb2016-02-17 11:26:55 +01006463 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meulemanb3657452013-05-27 21:09:53 +02006464
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006465 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01006466default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02006467
6468 return err;
6469
6470}
6471
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006472static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006473{
Arend van Sprielc1179032012-10-22 13:55:33 -07006474 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006475
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006476 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006477}
6478
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006479static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006480{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006481 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07006482
Arend van Spriel5b435de2011-10-05 13:19:03 +02006483 /*
6484 * While going down, if associated with AP disassociate
6485 * from AP to save power
6486 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01006487 if (check_vif_up(ifp->vif)) {
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01006488 brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006489
6490 /* Make sure WPA_Supplicant receives all the event
6491 generated due to DISASSOC call to the fw to keep
6492 the state fw and WPA_Supplicant state consistent
6493 */
6494 brcmf_delay(500);
6495 }
6496
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006497 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07006498 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006499
Arend van Spriel5b435de2011-10-05 13:19:03 +02006500 return 0;
6501}
6502
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006503s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006504{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006505 struct brcmf_if *ifp = netdev_priv(ndev);
6506 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006507 s32 err = 0;
6508
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006509 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006510 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006511 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006512
6513 return err;
6514}
6515
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006516s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006517{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006518 struct brcmf_if *ifp = netdev_priv(ndev);
6519 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006520 s32 err = 0;
6521
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006522 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006523 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006524 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006525
6526 return err;
6527}
6528
Arend van Spriela7965fb2013-04-11 17:08:37 +02006529enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
6530{
6531 struct wireless_dev *wdev = &ifp->vif->wdev;
6532
6533 return wdev->iftype;
6534}
6535
Hante Meulemanbfe81972014-10-28 14:56:16 +01006536bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
6537 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01006538{
6539 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006540
6541 list_for_each_entry(vif, &cfg->vif_list, list) {
6542 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006543 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006544 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006545 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006546}
Arend van Sprield3c0b632013-02-08 15:53:37 +01006547
6548static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
6549 u8 action)
6550{
6551 u8 evt_action;
6552
6553 mutex_lock(&event->vif_event_lock);
6554 evt_action = event->action;
6555 mutex_unlock(&event->vif_event_lock);
6556 return evt_action == action;
6557}
6558
6559void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
6560 struct brcmf_cfg80211_vif *vif)
6561{
6562 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6563
6564 mutex_lock(&event->vif_event_lock);
6565 event->vif = vif;
6566 event->action = 0;
6567 mutex_unlock(&event->vif_event_lock);
6568}
6569
6570bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
6571{
6572 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6573 bool armed;
6574
6575 mutex_lock(&event->vif_event_lock);
6576 armed = event->vif != NULL;
6577 mutex_unlock(&event->vif_event_lock);
6578
6579 return armed;
6580}
Arend van Spriela9eb0c42016-02-17 11:26:50 +01006581
6582int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
6583 u8 action, ulong timeout)
Arend van Sprield3c0b632013-02-08 15:53:37 +01006584{
6585 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6586
6587 return wait_event_timeout(event->vif_wq,
6588 vif_event_equals(event, action), timeout);
6589}
6590
Hante Meuleman73345fd2016-02-17 11:26:53 +01006591static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2],
6592 struct brcmf_fil_country_le *ccreq)
6593{
Hante Meuleman4d792892016-02-17 11:27:07 +01006594 struct brcmfmac_pd_cc *country_codes;
6595 struct brcmfmac_pd_cc_entry *cc;
Hante Meuleman73345fd2016-02-17 11:26:53 +01006596 s32 found_index;
6597 int i;
6598
6599 country_codes = drvr->settings->country_codes;
6600 if (!country_codes) {
6601 brcmf_dbg(TRACE, "No country codes configured for device\n");
6602 return -EINVAL;
6603 }
6604
6605 if ((alpha2[0] == ccreq->country_abbrev[0]) &&
6606 (alpha2[1] == ccreq->country_abbrev[1])) {
6607 brcmf_dbg(TRACE, "Country code already set\n");
6608 return -EAGAIN;
6609 }
6610
6611 found_index = -1;
6612 for (i = 0; i < country_codes->table_size; i++) {
6613 cc = &country_codes->table[i];
6614 if ((cc->iso3166[0] == '\0') && (found_index == -1))
6615 found_index = i;
6616 if ((cc->iso3166[0] == alpha2[0]) &&
6617 (cc->iso3166[1] == alpha2[1])) {
6618 found_index = i;
6619 break;
6620 }
6621 }
6622 if (found_index == -1) {
6623 brcmf_dbg(TRACE, "No country code match found\n");
6624 return -EINVAL;
6625 }
6626 memset(ccreq, 0, sizeof(*ccreq));
6627 ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev);
6628 memcpy(ccreq->ccode, country_codes->table[found_index].cc,
6629 BRCMF_COUNTRY_BUF_SZ);
6630 ccreq->country_abbrev[0] = alpha2[0];
6631 ccreq->country_abbrev[1] = alpha2[1];
6632 ccreq->country_abbrev[2] = 0;
6633
6634 return 0;
6635}
6636
Arend van Spriel63db1a42014-12-21 12:43:51 +01006637static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
6638 struct regulatory_request *req)
6639{
6640 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6641 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6642 struct brcmf_fil_country_le ccreq;
Hante Meuleman73345fd2016-02-17 11:26:53 +01006643 s32 err;
Arend van Spriel63db1a42014-12-21 12:43:51 +01006644 int i;
6645
Arend van Spriel63db1a42014-12-21 12:43:51 +01006646 /* ignore non-ISO3166 country codes */
6647 for (i = 0; i < sizeof(req->alpha2); i++)
6648 if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
Hante Meuleman73345fd2016-02-17 11:26:53 +01006649 brcmf_err("not a ISO3166 code (0x%02x 0x%02x)\n",
6650 req->alpha2[0], req->alpha2[1]);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006651 return;
6652 }
Hante Meuleman73345fd2016-02-17 11:26:53 +01006653
6654 brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator,
6655 req->alpha2[0], req->alpha2[1]);
6656
6657 err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq));
6658 if (err) {
6659 brcmf_err("Country code iovar returned err = %d\n", err);
6660 return;
6661 }
6662
6663 err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq);
6664 if (err)
6665 return;
6666
6667 err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
6668 if (err) {
6669 brcmf_err("Firmware rejected country setting\n");
Arend van Spriel8afe0ec2015-04-14 20:10:25 +02006670 return;
6671 }
6672 brcmf_setup_wiphybands(wiphy);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006673}
6674
Arend van Sprielb48d8912014-07-12 08:49:41 +02006675static void brcmf_free_wiphy(struct wiphy *wiphy)
6676{
Arend van Spriel0882dda2015-08-20 22:06:03 +02006677 int i;
6678
Arend van Spriel58de92d2015-04-14 20:10:24 +02006679 if (!wiphy)
6680 return;
6681
Arend van Spriel0882dda2015-08-20 22:06:03 +02006682 if (wiphy->iface_combinations) {
6683 for (i = 0; i < wiphy->n_iface_combinations; i++)
6684 kfree(wiphy->iface_combinations[i].limits);
6685 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006686 kfree(wiphy->iface_combinations);
Johannes Berg57fbcce2016-04-12 15:56:15 +02006687 if (wiphy->bands[NL80211_BAND_2GHZ]) {
6688 kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels);
6689 kfree(wiphy->bands[NL80211_BAND_2GHZ]);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006690 }
Johannes Berg57fbcce2016-04-12 15:56:15 +02006691 if (wiphy->bands[NL80211_BAND_5GHZ]) {
6692 kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels);
6693 kfree(wiphy->bands[NL80211_BAND_5GHZ]);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006694 }
6695 wiphy_free(wiphy);
6696}
6697
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006698struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006699 struct device *busdev,
6700 bool p2pdev_forced)
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006701{
Arend van Spriel46f3b6e2015-08-26 22:14:58 +02006702 struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006703 struct brcmf_cfg80211_info *cfg;
6704 struct wiphy *wiphy;
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006705 struct cfg80211_ops *ops;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006706 struct brcmf_cfg80211_vif *vif;
6707 struct brcmf_if *ifp;
6708 s32 err = 0;
6709 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006710 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006711
6712 if (!ndev) {
6713 brcmf_err("ndev is invalid\n");
6714 return NULL;
6715 }
6716
Muhammad Falak R Wanid464fd82016-05-19 19:29:03 +05306717 ops = kmemdup(&brcmf_cfg80211_ops, sizeof(*ops), GFP_KERNEL);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006718 if (!ops)
6719 return NULL;
6720
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006721 ifp = netdev_priv(ndev);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006722#ifdef CONFIG_PM
6723 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK))
6724 ops->set_rekey_data = brcmf_cfg80211_set_rekey_data;
6725#endif
6726 wiphy = wiphy_new(ops, sizeof(struct brcmf_cfg80211_info));
Arend van Sprielb48d8912014-07-12 08:49:41 +02006727 if (!wiphy) {
6728 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006729 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006730 }
Rafał Miłecki6896f4f2015-05-31 02:52:26 +02006731 memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006732 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006733
6734 cfg = wiphy_priv(wiphy);
6735 cfg->wiphy = wiphy;
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006736 cfg->ops = ops;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006737 cfg->pub = drvr;
6738 init_vif_event(&cfg->vif_event);
6739 INIT_LIST_HEAD(&cfg->vif_list);
6740
6741 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006742 if (IS_ERR(vif))
6743 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006744
6745 vif->ifp = ifp;
6746 vif->wdev.netdev = ndev;
6747 ndev->ieee80211_ptr = &vif->wdev;
6748 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
6749
6750 err = wl_init_priv(cfg);
6751 if (err) {
6752 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006753 brcmf_free_vif(vif);
6754 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006755 }
6756 ifp->vif = vif;
6757
Arend van Sprielb48d8912014-07-12 08:49:41 +02006758 /* determine d11 io type before wiphy setup */
6759 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006760 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006761 brcmf_err("Failed to get D11 version (%d)\n", err);
6762 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006763 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006764 cfg->d11inf.io_type = (u8)io_type;
6765 brcmu_d11_attach(&cfg->d11inf);
6766
6767 err = brcmf_setup_wiphy(wiphy, ifp);
6768 if (err < 0)
6769 goto priv_out;
6770
6771 brcmf_dbg(INFO, "Registering custom regulatory\n");
Arend van Spriel63db1a42014-12-21 12:43:51 +01006772 wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006773 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
6774 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
6775
6776 /* firmware defaults to 40MHz disabled in 2G band. We signal
6777 * cfg80211 here that we do and have it decide we can enable
6778 * it. But first check if device does support 2G operation.
6779 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006780 if (wiphy->bands[NL80211_BAND_2GHZ]) {
6781 cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006782 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6783 }
6784 err = wiphy_register(wiphy);
6785 if (err < 0) {
6786 brcmf_err("Could not register wiphy device (%d)\n", err);
6787 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006788 }
6789
6790 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
6791 * setup 40MHz in 2GHz band and enable OBSS scanning.
6792 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02006793 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
6794 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006795 if (!err)
6796 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
6797 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006798 else
6799 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006800 }
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006801 /* p2p might require that "if-events" get processed by fweh. So
6802 * activate the already registered event handlers now and activate
6803 * the rest when initialization has completed. drvr->config needs to
6804 * be assigned before activating events.
6805 */
6806 drvr->config = cfg;
6807 err = brcmf_fweh_activate_events(ifp);
6808 if (err) {
6809 brcmf_err("FWEH activation failed (%d)\n", err);
6810 goto wiphy_unreg_out;
6811 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006812
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006813 err = brcmf_p2p_attach(cfg, p2pdev_forced);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006814 if (err) {
6815 brcmf_err("P2P initilisation failed (%d)\n", err);
6816 goto wiphy_unreg_out;
6817 }
6818 err = brcmf_btcoex_attach(cfg);
6819 if (err) {
6820 brcmf_err("BT-coex initialisation failed (%d)\n", err);
6821 brcmf_p2p_detach(&cfg->p2p);
6822 goto wiphy_unreg_out;
6823 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006824
Hante Meulemana7b82d42015-12-10 13:43:04 +01006825 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) {
6826 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
6827 if (err) {
6828 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
6829 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
6830 } else {
6831 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
6832 brcmf_notify_tdls_peer_event);
6833 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006834 }
6835
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006836 /* (re-) activate FWEH event handling */
6837 err = brcmf_fweh_activate_events(ifp);
6838 if (err) {
6839 brcmf_err("FWEH activation failed (%d)\n", err);
6840 goto wiphy_unreg_out;
6841 }
6842
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006843 /* Fill in some of the advertised nl80211 supported features */
6844 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) {
6845 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6846#ifdef CONFIG_PM
Franky Lin6ea09152016-02-17 11:26:52 +01006847 if (wiphy->wowlan &&
6848 wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT)
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006849 wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6850#endif
6851 }
6852
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006853 return cfg;
6854
Arend van Sprielb48d8912014-07-12 08:49:41 +02006855wiphy_unreg_out:
6856 wiphy_unregister(cfg->wiphy);
6857priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006858 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006859 brcmf_free_vif(vif);
Hante Meuleman2b5d3482015-09-18 22:08:04 +02006860 ifp->vif = NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006861wiphy_out:
6862 brcmf_free_wiphy(wiphy);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006863 kfree(ops);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006864 return NULL;
6865}
6866
6867void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
6868{
6869 if (!cfg)
6870 return;
6871
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006872 brcmf_btcoex_detach(cfg);
Arend van Sprielf7a40872015-06-11 00:12:23 +02006873 wiphy_unregister(cfg->wiphy);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006874 kfree(cfg->ops);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006875 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006876 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006877}