blob: f3a9804988a6c30a80b9e678d65b4d490b1892f9 [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>
29#include "dhd.h"
Arend van Spriel16886732012-12-05 15:26:04 +010030#include "dhd_dbg.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 Spriel5b435de2011-10-05 13:19:03 +020035#include "wl_cfg80211.h"
Arend van Sprielc08437b2014-07-12 08:49:39 +020036#include "feature.h"
Hante Meuleman81f5dcb2012-10-22 10:36:14 -070037#include "fwil.h"
Hante Meuleman8851cce2014-07-30 13:20:02 +020038#include "proto.h"
Franky Lin1bacb042014-06-21 12:11:16 +020039#include "vendor.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020040
Arend van Spriele5806072012-09-19 22:21:08 +020041#define BRCMF_SCAN_IE_LEN_MAX 2048
42#define BRCMF_PNO_VERSION 2
43#define BRCMF_PNO_TIME 30
44#define BRCMF_PNO_REPEAT 4
45#define BRCMF_PNO_FREQ_EXPO_MAX 3
46#define BRCMF_PNO_MAX_PFN_COUNT 16
47#define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
48#define BRCMF_PNO_HIDDEN_BIT 2
49#define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
50#define BRCMF_PNO_SCAN_COMPLETE 1
51#define BRCMF_PNO_SCAN_INCOMPLETE 0
52
Arend van Spriel9f440b72013-02-08 15:53:36 +010053#define BRCMF_IFACE_MAX_CNT 3
Arend van Spriel3eacf862012-10-22 13:55:30 -070054
Hante Meuleman1a873342012-09-27 14:17:54 +020055#define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
56#define WPA_OUI_TYPE 1
57#define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
58#define WME_OUI_TYPE 2
Hante Meuleman89286dc2013-02-08 15:53:46 +010059#define WPS_OUI_TYPE 4
Hante Meuleman1a873342012-09-27 14:17:54 +020060
61#define VS_IE_FIXED_HDR_LEN 6
62#define WPA_IE_VERSION_LEN 2
63#define WPA_IE_MIN_OUI_LEN 4
64#define WPA_IE_SUITE_COUNT_LEN 2
65
66#define WPA_CIPHER_NONE 0 /* None */
67#define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
68#define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
69#define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
70#define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
71
72#define RSN_AKM_NONE 0 /* None (IBSS) */
73#define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
74#define RSN_AKM_PSK 2 /* Pre-shared Key */
75#define RSN_CAP_LEN 2 /* Length of RSN capabilities */
76#define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
77
78#define VNDR_IE_CMD_LEN 4 /* length of the set command
79 * string :"add", "del" (+ NUL)
80 */
81#define VNDR_IE_COUNT_OFFSET 4
82#define VNDR_IE_PKTFLAG_OFFSET 8
83#define VNDR_IE_VSIE_OFFSET 12
84#define VNDR_IE_HDR_SIZE 12
Arend van Spriel9f440b72013-02-08 15:53:36 +010085#define VNDR_IE_PARSE_LIMIT 5
Hante Meuleman1a873342012-09-27 14:17:54 +020086
87#define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
88#define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
Hante Meuleman04012892012-09-27 14:17:49 +020089
Hante Meuleman89286dc2013-02-08 15:53:46 +010090#define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
91#define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
92#define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
93
Arend van Spriel5b435de2011-10-05 13:19:03 +020094#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
95 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
96
Arend van Sprielce81e312012-10-22 13:55:37 -070097static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +020098{
Arend van Sprielc1179032012-10-22 13:55:33 -070099 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100100 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
101 vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200102 return false;
103 }
104 return true;
105}
106
Arend van Spriel5b435de2011-10-05 13:19:03 +0200107#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
108#define RATETAB_ENT(_rateid, _flags) \
109 { \
110 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
111 .hw_value = (_rateid), \
112 .flags = (_flags), \
113 }
114
115static struct ieee80211_rate __wl_rates[] = {
116 RATETAB_ENT(BRCM_RATE_1M, 0),
117 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
118 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
119 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
120 RATETAB_ENT(BRCM_RATE_6M, 0),
121 RATETAB_ENT(BRCM_RATE_9M, 0),
122 RATETAB_ENT(BRCM_RATE_12M, 0),
123 RATETAB_ENT(BRCM_RATE_18M, 0),
124 RATETAB_ENT(BRCM_RATE_24M, 0),
125 RATETAB_ENT(BRCM_RATE_36M, 0),
126 RATETAB_ENT(BRCM_RATE_48M, 0),
127 RATETAB_ENT(BRCM_RATE_54M, 0),
128};
129
130#define wl_a_rates (__wl_rates + 4)
131#define wl_a_rates_size 8
132#define wl_g_rates (__wl_rates + 0)
133#define wl_g_rates_size 12
134
Arend van Sprielb48d8912014-07-12 08:49:41 +0200135/* Band templates duplicated per wiphy. The channel info
136 * is filled in after querying the device.
137 */
138static const struct ieee80211_supported_band __wl_band_2ghz = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200139 .band = IEEE80211_BAND_2GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200140 .bitrates = wl_g_rates,
141 .n_bitrates = wl_g_rates_size,
142};
143
Arend van Sprielb48d8912014-07-12 08:49:41 +0200144static const struct ieee80211_supported_band __wl_band_5ghz_a = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200145 .band = IEEE80211_BAND_5GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200146 .bitrates = wl_a_rates,
147 .n_bitrates = wl_a_rates_size,
148};
149
Hante Meulemand48200b2013-04-03 12:40:29 +0200150/* This is to override regulatory domains defined in cfg80211 module (reg.c)
151 * By default world regulatory domain defined in reg.c puts the flags
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200152 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
153 * With respect to these flags, wpa_supplicant doesn't * start p2p
154 * operations on 5GHz channels. All the changes in world regulatory
Hante Meulemand48200b2013-04-03 12:40:29 +0200155 * domain are to be done here.
156 */
157static const struct ieee80211_regdomain brcmf_regdom = {
158 .n_reg_rules = 4,
159 .alpha2 = "99",
160 .reg_rules = {
161 /* IEEE 802.11b/g, channels 1..11 */
162 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
163 /* If any */
164 /* IEEE 802.11 channel 14 - Only JP enables
165 * this and for 802.11b only
166 */
167 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
168 /* IEEE 802.11a, channel 36..64 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200169 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
Hante Meulemand48200b2013-04-03 12:40:29 +0200170 /* IEEE 802.11a, channel 100..165 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200171 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200172};
173
174static const u32 __wl_cipher_suites[] = {
175 WLAN_CIPHER_SUITE_WEP40,
176 WLAN_CIPHER_SUITE_WEP104,
177 WLAN_CIPHER_SUITE_TKIP,
178 WLAN_CIPHER_SUITE_CCMP,
179 WLAN_CIPHER_SUITE_AES_CMAC,
180};
181
Hante Meuleman1a873342012-09-27 14:17:54 +0200182/* Vendor specific ie. id = 221, oui and type defines exact ie */
183struct brcmf_vs_tlv {
184 u8 id;
185 u8 len;
186 u8 oui[3];
187 u8 oui_type;
188};
189
190struct parsed_vndr_ie_info {
191 u8 *ie_ptr;
192 u32 ie_len; /* total length including id & length field */
193 struct brcmf_vs_tlv vndrie;
194};
195
196struct parsed_vndr_ies {
197 u32 count;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100198 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
Hante Meuleman1a873342012-09-27 14:17:54 +0200199};
200
Hante Meuleman68ca3952014-02-25 20:30:26 +0100201static int brcmf_roamoff;
202module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
203MODULE_PARM_DESC(roamoff, "do not use internal roaming engine");
204
Alwin Beukersef6ac172011-10-12 20:51:26 +0200205/* Quarter dBm units to mW
206 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
207 * Table is offset so the last entry is largest mW value that fits in
208 * a u16.
209 */
210
211#define QDBM_OFFSET 153 /* Offset for first entry */
212#define QDBM_TABLE_LEN 40 /* Table size */
213
214/* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
215 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
216 */
217#define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
218
219/* Largest mW value that will round down to the last table entry,
220 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
221 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
222 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
223 */
224#define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
225
226static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
227/* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
228/* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
229/* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
230/* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
231/* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
232/* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
233};
234
235static u16 brcmf_qdbm_to_mw(u8 qdbm)
236{
237 uint factor = 1;
238 int idx = qdbm - QDBM_OFFSET;
239
240 if (idx >= QDBM_TABLE_LEN)
241 /* clamp to max u16 mW value */
242 return 0xFFFF;
243
244 /* scale the qdBm index up to the range of the table 0-40
245 * where an offset of 40 qdBm equals a factor of 10 mW.
246 */
247 while (idx < 0) {
248 idx += 40;
249 factor *= 10;
250 }
251
252 /* return the mW value scaled down to the correct factor of 10,
253 * adding in factor/2 to get proper rounding.
254 */
255 return (nqdBm_to_mW_map[idx] + factor / 2) / factor;
256}
257
258static u8 brcmf_mw_to_qdbm(u16 mw)
259{
260 u8 qdbm;
261 int offset;
262 uint mw_uint = mw;
263 uint boundary;
264
265 /* handle boundary case */
266 if (mw_uint <= 1)
267 return 0;
268
269 offset = QDBM_OFFSET;
270
271 /* move mw into the range of the table */
272 while (mw_uint < QDBM_TABLE_LOW_BOUND) {
273 mw_uint *= 10;
274 offset -= 40;
275 }
276
277 for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) {
278 boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] -
279 nqdBm_to_mW_map[qdbm]) / 2;
280 if (mw_uint < boundary)
281 break;
282 }
283
284 qdbm += (u8) offset;
285
286 return qdbm;
287}
288
Arend van Spriel5a394eb2014-05-27 12:56:15 +0200289static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
290 struct cfg80211_chan_def *ch)
Arend van Spriel600a8972014-05-12 10:47:39 +0200291{
292 struct brcmu_chan ch_inf;
293 s32 primary_offset;
294
295 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
296 ch->chan->center_freq, ch->center_freq1, ch->width);
297 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
298 primary_offset = ch->center_freq1 - ch->chan->center_freq;
299 switch (ch->width) {
300 case NL80211_CHAN_WIDTH_20:
301 ch_inf.bw = BRCMU_CHAN_BW_20;
302 WARN_ON(primary_offset != 0);
303 break;
304 case NL80211_CHAN_WIDTH_40:
305 ch_inf.bw = BRCMU_CHAN_BW_40;
306 if (primary_offset < 0)
307 ch_inf.sb = BRCMU_CHAN_SB_U;
308 else
309 ch_inf.sb = BRCMU_CHAN_SB_L;
310 break;
311 case NL80211_CHAN_WIDTH_80:
312 ch_inf.bw = BRCMU_CHAN_BW_80;
313 if (primary_offset < 0) {
314 if (primary_offset < -CH_10MHZ_APART)
315 ch_inf.sb = BRCMU_CHAN_SB_UU;
316 else
317 ch_inf.sb = BRCMU_CHAN_SB_UL;
318 } else {
319 if (primary_offset > CH_10MHZ_APART)
320 ch_inf.sb = BRCMU_CHAN_SB_LL;
321 else
322 ch_inf.sb = BRCMU_CHAN_SB_LU;
323 }
324 break;
325 default:
326 WARN_ON_ONCE(1);
327 }
328 switch (ch->chan->band) {
329 case IEEE80211_BAND_2GHZ:
330 ch_inf.band = BRCMU_CHAN_BAND_2G;
331 break;
332 case IEEE80211_BAND_5GHZ:
333 ch_inf.band = BRCMU_CHAN_BAND_5G;
334 break;
335 default:
336 WARN_ON_ONCE(1);
337 }
338 d11inf->encchspec(&ch_inf);
339
340 return ch_inf.chspec;
341}
342
Franky Lin83cf17a2013-04-11 13:28:50 +0200343u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
344 struct ieee80211_channel *ch)
Arend van Spriel6e186162012-10-22 10:36:22 -0700345{
Franky Lin83cf17a2013-04-11 13:28:50 +0200346 struct brcmu_chan ch_inf;
Arend van Spriel6e186162012-10-22 10:36:22 -0700347
Franky Lin83cf17a2013-04-11 13:28:50 +0200348 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
349 ch_inf.bw = BRCMU_CHAN_BW_20;
350 d11inf->encchspec(&ch_inf);
Arend van Spriel6e186162012-10-22 10:36:22 -0700351
Franky Lin83cf17a2013-04-11 13:28:50 +0200352 return ch_inf.chspec;
Arend van Spriel6e186162012-10-22 10:36:22 -0700353}
354
Hante Meuleman89286dc2013-02-08 15:53:46 +0100355/* Traverse a string of 1-byte tag/1-byte length/variable-length value
356 * triples, returning a pointer to the substring whose first element
357 * matches tag
358 */
Johannes Berg4b5800f2014-01-15 14:55:59 +0100359const struct brcmf_tlv *
360brcmf_parse_tlvs(const void *buf, int buflen, uint key)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100361{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100362 const struct brcmf_tlv *elt = buf;
363 int totlen = buflen;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100364
365 /* find tagged parameter */
366 while (totlen >= TLV_HDR_LEN) {
367 int len = elt->len;
368
369 /* validate remaining totlen */
370 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
371 return elt;
372
373 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
374 totlen -= (len + TLV_HDR_LEN);
375 }
376
377 return NULL;
378}
379
380/* Is any of the tlvs the expected entry? If
381 * not update the tlvs buffer pointer/length.
382 */
383static bool
Johannes Berg4b5800f2014-01-15 14:55:59 +0100384brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
385 const u8 *oui, u32 oui_len, u8 type)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100386{
387 /* If the contents match the OUI and the type */
388 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
389 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
390 type == ie[TLV_BODY_OFF + oui_len]) {
391 return true;
392 }
393
394 if (tlvs == NULL)
395 return false;
396 /* point to the next ie */
397 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
398 /* calculate the length of the rest of the buffer */
399 *tlvs_len -= (int)(ie - *tlvs);
400 /* update the pointer to the start of the buffer */
401 *tlvs = ie;
402
403 return false;
404}
405
406static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100407brcmf_find_wpaie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100408{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100409 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100410
411 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
Johannes Berg4b5800f2014-01-15 14:55:59 +0100412 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
Hante Meuleman89286dc2013-02-08 15:53:46 +0100413 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
414 return (struct brcmf_vs_tlv *)ie;
415 }
416 return NULL;
417}
418
419static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100420brcmf_find_wpsie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100421{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100422 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100423
424 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
425 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
426 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
427 return (struct brcmf_vs_tlv *)ie;
428 }
429 return NULL;
430}
431
432
Arend van Spriel5b435de2011-10-05 13:19:03 +0200433static void convert_key_from_CPU(struct brcmf_wsec_key *key,
434 struct brcmf_wsec_key_le *key_le)
435{
436 key_le->index = cpu_to_le32(key->index);
437 key_le->len = cpu_to_le32(key->len);
438 key_le->algo = cpu_to_le32(key->algo);
439 key_le->flags = cpu_to_le32(key->flags);
440 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
441 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
442 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
443 memcpy(key_le->data, key->data, sizeof(key->data));
444 memcpy(key_le->ea, key->ea, sizeof(key->ea));
445}
446
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200447static int
Arend van Spriel2eaba7e2012-10-22 10:36:26 -0700448send_key_to_dongle(struct net_device *ndev, struct brcmf_wsec_key *key)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200449{
450 int err;
451 struct brcmf_wsec_key_le key_le;
452
453 convert_key_from_CPU(key, &key_le);
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200454
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700455 brcmf_netdev_wait_pend8021x(ndev);
456
Arend van Sprielac24be62012-10-22 10:36:23 -0700457 err = brcmf_fil_bsscfg_data_set(netdev_priv(ndev), "wsec_key", &key_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700458 sizeof(key_le));
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200459
Arend van Spriel5b435de2011-10-05 13:19:03 +0200460 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +0100461 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200462 return err;
463}
464
Hante Meulemanb3657452013-05-27 21:09:53 +0200465static s32
466brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable)
467{
468 s32 err;
469 u32 mode;
470
471 if (enable)
472 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
473 else
474 mode = 0;
475
476 /* Try to set and enable ARP offload feature, this may fail, then it */
477 /* is simply not supported and err 0 will be returned */
478 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
479 if (err) {
480 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
481 mode, err);
482 err = 0;
483 } else {
484 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
485 if (err) {
486 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
487 enable, err);
488 err = 0;
489 } else
490 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
491 enable, mode);
492 }
493
494 return err;
495}
496
Hante Meuleman8851cce2014-07-30 13:20:02 +0200497static void
498brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
499{
Arend van Spriel8f2b4592014-09-11 22:51:32 +0200500 struct brcmf_cfg80211_vif *vif;
501 struct brcmf_if *ifp;
502
503 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
504 ifp = vif->ifp;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200505
506 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
507 (wdev->iftype == NL80211_IFTYPE_AP) ||
508 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
509 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
510 ADDR_DIRECT);
511 else
512 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
513 ADDR_INDIRECT);
514}
515
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100516static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
517{
518 enum nl80211_iftype iftype;
519
520 iftype = vif->wdev.iftype;
521 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
522}
523
524static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
525{
526 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
527}
528
Arend van Spriel9f440b72013-02-08 15:53:36 +0100529static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
530 const char *name,
531 enum nl80211_iftype type,
532 u32 *flags,
533 struct vif_params *params)
534{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200535 struct wireless_dev *wdev;
536
Arend van Spriel9f440b72013-02-08 15:53:36 +0100537 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
538 switch (type) {
539 case NL80211_IFTYPE_ADHOC:
540 case NL80211_IFTYPE_STATION:
541 case NL80211_IFTYPE_AP:
542 case NL80211_IFTYPE_AP_VLAN:
543 case NL80211_IFTYPE_WDS:
544 case NL80211_IFTYPE_MONITOR:
545 case NL80211_IFTYPE_MESH_POINT:
546 return ERR_PTR(-EOPNOTSUPP);
547 case NL80211_IFTYPE_P2P_CLIENT:
548 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200549 case NL80211_IFTYPE_P2P_DEVICE:
Hante Meuleman8851cce2014-07-30 13:20:02 +0200550 wdev = brcmf_p2p_add_vif(wiphy, name, type, flags, params);
551 if (!IS_ERR(wdev))
552 brcmf_cfg80211_update_proto_addr_mode(wdev);
553 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100554 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100555 default:
556 return ERR_PTR(-EINVAL);
557 }
558}
559
Daniel Kim5e787f72014-06-21 12:11:18 +0200560static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
561{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200562 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200563 brcmf_set_mpc(ifp, mpc);
564}
565
Arend van Sprielf96aa072013-04-05 10:57:48 +0200566void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100567{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100568 s32 err = 0;
569
570 if (check_vif_up(ifp->vif)) {
571 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
572 if (err) {
573 brcmf_err("fail to set mpc\n");
574 return;
575 }
576 brcmf_dbg(INFO, "MPC : %d\n", mpc);
577 }
578}
579
Arend van Spriela0f472a2013-04-05 10:57:49 +0200580s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
581 struct brcmf_if *ifp, bool aborted,
582 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100583{
584 struct brcmf_scan_params_le params_le;
585 struct cfg80211_scan_request *scan_request;
586 s32 err = 0;
587
588 brcmf_dbg(SCAN, "Enter\n");
589
590 /* clear scan request, because the FW abort can cause a second call */
591 /* to this functon and might cause a double cfg80211_scan_done */
592 scan_request = cfg->scan_request;
593 cfg->scan_request = NULL;
594
595 if (timer_pending(&cfg->escan_timeout))
596 del_timer_sync(&cfg->escan_timeout);
597
598 if (fw_abort) {
599 /* Do a scan abort to stop the driver's scan engine */
600 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
601 memset(&params_le, 0, sizeof(params_le));
602 memset(params_le.bssid, 0xFF, ETH_ALEN);
603 params_le.bss_type = DOT11_BSSTYPE_ANY;
604 params_le.scan_type = 0;
605 params_le.channel_num = cpu_to_le32(1);
606 params_le.nprobes = cpu_to_le32(1);
607 params_le.active_time = cpu_to_le32(-1);
608 params_le.passive_time = cpu_to_le32(-1);
609 params_le.home_time = cpu_to_le32(-1);
610 /* Scan is aborted by setting channel_list[0] to -1 */
611 params_le.channel_list[0] = cpu_to_le16(-1);
612 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200613 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100614 &params_le, sizeof(params_le));
615 if (err)
616 brcmf_err("Scan abort failed\n");
617 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200618
Daniel Kim5e787f72014-06-21 12:11:18 +0200619 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200620
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100621 /*
622 * e-scan can be initiated by scheduled scan
623 * which takes precedence.
624 */
625 if (cfg->sched_escan) {
626 brcmf_dbg(SCAN, "scheduled scan completed\n");
627 cfg->sched_escan = false;
628 if (!aborted)
629 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100630 } else if (scan_request) {
631 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
632 aborted ? "Aborted" : "Done");
633 cfg80211_scan_done(scan_request, aborted);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100634 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100635 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
636 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100637
638 return err;
639}
640
Arend van Spriel9f440b72013-02-08 15:53:36 +0100641static
642int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
643{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100644 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
645 struct net_device *ndev = wdev->netdev;
646
647 /* vif event pending in firmware */
648 if (brcmf_cfg80211_vif_event_armed(cfg))
649 return -EBUSY;
650
651 if (ndev) {
652 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200653 cfg->escan_info.ifp == netdev_priv(ndev))
654 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
655 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100656
657 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
658 }
659
Arend van Spriel9f440b72013-02-08 15:53:36 +0100660 switch (wdev->iftype) {
661 case NL80211_IFTYPE_ADHOC:
662 case NL80211_IFTYPE_STATION:
663 case NL80211_IFTYPE_AP:
664 case NL80211_IFTYPE_AP_VLAN:
665 case NL80211_IFTYPE_WDS:
666 case NL80211_IFTYPE_MONITOR:
667 case NL80211_IFTYPE_MESH_POINT:
668 return -EOPNOTSUPP;
669 case NL80211_IFTYPE_P2P_CLIENT:
670 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200671 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100672 return brcmf_p2p_del_vif(wiphy, wdev);
673 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100674 default:
675 return -EINVAL;
676 }
677 return -EOPNOTSUPP;
678}
679
Arend van Spriel5b435de2011-10-05 13:19:03 +0200680static s32
681brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
682 enum nl80211_iftype type, u32 *flags,
683 struct vif_params *params)
684{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100685 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700686 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100687 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200688 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200689 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200690 s32 err = 0;
691
Arend van Sprield96b8012012-12-05 15:26:02 +0100692 brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200693
694 switch (type) {
695 case NL80211_IFTYPE_MONITOR:
696 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100697 brcmf_err("type (%d) : currently we do not support this type\n",
698 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200699 return -EOPNOTSUPP;
700 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200701 infra = 0;
702 break;
703 case NL80211_IFTYPE_STATION:
Hante Meuleman1bc7c652013-02-08 15:53:56 +0100704 /* Ignore change for p2p IF. Unclear why supplicant does this */
705 if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
706 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) {
707 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
708 /* WAR: It is unexpected to get a change of VIF for P2P
709 * IF, but it happens. The request can not be handled
710 * but returning EPERM causes a crash. Returning 0
711 * without setting ieee80211_ptr->iftype causes trace
712 * (WARN_ON) but it works with wpa_supplicant
713 */
714 return 0;
715 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200716 infra = 1;
717 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200718 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100719 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200720 ap = 1;
721 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200722 default:
723 err = -EINVAL;
724 goto done;
725 }
726
Hante Meuleman1a873342012-09-27 14:17:54 +0200727 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100728 if (type == NL80211_IFTYPE_P2P_GO) {
729 brcmf_dbg(INFO, "IF Type = P2P GO\n");
730 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
731 }
732 if (!err) {
733 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state);
734 brcmf_dbg(INFO, "IF Type = AP\n");
735 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200736 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100737 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200738 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100739 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200740 err = -EAGAIN;
741 goto done;
742 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100743 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100744 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200745 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200746 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200747
Hante Meuleman8851cce2014-07-30 13:20:02 +0200748 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
749
Arend van Spriel5b435de2011-10-05 13:19:03 +0200750done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100751 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200752
753 return err;
754}
755
Franky Lin83cf17a2013-04-11 13:28:50 +0200756static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
757 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200758 struct cfg80211_scan_request *request)
759{
760 u32 n_ssids;
761 u32 n_channels;
762 s32 i;
763 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200764 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200765 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200766 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200767
Arend van Sprielba40d162012-10-22 13:55:38 -0700768 memset(params_le->bssid, 0xFF, ETH_ALEN);
Hante Meulemane756af52012-09-11 21:18:52 +0200769 params_le->bss_type = DOT11_BSSTYPE_ANY;
770 params_le->scan_type = 0;
771 params_le->channel_num = 0;
772 params_le->nprobes = cpu_to_le32(-1);
773 params_le->active_time = cpu_to_le32(-1);
774 params_le->passive_time = cpu_to_le32(-1);
775 params_le->home_time = cpu_to_le32(-1);
776 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
777
778 /* if request is null exit so it will be all channel broadcast scan */
779 if (!request)
780 return;
781
782 n_ssids = request->n_ssids;
783 n_channels = request->n_channels;
784 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100785 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
786 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200787 if (n_channels > 0) {
788 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200789 chanspec = channel_to_chanspec(&cfg->d11inf,
790 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100791 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
792 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200793 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200794 }
795 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100796 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200797 }
798 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100799 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200800 if (n_ssids > 0) {
801 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
802 n_channels * sizeof(u16);
803 offset = roundup(offset, sizeof(u32));
804 ptr = (char *)params_le + offset;
805 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +0200806 memset(&ssid_le, 0, sizeof(ssid_le));
807 ssid_le.SSID_len =
808 cpu_to_le32(request->ssids[i].ssid_len);
809 memcpy(ssid_le.SSID, request->ssids[i].ssid,
810 request->ssids[i].ssid_len);
811 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100812 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +0200813 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100814 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
815 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +0200816 memcpy(ptr, &ssid_le, sizeof(ssid_le));
817 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +0200818 }
819 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100820 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200821 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100822 brcmf_dbg(SCAN, "SSID %s len=%d\n",
823 params_le->ssid_le.SSID,
824 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200825 params_le->ssid_le.SSID_len =
826 cpu_to_le32(request->ssids->ssid_len);
827 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
828 request->ssids->ssid_len);
829 }
830 }
831 /* Adding mask to channel numbers */
832 params_le->channel_num =
833 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
834 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
835}
836
837static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200838brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +0200839 struct cfg80211_scan_request *request, u16 action)
840{
841 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
842 offsetof(struct brcmf_escan_params_le, params_le);
843 struct brcmf_escan_params_le *params;
844 s32 err = 0;
845
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100846 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200847
848 if (request != NULL) {
849 /* Allocate space for populating ssids in struct */
850 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
851
852 /* Allocate space for populating ssids in struct */
853 params_size += sizeof(struct brcmf_ssid) * request->n_ssids;
854 }
855
856 params = kzalloc(params_size, GFP_KERNEL);
857 if (!params) {
858 err = -ENOMEM;
859 goto exit;
860 }
861 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +0200862 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +0200863 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
864 params->action = cpu_to_le16(action);
865 params->sync_id = cpu_to_le16(0x1234);
866
Arend van Spriela0f472a2013-04-05 10:57:49 +0200867 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +0200868 if (err) {
869 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100870 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200871 else
Arend van Spriel57d6e912012-12-05 15:26:00 +0100872 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200873 }
874
875 kfree(params);
876exit:
877 return err;
878}
879
880static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200881brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
Arend van Spriela0f472a2013-04-05 10:57:49 +0200882 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200883{
884 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700885 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +0200886 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100887 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +0200888
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100889 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +0200890 escan->ifp = ifp;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100891 escan->wiphy = wiphy;
892 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700893 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +0200894 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700895 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +0200896 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100897 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200898 return err;
899 }
Daniel Kim5e787f72014-06-21 12:11:18 +0200900 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200901 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +0200902 results->version = 0;
903 results->count = 0;
904 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
905
Arend van Spriela0f472a2013-04-05 10:57:49 +0200906 err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +0200907 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +0200908 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +0200909 return err;
910}
911
912static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200913brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +0200914 struct cfg80211_scan_request *request,
915 struct cfg80211_ssid *this_ssid)
916{
Arend van Spriela0f472a2013-04-05 10:57:49 +0200917 struct brcmf_if *ifp = vif->ifp;
918 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +0200919 struct cfg80211_ssid *ssids;
Hante Meulemanf07998952012-11-05 16:22:13 -0800920 struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700921 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +0200922 bool escan_req;
923 bool spec_scan;
924 s32 err;
925 u32 SSID_len;
926
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100927 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200928
Arend van Sprielc1179032012-10-22 13:55:33 -0700929 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100930 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +0200931 return -EAGAIN;
932 }
Arend van Sprielc1179032012-10-22 13:55:33 -0700933 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100934 brcmf_err("Scanning being aborted: status (%lu)\n",
935 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +0200936 return -EAGAIN;
937 }
Arend van Spriel1687eee2013-04-23 12:53:11 +0200938 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
939 brcmf_err("Scanning suppressed: status (%lu)\n",
940 cfg->scan_status);
941 return -EAGAIN;
942 }
Arend van Sprielc1179032012-10-22 13:55:33 -0700943 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100944 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +0200945 return -EAGAIN;
946 }
947
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100948 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +0200949 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
950 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100951
Hante Meulemane756af52012-09-11 21:18:52 +0200952 /* Arm scan timeout timer */
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200953 mod_timer(&cfg->escan_timeout, jiffies +
Hante Meulemane756af52012-09-11 21:18:52 +0200954 WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
955
956 escan_req = false;
957 if (request) {
958 /* scan bss */
959 ssids = request->ssids;
960 escan_req = true;
961 } else {
962 /* scan in ibss */
963 /* we don't do escan in ibss */
964 ssids = this_ssid;
965 }
966
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200967 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -0700968 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +0200969 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +0100970 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +0200971 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100972 if (err)
973 goto scan_out;
974
Arend van Spriela0f472a2013-04-05 10:57:49 +0200975 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -0800976 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +0200977 goto scan_out;
978 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100979 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
980 ssids->ssid, ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200981 memset(&sr->ssid_le, 0, sizeof(sr->ssid_le));
982 SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len);
983 sr->ssid_le.SSID_len = cpu_to_le32(0);
984 spec_scan = false;
985 if (SSID_len) {
986 memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len);
987 sr->ssid_le.SSID_len = cpu_to_le32(SSID_len);
988 spec_scan = true;
989 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100990 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200991
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700992 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -0700993 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700994 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +0200995 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100996 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200997 goto scan_out;
998 }
Daniel Kim5e787f72014-06-21 12:11:18 +0200999 brcmf_scan_config_mpc(ifp, 0);
Arend van Sprielc1179032012-10-22 13:55:33 -07001000 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Sprielac24be62012-10-22 10:36:23 -07001001 &sr->ssid_le, sizeof(sr->ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001002 if (err) {
1003 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001004 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
1005 sr->ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001006 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001007 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001008
Daniel Kim5e787f72014-06-21 12:11:18 +02001009 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001010 goto scan_out;
1011 }
1012 }
1013
1014 return 0;
1015
1016scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001017 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001018 if (timer_pending(&cfg->escan_timeout))
1019 del_timer_sync(&cfg->escan_timeout);
1020 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001021 return err;
1022}
1023
Arend van Spriel5b435de2011-10-05 13:19:03 +02001024static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001025brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001026{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001027 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001028 s32 err = 0;
1029
Arend van Sprield96b8012012-12-05 15:26:02 +01001030 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001031 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1032 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001033 return -EIO;
1034
Arend van Spriela0f472a2013-04-05 10:57:49 +02001035 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001036
Arend van Spriel5b435de2011-10-05 13:19:03 +02001037 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001038 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001039
Arend van Sprield96b8012012-12-05 15:26:02 +01001040 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001041 return err;
1042}
1043
1044static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1045{
1046 s32 err = 0;
1047
Arend van Sprielac24be62012-10-22 10:36:23 -07001048 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1049 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001050 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001051 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001052
1053 return err;
1054}
1055
1056static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1057{
1058 s32 err = 0;
1059
Arend van Sprielac24be62012-10-22 10:36:23 -07001060 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1061 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001062 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001063 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001064
1065 return err;
1066}
1067
1068static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1069{
1070 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001071 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001072
Arend van Sprielac24be62012-10-22 10:36:23 -07001073 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001074 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001075 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001076 return err;
1077 }
1078 return err;
1079}
1080
1081static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1082{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001083 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1084 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001085 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001086 s32 err = 0;
1087
Arend van Sprield96b8012012-12-05 15:26:02 +01001088 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001089 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001090 return -EIO;
1091
1092 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001093 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1094 cfg->conf->rts_threshold = wiphy->rts_threshold;
1095 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001096 if (!err)
1097 goto done;
1098 }
1099 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001100 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1101 cfg->conf->frag_threshold = wiphy->frag_threshold;
1102 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001103 if (!err)
1104 goto done;
1105 }
1106 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001107 && (cfg->conf->retry_long != wiphy->retry_long)) {
1108 cfg->conf->retry_long = wiphy->retry_long;
1109 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001110 if (!err)
1111 goto done;
1112 }
1113 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001114 && (cfg->conf->retry_short != wiphy->retry_short)) {
1115 cfg->conf->retry_short = wiphy->retry_short;
1116 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001117 if (!err)
1118 goto done;
1119 }
1120
1121done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001122 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001123 return err;
1124}
1125
Arend van Spriel5b435de2011-10-05 13:19:03 +02001126static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1127{
1128 memset(prof, 0, sizeof(*prof));
1129}
1130
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001131static void brcmf_link_down(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001132{
Piotr Haber61730d42013-04-23 12:53:12 +02001133 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001134 s32 err = 0;
1135
Arend van Sprield96b8012012-12-05 15:26:02 +01001136 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001137
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001138 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001139 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001140 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001141 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001142 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001143 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001144 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001145 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001146 cfg80211_disconnected(vif->wdev.netdev, 0, NULL, 0, GFP_KERNEL);
1147
Arend van Spriel5b435de2011-10-05 13:19:03 +02001148 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001149 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001150 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1151 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001152 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001153}
1154
1155static s32
1156brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1157 struct cfg80211_ibss_params *params)
1158{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001159 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001160 struct brcmf_if *ifp = netdev_priv(ndev);
1161 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001162 struct brcmf_join_params join_params;
1163 size_t join_params_size = 0;
1164 s32 err = 0;
1165 s32 wsec = 0;
1166 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001167 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001168
Arend van Sprield96b8012012-12-05 15:26:02 +01001169 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001170 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001171 return -EIO;
1172
1173 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001174 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001175 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001176 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001177 return -EOPNOTSUPP;
1178 }
1179
Arend van Sprielc1179032012-10-22 13:55:33 -07001180 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001181
1182 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001183 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001184 else
Arend van Spriel16886732012-12-05 15:26:04 +01001185 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001186
Johannes Berg683b6d32012-11-08 21:25:48 +01001187 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001188 brcmf_dbg(CONN, "channel: %d\n",
1189 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001190 else
Arend van Spriel16886732012-12-05 15:26:04 +01001191 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001192
1193 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001194 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001195 else
Arend van Spriel16886732012-12-05 15:26:04 +01001196 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001197
1198 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001199 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001200 else
Arend van Spriel16886732012-12-05 15:26:04 +01001201 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001202
1203 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001204 brcmf_dbg(CONN, "beacon interval: %d\n",
1205 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001206 else
Arend van Spriel16886732012-12-05 15:26:04 +01001207 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001208
1209 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001210 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001211 else
Arend van Spriel16886732012-12-05 15:26:04 +01001212 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001213
1214 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001215 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001216 else
Arend van Spriel16886732012-12-05 15:26:04 +01001217 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001218
1219 /* Configure Privacy for starter */
1220 if (params->privacy)
1221 wsec |= WEP_ENABLED;
1222
Arend van Sprielc1179032012-10-22 13:55:33 -07001223 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001224 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001225 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001226 goto done;
1227 }
1228
1229 /* Configure Beacon Interval for starter */
1230 if (params->beacon_interval)
1231 bcnprd = params->beacon_interval;
1232 else
1233 bcnprd = 100;
1234
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001235 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001236 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001237 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001238 goto done;
1239 }
1240
1241 /* Configure required join parameter */
1242 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1243
1244 /* SSID */
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001245 profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32);
1246 memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len);
1247 memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len);
1248 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001249 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001250
1251 /* BSSID */
1252 if (params->bssid) {
1253 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
1254 join_params_size = sizeof(join_params.ssid_le) +
1255 BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001256 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001257 } else {
Arend van Sprielba40d162012-10-22 13:55:38 -07001258 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001259 memset(profile->bssid, 0, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001260 }
1261
Arend van Spriel5b435de2011-10-05 13:19:03 +02001262 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001263 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001264 u32 target_channel;
1265
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001266 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001267 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001268 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001269 if (params->channel_fixed) {
1270 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001271 chanspec = chandef_to_chanspec(&cfg->d11inf,
1272 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001273 join_params.params_le.chanspec_list[0] =
1274 cpu_to_le16(chanspec);
1275 join_params.params_le.chanspec_num = cpu_to_le32(1);
1276 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001277 }
1278
1279 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001280 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001281 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001282 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001283 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001284 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001285 goto done;
1286 }
1287 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001288 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001289
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001290 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001291
1292
Arend van Sprielc1179032012-10-22 13:55:33 -07001293 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001294 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001295 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001296 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001297 goto done;
1298 }
1299
1300done:
1301 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001302 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001303 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001304 return err;
1305}
1306
1307static s32
1308brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1309{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001310 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001311
Arend van Sprield96b8012012-12-05 15:26:02 +01001312 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001313 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001314 return -EIO;
1315
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001316 brcmf_link_down(ifp->vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001317
Arend van Sprield96b8012012-12-05 15:26:02 +01001318 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001319
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001320 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001321}
1322
1323static s32 brcmf_set_wpa_version(struct net_device *ndev,
1324 struct cfg80211_connect_params *sme)
1325{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001326 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001327 struct brcmf_cfg80211_security *sec;
1328 s32 val = 0;
1329 s32 err = 0;
1330
1331 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1332 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1333 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1334 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1335 else
1336 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001337 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001338 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001339 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001340 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001341 return err;
1342 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001343 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001344 sec->wpa_versions = sme->crypto.wpa_versions;
1345 return err;
1346}
1347
1348static s32 brcmf_set_auth_type(struct net_device *ndev,
1349 struct cfg80211_connect_params *sme)
1350{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001351 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001352 struct brcmf_cfg80211_security *sec;
1353 s32 val = 0;
1354 s32 err = 0;
1355
1356 switch (sme->auth_type) {
1357 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1358 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001359 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001360 break;
1361 case NL80211_AUTHTYPE_SHARED_KEY:
1362 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001363 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001364 break;
1365 case NL80211_AUTHTYPE_AUTOMATIC:
1366 val = 2;
Arend van Spriel16886732012-12-05 15:26:04 +01001367 brcmf_dbg(CONN, "automatic\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001368 break;
1369 case NL80211_AUTHTYPE_NETWORK_EAP:
Arend van Spriel16886732012-12-05 15:26:04 +01001370 brcmf_dbg(CONN, "network eap\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001371 default:
1372 val = 2;
Arend van Spriel57d6e912012-12-05 15:26:00 +01001373 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001374 break;
1375 }
1376
Hante Meuleman89286dc2013-02-08 15:53:46 +01001377 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001378 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001379 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001380 return err;
1381 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001382 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001383 sec->auth_type = sme->auth_type;
1384 return err;
1385}
1386
1387static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001388brcmf_set_wsec_mode(struct net_device *ndev,
1389 struct cfg80211_connect_params *sme, bool mfp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001390{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001391 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001392 struct brcmf_cfg80211_security *sec;
1393 s32 pval = 0;
1394 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001395 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001396 s32 err = 0;
1397
1398 if (sme->crypto.n_ciphers_pairwise) {
1399 switch (sme->crypto.ciphers_pairwise[0]) {
1400 case WLAN_CIPHER_SUITE_WEP40:
1401 case WLAN_CIPHER_SUITE_WEP104:
1402 pval = WEP_ENABLED;
1403 break;
1404 case WLAN_CIPHER_SUITE_TKIP:
1405 pval = TKIP_ENABLED;
1406 break;
1407 case WLAN_CIPHER_SUITE_CCMP:
1408 pval = AES_ENABLED;
1409 break;
1410 case WLAN_CIPHER_SUITE_AES_CMAC:
1411 pval = AES_ENABLED;
1412 break;
1413 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001414 brcmf_err("invalid cipher pairwise (%d)\n",
1415 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001416 return -EINVAL;
1417 }
1418 }
1419 if (sme->crypto.cipher_group) {
1420 switch (sme->crypto.cipher_group) {
1421 case WLAN_CIPHER_SUITE_WEP40:
1422 case WLAN_CIPHER_SUITE_WEP104:
1423 gval = WEP_ENABLED;
1424 break;
1425 case WLAN_CIPHER_SUITE_TKIP:
1426 gval = TKIP_ENABLED;
1427 break;
1428 case WLAN_CIPHER_SUITE_CCMP:
1429 gval = AES_ENABLED;
1430 break;
1431 case WLAN_CIPHER_SUITE_AES_CMAC:
1432 gval = AES_ENABLED;
1433 break;
1434 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001435 brcmf_err("invalid cipher group (%d)\n",
1436 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001437 return -EINVAL;
1438 }
1439 }
1440
Arend van Spriel16886732012-12-05 15:26:04 +01001441 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001442 /* In case of privacy, but no security and WPS then simulate */
1443 /* setting AES. WPS-2.0 allows no security */
1444 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1445 sme->privacy)
1446 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001447
1448 if (mfp)
1449 wsec = pval | gval | MFP_CAPABLE;
1450 else
1451 wsec = pval | gval;
1452 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001453 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001454 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001455 return err;
1456 }
1457
Arend van Spriel06bb1232012-09-27 14:17:56 +02001458 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001459 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1460 sec->cipher_group = sme->crypto.cipher_group;
1461
1462 return err;
1463}
1464
1465static s32
1466brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1467{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001468 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001469 struct brcmf_cfg80211_security *sec;
1470 s32 val = 0;
1471 s32 err = 0;
1472
1473 if (sme->crypto.n_akm_suites) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01001474 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
1475 "wpa_auth", &val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001476 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001477 brcmf_err("could not get wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001478 return err;
1479 }
1480 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1481 switch (sme->crypto.akm_suites[0]) {
1482 case WLAN_AKM_SUITE_8021X:
1483 val = WPA_AUTH_UNSPECIFIED;
1484 break;
1485 case WLAN_AKM_SUITE_PSK:
1486 val = WPA_AUTH_PSK;
1487 break;
1488 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001489 brcmf_err("invalid cipher group (%d)\n",
1490 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001491 return -EINVAL;
1492 }
1493 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1494 switch (sme->crypto.akm_suites[0]) {
1495 case WLAN_AKM_SUITE_8021X:
1496 val = WPA2_AUTH_UNSPECIFIED;
1497 break;
1498 case WLAN_AKM_SUITE_PSK:
1499 val = WPA2_AUTH_PSK;
1500 break;
1501 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001502 brcmf_err("invalid cipher group (%d)\n",
1503 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001504 return -EINVAL;
1505 }
1506 }
1507
Arend van Spriel16886732012-12-05 15:26:04 +01001508 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001509 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
1510 "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001511 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001512 brcmf_err("could not set wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001513 return err;
1514 }
1515 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001516 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001517 sec->wpa_auth = sme->crypto.akm_suites[0];
1518
1519 return err;
1520}
1521
1522static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001523brcmf_set_sharedkey(struct net_device *ndev,
1524 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001525{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001526 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001527 struct brcmf_cfg80211_security *sec;
1528 struct brcmf_wsec_key key;
1529 s32 val;
1530 s32 err = 0;
1531
Arend van Spriel16886732012-12-05 15:26:04 +01001532 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001533
Roland Vossena718e2f2011-10-12 20:51:24 +02001534 if (sme->key_len == 0)
1535 return 0;
1536
Arend van Spriel06bb1232012-09-27 14:17:56 +02001537 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001538 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1539 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001540
1541 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1542 return 0;
1543
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001544 if (!(sec->cipher_pairwise &
1545 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1546 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001547
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001548 memset(&key, 0, sizeof(key));
1549 key.len = (u32) sme->key_len;
1550 key.index = (u32) sme->key_idx;
1551 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001552 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001553 return -EINVAL;
1554 }
1555 memcpy(key.data, sme->key, key.len);
1556 key.flags = BRCMF_PRIMARY_KEY;
1557 switch (sec->cipher_pairwise) {
1558 case WLAN_CIPHER_SUITE_WEP40:
1559 key.algo = CRYPTO_ALGO_WEP1;
1560 break;
1561 case WLAN_CIPHER_SUITE_WEP104:
1562 key.algo = CRYPTO_ALGO_WEP128;
1563 break;
1564 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001565 brcmf_err("Invalid algorithm (%d)\n",
1566 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001567 return -EINVAL;
1568 }
1569 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001570 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1571 key.len, key.index, key.algo);
1572 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07001573 err = send_key_to_dongle(ndev, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001574 if (err)
1575 return err;
1576
1577 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001578 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001579 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001580 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001581 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001582 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001583 }
1584 return err;
1585}
1586
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001587static
1588enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1589 enum nl80211_auth_type type)
1590{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001591 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1592 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1593 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1594 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001595 }
1596 return type;
1597}
1598
Arend van Spriel5b435de2011-10-05 13:19:03 +02001599static s32
1600brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001601 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001602{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001603 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001604 struct brcmf_if *ifp = netdev_priv(ndev);
1605 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001606 struct ieee80211_channel *chan = sme->channel;
1607 struct brcmf_join_params join_params;
1608 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001609 const struct brcmf_tlv *rsn_ie;
1610 const struct brcmf_vs_tlv *wpa_ie;
1611 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001612 u32 ie_len;
1613 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001614 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001615 s32 err = 0;
1616
Arend van Sprield96b8012012-12-05 15:26:02 +01001617 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001618 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001619 return -EIO;
1620
1621 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001622 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001623 return -EOPNOTSUPP;
1624 }
1625
Hante Meuleman89286dc2013-02-08 15:53:46 +01001626 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1627 /* A normal (non P2P) connection request setup. */
1628 ie = NULL;
1629 ie_len = 0;
1630 /* find the WPA_IE */
1631 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1632 if (wpa_ie) {
1633 ie = wpa_ie;
1634 ie_len = wpa_ie->len + TLV_HDR_LEN;
1635 } else {
1636 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001637 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1638 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001639 WLAN_EID_RSN);
1640 if (rsn_ie) {
1641 ie = rsn_ie;
1642 ie_len = rsn_ie->len + TLV_HDR_LEN;
1643 }
1644 }
1645 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1646 }
1647
1648 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1649 sme->ie, sme->ie_len);
1650 if (err)
1651 brcmf_err("Set Assoc REQ IE Failed\n");
1652 else
1653 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1654
Arend van Sprielc1179032012-10-22 13:55:33 -07001655 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001656
1657 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001658 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001659 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001660 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001661 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1662 cfg->channel, chan->center_freq, chanspec);
1663 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001664 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001665 chanspec = 0;
1666 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001667
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001668 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001669
1670 err = brcmf_set_wpa_version(ndev, sme);
1671 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001672 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001673 goto done;
1674 }
1675
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001676 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001677 err = brcmf_set_auth_type(ndev, sme);
1678 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001679 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001680 goto done;
1681 }
1682
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001683 err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001684 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001685 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001686 goto done;
1687 }
1688
1689 err = brcmf_set_key_mgmt(ndev, sme);
1690 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001691 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001692 goto done;
1693 }
1694
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001695 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001696 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001697 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001698 goto done;
1699 }
1700
Hante Meuleman89286dc2013-02-08 15:53:46 +01001701 profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID),
1702 (u32)sme->ssid_len);
1703 memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len);
1704 if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1705 profile->ssid.SSID[profile->ssid.SSID_len] = 0;
1706 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID,
1707 profile->ssid.SSID_len);
1708 }
1709
1710 /* Join with specific BSSID and cached SSID
1711 * If SSID is zero join based on BSSID only
1712 */
1713 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1714 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1715 if (cfg->channel)
1716 join_params_size += sizeof(u16);
1717 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1718 if (ext_join_params == NULL) {
1719 err = -ENOMEM;
1720 goto done;
1721 }
1722 ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
1723 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid,
1724 profile->ssid.SSID_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001725
Hante Meuleman89286dc2013-02-08 15:53:46 +01001726 /* Set up join scan parameters */
1727 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001728 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1729
1730 if (sme->bssid)
1731 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1732 else
1733 memset(&ext_join_params->assoc_le.bssid, 0xFF, ETH_ALEN);
1734
1735 if (cfg->channel) {
1736 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
1737
1738 ext_join_params->assoc_le.chanspec_list[0] =
1739 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001740 /* Increase dwell time to receive probe response or detect
1741 * beacon from target AP at a noisy air only during connect
1742 * command.
1743 */
1744 ext_join_params->scan_le.active_time =
1745 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
1746 ext_join_params->scan_le.passive_time =
1747 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
1748 /* To sync with presence period of VSDB GO send probe request
1749 * more frequently. Probe request will be stopped when it gets
1750 * probe response from target AP/GO.
1751 */
1752 ext_join_params->scan_le.nprobes =
1753 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
1754 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
1755 } else {
1756 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
1757 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
1758 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001759 }
1760
1761 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
1762 join_params_size);
1763 kfree(ext_join_params);
1764 if (!err)
1765 /* This is it. join command worked, we are done */
1766 goto done;
1767
1768 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02001769 memset(&join_params, 0, sizeof(join_params));
1770 join_params_size = sizeof(join_params.ssid_le);
1771
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001772 memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001773 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001774
Hante Meuleman89286dc2013-02-08 15:53:46 +01001775 if (sme->bssid)
1776 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
1777 else
1778 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001779
Hante Meuleman17012612013-02-06 18:40:44 +01001780 if (cfg->channel) {
1781 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
1782 join_params.params_le.chanspec_num = cpu_to_le32(1);
1783 join_params_size += sizeof(join_params.params_le);
1784 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001785 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001786 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001787 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01001788 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001789
1790done:
1791 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001792 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001793 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001794 return err;
1795}
1796
1797static s32
1798brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1799 u16 reason_code)
1800{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001801 struct brcmf_if *ifp = netdev_priv(ndev);
1802 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001803 struct brcmf_scb_val_le scbval;
1804 s32 err = 0;
1805
Arend van Sprield96b8012012-12-05 15:26:02 +01001806 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
Arend van Sprielce81e312012-10-22 13:55:37 -07001807 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001808 return -EIO;
1809
Arend van Sprielc1179032012-10-22 13:55:33 -07001810 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001811 cfg80211_disconnected(ndev, reason_code, NULL, 0, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001812
Arend van Spriel06bb1232012-09-27 14:17:56 +02001813 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001814 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07001815 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07001816 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001817 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001818 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001819
Arend van Sprield96b8012012-12-05 15:26:02 +01001820 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001821 return err;
1822}
1823
1824static s32
Johannes Bergc8442112012-10-24 10:17:18 +02001825brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001826 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001827{
1828
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001829 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001830 struct net_device *ndev = cfg_to_ndev(cfg);
1831 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001832 u16 txpwrmw;
1833 s32 err = 0;
1834 s32 disable = 0;
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001835 s32 dbm = MBM_TO_DBM(mbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001836
Arend van Sprield96b8012012-12-05 15:26:02 +01001837 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001838 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001839 return -EIO;
1840
1841 switch (type) {
1842 case NL80211_TX_POWER_AUTOMATIC:
1843 break;
1844 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02001845 case NL80211_TX_POWER_FIXED:
1846 if (dbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001847 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001848 err = -EINVAL;
1849 goto done;
1850 }
1851 break;
1852 }
1853 /* Make sure radio is off or on as far as software is concerned */
1854 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07001855 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001856 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001857 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001858
1859 if (dbm > 0xffff)
1860 txpwrmw = 0xffff;
1861 else
1862 txpwrmw = (u16) dbm;
Arend van Sprielac24be62012-10-22 10:36:23 -07001863 err = brcmf_fil_iovar_int_set(ifp, "qtxpower",
1864 (s32)brcmf_mw_to_qdbm(txpwrmw));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001865 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001866 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001867 cfg->conf->tx_power = dbm;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001868
1869done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001870 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001871 return err;
1872}
1873
Johannes Bergc8442112012-10-24 10:17:18 +02001874static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy,
1875 struct wireless_dev *wdev,
1876 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001877{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001878 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001879 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001880 s32 txpwrdbm;
1881 u8 result;
1882 s32 err = 0;
1883
Arend van Sprield96b8012012-12-05 15:26:02 +01001884 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001885 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001886 return -EIO;
1887
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001888 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &txpwrdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001889 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001890 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001891 goto done;
1892 }
1893
1894 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
Alwin Beukersef6ac172011-10-12 20:51:26 +02001895 *dbm = (s32) brcmf_qdbm_to_mw(result);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001896
1897done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001898 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001899 return err;
1900}
1901
1902static s32
1903brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
1904 u8 key_idx, bool unicast, bool multicast)
1905{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001906 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001907 u32 index;
1908 u32 wsec;
1909 s32 err = 0;
1910
Arend van Sprield96b8012012-12-05 15:26:02 +01001911 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01001912 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07001913 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001914 return -EIO;
1915
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001916 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001917 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001918 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001919 goto done;
1920 }
1921
1922 if (wsec & WEP_ENABLED) {
1923 /* Just select a new current key */
1924 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001925 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001926 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001927 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001928 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001929 }
1930done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001931 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001932 return err;
1933}
1934
1935static s32
1936brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
1937 u8 key_idx, const u8 *mac_addr, struct key_params *params)
1938{
Hante Meuleman992f6062013-04-02 21:06:17 +02001939 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001940 struct brcmf_wsec_key key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001941 s32 err = 0;
Hante Meuleman992f6062013-04-02 21:06:17 +02001942 u8 keybuf[8];
Arend van Spriel5b435de2011-10-05 13:19:03 +02001943
1944 memset(&key, 0, sizeof(key));
1945 key.index = (u32) key_idx;
1946 /* Instead of bcast for ea address for default wep keys,
1947 driver needs it to be Null */
1948 if (!is_multicast_ether_addr(mac_addr))
1949 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
1950 key.len = (u32) params->key_len;
1951 /* check for key index change */
1952 if (key.len == 0) {
1953 /* key delete */
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07001954 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001955 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001956 brcmf_err("key delete error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001957 } else {
1958 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001959 brcmf_err("Invalid key length (%d)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001960 return -EINVAL;
1961 }
1962
Arend van Spriel16886732012-12-05 15:26:04 +01001963 brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001964 memcpy(key.data, params->key, key.len);
1965
Arend van Spriel967fe2c2014-03-15 17:18:21 +01001966 if (!brcmf_is_apmode(ifp->vif) &&
Hante Meuleman992f6062013-04-02 21:06:17 +02001967 (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
1968 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001969 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1970 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1971 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1972 }
1973
1974 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1975 if (params->seq && params->seq_len == 6) {
1976 /* rx iv */
1977 u8 *ivptr;
1978 ivptr = (u8 *) params->seq;
1979 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
1980 (ivptr[3] << 8) | ivptr[2];
1981 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
1982 key.iv_initialized = true;
1983 }
1984
1985 switch (params->cipher) {
1986 case WLAN_CIPHER_SUITE_WEP40:
1987 key.algo = CRYPTO_ALGO_WEP1;
Arend van Spriel16886732012-12-05 15:26:04 +01001988 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001989 break;
1990 case WLAN_CIPHER_SUITE_WEP104:
1991 key.algo = CRYPTO_ALGO_WEP128;
Arend van Spriel16886732012-12-05 15:26:04 +01001992 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001993 break;
1994 case WLAN_CIPHER_SUITE_TKIP:
1995 key.algo = CRYPTO_ALGO_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01001996 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001997 break;
1998 case WLAN_CIPHER_SUITE_AES_CMAC:
1999 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002000 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002001 break;
2002 case WLAN_CIPHER_SUITE_CCMP:
2003 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002004 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002005 break;
2006 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002007 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002008 return -EINVAL;
2009 }
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002010 err = send_key_to_dongle(ndev, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002011 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002012 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002013 }
2014 return err;
2015}
2016
2017static s32
2018brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2019 u8 key_idx, bool pairwise, const u8 *mac_addr,
2020 struct key_params *params)
2021{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002022 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002023 struct brcmf_wsec_key key;
2024 s32 val;
2025 s32 wsec;
2026 s32 err = 0;
2027 u8 keybuf[8];
2028
Arend van Sprield96b8012012-12-05 15:26:02 +01002029 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002030 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002031 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002032 return -EIO;
2033
Daniel Kim787eb032014-01-29 15:32:23 +01002034 if (mac_addr &&
2035 (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2036 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01002037 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002038 return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
2039 }
2040 memset(&key, 0, sizeof(key));
2041
2042 key.len = (u32) params->key_len;
2043 key.index = (u32) key_idx;
2044
2045 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002046 brcmf_err("Too long key length (%u)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002047 err = -EINVAL;
2048 goto done;
2049 }
2050 memcpy(key.data, params->key, key.len);
2051
2052 key.flags = BRCMF_PRIMARY_KEY;
2053 switch (params->cipher) {
2054 case WLAN_CIPHER_SUITE_WEP40:
2055 key.algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002056 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002057 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002058 break;
2059 case WLAN_CIPHER_SUITE_WEP104:
2060 key.algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002061 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002062 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002063 break;
2064 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002065 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002066 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02002067 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2068 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2069 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2070 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002071 key.algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002072 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002073 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002074 break;
2075 case WLAN_CIPHER_SUITE_AES_CMAC:
2076 key.algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002077 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002078 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002079 break;
2080 case WLAN_CIPHER_SUITE_CCMP:
2081 key.algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002082 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002083 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002084 break;
2085 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002086 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002087 err = -EINVAL;
2088 goto done;
2089 }
2090
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002091 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002092 if (err)
2093 goto done;
2094
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002095 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002096 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002097 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002098 goto done;
2099 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002100 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002101 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002102 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002103 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002104 goto done;
2105 }
2106
Arend van Spriel5b435de2011-10-05 13:19:03 +02002107done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002108 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002109 return err;
2110}
2111
2112static s32
2113brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2114 u8 key_idx, bool pairwise, const u8 *mac_addr)
2115{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002116 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002117 struct brcmf_wsec_key key;
2118 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002119
Arend van Sprield96b8012012-12-05 15:26:02 +01002120 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002121 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002122 return -EIO;
2123
Hante Meuleman256c3742012-11-05 16:22:28 -08002124 if (key_idx >= DOT11_MAX_DEFAULT_KEYS) {
2125 /* we ignore this key index in this case */
Arend van Spriel57d6e912012-12-05 15:26:00 +01002126 brcmf_err("invalid key index (%d)\n", key_idx);
Hante Meuleman256c3742012-11-05 16:22:28 -08002127 return -EINVAL;
2128 }
2129
Arend van Spriel5b435de2011-10-05 13:19:03 +02002130 memset(&key, 0, sizeof(key));
2131
2132 key.index = (u32) key_idx;
2133 key.flags = BRCMF_PRIMARY_KEY;
2134 key.algo = CRYPTO_ALGO_OFF;
2135
Arend van Spriel16886732012-12-05 15:26:04 +01002136 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002137
2138 /* Set the new key/index */
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002139 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002140
Arend van Sprield96b8012012-12-05 15:26:02 +01002141 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002142 return err;
2143}
2144
2145static s32
2146brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2147 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
2148 void (*callback) (void *cookie, struct key_params * params))
2149{
2150 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002151 struct brcmf_if *ifp = netdev_priv(ndev);
2152 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002153 struct brcmf_cfg80211_security *sec;
2154 s32 wsec;
2155 s32 err = 0;
2156
Arend van Sprield96b8012012-12-05 15:26:02 +01002157 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002158 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002159 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002160 return -EIO;
2161
2162 memset(&params, 0, sizeof(params));
2163
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002164 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002165 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002166 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002167 /* Ignore this error, may happen during DISASSOC */
2168 err = -EAGAIN;
2169 goto done;
2170 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002171 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002172 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002173 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2174 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002175 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002176 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2177 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002178 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002179 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002180 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002181 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002182 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002183 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002184 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002185 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002186 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002187 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002188 err = -EINVAL;
2189 goto done;
2190 }
2191 callback(cookie, &params);
2192
2193done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002194 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002195 return err;
2196}
2197
2198static s32
2199brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2200 struct net_device *ndev, u8 key_idx)
2201{
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002202 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002203
2204 return -EOPNOTSUPP;
2205}
2206
2207static s32
2208brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002209 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002210{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002211 struct brcmf_if *ifp = netdev_priv(ndev);
2212 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002213 struct brcmf_scb_val_le scb_val;
2214 int rssi;
2215 s32 rate;
2216 s32 err = 0;
Arend van Spriel06bb1232012-09-27 14:17:56 +02002217 u8 *bssid = profile->bssid;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002218 struct brcmf_sta_info_le sta_info_le;
Hante Meuleman9ee66d12014-01-29 15:32:11 +01002219 u32 beacon_period;
2220 u32 dtim_period;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002221
Arend van Sprield96b8012012-12-05 15:26:02 +01002222 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002223 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002224 return -EIO;
2225
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002226 if (brcmf_is_apmode(ifp->vif)) {
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002227 memcpy(&sta_info_le, mac, ETH_ALEN);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002228 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002229 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002230 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002231 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002232 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002233 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002234 }
Hante Meuleman1a873342012-09-27 14:17:54 +02002235 sinfo->filled = STATION_INFO_INACTIVE_TIME;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002236 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2237 if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002238 sinfo->filled |= STATION_INFO_CONNECTED_TIME;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002239 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
Hante Meuleman1a873342012-09-27 14:17:54 +02002240 }
Arend van Sprield96b8012012-12-05 15:26:02 +01002241 brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n",
2242 sinfo->inactive_time, sinfo->connected_time);
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002243 } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002244 if (memcmp(mac, bssid, ETH_ALEN)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002245 brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
2246 mac, bssid);
Hante Meuleman1a873342012-09-27 14:17:54 +02002247 err = -ENOENT;
2248 goto done;
2249 }
2250 /* Report the current tx rate */
Hante Meuleman89286dc2013-02-08 15:53:46 +01002251 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
Hante Meuleman1a873342012-09-27 14:17:54 +02002252 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002253 brcmf_err("Could not get rate (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002254 goto done;
2255 } else {
2256 sinfo->filled |= STATION_INFO_TX_BITRATE;
2257 sinfo->txrate.legacy = rate * 5;
Arend van Spriel16886732012-12-05 15:26:04 +01002258 brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2);
Hante Meuleman1a873342012-09-27 14:17:54 +02002259 }
2260
Arend van Sprielc1179032012-10-22 13:55:33 -07002261 if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
2262 &ifp->vif->sme_state)) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002263 memset(&scb_val, 0, sizeof(scb_val));
Arend van Sprielc1179032012-10-22 13:55:33 -07002264 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
2265 &scb_val, sizeof(scb_val));
Hante Meuleman1a873342012-09-27 14:17:54 +02002266 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002267 brcmf_err("Could not get rssi (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002268 goto done;
2269 } else {
2270 rssi = le32_to_cpu(scb_val.val);
2271 sinfo->filled |= STATION_INFO_SIGNAL;
2272 sinfo->signal = rssi;
Arend van Spriel16886732012-12-05 15:26:04 +01002273 brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
Hante Meuleman1a873342012-09-27 14:17:54 +02002274 }
Hante Meuleman9ee66d12014-01-29 15:32:11 +01002275 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD,
2276 &beacon_period);
2277 if (err) {
2278 brcmf_err("Could not get beacon period (%d)\n",
2279 err);
2280 goto done;
2281 } else {
2282 sinfo->bss_param.beacon_interval =
2283 beacon_period;
2284 brcmf_dbg(CONN, "Beacon peroid %d\n",
2285 beacon_period);
2286 }
2287 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD,
2288 &dtim_period);
2289 if (err) {
2290 brcmf_err("Could not get DTIM period (%d)\n",
2291 err);
2292 goto done;
2293 } else {
2294 sinfo->bss_param.dtim_period = dtim_period;
2295 brcmf_dbg(CONN, "DTIM peroid %d\n",
2296 dtim_period);
2297 }
2298 sinfo->filled |= STATION_INFO_BSS_PARAM;
Hante Meuleman1a873342012-09-27 14:17:54 +02002299 }
2300 } else
2301 err = -EPERM;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002302done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002303 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002304 return err;
2305}
2306
2307static s32
2308brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2309 bool enabled, s32 timeout)
2310{
2311 s32 pm;
2312 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002313 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002314 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002315
Arend van Sprield96b8012012-12-05 15:26:02 +01002316 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002317
2318 /*
2319 * Powersave enable/disable request is coming from the
2320 * cfg80211 even before the interface is up. In that
2321 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002322 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002323 * FW later while initializing the dongle
2324 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002325 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002326 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002327
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002328 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002329 goto done;
2330 }
2331
2332 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002333 /* Do not enable the power save after assoc if it is a p2p interface */
2334 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2335 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2336 pm = PM_OFF;
2337 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002338 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002339
Arend van Sprielc1179032012-10-22 13:55:33 -07002340 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002341 if (err) {
2342 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002343 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002344 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002345 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002346 }
2347done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002348 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002349 return err;
2350}
2351
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002352static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002353 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002354{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002355 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002356 struct ieee80211_channel *notify_channel;
2357 struct cfg80211_bss *bss;
2358 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002359 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002360 u16 channel;
2361 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002362 u16 notify_capability;
2363 u16 notify_interval;
2364 u8 *notify_ie;
2365 size_t notify_ielen;
2366 s32 notify_signal;
2367
2368 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002369 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002370 return 0;
2371 }
2372
Franky Lin83cf17a2013-04-11 13:28:50 +02002373 if (!bi->ctl_ch) {
2374 ch.chspec = le16_to_cpu(bi->chanspec);
2375 cfg->d11inf.decchspec(&ch);
2376 bi->ctl_ch = ch.chnum;
2377 }
2378 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002379
2380 if (channel <= CH_MAX_2G_CHANNEL)
2381 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2382 else
2383 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2384
2385 freq = ieee80211_channel_to_frequency(channel, band->band);
2386 notify_channel = ieee80211_get_channel(wiphy, freq);
2387
Arend van Spriel5b435de2011-10-05 13:19:03 +02002388 notify_capability = le16_to_cpu(bi->capability);
2389 notify_interval = le16_to_cpu(bi->beacon_period);
2390 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2391 notify_ielen = le32_to_cpu(bi->ie_length);
2392 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2393
Arend van Spriel16886732012-12-05 15:26:04 +01002394 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2395 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2396 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2397 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2398 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002399
2400 bss = cfg80211_inform_bss(wiphy, notify_channel, (const u8 *)bi->BSSID,
Johannes Berg8e6cffb2012-03-13 13:57:03 +01002401 0, notify_capability, notify_interval, notify_ie,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002402 notify_ielen, notify_signal, GFP_KERNEL);
2403
Franky Line78946e2011-11-10 20:30:34 +01002404 if (!bss)
2405 return -ENOMEM;
2406
Johannes Berg5b112d32013-02-01 01:49:58 +01002407 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002408
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002409 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002410}
2411
Roland Vossen6f09be02011-10-18 14:03:02 +02002412static struct brcmf_bss_info_le *
2413next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2414{
2415 if (bss == NULL)
2416 return list->bss_info_le;
2417 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2418 le32_to_cpu(bss->length));
2419}
2420
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002421static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002422{
2423 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002424 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002425 s32 err = 0;
2426 int i;
2427
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002428 bss_list = cfg->bss_list;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002429 if (bss_list->count != 0 &&
2430 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002431 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2432 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002433 return -EOPNOTSUPP;
2434 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002435 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002436 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002437 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002438 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002439 if (err)
2440 break;
2441 }
2442 return err;
2443}
2444
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002445static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002446 struct net_device *ndev, const u8 *bssid)
2447{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002448 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002449 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002450 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002451 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002452 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002453 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002454 u8 *buf = NULL;
2455 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002456 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002457 u16 notify_capability;
2458 u16 notify_interval;
2459 u8 *notify_ie;
2460 size_t notify_ielen;
2461 s32 notify_signal;
2462
Arend van Sprield96b8012012-12-05 15:26:02 +01002463 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002464
2465 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2466 if (buf == NULL) {
2467 err = -ENOMEM;
2468 goto CleanUp;
2469 }
2470
2471 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2472
Arend van Sprielac24be62012-10-22 10:36:23 -07002473 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2474 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002475 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002476 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002477 goto CleanUp;
2478 }
2479
Roland Vossend34bf642011-10-18 14:03:01 +02002480 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002481
Franky Lin83cf17a2013-04-11 13:28:50 +02002482 ch.chspec = le16_to_cpu(bi->chanspec);
2483 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002484
Franky Lin83cf17a2013-04-11 13:28:50 +02002485 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002486 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2487 else
2488 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2489
Franky Lin83cf17a2013-04-11 13:28:50 +02002490 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002491 notify_channel = ieee80211_get_channel(wiphy, freq);
2492
Arend van Spriel5b435de2011-10-05 13:19:03 +02002493 notify_capability = le16_to_cpu(bi->capability);
2494 notify_interval = le16_to_cpu(bi->beacon_period);
2495 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2496 notify_ielen = le32_to_cpu(bi->ie_length);
2497 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2498
Franky Lin83cf17a2013-04-11 13:28:50 +02002499 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002500 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2501 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2502 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002503
Franky Line78946e2011-11-10 20:30:34 +01002504 bss = cfg80211_inform_bss(wiphy, notify_channel, bssid,
Johannes Berg8e6cffb2012-03-13 13:57:03 +01002505 0, notify_capability, notify_interval,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002506 notify_ie, notify_ielen, notify_signal, GFP_KERNEL);
2507
Franky Line78946e2011-11-10 20:30:34 +01002508 if (!bss) {
2509 err = -ENOMEM;
2510 goto CleanUp;
2511 }
2512
Johannes Berg5b112d32013-02-01 01:49:58 +01002513 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002514
Arend van Spriel5b435de2011-10-05 13:19:03 +02002515CleanUp:
2516
2517 kfree(buf);
2518
Arend van Sprield96b8012012-12-05 15:26:02 +01002519 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002520
2521 return err;
2522}
2523
Hante Meuleman89286dc2013-02-08 15:53:46 +01002524static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2525 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002526{
Hante Meuleman89286dc2013-02-08 15:53:46 +01002527 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev);
Roland Vossend34bf642011-10-18 14:03:01 +02002528 struct brcmf_bss_info_le *bi;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002529 struct brcmf_ssid *ssid;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002530 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002531 u16 beacon_interval;
2532 u8 dtim_period;
2533 size_t ie_len;
2534 u8 *ie;
2535 s32 err = 0;
2536
Arend van Sprield96b8012012-12-05 15:26:02 +01002537 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002538 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002539 return err;
2540
Arend van Spriel06bb1232012-09-27 14:17:56 +02002541 ssid = &profile->ssid;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002542
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002543 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002544 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002545 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002546 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002547 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002548 goto update_bss_info_out;
2549 }
2550
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002551 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2552 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002553 if (err)
2554 goto update_bss_info_out;
2555
2556 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2557 ie_len = le32_to_cpu(bi->ie_length);
2558 beacon_interval = le16_to_cpu(bi->beacon_period);
2559
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002560 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002561 if (tim)
2562 dtim_period = tim->data[1];
2563 else {
2564 /*
2565 * active scan was done so we could not get dtim
2566 * information out of probe response.
2567 * so we speficially query dtim information to dongle.
2568 */
2569 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002570 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002571 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002572 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002573 goto update_bss_info_out;
2574 }
2575 dtim_period = (u8)var;
2576 }
2577
Arend van Spriel5b435de2011-10-05 13:19:03 +02002578update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01002579 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002580 return err;
2581}
2582
Hante Meuleman18e2f612013-02-08 15:53:49 +01002583void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002584{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002585 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002586
Arend van Sprielc1179032012-10-22 13:55:33 -07002587 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Hante Meulemanf07998952012-11-05 16:22:13 -08002588 if (cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02002589 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002590 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02002591 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002592 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2593 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002594}
2595
Hante Meulemane756af52012-09-11 21:18:52 +02002596static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2597{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002598 struct brcmf_cfg80211_info *cfg =
2599 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02002600 escan_timeout_work);
2601
Arend van Spriela0f472a2013-04-05 10:57:49 +02002602 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02002603}
2604
2605static void brcmf_escan_timeout(unsigned long data)
2606{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002607 struct brcmf_cfg80211_info *cfg =
2608 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02002609
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002610 if (cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002611 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08002612 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02002613 }
2614}
2615
2616static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02002617brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2618 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02002619 struct brcmf_bss_info_le *bss_info_le)
2620{
Franky Lin83cf17a2013-04-11 13:28:50 +02002621 struct brcmu_chan ch_bss, ch_bss_info_le;
2622
2623 ch_bss.chspec = le16_to_cpu(bss->chanspec);
2624 cfg->d11inf.decchspec(&ch_bss);
2625 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
2626 cfg->d11inf.decchspec(&ch_bss_info_le);
2627
Hante Meulemane756af52012-09-11 21:18:52 +02002628 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02002629 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02002630 bss_info_le->SSID_len == bss->SSID_len &&
2631 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002632 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
2633 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02002634 s16 bss_rssi = le16_to_cpu(bss->RSSI);
2635 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
2636
Hante Meulemane756af52012-09-11 21:18:52 +02002637 /* preserve max RSSI if the measurements are
2638 * both on-channel or both off-channel
2639 */
Arend van Spriel029591f2012-09-19 22:21:06 +02002640 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02002641 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002642 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
2643 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02002644 /* preserve the on-channel rssi measurement
2645 * if the new measurement is off channel
2646 */
2647 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002648 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02002649 }
2650 return 1;
2651 }
2652 return 0;
2653}
2654
2655static s32
Arend van Spriel19937322012-11-05 16:22:32 -08002656brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02002657 const struct brcmf_event_msg *e, void *data)
2658{
Arend van Spriel19937322012-11-05 16:22:32 -08002659 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02002660 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02002661 struct brcmf_escan_result_le *escan_result_le;
2662 struct brcmf_bss_info_le *bss_info_le;
2663 struct brcmf_bss_info_le *bss = NULL;
2664 u32 bi_length;
2665 struct brcmf_scan_results *list;
2666 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002667 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02002668
Arend van Spriel5c36b992012-11-14 18:46:05 -08002669 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02002670
Arend van Spriela0f472a2013-04-05 10:57:49 +02002671 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
2672 brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx);
Hante Meulemane756af52012-09-11 21:18:52 +02002673 return -EPERM;
2674 }
2675
2676 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002677 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002678 escan_result_le = (struct brcmf_escan_result_le *) data;
2679 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002680 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002681 goto exit;
2682 }
Hante Meulemane756af52012-09-11 21:18:52 +02002683 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002684 brcmf_err("Invalid bss_count %d: ignoring\n",
2685 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02002686 goto exit;
2687 }
2688 bss_info_le = &escan_result_le->bss_info_le;
2689
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002690 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
2691 goto exit;
2692
2693 if (!cfg->scan_request) {
2694 brcmf_dbg(SCAN, "result without cfg80211 request\n");
2695 goto exit;
2696 }
2697
Hante Meulemane756af52012-09-11 21:18:52 +02002698 bi_length = le32_to_cpu(bss_info_le->length);
2699 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
2700 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002701 brcmf_err("Invalid bss_info length %d: ignoring\n",
2702 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02002703 goto exit;
2704 }
2705
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002706 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02002707 BIT(NL80211_IFTYPE_ADHOC))) {
2708 if (le16_to_cpu(bss_info_le->capability) &
2709 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002710 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002711 goto exit;
2712 }
2713 }
2714
2715 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002716 cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02002717 if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002718 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002719 goto exit;
2720 }
2721
2722 for (i = 0; i < list->count; i++) {
2723 bss = bss ? (struct brcmf_bss_info_le *)
2724 ((unsigned char *)bss +
2725 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02002726 if (brcmf_compare_update_same_bss(cfg, bss,
2727 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02002728 goto exit;
2729 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002730 memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
Hante Meulemane756af52012-09-11 21:18:52 +02002731 bss_info_le, bi_length);
2732 list->version = le32_to_cpu(bss_info_le->version);
2733 list->buflen += bi_length;
2734 list->count++;
2735 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002736 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002737 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
2738 goto exit;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002739 if (cfg->scan_request) {
2740 cfg->bss_list = (struct brcmf_scan_results *)
2741 cfg->escan_info.escan_buf;
2742 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002743 aborted = status != BRCMF_E_STATUS_SUCCESS;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002744 brcmf_notify_escan_complete(cfg, ifp, aborted,
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002745 false);
Hante Meulemane756af52012-09-11 21:18:52 +02002746 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002747 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
2748 status);
Hante Meulemane756af52012-09-11 21:18:52 +02002749 }
2750exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002751 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02002752}
2753
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002754static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02002755{
Arend van Spriel5c36b992012-11-14 18:46:05 -08002756 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
2757 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08002758 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
2759 /* Init scan_timeout timer */
2760 init_timer(&cfg->escan_timeout);
2761 cfg->escan_timeout.data = (unsigned long) cfg;
2762 cfg->escan_timeout.function = brcmf_escan_timeout;
2763 INIT_WORK(&cfg->escan_timeout_work,
2764 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02002765}
2766
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05002767static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002768{
2769 if (ms < 1000 / HZ) {
2770 cond_resched();
2771 mdelay(ms);
2772 } else {
2773 msleep(ms);
2774 }
2775}
2776
2777static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
2778{
Arend van Sprield96b8012012-12-05 15:26:02 +01002779 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002780
Arend van Spriel5b435de2011-10-05 13:19:03 +02002781 return 0;
2782}
2783
2784static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
2785 struct cfg80211_wowlan *wow)
2786{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002787 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2788 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel7d641072012-10-22 13:55:39 -07002789 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002790
Arend van Sprield96b8012012-12-05 15:26:02 +01002791 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002792
2793 /*
Arend van Spriel7d641072012-10-22 13:55:39 -07002794 * if the primary net_device is not READY there is nothing
2795 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02002796 */
Arend van Spriel7d641072012-10-22 13:55:39 -07002797 vif = ((struct brcmf_if *)netdev_priv(ndev))->vif;
2798 if (!check_vif_up(vif))
2799 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002800
Arend van Spriel7d641072012-10-22 13:55:39 -07002801 list_for_each_entry(vif, &cfg->vif_list, list) {
2802 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
2803 continue;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002804 /*
Arend van Spriel7d641072012-10-22 13:55:39 -07002805 * While going to suspend if associated with AP disassociate
2806 * from AP to save power while system is in suspended state
Arend van Spriel5b435de2011-10-05 13:19:03 +02002807 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01002808 brcmf_link_down(vif);
Arend van Spriel7d641072012-10-22 13:55:39 -07002809
Arend van Spriel903e0ee2012-11-28 21:44:11 +01002810 /* Make sure WPA_Supplicant receives all the event
2811 * generated due to DISASSOC call to the fw to keep
2812 * the state fw and WPA_Supplicant state consistent
2813 */
2814 brcmf_delay(500);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002815 }
2816
Arend van Spriel7d641072012-10-22 13:55:39 -07002817 /* end any scanning */
2818 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002819 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002820
2821 /* Turn off watchdog timer */
Arend van Sprielf96aa072013-04-05 10:57:48 +02002822 brcmf_set_mpc(netdev_priv(ndev), 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002823
Arend van Spriel7d641072012-10-22 13:55:39 -07002824exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01002825 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07002826 /* clear any scanning activity */
2827 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002828 return 0;
2829}
2830
2831static __used s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02002832brcmf_update_pmklist(struct net_device *ndev,
2833 struct brcmf_cfg80211_pmk_list *pmk_list, s32 err)
2834{
2835 int i, j;
Arend van Spriel40c8e952011-10-12 20:51:20 +02002836 int pmkid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002837
Arend van Spriel40c8e952011-10-12 20:51:20 +02002838 pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid);
2839
Arend van Spriel16886732012-12-05 15:26:04 +01002840 brcmf_dbg(CONN, "No of elements %d\n", pmkid_len);
Arend van Spriel40c8e952011-10-12 20:51:20 +02002841 for (i = 0; i < pmkid_len; i++) {
Arend van Spriel16886732012-12-05 15:26:04 +01002842 brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i,
2843 &pmk_list->pmkids.pmkid[i].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002844 for (j = 0; j < WLAN_PMKID_LEN; j++)
Arend van Spriel16886732012-12-05 15:26:04 +01002845 brcmf_dbg(CONN, "%02x\n",
2846 pmk_list->pmkids.pmkid[i].PMKID[j]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002847 }
2848
2849 if (!err)
Arend van Sprielac24be62012-10-22 10:36:23 -07002850 brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info",
2851 (char *)pmk_list, sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002852
2853 return err;
2854}
2855
2856static s32
2857brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
2858 struct cfg80211_pmksa *pmksa)
2859{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002860 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002861 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002862 struct pmkid_list *pmkids = &cfg->pmk_list->pmkids;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002863 s32 err = 0;
2864 int i;
Arend van Spriel40c8e952011-10-12 20:51:20 +02002865 int pmkid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002866
Arend van Sprield96b8012012-12-05 15:26:02 +01002867 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002868 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002869 return -EIO;
2870
Arend van Spriel40c8e952011-10-12 20:51:20 +02002871 pmkid_len = le32_to_cpu(pmkids->npmkid);
2872 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002873 if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN))
2874 break;
2875 if (i < WL_NUM_PMKIDS_MAX) {
2876 memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN);
2877 memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
Arend van Spriel40c8e952011-10-12 20:51:20 +02002878 if (i == pmkid_len) {
2879 pmkid_len++;
2880 pmkids->npmkid = cpu_to_le32(pmkid_len);
2881 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002882 } else
2883 err = -EINVAL;
2884
Arend van Spriel16886732012-12-05 15:26:04 +01002885 brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2886 pmkids->pmkid[pmkid_len].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002887 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01002888 brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002889
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002890 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002891
Arend van Sprield96b8012012-12-05 15:26:02 +01002892 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002893 return err;
2894}
2895
2896static s32
2897brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
2898 struct cfg80211_pmksa *pmksa)
2899{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002900 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002901 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002902 struct pmkid_list pmkid;
2903 s32 err = 0;
Arend van Spriel40c8e952011-10-12 20:51:20 +02002904 int i, pmkid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002905
Arend van Sprield96b8012012-12-05 15:26:02 +01002906 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002907 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002908 return -EIO;
2909
2910 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
2911 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2912
Arend van Spriel16886732012-12-05 15:26:04 +01002913 brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
2914 &pmkid.pmkid[0].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002915 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01002916 brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002917
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002918 pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid);
Arend van Spriel40c8e952011-10-12 20:51:20 +02002919 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002920 if (!memcmp
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002921 (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002922 ETH_ALEN))
2923 break;
2924
Arend van Spriel40c8e952011-10-12 20:51:20 +02002925 if ((pmkid_len > 0)
2926 && (i < pmkid_len)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002927 memset(&cfg->pmk_list->pmkids.pmkid[i], 0,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002928 sizeof(struct pmkid));
Arend van Spriel40c8e952011-10-12 20:51:20 +02002929 for (; i < (pmkid_len - 1); i++) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002930 memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID,
2931 &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002932 ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002933 memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID,
2934 &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002935 WLAN_PMKID_LEN);
2936 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002937 cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002938 } else
2939 err = -EINVAL;
2940
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002941 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002942
Arend van Sprield96b8012012-12-05 15:26:02 +01002943 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002944 return err;
2945
2946}
2947
2948static s32
2949brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
2950{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002951 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002952 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002953 s32 err = 0;
2954
Arend van Sprield96b8012012-12-05 15:26:02 +01002955 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002956 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002957 return -EIO;
2958
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002959 memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list));
2960 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002961
Arend van Sprield96b8012012-12-05 15:26:02 +01002962 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002963 return err;
2964
2965}
2966
Arend van Spriele5806072012-09-19 22:21:08 +02002967/*
2968 * PFN result doesn't have all the info which are
2969 * required by the supplicant
2970 * (For e.g IEs) Do a target Escan so that sched scan results are reported
2971 * via wl_inform_single_bss in the required format. Escan does require the
2972 * scan request in the form of cfg80211_scan_request. For timebeing, create
2973 * cfg80211_scan_request one out of the received PNO event.
2974 */
2975static s32
Arend van Spriel19937322012-11-05 16:22:32 -08002976brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
Arend van Spriele5806072012-09-19 22:21:08 +02002977 const struct brcmf_event_msg *e, void *data)
2978{
Arend van Spriel19937322012-11-05 16:22:32 -08002979 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriele5806072012-09-19 22:21:08 +02002980 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
2981 struct cfg80211_scan_request *request = NULL;
2982 struct cfg80211_ssid *ssid = NULL;
2983 struct ieee80211_channel *channel = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002984 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02002985 int err = 0;
2986 int channel_req = 0;
2987 int band = 0;
2988 struct brcmf_pno_scanresults_le *pfn_result;
2989 u32 result_count;
2990 u32 status;
2991
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002992 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02002993
Arend van Spriel5c36b992012-11-14 18:46:05 -08002994 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002995 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
Arend van Spriele5806072012-09-19 22:21:08 +02002996 return 0;
2997 }
2998
2999 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3000 result_count = le32_to_cpu(pfn_result->count);
3001 status = le32_to_cpu(pfn_result->status);
3002
3003 /*
3004 * PFN event is limited to fit 512 bytes so we may get
3005 * multiple NET_FOUND events. For now place a warning here.
3006 */
3007 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003008 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
Arend van Spriele5806072012-09-19 22:21:08 +02003009 if (result_count > 0) {
3010 int i;
3011
3012 request = kzalloc(sizeof(*request), GFP_KERNEL);
Dan Carpenter58901d12012-09-26 10:21:48 +03003013 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3014 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
Arend van Spriele5806072012-09-19 22:21:08 +02003015 if (!request || !ssid || !channel) {
3016 err = -ENOMEM;
3017 goto out_err;
3018 }
3019
3020 request->wiphy = wiphy;
3021 data += sizeof(struct brcmf_pno_scanresults_le);
3022 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3023
3024 for (i = 0; i < result_count; i++) {
3025 netinfo = &netinfo_start[i];
3026 if (!netinfo) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003027 brcmf_err("Invalid netinfo ptr. index: %d\n",
3028 i);
Arend van Spriele5806072012-09-19 22:21:08 +02003029 err = -EINVAL;
3030 goto out_err;
3031 }
3032
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003033 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3034 netinfo->SSID, netinfo->channel);
Arend van Spriele5806072012-09-19 22:21:08 +02003035 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3036 ssid[i].ssid_len = netinfo->SSID_len;
3037 request->n_ssids++;
3038
3039 channel_req = netinfo->channel;
3040 if (channel_req <= CH_MAX_2G_CHANNEL)
3041 band = NL80211_BAND_2GHZ;
3042 else
3043 band = NL80211_BAND_5GHZ;
3044 channel[i].center_freq =
3045 ieee80211_channel_to_frequency(channel_req,
3046 band);
3047 channel[i].band = band;
3048 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3049 request->channels[i] = &channel[i];
3050 request->n_channels++;
3051 }
3052
3053 /* assign parsed ssid array */
3054 if (request->n_ssids)
3055 request->ssids = &ssid[0];
3056
Arend van Sprielc1179032012-10-22 13:55:33 -07003057 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriele5806072012-09-19 22:21:08 +02003058 /* Abort any on-going scan */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003059 brcmf_abort_scanning(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003060 }
3061
Arend van Sprielc1179032012-10-22 13:55:33 -07003062 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel2668b0b2014-01-13 22:20:28 +01003063 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02003064 err = brcmf_do_escan(cfg, wiphy, ifp, request);
Arend van Spriele5806072012-09-19 22:21:08 +02003065 if (err) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003066 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003067 goto out_err;
3068 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003069 cfg->sched_escan = true;
3070 cfg->scan_request = request;
Arend van Spriele5806072012-09-19 22:21:08 +02003071 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003072 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003073 goto out_err;
3074 }
3075
3076 kfree(ssid);
3077 kfree(channel);
3078 kfree(request);
3079 return 0;
3080
3081out_err:
3082 kfree(ssid);
3083 kfree(channel);
3084 kfree(request);
3085 cfg80211_sched_scan_stopped(wiphy);
3086 return err;
3087}
3088
Arend van Spriele5806072012-09-19 22:21:08 +02003089static int brcmf_dev_pno_clean(struct net_device *ndev)
3090{
Arend van Spriele5806072012-09-19 22:21:08 +02003091 int ret;
3092
3093 /* Disable pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003094 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003095 if (ret == 0) {
3096 /* clear pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003097 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3098 NULL, 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003099 }
3100 if (ret < 0)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003101 brcmf_err("failed code %d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003102
3103 return ret;
3104}
3105
3106static int brcmf_dev_pno_config(struct net_device *ndev)
3107{
3108 struct brcmf_pno_param_le pfn_param;
Arend van Spriele5806072012-09-19 22:21:08 +02003109
3110 memset(&pfn_param, 0, sizeof(pfn_param));
3111 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3112
3113 /* set extra pno params */
3114 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3115 pfn_param.repeat = BRCMF_PNO_REPEAT;
3116 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3117
3118 /* set up pno scan fr */
3119 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3120
Arend van Sprielac24be62012-10-22 10:36:23 -07003121 return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set",
3122 &pfn_param, sizeof(pfn_param));
Arend van Spriele5806072012-09-19 22:21:08 +02003123}
3124
3125static int
3126brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3127 struct net_device *ndev,
3128 struct cfg80211_sched_scan_request *request)
3129{
Arend van Sprielc1179032012-10-22 13:55:33 -07003130 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003131 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003132 struct brcmf_pno_net_param_le pfn;
3133 int i;
3134 int ret = 0;
3135
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003136 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003137 request->n_match_sets, request->n_ssids);
Arend van Sprielc1179032012-10-22 13:55:33 -07003138 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003139 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003140 return -EAGAIN;
3141 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02003142 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3143 brcmf_err("Scanning suppressed: status (%lu)\n",
3144 cfg->scan_status);
3145 return -EAGAIN;
3146 }
Arend van Spriele5806072012-09-19 22:21:08 +02003147
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003148 if (!request->n_ssids || !request->n_match_sets) {
Arend van Spriel181f2d12014-05-27 12:56:13 +02003149 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003150 request->n_ssids);
Arend van Spriele5806072012-09-19 22:21:08 +02003151 return -EINVAL;
3152 }
3153
3154 if (request->n_ssids > 0) {
3155 for (i = 0; i < request->n_ssids; i++) {
3156 /* Active scan req for ssids */
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003157 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3158 request->ssids[i].ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003159
3160 /*
3161 * match_set ssids is a supert set of n_ssid list,
3162 * so we need not add these set seperately.
3163 */
3164 }
3165 }
3166
3167 if (request->n_match_sets > 0) {
3168 /* clean up everything */
3169 ret = brcmf_dev_pno_clean(ndev);
3170 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003171 brcmf_err("failed error=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003172 return ret;
3173 }
3174
3175 /* configure pno */
3176 ret = brcmf_dev_pno_config(ndev);
3177 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003178 brcmf_err("PNO setup failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003179 return -EINVAL;
3180 }
3181
3182 /* configure each match set */
3183 for (i = 0; i < request->n_match_sets; i++) {
3184 struct cfg80211_ssid *ssid;
3185 u32 ssid_len;
3186
3187 ssid = &request->match_sets[i].ssid;
3188 ssid_len = ssid->ssid_len;
3189
3190 if (!ssid_len) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003191 brcmf_err("skip broadcast ssid\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003192 continue;
3193 }
3194 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3195 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3196 pfn.wsec = cpu_to_le32(0);
3197 pfn.infra = cpu_to_le32(1);
3198 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3199 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3200 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
Arend van Sprielc1179032012-10-22 13:55:33 -07003201 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
Arend van Sprielac24be62012-10-22 10:36:23 -07003202 sizeof(pfn));
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003203 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3204 ret == 0 ? "set" : "failed", ssid->ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003205 }
3206 /* Enable the PNO */
Arend van Sprielc1179032012-10-22 13:55:33 -07003207 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003208 brcmf_err("PNO enable failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003209 return -EINVAL;
3210 }
3211 } else {
3212 return -EINVAL;
3213 }
3214
3215 return 0;
3216}
3217
3218static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3219 struct net_device *ndev)
3220{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003221 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003222
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003223 brcmf_dbg(SCAN, "enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003224 brcmf_dev_pno_clean(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003225 if (cfg->sched_escan)
Arend van Spriela0f472a2013-04-05 10:57:49 +02003226 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
Arend van Spriele5806072012-09-19 22:21:08 +02003227 return 0;
3228}
Arend van Spriele5806072012-09-19 22:21:08 +02003229
Hante Meuleman1f170112013-02-06 18:40:38 +01003230static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003231{
3232 s32 err;
3233
3234 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003235 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003236 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003237 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003238 return err;
3239 }
3240 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003241 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003242 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003243 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003244 return err;
3245 }
3246 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003247 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003248 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003249 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003250 return err;
3251 }
3252
3253 return 0;
3254}
3255
3256static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3257{
3258 if (is_rsn_ie)
3259 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3260
3261 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3262}
3263
3264static s32
Johannes Berg4b5800f2014-01-15 14:55:59 +01003265brcmf_configure_wpaie(struct net_device *ndev,
3266 const struct brcmf_vs_tlv *wpa_ie,
3267 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003268{
Arend van Sprielac24be62012-10-22 10:36:23 -07003269 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02003270 u32 auth = 0; /* d11 open authentication */
3271 u16 count;
3272 s32 err = 0;
3273 s32 len = 0;
3274 u32 i;
3275 u32 wsec;
3276 u32 pval = 0;
3277 u32 gval = 0;
3278 u32 wpa_auth = 0;
3279 u32 offset;
3280 u8 *data;
3281 u16 rsn_cap;
3282 u32 wme_bss_disable;
3283
Arend van Sprield96b8012012-12-05 15:26:02 +01003284 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003285 if (wpa_ie == NULL)
3286 goto exit;
3287
3288 len = wpa_ie->len + TLV_HDR_LEN;
3289 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003290 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003291 if (!is_rsn_ie)
3292 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003293 else
3294 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003295
3296 /* check for multicast cipher suite */
3297 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3298 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003299 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003300 goto exit;
3301 }
3302
3303 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3304 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003305 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003306 goto exit;
3307 }
3308 offset += TLV_OUI_LEN;
3309
3310 /* pick up multicast cipher */
3311 switch (data[offset]) {
3312 case WPA_CIPHER_NONE:
3313 gval = 0;
3314 break;
3315 case WPA_CIPHER_WEP_40:
3316 case WPA_CIPHER_WEP_104:
3317 gval = WEP_ENABLED;
3318 break;
3319 case WPA_CIPHER_TKIP:
3320 gval = TKIP_ENABLED;
3321 break;
3322 case WPA_CIPHER_AES_CCM:
3323 gval = AES_ENABLED;
3324 break;
3325 default:
3326 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003327 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003328 goto exit;
3329 }
3330
3331 offset++;
3332 /* walk thru unicast cipher list and pick up what we recognize */
3333 count = data[offset] + (data[offset + 1] << 8);
3334 offset += WPA_IE_SUITE_COUNT_LEN;
3335 /* Check for unicast suite(s) */
3336 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3337 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003338 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003339 goto exit;
3340 }
3341 for (i = 0; i < count; i++) {
3342 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3343 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003344 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003345 goto exit;
3346 }
3347 offset += TLV_OUI_LEN;
3348 switch (data[offset]) {
3349 case WPA_CIPHER_NONE:
3350 break;
3351 case WPA_CIPHER_WEP_40:
3352 case WPA_CIPHER_WEP_104:
3353 pval |= WEP_ENABLED;
3354 break;
3355 case WPA_CIPHER_TKIP:
3356 pval |= TKIP_ENABLED;
3357 break;
3358 case WPA_CIPHER_AES_CCM:
3359 pval |= AES_ENABLED;
3360 break;
3361 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003362 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003363 }
3364 offset++;
3365 }
3366 /* walk thru auth management suite list and pick up what we recognize */
3367 count = data[offset] + (data[offset + 1] << 8);
3368 offset += WPA_IE_SUITE_COUNT_LEN;
3369 /* Check for auth key management suite(s) */
3370 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3371 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003372 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003373 goto exit;
3374 }
3375 for (i = 0; i < count; i++) {
3376 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3377 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003378 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003379 goto exit;
3380 }
3381 offset += TLV_OUI_LEN;
3382 switch (data[offset]) {
3383 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003384 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003385 wpa_auth |= WPA_AUTH_NONE;
3386 break;
3387 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003388 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003389 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3390 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3391 break;
3392 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01003393 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003394 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3395 (wpa_auth |= WPA_AUTH_PSK);
3396 break;
3397 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003398 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003399 }
3400 offset++;
3401 }
3402
3403 if (is_rsn_ie) {
3404 wme_bss_disable = 1;
3405 if ((offset + RSN_CAP_LEN) <= len) {
3406 rsn_cap = data[offset] + (data[offset + 1] << 8);
3407 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3408 wme_bss_disable = 0;
3409 }
3410 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07003411 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003412 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02003413 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003414 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003415 goto exit;
3416 }
3417 }
3418 /* FOR WPS , set SES_OW_ENABLED */
3419 wsec = (pval | gval | SES_OW_ENABLED);
3420
3421 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003422 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003423 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003424 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003425 goto exit;
3426 }
3427 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003428 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02003429 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003430 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003431 goto exit;
3432 }
3433 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003434 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003435 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003436 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003437 goto exit;
3438 }
3439
3440exit:
3441 return err;
3442}
3443
3444static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08003445brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02003446 struct parsed_vndr_ies *vndr_ies)
3447{
Hante Meuleman1a873342012-09-27 14:17:54 +02003448 struct brcmf_vs_tlv *vndrie;
3449 struct brcmf_tlv *ie;
3450 struct parsed_vndr_ie_info *parsed_info;
3451 s32 remaining_len;
3452
3453 remaining_len = (s32)vndr_ie_len;
3454 memset(vndr_ies, 0, sizeof(*vndr_ies));
3455
3456 ie = (struct brcmf_tlv *)vndr_ie_buf;
3457 while (ie) {
3458 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
3459 goto next;
3460 vndrie = (struct brcmf_vs_tlv *)ie;
3461 /* len should be bigger than OUI length + one */
3462 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003463 brcmf_err("invalid vndr ie. length is too small %d\n",
3464 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003465 goto next;
3466 }
3467 /* if wpa or wme ie, do not add ie */
3468 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
3469 ((vndrie->oui_type == WPA_OUI_TYPE) ||
3470 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003471 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003472 goto next;
3473 }
3474
3475 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
3476
3477 /* save vndr ie information */
3478 parsed_info->ie_ptr = (char *)vndrie;
3479 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
3480 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
3481
3482 vndr_ies->count++;
3483
Arend van Sprield96b8012012-12-05 15:26:02 +01003484 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
3485 parsed_info->vndrie.oui[0],
3486 parsed_info->vndrie.oui[1],
3487 parsed_info->vndrie.oui[2],
3488 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02003489
Arend van Spriel9f440b72013-02-08 15:53:36 +01003490 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02003491 break;
3492next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003493 remaining_len -= (ie->len + TLV_HDR_LEN);
3494 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02003495 ie = NULL;
3496 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003497 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
3498 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02003499 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003500 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02003501}
3502
3503static u32
3504brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
3505{
3506
3507 __le32 iecount_le;
3508 __le32 pktflag_le;
3509
3510 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
3511 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
3512
3513 iecount_le = cpu_to_le32(1);
3514 memcpy(&iebuf[VNDR_IE_COUNT_OFFSET], &iecount_le, sizeof(iecount_le));
3515
3516 pktflag_le = cpu_to_le32(pktflag);
3517 memcpy(&iebuf[VNDR_IE_PKTFLAG_OFFSET], &pktflag_le, sizeof(pktflag_le));
3518
3519 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
3520
3521 return ie_len + VNDR_IE_HDR_SIZE;
3522}
3523
Arend van Spriel1332e262012-11-05 16:22:18 -08003524s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
3525 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02003526{
Arend van Spriel1332e262012-11-05 16:22:18 -08003527 struct brcmf_if *ifp;
3528 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003529 s32 err = 0;
3530 u8 *iovar_ie_buf;
3531 u8 *curr_ie_buf;
3532 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003533 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07003534 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003535 u32 del_add_ie_buf_len = 0;
3536 u32 total_ie_buf_len = 0;
3537 u32 parsed_ie_buf_len = 0;
3538 struct parsed_vndr_ies old_vndr_ies;
3539 struct parsed_vndr_ies new_vndr_ies;
3540 struct parsed_vndr_ie_info *vndrie_info;
3541 s32 i;
3542 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003543 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003544
Arend van Spriel1332e262012-11-05 16:22:18 -08003545 if (!vif)
3546 return -ENODEV;
3547 ifp = vif->ifp;
3548 saved_ie = &vif->saved_ie;
3549
Arend van Sprield96b8012012-12-05 15:26:02 +01003550 brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02003551 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
3552 if (!iovar_ie_buf)
3553 return -ENOMEM;
3554 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01003555 switch (pktflag) {
3556 case BRCMF_VNDR_IE_PRBREQ_FLAG:
3557 mgmt_ie_buf = saved_ie->probe_req_ie;
3558 mgmt_ie_len = &saved_ie->probe_req_ie_len;
3559 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
3560 break;
3561 case BRCMF_VNDR_IE_PRBRSP_FLAG:
3562 mgmt_ie_buf = saved_ie->probe_res_ie;
3563 mgmt_ie_len = &saved_ie->probe_res_ie_len;
3564 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
3565 break;
3566 case BRCMF_VNDR_IE_BEACON_FLAG:
3567 mgmt_ie_buf = saved_ie->beacon_ie;
3568 mgmt_ie_len = &saved_ie->beacon_ie_len;
3569 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
3570 break;
3571 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
3572 mgmt_ie_buf = saved_ie->assoc_req_ie;
3573 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
3574 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
3575 break;
3576 default:
3577 err = -EPERM;
3578 brcmf_err("not suitable type\n");
3579 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003580 }
3581
3582 if (vndr_ie_len > mgmt_ie_buf_len) {
3583 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003584 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003585 goto exit;
3586 }
3587
3588 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3589 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
3590 ptr = curr_ie_buf;
3591 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
3592 for (i = 0; i < new_vndr_ies.count; i++) {
3593 vndrie_info = &new_vndr_ies.ie_info[i];
3594 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
3595 vndrie_info->ie_len);
3596 parsed_ie_buf_len += vndrie_info->ie_len;
3597 }
3598 }
3599
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003600 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02003601 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
3602 (memcmp(mgmt_ie_buf, curr_ie_buf,
3603 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003604 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003605 goto exit;
3606 }
3607
3608 /* parse old vndr_ie */
3609 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
3610
3611 /* make a command to delete old ie */
3612 for (i = 0; i < old_vndr_ies.count; i++) {
3613 vndrie_info = &old_vndr_ies.ie_info[i];
3614
Arend van Sprield96b8012012-12-05 15:26:02 +01003615 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3616 vndrie_info->vndrie.id,
3617 vndrie_info->vndrie.len,
3618 vndrie_info->vndrie.oui[0],
3619 vndrie_info->vndrie.oui[1],
3620 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003621
3622 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3623 vndrie_info->ie_ptr,
3624 vndrie_info->ie_len,
3625 "del");
3626 curr_ie_buf += del_add_ie_buf_len;
3627 total_ie_buf_len += del_add_ie_buf_len;
3628 }
3629 }
3630
3631 *mgmt_ie_len = 0;
3632 /* Add if there is any extra IE */
3633 if (mgmt_ie_buf && parsed_ie_buf_len) {
3634 ptr = mgmt_ie_buf;
3635
3636 remained_buf_len = mgmt_ie_buf_len;
3637
3638 /* make a command to add new ie */
3639 for (i = 0; i < new_vndr_ies.count; i++) {
3640 vndrie_info = &new_vndr_ies.ie_info[i];
3641
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003642 /* verify remained buf size before copy data */
3643 if (remained_buf_len < (vndrie_info->vndrie.len +
3644 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003645 brcmf_err("no space in mgmt_ie_buf: len left %d",
3646 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003647 break;
3648 }
3649 remained_buf_len -= (vndrie_info->ie_len +
3650 VNDR_IE_VSIE_OFFSET);
3651
Arend van Sprield96b8012012-12-05 15:26:02 +01003652 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3653 vndrie_info->vndrie.id,
3654 vndrie_info->vndrie.len,
3655 vndrie_info->vndrie.oui[0],
3656 vndrie_info->vndrie.oui[1],
3657 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003658
3659 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3660 vndrie_info->ie_ptr,
3661 vndrie_info->ie_len,
3662 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02003663
3664 /* save the parsed IE in wl struct */
3665 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
3666 vndrie_info->ie_len);
3667 *mgmt_ie_len += vndrie_info->ie_len;
3668
3669 curr_ie_buf += del_add_ie_buf_len;
3670 total_ie_buf_len += del_add_ie_buf_len;
3671 }
3672 }
3673 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003674 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003675 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003676 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003677 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003678 }
3679
3680exit:
3681 kfree(iovar_ie_buf);
3682 return err;
3683}
3684
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01003685s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
3686{
3687 s32 pktflags[] = {
3688 BRCMF_VNDR_IE_PRBREQ_FLAG,
3689 BRCMF_VNDR_IE_PRBRSP_FLAG,
3690 BRCMF_VNDR_IE_BEACON_FLAG
3691 };
3692 int i;
3693
3694 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
3695 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
3696
3697 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
3698 return 0;
3699}
3700
Hante Meuleman1a873342012-09-27 14:17:54 +02003701static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01003702brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
3703 struct cfg80211_beacon_data *beacon)
3704{
3705 s32 err;
3706
3707 /* Set Beacon IEs to FW */
3708 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
3709 beacon->tail, beacon->tail_len);
3710 if (err) {
3711 brcmf_err("Set Beacon IE Failed\n");
3712 return err;
3713 }
3714 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
3715
3716 /* Set Probe Response IEs to FW */
3717 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
3718 beacon->proberesp_ies,
3719 beacon->proberesp_ies_len);
3720 if (err)
3721 brcmf_err("Set Probe Resp IE Failed\n");
3722 else
3723 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
3724
3725 return err;
3726}
3727
3728static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02003729brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
3730 struct cfg80211_ap_settings *settings)
3731{
3732 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003733 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07003734 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01003735 const struct brcmf_tlv *ssid_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003736 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02003737 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01003738 const struct brcmf_tlv *rsn_ie;
3739 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003740 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01003741 enum nl80211_iftype dev_role;
3742 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02003743 u16 chanspec;
Hante Meuleman1a873342012-09-27 14:17:54 +02003744
Arend van Spriel06c01582014-05-12 10:47:37 +02003745 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3746 settings->chandef.chan->hw_value,
3747 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02003748 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01003749 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3750 settings->ssid, settings->ssid_len, settings->auth_type,
3751 settings->inactivity_timeout);
Hante Meuleman1a873342012-09-27 14:17:54 +02003752
Hante Meuleman426d0a52013-02-08 15:53:53 +01003753 dev_role = ifp->vif->wdev.iftype;
Hante Meuleman1a873342012-09-27 14:17:54 +02003754
3755 memset(&ssid_le, 0, sizeof(ssid_le));
3756 if (settings->ssid == NULL || settings->ssid_len == 0) {
3757 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
3758 ssid_ie = brcmf_parse_tlvs(
3759 (u8 *)&settings->beacon.head[ie_offset],
3760 settings->beacon.head_len - ie_offset,
3761 WLAN_EID_SSID);
3762 if (!ssid_ie)
3763 return -EINVAL;
3764
3765 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
3766 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01003767 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02003768 } else {
3769 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
3770 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
3771 }
3772
Arend van Sprielf96aa072013-04-05 10:57:48 +02003773 brcmf_set_mpc(ifp, 0);
Hante Meulemanb3657452013-05-27 21:09:53 +02003774 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02003775
3776 /* find the RSN_IE */
3777 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
3778 settings->beacon.tail_len, WLAN_EID_RSN);
3779
3780 /* find the WPA_IE */
3781 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
3782 settings->beacon.tail_len);
3783
Hante Meuleman1a873342012-09-27 14:17:54 +02003784 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003785 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003786 if (wpa_ie != NULL) {
3787 /* WPA IE */
Arend van Spriel34778522012-11-05 16:22:19 -08003788 err = brcmf_configure_wpaie(ndev, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02003789 if (err < 0)
3790 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003791 } else {
3792 /* RSN IE */
3793 err = brcmf_configure_wpaie(ndev,
Arend van Spriel34778522012-11-05 16:22:19 -08003794 (struct brcmf_vs_tlv *)rsn_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02003795 if (err < 0)
3796 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003797 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003798 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01003799 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01003800 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02003801 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003802
Hante Meulemana0f07952013-02-08 15:53:47 +01003803 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02003804
Arend van Spriel600a8972014-05-12 10:47:39 +02003805 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef);
Arend van Spriel06c01582014-05-12 10:47:37 +02003806 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003807 if (err < 0) {
Arend van Spriel06c01582014-05-12 10:47:37 +02003808 brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec, err);
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003809 goto exit;
3810 }
3811
Hante Meuleman1a873342012-09-27 14:17:54 +02003812 if (settings->beacon_interval) {
Arend van Sprielac24be62012-10-22 10:36:23 -07003813 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003814 settings->beacon_interval);
Hante Meuleman1a873342012-09-27 14:17:54 +02003815 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003816 brcmf_err("Beacon Interval Set Error, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003817 goto exit;
3818 }
3819 }
3820 if (settings->dtim_period) {
Arend van Sprielac24be62012-10-22 10:36:23 -07003821 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003822 settings->dtim_period);
Hante Meuleman1a873342012-09-27 14:17:54 +02003823 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003824 brcmf_err("DTIM Interval Set Error, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003825 goto exit;
3826 }
3827 }
Hante Meulemana0f07952013-02-08 15:53:47 +01003828
3829 if (dev_role == NL80211_IFTYPE_AP) {
3830 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
3831 if (err < 0) {
3832 brcmf_err("BRCMF_C_DOWN error %d\n", err);
3833 goto exit;
3834 }
Hante Meuleman2880b862013-02-08 12:06:31 +01003835 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003836 }
3837
Hante Meulemana0f07952013-02-08 15:53:47 +01003838 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02003839 if (err < 0) {
Hante Meulemana0f07952013-02-08 15:53:47 +01003840 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003841 goto exit;
3842 }
Hante Meulemana0f07952013-02-08 15:53:47 +01003843 if (dev_role == NL80211_IFTYPE_AP) {
3844 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
3845 if (err < 0) {
3846 brcmf_err("setting AP mode failed %d\n", err);
3847 goto exit;
3848 }
3849 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
3850 if (err < 0) {
3851 brcmf_err("BRCMF_C_UP error (%d)\n", err);
3852 goto exit;
3853 }
3854
3855 memset(&join_params, 0, sizeof(join_params));
3856 /* join parameters starts with ssid */
3857 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
3858 /* create softap */
3859 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
3860 &join_params, sizeof(join_params));
3861 if (err < 0) {
3862 brcmf_err("SET SSID error (%d)\n", err);
3863 goto exit;
3864 }
3865 brcmf_dbg(TRACE, "AP mode configuration complete\n");
3866 } else {
3867 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
3868 sizeof(ssid_le));
3869 if (err < 0) {
3870 brcmf_err("setting ssid failed %d\n", err);
3871 goto exit;
3872 }
3873 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
3874 bss_enable.enable = cpu_to_le32(1);
3875 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
3876 sizeof(bss_enable));
3877 if (err < 0) {
3878 brcmf_err("bss_enable config failed %d\n", err);
3879 goto exit;
3880 }
3881
3882 brcmf_dbg(TRACE, "GO mode configuration complete\n");
3883 }
Arend van Sprielc1179032012-10-22 13:55:33 -07003884 clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
3885 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman1a873342012-09-27 14:17:54 +02003886
3887exit:
Hante Meulemanb3657452013-05-27 21:09:53 +02003888 if (err) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02003889 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02003890 brcmf_configure_arp_offload(ifp, true);
3891 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003892 return err;
3893}
3894
3895static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
3896{
Arend van Sprielc1179032012-10-22 13:55:33 -07003897 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02003898 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01003899 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02003900 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02003901
Arend van Sprield96b8012012-12-05 15:26:02 +01003902 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003903
Hante Meuleman426d0a52013-02-08 15:53:53 +01003904 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02003905 /* Due to most likely deauths outstanding we sleep */
3906 /* first to make sure they get processed by fw. */
3907 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02003908
3909 memset(&join_params, 0, sizeof(join_params));
3910 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
3911 &join_params, sizeof(join_params));
3912 if (err < 0)
3913 brcmf_err("SET SSID error (%d)\n", err);
Arend van Spriel128ce3b2012-11-28 21:44:12 +01003914 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
Hante Meuleman5c33a942013-04-02 21:06:18 +02003915 if (err < 0)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003916 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02003917 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
3918 if (err < 0)
3919 brcmf_err("setting AP mode failed %d\n", err);
3920 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
3921 if (err < 0)
3922 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01003923 } else {
3924 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
3925 bss_enable.enable = cpu_to_le32(0);
3926 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
3927 sizeof(bss_enable));
3928 if (err < 0)
3929 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003930 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02003931 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02003932 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01003933 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
3934 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
3935
Hante Meuleman1a873342012-09-27 14:17:54 +02003936 return err;
3937}
3938
Hante Meulemana0f07952013-02-08 15:53:47 +01003939static s32
3940brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
3941 struct cfg80211_beacon_data *info)
3942{
Hante Meulemana0f07952013-02-08 15:53:47 +01003943 struct brcmf_if *ifp = netdev_priv(ndev);
3944 s32 err;
3945
3946 brcmf_dbg(TRACE, "Enter\n");
3947
Hante Meulemana0f07952013-02-08 15:53:47 +01003948 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
3949
3950 return err;
3951}
3952
Hante Meuleman1a873342012-09-27 14:17:54 +02003953static int
3954brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02003955 const u8 *mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02003956{
Hante Meulemana0f07952013-02-08 15:53:47 +01003957 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02003958 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003959 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02003960 s32 err;
3961
3962 if (!mac)
3963 return -EFAULT;
3964
Arend van Sprield96b8012012-12-05 15:26:02 +01003965 brcmf_dbg(TRACE, "Enter %pM\n", mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02003966
Hante Meulemana0f07952013-02-08 15:53:47 +01003967 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
3968 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07003969 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02003970 return -EIO;
3971
3972 memcpy(&scbval.ea, mac, ETH_ALEN);
3973 scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003974 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003975 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02003976 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003977 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01003978
Arend van Sprield96b8012012-12-05 15:26:02 +01003979 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003980 return err;
3981}
3982
Hante Meuleman0de8aac2013-02-08 15:53:38 +01003983
3984static void
3985brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
3986 struct wireless_dev *wdev,
3987 u16 frame_type, bool reg)
3988{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02003989 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01003990 u16 mgmt_type;
3991
3992 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
3993
3994 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02003995 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01003996 if (reg)
3997 vif->mgmt_rx_reg |= BIT(mgmt_type);
3998 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01003999 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004000}
4001
4002
4003static int
4004brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004005 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004006{
4007 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004008 struct ieee80211_channel *chan = params->chan;
4009 const u8 *buf = params->buf;
4010 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004011 const struct ieee80211_mgmt *mgmt;
4012 struct brcmf_cfg80211_vif *vif;
4013 s32 err = 0;
4014 s32 ie_offset;
4015 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004016 struct brcmf_fil_action_frame_le *action_frame;
4017 struct brcmf_fil_af_params_le *af_params;
4018 bool ack;
4019 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004020 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004021
4022 brcmf_dbg(TRACE, "Enter\n");
4023
4024 *cookie = 0;
4025
4026 mgmt = (const struct ieee80211_mgmt *)buf;
4027
Hante Meulemana0f07952013-02-08 15:53:47 +01004028 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4029 brcmf_err("Driver only allows MGMT packet type\n");
4030 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004031 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004032
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004033 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4034
Hante Meulemana0f07952013-02-08 15:53:47 +01004035 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4036 /* Right now the only reason to get a probe response */
4037 /* is for p2p listen response or for p2p GO from */
4038 /* wpa_supplicant. Unfortunately the probe is send */
4039 /* on primary ndev, while dongle wants it on the p2p */
4040 /* vif. Since this is only reason for a probe */
4041 /* response to be sent, the vif is taken from cfg. */
4042 /* If ever desired to send proberesp for non p2p */
4043 /* response then data should be checked for */
4044 /* "DIRECT-". Note in future supplicant will take */
4045 /* dedicated p2p wdev to do this and then this 'hack'*/
4046 /* is not needed anymore. */
4047 ie_offset = DOT11_MGMT_HDR_LEN +
4048 DOT11_BCN_PRB_FIXED_LEN;
4049 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004050 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4051 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4052 err = brcmf_vif_set_mgmt_ie(vif,
4053 BRCMF_VNDR_IE_PRBRSP_FLAG,
4054 &buf[ie_offset],
4055 ie_len);
4056 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4057 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004058 } else if (ieee80211_is_action(mgmt->frame_control)) {
4059 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4060 if (af_params == NULL) {
4061 brcmf_err("unable to allocate frame\n");
4062 err = -ENOMEM;
4063 goto exit;
4064 }
4065 action_frame = &af_params->action_frame;
4066 /* Add the packet Id */
4067 action_frame->packet_id = cpu_to_le32(*cookie);
4068 /* Add BSSID */
4069 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4070 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4071 /* Add the length exepted for 802.11 header */
4072 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004073 /* Add the channel. Use the one specified as parameter if any or
4074 * the current one (got from the firmware) otherwise
4075 */
4076 if (chan)
4077 freq = chan->center_freq;
4078 else
4079 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4080 &freq);
4081 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004082 af_params->channel = cpu_to_le32(chan_nr);
4083
4084 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4085 le16_to_cpu(action_frame->len));
4086
4087 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004088 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004089
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004090 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004091 af_params);
4092
4093 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4094 GFP_KERNEL);
4095 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004096 } else {
4097 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4098 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4099 }
4100
Hante Meuleman18e2f612013-02-08 15:53:49 +01004101exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004102 return err;
4103}
4104
4105
4106static int
4107brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4108 struct wireless_dev *wdev,
4109 u64 cookie)
4110{
4111 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4112 struct brcmf_cfg80211_vif *vif;
4113 int err = 0;
4114
4115 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4116
4117 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4118 if (vif == NULL) {
4119 brcmf_err("No p2p device available for probe response\n");
4120 err = -ENODEV;
4121 goto exit;
4122 }
4123 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4124exit:
4125 return err;
4126}
4127
Piotr Haber61730d42013-04-23 12:53:12 +02004128static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4129 struct wireless_dev *wdev,
4130 enum nl80211_crit_proto_id proto,
4131 u16 duration)
4132{
4133 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4134 struct brcmf_cfg80211_vif *vif;
4135
4136 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4137
4138 /* only DHCP support for now */
4139 if (proto != NL80211_CRIT_PROTO_DHCP)
4140 return -EINVAL;
4141
4142 /* suppress and abort scanning */
4143 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4144 brcmf_abort_scanning(cfg);
4145
4146 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4147}
4148
4149static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4150 struct wireless_dev *wdev)
4151{
4152 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4153 struct brcmf_cfg80211_vif *vif;
4154
4155 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4156
4157 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4158 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4159}
4160
Hante Meuleman70b7d942014-07-30 13:20:07 +02004161static s32
4162brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4163 const struct brcmf_event_msg *e, void *data)
4164{
4165 switch (e->reason) {
4166 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4167 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4168 break;
4169 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4170 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4171 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4172 break;
4173 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4174 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4175 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4176 break;
4177 }
4178
4179 return 0;
4180}
4181
Arend van Spriel89c2f382013-08-10 12:27:25 +02004182static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4183{
4184 int ret;
4185
4186 switch (oper) {
4187 case NL80211_TDLS_DISCOVERY_REQ:
4188 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4189 break;
4190 case NL80211_TDLS_SETUP:
4191 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4192 break;
4193 case NL80211_TDLS_TEARDOWN:
4194 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4195 break;
4196 default:
4197 brcmf_err("unsupported operation: %d\n", oper);
4198 ret = -EOPNOTSUPP;
4199 }
4200 return ret;
4201}
4202
4203static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004204 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004205 enum nl80211_tdls_operation oper)
4206{
4207 struct brcmf_if *ifp;
4208 struct brcmf_tdls_iovar_le info;
4209 int ret = 0;
4210
4211 ret = brcmf_convert_nl80211_tdls_oper(oper);
4212 if (ret < 0)
4213 return ret;
4214
4215 ifp = netdev_priv(ndev);
4216 memset(&info, 0, sizeof(info));
4217 info.mode = (u8)ret;
4218 if (peer)
4219 memcpy(info.ea, peer, ETH_ALEN);
4220
4221 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4222 &info, sizeof(info));
4223 if (ret < 0)
4224 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4225
4226 return ret;
4227}
4228
Arend van Spriel5b435de2011-10-05 13:19:03 +02004229static struct cfg80211_ops wl_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01004230 .add_virtual_intf = brcmf_cfg80211_add_iface,
4231 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004232 .change_virtual_intf = brcmf_cfg80211_change_iface,
4233 .scan = brcmf_cfg80211_scan,
4234 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4235 .join_ibss = brcmf_cfg80211_join_ibss,
4236 .leave_ibss = brcmf_cfg80211_leave_ibss,
4237 .get_station = brcmf_cfg80211_get_station,
4238 .set_tx_power = brcmf_cfg80211_set_tx_power,
4239 .get_tx_power = brcmf_cfg80211_get_tx_power,
4240 .add_key = brcmf_cfg80211_add_key,
4241 .del_key = brcmf_cfg80211_del_key,
4242 .get_key = brcmf_cfg80211_get_key,
4243 .set_default_key = brcmf_cfg80211_config_default_key,
4244 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4245 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004246 .connect = brcmf_cfg80211_connect,
4247 .disconnect = brcmf_cfg80211_disconnect,
4248 .suspend = brcmf_cfg80211_suspend,
4249 .resume = brcmf_cfg80211_resume,
4250 .set_pmksa = brcmf_cfg80211_set_pmksa,
4251 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02004252 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02004253 .start_ap = brcmf_cfg80211_start_ap,
4254 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01004255 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02004256 .del_station = brcmf_cfg80211_del_station,
Arend van Spriele5806072012-09-19 22:21:08 +02004257 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4258 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004259 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4260 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4261 .remain_on_channel = brcmf_p2p_remain_on_channel,
4262 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02004263 .start_p2p_device = brcmf_p2p_start_device,
4264 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02004265 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4266 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004267 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004268};
4269
Arend van Spriel3eacf862012-10-22 13:55:30 -07004270struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01004271 enum nl80211_iftype type,
4272 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004273{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004274 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004275
Arend van Spriel33a6b152013-02-08 15:53:39 +01004276 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01004277 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07004278 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4279 if (!vif)
4280 return ERR_PTR(-ENOMEM);
4281
4282 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01004283 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004284
Arend van Spriel3eacf862012-10-22 13:55:30 -07004285 vif->pm_block = pm_block;
4286 vif->roam_off = -1;
4287
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004288 brcmf_init_prof(&vif->profile);
4289
Arend van Spriel3eacf862012-10-22 13:55:30 -07004290 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004291 return vif;
4292}
4293
Arend van Spriel427dec52014-01-06 12:40:47 +01004294void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07004295{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004296 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004297 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004298}
4299
Arend van Spriel9df4d542014-01-06 12:40:49 +01004300void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4301{
4302 struct brcmf_cfg80211_vif *vif;
4303 struct brcmf_if *ifp;
4304
4305 ifp = netdev_priv(ndev);
4306 vif = ifp->vif;
4307
4308 brcmf_free_vif(vif);
4309 free_netdev(ndev);
4310}
4311
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004312static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004313{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004314 u32 event = e->event_code;
4315 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004316
4317 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004318 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004319 return true;
4320 }
4321
4322 return false;
4323}
4324
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004325static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004326{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004327 u32 event = e->event_code;
4328 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004329
Hante Meuleman68ca3952014-02-25 20:30:26 +01004330 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4331 (event == BRCMF_E_DISASSOC_IND) ||
4332 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01004333 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004334 return true;
4335 }
4336 return false;
4337}
4338
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004339static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004340 const struct brcmf_event_msg *e)
4341{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004342 u32 event = e->event_code;
4343 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004344
4345 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004346 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
4347 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004348 return true;
4349 }
4350
4351 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004352 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004353 return true;
4354 }
4355
4356 return false;
4357}
4358
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004359static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004360{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004361 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004362
4363 kfree(conn_info->req_ie);
4364 conn_info->req_ie = NULL;
4365 conn_info->req_ie_len = 0;
4366 kfree(conn_info->resp_ie);
4367 conn_info->resp_ie = NULL;
4368 conn_info->resp_ie_len = 0;
4369}
4370
Hante Meuleman89286dc2013-02-08 15:53:46 +01004371static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
4372 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004373{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004374 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004375 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004376 u32 req_len;
4377 u32 resp_len;
4378 s32 err = 0;
4379
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004380 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004381
Arend van Sprielac24be62012-10-22 10:36:23 -07004382 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
4383 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004384 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004385 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004386 return err;
4387 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004388 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004389 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004390 req_len = le32_to_cpu(assoc_info->req_len);
4391 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004392 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004393 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004394 cfg->extra_buf,
4395 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004396 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004397 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004398 return err;
4399 }
4400 conn_info->req_ie_len = req_len;
4401 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004402 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004403 GFP_KERNEL);
4404 } else {
4405 conn_info->req_ie_len = 0;
4406 conn_info->req_ie = NULL;
4407 }
4408 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004409 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004410 cfg->extra_buf,
4411 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004412 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004413 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004414 return err;
4415 }
4416 conn_info->resp_ie_len = resp_len;
4417 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004418 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004419 GFP_KERNEL);
4420 } else {
4421 conn_info->resp_ie_len = 0;
4422 conn_info->resp_ie = NULL;
4423 }
Arend van Spriel16886732012-12-05 15:26:04 +01004424 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
4425 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004426
4427 return err;
4428}
4429
4430static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004431brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004432 struct net_device *ndev,
4433 const struct brcmf_event_msg *e)
4434{
Arend van Sprielc1179032012-10-22 13:55:33 -07004435 struct brcmf_if *ifp = netdev_priv(ndev);
4436 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004437 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4438 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07004439 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004440 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07004441 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02004442 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004443 u32 freq;
4444 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07004445 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004446
Arend van Sprield96b8012012-12-05 15:26:02 +01004447 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004448
Hante Meuleman89286dc2013-02-08 15:53:46 +01004449 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004450 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004451 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004452
Franky Lina180b832012-10-10 11:13:09 -07004453 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
4454 if (buf == NULL) {
4455 err = -ENOMEM;
4456 goto done;
4457 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02004458
Franky Lina180b832012-10-10 11:13:09 -07004459 /* data sent to dongle has to be little endian */
4460 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07004461 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07004462 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07004463
4464 if (err)
4465 goto done;
4466
4467 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02004468 ch.chspec = le16_to_cpu(bi->chanspec);
4469 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004470
Franky Lin83cf17a2013-04-11 13:28:50 +02004471 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004472 band = wiphy->bands[IEEE80211_BAND_2GHZ];
4473 else
4474 band = wiphy->bands[IEEE80211_BAND_5GHZ];
4475
Franky Lin83cf17a2013-04-11 13:28:50 +02004476 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004477 notify_channel = ieee80211_get_channel(wiphy, freq);
4478
Franky Lina180b832012-10-10 11:13:09 -07004479done:
4480 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02004481 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004482 conn_info->req_ie, conn_info->req_ie_len,
4483 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004484 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004485
Arend van Sprielc1179032012-10-22 13:55:33 -07004486 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01004487 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004488 return err;
4489}
4490
4491static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004492brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004493 struct net_device *ndev, const struct brcmf_event_msg *e,
4494 bool completed)
4495{
Arend van Sprielc1179032012-10-22 13:55:33 -07004496 struct brcmf_if *ifp = netdev_priv(ndev);
4497 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004498 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004499
Arend van Sprield96b8012012-12-05 15:26:02 +01004500 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004501
Arend van Sprielc1179032012-10-22 13:55:33 -07004502 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4503 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02004504 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01004505 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004506 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004507 brcmf_update_bss_info(cfg, ifp);
4508 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4509 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004510 }
4511 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02004512 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004513 conn_info->req_ie,
4514 conn_info->req_ie_len,
4515 conn_info->resp_ie,
4516 conn_info->resp_ie_len,
4517 completed ? WLAN_STATUS_SUCCESS :
4518 WLAN_STATUS_AUTH_TIMEOUT,
4519 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004520 brcmf_dbg(CONN, "Report connect result - connection %s\n",
4521 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004522 }
Arend van Sprield96b8012012-12-05 15:26:02 +01004523 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004524 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004525}
4526
4527static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004528brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02004529 struct net_device *ndev,
4530 const struct brcmf_event_msg *e, void *data)
4531{
Hante Meuleman7ee29602013-02-06 18:40:43 +01004532 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004533 u32 event = e->event_code;
4534 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02004535 struct station_info sinfo;
4536
Arend van Spriel16886732012-12-05 15:26:04 +01004537 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004538 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
4539 ndev != cfg_to_ndev(cfg)) {
4540 brcmf_dbg(CONN, "AP mode link down\n");
4541 complete(&cfg->vif_disabled);
4542 return 0;
4543 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004544
Hante Meuleman1a873342012-09-27 14:17:54 +02004545 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01004546 (reason == BRCMF_E_STATUS_SUCCESS)) {
4547 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02004548 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
4549 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004550 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02004551 return -EINVAL;
4552 }
4553 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01004554 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02004555 generation++;
4556 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01004557 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02004558 } else if ((event == BRCMF_E_DISASSOC_IND) ||
4559 (event == BRCMF_E_DEAUTH_IND) ||
4560 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01004561 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02004562 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01004563 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004564}
4565
4566static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004567brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004568 const struct brcmf_event_msg *e, void *data)
4569{
Arend van Spriel19937322012-11-05 16:22:32 -08004570 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4571 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07004572 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004573 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004574 s32 err = 0;
4575
Hante Meuleman8851cce2014-07-30 13:20:02 +02004576 if ((e->event_code == BRCMF_E_DEAUTH) ||
4577 (e->event_code == BRCMF_E_DEAUTH_IND) ||
4578 (e->event_code == BRCMF_E_DISASSOC_IND) ||
4579 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
4580 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4581 }
4582
Arend van Spriel967fe2c2014-03-15 17:18:21 +01004583 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004584 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004585 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01004586 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004587 if (brcmf_is_ibssmode(ifp->vif)) {
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004588 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004589 memcpy(profile->bssid, e->addr, ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004590 wl_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004591 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07004592 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4593 &ifp->vif->sme_state);
4594 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4595 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004596 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004597 brcmf_bss_connect_done(cfg, ndev, e, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004598 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01004599 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004600 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004601 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004602 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004603 brcmf_link_down(ifp->vif);
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004604 brcmf_init_prof(ndev_to_prof(ndev));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004605 if (ndev != cfg_to_ndev(cfg))
4606 complete(&cfg->vif_disabled);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004607 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004608 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07004609 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4610 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004611 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004612 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004613 }
4614
4615 return err;
4616}
4617
4618static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004619brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004620 const struct brcmf_event_msg *e, void *data)
4621{
Arend van Spriel19937322012-11-05 16:22:32 -08004622 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004623 u32 event = e->event_code;
4624 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004625
4626 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004627 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08004628 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004629 else
Arend van Spriel19937322012-11-05 16:22:32 -08004630 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004631 }
4632
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004633 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004634}
4635
4636static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004637brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004638 const struct brcmf_event_msg *e, void *data)
4639{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004640 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004641 enum nl80211_key_type key_type;
4642
4643 if (flags & BRCMF_EVENT_MSG_GROUP)
4644 key_type = NL80211_KEYTYPE_GROUP;
4645 else
4646 key_type = NL80211_KEYTYPE_PAIRWISE;
4647
Arend van Spriel19937322012-11-05 16:22:32 -08004648 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004649 NULL, GFP_KERNEL);
4650
4651 return 0;
4652}
4653
Arend van Sprield3c0b632013-02-08 15:53:37 +01004654static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
4655 const struct brcmf_event_msg *e, void *data)
4656{
4657 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4658 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
4659 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
4660 struct brcmf_cfg80211_vif *vif;
4661
4662 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4663 ifevent->action, ifevent->flags, ifevent->ifidx,
4664 ifevent->bssidx);
4665
Arend van Sprield3c0b632013-02-08 15:53:37 +01004666 mutex_lock(&event->vif_event_lock);
4667 event->action = ifevent->action;
4668 vif = event->vif;
4669
4670 switch (ifevent->action) {
4671 case BRCMF_E_IF_ADD:
4672 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08004673 if (!cfg->vif_event.vif) {
4674 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004675 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08004676 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01004677
4678 ifp->vif = vif;
4679 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02004680 if (ifp->ndev) {
4681 vif->wdev.netdev = ifp->ndev;
4682 ifp->ndev->ieee80211_ptr = &vif->wdev;
4683 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
4684 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01004685 mutex_unlock(&event->vif_event_lock);
4686 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01004687 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01004688
4689 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01004690 mutex_unlock(&event->vif_event_lock);
4691 /* event may not be upon user request */
4692 if (brcmf_cfg80211_vif_event_armed(cfg))
4693 wake_up(&event->vif_wq);
4694 return 0;
4695
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01004696 case BRCMF_E_IF_CHANGE:
4697 mutex_unlock(&event->vif_event_lock);
4698 wake_up(&event->vif_wq);
4699 return 0;
4700
Arend van Sprield3c0b632013-02-08 15:53:37 +01004701 default:
4702 mutex_unlock(&event->vif_event_lock);
4703 break;
4704 }
4705 return -EINVAL;
4706}
4707
Arend van Spriel5b435de2011-10-05 13:19:03 +02004708static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
4709{
Arend van Spriel5b435de2011-10-05 13:19:03 +02004710 conf->frag_threshold = (u32)-1;
4711 conf->rts_threshold = (u32)-1;
4712 conf->retry_short = (u32)-1;
4713 conf->retry_long = (u32)-1;
4714 conf->tx_power = -1;
4715}
4716
Arend van Spriel5c36b992012-11-14 18:46:05 -08004717static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004718{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004719 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
4720 brcmf_notify_connect_status);
4721 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
4722 brcmf_notify_connect_status);
4723 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
4724 brcmf_notify_connect_status);
4725 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
4726 brcmf_notify_connect_status);
4727 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
4728 brcmf_notify_connect_status);
4729 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
4730 brcmf_notify_connect_status);
4731 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
4732 brcmf_notify_roaming_status);
4733 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
4734 brcmf_notify_mic_status);
4735 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
4736 brcmf_notify_connect_status);
4737 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
4738 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004739 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
4740 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004741 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01004742 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004743 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
4744 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01004745 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
4746 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004747 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
4748 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01004749 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
4750 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004751}
4752
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004753static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004754{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004755 kfree(cfg->conf);
4756 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004757 kfree(cfg->escan_ioctl_buf);
4758 cfg->escan_ioctl_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004759 kfree(cfg->extra_buf);
4760 cfg->extra_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004761 kfree(cfg->pmk_list);
4762 cfg->pmk_list = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004763}
4764
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004765static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004766{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004767 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
4768 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004769 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004770 cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
4771 if (!cfg->escan_ioctl_buf)
Hante Meulemane756af52012-09-11 21:18:52 +02004772 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004773 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4774 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004775 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004776 cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL);
4777 if (!cfg->pmk_list)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004778 goto init_priv_mem_out;
4779
4780 return 0;
4781
4782init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004783 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004784
4785 return -ENOMEM;
4786}
4787
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004788static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004789{
4790 s32 err = 0;
4791
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004792 cfg->scan_request = NULL;
4793 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01004794 cfg->active_scan = true; /* we do active scan per default */
4795 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004796 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004797 if (err)
4798 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004799 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004800 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004801 brcmf_init_escan(cfg);
4802 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004803 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004804 return err;
4805}
4806
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004807static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004808{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004809 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004810 brcmf_abort_scanning(cfg);
4811 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004812}
4813
Arend van Sprield3c0b632013-02-08 15:53:37 +01004814static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
4815{
4816 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004817 mutex_init(&event->vif_event_lock);
4818}
4819
Arend van Spriel5b435de2011-10-05 13:19:03 +02004820static s32
Hante Meuleman68ca3952014-02-25 20:30:26 +01004821brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004822{
Arend van Spriel5b435de2011-10-05 13:19:03 +02004823 s32 err = 0;
Arend van Sprielf588bc02011-10-12 20:51:22 +02004824 __le32 roamtrigger[2];
4825 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02004826
4827 /*
4828 * Setup timeout if Beacons are lost and roam is
4829 * off to report link down
4830 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01004831 if (brcmf_roamoff) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004832 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004833 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004834 brcmf_err("bcn_timeout error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004835 goto dongle_rom_out;
4836 }
4837 }
4838
4839 /*
4840 * Enable/Disable built-in roaming to allow supplicant
4841 * to take care of roaming
4842 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01004843 brcmf_dbg(INFO, "Internal Roaming = %s\n",
4844 brcmf_roamoff ? "Off" : "On");
4845 err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff));
Arend van Spriel5b435de2011-10-05 13:19:03 +02004846 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004847 brcmf_err("roam_off error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004848 goto dongle_rom_out;
4849 }
4850
Arend van Sprielf588bc02011-10-12 20:51:22 +02004851 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
4852 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07004853 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004854 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02004855 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004856 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004857 goto dongle_rom_out;
4858 }
4859
Arend van Sprielf588bc02011-10-12 20:51:22 +02004860 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
4861 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07004862 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004863 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02004864 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004865 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004866 goto dongle_rom_out;
4867 }
4868
4869dongle_rom_out:
4870 return err;
4871}
4872
4873static s32
Hante Meuleman40a23292013-01-02 15:22:51 +01004874brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time,
Arend van Sprielc68cdc02011-10-12 20:51:23 +02004875 s32 scan_unassoc_time, s32 scan_passive_time)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004876{
4877 s32 err = 0;
4878
Arend van Sprielac24be62012-10-22 10:36:23 -07004879 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004880 scan_assoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004881 if (err) {
4882 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01004883 brcmf_dbg(INFO, "Scan assoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004884 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01004885 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004886 goto dongle_scantime_out;
4887 }
Arend van Sprielac24be62012-10-22 10:36:23 -07004888 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004889 scan_unassoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004890 if (err) {
4891 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01004892 brcmf_dbg(INFO, "Scan unassoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004893 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01004894 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004895 goto dongle_scantime_out;
4896 }
4897
Arend van Sprielac24be62012-10-22 10:36:23 -07004898 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004899 scan_passive_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004900 if (err) {
4901 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01004902 brcmf_dbg(INFO, "Scan passive time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004903 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01004904 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004905 goto dongle_scantime_out;
4906 }
4907
4908dongle_scantime_out:
4909 return err;
4910}
4911
Arend van Sprielb48d8912014-07-12 08:49:41 +02004912/* Filter the list of channels received from firmware counting only
4913 * the 20MHz channels. The wiphy band data only needs those which get
4914 * flagged to indicate if they can take part in higher bandwidth.
4915 */
4916static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
4917 struct brcmf_chanspec_list *chlist,
4918 u32 chcnt[])
4919{
4920 u32 total = le32_to_cpu(chlist->count);
4921 struct brcmu_chan ch;
4922 int i;
Hante Meulemand48200b2013-04-03 12:40:29 +02004923
Arend van Sprielb48d8912014-07-12 08:49:41 +02004924 for (i = 0; i <= total; i++) {
4925 ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
4926 cfg->d11inf.decchspec(&ch);
4927
4928 /* Firmware gives a ordered list. We skip non-20MHz
4929 * channels is 2G. For 5G we can abort upon reaching
4930 * a non-20MHz channel in the list.
4931 */
4932 if (ch.bw != BRCMU_CHAN_BW_20) {
4933 if (ch.band == BRCMU_CHAN_BAND_5G)
4934 break;
4935 else
4936 continue;
4937 }
4938
4939 if (ch.band == BRCMU_CHAN_BAND_2G)
4940 chcnt[0] += 1;
4941 else if (ch.band == BRCMU_CHAN_BAND_5G)
4942 chcnt[1] += 1;
4943 }
4944}
4945
4946static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
4947 struct brcmu_chan *ch)
4948{
4949 u32 ht40_flag;
4950
4951 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
4952 if (ch->sb == BRCMU_CHAN_SB_U) {
4953 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
4954 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
4955 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
4956 } else {
4957 /* It should be one of
4958 * IEEE80211_CHAN_NO_HT40 or
4959 * IEEE80211_CHAN_NO_HT40PLUS
4960 */
4961 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
4962 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
4963 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
4964 }
4965}
4966
4967static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
4968 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02004969{
4970 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02004971 struct ieee80211_supported_band *band;
4972 struct ieee80211_channel *channel;
4973 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02004974 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02004975 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02004976 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02004977 u8 *pbuf;
4978 u32 i, j;
4979 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02004980 u32 chaninfo;
4981 u32 chcnt[2] = { 0, 0 };
Hante Meulemand48200b2013-04-03 12:40:29 +02004982 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02004983
4984 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
4985
4986 if (pbuf == NULL)
4987 return -ENOMEM;
4988
4989 list = (struct brcmf_chanspec_list *)pbuf;
4990
4991 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
4992 BRCMF_DCMD_MEDLEN);
4993 if (err) {
4994 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02004995 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02004996 }
4997
Arend van Sprielb48d8912014-07-12 08:49:41 +02004998 brcmf_count_20mhz_channels(cfg, list, chcnt);
4999 wiphy = cfg_to_wiphy(cfg);
5000 if (chcnt[0]) {
5001 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
5002 GFP_KERNEL);
5003 if (band == NULL) {
5004 err = -ENOMEM;
5005 goto fail_pbuf;
5006 }
5007 band->channels = kcalloc(chcnt[0], sizeof(*channel),
5008 GFP_KERNEL);
5009 if (band->channels == NULL) {
5010 kfree(band);
5011 err = -ENOMEM;
5012 goto fail_pbuf;
5013 }
5014 band->n_channels = 0;
5015 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5016 }
5017 if (chcnt[1]) {
5018 band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a),
5019 GFP_KERNEL);
5020 if (band == NULL) {
5021 err = -ENOMEM;
5022 goto fail_band2g;
5023 }
5024 band->channels = kcalloc(chcnt[1], sizeof(*channel),
5025 GFP_KERNEL);
5026 if (band->channels == NULL) {
5027 kfree(band);
5028 err = -ENOMEM;
5029 goto fail_band2g;
5030 }
5031 band->n_channels = 0;
5032 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5033 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005034
5035 total = le32_to_cpu(list->count);
5036 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005037 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5038 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005039
Franky Lin83cf17a2013-04-11 13:28:50 +02005040 if (ch.band == BRCMU_CHAN_BAND_2G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005041 band = wiphy->bands[IEEE80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005042 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005043 band = wiphy->bands[IEEE80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005044 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005045 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005046 continue;
5047 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005048 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005049 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005050 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005051 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005052 ch.bw == BRCMU_CHAN_BW_80)
5053 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005054
5055 channel = band->channels;
5056 index = band->n_channels;
5057 for (j = 0; j < band->n_channels; j++) {
5058 if (channel[j].hw_value == ch.chnum) {
5059 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005060 break;
5061 }
5062 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005063 channel[index].center_freq =
5064 ieee80211_channel_to_frequency(ch.chnum, band->band);
5065 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005066
Arend van Sprielb48d8912014-07-12 08:49:41 +02005067 /* assuming the chanspecs order is HT20,
5068 * HT40 upper, HT40 lower, and VHT80.
5069 */
5070 if (ch.bw == BRCMU_CHAN_BW_80) {
5071 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5072 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5073 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5074 } else {
5075 /* disable other bandwidths for now as mentioned
5076 * order assure they are enabled for subsequent
5077 * chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005078 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005079 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5080 IEEE80211_CHAN_NO_80MHZ;
5081 ch.bw = BRCMU_CHAN_BW_20;
5082 cfg->d11inf.encchspec(&ch);
5083 chaninfo = ch.chspec;
5084 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5085 &chaninfo);
5086 if (!err) {
5087 if (chaninfo & WL_CHAN_RADAR)
5088 channel[index].flags |=
5089 (IEEE80211_CHAN_RADAR |
5090 IEEE80211_CHAN_NO_IR);
5091 if (chaninfo & WL_CHAN_PASSIVE)
5092 channel[index].flags |=
5093 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005094 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005095 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005096 if (index == band->n_channels)
5097 band->n_channels++;
Hante Meulemand48200b2013-04-03 12:40:29 +02005098 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005099 kfree(pbuf);
5100 return 0;
5101
5102fail_band2g:
5103 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5104 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5105 wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
5106fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005107 kfree(pbuf);
5108 return err;
5109}
5110
Arend van Sprielb48d8912014-07-12 08:49:41 +02005111static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005112{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005113 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5114 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005115 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005116 struct brcmf_chanspec_list *list;
5117 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005118 u32 val;
5119 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005120 struct brcmu_chan ch;
5121 u32 num_chan;
5122 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005123
5124 /* verify support for bw_cap command */
5125 val = WLC_BAND_5G;
5126 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5127
5128 if (!err) {
5129 /* only set 2G bandwidth using bw_cap command */
5130 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5131 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5132 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5133 sizeof(band_bwcap));
5134 } else {
5135 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5136 val = WLC_N_BW_40ALL;
5137 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5138 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005139
5140 if (!err) {
5141 /* update channel info in 2G band */
5142 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5143
5144 if (pbuf == NULL)
5145 return -ENOMEM;
5146
5147 ch.band = BRCMU_CHAN_BAND_2G;
5148 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005149 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005150 ch.chnum = 0;
5151 cfg->d11inf.encchspec(&ch);
5152
5153 /* pass encoded chanspec in query */
5154 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5155
5156 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5157 BRCMF_DCMD_MEDLEN);
5158 if (err) {
5159 brcmf_err("get chanspecs error (%d)\n", err);
5160 kfree(pbuf);
5161 return err;
5162 }
5163
5164 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5165 list = (struct brcmf_chanspec_list *)pbuf;
5166 num_chan = le32_to_cpu(list->count);
5167 for (i = 0; i < num_chan; i++) {
5168 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5169 cfg->d11inf.decchspec(&ch);
5170 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5171 continue;
5172 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5173 continue;
5174 for (j = 0; j < band->n_channels; j++) {
5175 if (band->channels[j].hw_value == ch.chnum)
5176 break;
5177 }
5178 if (WARN_ON(j == band->n_channels))
5179 continue;
5180
5181 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5182 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005183 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005184 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005185 return err;
5186}
5187
Arend van Spriel2375d972014-01-06 12:40:41 +01005188static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5189{
5190 u32 band, mimo_bwcap;
5191 int err;
5192
5193 band = WLC_BAND_2G;
5194 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5195 if (!err) {
5196 bw_cap[IEEE80211_BAND_2GHZ] = band;
5197 band = WLC_BAND_5G;
5198 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5199 if (!err) {
5200 bw_cap[IEEE80211_BAND_5GHZ] = band;
5201 return;
5202 }
5203 WARN_ON(1);
5204 return;
5205 }
5206 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5207 mimo_bwcap = 0;
5208 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5209 if (err)
5210 /* assume 20MHz if firmware does not give a clue */
5211 mimo_bwcap = WLC_N_BW_20ALL;
5212
5213 switch (mimo_bwcap) {
5214 case WLC_N_BW_40ALL:
5215 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5216 /* fall-thru */
5217 case WLC_N_BW_20IN2G_40IN5G:
5218 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5219 /* fall-thru */
5220 case WLC_N_BW_20ALL:
5221 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5222 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5223 break;
5224 default:
5225 brcmf_err("invalid mimo_bw_cap value\n");
5226 }
5227}
Hante Meulemand48200b2013-04-03 12:40:29 +02005228
Arend van Spriel18d6c532014-05-12 10:47:35 +02005229static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5230 u32 bw_cap[2], u32 nchain)
5231{
5232 band->ht_cap.ht_supported = true;
5233 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5234 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5235 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5236 }
5237 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5238 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5239 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5240 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5241 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5242 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5243}
5244
5245static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5246{
5247 u16 mcs_map;
5248 int i;
5249
5250 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5251 mcs_map = (mcs_map << 2) | supp;
5252
5253 return cpu_to_le16(mcs_map);
5254}
5255
5256static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
5257 u32 bw_cap[2], u32 nchain)
5258{
5259 __le16 mcs_map;
5260
5261 /* not allowed in 2.4G band */
5262 if (band->band == IEEE80211_BAND_2GHZ)
5263 return;
5264
5265 band->vht_cap.vht_supported = true;
5266 /* 80MHz is mandatory */
5267 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5268 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5269 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5270 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5271 }
5272 /* all support 256-QAM */
5273 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5274 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5275 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
5276}
5277
Arend van Sprielb48d8912014-07-12 08:49:41 +02005278static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005279{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005280 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07005281 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02005282 u32 nmode = 0;
5283 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005284 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01005285 u32 rxchain;
5286 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005287 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005288 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01005289 struct ieee80211_supported_band *band;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005290
Arend van Spriel18d6c532014-05-12 10:47:35 +02005291 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02005292 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5293 if (err) {
5294 brcmf_err("nmode error (%d)\n", err);
5295 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005296 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005297 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005298 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5299 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5300 bw_cap[IEEE80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02005301
Daniel Kim4aca7a12014-02-25 20:30:36 +01005302 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5303 if (err) {
5304 brcmf_err("rxchain error (%d)\n", err);
5305 nchain = 1;
5306 } else {
5307 for (nchain = 0; rxchain; nchain++)
5308 rxchain = rxchain & (rxchain - 1);
5309 }
5310 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5311
Arend van Sprielb48d8912014-07-12 08:49:41 +02005312 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005313 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005314 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02005315 return err;
5316 }
5317
Arend van Sprielb48d8912014-07-12 08:49:41 +02005318 wiphy = cfg_to_wiphy(cfg);
5319 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5320 band = wiphy->bands[i];
5321 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01005322 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02005323
Arend van Spriel18d6c532014-05-12 10:47:35 +02005324 if (nmode)
5325 brcmf_update_ht_cap(band, bw_cap, nchain);
5326 if (vhtmode)
5327 brcmf_update_vht_cap(band, bw_cap, nchain);
Hante Meulemand48200b2013-04-03 12:40:29 +02005328 }
5329
Arend van Sprielb48d8912014-07-12 08:49:41 +02005330 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005331}
5332
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005333static const struct ieee80211_iface_limit brcmf_iface_limits[] = {
5334 {
5335 .max = 2,
5336 .types = BIT(NL80211_IFTYPE_STATION) |
5337 BIT(NL80211_IFTYPE_ADHOC) |
5338 BIT(NL80211_IFTYPE_AP)
5339 },
5340 {
5341 .max = 1,
5342 .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
5343 BIT(NL80211_IFTYPE_P2P_GO)
5344 },
5345 {
5346 .max = 1,
5347 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5348 }
5349};
5350static struct ieee80211_iface_combination brcmf_iface_combos[] = {
5351 {
5352 .max_interfaces = BRCMF_IFACE_MAX_CNT,
5353 .num_different_channels = 1,
5354 .n_limits = ARRAY_SIZE(brcmf_iface_limits),
5355 .limits = brcmf_iface_limits
5356 }
5357};
5358
5359static const struct ieee80211_txrx_stypes
5360brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5361 [NL80211_IFTYPE_STATION] = {
5362 .tx = 0xffff,
5363 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5364 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5365 },
5366 [NL80211_IFTYPE_P2P_CLIENT] = {
5367 .tx = 0xffff,
5368 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5369 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5370 },
5371 [NL80211_IFTYPE_P2P_GO] = {
5372 .tx = 0xffff,
5373 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5374 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5375 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5376 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5377 BIT(IEEE80211_STYPE_AUTH >> 4) |
5378 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5379 BIT(IEEE80211_STYPE_ACTION >> 4)
5380 },
5381 [NL80211_IFTYPE_P2P_DEVICE] = {
5382 .tx = 0xffff,
5383 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5384 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5385 }
5386};
5387
5388static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
5389{
5390 /* scheduled scan settings */
5391 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
5392 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
5393 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5394 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
5395}
5396
Arend van Sprielb48d8912014-07-12 08:49:41 +02005397static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005398{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005399 struct ieee80211_iface_combination ifc_combo;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005400 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
5401 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5402 wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
5403 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
5404 BIT(NL80211_IFTYPE_ADHOC) |
5405 BIT(NL80211_IFTYPE_AP) |
5406 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5407 BIT(NL80211_IFTYPE_P2P_GO) |
5408 BIT(NL80211_IFTYPE_P2P_DEVICE);
5409 /* need VSDB firmware feature for concurrent channels */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005410 ifc_combo = brcmf_iface_combos[0];
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005411 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
Arend van Sprielb48d8912014-07-12 08:49:41 +02005412 ifc_combo.num_different_channels = 2;
5413 wiphy->iface_combinations = kmemdup(&ifc_combo,
5414 sizeof(ifc_combo),
5415 GFP_KERNEL);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005416 wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005417 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
5418 wiphy->cipher_suites = __wl_cipher_suites;
5419 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
5420 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
5421 WIPHY_FLAG_OFFCHAN_TX |
5422 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5423 WIPHY_FLAG_SUPPORTS_TDLS;
5424 if (!brcmf_roamoff)
5425 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
5426 wiphy->mgmt_stypes = brcmf_txrx_stypes;
5427 wiphy->max_remain_on_channel_duration = 5000;
5428 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005429
5430 /* vendor commands/events support */
5431 wiphy->vendor_commands = brcmf_vendor_cmds;
5432 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
5433
Arend van Sprielb48d8912014-07-12 08:49:41 +02005434 return brcmf_setup_wiphybands(wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005435}
5436
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005437static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005438{
5439 struct net_device *ndev;
5440 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01005441 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005442 s32 power_mode;
5443 s32 err = 0;
5444
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005445 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005446 return err;
5447
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005448 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005449 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01005450 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005451
Hante Meuleman40a23292013-01-02 15:22:51 +01005452 /* make sure RF is ready for work */
5453 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
5454
5455 brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME,
5456 WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005457
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005458 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01005459 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005460 if (err)
5461 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005462 brcmf_dbg(INFO, "power save set to %s\n",
5463 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005464
Hante Meuleman68ca3952014-02-25 20:30:26 +01005465 err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005466 if (err)
5467 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07005468 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
5469 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01005470 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005471 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005472
Hante Meulemanb3657452013-05-27 21:09:53 +02005473 brcmf_configure_arp_offload(ifp, true);
5474
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005475 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01005476default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005477
5478 return err;
5479
5480}
5481
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005482static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005483{
Arend van Sprielc1179032012-10-22 13:55:33 -07005484 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005485
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005486 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005487}
5488
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005489static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005490{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005491 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07005492
Arend van Spriel5b435de2011-10-05 13:19:03 +02005493 /*
5494 * While going down, if associated with AP disassociate
5495 * from AP to save power
5496 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005497 if (check_vif_up(ifp->vif)) {
5498 brcmf_link_down(ifp->vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005499
5500 /* Make sure WPA_Supplicant receives all the event
5501 generated due to DISASSOC call to the fw to keep
5502 the state fw and WPA_Supplicant state consistent
5503 */
5504 brcmf_delay(500);
5505 }
5506
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005507 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07005508 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005509
Arend van Spriel5b435de2011-10-05 13:19:03 +02005510 return 0;
5511}
5512
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005513s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005514{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005515 struct brcmf_if *ifp = netdev_priv(ndev);
5516 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005517 s32 err = 0;
5518
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005519 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005520 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005521 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005522
5523 return err;
5524}
5525
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005526s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005527{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005528 struct brcmf_if *ifp = netdev_priv(ndev);
5529 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005530 s32 err = 0;
5531
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005532 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005533 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005534 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005535
5536 return err;
5537}
5538
Arend van Spriela7965fb2013-04-11 17:08:37 +02005539enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
5540{
5541 struct wireless_dev *wdev = &ifp->vif->wdev;
5542
5543 return wdev->iftype;
5544}
5545
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005546bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01005547{
5548 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005549
5550 list_for_each_entry(vif, &cfg->vif_list, list) {
5551 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005552 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005553 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005554 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005555}
Arend van Sprield3c0b632013-02-08 15:53:37 +01005556
5557static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
5558 u8 action)
5559{
5560 u8 evt_action;
5561
5562 mutex_lock(&event->vif_event_lock);
5563 evt_action = event->action;
5564 mutex_unlock(&event->vif_event_lock);
5565 return evt_action == action;
5566}
5567
5568void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
5569 struct brcmf_cfg80211_vif *vif)
5570{
5571 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5572
5573 mutex_lock(&event->vif_event_lock);
5574 event->vif = vif;
5575 event->action = 0;
5576 mutex_unlock(&event->vif_event_lock);
5577}
5578
5579bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
5580{
5581 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5582 bool armed;
5583
5584 mutex_lock(&event->vif_event_lock);
5585 armed = event->vif != NULL;
5586 mutex_unlock(&event->vif_event_lock);
5587
5588 return armed;
5589}
5590int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
5591 u8 action, ulong timeout)
5592{
5593 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5594
5595 return wait_event_timeout(event->vif_wq,
5596 vif_event_equals(event, action), timeout);
5597}
5598
Arend van Sprielb48d8912014-07-12 08:49:41 +02005599static void brcmf_free_wiphy(struct wiphy *wiphy)
5600{
5601 kfree(wiphy->iface_combinations);
5602 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5603 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5604 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5605 }
5606 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
5607 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
5608 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
5609 }
5610 wiphy_free(wiphy);
5611}
5612
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005613struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
5614 struct device *busdev)
5615{
5616 struct net_device *ndev = drvr->iflist[0]->ndev;
5617 struct brcmf_cfg80211_info *cfg;
5618 struct wiphy *wiphy;
5619 struct brcmf_cfg80211_vif *vif;
5620 struct brcmf_if *ifp;
5621 s32 err = 0;
5622 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005623 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005624
5625 if (!ndev) {
5626 brcmf_err("ndev is invalid\n");
5627 return NULL;
5628 }
5629
5630 ifp = netdev_priv(ndev);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005631 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
5632 if (!wiphy) {
5633 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005634 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005635 }
5636 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005637
5638 cfg = wiphy_priv(wiphy);
5639 cfg->wiphy = wiphy;
5640 cfg->pub = drvr;
5641 init_vif_event(&cfg->vif_event);
5642 INIT_LIST_HEAD(&cfg->vif_list);
5643
5644 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005645 if (IS_ERR(vif))
5646 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005647
5648 vif->ifp = ifp;
5649 vif->wdev.netdev = ndev;
5650 ndev->ieee80211_ptr = &vif->wdev;
5651 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
5652
5653 err = wl_init_priv(cfg);
5654 if (err) {
5655 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005656 brcmf_free_vif(vif);
5657 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005658 }
5659 ifp->vif = vif;
5660
Arend van Sprielb48d8912014-07-12 08:49:41 +02005661 /* determine d11 io type before wiphy setup */
5662 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005663 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005664 brcmf_err("Failed to get D11 version (%d)\n", err);
5665 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005666 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005667 cfg->d11inf.io_type = (u8)io_type;
5668 brcmu_d11_attach(&cfg->d11inf);
5669
5670 err = brcmf_setup_wiphy(wiphy, ifp);
5671 if (err < 0)
5672 goto priv_out;
5673
5674 brcmf_dbg(INFO, "Registering custom regulatory\n");
5675 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
5676 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
5677
5678 /* firmware defaults to 40MHz disabled in 2G band. We signal
5679 * cfg80211 here that we do and have it decide we can enable
5680 * it. But first check if device does support 2G operation.
5681 */
5682 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5683 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
5684 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5685 }
5686 err = wiphy_register(wiphy);
5687 if (err < 0) {
5688 brcmf_err("Could not register wiphy device (%d)\n", err);
5689 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005690 }
5691
5692 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
5693 * setup 40MHz in 2GHz band and enable OBSS scanning.
5694 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005695 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
5696 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005697 if (!err)
5698 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
5699 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005700 else
5701 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005702 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005703
5704 err = brcmf_p2p_attach(cfg);
5705 if (err) {
5706 brcmf_err("P2P initilisation failed (%d)\n", err);
5707 goto wiphy_unreg_out;
5708 }
5709 err = brcmf_btcoex_attach(cfg);
5710 if (err) {
5711 brcmf_err("BT-coex initialisation failed (%d)\n", err);
5712 brcmf_p2p_detach(&cfg->p2p);
5713 goto wiphy_unreg_out;
5714 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005715
5716 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
5717 if (err) {
5718 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
5719 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman70b7d942014-07-30 13:20:07 +02005720 } else {
5721 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
5722 brcmf_notify_tdls_peer_event);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005723 }
5724
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005725 return cfg;
5726
Arend van Sprielb48d8912014-07-12 08:49:41 +02005727wiphy_unreg_out:
5728 wiphy_unregister(cfg->wiphy);
5729priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005730 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005731 brcmf_free_vif(vif);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005732wiphy_out:
5733 brcmf_free_wiphy(wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005734 return NULL;
5735}
5736
5737void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
5738{
5739 if (!cfg)
5740 return;
5741
5742 WARN_ON(!list_empty(&cfg->vif_list));
5743 wiphy_unregister(cfg->wiphy);
5744 brcmf_btcoex_detach(cfg);
Arend van Sprielc3da74b2014-07-12 08:49:42 +02005745 brcmf_p2p_detach(&cfg->p2p);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005746 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005747 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005748}