blob: 4e1ca69f6aa1c27fd9530e7f14a36a0101657b85 [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"
Arend Van Sprielac551362016-11-23 10:25:22 +000035#include "pno.h"
Hante Meulemanbfe81972014-10-28 14:56:16 +010036#include "cfg80211.h"
Arend van Sprielc08437b2014-07-12 08:49:39 +020037#include "feature.h"
Hante Meuleman81f5dcb2012-10-22 10:36:14 -070038#include "fwil.h"
Hante Meuleman8851cce2014-07-30 13:20:02 +020039#include "proto.h"
Franky Lin1bacb042014-06-21 12:11:16 +020040#include "vendor.h"
Hante Meulemand14f78b2014-10-28 14:56:14 +010041#include "bus.h"
Hante Meuleman6b89dcb2014-12-21 12:43:52 +010042#include "common.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020043
Arend van Spriele5806072012-09-19 22:21:08 +020044#define BRCMF_SCAN_IE_LEN_MAX 2048
Arend van Spriele5806072012-09-19 22:21:08 +020045
Hante Meuleman1a873342012-09-27 14:17:54 +020046#define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
47#define WPA_OUI_TYPE 1
48#define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
49#define WME_OUI_TYPE 2
Hante Meuleman89286dc2013-02-08 15:53:46 +010050#define WPS_OUI_TYPE 4
Hante Meuleman1a873342012-09-27 14:17:54 +020051
52#define VS_IE_FIXED_HDR_LEN 6
53#define WPA_IE_VERSION_LEN 2
54#define WPA_IE_MIN_OUI_LEN 4
55#define WPA_IE_SUITE_COUNT_LEN 2
56
57#define WPA_CIPHER_NONE 0 /* None */
58#define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
59#define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
60#define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
61#define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
62
63#define RSN_AKM_NONE 0 /* None (IBSS) */
64#define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
65#define RSN_AKM_PSK 2 /* Pre-shared Key */
Hante Meuleman240d61a2016-02-17 11:27:10 +010066#define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */
67#define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */
Hante Meuleman1a873342012-09-27 14:17:54 +020068#define RSN_CAP_LEN 2 /* Length of RSN capabilities */
Hante Meuleman240d61a2016-02-17 11:27:10 +010069#define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3))
70#define RSN_CAP_MFPR_MASK BIT(6)
71#define RSN_CAP_MFPC_MASK BIT(7)
72#define RSN_PMKID_COUNT_LEN 2
Hante Meuleman1a873342012-09-27 14:17:54 +020073
74#define VNDR_IE_CMD_LEN 4 /* length of the set command
75 * string :"add", "del" (+ NUL)
76 */
77#define VNDR_IE_COUNT_OFFSET 4
78#define VNDR_IE_PKTFLAG_OFFSET 8
79#define VNDR_IE_VSIE_OFFSET 12
80#define VNDR_IE_HDR_SIZE 12
Arend van Spriel9f440b72013-02-08 15:53:36 +010081#define VNDR_IE_PARSE_LIMIT 5
Hante Meuleman1a873342012-09-27 14:17:54 +020082
83#define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
84#define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
Hante Meuleman04012892012-09-27 14:17:49 +020085
Hante Meuleman89286dc2013-02-08 15:53:46 +010086#define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
87#define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
88#define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
89
Hante Meuleman1678ba82015-12-10 13:43:00 +010090#define BRCMF_SCAN_CHANNEL_TIME 40
91#define BRCMF_SCAN_UNASSOC_TIME 40
92#define BRCMF_SCAN_PASSIVE_TIME 120
93
Hante Meuleman3021ad92016-01-05 11:05:45 +010094#define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000)
95
Arend van Spriel5b435de2011-10-05 13:19:03 +020096#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
97 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
98
Arend van Sprielce81e312012-10-22 13:55:37 -070099static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200100{
Arend van Sprielc1179032012-10-22 13:55:33 -0700101 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100102 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
103 vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200104 return false;
105 }
106 return true;
107}
108
Arend van Spriel5b435de2011-10-05 13:19:03 +0200109#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
110#define RATETAB_ENT(_rateid, _flags) \
111 { \
112 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
113 .hw_value = (_rateid), \
114 .flags = (_flags), \
115 }
116
117static struct ieee80211_rate __wl_rates[] = {
118 RATETAB_ENT(BRCM_RATE_1M, 0),
119 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
120 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
121 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
122 RATETAB_ENT(BRCM_RATE_6M, 0),
123 RATETAB_ENT(BRCM_RATE_9M, 0),
124 RATETAB_ENT(BRCM_RATE_12M, 0),
125 RATETAB_ENT(BRCM_RATE_18M, 0),
126 RATETAB_ENT(BRCM_RATE_24M, 0),
127 RATETAB_ENT(BRCM_RATE_36M, 0),
128 RATETAB_ENT(BRCM_RATE_48M, 0),
129 RATETAB_ENT(BRCM_RATE_54M, 0),
130};
131
Arend van Spriel5b435de2011-10-05 13:19:03 +0200132#define wl_g_rates (__wl_rates + 0)
Arend van Spriel58de92d2015-04-14 20:10:24 +0200133#define wl_g_rates_size ARRAY_SIZE(__wl_rates)
134#define wl_a_rates (__wl_rates + 4)
135#define wl_a_rates_size (wl_g_rates_size - 4)
136
137#define CHAN2G(_channel, _freq) { \
Johannes Berg57fbcce2016-04-12 15:56:15 +0200138 .band = NL80211_BAND_2GHZ, \
Arend van Spriel58de92d2015-04-14 20:10:24 +0200139 .center_freq = (_freq), \
140 .hw_value = (_channel), \
Arend van Spriel58de92d2015-04-14 20:10:24 +0200141 .max_antenna_gain = 0, \
142 .max_power = 30, \
143}
144
145#define CHAN5G(_channel) { \
Johannes Berg57fbcce2016-04-12 15:56:15 +0200146 .band = NL80211_BAND_5GHZ, \
Arend van Spriel58de92d2015-04-14 20:10:24 +0200147 .center_freq = 5000 + (5 * (_channel)), \
148 .hw_value = (_channel), \
Arend van Spriel58de92d2015-04-14 20:10:24 +0200149 .max_antenna_gain = 0, \
150 .max_power = 30, \
151}
152
153static struct ieee80211_channel __wl_2ghz_channels[] = {
154 CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427),
155 CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447),
156 CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467),
157 CHAN2G(13, 2472), CHAN2G(14, 2484)
158};
159
160static struct ieee80211_channel __wl_5ghz_channels[] = {
161 CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42),
162 CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56),
163 CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108),
164 CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128),
165 CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149),
166 CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165)
167};
Arend van Spriel5b435de2011-10-05 13:19:03 +0200168
Arend van Sprielb48d8912014-07-12 08:49:41 +0200169/* Band templates duplicated per wiphy. The channel info
Arend van Spriel58de92d2015-04-14 20:10:24 +0200170 * above is added to the band during setup.
Arend van Sprielb48d8912014-07-12 08:49:41 +0200171 */
172static const struct ieee80211_supported_band __wl_band_2ghz = {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200173 .band = NL80211_BAND_2GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200174 .bitrates = wl_g_rates,
175 .n_bitrates = wl_g_rates_size,
176};
177
Arend van Spriel58de92d2015-04-14 20:10:24 +0200178static const struct ieee80211_supported_band __wl_band_5ghz = {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200179 .band = NL80211_BAND_5GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200180 .bitrates = wl_a_rates,
181 .n_bitrates = wl_a_rates_size,
182};
183
Hante Meulemand48200b2013-04-03 12:40:29 +0200184/* This is to override regulatory domains defined in cfg80211 module (reg.c)
185 * By default world regulatory domain defined in reg.c puts the flags
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200186 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
187 * With respect to these flags, wpa_supplicant doesn't * start p2p
188 * operations on 5GHz channels. All the changes in world regulatory
Hante Meulemand48200b2013-04-03 12:40:29 +0200189 * domain are to be done here.
190 */
191static const struct ieee80211_regdomain brcmf_regdom = {
192 .n_reg_rules = 4,
193 .alpha2 = "99",
194 .reg_rules = {
195 /* IEEE 802.11b/g, channels 1..11 */
196 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
197 /* If any */
198 /* IEEE 802.11 channel 14 - Only JP enables
199 * this and for 802.11b only
200 */
201 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
202 /* IEEE 802.11a, channel 36..64 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200203 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
Hante Meulemand48200b2013-04-03 12:40:29 +0200204 /* IEEE 802.11a, channel 100..165 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200205 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200206};
207
Hante Meuleman240d61a2016-02-17 11:27:10 +0100208/* Note: brcmf_cipher_suites is an array of int defining which cipher suites
209 * are supported. A pointer to this array and the number of entries is passed
210 * on to upper layers. AES_CMAC defines whether or not the driver supports MFP.
211 * So the cipher suite AES_CMAC has to be the last one in the array, and when
212 * device does not support MFP then the number of suites will be decreased by 1
213 */
214static const u32 brcmf_cipher_suites[] = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200215 WLAN_CIPHER_SUITE_WEP40,
216 WLAN_CIPHER_SUITE_WEP104,
217 WLAN_CIPHER_SUITE_TKIP,
218 WLAN_CIPHER_SUITE_CCMP,
Hante Meuleman240d61a2016-02-17 11:27:10 +0100219 /* Keep as last entry: */
220 WLAN_CIPHER_SUITE_AES_CMAC
Arend van Spriel5b435de2011-10-05 13:19:03 +0200221};
222
Hante Meuleman1a873342012-09-27 14:17:54 +0200223/* Vendor specific ie. id = 221, oui and type defines exact ie */
224struct brcmf_vs_tlv {
225 u8 id;
226 u8 len;
227 u8 oui[3];
228 u8 oui_type;
229};
230
231struct parsed_vndr_ie_info {
232 u8 *ie_ptr;
233 u32 ie_len; /* total length including id & length field */
234 struct brcmf_vs_tlv vndrie;
235};
236
237struct parsed_vndr_ies {
238 u32 count;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100239 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
Hante Meuleman1a873342012-09-27 14:17:54 +0200240};
241
Arend van Spriel7705ba62016-04-17 16:44:58 +0200242static u8 nl80211_band_to_fwil(enum nl80211_band band)
243{
244 switch (band) {
245 case NL80211_BAND_2GHZ:
246 return WLC_BAND_2G;
247 case NL80211_BAND_5GHZ:
248 return WLC_BAND_5G;
249 default:
250 WARN_ON(1);
251 break;
252 }
253 return 0;
254}
255
Arend van Spriel5a394eb2014-05-27 12:56:15 +0200256static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
257 struct cfg80211_chan_def *ch)
Arend van Spriel600a8972014-05-12 10:47:39 +0200258{
259 struct brcmu_chan ch_inf;
260 s32 primary_offset;
261
262 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
263 ch->chan->center_freq, ch->center_freq1, ch->width);
264 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
Rafał Miłecki36e80722016-01-20 16:46:04 +0100265 primary_offset = ch->chan->center_freq - ch->center_freq1;
Arend van Spriel600a8972014-05-12 10:47:39 +0200266 switch (ch->width) {
267 case NL80211_CHAN_WIDTH_20:
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100268 case NL80211_CHAN_WIDTH_20_NOHT:
Arend van Spriel600a8972014-05-12 10:47:39 +0200269 ch_inf.bw = BRCMU_CHAN_BW_20;
270 WARN_ON(primary_offset != 0);
271 break;
272 case NL80211_CHAN_WIDTH_40:
273 ch_inf.bw = BRCMU_CHAN_BW_40;
Rafał Miłecki36e80722016-01-20 16:46:04 +0100274 if (primary_offset > 0)
Arend van Spriel600a8972014-05-12 10:47:39 +0200275 ch_inf.sb = BRCMU_CHAN_SB_U;
276 else
277 ch_inf.sb = BRCMU_CHAN_SB_L;
278 break;
279 case NL80211_CHAN_WIDTH_80:
280 ch_inf.bw = BRCMU_CHAN_BW_80;
Rafał Miłecki36e80722016-01-20 16:46:04 +0100281 if (primary_offset == -30)
282 ch_inf.sb = BRCMU_CHAN_SB_LL;
283 else if (primary_offset == -10)
284 ch_inf.sb = BRCMU_CHAN_SB_LU;
285 else if (primary_offset == 10)
286 ch_inf.sb = BRCMU_CHAN_SB_UL;
287 else
288 ch_inf.sb = BRCMU_CHAN_SB_UU;
Arend van Spriel600a8972014-05-12 10:47:39 +0200289 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100290 case NL80211_CHAN_WIDTH_80P80:
291 case NL80211_CHAN_WIDTH_160:
292 case NL80211_CHAN_WIDTH_5:
293 case NL80211_CHAN_WIDTH_10:
Arend van Spriel600a8972014-05-12 10:47:39 +0200294 default:
295 WARN_ON_ONCE(1);
296 }
297 switch (ch->chan->band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200298 case NL80211_BAND_2GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200299 ch_inf.band = BRCMU_CHAN_BAND_2G;
300 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200301 case NL80211_BAND_5GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200302 ch_inf.band = BRCMU_CHAN_BAND_5G;
303 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200304 case NL80211_BAND_60GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200305 default:
306 WARN_ON_ONCE(1);
307 }
308 d11inf->encchspec(&ch_inf);
309
310 return ch_inf.chspec;
311}
312
Franky Lin83cf17a2013-04-11 13:28:50 +0200313u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
314 struct ieee80211_channel *ch)
Arend van Spriel6e186162012-10-22 10:36:22 -0700315{
Franky Lin83cf17a2013-04-11 13:28:50 +0200316 struct brcmu_chan ch_inf;
Arend van Spriel6e186162012-10-22 10:36:22 -0700317
Franky Lin83cf17a2013-04-11 13:28:50 +0200318 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
319 ch_inf.bw = BRCMU_CHAN_BW_20;
320 d11inf->encchspec(&ch_inf);
Arend van Spriel6e186162012-10-22 10:36:22 -0700321
Franky Lin83cf17a2013-04-11 13:28:50 +0200322 return ch_inf.chspec;
Arend van Spriel6e186162012-10-22 10:36:22 -0700323}
324
Hante Meuleman89286dc2013-02-08 15:53:46 +0100325/* Traverse a string of 1-byte tag/1-byte length/variable-length value
326 * triples, returning a pointer to the substring whose first element
327 * matches tag
328 */
Rafał Miłeckic8d87072017-01-18 11:48:51 +0100329static const struct brcmf_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100330brcmf_parse_tlvs(const void *buf, int buflen, uint key)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100331{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100332 const struct brcmf_tlv *elt = buf;
333 int totlen = buflen;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100334
335 /* find tagged parameter */
336 while (totlen >= TLV_HDR_LEN) {
337 int len = elt->len;
338
339 /* validate remaining totlen */
340 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
341 return elt;
342
343 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
344 totlen -= (len + TLV_HDR_LEN);
345 }
346
347 return NULL;
348}
349
350/* Is any of the tlvs the expected entry? If
351 * not update the tlvs buffer pointer/length.
352 */
353static bool
Johannes Berg4b5800f2014-01-15 14:55:59 +0100354brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
355 const u8 *oui, u32 oui_len, u8 type)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100356{
357 /* If the contents match the OUI and the type */
358 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
359 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
360 type == ie[TLV_BODY_OFF + oui_len]) {
361 return true;
362 }
363
364 if (tlvs == NULL)
365 return false;
366 /* point to the next ie */
367 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
368 /* calculate the length of the rest of the buffer */
369 *tlvs_len -= (int)(ie - *tlvs);
370 /* update the pointer to the start of the buffer */
371 *tlvs = ie;
372
373 return false;
374}
375
376static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100377brcmf_find_wpaie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100378{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100379 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100380
381 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
Johannes Berg4b5800f2014-01-15 14:55:59 +0100382 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
Hante Meuleman89286dc2013-02-08 15:53:46 +0100383 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
384 return (struct brcmf_vs_tlv *)ie;
385 }
386 return NULL;
387}
388
389static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100390brcmf_find_wpsie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100391{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100392 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100393
394 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
395 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
396 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
397 return (struct brcmf_vs_tlv *)ie;
398 }
399 return NULL;
400}
401
Arend van Spriel39504a22015-08-20 22:06:05 +0200402static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
403 struct brcmf_cfg80211_vif *vif,
404 enum nl80211_iftype new_type)
405{
Arend van Spriel39504a22015-08-20 22:06:05 +0200406 struct brcmf_cfg80211_vif *pos;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100407 bool check_combos = false;
408 int ret = 0;
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530409 struct iface_combination_params params = {
410 .num_different_channels = 1,
411 };
Arend van Spriel39504a22015-08-20 22:06:05 +0200412
Arend van Spriel39504a22015-08-20 22:06:05 +0200413 list_for_each_entry(pos, &cfg->vif_list, list)
Arend van Spriel353c46a2015-12-10 13:43:06 +0100414 if (pos == vif) {
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530415 params.iftype_num[new_type]++;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100416 } else {
417 /* concurrent interfaces so need check combinations */
418 check_combos = true;
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530419 params.iftype_num[pos->wdev.iftype]++;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100420 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200421
Arend van Spriel353c46a2015-12-10 13:43:06 +0100422 if (check_combos)
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530423 ret = cfg80211_check_combinations(cfg->wiphy, &params);
Arend van Spriel353c46a2015-12-10 13:43:06 +0100424
425 return ret;
Arend van Spriel39504a22015-08-20 22:06:05 +0200426}
427
428static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
429 enum nl80211_iftype new_type)
430{
Arend van Spriel39504a22015-08-20 22:06:05 +0200431 struct brcmf_cfg80211_vif *pos;
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530432 struct iface_combination_params params = {
433 .num_different_channels = 1,
434 };
Arend van Spriel39504a22015-08-20 22:06:05 +0200435
Arend van Spriel39504a22015-08-20 22:06:05 +0200436 list_for_each_entry(pos, &cfg->vif_list, list)
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530437 params.iftype_num[pos->wdev.iftype]++;
Arend van Spriel39504a22015-08-20 22:06:05 +0200438
Purushottam Kushwahae2273002016-10-12 18:25:35 +0530439 params.iftype_num[new_type]++;
440 return cfg80211_check_combinations(cfg->wiphy, &params);
Arend van Spriel39504a22015-08-20 22:06:05 +0200441}
Hante Meuleman89286dc2013-02-08 15:53:46 +0100442
Arend van Spriel5b435de2011-10-05 13:19:03 +0200443static void convert_key_from_CPU(struct brcmf_wsec_key *key,
444 struct brcmf_wsec_key_le *key_le)
445{
446 key_le->index = cpu_to_le32(key->index);
447 key_le->len = cpu_to_le32(key->len);
448 key_le->algo = cpu_to_le32(key->algo);
449 key_le->flags = cpu_to_le32(key->flags);
450 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
451 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
452 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
453 memcpy(key_le->data, key->data, sizeof(key->data));
454 memcpy(key_le->ea, key->ea, sizeof(key->ea));
455}
456
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200457static int
Hante Meuleman118eb302014-12-21 12:43:49 +0100458send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200459{
460 int err;
461 struct brcmf_wsec_key_le key_le;
462
463 convert_key_from_CPU(key, &key_le);
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200464
Hante Meuleman118eb302014-12-21 12:43:49 +0100465 brcmf_netdev_wait_pend8021x(ifp);
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700466
Hante Meuleman118eb302014-12-21 12:43:49 +0100467 err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700468 sizeof(key_le));
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200469
Arend van Spriel5b435de2011-10-05 13:19:03 +0200470 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +0100471 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200472 return err;
473}
474
Hante Meulemanb3657452013-05-27 21:09:53 +0200475static s32
Franky Lin52f22fb2016-02-17 11:26:55 +0100476brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable)
Hante Meulemanb3657452013-05-27 21:09:53 +0200477{
478 s32 err;
479 u32 mode;
480
481 if (enable)
482 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
483 else
484 mode = 0;
485
486 /* Try to set and enable ARP offload feature, this may fail, then it */
487 /* is simply not supported and err 0 will be returned */
488 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
489 if (err) {
490 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
491 mode, err);
492 err = 0;
493 } else {
494 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
495 if (err) {
496 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
497 enable, err);
498 err = 0;
499 } else
500 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
501 enable, mode);
502 }
503
Franky Lin52f22fb2016-02-17 11:26:55 +0100504 err = brcmf_fil_iovar_int_set(ifp, "ndoe", enable);
505 if (err) {
506 brcmf_dbg(TRACE, "failed to configure (%d) ND offload err = %d\n",
507 enable, err);
508 err = 0;
509 } else
510 brcmf_dbg(TRACE, "successfully configured (%d) ND offload to 0x%x\n",
511 enable, mode);
512
Hante Meulemanb3657452013-05-27 21:09:53 +0200513 return err;
514}
515
Hante Meuleman8851cce2014-07-30 13:20:02 +0200516static void
517brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
518{
Arend van Spriel8f2b4592014-09-11 22:51:32 +0200519 struct brcmf_cfg80211_vif *vif;
520 struct brcmf_if *ifp;
521
522 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
523 ifp = vif->ifp;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200524
525 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
526 (wdev->iftype == NL80211_IFTYPE_AP) ||
527 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
528 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
529 ADDR_DIRECT);
530 else
531 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
532 ADDR_INDIRECT);
533}
534
Rafał Miłeckid02fb8f2016-05-26 01:44:27 +0200535static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr)
536{
537 int bsscfgidx;
538
539 for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) {
540 /* bsscfgidx 1 is reserved for legacy P2P */
541 if (bsscfgidx == 1)
542 continue;
543 if (!drvr->iflist[bsscfgidx])
544 return bsscfgidx;
545 }
546
547 return -ENOMEM;
548}
549
Hante Meulemana44aa402014-12-03 21:05:33 +0100550static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
551{
552 struct brcmf_mbss_ssid_le mbss_ssid_le;
553 int bsscfgidx;
554 int err;
555
556 memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
Rafał Miłeckid02fb8f2016-05-26 01:44:27 +0200557 bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr);
Hante Meulemana44aa402014-12-03 21:05:33 +0100558 if (bsscfgidx < 0)
559 return bsscfgidx;
560
561 mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
562 mbss_ssid_le.SSID_len = cpu_to_le32(5);
563 sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
564
565 err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
566 sizeof(mbss_ssid_le));
567 if (err < 0)
568 brcmf_err("setting ssid failed %d\n", err);
569
570 return err;
571}
572
573/**
574 * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
575 *
576 * @wiphy: wiphy device of new interface.
577 * @name: name of the new interface.
578 * @flags: not used.
579 * @params: contains mac address for AP device.
580 */
581static
582struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
583 u32 *flags, struct vif_params *params)
584{
585 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
586 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
587 struct brcmf_cfg80211_vif *vif;
588 int err;
589
590 if (brcmf_cfg80211_vif_event_armed(cfg))
591 return ERR_PTR(-EBUSY);
592
593 brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
594
Rafał Miłecki26072332016-06-06 23:03:55 +0200595 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP);
Hante Meulemana44aa402014-12-03 21:05:33 +0100596 if (IS_ERR(vif))
597 return (struct wireless_dev *)vif;
598
599 brcmf_cfg80211_arm_vif_event(cfg, vif);
600
601 err = brcmf_cfg80211_request_ap_if(ifp);
602 if (err) {
603 brcmf_cfg80211_arm_vif_event(cfg, NULL);
604 goto fail;
605 }
606
607 /* wait for firmware event */
Arend van Spriela9eb0c42016-02-17 11:26:50 +0100608 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD,
609 BRCMF_VIF_EVENT_TIMEOUT);
Hante Meulemana44aa402014-12-03 21:05:33 +0100610 brcmf_cfg80211_arm_vif_event(cfg, NULL);
611 if (!err) {
612 brcmf_err("timeout occurred\n");
613 err = -EIO;
614 goto fail;
615 }
616
617 /* interface created in firmware */
618 ifp = vif->ifp;
619 if (!ifp) {
620 brcmf_err("no if pointer provided\n");
621 err = -ENOENT;
622 goto fail;
623 }
624
625 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
626 err = brcmf_net_attach(ifp, true);
627 if (err) {
628 brcmf_err("Registering netdevice failed\n");
629 goto fail;
630 }
631
632 return &ifp->vif->wdev;
633
634fail:
635 brcmf_free_vif(vif);
636 return ERR_PTR(err);
637}
638
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100639static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
640{
641 enum nl80211_iftype iftype;
642
643 iftype = vif->wdev.iftype;
644 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
645}
646
647static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
648{
649 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
650}
651
Arend van Spriel9f440b72013-02-08 15:53:36 +0100652static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
653 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100654 unsigned char name_assign_type,
Arend van Spriel9f440b72013-02-08 15:53:36 +0100655 enum nl80211_iftype type,
656 u32 *flags,
657 struct vif_params *params)
658{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200659 struct wireless_dev *wdev;
Arend van Spriel39504a22015-08-20 22:06:05 +0200660 int err;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200661
Arend van Spriel9f440b72013-02-08 15:53:36 +0100662 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
Arend van Spriel39504a22015-08-20 22:06:05 +0200663 err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
664 if (err) {
665 brcmf_err("iface validation failed: err=%d\n", err);
666 return ERR_PTR(err);
667 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100668 switch (type) {
669 case NL80211_IFTYPE_ADHOC:
670 case NL80211_IFTYPE_STATION:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100671 case NL80211_IFTYPE_AP_VLAN:
672 case NL80211_IFTYPE_WDS:
673 case NL80211_IFTYPE_MONITOR:
674 case NL80211_IFTYPE_MESH_POINT:
675 return ERR_PTR(-EOPNOTSUPP);
Hante Meulemana44aa402014-12-03 21:05:33 +0100676 case NL80211_IFTYPE_AP:
677 wdev = brcmf_ap_add_vif(wiphy, name, flags, params);
Rafał Miłecki0cd33c22016-05-27 10:54:28 +0200678 break;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100679 case NL80211_IFTYPE_P2P_CLIENT:
680 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200681 case NL80211_IFTYPE_P2P_DEVICE:
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100682 wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, flags, params);
Rafał Miłecki0cd33c22016-05-27 10:54:28 +0200683 break;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100684 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100685 default:
686 return ERR_PTR(-EINVAL);
687 }
Rafał Miłecki0cd33c22016-05-27 10:54:28 +0200688
689 if (IS_ERR(wdev))
690 brcmf_err("add iface %s type %d failed: err=%d\n",
691 name, type, (int)PTR_ERR(wdev));
692 else
693 brcmf_cfg80211_update_proto_addr_mode(wdev);
694
695 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100696}
697
Daniel Kim5e787f72014-06-21 12:11:18 +0200698static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
699{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200700 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200701 brcmf_set_mpc(ifp, mpc);
702}
703
Arend van Sprielf96aa072013-04-05 10:57:48 +0200704void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100705{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100706 s32 err = 0;
707
708 if (check_vif_up(ifp->vif)) {
709 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
710 if (err) {
711 brcmf_err("fail to set mpc\n");
712 return;
713 }
714 brcmf_dbg(INFO, "MPC : %d\n", mpc);
715 }
716}
717
Arend van Spriela0f472a2013-04-05 10:57:49 +0200718s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
719 struct brcmf_if *ifp, bool aborted,
720 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100721{
722 struct brcmf_scan_params_le params_le;
723 struct cfg80211_scan_request *scan_request;
724 s32 err = 0;
725
726 brcmf_dbg(SCAN, "Enter\n");
727
728 /* clear scan request, because the FW abort can cause a second call */
729 /* to this functon and might cause a double cfg80211_scan_done */
730 scan_request = cfg->scan_request;
731 cfg->scan_request = NULL;
732
733 if (timer_pending(&cfg->escan_timeout))
734 del_timer_sync(&cfg->escan_timeout);
735
736 if (fw_abort) {
737 /* Do a scan abort to stop the driver's scan engine */
738 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
739 memset(&params_le, 0, sizeof(params_le));
Joe Perches93803b32015-03-02 19:54:49 -0800740 eth_broadcast_addr(params_le.bssid);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100741 params_le.bss_type = DOT11_BSSTYPE_ANY;
742 params_le.scan_type = 0;
743 params_le.channel_num = cpu_to_le32(1);
744 params_le.nprobes = cpu_to_le32(1);
745 params_le.active_time = cpu_to_le32(-1);
746 params_le.passive_time = cpu_to_le32(-1);
747 params_le.home_time = cpu_to_le32(-1);
748 /* Scan is aborted by setting channel_list[0] to -1 */
749 params_le.channel_list[0] = cpu_to_le16(-1);
750 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200751 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100752 &params_le, sizeof(params_le));
753 if (err)
754 brcmf_err("Scan abort failed\n");
755 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200756
Daniel Kim5e787f72014-06-21 12:11:18 +0200757 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200758
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100759 /*
Arend Van Sprielfa85b302016-11-23 10:25:25 +0000760 * e-scan can be initiated internally
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100761 * which takes precedence.
762 */
Arend Van Sprielfa85b302016-11-23 10:25:25 +0000763 if (cfg->internal_escan) {
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100764 brcmf_dbg(SCAN, "scheduled scan completed\n");
Arend Van Sprielfa85b302016-11-23 10:25:25 +0000765 cfg->internal_escan = false;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100766 if (!aborted)
767 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100768 } else if (scan_request) {
Avraham Stern1d762502016-07-05 17:10:13 +0300769 struct cfg80211_scan_info info = {
770 .aborted = aborted,
771 };
772
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100773 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
774 aborted ? "Aborted" : "Done");
Avraham Stern1d762502016-07-05 17:10:13 +0300775 cfg80211_scan_done(scan_request, &info);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100776 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100777 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
778 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100779
780 return err;
781}
782
Rafał Miłeckidba8fbc2016-06-29 21:54:27 +0200783static int brcmf_cfg80211_del_ap_iface(struct wiphy *wiphy,
784 struct wireless_dev *wdev)
785{
786 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
787 struct net_device *ndev = wdev->netdev;
788 struct brcmf_if *ifp = netdev_priv(ndev);
789 int ret;
790 int err;
791
792 brcmf_cfg80211_arm_vif_event(cfg, ifp->vif);
793
794 err = brcmf_fil_bsscfg_data_set(ifp, "interface_remove", NULL, 0);
795 if (err) {
796 brcmf_err("interface_remove failed %d\n", err);
797 goto err_unarm;
798 }
799
800 /* wait for firmware event */
801 ret = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_DEL,
802 BRCMF_VIF_EVENT_TIMEOUT);
803 if (!ret) {
804 brcmf_err("timeout occurred\n");
805 err = -EIO;
806 goto err_unarm;
807 }
808
809 brcmf_remove_interface(ifp, true);
810
811err_unarm:
812 brcmf_cfg80211_arm_vif_event(cfg, NULL);
813 return err;
814}
815
Arend van Spriel9f440b72013-02-08 15:53:36 +0100816static
817int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
818{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100819 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
820 struct net_device *ndev = wdev->netdev;
821
Rafał Miłeckidba8fbc2016-06-29 21:54:27 +0200822 if (ndev && ndev == cfg_to_ndev(cfg))
823 return -ENOTSUPP;
824
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100825 /* vif event pending in firmware */
826 if (brcmf_cfg80211_vif_event_armed(cfg))
827 return -EBUSY;
828
829 if (ndev) {
830 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200831 cfg->escan_info.ifp == netdev_priv(ndev))
832 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
833 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100834
835 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
836 }
837
Arend van Spriel9f440b72013-02-08 15:53:36 +0100838 switch (wdev->iftype) {
839 case NL80211_IFTYPE_ADHOC:
840 case NL80211_IFTYPE_STATION:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100841 case NL80211_IFTYPE_AP_VLAN:
842 case NL80211_IFTYPE_WDS:
843 case NL80211_IFTYPE_MONITOR:
844 case NL80211_IFTYPE_MESH_POINT:
845 return -EOPNOTSUPP;
Rafał Miłeckidba8fbc2016-06-29 21:54:27 +0200846 case NL80211_IFTYPE_AP:
847 return brcmf_cfg80211_del_ap_iface(wiphy, wdev);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100848 case NL80211_IFTYPE_P2P_CLIENT:
849 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200850 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100851 return brcmf_p2p_del_vif(wiphy, wdev);
852 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100853 default:
854 return -EINVAL;
855 }
856 return -EOPNOTSUPP;
857}
858
Arend van Spriel5b435de2011-10-05 13:19:03 +0200859static s32
860brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
861 enum nl80211_iftype type, u32 *flags,
862 struct vif_params *params)
863{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100864 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700865 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100866 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200867 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200868 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200869 s32 err = 0;
870
Hante Meuleman37a869e2015-10-29 20:33:17 +0100871 brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx,
872 type);
Hante Meuleman178e9ef2015-09-18 22:08:11 +0200873
874 /* WAR: There are a number of p2p interface related problems which
875 * need to be handled initially (before doing the validate).
876 * wpa_supplicant tends to do iface changes on p2p device/client/go
877 * which are not always possible/allowed. However we need to return
878 * OK otherwise the wpa_supplicant wont start. The situation differs
879 * on configuration and setup (p2pon=1 module param). The first check
880 * is to see if the request is a change to station for p2p iface.
881 */
882 if ((type == NL80211_IFTYPE_STATION) &&
883 ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
884 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) ||
885 (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) {
886 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
887 /* Now depending on whether module param p2pon=1 was used the
888 * response needs to be either 0 or EOPNOTSUPP. The reason is
889 * that if p2pon=1 is used, but a newer supplicant is used then
890 * we should return an error, as this combination wont work.
891 * In other situations 0 is returned and supplicant will start
892 * normally. It will give a trace in cfg80211, but it is the
893 * only way to get it working. Unfortunately this will result
894 * in situation where we wont support new supplicant in
895 * combination with module param p2pon=1, but that is the way
896 * it is. If the user tries this then unloading of driver might
897 * fail/lock.
898 */
899 if (cfg->p2p.p2pdev_dynamically)
900 return -EOPNOTSUPP;
901 else
902 return 0;
903 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200904 err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
905 if (err) {
906 brcmf_err("iface validation failed: err=%d\n", err);
907 return err;
908 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200909 switch (type) {
910 case NL80211_IFTYPE_MONITOR:
911 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100912 brcmf_err("type (%d) : currently we do not support this type\n",
913 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200914 return -EOPNOTSUPP;
915 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200916 infra = 0;
917 break;
918 case NL80211_IFTYPE_STATION:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200919 infra = 1;
920 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200921 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100922 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200923 ap = 1;
924 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200925 default:
926 err = -EINVAL;
927 goto done;
928 }
929
Hante Meuleman1a873342012-09-27 14:17:54 +0200930 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100931 if (type == NL80211_IFTYPE_P2P_GO) {
932 brcmf_dbg(INFO, "IF Type = P2P GO\n");
933 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
934 }
935 if (!err) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100936 brcmf_dbg(INFO, "IF Type = AP\n");
937 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200938 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100939 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200940 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100941 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200942 err = -EAGAIN;
943 goto done;
944 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100945 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100946 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200947 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200948 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200949
Hante Meuleman8851cce2014-07-30 13:20:02 +0200950 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
951
Arend van Spriel5b435de2011-10-05 13:19:03 +0200952done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100953 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200954
955 return err;
956}
957
Franky Lin83cf17a2013-04-11 13:28:50 +0200958static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
959 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200960 struct cfg80211_scan_request *request)
961{
962 u32 n_ssids;
963 u32 n_channels;
964 s32 i;
965 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200966 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200967 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200968 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200969
Joe Perches93803b32015-03-02 19:54:49 -0800970 eth_broadcast_addr(params_le->bssid);
Hante Meulemane756af52012-09-11 21:18:52 +0200971 params_le->bss_type = DOT11_BSSTYPE_ANY;
972 params_le->scan_type = 0;
973 params_le->channel_num = 0;
974 params_le->nprobes = cpu_to_le32(-1);
975 params_le->active_time = cpu_to_le32(-1);
976 params_le->passive_time = cpu_to_le32(-1);
977 params_le->home_time = cpu_to_le32(-1);
978 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
979
980 /* if request is null exit so it will be all channel broadcast scan */
981 if (!request)
982 return;
983
984 n_ssids = request->n_ssids;
985 n_channels = request->n_channels;
986 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100987 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
988 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200989 if (n_channels > 0) {
990 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200991 chanspec = channel_to_chanspec(&cfg->d11inf,
992 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100993 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
994 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200995 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200996 }
997 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100998 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200999 }
1000 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001001 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +02001002 if (n_ssids > 0) {
1003 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
1004 n_channels * sizeof(u16);
1005 offset = roundup(offset, sizeof(u32));
1006 ptr = (char *)params_le + offset;
1007 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +02001008 memset(&ssid_le, 0, sizeof(ssid_le));
1009 ssid_le.SSID_len =
1010 cpu_to_le32(request->ssids[i].ssid_len);
1011 memcpy(ssid_le.SSID, request->ssids[i].ssid,
1012 request->ssids[i].ssid_len);
1013 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001014 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +02001015 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001016 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
1017 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +02001018 memcpy(ptr, &ssid_le, sizeof(ssid_le));
1019 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +02001020 }
1021 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001022 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +02001023 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001024 brcmf_dbg(SCAN, "SSID %s len=%d\n",
1025 params_le->ssid_le.SSID,
1026 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +02001027 params_le->ssid_le.SSID_len =
1028 cpu_to_le32(request->ssids->ssid_len);
1029 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
1030 request->ssids->ssid_len);
1031 }
1032 }
1033 /* Adding mask to channel numbers */
1034 params_le->channel_num =
1035 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
1036 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
1037}
1038
1039static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001040brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemanc4958102015-11-25 11:32:41 +01001041 struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +02001042{
1043 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
1044 offsetof(struct brcmf_escan_params_le, params_le);
1045 struct brcmf_escan_params_le *params;
1046 s32 err = 0;
1047
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001048 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001049
1050 if (request != NULL) {
1051 /* Allocate space for populating ssids in struct */
1052 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
1053
1054 /* Allocate space for populating ssids in struct */
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001055 params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids;
Hante Meulemane756af52012-09-11 21:18:52 +02001056 }
1057
1058 params = kzalloc(params_size, GFP_KERNEL);
1059 if (!params) {
1060 err = -ENOMEM;
1061 goto exit;
1062 }
1063 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +02001064 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +02001065 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
Hante Meulemanc4958102015-11-25 11:32:41 +01001066 params->action = cpu_to_le16(WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +02001067 params->sync_id = cpu_to_le16(0x1234);
1068
Arend van Spriela0f472a2013-04-05 10:57:49 +02001069 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +02001070 if (err) {
1071 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001072 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001073 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001074 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001075 }
1076
1077 kfree(params);
1078exit:
1079 return err;
1080}
1081
1082static s32
Arend Van Sprielab5981c2016-11-23 10:25:24 +00001083brcmf_do_escan(struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +02001084{
Arend Van Sprielab5981c2016-11-23 10:25:24 +00001085 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02001086 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001087 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001088 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001089 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +02001090
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001091 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001092 escan->ifp = ifp;
Arend Van Sprielab5981c2016-11-23 10:25:24 +00001093 escan->wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001094 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001095 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +02001096 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001097 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001098 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001099 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001100 return err;
1101 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001102 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001103 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02001104 results->version = 0;
1105 results->count = 0;
1106 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
1107
Hante Meulemanc4958102015-11-25 11:32:41 +01001108 err = escan->run(cfg, ifp, request);
Hante Meulemane756af52012-09-11 21:18:52 +02001109 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +02001110 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001111 return err;
1112}
1113
1114static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001115brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +02001116 struct cfg80211_scan_request *request,
1117 struct cfg80211_ssid *this_ssid)
1118{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001119 struct brcmf_if *ifp = vif->ifp;
1120 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +02001121 struct cfg80211_ssid *ssids;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001122 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001123 bool escan_req;
1124 bool spec_scan;
1125 s32 err;
Hante Meuleman675f5d82015-12-10 13:43:01 +01001126 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +02001127 u32 SSID_len;
1128
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001129 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001130
Arend van Sprielc1179032012-10-22 13:55:33 -07001131 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001132 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001133 return -EAGAIN;
1134 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001135 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001136 brcmf_err("Scanning being aborted: status (%lu)\n",
1137 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001138 return -EAGAIN;
1139 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02001140 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
1141 brcmf_err("Scanning suppressed: status (%lu)\n",
1142 cfg->scan_status);
1143 return -EAGAIN;
1144 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001145 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001146 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +02001147 return -EAGAIN;
1148 }
1149
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001150 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001151 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
1152 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001153
Hante Meulemane756af52012-09-11 21:18:52 +02001154 escan_req = false;
1155 if (request) {
1156 /* scan bss */
1157 ssids = request->ssids;
1158 escan_req = true;
1159 } else {
1160 /* scan in ibss */
1161 /* we don't do escan in ibss */
1162 ssids = this_ssid;
1163 }
1164
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001165 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -07001166 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001167 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +01001168 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001169 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001170 if (err)
1171 goto scan_out;
1172
Arend Van Sprielab5981c2016-11-23 10:25:24 +00001173 err = brcmf_do_escan(vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -08001174 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +02001175 goto scan_out;
1176 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001177 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
1178 ssids->ssid, ssids->ssid_len);
Hante Meuleman675f5d82015-12-10 13:43:01 +01001179 memset(&ssid_le, 0, sizeof(ssid_le));
1180 SSID_len = min_t(u8, sizeof(ssid_le.SSID), ssids->ssid_len);
1181 ssid_le.SSID_len = cpu_to_le32(0);
Hante Meulemane756af52012-09-11 21:18:52 +02001182 spec_scan = false;
1183 if (SSID_len) {
Hante Meuleman675f5d82015-12-10 13:43:01 +01001184 memcpy(ssid_le.SSID, ssids->ssid, SSID_len);
1185 ssid_le.SSID_len = cpu_to_le32(SSID_len);
Hante Meulemane756af52012-09-11 21:18:52 +02001186 spec_scan = true;
1187 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001188 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001189
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001190 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -07001191 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001192 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001193 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001194 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001195 goto scan_out;
1196 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001197 brcmf_scan_config_mpc(ifp, 0);
Hante Meuleman675f5d82015-12-10 13:43:01 +01001198 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &ssid_le,
1199 sizeof(ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001200 if (err) {
1201 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001202 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
Hante Meuleman675f5d82015-12-10 13:43:01 +01001203 ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001204 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001205 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001206
Daniel Kim5e787f72014-06-21 12:11:18 +02001207 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001208 goto scan_out;
1209 }
1210 }
1211
Hante Meuleman661fa952015-02-06 18:36:47 +01001212 /* Arm scan timeout timer */
1213 mod_timer(&cfg->escan_timeout, jiffies +
Hante Meulemand5367332016-02-17 11:26:51 +01001214 BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
Hante Meuleman661fa952015-02-06 18:36:47 +01001215
Hante Meulemane756af52012-09-11 21:18:52 +02001216 return 0;
1217
1218scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001219 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001220 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001221 return err;
1222}
1223
Arend van Spriel5b435de2011-10-05 13:19:03 +02001224static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001225brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001226{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001227 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001228 s32 err = 0;
1229
Arend van Sprield96b8012012-12-05 15:26:02 +01001230 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001231 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1232 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001233 return -EIO;
1234
Arend van Spriela0f472a2013-04-05 10:57:49 +02001235 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001236
Arend van Spriel5b435de2011-10-05 13:19:03 +02001237 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001238 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001239
Arend van Sprield96b8012012-12-05 15:26:02 +01001240 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001241 return err;
1242}
1243
1244static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1245{
1246 s32 err = 0;
1247
Arend van Sprielac24be62012-10-22 10:36:23 -07001248 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1249 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001250 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001251 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001252
1253 return err;
1254}
1255
1256static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1257{
1258 s32 err = 0;
1259
Arend van Sprielac24be62012-10-22 10:36:23 -07001260 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1261 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001262 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001263 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001264
1265 return err;
1266}
1267
1268static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1269{
1270 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001271 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001272
Arend van Sprielac24be62012-10-22 10:36:23 -07001273 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001274 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001275 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001276 return err;
1277 }
1278 return err;
1279}
1280
1281static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1282{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001283 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1284 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001285 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001286 s32 err = 0;
1287
Arend van Sprield96b8012012-12-05 15:26:02 +01001288 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001289 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001290 return -EIO;
1291
1292 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001293 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1294 cfg->conf->rts_threshold = wiphy->rts_threshold;
1295 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001296 if (!err)
1297 goto done;
1298 }
1299 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001300 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1301 cfg->conf->frag_threshold = wiphy->frag_threshold;
1302 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001303 if (!err)
1304 goto done;
1305 }
1306 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001307 && (cfg->conf->retry_long != wiphy->retry_long)) {
1308 cfg->conf->retry_long = wiphy->retry_long;
1309 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001310 if (!err)
1311 goto done;
1312 }
1313 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001314 && (cfg->conf->retry_short != wiphy->retry_short)) {
1315 cfg->conf->retry_short = wiphy->retry_short;
1316 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001317 if (!err)
1318 goto done;
1319 }
1320
1321done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001322 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001323 return err;
1324}
1325
Arend van Spriel5b435de2011-10-05 13:19:03 +02001326static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1327{
1328 memset(prof, 0, sizeof(*prof));
1329}
1330
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001331static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
1332{
1333 u16 reason;
1334
1335 switch (e->event_code) {
1336 case BRCMF_E_DEAUTH:
1337 case BRCMF_E_DEAUTH_IND:
1338 case BRCMF_E_DISASSOC_IND:
1339 reason = e->reason;
1340 break;
1341 case BRCMF_E_LINK:
1342 default:
1343 reason = 0;
1344 break;
1345 }
1346 return reason;
1347}
1348
1349static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001350{
Piotr Haber61730d42013-04-23 12:53:12 +02001351 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001352 s32 err = 0;
1353
Arend van Sprield96b8012012-12-05 15:26:02 +01001354 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001355
Hante Meulemanb0a79082015-12-10 13:43:07 +01001356 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001357 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001358 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001359 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001360 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001361 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001362 }
Hante Meulemanb0a79082015-12-10 13:43:07 +01001363 if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) ||
1364 (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT))
1365 cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
1366 true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001367 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001368 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001369 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1370 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001371 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001372}
1373
1374static s32
1375brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1376 struct cfg80211_ibss_params *params)
1377{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001378 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001379 struct brcmf_if *ifp = netdev_priv(ndev);
1380 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001381 struct brcmf_join_params join_params;
1382 size_t join_params_size = 0;
1383 s32 err = 0;
1384 s32 wsec = 0;
1385 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001386 u16 chanspec;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001387 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001388
Arend van Sprield96b8012012-12-05 15:26:02 +01001389 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001390 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001391 return -EIO;
1392
1393 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001394 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001395 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001396 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001397 return -EOPNOTSUPP;
1398 }
1399
Arend van Sprielc1179032012-10-22 13:55:33 -07001400 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001401
1402 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001403 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001404 else
Arend van Spriel16886732012-12-05 15:26:04 +01001405 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001406
Johannes Berg683b6d32012-11-08 21:25:48 +01001407 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001408 brcmf_dbg(CONN, "channel: %d\n",
1409 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001410 else
Arend van Spriel16886732012-12-05 15:26:04 +01001411 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001412
1413 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001414 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001415 else
Arend van Spriel16886732012-12-05 15:26:04 +01001416 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001417
1418 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001419 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001420 else
Arend van Spriel16886732012-12-05 15:26:04 +01001421 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001422
1423 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001424 brcmf_dbg(CONN, "beacon interval: %d\n",
1425 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001426 else
Arend van Spriel16886732012-12-05 15:26:04 +01001427 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001428
1429 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001430 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001431 else
Arend van Spriel16886732012-12-05 15:26:04 +01001432 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001433
1434 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001435 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001436 else
Arend van Spriel16886732012-12-05 15:26:04 +01001437 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001438
1439 /* Configure Privacy for starter */
1440 if (params->privacy)
1441 wsec |= WEP_ENABLED;
1442
Arend van Sprielc1179032012-10-22 13:55:33 -07001443 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001444 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001445 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001446 goto done;
1447 }
1448
1449 /* Configure Beacon Interval for starter */
1450 if (params->beacon_interval)
1451 bcnprd = params->beacon_interval;
1452 else
1453 bcnprd = 100;
1454
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001455 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001456 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001457 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001458 goto done;
1459 }
1460
1461 /* Configure required join parameter */
1462 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1463
1464 /* SSID */
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001465 ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN);
1466 memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len);
1467 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001468 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001469
1470 /* BSSID */
1471 if (params->bssid) {
1472 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001473 join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001474 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001475 } else {
Joe Perches93803b32015-03-02 19:54:49 -08001476 eth_broadcast_addr(join_params.params_le.bssid);
1477 eth_zero_addr(profile->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001478 }
1479
Arend van Spriel5b435de2011-10-05 13:19:03 +02001480 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001481 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001482 u32 target_channel;
1483
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001484 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001485 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001486 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001487 if (params->channel_fixed) {
1488 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001489 chanspec = chandef_to_chanspec(&cfg->d11inf,
1490 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001491 join_params.params_le.chanspec_list[0] =
1492 cpu_to_le16(chanspec);
1493 join_params.params_le.chanspec_num = cpu_to_le32(1);
1494 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001495 }
1496
1497 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001498 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001499 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001500 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001501 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001502 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001503 goto done;
1504 }
1505 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001506 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001507
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001508 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001509
1510
Arend van Sprielc1179032012-10-22 13:55:33 -07001511 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001512 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001513 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001514 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001515 goto done;
1516 }
1517
1518done:
1519 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001520 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001521 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001522 return err;
1523}
1524
1525static s32
1526brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1527{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001528 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001529
Arend van Sprield96b8012012-12-05 15:26:02 +01001530 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman6a98d642016-01-02 09:41:40 +01001531 if (!check_vif_up(ifp->vif)) {
1532 /* When driver is being unloaded, it can end up here. If an
1533 * error is returned then later on a debug trace in the wireless
1534 * core module will be printed. To avoid this 0 is returned.
1535 */
1536 return 0;
1537 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001538
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001539 brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01001540 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001541
Arend van Sprield96b8012012-12-05 15:26:02 +01001542 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001543
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001544 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001545}
1546
1547static s32 brcmf_set_wpa_version(struct net_device *ndev,
1548 struct cfg80211_connect_params *sme)
1549{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001550 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001551 struct brcmf_cfg80211_security *sec;
1552 s32 val = 0;
1553 s32 err = 0;
1554
1555 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1556 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1557 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1558 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1559 else
1560 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001561 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001562 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001563 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001564 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001565 return err;
1566 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001567 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001568 sec->wpa_versions = sme->crypto.wpa_versions;
1569 return err;
1570}
1571
1572static s32 brcmf_set_auth_type(struct net_device *ndev,
1573 struct cfg80211_connect_params *sme)
1574{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001575 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001576 struct brcmf_cfg80211_security *sec;
1577 s32 val = 0;
1578 s32 err = 0;
1579
1580 switch (sme->auth_type) {
1581 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1582 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001583 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001584 break;
1585 case NL80211_AUTHTYPE_SHARED_KEY:
1586 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001587 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001588 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001589 default:
1590 val = 2;
Hante Meuleman92c31362016-09-19 12:09:59 +01001591 brcmf_dbg(CONN, "automatic, auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001592 break;
1593 }
1594
Hante Meuleman89286dc2013-02-08 15:53:46 +01001595 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001596 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001597 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001598 return err;
1599 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001600 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001601 sec->auth_type = sme->auth_type;
1602 return err;
1603}
1604
1605static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001606brcmf_set_wsec_mode(struct net_device *ndev,
Hante Meuleman240d61a2016-02-17 11:27:10 +01001607 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001608{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001609 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001610 struct brcmf_cfg80211_security *sec;
1611 s32 pval = 0;
1612 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001613 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001614 s32 err = 0;
1615
1616 if (sme->crypto.n_ciphers_pairwise) {
1617 switch (sme->crypto.ciphers_pairwise[0]) {
1618 case WLAN_CIPHER_SUITE_WEP40:
1619 case WLAN_CIPHER_SUITE_WEP104:
1620 pval = WEP_ENABLED;
1621 break;
1622 case WLAN_CIPHER_SUITE_TKIP:
1623 pval = TKIP_ENABLED;
1624 break;
1625 case WLAN_CIPHER_SUITE_CCMP:
1626 pval = AES_ENABLED;
1627 break;
1628 case WLAN_CIPHER_SUITE_AES_CMAC:
1629 pval = AES_ENABLED;
1630 break;
1631 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001632 brcmf_err("invalid cipher pairwise (%d)\n",
1633 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001634 return -EINVAL;
1635 }
1636 }
1637 if (sme->crypto.cipher_group) {
1638 switch (sme->crypto.cipher_group) {
1639 case WLAN_CIPHER_SUITE_WEP40:
1640 case WLAN_CIPHER_SUITE_WEP104:
1641 gval = WEP_ENABLED;
1642 break;
1643 case WLAN_CIPHER_SUITE_TKIP:
1644 gval = TKIP_ENABLED;
1645 break;
1646 case WLAN_CIPHER_SUITE_CCMP:
1647 gval = AES_ENABLED;
1648 break;
1649 case WLAN_CIPHER_SUITE_AES_CMAC:
1650 gval = AES_ENABLED;
1651 break;
1652 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001653 brcmf_err("invalid cipher group (%d)\n",
1654 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001655 return -EINVAL;
1656 }
1657 }
1658
Arend van Spriel16886732012-12-05 15:26:04 +01001659 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001660 /* In case of privacy, but no security and WPS then simulate */
1661 /* setting AES. WPS-2.0 allows no security */
1662 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1663 sme->privacy)
1664 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001665
Hante Meuleman240d61a2016-02-17 11:27:10 +01001666 wsec = pval | gval;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001667 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001668 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001669 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001670 return err;
1671 }
1672
Arend van Spriel06bb1232012-09-27 14:17:56 +02001673 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001674 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1675 sec->cipher_group = sme->crypto.cipher_group;
1676
1677 return err;
1678}
1679
1680static s32
1681brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1682{
Hante Meuleman240d61a2016-02-17 11:27:10 +01001683 struct brcmf_if *ifp = netdev_priv(ndev);
1684 s32 val;
1685 s32 err;
1686 const struct brcmf_tlv *rsn_ie;
1687 const u8 *ie;
1688 u32 ie_len;
1689 u32 offset;
1690 u16 rsn_cap;
1691 u32 mfp;
1692 u16 count;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001693
Hante Meuleman240d61a2016-02-17 11:27:10 +01001694 if (!sme->crypto.n_akm_suites)
1695 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001696
Hante Meuleman240d61a2016-02-17 11:27:10 +01001697 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val);
1698 if (err) {
1699 brcmf_err("could not get wpa_auth (%d)\n", err);
1700 return err;
1701 }
1702 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1703 switch (sme->crypto.akm_suites[0]) {
1704 case WLAN_AKM_SUITE_8021X:
1705 val = WPA_AUTH_UNSPECIFIED;
1706 break;
1707 case WLAN_AKM_SUITE_PSK:
1708 val = WPA_AUTH_PSK;
1709 break;
1710 default:
1711 brcmf_err("invalid cipher group (%d)\n",
1712 sme->crypto.cipher_group);
1713 return -EINVAL;
1714 }
1715 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1716 switch (sme->crypto.akm_suites[0]) {
1717 case WLAN_AKM_SUITE_8021X:
1718 val = WPA2_AUTH_UNSPECIFIED;
1719 break;
1720 case WLAN_AKM_SUITE_8021X_SHA256:
1721 val = WPA2_AUTH_1X_SHA256;
1722 break;
1723 case WLAN_AKM_SUITE_PSK_SHA256:
1724 val = WPA2_AUTH_PSK_SHA256;
1725 break;
1726 case WLAN_AKM_SUITE_PSK:
1727 val = WPA2_AUTH_PSK;
1728 break;
1729 default:
1730 brcmf_err("invalid cipher group (%d)\n",
1731 sme->crypto.cipher_group);
1732 return -EINVAL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001733 }
1734 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01001735
1736 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
1737 goto skip_mfp_config;
1738 /* The MFP mode (1 or 2) needs to be determined, parse IEs. The
1739 * IE will not be verified, just a quick search for MFP config
1740 */
1741 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len,
1742 WLAN_EID_RSN);
1743 if (!rsn_ie)
1744 goto skip_mfp_config;
1745 ie = (const u8 *)rsn_ie;
1746 ie_len = rsn_ie->len + TLV_HDR_LEN;
1747 /* Skip unicast suite */
1748 offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN;
1749 if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
1750 goto skip_mfp_config;
1751 /* Skip multicast suite */
1752 count = ie[offset] + (ie[offset + 1] << 8);
1753 offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
1754 if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
1755 goto skip_mfp_config;
1756 /* Skip auth key management suite(s) */
1757 count = ie[offset] + (ie[offset + 1] << 8);
1758 offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
1759 if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len)
1760 goto skip_mfp_config;
1761 /* Ready to read capabilities */
1762 mfp = BRCMF_MFP_NONE;
1763 rsn_cap = ie[offset] + (ie[offset + 1] << 8);
1764 if (rsn_cap & RSN_CAP_MFPR_MASK)
1765 mfp = BRCMF_MFP_REQUIRED;
1766 else if (rsn_cap & RSN_CAP_MFPC_MASK)
1767 mfp = BRCMF_MFP_CAPABLE;
1768 brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp);
1769
1770skip_mfp_config:
1771 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
1772 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
1773 if (err) {
1774 brcmf_err("could not set wpa_auth (%d)\n", err);
1775 return err;
1776 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001777
1778 return err;
1779}
1780
1781static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001782brcmf_set_sharedkey(struct net_device *ndev,
1783 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001784{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001785 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001786 struct brcmf_cfg80211_security *sec;
1787 struct brcmf_wsec_key key;
1788 s32 val;
1789 s32 err = 0;
1790
Arend van Spriel16886732012-12-05 15:26:04 +01001791 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001792
Roland Vossena718e2f2011-10-12 20:51:24 +02001793 if (sme->key_len == 0)
1794 return 0;
1795
Arend van Spriel06bb1232012-09-27 14:17:56 +02001796 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001797 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1798 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001799
1800 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1801 return 0;
1802
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001803 if (!(sec->cipher_pairwise &
1804 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1805 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001806
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001807 memset(&key, 0, sizeof(key));
1808 key.len = (u32) sme->key_len;
1809 key.index = (u32) sme->key_idx;
1810 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001811 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001812 return -EINVAL;
1813 }
1814 memcpy(key.data, sme->key, key.len);
1815 key.flags = BRCMF_PRIMARY_KEY;
1816 switch (sec->cipher_pairwise) {
1817 case WLAN_CIPHER_SUITE_WEP40:
1818 key.algo = CRYPTO_ALGO_WEP1;
1819 break;
1820 case WLAN_CIPHER_SUITE_WEP104:
1821 key.algo = CRYPTO_ALGO_WEP128;
1822 break;
1823 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001824 brcmf_err("Invalid algorithm (%d)\n",
1825 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001826 return -EINVAL;
1827 }
1828 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001829 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1830 key.len, key.index, key.algo);
1831 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Hante Meuleman118eb302014-12-21 12:43:49 +01001832 err = send_key_to_dongle(netdev_priv(ndev), &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001833 if (err)
1834 return err;
1835
1836 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001837 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001838 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001839 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001840 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001841 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001842 }
1843 return err;
1844}
1845
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001846static
1847enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1848 enum nl80211_auth_type type)
1849{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001850 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1851 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1852 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1853 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001854 }
1855 return type;
1856}
1857
Arend van Spriel7705ba62016-04-17 16:44:58 +02001858static void brcmf_set_join_pref(struct brcmf_if *ifp,
1859 struct cfg80211_bss_selection *bss_select)
1860{
1861 struct brcmf_join_pref_params join_pref_params[2];
1862 enum nl80211_band band;
1863 int err, i = 0;
1864
1865 join_pref_params[i].len = 2;
1866 join_pref_params[i].rssi_gain = 0;
1867
1868 if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF)
1869 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO);
1870
1871 switch (bss_select->behaviour) {
1872 case __NL80211_BSS_SELECT_ATTR_INVALID:
1873 brcmf_c_set_joinpref_default(ifp);
1874 return;
1875 case NL80211_BSS_SELECT_ATTR_BAND_PREF:
1876 join_pref_params[i].type = BRCMF_JOIN_PREF_BAND;
1877 band = bss_select->param.band_pref;
1878 join_pref_params[i].band = nl80211_band_to_fwil(band);
1879 i++;
1880 break;
1881 case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST:
1882 join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA;
1883 band = bss_select->param.adjust.band;
1884 join_pref_params[i].band = nl80211_band_to_fwil(band);
1885 join_pref_params[i].rssi_gain = bss_select->param.adjust.delta;
1886 i++;
1887 break;
1888 case NL80211_BSS_SELECT_ATTR_RSSI:
1889 default:
1890 break;
1891 }
1892 join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI;
1893 join_pref_params[i].len = 2;
1894 join_pref_params[i].rssi_gain = 0;
1895 join_pref_params[i].band = 0;
1896 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
1897 sizeof(join_pref_params));
1898 if (err)
1899 brcmf_err("Set join_pref error (%d)\n", err);
1900}
1901
Arend van Spriel5b435de2011-10-05 13:19:03 +02001902static s32
1903brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001904 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001905{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001906 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001907 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001908 struct ieee80211_channel *chan = sme->channel;
1909 struct brcmf_join_params join_params;
1910 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001911 const struct brcmf_tlv *rsn_ie;
1912 const struct brcmf_vs_tlv *wpa_ie;
1913 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001914 u32 ie_len;
1915 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001916 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001917 s32 err = 0;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001918 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001919
Arend van Sprield96b8012012-12-05 15:26:02 +01001920 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001921 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001922 return -EIO;
1923
1924 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001925 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001926 return -EOPNOTSUPP;
1927 }
1928
Hante Meuleman89286dc2013-02-08 15:53:46 +01001929 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1930 /* A normal (non P2P) connection request setup. */
1931 ie = NULL;
1932 ie_len = 0;
1933 /* find the WPA_IE */
1934 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1935 if (wpa_ie) {
1936 ie = wpa_ie;
1937 ie_len = wpa_ie->len + TLV_HDR_LEN;
1938 } else {
1939 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001940 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1941 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001942 WLAN_EID_RSN);
1943 if (rsn_ie) {
1944 ie = rsn_ie;
1945 ie_len = rsn_ie->len + TLV_HDR_LEN;
1946 }
1947 }
1948 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1949 }
1950
1951 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1952 sme->ie, sme->ie_len);
1953 if (err)
1954 brcmf_err("Set Assoc REQ IE Failed\n");
1955 else
1956 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1957
Arend van Sprielc1179032012-10-22 13:55:33 -07001958 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001959
1960 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001961 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001962 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001963 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001964 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1965 cfg->channel, chan->center_freq, chanspec);
1966 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001967 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001968 chanspec = 0;
1969 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001970
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001971 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001972
1973 err = brcmf_set_wpa_version(ndev, sme);
1974 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001975 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001976 goto done;
1977 }
1978
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001979 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001980 err = brcmf_set_auth_type(ndev, sme);
1981 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001982 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001983 goto done;
1984 }
1985
Hante Meuleman240d61a2016-02-17 11:27:10 +01001986 err = brcmf_set_wsec_mode(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001987 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001988 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001989 goto done;
1990 }
1991
1992 err = brcmf_set_key_mgmt(ndev, sme);
1993 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001994 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001995 goto done;
1996 }
1997
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001998 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001999 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002000 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002001 goto done;
2002 }
2003
Hante Meuleman89286dc2013-02-08 15:53:46 +01002004 /* Join with specific BSSID and cached SSID
2005 * If SSID is zero join based on BSSID only
2006 */
2007 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
2008 offsetof(struct brcmf_assoc_params_le, chanspec_list);
2009 if (cfg->channel)
2010 join_params_size += sizeof(u16);
2011 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
2012 if (ext_join_params == NULL) {
2013 err = -ENOMEM;
2014 goto done;
2015 }
Hante Meulemane9a6ca82015-11-25 11:32:37 +01002016 ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN);
2017 ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len);
2018 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len);
2019 if (ssid_len < IEEE80211_MAX_SSID_LEN)
2020 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n",
2021 ext_join_params->ssid_le.SSID, ssid_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01002022
Hante Meuleman89286dc2013-02-08 15:53:46 +01002023 /* Set up join scan parameters */
2024 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01002025 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
2026
2027 if (sme->bssid)
2028 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
2029 else
Joe Perches93803b32015-03-02 19:54:49 -08002030 eth_broadcast_addr(ext_join_params->assoc_le.bssid);
Hante Meuleman89286dc2013-02-08 15:53:46 +01002031
2032 if (cfg->channel) {
2033 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
2034
2035 ext_join_params->assoc_le.chanspec_list[0] =
2036 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01002037 /* Increase dwell time to receive probe response or detect
2038 * beacon from target AP at a noisy air only during connect
2039 * command.
2040 */
2041 ext_join_params->scan_le.active_time =
2042 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
2043 ext_join_params->scan_le.passive_time =
2044 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
2045 /* To sync with presence period of VSDB GO send probe request
2046 * more frequently. Probe request will be stopped when it gets
2047 * probe response from target AP/GO.
2048 */
2049 ext_join_params->scan_le.nprobes =
2050 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
2051 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
2052 } else {
2053 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
2054 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
2055 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01002056 }
2057
Arend van Spriel7705ba62016-04-17 16:44:58 +02002058 brcmf_set_join_pref(ifp, &sme->bss_select);
2059
Hante Meuleman89286dc2013-02-08 15:53:46 +01002060 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
2061 join_params_size);
2062 kfree(ext_join_params);
2063 if (!err)
2064 /* This is it. join command worked, we are done */
2065 goto done;
2066
2067 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002068 memset(&join_params, 0, sizeof(join_params));
2069 join_params_size = sizeof(join_params.ssid_le);
2070
Hante Meulemane9a6ca82015-11-25 11:32:37 +01002071 memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len);
2072 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002073
Hante Meuleman89286dc2013-02-08 15:53:46 +01002074 if (sme->bssid)
2075 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
2076 else
Joe Perches93803b32015-03-02 19:54:49 -08002077 eth_broadcast_addr(join_params.params_le.bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002078
Hante Meuleman17012612013-02-06 18:40:44 +01002079 if (cfg->channel) {
2080 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
2081 join_params.params_le.chanspec_num = cpu_to_le32(1);
2082 join_params_size += sizeof(join_params.params_le);
2083 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002084 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002085 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002086 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01002087 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002088
2089done:
2090 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07002091 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01002092 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002093 return err;
2094}
2095
2096static s32
2097brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2098 u16 reason_code)
2099{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002100 struct brcmf_if *ifp = netdev_priv(ndev);
2101 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002102 struct brcmf_scb_val_le scbval;
2103 s32 err = 0;
2104
Arend van Sprield96b8012012-12-05 15:26:02 +01002105 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
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
Arend van Sprielc1179032012-10-22 13:55:33 -07002109 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel4f3fff12014-11-20 22:27:02 +01002110 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Johannes Berg80279fb2015-05-22 16:22:20 +02002111 cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002112
Arend van Spriel06bb1232012-09-27 14:17:56 +02002113 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002114 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07002115 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07002116 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002117 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002118 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002119
Arend van Sprield96b8012012-12-05 15:26:02 +01002120 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002121 return err;
2122}
2123
2124static s32
Johannes Bergc8442112012-10-24 10:17:18 +02002125brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05002126 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002127{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002128 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002129 struct net_device *ndev = cfg_to_ndev(cfg);
2130 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002131 s32 err;
2132 s32 disable;
2133 u32 qdbm = 127;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002134
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002135 brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm);
Arend van Sprielce81e312012-10-22 13:55:37 -07002136 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002137 return -EIO;
2138
2139 switch (type) {
2140 case NL80211_TX_POWER_AUTOMATIC:
2141 break;
2142 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02002143 case NL80211_TX_POWER_FIXED:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002144 if (mbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002145 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002146 err = -EINVAL;
2147 goto done;
2148 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002149 qdbm = MBM_TO_DBM(4 * mbm);
2150 if (qdbm > 127)
2151 qdbm = 127;
2152 qdbm |= WL_TXPWR_OVERRIDE;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002153 break;
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002154 default:
2155 brcmf_err("Unsupported type %d\n", type);
2156 err = -EINVAL;
2157 goto done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002158 }
2159 /* Make sure radio is off or on as far as software is concerned */
2160 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07002161 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002162 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002163 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002164
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002165 err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002166 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002167 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002168
2169done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002170 brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002171 return err;
2172}
2173
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002174static s32
2175brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2176 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002177{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002178 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002179 struct net_device *ndev = cfg_to_ndev(cfg);
2180 struct brcmf_if *ifp = netdev_priv(ndev);
2181 s32 qdbm = 0;
2182 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002183
Arend van Sprield96b8012012-12-05 15:26:02 +01002184 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002185 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002186 return -EIO;
2187
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002188 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002189 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002190 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002191 goto done;
2192 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002193 *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002194
2195done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002196 brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002197 return err;
2198}
2199
2200static s32
2201brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002202 u8 key_idx, bool unicast, bool multicast)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002203{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002204 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002205 u32 index;
2206 u32 wsec;
2207 s32 err = 0;
2208
Arend van Sprield96b8012012-12-05 15:26:02 +01002209 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002210 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002211 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002212 return -EIO;
2213
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002214 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002215 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002216 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002217 goto done;
2218 }
2219
2220 if (wsec & WEP_ENABLED) {
2221 /* Just select a new current key */
2222 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002223 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07002224 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002225 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002226 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002227 }
2228done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002229 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002230 return err;
2231}
2232
2233static s32
Hante Meuleman219e0f72016-02-17 11:27:09 +01002234brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2235 u8 key_idx, bool pairwise, const u8 *mac_addr)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002236{
Hante Meuleman992f6062013-04-02 21:06:17 +02002237 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman240d61a2016-02-17 11:27:10 +01002238 struct brcmf_wsec_key *key;
2239 s32 err;
Hante Meuleman219e0f72016-02-17 11:27:09 +01002240
2241 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman240d61a2016-02-17 11:27:10 +01002242 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2243
Hante Meuleman219e0f72016-02-17 11:27:09 +01002244 if (!check_vif_up(ifp->vif))
2245 return -EIO;
2246
2247 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2248 /* we ignore this key index in this case */
2249 return -EINVAL;
2250 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002251
Hante Meuleman240d61a2016-02-17 11:27:10 +01002252 key = &ifp->vif->profile.key[key_idx];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002253
Hante Meuleman240d61a2016-02-17 11:27:10 +01002254 if (key->algo == CRYPTO_ALGO_OFF) {
2255 brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n");
2256 return -EINVAL;
2257 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002258
Hante Meuleman240d61a2016-02-17 11:27:10 +01002259 memset(key, 0, sizeof(*key));
2260 key->index = (u32)key_idx;
2261 key->flags = BRCMF_PRIMARY_KEY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002262
Hante Meuleman240d61a2016-02-17 11:27:10 +01002263 /* Clear the key/index */
2264 err = send_key_to_dongle(ifp, key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002265
Hante Meuleman219e0f72016-02-17 11:27:09 +01002266 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002267 return err;
2268}
2269
2270static s32
2271brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman240d61a2016-02-17 11:27:10 +01002272 u8 key_idx, bool pairwise, const u8 *mac_addr,
2273 struct key_params *params)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002274{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002275 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman118eb302014-12-21 12:43:49 +01002276 struct brcmf_wsec_key *key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002277 s32 val;
2278 s32 wsec;
Hante Meuleman219e0f72016-02-17 11:27:09 +01002279 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002280 u8 keybuf[8];
Hante Meuleman219e0f72016-02-17 11:27:09 +01002281 bool ext_key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002282
Arend van Sprield96b8012012-12-05 15:26:02 +01002283 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002284 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002285 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002286 return -EIO;
2287
Hante Meuleman118eb302014-12-21 12:43:49 +01002288 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2289 /* we ignore this key index in this case */
2290 brcmf_err("invalid key index (%d)\n", key_idx);
2291 return -EINVAL;
2292 }
2293
Hante Meuleman219e0f72016-02-17 11:27:09 +01002294 if (params->key_len == 0)
2295 return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise,
2296 mac_addr);
2297
2298 if (params->key_len > sizeof(key->data)) {
2299 brcmf_err("Too long key length (%u)\n", params->key_len);
2300 return -EINVAL;
2301 }
2302
2303 ext_key = false;
2304 if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2305 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
2306 brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr);
2307 ext_key = true;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002308 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002309
Hante Meuleman118eb302014-12-21 12:43:49 +01002310 key = &ifp->vif->profile.key[key_idx];
2311 memset(key, 0, sizeof(*key));
Hante Meuleman219e0f72016-02-17 11:27:09 +01002312 if ((ext_key) && (!is_multicast_ether_addr(mac_addr)))
2313 memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN);
Hante Meuleman118eb302014-12-21 12:43:49 +01002314 key->len = params->key_len;
2315 key->index = key_idx;
Hante Meuleman118eb302014-12-21 12:43:49 +01002316 memcpy(key->data, params->key, key->len);
Hante Meuleman219e0f72016-02-17 11:27:09 +01002317 if (!ext_key)
2318 key->flags = BRCMF_PRIMARY_KEY;
Hante Meuleman118eb302014-12-21 12:43:49 +01002319
Arend van Spriel5b435de2011-10-05 13:19:03 +02002320 switch (params->cipher) {
2321 case WLAN_CIPHER_SUITE_WEP40:
Hante Meuleman118eb302014-12-21 12:43:49 +01002322 key->algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002323 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002324 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002325 break;
2326 case WLAN_CIPHER_SUITE_WEP104:
Hante Meuleman118eb302014-12-21 12:43:49 +01002327 key->algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002328 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002329 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002330 break;
2331 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002332 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002333 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman118eb302014-12-21 12:43:49 +01002334 memcpy(keybuf, &key->data[24], sizeof(keybuf));
2335 memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
2336 memcpy(&key->data[16], keybuf, sizeof(keybuf));
Hante Meuleman1a873342012-09-27 14:17:54 +02002337 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002338 key->algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002339 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002340 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002341 break;
2342 case WLAN_CIPHER_SUITE_AES_CMAC:
Hante Meuleman118eb302014-12-21 12:43:49 +01002343 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002344 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002345 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002346 break;
2347 case WLAN_CIPHER_SUITE_CCMP:
Hante Meuleman118eb302014-12-21 12:43:49 +01002348 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002349 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002350 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002351 break;
2352 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002353 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002354 err = -EINVAL;
2355 goto done;
2356 }
2357
Hante Meuleman118eb302014-12-21 12:43:49 +01002358 err = send_key_to_dongle(ifp, key);
Hante Meuleman219e0f72016-02-17 11:27:09 +01002359 if (ext_key || err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002360 goto done;
2361
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002362 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002363 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002364 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002365 goto done;
2366 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002367 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002368 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002369 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002370 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002371 goto done;
2372 }
2373
Arend van Spriel5b435de2011-10-05 13:19:03 +02002374done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002375 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002376 return err;
2377}
2378
2379static s32
Hante Meuleman240d61a2016-02-17 11:27:10 +01002380brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, u8 key_idx,
2381 bool pairwise, const u8 *mac_addr, void *cookie,
2382 void (*callback)(void *cookie,
2383 struct key_params *params))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002384{
2385 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002386 struct brcmf_if *ifp = netdev_priv(ndev);
2387 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002388 struct brcmf_cfg80211_security *sec;
2389 s32 wsec;
2390 s32 err = 0;
2391
Arend van Sprield96b8012012-12-05 15:26:02 +01002392 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002393 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002394 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002395 return -EIO;
2396
2397 memset(&params, 0, sizeof(params));
2398
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002399 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002400 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002401 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002402 /* Ignore this error, may happen during DISASSOC */
2403 err = -EAGAIN;
2404 goto done;
2405 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002406 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002407 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002408 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2409 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002410 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002411 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2412 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002413 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002414 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002415 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002416 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002417 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002418 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002419 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002420 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002421 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002422 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002423 err = -EINVAL;
2424 goto done;
2425 }
2426 callback(cookie, &params);
2427
2428done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002429 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002430 return err;
2431}
2432
2433static s32
2434brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
Hante Meuleman240d61a2016-02-17 11:27:10 +01002435 struct net_device *ndev, u8 key_idx)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002436{
Hante Meuleman240d61a2016-02-17 11:27:10 +01002437 struct brcmf_if *ifp = netdev_priv(ndev);
2438
2439 brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx);
2440
2441 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
2442 return 0;
2443
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002444 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002445
2446 return -EOPNOTSUPP;
2447}
2448
Hante Meuleman118eb302014-12-21 12:43:49 +01002449static void
2450brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
2451{
2452 s32 err;
2453 u8 key_idx;
2454 struct brcmf_wsec_key *key;
2455 s32 wsec;
2456
2457 for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
2458 key = &ifp->vif->profile.key[key_idx];
2459 if ((key->algo == CRYPTO_ALGO_WEP1) ||
2460 (key->algo == CRYPTO_ALGO_WEP128))
2461 break;
2462 }
2463 if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
2464 return;
2465
2466 err = send_key_to_dongle(ifp, key);
2467 if (err) {
2468 brcmf_err("Setting WEP key failed (%d)\n", err);
2469 return;
2470 }
2471 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2472 if (err) {
2473 brcmf_err("get wsec error (%d)\n", err);
2474 return;
2475 }
2476 wsec |= WEP_ENABLED;
2477 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2478 if (err)
2479 brcmf_err("set wsec error (%d)\n", err);
2480}
2481
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002482static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si)
2483{
2484 struct nl80211_sta_flag_update *sfu;
2485
2486 brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags);
2487 si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS);
2488 sfu = &si->sta_flags;
2489 sfu->mask = BIT(NL80211_STA_FLAG_WME) |
2490 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2491 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2492 BIT(NL80211_STA_FLAG_AUTHORIZED);
2493 if (fw_sta_flags & BRCMF_STA_WME)
2494 sfu->set |= BIT(NL80211_STA_FLAG_WME);
2495 if (fw_sta_flags & BRCMF_STA_AUTHE)
2496 sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2497 if (fw_sta_flags & BRCMF_STA_ASSOC)
2498 sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2499 if (fw_sta_flags & BRCMF_STA_AUTHO)
2500 sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2501}
2502
2503static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si)
2504{
2505 struct {
2506 __le32 len;
2507 struct brcmf_bss_info_le bss_le;
2508 } *buf;
2509 u16 capability;
2510 int err;
2511
2512 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2513 if (!buf)
2514 return;
2515
2516 buf->len = cpu_to_le32(WL_BSS_INFO_MAX);
2517 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf,
2518 WL_BSS_INFO_MAX);
2519 if (err) {
2520 brcmf_err("Failed to get bss info (%d)\n", err);
Rafał Miłecki23e9c122016-09-21 08:23:24 +02002521 goto out_kfree;
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002522 }
2523 si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
2524 si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period);
2525 si->bss_param.dtim_period = buf->bss_le.dtim_period;
2526 capability = le16_to_cpu(buf->bss_le.capability);
2527 if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT)
2528 si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2529 if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2530 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2531 if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2532 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Rafał Miłecki23e9c122016-09-21 08:23:24 +02002533
2534out_kfree:
2535 kfree(buf);
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002536}
2537
Arend van Spriel5b435de2011-10-05 13:19:03 +02002538static s32
Hante Meuleman3f5893d2016-01-02 09:41:37 +01002539brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp,
2540 struct station_info *sinfo)
2541{
2542 struct brcmf_scb_val_le scbval;
2543 struct brcmf_pktcnt_le pktcnt;
2544 s32 err;
2545 u32 rate;
2546 u32 rssi;
2547
2548 /* Get the current tx rate */
2549 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
2550 if (err < 0) {
2551 brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err);
2552 return err;
2553 }
2554 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
2555 sinfo->txrate.legacy = rate * 5;
2556
2557 memset(&scbval, 0, sizeof(scbval));
2558 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval,
2559 sizeof(scbval));
2560 if (err) {
2561 brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err);
2562 return err;
2563 }
2564 rssi = le32_to_cpu(scbval.val);
2565 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2566 sinfo->signal = rssi;
2567
2568 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt,
2569 sizeof(pktcnt));
2570 if (err) {
2571 brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err);
2572 return err;
2573 }
2574 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS) |
2575 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
2576 BIT(NL80211_STA_INFO_TX_PACKETS) |
2577 BIT(NL80211_STA_INFO_TX_FAILED);
2578 sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt);
2579 sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt);
2580 sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt);
2581 sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt);
2582
2583 return 0;
2584}
2585
2586static s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02002587brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002588 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002589{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002590 struct brcmf_if *ifp = netdev_priv(ndev);
Jaap Jan Meijer94abd772016-05-12 18:25:08 +02002591 struct brcmf_scb_val_le scb_val;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002592 s32 err = 0;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002593 struct brcmf_sta_info_le sta_info_le;
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002594 u32 sta_flags;
2595 u32 is_tdls_peer;
Hante Meulemancae355d2015-10-08 20:33:17 +02002596 s32 total_rssi;
2597 s32 count_rssi;
Jaap Jan Meijer94abd772016-05-12 18:25:08 +02002598 int rssi;
Hante Meulemancae355d2015-10-08 20:33:17 +02002599 u32 i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002600
Arend van Sprield96b8012012-12-05 15:26:02 +01002601 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002602 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002603 return -EIO;
2604
Hante Meuleman3f5893d2016-01-02 09:41:37 +01002605 if (brcmf_is_ibssmode(ifp->vif))
2606 return brcmf_cfg80211_get_station_ibss(ifp, sinfo);
2607
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002608 memset(&sta_info_le, 0, sizeof(sta_info_le));
2609 memcpy(&sta_info_le, mac, ETH_ALEN);
2610 err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info",
2611 &sta_info_le,
2612 sizeof(sta_info_le));
2613 is_tdls_peer = !err;
2614 if (err) {
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002615 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002616 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002617 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002618 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002619 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002620 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002621 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002622 }
2623 brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver));
2624 sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME);
2625 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2626 sta_flags = le32_to_cpu(sta_info_le.flags);
2627 brcmf_convert_sta_flags(sta_flags, sinfo);
2628 sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2629 if (is_tdls_peer)
2630 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2631 else
2632 sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2633 if (sta_flags & BRCMF_STA_ASSOC) {
2634 sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
2635 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
2636 brcmf_fill_bss_param(ifp, sinfo);
2637 }
2638 if (sta_flags & BRCMF_STA_SCBSTATS) {
2639 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
2640 sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures);
2641 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
2642 sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts);
2643 sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts);
2644 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
2645 sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts);
2646 sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts);
2647 if (sinfo->tx_packets) {
Johannes Berg319090b2014-11-17 14:08:11 +01002648 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002649 sinfo->txrate.legacy =
2650 le32_to_cpu(sta_info_le.tx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002651 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002652 if (sinfo->rx_packets) {
2653 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002654 sinfo->rxrate.legacy =
2655 le32_to_cpu(sta_info_le.rx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002656 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002657 if (le16_to_cpu(sta_info_le.ver) >= 4) {
2658 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES);
2659 sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes);
2660 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES);
2661 sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes);
2662 }
Hante Meulemancae355d2015-10-08 20:33:17 +02002663 total_rssi = 0;
2664 count_rssi = 0;
2665 for (i = 0; i < BRCMF_ANT_MAX; i++) {
2666 if (sta_info_le.rssi[i]) {
2667 sinfo->chain_signal_avg[count_rssi] =
2668 sta_info_le.rssi[i];
2669 sinfo->chain_signal[count_rssi] =
2670 sta_info_le.rssi[i];
2671 total_rssi += sta_info_le.rssi[i];
2672 count_rssi++;
2673 }
2674 }
2675 if (count_rssi) {
2676 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
2677 sinfo->chains = count_rssi;
2678
2679 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2680 total_rssi /= count_rssi;
2681 sinfo->signal = total_rssi;
Jaap Jan Meijer94abd772016-05-12 18:25:08 +02002682 } else if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
2683 &ifp->vif->sme_state)) {
2684 memset(&scb_val, 0, sizeof(scb_val));
2685 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
2686 &scb_val, sizeof(scb_val));
2687 if (err) {
2688 brcmf_err("Could not get rssi (%d)\n", err);
2689 goto done;
2690 } else {
2691 rssi = le32_to_cpu(scb_val.val);
2692 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2693 sinfo->signal = rssi;
2694 brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
2695 }
Hante Meulemancae355d2015-10-08 20:33:17 +02002696 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002697 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002698done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002699 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002700 return err;
2701}
2702
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02002703static int
2704brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
2705 int idx, u8 *mac, struct station_info *sinfo)
2706{
2707 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2708 struct brcmf_if *ifp = netdev_priv(ndev);
2709 s32 err;
2710
2711 brcmf_dbg(TRACE, "Enter, idx %d\n", idx);
2712
2713 if (idx == 0) {
2714 cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST);
2715 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST,
2716 &cfg->assoclist,
2717 sizeof(cfg->assoclist));
2718 if (err) {
2719 brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n",
2720 err);
2721 cfg->assoclist.count = 0;
2722 return -EOPNOTSUPP;
2723 }
2724 }
2725 if (idx < le32_to_cpu(cfg->assoclist.count)) {
2726 memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN);
2727 return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo);
2728 }
2729 return -ENOENT;
2730}
2731
Arend van Spriel5b435de2011-10-05 13:19:03 +02002732static s32
2733brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2734 bool enabled, s32 timeout)
2735{
2736 s32 pm;
2737 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002738 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002739 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002740
Arend van Sprield96b8012012-12-05 15:26:02 +01002741 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002742
2743 /*
2744 * Powersave enable/disable request is coming from the
2745 * cfg80211 even before the interface is up. In that
2746 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002747 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002748 * FW later while initializing the dongle
2749 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002750 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002751 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002752
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002753 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002754 goto done;
2755 }
2756
2757 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002758 /* Do not enable the power save after assoc if it is a p2p interface */
2759 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2760 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2761 pm = PM_OFF;
2762 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002763 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002764
Arend van Sprielc1179032012-10-22 13:55:33 -07002765 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002766 if (err) {
2767 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002768 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002769 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002770 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002771 }
2772done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002773 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002774 return err;
2775}
2776
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002777static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002778 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002779{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002780 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002781 struct ieee80211_channel *notify_channel;
2782 struct cfg80211_bss *bss;
2783 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002784 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002785 u16 channel;
2786 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002787 u16 notify_capability;
2788 u16 notify_interval;
2789 u8 *notify_ie;
2790 size_t notify_ielen;
2791 s32 notify_signal;
2792
2793 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002794 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002795 return 0;
2796 }
2797
Franky Lin83cf17a2013-04-11 13:28:50 +02002798 if (!bi->ctl_ch) {
2799 ch.chspec = le16_to_cpu(bi->chanspec);
2800 cfg->d11inf.decchspec(&ch);
Rafał Miłecki4712d882016-05-20 13:38:57 +02002801 bi->ctl_ch = ch.control_ch_num;
Franky Lin83cf17a2013-04-11 13:28:50 +02002802 }
2803 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002804
2805 if (channel <= CH_MAX_2G_CHANNEL)
Johannes Berg57fbcce2016-04-12 15:56:15 +02002806 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002807 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02002808 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002809
2810 freq = ieee80211_channel_to_frequency(channel, band->band);
2811 notify_channel = ieee80211_get_channel(wiphy, freq);
2812
Arend van Spriel5b435de2011-10-05 13:19:03 +02002813 notify_capability = le16_to_cpu(bi->capability);
2814 notify_interval = le16_to_cpu(bi->beacon_period);
2815 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2816 notify_ielen = le32_to_cpu(bi->ie_length);
2817 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2818
Arend van Spriel16886732012-12-05 15:26:04 +01002819 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2820 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2821 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2822 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2823 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002824
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002825 bss = cfg80211_inform_bss(wiphy, notify_channel,
2826 CFG80211_BSS_FTYPE_UNKNOWN,
2827 (const u8 *)bi->BSSID,
2828 0, notify_capability,
2829 notify_interval, notify_ie,
2830 notify_ielen, notify_signal,
2831 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002832
Franky Line78946e2011-11-10 20:30:34 +01002833 if (!bss)
2834 return -ENOMEM;
2835
Johannes Berg5b112d32013-02-01 01:49:58 +01002836 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002837
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002838 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002839}
2840
Roland Vossen6f09be02011-10-18 14:03:02 +02002841static struct brcmf_bss_info_le *
2842next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2843{
2844 if (bss == NULL)
2845 return list->bss_info_le;
2846 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2847 le32_to_cpu(bss->length));
2848}
2849
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002850static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002851{
2852 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002853 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002854 s32 err = 0;
2855 int i;
2856
Hante Meulemanef8596e2014-09-30 10:23:13 +02002857 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002858 if (bss_list->count != 0 &&
2859 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002860 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2861 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002862 return -EOPNOTSUPP;
2863 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002864 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002865 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002866 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002867 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002868 if (err)
2869 break;
2870 }
2871 return err;
2872}
2873
Hante Meulemanb0a79082015-12-10 13:43:07 +01002874static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg,
2875 struct net_device *ndev, const u8 *bssid)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002876{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002877 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002878 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002879 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002880 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002881 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002882 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002883 u8 *buf = NULL;
2884 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002885 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002886 u16 notify_capability;
2887 u16 notify_interval;
2888 u8 *notify_ie;
2889 size_t notify_ielen;
2890 s32 notify_signal;
2891
Arend van Sprield96b8012012-12-05 15:26:02 +01002892 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002893
2894 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2895 if (buf == NULL) {
2896 err = -ENOMEM;
2897 goto CleanUp;
2898 }
2899
2900 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2901
Arend van Sprielac24be62012-10-22 10:36:23 -07002902 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2903 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002904 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002905 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002906 goto CleanUp;
2907 }
2908
Roland Vossend34bf642011-10-18 14:03:01 +02002909 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002910
Franky Lin83cf17a2013-04-11 13:28:50 +02002911 ch.chspec = le16_to_cpu(bi->chanspec);
2912 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002913
Franky Lin83cf17a2013-04-11 13:28:50 +02002914 if (ch.band == BRCMU_CHAN_BAND_2G)
Johannes Berg57fbcce2016-04-12 15:56:15 +02002915 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002916 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02002917 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002918
Rafał Miłecki4712d882016-05-20 13:38:57 +02002919 freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band);
Hante Meulemanb0a79082015-12-10 13:43:07 +01002920 cfg->channel = freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002921 notify_channel = ieee80211_get_channel(wiphy, freq);
2922
Arend van Spriel5b435de2011-10-05 13:19:03 +02002923 notify_capability = le16_to_cpu(bi->capability);
2924 notify_interval = le16_to_cpu(bi->beacon_period);
2925 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2926 notify_ielen = le32_to_cpu(bi->ie_length);
2927 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2928
Rafał Miłecki4712d882016-05-20 13:38:57 +02002929 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.control_ch_num, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002930 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2931 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2932 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002933
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002934 bss = cfg80211_inform_bss(wiphy, notify_channel,
2935 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2936 notify_capability, notify_interval,
2937 notify_ie, notify_ielen, notify_signal,
2938 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002939
Franky Line78946e2011-11-10 20:30:34 +01002940 if (!bss) {
2941 err = -ENOMEM;
2942 goto CleanUp;
2943 }
2944
Johannes Berg5b112d32013-02-01 01:49:58 +01002945 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002946
Arend van Spriel5b435de2011-10-05 13:19:03 +02002947CleanUp:
2948
2949 kfree(buf);
2950
Arend van Sprield96b8012012-12-05 15:26:02 +01002951 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002952
2953 return err;
2954}
2955
Hante Meuleman89286dc2013-02-08 15:53:46 +01002956static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2957 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002958{
Roland Vossend34bf642011-10-18 14:03:01 +02002959 struct brcmf_bss_info_le *bi;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002960 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002961 u16 beacon_interval;
2962 u8 dtim_period;
2963 size_t ie_len;
2964 u8 *ie;
2965 s32 err = 0;
2966
Arend van Sprield96b8012012-12-05 15:26:02 +01002967 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002968 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002969 return err;
2970
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002971 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002972 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002973 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002974 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002975 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002976 goto update_bss_info_out;
2977 }
2978
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002979 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2980 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002981 if (err)
2982 goto update_bss_info_out;
2983
2984 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2985 ie_len = le32_to_cpu(bi->ie_length);
2986 beacon_interval = le16_to_cpu(bi->beacon_period);
2987
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002988 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002989 if (tim)
2990 dtim_period = tim->data[1];
2991 else {
2992 /*
2993 * active scan was done so we could not get dtim
2994 * information out of probe response.
2995 * so we speficially query dtim information to dongle.
2996 */
2997 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002998 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002999 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003000 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003001 goto update_bss_info_out;
3002 }
3003 dtim_period = (u8)var;
3004 }
3005
Arend van Spriel5b435de2011-10-05 13:19:03 +02003006update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01003007 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003008 return err;
3009}
3010
Hante Meuleman18e2f612013-02-08 15:53:49 +01003011void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003012{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003013 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003014
Arend van Sprielc1179032012-10-22 13:55:33 -07003015 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003016 if (cfg->internal_escan || cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02003017 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02003018 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02003019 }
Arend van Sprielc1179032012-10-22 13:55:33 -07003020 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3021 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003022}
3023
Hante Meulemane756af52012-09-11 21:18:52 +02003024static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
3025{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003026 struct brcmf_cfg80211_info *cfg =
3027 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02003028 escan_timeout_work);
3029
Hante Meulemanef8596e2014-09-30 10:23:13 +02003030 brcmf_inform_bss(cfg);
Arend van Spriela0f472a2013-04-05 10:57:49 +02003031 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02003032}
3033
3034static void brcmf_escan_timeout(unsigned long data)
3035{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003036 struct brcmf_cfg80211_info *cfg =
3037 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02003038
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003039 if (cfg->internal_escan || cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003040 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08003041 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02003042 }
3043}
3044
3045static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02003046brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
3047 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02003048 struct brcmf_bss_info_le *bss_info_le)
3049{
Franky Lin83cf17a2013-04-11 13:28:50 +02003050 struct brcmu_chan ch_bss, ch_bss_info_le;
3051
3052 ch_bss.chspec = le16_to_cpu(bss->chanspec);
3053 cfg->d11inf.decchspec(&ch_bss);
3054 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
3055 cfg->d11inf.decchspec(&ch_bss_info_le);
3056
Hante Meulemane756af52012-09-11 21:18:52 +02003057 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02003058 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02003059 bss_info_le->SSID_len == bss->SSID_len &&
3060 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01003061 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
3062 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02003063 s16 bss_rssi = le16_to_cpu(bss->RSSI);
3064 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
3065
Hante Meulemane756af52012-09-11 21:18:52 +02003066 /* preserve max RSSI if the measurements are
3067 * both on-channel or both off-channel
3068 */
Arend van Spriel029591f2012-09-19 22:21:06 +02003069 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02003070 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01003071 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
3072 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02003073 /* preserve the on-channel rssi measurement
3074 * if the new measurement is off channel
3075 */
3076 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01003077 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02003078 }
3079 return 1;
3080 }
3081 return 0;
3082}
3083
3084static s32
Arend van Spriel19937322012-11-05 16:22:32 -08003085brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02003086 const struct brcmf_event_msg *e, void *data)
3087{
Arend van Spriel19937322012-11-05 16:22:32 -08003088 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02003089 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02003090 struct brcmf_escan_result_le *escan_result_le;
3091 struct brcmf_bss_info_le *bss_info_le;
3092 struct brcmf_bss_info_le *bss = NULL;
3093 u32 bi_length;
3094 struct brcmf_scan_results *list;
3095 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02003096 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02003097
Arend van Spriel5c36b992012-11-14 18:46:05 -08003098 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02003099
Hans de Goedeb9472a22017-03-08 14:50:17 +01003100 if (status == BRCMF_E_STATUS_ABORT)
3101 goto exit;
3102
Arend van Spriela0f472a2013-04-05 10:57:49 +02003103 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Hante Meuleman37a869e2015-10-29 20:33:17 +01003104 brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx);
Hante Meulemane756af52012-09-11 21:18:52 +02003105 return -EPERM;
3106 }
3107
3108 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003109 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003110 escan_result_le = (struct brcmf_escan_result_le *) data;
3111 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003112 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003113 goto exit;
3114 }
Hante Meulemane756af52012-09-11 21:18:52 +02003115 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003116 brcmf_err("Invalid bss_count %d: ignoring\n",
3117 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02003118 goto exit;
3119 }
3120 bss_info_le = &escan_result_le->bss_info_le;
3121
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003122 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
3123 goto exit;
3124
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003125 if (!cfg->internal_escan && !cfg->scan_request) {
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003126 brcmf_dbg(SCAN, "result without cfg80211 request\n");
3127 goto exit;
3128 }
3129
Hante Meulemane756af52012-09-11 21:18:52 +02003130 bi_length = le32_to_cpu(bss_info_le->length);
3131 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
3132 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003133 brcmf_err("Invalid bss_info length %d: ignoring\n",
3134 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02003135 goto exit;
3136 }
3137
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003138 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02003139 BIT(NL80211_IFTYPE_ADHOC))) {
3140 if (le16_to_cpu(bss_info_le->capability) &
3141 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003142 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003143 goto exit;
3144 }
3145 }
3146
3147 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003148 cfg->escan_info.escan_buf;
Hante Meulemand5367332016-02-17 11:26:51 +01003149 if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003150 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003151 goto exit;
3152 }
3153
3154 for (i = 0; i < list->count; i++) {
3155 bss = bss ? (struct brcmf_bss_info_le *)
3156 ((unsigned char *)bss +
3157 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02003158 if (brcmf_compare_update_same_bss(cfg, bss,
3159 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02003160 goto exit;
3161 }
Hante Meulemand5367332016-02-17 11:26:51 +01003162 memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le,
3163 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02003164 list->version = le32_to_cpu(bss_info_le->version);
3165 list->buflen += bi_length;
3166 list->count++;
3167 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003168 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003169 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
3170 goto exit;
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003171 if (cfg->internal_escan || cfg->scan_request) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003172 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02003173 aborted = status != BRCMF_E_STATUS_SUCCESS;
Hante Meulemanef8596e2014-09-30 10:23:13 +02003174 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
Hante Meulemane756af52012-09-11 21:18:52 +02003175 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003176 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
3177 status);
Hante Meulemane756af52012-09-11 21:18:52 +02003178 }
3179exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003180 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02003181}
3182
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003183static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02003184{
Arend van Spriel5c36b992012-11-14 18:46:05 -08003185 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
3186 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08003187 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
3188 /* Init scan_timeout timer */
3189 init_timer(&cfg->escan_timeout);
3190 cfg->escan_timeout.data = (unsigned long) cfg;
3191 cfg->escan_timeout.function = brcmf_escan_timeout;
3192 INIT_WORK(&cfg->escan_timeout_work,
3193 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02003194}
3195
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003196static struct cfg80211_scan_request *
3197brcmf_alloc_internal_escan_request(struct wiphy *wiphy, u32 n_netinfo) {
3198 struct cfg80211_scan_request *req;
3199 size_t req_size;
3200
3201 req_size = sizeof(*req) +
3202 n_netinfo * sizeof(req->channels[0]) +
3203 n_netinfo * sizeof(*req->ssids);
3204
3205 req = kzalloc(req_size, GFP_KERNEL);
3206 if (req) {
3207 req->wiphy = wiphy;
3208 req->ssids = (void *)(&req->channels[0]) +
3209 n_netinfo * sizeof(req->channels[0]);
3210 }
3211 return req;
3212}
3213
3214static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req,
3215 u8 *ssid, u8 ssid_len, u8 channel)
3216{
3217 struct ieee80211_channel *chan;
3218 enum nl80211_band band;
3219 int freq;
3220
3221 if (channel <= CH_MAX_2G_CHANNEL)
3222 band = NL80211_BAND_2GHZ;
3223 else
3224 band = NL80211_BAND_5GHZ;
3225
3226 freq = ieee80211_channel_to_frequency(channel, band);
3227 if (!freq)
3228 return -EINVAL;
3229
3230 chan = ieee80211_get_channel(req->wiphy, freq);
3231 if (!chan)
3232 return -EINVAL;
3233
3234 req->channels[req->n_channels++] = chan;
3235 memcpy(req->ssids[req->n_ssids].ssid, ssid, ssid_len);
3236 req->ssids[req->n_ssids++].ssid_len = ssid_len;
3237
3238 return 0;
3239}
3240
3241static int brcmf_start_internal_escan(struct brcmf_if *ifp,
3242 struct cfg80211_scan_request *request)
3243{
3244 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3245 int err;
3246
3247 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3248 /* Abort any on-going scan */
3249 brcmf_abort_scanning(cfg);
3250 }
3251
3252 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3253 cfg->escan_info.run = brcmf_run_escan;
3254 err = brcmf_do_escan(ifp, request);
3255 if (err) {
3256 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3257 return err;
3258 }
3259 cfg->internal_escan = true;
3260 return 0;
3261}
3262
Arend Van Spriel53e3a802016-11-23 10:25:31 +00003263static struct brcmf_pno_net_info_le *
3264brcmf_get_netinfo_array(struct brcmf_pno_scanresults_le *pfn_v1)
3265{
3266 struct brcmf_pno_scanresults_v2_le *pfn_v2;
3267 struct brcmf_pno_net_info_le *netinfo;
3268
3269 switch (pfn_v1->version) {
3270 default:
3271 WARN_ON(1);
3272 /* fall-thru */
3273 case cpu_to_le32(1):
3274 netinfo = (struct brcmf_pno_net_info_le *)(pfn_v1 + 1);
3275 break;
3276 case cpu_to_le32(2):
3277 pfn_v2 = (struct brcmf_pno_scanresults_v2_le *)pfn_v1;
3278 netinfo = (struct brcmf_pno_net_info_le *)(pfn_v2 + 1);
3279 break;
3280 }
3281
3282 return netinfo;
3283}
3284
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003285/* PFN result doesn't have all the info which are required by the supplicant
3286 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3287 * via wl_inform_single_bss in the required format. Escan does require the
3288 * scan request in the form of cfg80211_scan_request. For timebeing, create
3289 * cfg80211_scan_request one out of the received PNO event.
3290 */
3291static s32
3292brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
3293 const struct brcmf_event_msg *e, void *data)
3294{
3295 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3296 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3297 struct cfg80211_scan_request *request = NULL;
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003298 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003299 int i, err = 0;
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003300 struct brcmf_pno_scanresults_le *pfn_result;
3301 u32 result_count;
3302 u32 status;
3303
3304 brcmf_dbg(SCAN, "Enter\n");
3305
Hante Meuleman0aedbca2016-02-17 11:26:54 +01003306 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3307 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3308 return 0;
3309 }
3310
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003311 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3312 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
3313 return 0;
3314 }
3315
3316 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3317 result_count = le32_to_cpu(pfn_result->count);
3318 status = le32_to_cpu(pfn_result->status);
3319
3320 /* PFN event is limited to fit 512 bytes so we may get
3321 * multiple NET_FOUND events. For now place a warning here.
3322 */
3323 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
3324 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003325 if (!result_count) {
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003326 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3327 goto out_err;
3328 }
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003329 request = brcmf_alloc_internal_escan_request(wiphy,
3330 result_count);
3331 if (!request) {
3332 err = -ENOMEM;
3333 goto out_err;
3334 }
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003335
Arend Van Spriel53e3a802016-11-23 10:25:31 +00003336 netinfo_start = brcmf_get_netinfo_array(pfn_result);
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003337
3338 for (i = 0; i < result_count; i++) {
3339 netinfo = &netinfo_start[i];
3340 if (!netinfo) {
3341 brcmf_err("Invalid netinfo ptr. index: %d\n",
3342 i);
3343 err = -EINVAL;
3344 goto out_err;
3345 }
3346
3347 brcmf_dbg(SCAN, "SSID:%.32s Channel:%d\n",
3348 netinfo->SSID, netinfo->channel);
3349 err = brcmf_internal_escan_add_info(request,
3350 netinfo->SSID,
3351 netinfo->SSID_len,
3352 netinfo->channel);
3353 if (err)
3354 goto out_err;
3355 }
3356
3357 err = brcmf_start_internal_escan(ifp, request);
3358 if (!err)
3359 goto free_req;
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003360
3361out_err:
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003362 cfg80211_sched_scan_stopped(wiphy);
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003363free_req:
3364 kfree(request);
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003365 return err;
3366}
3367
3368static int
3369brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3370 struct net_device *ndev,
Arend Van Spriel3e2e86a2016-11-23 10:25:23 +00003371 struct cfg80211_sched_scan_request *req)
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003372{
3373 struct brcmf_if *ifp = netdev_priv(ndev);
3374 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003375
3376 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
Arend Van Spriel3e2e86a2016-11-23 10:25:23 +00003377 req->n_match_sets, req->n_ssids);
Arend Van Sprieldfe5b0d2016-11-23 10:25:29 +00003378
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003379 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3380 brcmf_err("Scanning suppressed: status (%lu)\n",
3381 cfg->scan_status);
3382 return -EAGAIN;
3383 }
3384
Arend Van Spriel3e2e86a2016-11-23 10:25:23 +00003385 if (req->n_match_sets <= 0) {
3386 brcmf_dbg(SCAN, "invalid number of matchsets specified: %d\n",
3387 req->n_match_sets);
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003388 return -EINVAL;
3389 }
3390
Arend Van Spriel3e486112016-11-23 10:25:27 +00003391 return brcmf_pno_start_sched_scan(ifp, req);
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003392}
3393
3394static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3395 struct net_device *ndev)
3396{
3397 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend Van Sprielac551362016-11-23 10:25:22 +00003398 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003399
3400 brcmf_dbg(SCAN, "enter\n");
Arend Van Sprielac551362016-11-23 10:25:22 +00003401 brcmf_pno_clean(ifp);
Arend Van Sprielfa85b302016-11-23 10:25:25 +00003402 if (cfg->internal_escan)
Arend Van Sprielac551362016-11-23 10:25:22 +00003403 brcmf_notify_escan_complete(cfg, ifp, true, true);
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003404 return 0;
3405}
3406
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05003407static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003408{
3409 if (ms < 1000 / HZ) {
3410 cond_resched();
3411 mdelay(ms);
3412 } else {
3413 msleep(ms);
3414 }
3415}
3416
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003417static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
3418 u8 *pattern, u32 patternsize, u8 *mask,
3419 u32 packet_offset)
3420{
3421 struct brcmf_fil_wowl_pattern_le *filter;
3422 u32 masksize;
3423 u32 patternoffset;
3424 u8 *buf;
3425 u32 bufsize;
3426 s32 ret;
3427
3428 masksize = (patternsize + 7) / 8;
3429 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
3430
3431 bufsize = sizeof(*filter) + patternsize + masksize;
3432 buf = kzalloc(bufsize, GFP_KERNEL);
3433 if (!buf)
3434 return -ENOMEM;
3435 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
3436
3437 memcpy(filter->cmd, cmd, 4);
3438 filter->masksize = cpu_to_le32(masksize);
3439 filter->offset = cpu_to_le32(packet_offset);
3440 filter->patternoffset = cpu_to_le32(patternoffset);
3441 filter->patternsize = cpu_to_le32(patternsize);
3442 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
3443
3444 if ((mask) && (masksize))
3445 memcpy(buf + sizeof(*filter), mask, masksize);
3446 if ((pattern) && (patternsize))
3447 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
3448
3449 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
3450
3451 kfree(buf);
3452 return ret;
3453}
3454
Hante Meuleman3021ad92016-01-05 11:05:45 +01003455static s32
3456brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
3457 void *data)
3458{
3459 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3460 struct brcmf_pno_scanresults_le *pfn_result;
3461 struct brcmf_pno_net_info_le *netinfo;
3462
3463 brcmf_dbg(SCAN, "Enter\n");
3464
Hante Meuleman0aedbca2016-02-17 11:26:54 +01003465 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3466 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3467 return 0;
3468 }
3469
Hante Meuleman3021ad92016-01-05 11:05:45 +01003470 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3471
3472 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3473 brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n");
3474 return 0;
3475 }
3476
3477 if (le32_to_cpu(pfn_result->count) < 1) {
3478 brcmf_err("Invalid result count, expected 1 (%d)\n",
3479 le32_to_cpu(pfn_result->count));
3480 return -EINVAL;
3481 }
3482
Arend Van Sprield29afe92017-01-27 12:27:46 +00003483 netinfo = brcmf_get_netinfo_array(pfn_result);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003484 memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
3485 cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
3486 cfg->wowl.nd->n_channels = 1;
3487 cfg->wowl.nd->channels[0] =
3488 ieee80211_channel_to_frequency(netinfo->channel,
3489 netinfo->channel <= CH_MAX_2G_CHANNEL ?
3490 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
3491 cfg->wowl.nd_info->n_matches = 1;
3492 cfg->wowl.nd_info->matches[0] = cfg->wowl.nd;
3493
3494 /* Inform (the resume task) that the net detect information was recvd */
3495 cfg->wowl.nd_data_completed = true;
3496 wake_up(&cfg->wowl.nd_data_wait);
3497
3498 return 0;
3499}
3500
Hante Meulemanaeb64222015-10-29 20:33:19 +01003501#ifdef CONFIG_PM
3502
3503static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3504{
Hante Meuleman3021ad92016-01-05 11:05:45 +01003505 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemanaeb64222015-10-29 20:33:19 +01003506 struct brcmf_wowl_wakeind_le wake_ind_le;
3507 struct cfg80211_wowlan_wakeup wakeup_data;
3508 struct cfg80211_wowlan_wakeup *wakeup;
3509 u32 wakeind;
3510 s32 err;
Hante Meuleman3021ad92016-01-05 11:05:45 +01003511 int timeout;
Hante Meulemanaeb64222015-10-29 20:33:19 +01003512
3513 err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
3514 sizeof(wake_ind_le));
Hante Meuleman3021ad92016-01-05 11:05:45 +01003515 if (err) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003516 brcmf_err("Get wowl_wakeind failed, err = %d\n", err);
3517 return;
3518 }
3519
3520 wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
3521 if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
Hante Meuleman3021ad92016-01-05 11:05:45 +01003522 BRCMF_WOWL_RETR | BRCMF_WOWL_NET |
3523 BRCMF_WOWL_PFN_FOUND)) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003524 wakeup = &wakeup_data;
3525 memset(&wakeup_data, 0, sizeof(wakeup_data));
3526 wakeup_data.pattern_idx = -1;
3527
3528 if (wakeind & BRCMF_WOWL_MAGIC) {
3529 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
3530 wakeup_data.magic_pkt = true;
3531 }
3532 if (wakeind & BRCMF_WOWL_DIS) {
3533 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
3534 wakeup_data.disconnect = true;
3535 }
3536 if (wakeind & BRCMF_WOWL_BCN) {
3537 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
3538 wakeup_data.disconnect = true;
3539 }
3540 if (wakeind & BRCMF_WOWL_RETR) {
3541 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
3542 wakeup_data.disconnect = true;
3543 }
3544 if (wakeind & BRCMF_WOWL_NET) {
3545 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
3546 /* For now always map to pattern 0, no API to get
3547 * correct information available at the moment.
3548 */
3549 wakeup_data.pattern_idx = 0;
3550 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003551 if (wakeind & BRCMF_WOWL_PFN_FOUND) {
3552 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n");
3553 timeout = wait_event_timeout(cfg->wowl.nd_data_wait,
3554 cfg->wowl.nd_data_completed,
3555 BRCMF_ND_INFO_TIMEOUT);
3556 if (!timeout)
3557 brcmf_err("No result for wowl net detect\n");
3558 else
3559 wakeup_data.net_detect = cfg->wowl.nd_info;
3560 }
Hante Meuleman5c22fb82016-02-17 11:27:03 +01003561 if (wakeind & BRCMF_WOWL_GTK_FAILURE) {
3562 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n");
3563 wakeup_data.gtk_rekey_failure = true;
3564 }
Hante Meulemanaeb64222015-10-29 20:33:19 +01003565 } else {
3566 wakeup = NULL;
3567 }
3568 cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
3569}
3570
3571#else
3572
3573static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3574{
3575}
3576
3577#endif /* CONFIG_PM */
3578
Arend van Spriel5b435de2011-10-05 13:19:03 +02003579static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
3580{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003581 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3582 struct net_device *ndev = cfg_to_ndev(cfg);
3583 struct brcmf_if *ifp = netdev_priv(ndev);
3584
Arend van Sprield96b8012012-12-05 15:26:02 +01003585 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003586
Hante Meuleman3021ad92016-01-05 11:05:45 +01003587 if (cfg->wowl.active) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003588 brcmf_report_wowl_wakeind(wiphy, ifp);
3589 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
3590 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meuleman73ef9e62016-02-17 11:27:05 +01003591 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
3592 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003593 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
Hante Meuleman3021ad92016-01-05 11:05:45 +01003594 cfg->wowl.pre_pmmode);
3595 cfg->wowl.active = false;
3596 if (cfg->wowl.nd_enabled) {
3597 brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev);
3598 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3599 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3600 brcmf_notify_sched_scan_results);
3601 cfg->wowl.nd_enabled = false;
3602 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003603 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003604 return 0;
3605}
3606
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003607static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
3608 struct brcmf_if *ifp,
3609 struct cfg80211_wowlan *wowl)
3610{
3611 u32 wowl_config;
Hante Meulemana7ed7822016-09-19 12:09:58 +01003612 struct brcmf_wowl_wakeind_le wowl_wakeind;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003613 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003614
3615 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
3616
Hante Meuleman73ef9e62016-02-17 11:27:05 +01003617 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
3618 brcmf_configure_arp_nd_offload(ifp, false);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003619 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003620 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
3621
3622 wowl_config = 0;
3623 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003624 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003625 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003626 wowl_config |= BRCMF_WOWL_MAGIC;
3627 if ((wowl->patterns) && (wowl->n_patterns)) {
3628 wowl_config |= BRCMF_WOWL_NET;
3629 for (i = 0; i < wowl->n_patterns; i++) {
3630 brcmf_config_wowl_pattern(ifp, "add",
3631 (u8 *)wowl->patterns[i].pattern,
3632 wowl->patterns[i].pattern_len,
3633 (u8 *)wowl->patterns[i].mask,
3634 wowl->patterns[i].pkt_offset);
3635 }
3636 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003637 if (wowl->nd_config) {
3638 brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev,
3639 wowl->nd_config);
3640 wowl_config |= BRCMF_WOWL_PFN_FOUND;
3641
3642 cfg->wowl.nd_data_completed = false;
3643 cfg->wowl.nd_enabled = true;
3644 /* Now reroute the event for PFN to the wowl function. */
3645 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3646 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3647 brcmf_wowl_nd_results);
3648 }
Hante Meuleman5c22fb82016-02-17 11:27:03 +01003649 if (wowl->gtk_rekey_failure)
3650 wowl_config |= BRCMF_WOWL_GTK_FAILURE;
Hante Meuleman3021ad92016-01-05 11:05:45 +01003651 if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
3652 wowl_config |= BRCMF_WOWL_UNASSOC;
3653
Hante Meulemana7ed7822016-09-19 12:09:58 +01003654 memcpy(&wowl_wakeind, "clear", 6);
3655 brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", &wowl_wakeind,
3656 sizeof(wowl_wakeind));
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003657 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
3658 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
3659 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003660 cfg->wowl.active = true;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003661}
3662
Arend van Spriel5b435de2011-10-05 13:19:03 +02003663static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003664 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003665{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003666 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3667 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003668 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07003669 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003670
Arend van Sprield96b8012012-12-05 15:26:02 +01003671 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003672
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003673 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07003674 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02003675 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003676 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07003677 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003678
Hante Meuleman3021ad92016-01-05 11:05:45 +01003679 /* Stop scheduled scan */
3680 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
3681 brcmf_cfg80211_sched_scan_stop(wiphy, ndev);
3682
Arend van Spriel7d641072012-10-22 13:55:39 -07003683 /* end any scanning */
3684 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003685 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003686
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003687 if (wowl == NULL) {
3688 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
3689 list_for_each_entry(vif, &cfg->vif_list, list) {
3690 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
3691 continue;
3692 /* While going to suspend if associated with AP
3693 * disassociate from AP to save power while system is
3694 * in suspended state
3695 */
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01003696 brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003697 /* Make sure WPA_Supplicant receives all the event
3698 * generated due to DISASSOC call to the fw to keep
3699 * the state fw and WPA_Supplicant state consistent
3700 */
3701 brcmf_delay(500);
3702 }
3703 /* Configure MPC */
3704 brcmf_set_mpc(ifp, 1);
3705
3706 } else {
3707 /* Configure WOWL paramaters */
3708 brcmf_configure_wowl(cfg, ifp, wowl);
3709 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003710
Arend van Spriel7d641072012-10-22 13:55:39 -07003711exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01003712 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07003713 /* clear any scanning activity */
3714 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003715 return 0;
3716}
3717
3718static __used s32
Hante Meuleman6c404f32015-12-10 13:43:03 +01003719brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003720{
Hante Meuleman6c404f32015-12-10 13:43:03 +01003721 struct brcmf_pmk_list_le *pmk_list;
3722 int i;
3723 u32 npmk;
3724 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003725
Hante Meuleman6c404f32015-12-10 13:43:03 +01003726 pmk_list = &cfg->pmk_list;
3727 npmk = le32_to_cpu(pmk_list->npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003728
Hante Meuleman6c404f32015-12-10 13:43:03 +01003729 brcmf_dbg(CONN, "No of elements %d\n", npmk);
3730 for (i = 0; i < npmk; i++)
3731 brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003732
Hante Meuleman6c404f32015-12-10 13:43:03 +01003733 err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list,
3734 sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02003735
3736 return err;
3737}
3738
3739static s32
3740brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3741 struct cfg80211_pmksa *pmksa)
3742{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003743 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003744 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003745 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3746 s32 err;
3747 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003748
Arend van Sprield96b8012012-12-05 15:26:02 +01003749 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003750 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003751 return -EIO;
3752
Hante Meuleman6c404f32015-12-10 13:43:03 +01003753 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3754 for (i = 0; i < npmk; i++)
3755 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003756 break;
Hante Meuleman6c404f32015-12-10 13:43:03 +01003757 if (i < BRCMF_MAXPMKID) {
3758 memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN);
3759 memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
3760 if (i == npmk) {
3761 npmk++;
3762 cfg->pmk_list.npmk = cpu_to_le32(npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003763 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003764 } else {
3765 brcmf_err("Too many PMKSA entries cached %d\n", npmk);
3766 return -EINVAL;
3767 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003768
Hante Meuleman6c404f32015-12-10 13:43:03 +01003769 brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid);
3770 for (i = 0; i < WLAN_PMKID_LEN; i += 4)
3771 brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i],
3772 pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2],
3773 pmk[npmk].pmkid[i + 3]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003774
Hante Meuleman6c404f32015-12-10 13:43:03 +01003775 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003776
Arend van Sprield96b8012012-12-05 15:26:02 +01003777 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003778 return err;
3779}
3780
3781static s32
3782brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman6c404f32015-12-10 13:43:03 +01003783 struct cfg80211_pmksa *pmksa)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003784{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003785 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003786 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003787 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3788 s32 err;
3789 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003790
Arend van Sprield96b8012012-12-05 15:26:02 +01003791 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003792 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003793 return -EIO;
3794
Nicolas Iooss7703773ef2016-08-23 11:37:17 +02003795 brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", pmksa->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003796
Hante Meuleman6c404f32015-12-10 13:43:03 +01003797 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3798 for (i = 0; i < npmk; i++)
Nicolas Iooss7703773ef2016-08-23 11:37:17 +02003799 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003800 break;
3801
Hante Meuleman6c404f32015-12-10 13:43:03 +01003802 if ((npmk > 0) && (i < npmk)) {
3803 for (; i < (npmk - 1); i++) {
3804 memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN);
3805 memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003806 WLAN_PMKID_LEN);
3807 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003808 memset(&pmk[i], 0, sizeof(*pmk));
3809 cfg->pmk_list.npmk = cpu_to_le32(npmk - 1);
3810 } else {
3811 brcmf_err("Cache entry not found\n");
3812 return -EINVAL;
3813 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003814
Hante Meuleman6c404f32015-12-10 13:43:03 +01003815 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003816
Arend van Sprield96b8012012-12-05 15:26:02 +01003817 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003818 return err;
3819
3820}
3821
3822static s32
3823brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3824{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003825 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003826 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003827 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003828
Arend van Sprield96b8012012-12-05 15:26:02 +01003829 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003830 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003831 return -EIO;
3832
Hante Meuleman6c404f32015-12-10 13:43:03 +01003833 memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list));
3834 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003835
Arend van Sprield96b8012012-12-05 15:26:02 +01003836 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003837 return err;
3838
3839}
3840
Hante Meuleman1f170112013-02-06 18:40:38 +01003841static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003842{
3843 s32 err;
3844
3845 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003846 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003847 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003848 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003849 return err;
3850 }
3851 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003852 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003853 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003854 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003855 return err;
3856 }
3857 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003858 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003859 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003860 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003861 return err;
3862 }
3863
3864 return 0;
3865}
3866
3867static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3868{
3869 if (is_rsn_ie)
3870 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3871
3872 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3873}
3874
3875static s32
Hante Meulemana44aa402014-12-03 21:05:33 +01003876brcmf_configure_wpaie(struct brcmf_if *ifp,
Johannes Berg4b5800f2014-01-15 14:55:59 +01003877 const struct brcmf_vs_tlv *wpa_ie,
3878 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003879{
3880 u32 auth = 0; /* d11 open authentication */
3881 u16 count;
3882 s32 err = 0;
Hante Meuleman240d61a2016-02-17 11:27:10 +01003883 s32 len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003884 u32 i;
3885 u32 wsec;
3886 u32 pval = 0;
3887 u32 gval = 0;
3888 u32 wpa_auth = 0;
3889 u32 offset;
3890 u8 *data;
3891 u16 rsn_cap;
3892 u32 wme_bss_disable;
Hante Meuleman240d61a2016-02-17 11:27:10 +01003893 u32 mfp;
Hante Meuleman1a873342012-09-27 14:17:54 +02003894
Arend van Sprield96b8012012-12-05 15:26:02 +01003895 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003896 if (wpa_ie == NULL)
3897 goto exit;
3898
3899 len = wpa_ie->len + TLV_HDR_LEN;
3900 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003901 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003902 if (!is_rsn_ie)
3903 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003904 else
3905 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003906
3907 /* check for multicast cipher suite */
3908 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3909 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003910 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003911 goto exit;
3912 }
3913
3914 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3915 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003916 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003917 goto exit;
3918 }
3919 offset += TLV_OUI_LEN;
3920
3921 /* pick up multicast cipher */
3922 switch (data[offset]) {
3923 case WPA_CIPHER_NONE:
3924 gval = 0;
3925 break;
3926 case WPA_CIPHER_WEP_40:
3927 case WPA_CIPHER_WEP_104:
3928 gval = WEP_ENABLED;
3929 break;
3930 case WPA_CIPHER_TKIP:
3931 gval = TKIP_ENABLED;
3932 break;
3933 case WPA_CIPHER_AES_CCM:
3934 gval = AES_ENABLED;
3935 break;
3936 default:
3937 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003938 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003939 goto exit;
3940 }
3941
3942 offset++;
3943 /* walk thru unicast cipher list and pick up what we recognize */
3944 count = data[offset] + (data[offset + 1] << 8);
3945 offset += WPA_IE_SUITE_COUNT_LEN;
3946 /* Check for unicast suite(s) */
3947 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3948 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003949 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003950 goto exit;
3951 }
3952 for (i = 0; i < count; i++) {
3953 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3954 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003955 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003956 goto exit;
3957 }
3958 offset += TLV_OUI_LEN;
3959 switch (data[offset]) {
3960 case WPA_CIPHER_NONE:
3961 break;
3962 case WPA_CIPHER_WEP_40:
3963 case WPA_CIPHER_WEP_104:
3964 pval |= WEP_ENABLED;
3965 break;
3966 case WPA_CIPHER_TKIP:
3967 pval |= TKIP_ENABLED;
3968 break;
3969 case WPA_CIPHER_AES_CCM:
3970 pval |= AES_ENABLED;
3971 break;
3972 default:
Colin Ian Kingad334bb2016-12-23 00:43:22 +00003973 brcmf_err("Invalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003974 }
3975 offset++;
3976 }
3977 /* walk thru auth management suite list and pick up what we recognize */
3978 count = data[offset] + (data[offset + 1] << 8);
3979 offset += WPA_IE_SUITE_COUNT_LEN;
3980 /* Check for auth key management suite(s) */
3981 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3982 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003983 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003984 goto exit;
3985 }
3986 for (i = 0; i < count; i++) {
3987 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3988 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003989 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003990 goto exit;
3991 }
3992 offset += TLV_OUI_LEN;
3993 switch (data[offset]) {
3994 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003995 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003996 wpa_auth |= WPA_AUTH_NONE;
3997 break;
3998 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003999 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004000 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
4001 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
4002 break;
4003 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01004004 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004005 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
4006 (wpa_auth |= WPA_AUTH_PSK);
4007 break;
Hante Meuleman240d61a2016-02-17 11:27:10 +01004008 case RSN_AKM_SHA256_PSK:
4009 brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n");
4010 wpa_auth |= WPA2_AUTH_PSK_SHA256;
4011 break;
4012 case RSN_AKM_SHA256_1X:
4013 brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n");
4014 wpa_auth |= WPA2_AUTH_1X_SHA256;
4015 break;
Hante Meuleman1a873342012-09-27 14:17:54 +02004016 default:
Colin Ian Kingad334bb2016-12-23 00:43:22 +00004017 brcmf_err("Invalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004018 }
4019 offset++;
4020 }
4021
Hante Meuleman240d61a2016-02-17 11:27:10 +01004022 mfp = BRCMF_MFP_NONE;
Hante Meuleman1a873342012-09-27 14:17:54 +02004023 if (is_rsn_ie) {
4024 wme_bss_disable = 1;
4025 if ((offset + RSN_CAP_LEN) <= len) {
4026 rsn_cap = data[offset] + (data[offset + 1] << 8);
4027 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
4028 wme_bss_disable = 0;
Hante Meuleman240d61a2016-02-17 11:27:10 +01004029 if (rsn_cap & RSN_CAP_MFPR_MASK) {
4030 brcmf_dbg(TRACE, "MFP Required\n");
4031 mfp = BRCMF_MFP_REQUIRED;
4032 /* Firmware only supports mfp required in
4033 * combination with WPA2_AUTH_PSK_SHA256 or
4034 * WPA2_AUTH_1X_SHA256.
4035 */
4036 if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 |
4037 WPA2_AUTH_1X_SHA256))) {
4038 err = -EINVAL;
4039 goto exit;
4040 }
4041 /* Firmware has requirement that WPA2_AUTH_PSK/
4042 * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI
4043 * is to be included in the rsn ie.
4044 */
4045 if (wpa_auth & WPA2_AUTH_PSK_SHA256)
4046 wpa_auth |= WPA2_AUTH_PSK;
4047 else if (wpa_auth & WPA2_AUTH_1X_SHA256)
4048 wpa_auth |= WPA2_AUTH_UNSPECIFIED;
4049 } else if (rsn_cap & RSN_CAP_MFPC_MASK) {
4050 brcmf_dbg(TRACE, "MFP Capable\n");
4051 mfp = BRCMF_MFP_CAPABLE;
4052 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004053 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01004054 offset += RSN_CAP_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02004055 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07004056 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004057 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02004058 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004059 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004060 goto exit;
4061 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01004062
4063 /* Skip PMKID cnt as it is know to be 0 for AP. */
4064 offset += RSN_PMKID_COUNT_LEN;
4065
4066 /* See if there is BIP wpa suite left for MFP */
4067 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) &&
4068 ((offset + WPA_IE_MIN_OUI_LEN) <= len)) {
4069 err = brcmf_fil_bsscfg_data_set(ifp, "bip",
4070 &data[offset],
4071 WPA_IE_MIN_OUI_LEN);
4072 if (err < 0) {
4073 brcmf_err("bip error %d\n", err);
4074 goto exit;
4075 }
4076 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004077 }
4078 /* FOR WPS , set SES_OW_ENABLED */
4079 wsec = (pval | gval | SES_OW_ENABLED);
4080
4081 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07004082 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02004083 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004084 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004085 goto exit;
4086 }
4087 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07004088 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004089 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004090 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004091 goto exit;
4092 }
Hante Meuleman240d61a2016-02-17 11:27:10 +01004093 /* Configure MFP, this needs to go after wsec otherwise the wsec command
4094 * will overwrite the values set by MFP
4095 */
4096 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) {
4097 err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp);
4098 if (err < 0) {
4099 brcmf_err("mfp error %d\n", err);
4100 goto exit;
4101 }
4102 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004103 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07004104 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02004105 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004106 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004107 goto exit;
4108 }
4109
4110exit:
4111 return err;
4112}
4113
4114static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08004115brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02004116 struct parsed_vndr_ies *vndr_ies)
4117{
Hante Meuleman1a873342012-09-27 14:17:54 +02004118 struct brcmf_vs_tlv *vndrie;
4119 struct brcmf_tlv *ie;
4120 struct parsed_vndr_ie_info *parsed_info;
4121 s32 remaining_len;
4122
4123 remaining_len = (s32)vndr_ie_len;
4124 memset(vndr_ies, 0, sizeof(*vndr_ies));
4125
4126 ie = (struct brcmf_tlv *)vndr_ie_buf;
4127 while (ie) {
4128 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
4129 goto next;
4130 vndrie = (struct brcmf_vs_tlv *)ie;
4131 /* len should be bigger than OUI length + one */
4132 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004133 brcmf_err("invalid vndr ie. length is too small %d\n",
4134 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004135 goto next;
4136 }
4137 /* if wpa or wme ie, do not add ie */
4138 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
4139 ((vndrie->oui_type == WPA_OUI_TYPE) ||
4140 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004141 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004142 goto next;
4143 }
4144
4145 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
4146
4147 /* save vndr ie information */
4148 parsed_info->ie_ptr = (char *)vndrie;
4149 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
4150 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
4151
4152 vndr_ies->count++;
4153
Arend van Sprield96b8012012-12-05 15:26:02 +01004154 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
4155 parsed_info->vndrie.oui[0],
4156 parsed_info->vndrie.oui[1],
4157 parsed_info->vndrie.oui[2],
4158 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02004159
Arend van Spriel9f440b72013-02-08 15:53:36 +01004160 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02004161 break;
4162next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004163 remaining_len -= (ie->len + TLV_HDR_LEN);
4164 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02004165 ie = NULL;
4166 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004167 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
4168 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02004169 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004170 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004171}
4172
4173static u32
4174brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
4175{
4176
Hante Meuleman1a873342012-09-27 14:17:54 +02004177 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
4178 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
4179
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304180 put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004181
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304182 put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004183
4184 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
4185
4186 return ie_len + VNDR_IE_HDR_SIZE;
4187}
4188
Arend van Spriel1332e262012-11-05 16:22:18 -08004189s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
4190 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02004191{
Arend van Spriel1332e262012-11-05 16:22:18 -08004192 struct brcmf_if *ifp;
4193 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004194 s32 err = 0;
4195 u8 *iovar_ie_buf;
4196 u8 *curr_ie_buf;
4197 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004198 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07004199 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004200 u32 del_add_ie_buf_len = 0;
4201 u32 total_ie_buf_len = 0;
4202 u32 parsed_ie_buf_len = 0;
4203 struct parsed_vndr_ies old_vndr_ies;
4204 struct parsed_vndr_ies new_vndr_ies;
4205 struct parsed_vndr_ie_info *vndrie_info;
4206 s32 i;
4207 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004208 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004209
Arend van Spriel1332e262012-11-05 16:22:18 -08004210 if (!vif)
4211 return -ENODEV;
4212 ifp = vif->ifp;
4213 saved_ie = &vif->saved_ie;
4214
Hante Meuleman37a869e2015-10-29 20:33:17 +01004215 brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
4216 pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02004217 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4218 if (!iovar_ie_buf)
4219 return -ENOMEM;
4220 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01004221 switch (pktflag) {
4222 case BRCMF_VNDR_IE_PRBREQ_FLAG:
4223 mgmt_ie_buf = saved_ie->probe_req_ie;
4224 mgmt_ie_len = &saved_ie->probe_req_ie_len;
4225 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
4226 break;
4227 case BRCMF_VNDR_IE_PRBRSP_FLAG:
4228 mgmt_ie_buf = saved_ie->probe_res_ie;
4229 mgmt_ie_len = &saved_ie->probe_res_ie_len;
4230 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
4231 break;
4232 case BRCMF_VNDR_IE_BEACON_FLAG:
4233 mgmt_ie_buf = saved_ie->beacon_ie;
4234 mgmt_ie_len = &saved_ie->beacon_ie_len;
4235 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
4236 break;
4237 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
4238 mgmt_ie_buf = saved_ie->assoc_req_ie;
4239 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
4240 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
4241 break;
4242 default:
4243 err = -EPERM;
4244 brcmf_err("not suitable type\n");
4245 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004246 }
4247
4248 if (vndr_ie_len > mgmt_ie_buf_len) {
4249 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01004250 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004251 goto exit;
4252 }
4253
4254 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
4255 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
4256 ptr = curr_ie_buf;
4257 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
4258 for (i = 0; i < new_vndr_ies.count; i++) {
4259 vndrie_info = &new_vndr_ies.ie_info[i];
4260 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
4261 vndrie_info->ie_len);
4262 parsed_ie_buf_len += vndrie_info->ie_len;
4263 }
4264 }
4265
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004266 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004267 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
4268 (memcmp(mgmt_ie_buf, curr_ie_buf,
4269 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004270 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004271 goto exit;
4272 }
4273
4274 /* parse old vndr_ie */
4275 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
4276
4277 /* make a command to delete old ie */
4278 for (i = 0; i < old_vndr_ies.count; i++) {
4279 vndrie_info = &old_vndr_ies.ie_info[i];
4280
Arend van Sprield96b8012012-12-05 15:26:02 +01004281 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
4282 vndrie_info->vndrie.id,
4283 vndrie_info->vndrie.len,
4284 vndrie_info->vndrie.oui[0],
4285 vndrie_info->vndrie.oui[1],
4286 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004287
4288 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4289 vndrie_info->ie_ptr,
4290 vndrie_info->ie_len,
4291 "del");
4292 curr_ie_buf += del_add_ie_buf_len;
4293 total_ie_buf_len += del_add_ie_buf_len;
4294 }
4295 }
4296
4297 *mgmt_ie_len = 0;
4298 /* Add if there is any extra IE */
4299 if (mgmt_ie_buf && parsed_ie_buf_len) {
4300 ptr = mgmt_ie_buf;
4301
4302 remained_buf_len = mgmt_ie_buf_len;
4303
4304 /* make a command to add new ie */
4305 for (i = 0; i < new_vndr_ies.count; i++) {
4306 vndrie_info = &new_vndr_ies.ie_info[i];
4307
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004308 /* verify remained buf size before copy data */
4309 if (remained_buf_len < (vndrie_info->vndrie.len +
4310 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004311 brcmf_err("no space in mgmt_ie_buf: len left %d",
4312 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004313 break;
4314 }
4315 remained_buf_len -= (vndrie_info->ie_len +
4316 VNDR_IE_VSIE_OFFSET);
4317
Arend van Sprield96b8012012-12-05 15:26:02 +01004318 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
4319 vndrie_info->vndrie.id,
4320 vndrie_info->vndrie.len,
4321 vndrie_info->vndrie.oui[0],
4322 vndrie_info->vndrie.oui[1],
4323 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004324
4325 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4326 vndrie_info->ie_ptr,
4327 vndrie_info->ie_len,
4328 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02004329
4330 /* save the parsed IE in wl struct */
4331 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
4332 vndrie_info->ie_len);
4333 *mgmt_ie_len += vndrie_info->ie_len;
4334
4335 curr_ie_buf += del_add_ie_buf_len;
4336 total_ie_buf_len += del_add_ie_buf_len;
4337 }
4338 }
4339 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004340 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004341 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004342 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004343 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004344 }
4345
4346exit:
4347 kfree(iovar_ie_buf);
4348 return err;
4349}
4350
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004351s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
4352{
4353 s32 pktflags[] = {
4354 BRCMF_VNDR_IE_PRBREQ_FLAG,
4355 BRCMF_VNDR_IE_PRBRSP_FLAG,
4356 BRCMF_VNDR_IE_BEACON_FLAG
4357 };
4358 int i;
4359
4360 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
4361 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
4362
4363 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
4364 return 0;
4365}
4366
Hante Meuleman1a873342012-09-27 14:17:54 +02004367static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01004368brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
4369 struct cfg80211_beacon_data *beacon)
4370{
4371 s32 err;
4372
4373 /* Set Beacon IEs to FW */
4374 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
4375 beacon->tail, beacon->tail_len);
4376 if (err) {
4377 brcmf_err("Set Beacon IE Failed\n");
4378 return err;
4379 }
4380 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
4381
4382 /* Set Probe Response IEs to FW */
4383 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
4384 beacon->proberesp_ies,
4385 beacon->proberesp_ies_len);
4386 if (err)
4387 brcmf_err("Set Probe Resp IE Failed\n");
4388 else
4389 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
4390
4391 return err;
4392}
4393
4394static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02004395brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
4396 struct cfg80211_ap_settings *settings)
4397{
4398 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02004399 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07004400 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01004401 const struct brcmf_tlv *ssid_ie;
Arend van Spriel98027762014-12-21 12:43:53 +01004402 const struct brcmf_tlv *country_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004403 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02004404 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01004405 const struct brcmf_tlv *rsn_ie;
4406 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004407 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01004408 enum nl80211_iftype dev_role;
4409 struct brcmf_fil_bss_enable_le bss_enable;
Rafał Miłecki8707e082016-05-27 21:07:19 +02004410 u16 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef);
Hante Meulemana44aa402014-12-03 21:05:33 +01004411 bool mbss;
Arend van Spriel98027762014-12-21 12:43:53 +01004412 int is_11d;
Hante Meulemanb3589df2016-09-19 12:09:51 +01004413 bool supports_11d;
Hante Meuleman1a873342012-09-27 14:17:54 +02004414
Arend van Spriel06c01582014-05-12 10:47:37 +02004415 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
4416 settings->chandef.chan->hw_value,
4417 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02004418 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01004419 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
4420 settings->ssid, settings->ssid_len, settings->auth_type,
4421 settings->inactivity_timeout);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004422 dev_role = ifp->vif->wdev.iftype;
Hante Meulemana44aa402014-12-03 21:05:33 +01004423 mbss = ifp->vif->mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02004424
Arend van Spriel98027762014-12-21 12:43:53 +01004425 /* store current 11d setting */
Hante Meulemanb3589df2016-09-19 12:09:51 +01004426 if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY,
4427 &ifp->vif->is_11d)) {
Arnd Bergmannd3532ea2016-10-18 00:13:40 +02004428 is_11d = supports_11d = false;
Hante Meulemanb3589df2016-09-19 12:09:51 +01004429 } else {
4430 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4431 settings->beacon.tail_len,
4432 WLAN_EID_COUNTRY);
4433 is_11d = country_ie ? 1 : 0;
4434 supports_11d = true;
4435 }
Arend van Spriel98027762014-12-21 12:43:53 +01004436
Hante Meuleman1a873342012-09-27 14:17:54 +02004437 memset(&ssid_le, 0, sizeof(ssid_le));
4438 if (settings->ssid == NULL || settings->ssid_len == 0) {
4439 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
4440 ssid_ie = brcmf_parse_tlvs(
4441 (u8 *)&settings->beacon.head[ie_offset],
4442 settings->beacon.head_len - ie_offset,
4443 WLAN_EID_SSID);
Arend Van Sprielded89912016-09-05 10:45:47 +01004444 if (!ssid_ie || ssid_ie->len > IEEE80211_MAX_SSID_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02004445 return -EINVAL;
4446
4447 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
4448 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01004449 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02004450 } else {
4451 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
4452 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
4453 }
4454
Hante Meulemana44aa402014-12-03 21:05:33 +01004455 if (!mbss) {
4456 brcmf_set_mpc(ifp, 0);
Franky Lin52f22fb2016-02-17 11:26:55 +01004457 brcmf_configure_arp_nd_offload(ifp, false);
Hante Meulemana44aa402014-12-03 21:05:33 +01004458 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004459
4460 /* find the RSN_IE */
4461 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4462 settings->beacon.tail_len, WLAN_EID_RSN);
4463
4464 /* find the WPA_IE */
4465 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
4466 settings->beacon.tail_len);
4467
Hante Meuleman1a873342012-09-27 14:17:54 +02004468 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004469 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004470 if (wpa_ie != NULL) {
4471 /* WPA IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004472 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02004473 if (err < 0)
4474 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004475 } else {
Hante Meulemana44aa402014-12-03 21:05:33 +01004476 struct brcmf_vs_tlv *tmp_ie;
4477
4478 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
4479
Hante Meuleman1a873342012-09-27 14:17:54 +02004480 /* RSN IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004481 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004482 if (err < 0)
4483 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004484 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004485 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01004486 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01004487 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02004488 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004489
Rafał Miłecki8707e082016-05-27 21:07:19 +02004490 /* Parameters shared by all radio interfaces */
Hante Meulemana44aa402014-12-03 21:05:33 +01004491 if (!mbss) {
Hante Meulemanb3589df2016-09-19 12:09:51 +01004492 if ((supports_11d) && (is_11d != ifp->vif->is_11d)) {
Arend van Spriel98027762014-12-21 12:43:53 +01004493 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4494 is_11d);
4495 if (err < 0) {
4496 brcmf_err("Regulatory Set Error, %d\n", err);
4497 goto exit;
4498 }
4499 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004500 if (settings->beacon_interval) {
4501 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
4502 settings->beacon_interval);
4503 if (err < 0) {
4504 brcmf_err("Beacon Interval Set Error, %d\n",
4505 err);
4506 goto exit;
4507 }
4508 }
4509 if (settings->dtim_period) {
4510 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
4511 settings->dtim_period);
4512 if (err < 0) {
4513 brcmf_err("DTIM Interval Set Error, %d\n", err);
4514 goto exit;
4515 }
4516 }
4517
Hante Meuleman8abffd82015-10-29 20:33:16 +01004518 if ((dev_role == NL80211_IFTYPE_AP) &&
4519 ((ifp->ifidx == 0) ||
4520 !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004521 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4522 if (err < 0) {
4523 brcmf_err("BRCMF_C_DOWN error %d\n", err);
4524 goto exit;
4525 }
4526 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
4527 }
4528
4529 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02004530 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004531 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004532 goto exit;
4533 }
Hante Meulemanb3589df2016-09-19 12:09:51 +01004534 } else if (WARN_ON(supports_11d && (is_11d != ifp->vif->is_11d))) {
Arend van Spriel98027762014-12-21 12:43:53 +01004535 /* Multiple-BSS should use same 11d configuration */
4536 err = -EINVAL;
4537 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004538 }
Rafał Miłecki8707e082016-05-27 21:07:19 +02004539
4540 /* Interface specific setup */
Hante Meulemana0f07952013-02-08 15:53:47 +01004541 if (dev_role == NL80211_IFTYPE_AP) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004542 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
4543 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
4544
Hante Meulemana0f07952013-02-08 15:53:47 +01004545 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
4546 if (err < 0) {
4547 brcmf_err("setting AP mode failed %d\n", err);
4548 goto exit;
4549 }
Rafał Miłecki8707e082016-05-27 21:07:19 +02004550 if (!mbss) {
4551 /* Firmware 10.x requires setting channel after enabling
4552 * AP and before bringing interface up.
4553 */
4554 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
4555 if (err < 0) {
4556 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4557 chanspec, err);
4558 goto exit;
4559 }
4560 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004561 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4562 if (err < 0) {
4563 brcmf_err("BRCMF_C_UP error (%d)\n", err);
4564 goto exit;
4565 }
Hante Meuleman118eb302014-12-21 12:43:49 +01004566 /* On DOWN the firmware removes the WEP keys, reconfigure
4567 * them if they were set.
4568 */
4569 brcmf_cfg80211_reconfigure_wep(ifp);
Hante Meulemana0f07952013-02-08 15:53:47 +01004570
4571 memset(&join_params, 0, sizeof(join_params));
4572 /* join parameters starts with ssid */
4573 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
4574 /* create softap */
4575 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4576 &join_params, sizeof(join_params));
4577 if (err < 0) {
4578 brcmf_err("SET SSID error (%d)\n", err);
4579 goto exit;
4580 }
Rafał Miłeckic940de12016-07-06 12:22:54 +02004581
4582 if (settings->hidden_ssid) {
4583 err = brcmf_fil_iovar_int_set(ifp, "closednet", 1);
4584 if (err) {
4585 brcmf_err("closednet error (%d)\n", err);
4586 goto exit;
4587 }
4588 }
4589
Hante Meulemana0f07952013-02-08 15:53:47 +01004590 brcmf_dbg(TRACE, "AP mode configuration complete\n");
Rafał Miłecki8707e082016-05-27 21:07:19 +02004591 } else if (dev_role == NL80211_IFTYPE_P2P_GO) {
4592 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
4593 if (err < 0) {
4594 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4595 chanspec, err);
4596 goto exit;
4597 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004598 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
4599 sizeof(ssid_le));
4600 if (err < 0) {
4601 brcmf_err("setting ssid failed %d\n", err);
4602 goto exit;
4603 }
Hante Meuleman37a869e2015-10-29 20:33:17 +01004604 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meulemana0f07952013-02-08 15:53:47 +01004605 bss_enable.enable = cpu_to_le32(1);
4606 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4607 sizeof(bss_enable));
4608 if (err < 0) {
4609 brcmf_err("bss_enable config failed %d\n", err);
4610 goto exit;
4611 }
4612
4613 brcmf_dbg(TRACE, "GO mode configuration complete\n");
Rafał Miłecki8707e082016-05-27 21:07:19 +02004614 } else {
4615 WARN_ON(1);
Hante Meulemana0f07952013-02-08 15:53:47 +01004616 }
Rafał Miłecki8707e082016-05-27 21:07:19 +02004617
Wright Fengf25ba692016-11-18 09:59:52 +08004618 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Arend van Sprielc1179032012-10-22 13:55:33 -07004619 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004620 brcmf_net_setcarrier(ifp, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004621
4622exit:
Hante Meulemana44aa402014-12-03 21:05:33 +01004623 if ((err) && (!mbss)) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02004624 brcmf_set_mpc(ifp, 1);
Franky Lin52f22fb2016-02-17 11:26:55 +01004625 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meulemanb3657452013-05-27 21:09:53 +02004626 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004627 return err;
4628}
4629
4630static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
4631{
Arend van Sprielc1179032012-10-22 13:55:33 -07004632 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004633 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01004634 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02004635 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02004636
Arend van Sprield96b8012012-12-05 15:26:02 +01004637 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004638
Hante Meuleman426d0a52013-02-08 15:53:53 +01004639 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004640 /* Due to most likely deauths outstanding we sleep */
4641 /* first to make sure they get processed by fw. */
4642 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004643
Hante Meulemana44aa402014-12-03 21:05:33 +01004644 if (ifp->vif->mbss) {
4645 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4646 return err;
4647 }
4648
Rafał Miłeckic940de12016-07-06 12:22:54 +02004649 /* First BSS doesn't get a full reset */
4650 if (ifp->bsscfgidx == 0)
4651 brcmf_fil_iovar_int_set(ifp, "closednet", 0);
4652
Hante Meuleman5c33a942013-04-02 21:06:18 +02004653 memset(&join_params, 0, sizeof(join_params));
4654 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4655 &join_params, sizeof(join_params));
4656 if (err < 0)
4657 brcmf_err("SET SSID error (%d)\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004658 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004659 if (err < 0)
Hante Meulemana44aa402014-12-03 21:05:33 +01004660 brcmf_err("BRCMF_C_DOWN error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004661 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4662 if (err < 0)
4663 brcmf_err("setting AP mode failed %d\n", err);
4664 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4665 if (err < 0)
4666 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004667 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
4668 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
Hante Meulemanb3589df2016-09-19 12:09:51 +01004669 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4670 ifp->vif->is_11d);
Hante Meulemana44aa402014-12-03 21:05:33 +01004671 /* Bring device back up so it can be used again */
4672 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4673 if (err < 0)
4674 brcmf_err("BRCMF_C_UP error %d\n", err);
Wright Fengf25ba692016-11-18 09:59:52 +08004675
4676 brcmf_vif_clear_mgmt_ies(ifp->vif);
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);
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08004880 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%zu\n", len);
Hante Meulemana0f07952013-02-08 15:53:47 +01004881 }
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
Rafał Miłeckiee6e7aa2016-05-20 13:38:58 +02004910static int brcmf_cfg80211_get_channel(struct wiphy *wiphy,
4911 struct wireless_dev *wdev,
4912 struct cfg80211_chan_def *chandef)
4913{
4914 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4915 struct net_device *ndev = wdev->netdev;
4916 struct brcmf_if *ifp;
4917 struct brcmu_chan ch;
4918 enum nl80211_band band = 0;
4919 enum nl80211_chan_width width = 0;
4920 u32 chanspec;
4921 int freq, err;
4922
4923 if (!ndev)
4924 return -ENODEV;
4925 ifp = netdev_priv(ndev);
4926
4927 err = brcmf_fil_iovar_int_get(ifp, "chanspec", &chanspec);
4928 if (err) {
4929 brcmf_err("chanspec failed (%d)\n", err);
4930 return err;
4931 }
4932
4933 ch.chspec = chanspec;
4934 cfg->d11inf.decchspec(&ch);
4935
4936 switch (ch.band) {
4937 case BRCMU_CHAN_BAND_2G:
4938 band = NL80211_BAND_2GHZ;
4939 break;
4940 case BRCMU_CHAN_BAND_5G:
4941 band = NL80211_BAND_5GHZ;
4942 break;
4943 }
4944
4945 switch (ch.bw) {
4946 case BRCMU_CHAN_BW_80:
4947 width = NL80211_CHAN_WIDTH_80;
4948 break;
4949 case BRCMU_CHAN_BW_40:
4950 width = NL80211_CHAN_WIDTH_40;
4951 break;
4952 case BRCMU_CHAN_BW_20:
4953 width = NL80211_CHAN_WIDTH_20;
4954 break;
4955 case BRCMU_CHAN_BW_80P80:
4956 width = NL80211_CHAN_WIDTH_80P80;
4957 break;
4958 case BRCMU_CHAN_BW_160:
4959 width = NL80211_CHAN_WIDTH_160;
4960 break;
4961 }
4962
4963 freq = ieee80211_channel_to_frequency(ch.control_ch_num, band);
4964 chandef->chan = ieee80211_get_channel(wiphy, freq);
4965 chandef->width = width;
4966 chandef->center_freq1 = ieee80211_channel_to_frequency(ch.chnum, band);
4967 chandef->center_freq2 = 0;
4968
4969 return 0;
4970}
4971
Piotr Haber61730d42013-04-23 12:53:12 +02004972static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4973 struct wireless_dev *wdev,
4974 enum nl80211_crit_proto_id proto,
4975 u16 duration)
4976{
4977 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4978 struct brcmf_cfg80211_vif *vif;
4979
4980 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4981
4982 /* only DHCP support for now */
4983 if (proto != NL80211_CRIT_PROTO_DHCP)
4984 return -EINVAL;
4985
4986 /* suppress and abort scanning */
4987 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4988 brcmf_abort_scanning(cfg);
4989
4990 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4991}
4992
4993static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4994 struct wireless_dev *wdev)
4995{
4996 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4997 struct brcmf_cfg80211_vif *vif;
4998
4999 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
5000
5001 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
5002 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
5003}
5004
Hante Meuleman70b7d942014-07-30 13:20:07 +02005005static s32
5006brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
5007 const struct brcmf_event_msg *e, void *data)
5008{
5009 switch (e->reason) {
5010 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
5011 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
5012 break;
5013 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
5014 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
5015 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5016 break;
5017 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
5018 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
5019 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5020 break;
5021 }
5022
5023 return 0;
5024}
5025
Arend van Spriel89c2f382013-08-10 12:27:25 +02005026static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
5027{
5028 int ret;
5029
5030 switch (oper) {
5031 case NL80211_TDLS_DISCOVERY_REQ:
5032 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
5033 break;
5034 case NL80211_TDLS_SETUP:
5035 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
5036 break;
5037 case NL80211_TDLS_TEARDOWN:
5038 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
5039 break;
5040 default:
5041 brcmf_err("unsupported operation: %d\n", oper);
5042 ret = -EOPNOTSUPP;
5043 }
5044 return ret;
5045}
5046
5047static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02005048 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02005049 enum nl80211_tdls_operation oper)
5050{
5051 struct brcmf_if *ifp;
5052 struct brcmf_tdls_iovar_le info;
5053 int ret = 0;
5054
5055 ret = brcmf_convert_nl80211_tdls_oper(oper);
5056 if (ret < 0)
5057 return ret;
5058
5059 ifp = netdev_priv(ndev);
5060 memset(&info, 0, sizeof(info));
5061 info.mode = (u8)ret;
5062 if (peer)
5063 memcpy(info.ea, peer, ETH_ALEN);
5064
5065 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
5066 &info, sizeof(info));
5067 if (ret < 0)
5068 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
5069
5070 return ret;
5071}
5072
Arend Van Spriel2a2a5d12017-01-27 12:27:48 +00005073static int
5074brcmf_cfg80211_update_conn_params(struct wiphy *wiphy,
5075 struct net_device *ndev,
5076 struct cfg80211_connect_params *sme,
5077 u32 changed)
5078{
5079 struct brcmf_if *ifp;
5080 int err;
5081
5082 if (!(changed & UPDATE_ASSOC_IES))
5083 return 0;
5084
5085 ifp = netdev_priv(ndev);
5086 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
5087 sme->ie, sme->ie_len);
5088 if (err)
5089 brcmf_err("Set Assoc REQ IE Failed\n");
5090 else
5091 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
5092
5093 return err;
5094}
5095
Hante Meuleman5c22fb82016-02-17 11:27:03 +01005096#ifdef CONFIG_PM
5097static int
5098brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev,
5099 struct cfg80211_gtk_rekey_data *gtk)
5100{
5101 struct brcmf_if *ifp = netdev_priv(ndev);
5102 struct brcmf_gtk_keyinfo_le gtk_le;
5103 int ret;
5104
5105 brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx);
5106
5107 memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck));
5108 memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek));
5109 memcpy(gtk_le.replay_counter, gtk->replay_ctr,
5110 sizeof(gtk_le.replay_counter));
5111
5112 ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", &gtk_le,
5113 sizeof(gtk_le));
5114 if (ret < 0)
5115 brcmf_err("gtk_key_info iovar failed: ret=%d\n", ret);
5116
5117 return ret;
5118}
5119#endif
5120
5121static struct cfg80211_ops brcmf_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01005122 .add_virtual_intf = brcmf_cfg80211_add_iface,
5123 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005124 .change_virtual_intf = brcmf_cfg80211_change_iface,
5125 .scan = brcmf_cfg80211_scan,
5126 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
5127 .join_ibss = brcmf_cfg80211_join_ibss,
5128 .leave_ibss = brcmf_cfg80211_leave_ibss,
5129 .get_station = brcmf_cfg80211_get_station,
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02005130 .dump_station = brcmf_cfg80211_dump_station,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005131 .set_tx_power = brcmf_cfg80211_set_tx_power,
5132 .get_tx_power = brcmf_cfg80211_get_tx_power,
5133 .add_key = brcmf_cfg80211_add_key,
5134 .del_key = brcmf_cfg80211_del_key,
5135 .get_key = brcmf_cfg80211_get_key,
5136 .set_default_key = brcmf_cfg80211_config_default_key,
5137 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
5138 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005139 .connect = brcmf_cfg80211_connect,
5140 .disconnect = brcmf_cfg80211_disconnect,
5141 .suspend = brcmf_cfg80211_suspend,
5142 .resume = brcmf_cfg80211_resume,
5143 .set_pmksa = brcmf_cfg80211_set_pmksa,
5144 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02005145 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02005146 .start_ap = brcmf_cfg80211_start_ap,
5147 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01005148 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02005149 .del_station = brcmf_cfg80211_del_station,
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01005150 .change_station = brcmf_cfg80211_change_station,
Arend van Spriele5806072012-09-19 22:21:08 +02005151 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
5152 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005153 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
5154 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
5155 .remain_on_channel = brcmf_p2p_remain_on_channel,
5156 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Rafał Miłeckiee6e7aa2016-05-20 13:38:58 +02005157 .get_channel = brcmf_cfg80211_get_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02005158 .start_p2p_device = brcmf_p2p_start_device,
5159 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02005160 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
5161 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02005162 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend Van Spriel2a2a5d12017-01-27 12:27:48 +00005163 .update_connect_params = brcmf_cfg80211_update_conn_params,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005164};
5165
Arend van Spriel3eacf862012-10-22 13:55:30 -07005166struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Rafał Miłecki26072332016-06-06 23:03:55 +02005167 enum nl80211_iftype type)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005168{
Hante Meulemana44aa402014-12-03 21:05:33 +01005169 struct brcmf_cfg80211_vif *vif_walk;
Arend van Spriel3eacf862012-10-22 13:55:30 -07005170 struct brcmf_cfg80211_vif *vif;
Hante Meulemana44aa402014-12-03 21:05:33 +01005171 bool mbss;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005172
Arend van Spriel33a6b152013-02-08 15:53:39 +01005173 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01005174 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07005175 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
5176 if (!vif)
5177 return ERR_PTR(-ENOMEM);
5178
5179 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005180 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07005181
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07005182 brcmf_init_prof(&vif->profile);
5183
Hante Meulemana44aa402014-12-03 21:05:33 +01005184 if (type == NL80211_IFTYPE_AP) {
5185 mbss = false;
5186 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
5187 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
5188 mbss = true;
5189 break;
5190 }
5191 }
5192 vif->mbss = mbss;
5193 }
5194
Arend van Spriel3eacf862012-10-22 13:55:30 -07005195 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07005196 return vif;
5197}
5198
Arend van Spriel427dec52014-01-06 12:40:47 +01005199void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07005200{
Arend van Spriel3eacf862012-10-22 13:55:30 -07005201 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07005202 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005203}
5204
Arend van Spriel9df4d542014-01-06 12:40:49 +01005205void brcmf_cfg80211_free_netdev(struct net_device *ndev)
5206{
5207 struct brcmf_cfg80211_vif *vif;
5208 struct brcmf_if *ifp;
5209
5210 ifp = netdev_priv(ndev);
5211 vif = ifp->vif;
5212
Arend van Spriel95ef1232015-08-26 22:15:04 +02005213 if (vif)
5214 brcmf_free_vif(vif);
Arend van Spriel9df4d542014-01-06 12:40:49 +01005215 free_netdev(ndev);
5216}
5217
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005218static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005219{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005220 u32 event = e->event_code;
5221 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005222
5223 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005224 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005225 return true;
5226 }
5227
5228 return false;
5229}
5230
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005231static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005232{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005233 u32 event = e->event_code;
5234 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005235
Hante Meuleman68ca3952014-02-25 20:30:26 +01005236 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
5237 (event == BRCMF_E_DISASSOC_IND) ||
5238 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01005239 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005240 return true;
5241 }
5242 return false;
5243}
5244
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005245static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005246 const struct brcmf_event_msg *e)
5247{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005248 u32 event = e->event_code;
5249 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005250
5251 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005252 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
5253 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005254 return true;
5255 }
5256
5257 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005258 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005259 return true;
5260 }
5261
5262 return false;
5263}
5264
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005265static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005266{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005267 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005268
5269 kfree(conn_info->req_ie);
5270 conn_info->req_ie = NULL;
5271 conn_info->req_ie_len = 0;
5272 kfree(conn_info->resp_ie);
5273 conn_info->resp_ie = NULL;
5274 conn_info->resp_ie_len = 0;
5275}
5276
Hante Meuleman89286dc2013-02-08 15:53:46 +01005277static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
5278 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005279{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005280 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005281 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005282 u32 req_len;
5283 u32 resp_len;
5284 s32 err = 0;
5285
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005286 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005287
Arend van Sprielac24be62012-10-22 10:36:23 -07005288 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
5289 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005290 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005291 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005292 return err;
5293 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005294 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005295 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005296 req_len = le32_to_cpu(assoc_info->req_len);
5297 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005298 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005299 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005300 cfg->extra_buf,
5301 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005302 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005303 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005304 return err;
5305 }
5306 conn_info->req_ie_len = req_len;
5307 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005308 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005309 GFP_KERNEL);
5310 } else {
5311 conn_info->req_ie_len = 0;
5312 conn_info->req_ie = NULL;
5313 }
5314 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005315 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005316 cfg->extra_buf,
5317 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005318 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005319 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005320 return err;
5321 }
5322 conn_info->resp_ie_len = resp_len;
5323 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005324 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005325 GFP_KERNEL);
5326 } else {
5327 conn_info->resp_ie_len = 0;
5328 conn_info->resp_ie = NULL;
5329 }
Arend van Spriel16886732012-12-05 15:26:04 +01005330 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
5331 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005332
5333 return err;
5334}
5335
5336static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005337brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005338 struct net_device *ndev,
5339 const struct brcmf_event_msg *e)
5340{
Arend van Sprielc1179032012-10-22 13:55:33 -07005341 struct brcmf_if *ifp = netdev_priv(ndev);
5342 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005343 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
5344 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07005345 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005346 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07005347 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02005348 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005349 u32 freq;
5350 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07005351 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005352
Arend van Sprield96b8012012-12-05 15:26:02 +01005353 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005354
Hante Meuleman89286dc2013-02-08 15:53:46 +01005355 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005356 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005357 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005358
Franky Lina180b832012-10-10 11:13:09 -07005359 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
5360 if (buf == NULL) {
5361 err = -ENOMEM;
5362 goto done;
5363 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02005364
Franky Lina180b832012-10-10 11:13:09 -07005365 /* data sent to dongle has to be little endian */
5366 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07005367 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07005368 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07005369
5370 if (err)
5371 goto done;
5372
5373 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02005374 ch.chspec = le16_to_cpu(bi->chanspec);
5375 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005376
Franky Lin83cf17a2013-04-11 13:28:50 +02005377 if (ch.band == BRCMU_CHAN_BAND_2G)
Johannes Berg57fbcce2016-04-12 15:56:15 +02005378 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005379 else
Johannes Berg57fbcce2016-04-12 15:56:15 +02005380 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005381
Rafał Miłecki4712d882016-05-20 13:38:57 +02005382 freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005383 notify_channel = ieee80211_get_channel(wiphy, freq);
5384
Franky Lina180b832012-10-10 11:13:09 -07005385done:
5386 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02005387 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005388 conn_info->req_ie, conn_info->req_ie_len,
5389 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005390 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005391
Arend van Sprielc1179032012-10-22 13:55:33 -07005392 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01005393 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005394 return err;
5395}
5396
5397static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005398brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005399 struct net_device *ndev, const struct brcmf_event_msg *e,
5400 bool completed)
5401{
Arend van Sprielc1179032012-10-22 13:55:33 -07005402 struct brcmf_if *ifp = netdev_priv(ndev);
5403 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005404 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005405
Arend van Sprield96b8012012-12-05 15:26:02 +01005406 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005407
Arend van Sprielc1179032012-10-22 13:55:33 -07005408 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5409 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02005410 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01005411 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005412 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005413 brcmf_update_bss_info(cfg, ifp);
5414 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5415 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005416 }
5417 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02005418 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005419 conn_info->req_ie,
5420 conn_info->req_ie_len,
5421 conn_info->resp_ie,
5422 conn_info->resp_ie_len,
5423 completed ? WLAN_STATUS_SUCCESS :
5424 WLAN_STATUS_AUTH_TIMEOUT,
5425 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005426 brcmf_dbg(CONN, "Report connect result - connection %s\n",
5427 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005428 }
Arend van Sprield96b8012012-12-05 15:26:02 +01005429 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005430 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005431}
5432
5433static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005434brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02005435 struct net_device *ndev,
5436 const struct brcmf_event_msg *e, void *data)
5437{
Hante Meuleman7ee29602013-02-06 18:40:43 +01005438 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005439 u32 event = e->event_code;
5440 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02005441 struct station_info sinfo;
5442
Rafał Miłeckie1c122d2016-10-14 09:45:59 +02005443 brcmf_dbg(CONN, "event %s (%u), reason %d\n",
5444 brcmf_fweh_event_name(event), event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005445 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
5446 ndev != cfg_to_ndev(cfg)) {
5447 brcmf_dbg(CONN, "AP mode link down\n");
5448 complete(&cfg->vif_disabled);
5449 return 0;
5450 }
Hante Meuleman1a873342012-09-27 14:17:54 +02005451
Hante Meuleman1a873342012-09-27 14:17:54 +02005452 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01005453 (reason == BRCMF_E_STATUS_SUCCESS)) {
5454 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02005455 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005456 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02005457 return -EINVAL;
5458 }
5459 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005460 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02005461 generation++;
5462 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005463 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005464 } else if ((event == BRCMF_E_DISASSOC_IND) ||
5465 (event == BRCMF_E_DEAUTH_IND) ||
5466 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01005467 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005468 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01005469 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02005470}
5471
5472static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005473brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005474 const struct brcmf_event_msg *e, void *data)
5475{
Arend van Spriel19937322012-11-05 16:22:32 -08005476 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5477 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07005478 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005479 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005480 s32 err = 0;
5481
Hante Meuleman8851cce2014-07-30 13:20:02 +02005482 if ((e->event_code == BRCMF_E_DEAUTH) ||
5483 (e->event_code == BRCMF_E_DEAUTH_IND) ||
5484 (e->event_code == BRCMF_E_DISASSOC_IND) ||
5485 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
5486 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5487 }
5488
Arend van Spriel967fe2c2014-03-15 17:18:21 +01005489 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005490 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005491 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005492 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005493 if (brcmf_is_ibssmode(ifp->vif)) {
Hante Meulemanb0a79082015-12-10 13:43:07 +01005494 brcmf_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005495 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005496 memcpy(profile->bssid, e->addr, ETH_ALEN);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005497 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07005498 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5499 &ifp->vif->sme_state);
5500 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5501 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005502 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005503 brcmf_bss_connect_done(cfg, ndev, e, true);
Hante Meuleman92121e62015-10-08 20:33:21 +02005504 brcmf_net_setcarrier(ifp, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005505 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005506 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005507 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005508 brcmf_bss_connect_done(cfg, ndev, e, false);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01005509 brcmf_link_down(ifp->vif,
5510 brcmf_map_fw_linkdown_reason(e));
5511 brcmf_init_prof(ndev_to_prof(ndev));
5512 if (ndev != cfg_to_ndev(cfg))
5513 complete(&cfg->vif_disabled);
5514 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005515 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005516 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005517 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07005518 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5519 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005520 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005521 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005522 }
5523
5524 return err;
5525}
5526
5527static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005528brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005529 const struct brcmf_event_msg *e, void *data)
5530{
Arend van Spriel19937322012-11-05 16:22:32 -08005531 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005532 u32 event = e->event_code;
5533 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005534
5535 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07005536 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08005537 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005538 else
Arend van Spriel19937322012-11-05 16:22:32 -08005539 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005540 }
5541
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005542 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005543}
5544
5545static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005546brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005547 const struct brcmf_event_msg *e, void *data)
5548{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005549 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005550 enum nl80211_key_type key_type;
5551
5552 if (flags & BRCMF_EVENT_MSG_GROUP)
5553 key_type = NL80211_KEYTYPE_GROUP;
5554 else
5555 key_type = NL80211_KEYTYPE_PAIRWISE;
5556
Arend van Spriel19937322012-11-05 16:22:32 -08005557 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005558 NULL, GFP_KERNEL);
5559
5560 return 0;
5561}
5562
Arend van Sprield3c0b632013-02-08 15:53:37 +01005563static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
5564 const struct brcmf_event_msg *e, void *data)
5565{
5566 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5567 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
5568 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5569 struct brcmf_cfg80211_vif *vif;
5570
Hante Meuleman37a869e2015-10-29 20:33:17 +01005571 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
Arend van Sprield3c0b632013-02-08 15:53:37 +01005572 ifevent->action, ifevent->flags, ifevent->ifidx,
Hante Meuleman37a869e2015-10-29 20:33:17 +01005573 ifevent->bsscfgidx);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005574
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005575 spin_lock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005576 event->action = ifevent->action;
5577 vif = event->vif;
5578
5579 switch (ifevent->action) {
5580 case BRCMF_E_IF_ADD:
5581 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08005582 if (!cfg->vif_event.vif) {
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005583 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005584 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08005585 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005586
5587 ifp->vif = vif;
5588 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02005589 if (ifp->ndev) {
5590 vif->wdev.netdev = ifp->ndev;
5591 ifp->ndev->ieee80211_ptr = &vif->wdev;
5592 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
5593 }
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005594 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005595 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01005596 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01005597
5598 case BRCMF_E_IF_DEL:
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005599 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005600 /* event may not be upon user request */
5601 if (brcmf_cfg80211_vif_event_armed(cfg))
5602 wake_up(&event->vif_wq);
5603 return 0;
5604
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01005605 case BRCMF_E_IF_CHANGE:
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005606 spin_unlock(&event->vif_event_lock);
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01005607 wake_up(&event->vif_wq);
5608 return 0;
5609
Arend van Sprield3c0b632013-02-08 15:53:37 +01005610 default:
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005611 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005612 break;
5613 }
5614 return -EINVAL;
5615}
5616
Arend van Spriel5b435de2011-10-05 13:19:03 +02005617static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
5618{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005619 conf->frag_threshold = (u32)-1;
5620 conf->rts_threshold = (u32)-1;
5621 conf->retry_short = (u32)-1;
5622 conf->retry_long = (u32)-1;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005623}
5624
Arend van Spriel5c36b992012-11-14 18:46:05 -08005625static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005626{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005627 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
5628 brcmf_notify_connect_status);
5629 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
5630 brcmf_notify_connect_status);
5631 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
5632 brcmf_notify_connect_status);
5633 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
5634 brcmf_notify_connect_status);
5635 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
5636 brcmf_notify_connect_status);
5637 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
5638 brcmf_notify_connect_status);
5639 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
5640 brcmf_notify_roaming_status);
5641 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
5642 brcmf_notify_mic_status);
5643 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
5644 brcmf_notify_connect_status);
5645 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
5646 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005647 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
5648 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005649 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005650 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005651 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
5652 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01005653 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
5654 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01005655 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
5656 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005657 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
5658 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005659}
5660
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005661static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005662{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005663 kfree(cfg->conf);
5664 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005665 kfree(cfg->extra_buf);
5666 cfg->extra_buf = NULL;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005667 kfree(cfg->wowl.nd);
5668 cfg->wowl.nd = NULL;
5669 kfree(cfg->wowl.nd_info);
5670 cfg->wowl.nd_info = NULL;
Hante Meulemand5367332016-02-17 11:26:51 +01005671 kfree(cfg->escan_info.escan_buf);
5672 cfg->escan_info.escan_buf = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005673}
5674
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005675static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005676{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005677 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
5678 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005679 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005680 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
5681 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005682 goto init_priv_mem_out;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005683 cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL);
5684 if (!cfg->wowl.nd)
5685 goto init_priv_mem_out;
5686 cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) +
5687 sizeof(struct cfg80211_wowlan_nd_match *),
5688 GFP_KERNEL);
5689 if (!cfg->wowl.nd_info)
5690 goto init_priv_mem_out;
Hante Meulemand5367332016-02-17 11:26:51 +01005691 cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL);
5692 if (!cfg->escan_info.escan_buf)
5693 goto init_priv_mem_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005694
5695 return 0;
5696
5697init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005698 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005699
5700 return -ENOMEM;
5701}
5702
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005703static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005704{
5705 s32 err = 0;
5706
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005707 cfg->scan_request = NULL;
5708 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01005709 cfg->active_scan = true; /* we do active scan per default */
5710 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005711 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005712 if (err)
5713 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005714 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005715 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005716 brcmf_init_escan(cfg);
5717 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005718 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005719 return err;
5720}
5721
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005722static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005723{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005724 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005725 brcmf_abort_scanning(cfg);
5726 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005727}
5728
Arend van Sprield3c0b632013-02-08 15:53:37 +01005729static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
5730{
5731 init_waitqueue_head(&event->vif_wq);
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09005732 spin_lock_init(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005733}
5734
Hante Meuleman1119e232015-11-25 11:32:42 +01005735static s32 brcmf_dongle_roam(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005736{
Hante Meuleman1119e232015-11-25 11:32:42 +01005737 s32 err;
5738 u32 bcn_timeout;
Arend van Sprielf588bc02011-10-12 20:51:22 +02005739 __le32 roamtrigger[2];
5740 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005741
Hante Meuleman1119e232015-11-25 11:32:42 +01005742 /* Configure beacon timeout value based upon roaming setting */
Hante Meuleman7d34b052016-01-02 09:41:41 +01005743 if (ifp->drvr->settings->roamoff)
Hante Meuleman1119e232015-11-25 11:32:42 +01005744 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF;
5745 else
5746 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON;
5747 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
5748 if (err) {
5749 brcmf_err("bcn_timeout error (%d)\n", err);
5750 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005751 }
5752
Hante Meuleman1119e232015-11-25 11:32:42 +01005753 /* Enable/Disable built-in roaming to allow supplicant to take care of
5754 * roaming.
Arend van Spriel5b435de2011-10-05 13:19:03 +02005755 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005756 brcmf_dbg(INFO, "Internal Roaming = %s\n",
Hante Meuleman7d34b052016-01-02 09:41:41 +01005757 ifp->drvr->settings->roamoff ? "Off" : "On");
5758 err = brcmf_fil_iovar_int_set(ifp, "roam_off",
5759 ifp->drvr->settings->roamoff);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005760 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005761 brcmf_err("roam_off error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005762 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005763 }
5764
Arend van Sprielf588bc02011-10-12 20:51:22 +02005765 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
5766 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005767 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005768 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005769 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005770 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005771 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005772 }
5773
Arend van Sprielf588bc02011-10-12 20:51:22 +02005774 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
5775 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005776 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005777 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005778 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005779 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005780 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005781 }
5782
Hante Meuleman1119e232015-11-25 11:32:42 +01005783roam_setup_done:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005784 return err;
5785}
5786
5787static s32
Hante Meuleman1678ba82015-12-10 13:43:00 +01005788brcmf_dongle_scantime(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005789{
5790 s32 err = 0;
5791
Arend van Sprielac24be62012-10-22 10:36:23 -07005792 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005793 BRCMF_SCAN_CHANNEL_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005794 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005795 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005796 goto dongle_scantime_out;
5797 }
Arend van Sprielac24be62012-10-22 10:36:23 -07005798 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005799 BRCMF_SCAN_UNASSOC_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005800 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005801 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005802 goto dongle_scantime_out;
5803 }
5804
Arend van Sprielac24be62012-10-22 10:36:23 -07005805 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005806 BRCMF_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005807 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005808 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005809 goto dongle_scantime_out;
5810 }
5811
5812dongle_scantime_out:
5813 return err;
5814}
5815
Arend van Sprielb48d8912014-07-12 08:49:41 +02005816static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5817 struct brcmu_chan *ch)
5818{
5819 u32 ht40_flag;
5820
5821 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5822 if (ch->sb == BRCMU_CHAN_SB_U) {
5823 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5824 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5825 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5826 } else {
5827 /* It should be one of
5828 * IEEE80211_CHAN_NO_HT40 or
5829 * IEEE80211_CHAN_NO_HT40PLUS
5830 */
5831 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5832 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5833 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5834 }
5835}
5836
5837static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5838 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005839{
5840 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005841 struct ieee80211_supported_band *band;
5842 struct ieee80211_channel *channel;
5843 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005844 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005845 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005846 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005847 u8 *pbuf;
5848 u32 i, j;
5849 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005850 u32 chaninfo;
Hante Meulemand48200b2013-04-03 12:40:29 +02005851
5852 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5853
5854 if (pbuf == NULL)
5855 return -ENOMEM;
5856
5857 list = (struct brcmf_chanspec_list *)pbuf;
5858
5859 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5860 BRCMF_DCMD_MEDLEN);
5861 if (err) {
5862 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005863 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005864 }
5865
Arend van Sprielb48d8912014-07-12 08:49:41 +02005866 wiphy = cfg_to_wiphy(cfg);
Johannes Berg57fbcce2016-04-12 15:56:15 +02005867 band = wiphy->bands[NL80211_BAND_2GHZ];
Arend van Spriel58de92d2015-04-14 20:10:24 +02005868 if (band)
5869 for (i = 0; i < band->n_channels; i++)
5870 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Johannes Berg57fbcce2016-04-12 15:56:15 +02005871 band = wiphy->bands[NL80211_BAND_5GHZ];
Arend van Spriel58de92d2015-04-14 20:10:24 +02005872 if (band)
5873 for (i = 0; i < band->n_channels; i++)
5874 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Hante Meulemand48200b2013-04-03 12:40:29 +02005875
5876 total = le32_to_cpu(list->count);
5877 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005878 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5879 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005880
Franky Lin83cf17a2013-04-11 13:28:50 +02005881 if (ch.band == BRCMU_CHAN_BAND_2G) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02005882 band = wiphy->bands[NL80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005883 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02005884 band = wiphy->bands[NL80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005885 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005886 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005887 continue;
5888 }
Arend van Spriel58de92d2015-04-14 20:10:24 +02005889 if (!band)
5890 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005891 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005892 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005893 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005894 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005895 ch.bw == BRCMU_CHAN_BW_80)
5896 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005897
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005898 channel = NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005899 for (j = 0; j < band->n_channels; j++) {
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005900 if (band->channels[j].hw_value == ch.control_ch_num) {
5901 channel = &band->channels[j];
Hante Meulemand48200b2013-04-03 12:40:29 +02005902 break;
5903 }
5904 }
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005905 if (!channel) {
5906 /* It seems firmware supports some channel we never
5907 * considered. Something new in IEEE standard?
5908 */
5909 brcmf_err("Ignoring unexpected firmware channel %d\n",
5910 ch.control_ch_num);
5911 continue;
5912 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005913
Rafał Miłecki0f83ff62017-01-17 23:35:50 +01005914 if (channel->orig_flags & IEEE80211_CHAN_DISABLED)
5915 continue;
5916
Arend van Sprielb48d8912014-07-12 08:49:41 +02005917 /* assuming the chanspecs order is HT20,
5918 * HT40 upper, HT40 lower, and VHT80.
5919 */
5920 if (ch.bw == BRCMU_CHAN_BW_80) {
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005921 channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005922 } else if (ch.bw == BRCMU_CHAN_BW_40) {
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005923 brcmf_update_bw40_channel_flag(channel, &ch);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005924 } else {
Arend van Spriel58de92d2015-04-14 20:10:24 +02005925 /* enable the channel and disable other bandwidths
5926 * for now as mentioned order assure they are enabled
5927 * for subsequent chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005928 */
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005929 channel->flags = IEEE80211_CHAN_NO_HT40 |
5930 IEEE80211_CHAN_NO_80MHZ;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005931 ch.bw = BRCMU_CHAN_BW_20;
5932 cfg->d11inf.encchspec(&ch);
5933 chaninfo = ch.chspec;
5934 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5935 &chaninfo);
5936 if (!err) {
5937 if (chaninfo & WL_CHAN_RADAR)
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005938 channel->flags |=
Arend van Sprielb48d8912014-07-12 08:49:41 +02005939 (IEEE80211_CHAN_RADAR |
5940 IEEE80211_CHAN_NO_IR);
5941 if (chaninfo & WL_CHAN_PASSIVE)
Rafał Miłecki77c0d0c2017-01-04 12:09:41 +01005942 channel->flags |=
Arend van Sprielb48d8912014-07-12 08:49:41 +02005943 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005944 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005945 }
5946 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005947
Arend van Sprielb48d8912014-07-12 08:49:41 +02005948fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005949 kfree(pbuf);
5950 return err;
5951}
5952
Arend van Sprielb48d8912014-07-12 08:49:41 +02005953static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005954{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005955 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5956 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005957 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005958 struct brcmf_chanspec_list *list;
5959 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005960 u32 val;
5961 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005962 struct brcmu_chan ch;
5963 u32 num_chan;
5964 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005965
5966 /* verify support for bw_cap command */
5967 val = WLC_BAND_5G;
5968 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5969
5970 if (!err) {
5971 /* only set 2G bandwidth using bw_cap command */
5972 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5973 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5974 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5975 sizeof(band_bwcap));
5976 } else {
5977 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5978 val = WLC_N_BW_40ALL;
5979 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5980 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005981
5982 if (!err) {
5983 /* update channel info in 2G band */
5984 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5985
5986 if (pbuf == NULL)
5987 return -ENOMEM;
5988
5989 ch.band = BRCMU_CHAN_BAND_2G;
5990 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005991 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005992 ch.chnum = 0;
5993 cfg->d11inf.encchspec(&ch);
5994
5995 /* pass encoded chanspec in query */
5996 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5997
5998 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5999 BRCMF_DCMD_MEDLEN);
6000 if (err) {
6001 brcmf_err("get chanspecs error (%d)\n", err);
6002 kfree(pbuf);
6003 return err;
6004 }
6005
Johannes Berg57fbcce2016-04-12 15:56:15 +02006006 band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ];
Arend van Sprielb48d8912014-07-12 08:49:41 +02006007 list = (struct brcmf_chanspec_list *)pbuf;
6008 num_chan = le32_to_cpu(list->count);
6009 for (i = 0; i < num_chan; i++) {
6010 ch.chspec = (u16)le32_to_cpu(list->element[i]);
6011 cfg->d11inf.decchspec(&ch);
6012 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
6013 continue;
6014 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
6015 continue;
6016 for (j = 0; j < band->n_channels; j++) {
Rafał Miłecki4712d882016-05-20 13:38:57 +02006017 if (band->channels[j].hw_value == ch.control_ch_num)
Arend van Sprielb48d8912014-07-12 08:49:41 +02006018 break;
6019 }
6020 if (WARN_ON(j == band->n_channels))
6021 continue;
6022
6023 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
6024 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02006025 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006026 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006027 return err;
6028}
6029
Arend van Spriel2375d972014-01-06 12:40:41 +01006030static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
6031{
6032 u32 band, mimo_bwcap;
6033 int err;
6034
6035 band = WLC_BAND_2G;
6036 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
6037 if (!err) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006038 bw_cap[NL80211_BAND_2GHZ] = band;
Arend van Spriel2375d972014-01-06 12:40:41 +01006039 band = WLC_BAND_5G;
6040 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
6041 if (!err) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006042 bw_cap[NL80211_BAND_5GHZ] = band;
Arend van Spriel2375d972014-01-06 12:40:41 +01006043 return;
6044 }
6045 WARN_ON(1);
6046 return;
6047 }
6048 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
6049 mimo_bwcap = 0;
6050 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
6051 if (err)
6052 /* assume 20MHz if firmware does not give a clue */
6053 mimo_bwcap = WLC_N_BW_20ALL;
6054
6055 switch (mimo_bwcap) {
6056 case WLC_N_BW_40ALL:
Johannes Berg57fbcce2016-04-12 15:56:15 +02006057 bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
Arend van Spriel2375d972014-01-06 12:40:41 +01006058 /* fall-thru */
6059 case WLC_N_BW_20IN2G_40IN5G:
Johannes Berg57fbcce2016-04-12 15:56:15 +02006060 bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
Arend van Spriel2375d972014-01-06 12:40:41 +01006061 /* fall-thru */
6062 case WLC_N_BW_20ALL:
Johannes Berg57fbcce2016-04-12 15:56:15 +02006063 bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
6064 bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
Arend van Spriel2375d972014-01-06 12:40:41 +01006065 break;
6066 default:
6067 brcmf_err("invalid mimo_bw_cap value\n");
6068 }
6069}
Hante Meulemand48200b2013-04-03 12:40:29 +02006070
Arend van Spriel18d6c532014-05-12 10:47:35 +02006071static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
6072 u32 bw_cap[2], u32 nchain)
6073{
6074 band->ht_cap.ht_supported = true;
6075 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
6076 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6077 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6078 }
6079 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6080 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6081 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6082 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
6083 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
6084 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
6085}
6086
6087static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
6088{
6089 u16 mcs_map;
6090 int i;
6091
6092 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
6093 mcs_map = (mcs_map << 2) | supp;
6094
6095 return cpu_to_le16(mcs_map);
6096}
6097
6098static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006099 u32 bw_cap[2], u32 nchain, u32 txstreams,
6100 u32 txbf_bfe_cap, u32 txbf_bfr_cap)
Arend van Spriel18d6c532014-05-12 10:47:35 +02006101{
6102 __le16 mcs_map;
6103
6104 /* not allowed in 2.4G band */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006105 if (band->band == NL80211_BAND_2GHZ)
Arend van Spriel18d6c532014-05-12 10:47:35 +02006106 return;
6107
6108 band->vht_cap.vht_supported = true;
6109 /* 80MHz is mandatory */
6110 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
6111 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
6112 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
6113 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
6114 }
6115 /* all support 256-QAM */
6116 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
6117 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
6118 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006119
6120 /* Beamforming support information */
6121 if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP)
6122 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
6123 if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP)
6124 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
6125 if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP)
6126 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
6127 if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP)
6128 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
6129
6130 if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) {
6131 band->vht_cap.cap |=
6132 (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
6133 band->vht_cap.cap |= ((txstreams - 1) <<
6134 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
6135 band->vht_cap.cap |=
6136 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
6137 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02006138}
6139
Arend van Sprielb48d8912014-07-12 08:49:41 +02006140static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006141{
Arend van Sprielb48d8912014-07-12 08:49:41 +02006142 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07006143 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02006144 u32 nmode = 0;
6145 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006146 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01006147 u32 rxchain;
6148 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006149 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02006150 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01006151 struct ieee80211_supported_band *band;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006152 u32 txstreams = 0;
6153 u32 txbf_bfe_cap = 0;
6154 u32 txbf_bfr_cap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006155
Arend van Spriel18d6c532014-05-12 10:47:35 +02006156 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02006157 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
6158 if (err) {
6159 brcmf_err("nmode error (%d)\n", err);
6160 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01006161 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02006162 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02006163 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
Johannes Berg57fbcce2016-04-12 15:56:15 +02006164 nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ],
6165 bw_cap[NL80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02006166
Daniel Kim4aca7a12014-02-25 20:30:36 +01006167 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
6168 if (err) {
6169 brcmf_err("rxchain error (%d)\n", err);
6170 nchain = 1;
6171 } else {
6172 for (nchain = 0; rxchain; nchain++)
6173 rxchain = rxchain & (rxchain - 1);
6174 }
6175 brcmf_dbg(INFO, "nchain=%d\n", nchain);
6176
Arend van Sprielb48d8912014-07-12 08:49:41 +02006177 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02006178 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006179 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02006180 return err;
6181 }
6182
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006183 if (vhtmode) {
6184 (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams);
6185 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap",
6186 &txbf_bfe_cap);
6187 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap",
6188 &txbf_bfr_cap);
6189 }
6190
Arend van Sprielb48d8912014-07-12 08:49:41 +02006191 wiphy = cfg_to_wiphy(cfg);
6192 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
6193 band = wiphy->bands[i];
6194 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01006195 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02006196
Arend van Spriel18d6c532014-05-12 10:47:35 +02006197 if (nmode)
6198 brcmf_update_ht_cap(band, bw_cap, nchain);
6199 if (vhtmode)
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01006200 brcmf_update_vht_cap(band, bw_cap, nchain, txstreams,
6201 txbf_bfe_cap, txbf_bfr_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02006202 }
6203
Arend van Sprielb48d8912014-07-12 08:49:41 +02006204 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006205}
6206
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006207static const struct ieee80211_txrx_stypes
6208brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
6209 [NL80211_IFTYPE_STATION] = {
6210 .tx = 0xffff,
6211 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
6212 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
6213 },
6214 [NL80211_IFTYPE_P2P_CLIENT] = {
6215 .tx = 0xffff,
6216 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
6217 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
6218 },
6219 [NL80211_IFTYPE_P2P_GO] = {
6220 .tx = 0xffff,
6221 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
6222 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
6223 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
6224 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
6225 BIT(IEEE80211_STYPE_AUTH >> 4) |
6226 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
6227 BIT(IEEE80211_STYPE_ACTION >> 4)
6228 },
6229 [NL80211_IFTYPE_P2P_DEVICE] = {
6230 .tx = 0xffff,
6231 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
6232 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
6233 }
6234};
6235
Arend van Spriel0882dda2015-08-20 22:06:03 +02006236/**
6237 * brcmf_setup_ifmodes() - determine interface modes and combinations.
6238 *
6239 * @wiphy: wiphy object.
6240 * @ifp: interface object needed for feat module api.
6241 *
6242 * The interface modes and combinations are determined dynamically here
6243 * based on firmware functionality.
6244 *
6245 * no p2p and no mbss:
6246 *
6247 * #STA <= 1, #AP <= 1, channels = 1, 2 total
6248 *
6249 * no p2p and mbss:
6250 *
6251 * #STA <= 1, #AP <= 1, channels = 1, 2 total
6252 * #AP <= 4, matching BI, channels = 1, 4 total
6253 *
6254 * p2p, no mchan, and mbss:
6255 *
6256 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
6257 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
6258 * #AP <= 4, matching BI, channels = 1, 4 total
6259 *
6260 * p2p, mchan, and mbss:
6261 *
6262 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
6263 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
6264 * #AP <= 4, matching BI, channels = 1, 4 total
6265 */
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006266static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
6267{
6268 struct ieee80211_iface_combination *combo = NULL;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006269 struct ieee80211_iface_limit *c0_limits = NULL;
6270 struct ieee80211_iface_limit *p2p_limits = NULL;
6271 struct ieee80211_iface_limit *mbss_limits = NULL;
6272 bool mbss, p2p;
6273 int i, c, n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006274
Arend van Spriel0882dda2015-08-20 22:06:03 +02006275 mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
6276 p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
6277
6278 n_combos = 1 + !!p2p + !!mbss;
6279 combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006280 if (!combo)
6281 goto err;
6282
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006283 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
6284 BIT(NL80211_IFTYPE_ADHOC) |
6285 BIT(NL80211_IFTYPE_AP);
6286
Arend van Spriel0882dda2015-08-20 22:06:03 +02006287 c = 0;
6288 i = 0;
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006289 c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
6290 if (!c0_limits)
6291 goto err;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006292 c0_limits[i].max = 1;
6293 c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6294 if (p2p) {
6295 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
6296 combo[c].num_different_channels = 2;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006297 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
6298 BIT(NL80211_IFTYPE_P2P_GO) |
6299 BIT(NL80211_IFTYPE_P2P_DEVICE);
Arend van Spriel0882dda2015-08-20 22:06:03 +02006300 c0_limits[i].max = 1;
6301 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6302 c0_limits[i].max = 1;
6303 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
6304 BIT(NL80211_IFTYPE_P2P_GO);
6305 } else {
6306 c0_limits[i].max = 1;
6307 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006308 }
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006309 combo[c].num_different_channels = 1;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006310 combo[c].max_interfaces = i;
6311 combo[c].n_limits = i;
6312 combo[c].limits = c0_limits;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006313
Arend van Spriel0882dda2015-08-20 22:06:03 +02006314 if (p2p) {
6315 c++;
6316 i = 0;
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006317 p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
6318 if (!p2p_limits)
6319 goto err;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006320 p2p_limits[i].max = 1;
6321 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6322 p2p_limits[i].max = 1;
6323 p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
6324 p2p_limits[i].max = 1;
6325 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
6326 p2p_limits[i].max = 1;
6327 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006328 combo[c].num_different_channels = 1;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006329 combo[c].max_interfaces = i;
6330 combo[c].n_limits = i;
6331 combo[c].limits = p2p_limits;
6332 }
6333
6334 if (mbss) {
6335 c++;
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006336 i = 0;
6337 mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
6338 if (!mbss_limits)
6339 goto err;
6340 mbss_limits[i].max = 4;
6341 mbss_limits[i++].types = BIT(NL80211_IFTYPE_AP);
Arend van Spriel0882dda2015-08-20 22:06:03 +02006342 combo[c].beacon_int_infra_match = true;
6343 combo[c].num_different_channels = 1;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006344 combo[c].max_interfaces = 4;
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006345 combo[c].n_limits = i;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006346 combo[c].limits = mbss_limits;
6347 }
Rafał Miłeckif568ada2016-06-07 21:10:18 +02006348
Arend van Spriel0882dda2015-08-20 22:06:03 +02006349 wiphy->n_iface_combinations = n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006350 wiphy->iface_combinations = combo;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006351 return 0;
6352
6353err:
Arend van Spriel0882dda2015-08-20 22:06:03 +02006354 kfree(c0_limits);
6355 kfree(p2p_limits);
6356 kfree(mbss_limits);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006357 kfree(combo);
6358 return -ENOMEM;
6359}
6360
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006361static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
6362{
6363 /* scheduled scan settings */
6364 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
6365 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
6366 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
Arend Van Sprielc6989fd2016-11-23 10:25:30 +00006367 wiphy->max_sched_scan_plan_interval = BRCMF_PNO_SCHED_SCAN_MAX_PERIOD;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006368 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
6369}
6370
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006371#ifdef CONFIG_PM
Arend Van Spriel0b570102017-01-27 12:27:47 +00006372static const struct wiphy_wowlan_support brcmf_wowlan_support = {
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006373 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01006374 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
6375 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
6376 .pattern_min_len = 1,
6377 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006378};
6379#endif
6380
Hante Meuleman3021ad92016-01-05 11:05:45 +01006381static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp)
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006382{
6383#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006384 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend Van Spriel0b570102017-01-27 12:27:47 +00006385 struct wiphy_wowlan_support *wowl;
6386
6387 wowl = kmemdup(&brcmf_wowlan_support, sizeof(brcmf_wowlan_support),
6388 GFP_KERNEL);
6389 if (!wowl) {
6390 brcmf_err("only support basic wowlan features\n");
6391 wiphy->wowlan = &brcmf_wowlan_support;
6392 return;
6393 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01006394
6395 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006396 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) {
Arend Van Spriel0b570102017-01-27 12:27:47 +00006397 wowl->flags |= WIPHY_WOWLAN_NET_DETECT;
6398 wowl->max_nd_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006399 init_waitqueue_head(&cfg->wowl.nd_data_wait);
Hante Meuleman3021ad92016-01-05 11:05:45 +01006400 }
6401 }
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006402 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) {
Arend Van Spriel0b570102017-01-27 12:27:47 +00006403 wowl->flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY;
6404 wowl->flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE;
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006405 }
6406
Arend Van Spriel0b570102017-01-27 12:27:47 +00006407 wiphy->wowlan = wowl;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006408#endif
6409}
6410
Arend van Sprielb48d8912014-07-12 08:49:41 +02006411static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006412{
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006413 struct brcmf_pub *drvr = ifp->drvr;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006414 const struct ieee80211_iface_combination *combo;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006415 struct ieee80211_supported_band *band;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006416 u16 max_interfaces = 0;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006417 __le32 bandlist[3];
6418 u32 n_bands;
6419 int err, i;
6420
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006421 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
6422 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
Hante Meuleman6c404f32015-12-10 13:43:03 +01006423 wiphy->max_num_pmkids = BRCMF_MAXPMKID;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006424
6425 err = brcmf_setup_ifmodes(wiphy, ifp);
6426 if (err)
6427 return err;
6428
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006429 for (i = 0, combo = wiphy->iface_combinations;
6430 i < wiphy->n_iface_combinations; i++, combo++) {
6431 max_interfaces = max(max_interfaces, combo->max_interfaces);
6432 }
6433
6434 for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
6435 i++) {
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006436 u8 *addr = drvr->addresses[i].addr;
6437
6438 memcpy(addr, drvr->mac, ETH_ALEN);
6439 if (i) {
6440 addr[0] |= BIT(1);
6441 addr[ETH_ALEN - 1] ^= i;
6442 }
6443 }
6444 wiphy->addresses = drvr->addresses;
6445 wiphy->n_addresses = i;
6446
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006447 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
Hante Meuleman240d61a2016-02-17 11:27:10 +01006448 wiphy->cipher_suites = brcmf_cipher_suites;
6449 wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites);
6450 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
6451 wiphy->n_cipher_suites--;
Arend van Spriel7705ba62016-04-17 16:44:58 +02006452 wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) |
6453 BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) |
6454 BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST);
6455
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006456 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
6457 WIPHY_FLAG_OFFCHAN_TX |
Hante Meulemana7b82d42015-12-10 13:43:04 +01006458 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6459 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS))
6460 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman7d34b052016-01-02 09:41:41 +01006461 if (!ifp->drvr->settings->roamoff)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006462 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
6463 wiphy->mgmt_stypes = brcmf_txrx_stypes;
6464 wiphy->max_remain_on_channel_duration = 5000;
Arend van Spriel7a7a87d2015-04-14 20:10:27 +02006465 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
6466 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006467
6468 /* vendor commands/events support */
6469 wiphy->vendor_commands = brcmf_vendor_cmds;
6470 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
6471
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006472 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
Hante Meuleman3021ad92016-01-05 11:05:45 +01006473 brcmf_wiphy_wowl_params(wiphy, ifp);
Arend van Spriel58de92d2015-04-14 20:10:24 +02006474 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
6475 sizeof(bandlist));
6476 if (err) {
6477 brcmf_err("could not obtain band info: err=%d\n", err);
6478 return err;
6479 }
6480 /* first entry in bandlist is number of bands */
6481 n_bands = le32_to_cpu(bandlist[0]);
6482 for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
6483 if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
6484 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
6485 GFP_KERNEL);
6486 if (!band)
6487 return -ENOMEM;
6488
6489 band->channels = kmemdup(&__wl_2ghz_channels,
6490 sizeof(__wl_2ghz_channels),
6491 GFP_KERNEL);
6492 if (!band->channels) {
6493 kfree(band);
6494 return -ENOMEM;
6495 }
6496
6497 band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
Johannes Berg57fbcce2016-04-12 15:56:15 +02006498 wiphy->bands[NL80211_BAND_2GHZ] = band;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006499 }
6500 if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
6501 band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
6502 GFP_KERNEL);
6503 if (!band)
6504 return -ENOMEM;
6505
6506 band->channels = kmemdup(&__wl_5ghz_channels,
6507 sizeof(__wl_5ghz_channels),
6508 GFP_KERNEL);
6509 if (!band->channels) {
6510 kfree(band);
6511 return -ENOMEM;
6512 }
6513
6514 band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
Johannes Berg57fbcce2016-04-12 15:56:15 +02006515 wiphy->bands[NL80211_BAND_5GHZ] = band;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006516 }
6517 }
Rafał Miłecki0f83ff62017-01-17 23:35:50 +01006518
6519 wiphy_read_of_freq_limits(wiphy);
6520
Rafał Miłeckiab990632017-01-07 21:36:05 +01006521 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006522}
6523
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006524static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006525{
6526 struct net_device *ndev;
6527 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01006528 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006529 s32 power_mode;
6530 s32 err = 0;
6531
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006532 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006533 return err;
6534
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006535 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006536 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01006537 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006538
Hante Meuleman40a23292013-01-02 15:22:51 +01006539 /* make sure RF is ready for work */
6540 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
6541
Hante Meuleman1678ba82015-12-10 13:43:00 +01006542 brcmf_dongle_scantime(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006543
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006544 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01006545 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006546 if (err)
6547 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01006548 brcmf_dbg(INFO, "power save set to %s\n",
6549 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02006550
Hante Meuleman1119e232015-11-25 11:32:42 +01006551 err = brcmf_dongle_roam(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006552 if (err)
6553 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07006554 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
6555 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01006556 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006557 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006558
Franky Lin52f22fb2016-02-17 11:26:55 +01006559 brcmf_configure_arp_nd_offload(ifp, true);
Hante Meulemanb3657452013-05-27 21:09:53 +02006560
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006561 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01006562default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02006563
6564 return err;
6565
6566}
6567
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006568static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006569{
Arend van Sprielc1179032012-10-22 13:55:33 -07006570 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006571
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006572 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006573}
6574
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006575static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006576{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006577 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07006578
Arend van Spriel5b435de2011-10-05 13:19:03 +02006579 /*
6580 * While going down, if associated with AP disassociate
6581 * from AP to save power
6582 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01006583 if (check_vif_up(ifp->vif)) {
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01006584 brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006585
6586 /* Make sure WPA_Supplicant receives all the event
6587 generated due to DISASSOC call to the fw to keep
6588 the state fw and WPA_Supplicant state consistent
6589 */
6590 brcmf_delay(500);
6591 }
6592
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006593 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07006594 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006595
Arend van Spriel5b435de2011-10-05 13:19:03 +02006596 return 0;
6597}
6598
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006599s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006600{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006601 struct brcmf_if *ifp = netdev_priv(ndev);
6602 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006603 s32 err = 0;
6604
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006605 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006606 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006607 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006608
6609 return err;
6610}
6611
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006612s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006613{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006614 struct brcmf_if *ifp = netdev_priv(ndev);
6615 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006616 s32 err = 0;
6617
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006618 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006619 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006620 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006621
6622 return err;
6623}
6624
Arend van Spriela7965fb2013-04-11 17:08:37 +02006625enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
6626{
6627 struct wireless_dev *wdev = &ifp->vif->wdev;
6628
6629 return wdev->iftype;
6630}
6631
Hante Meulemanbfe81972014-10-28 14:56:16 +01006632bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
6633 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01006634{
6635 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006636
6637 list_for_each_entry(vif, &cfg->vif_list, list) {
6638 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006639 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006640 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006641 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006642}
Arend van Sprield3c0b632013-02-08 15:53:37 +01006643
6644static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
6645 u8 action)
6646{
6647 u8 evt_action;
6648
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09006649 spin_lock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01006650 evt_action = event->action;
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09006651 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01006652 return evt_action == action;
6653}
6654
6655void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
6656 struct brcmf_cfg80211_vif *vif)
6657{
6658 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6659
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09006660 spin_lock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01006661 event->vif = vif;
6662 event->action = 0;
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09006663 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01006664}
6665
6666bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
6667{
6668 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6669 bool armed;
6670
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09006671 spin_lock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01006672 armed = event->vif != NULL;
mhiramat@kernel.orgb64abcb2016-08-15 18:41:12 +09006673 spin_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01006674
6675 return armed;
6676}
Arend van Spriela9eb0c42016-02-17 11:26:50 +01006677
6678int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
6679 u8 action, ulong timeout)
Arend van Sprield3c0b632013-02-08 15:53:37 +01006680{
6681 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6682
6683 return wait_event_timeout(event->vif_wq,
6684 vif_event_equals(event, action), timeout);
6685}
6686
Hante Meuleman73345fd2016-02-17 11:26:53 +01006687static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2],
6688 struct brcmf_fil_country_le *ccreq)
6689{
Hante Meuleman4d792892016-02-17 11:27:07 +01006690 struct brcmfmac_pd_cc *country_codes;
6691 struct brcmfmac_pd_cc_entry *cc;
Hante Meuleman73345fd2016-02-17 11:26:53 +01006692 s32 found_index;
6693 int i;
6694
6695 country_codes = drvr->settings->country_codes;
6696 if (!country_codes) {
6697 brcmf_dbg(TRACE, "No country codes configured for device\n");
6698 return -EINVAL;
6699 }
6700
6701 if ((alpha2[0] == ccreq->country_abbrev[0]) &&
6702 (alpha2[1] == ccreq->country_abbrev[1])) {
6703 brcmf_dbg(TRACE, "Country code already set\n");
6704 return -EAGAIN;
6705 }
6706
6707 found_index = -1;
6708 for (i = 0; i < country_codes->table_size; i++) {
6709 cc = &country_codes->table[i];
6710 if ((cc->iso3166[0] == '\0') && (found_index == -1))
6711 found_index = i;
6712 if ((cc->iso3166[0] == alpha2[0]) &&
6713 (cc->iso3166[1] == alpha2[1])) {
6714 found_index = i;
6715 break;
6716 }
6717 }
6718 if (found_index == -1) {
6719 brcmf_dbg(TRACE, "No country code match found\n");
6720 return -EINVAL;
6721 }
6722 memset(ccreq, 0, sizeof(*ccreq));
6723 ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev);
6724 memcpy(ccreq->ccode, country_codes->table[found_index].cc,
6725 BRCMF_COUNTRY_BUF_SZ);
6726 ccreq->country_abbrev[0] = alpha2[0];
6727 ccreq->country_abbrev[1] = alpha2[1];
6728 ccreq->country_abbrev[2] = 0;
6729
6730 return 0;
6731}
6732
Arend van Spriel63db1a42014-12-21 12:43:51 +01006733static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
6734 struct regulatory_request *req)
6735{
6736 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6737 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6738 struct brcmf_fil_country_le ccreq;
Hante Meuleman73345fd2016-02-17 11:26:53 +01006739 s32 err;
Arend van Spriel63db1a42014-12-21 12:43:51 +01006740 int i;
6741
Hans de Goede26e537882017-03-08 14:50:16 +01006742 /* The country code gets set to "00" by default at boot, ignore */
6743 if (req->alpha2[0] == '0' && req->alpha2[1] == '0')
6744 return;
6745
Arend van Spriel63db1a42014-12-21 12:43:51 +01006746 /* ignore non-ISO3166 country codes */
6747 for (i = 0; i < sizeof(req->alpha2); i++)
6748 if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
Hante Meuleman73345fd2016-02-17 11:26:53 +01006749 brcmf_err("not a ISO3166 code (0x%02x 0x%02x)\n",
6750 req->alpha2[0], req->alpha2[1]);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006751 return;
6752 }
Hante Meuleman73345fd2016-02-17 11:26:53 +01006753
6754 brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator,
6755 req->alpha2[0], req->alpha2[1]);
6756
6757 err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq));
6758 if (err) {
6759 brcmf_err("Country code iovar returned err = %d\n", err);
6760 return;
6761 }
6762
6763 err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq);
6764 if (err)
6765 return;
6766
6767 err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
6768 if (err) {
6769 brcmf_err("Firmware rejected country setting\n");
Arend van Spriel8afe0ec2015-04-14 20:10:25 +02006770 return;
6771 }
6772 brcmf_setup_wiphybands(wiphy);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006773}
6774
Arend van Sprielb48d8912014-07-12 08:49:41 +02006775static void brcmf_free_wiphy(struct wiphy *wiphy)
6776{
Arend van Spriel0882dda2015-08-20 22:06:03 +02006777 int i;
6778
Arend van Spriel58de92d2015-04-14 20:10:24 +02006779 if (!wiphy)
6780 return;
6781
Arend van Spriel0882dda2015-08-20 22:06:03 +02006782 if (wiphy->iface_combinations) {
6783 for (i = 0; i < wiphy->n_iface_combinations; i++)
6784 kfree(wiphy->iface_combinations[i].limits);
6785 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006786 kfree(wiphy->iface_combinations);
Johannes Berg57fbcce2016-04-12 15:56:15 +02006787 if (wiphy->bands[NL80211_BAND_2GHZ]) {
6788 kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels);
6789 kfree(wiphy->bands[NL80211_BAND_2GHZ]);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006790 }
Johannes Berg57fbcce2016-04-12 15:56:15 +02006791 if (wiphy->bands[NL80211_BAND_5GHZ]) {
6792 kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels);
6793 kfree(wiphy->bands[NL80211_BAND_5GHZ]);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006794 }
Arend Van Spriel0b570102017-01-27 12:27:47 +00006795#if IS_ENABLED(CONFIG_PM)
6796 if (wiphy->wowlan != &brcmf_wowlan_support)
6797 kfree(wiphy->wowlan);
6798#endif
Arend van Sprielb48d8912014-07-12 08:49:41 +02006799 wiphy_free(wiphy);
6800}
6801
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006802struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006803 struct device *busdev,
6804 bool p2pdev_forced)
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006805{
Arend van Spriel46f3b6e2015-08-26 22:14:58 +02006806 struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006807 struct brcmf_cfg80211_info *cfg;
6808 struct wiphy *wiphy;
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006809 struct cfg80211_ops *ops;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006810 struct brcmf_cfg80211_vif *vif;
6811 struct brcmf_if *ifp;
6812 s32 err = 0;
6813 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006814 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006815
6816 if (!ndev) {
6817 brcmf_err("ndev is invalid\n");
6818 return NULL;
6819 }
6820
Muhammad Falak R Wanid464fd82016-05-19 19:29:03 +05306821 ops = kmemdup(&brcmf_cfg80211_ops, sizeof(*ops), GFP_KERNEL);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006822 if (!ops)
6823 return NULL;
6824
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006825 ifp = netdev_priv(ndev);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006826#ifdef CONFIG_PM
6827 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK))
6828 ops->set_rekey_data = brcmf_cfg80211_set_rekey_data;
6829#endif
6830 wiphy = wiphy_new(ops, sizeof(struct brcmf_cfg80211_info));
Arend van Sprielb48d8912014-07-12 08:49:41 +02006831 if (!wiphy) {
6832 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006833 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006834 }
Rafał Miłecki6896f4f2015-05-31 02:52:26 +02006835 memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006836 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006837
6838 cfg = wiphy_priv(wiphy);
6839 cfg->wiphy = wiphy;
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006840 cfg->ops = ops;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006841 cfg->pub = drvr;
6842 init_vif_event(&cfg->vif_event);
6843 INIT_LIST_HEAD(&cfg->vif_list);
6844
Rafał Miłecki26072332016-06-06 23:03:55 +02006845 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006846 if (IS_ERR(vif))
6847 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006848
6849 vif->ifp = ifp;
6850 vif->wdev.netdev = ndev;
6851 ndev->ieee80211_ptr = &vif->wdev;
6852 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
6853
6854 err = wl_init_priv(cfg);
6855 if (err) {
6856 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006857 brcmf_free_vif(vif);
6858 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006859 }
6860 ifp->vif = vif;
6861
Arend van Sprielb48d8912014-07-12 08:49:41 +02006862 /* determine d11 io type before wiphy setup */
6863 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006864 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006865 brcmf_err("Failed to get D11 version (%d)\n", err);
6866 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006867 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006868 cfg->d11inf.io_type = (u8)io_type;
6869 brcmu_d11_attach(&cfg->d11inf);
6870
6871 err = brcmf_setup_wiphy(wiphy, ifp);
6872 if (err < 0)
6873 goto priv_out;
6874
6875 brcmf_dbg(INFO, "Registering custom regulatory\n");
Arend van Spriel63db1a42014-12-21 12:43:51 +01006876 wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006877 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
6878 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
6879
6880 /* firmware defaults to 40MHz disabled in 2G band. We signal
6881 * cfg80211 here that we do and have it decide we can enable
6882 * it. But first check if device does support 2G operation.
6883 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006884 if (wiphy->bands[NL80211_BAND_2GHZ]) {
6885 cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006886 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6887 }
6888 err = wiphy_register(wiphy);
6889 if (err < 0) {
6890 brcmf_err("Could not register wiphy device (%d)\n", err);
6891 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006892 }
6893
Rafał Miłeckiab990632017-01-07 21:36:05 +01006894 err = brcmf_setup_wiphybands(wiphy);
6895 if (err) {
6896 brcmf_err("Setting wiphy bands failed (%d)\n", err);
6897 goto wiphy_unreg_out;
6898 }
6899
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006900 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
6901 * setup 40MHz in 2GHz band and enable OBSS scanning.
6902 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02006903 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
6904 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006905 if (!err)
6906 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
6907 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006908 else
6909 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006910 }
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006911 /* p2p might require that "if-events" get processed by fweh. So
6912 * activate the already registered event handlers now and activate
6913 * the rest when initialization has completed. drvr->config needs to
6914 * be assigned before activating events.
6915 */
6916 drvr->config = cfg;
6917 err = brcmf_fweh_activate_events(ifp);
6918 if (err) {
6919 brcmf_err("FWEH activation failed (%d)\n", err);
6920 goto wiphy_unreg_out;
6921 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006922
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006923 err = brcmf_p2p_attach(cfg, p2pdev_forced);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006924 if (err) {
Arend Van Sprielcb853da2016-12-09 11:34:13 +00006925 brcmf_err("P2P initialisation failed (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006926 goto wiphy_unreg_out;
6927 }
6928 err = brcmf_btcoex_attach(cfg);
6929 if (err) {
6930 brcmf_err("BT-coex initialisation failed (%d)\n", err);
6931 brcmf_p2p_detach(&cfg->p2p);
6932 goto wiphy_unreg_out;
6933 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006934
Hante Meulemana7b82d42015-12-10 13:43:04 +01006935 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) {
6936 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
6937 if (err) {
6938 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
6939 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
6940 } else {
6941 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
6942 brcmf_notify_tdls_peer_event);
6943 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006944 }
6945
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006946 /* (re-) activate FWEH event handling */
6947 err = brcmf_fweh_activate_events(ifp);
6948 if (err) {
6949 brcmf_err("FWEH activation failed (%d)\n", err);
Arend Van Sprielcb853da2016-12-09 11:34:13 +00006950 goto detach;
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006951 }
6952
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006953 /* Fill in some of the advertised nl80211 supported features */
6954 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) {
6955 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6956#ifdef CONFIG_PM
Franky Lin6ea09152016-02-17 11:26:52 +01006957 if (wiphy->wowlan &&
6958 wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT)
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006959 wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6960#endif
6961 }
6962
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006963 return cfg;
6964
Arend Van Sprielcb853da2016-12-09 11:34:13 +00006965detach:
6966 brcmf_btcoex_detach(cfg);
6967 brcmf_p2p_detach(&cfg->p2p);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006968wiphy_unreg_out:
6969 wiphy_unregister(cfg->wiphy);
6970priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006971 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006972 brcmf_free_vif(vif);
Hante Meuleman2b5d3482015-09-18 22:08:04 +02006973 ifp->vif = NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006974wiphy_out:
6975 brcmf_free_wiphy(wiphy);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006976 kfree(ops);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006977 return NULL;
6978}
6979
6980void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
6981{
6982 if (!cfg)
6983 return;
6984
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006985 brcmf_btcoex_detach(cfg);
Arend van Sprielf7a40872015-06-11 00:12:23 +02006986 wiphy_unregister(cfg->wiphy);
Hante Meuleman5c22fb82016-02-17 11:27:03 +01006987 kfree(cfg->ops);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006988 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006989 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006990}