blob: d1928de895f94494d6f052c095f838b143006f9d [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
18
19#include <linux/kernel.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020020#include <linux/etherdevice.h>
Hante Meuleman68ca3952014-02-25 20:30:26 +010021#include <linux/module.h>
Franky Lin1bacb042014-06-21 12:11:16 +020022#include <linux/vmalloc.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020023#include <net/cfg80211.h>
Arend van Sprielcbaa1772012-08-30 19:43:02 +020024#include <net/netlink.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020025
26#include <brcmu_utils.h>
27#include <defs.h>
28#include <brcmu_wifi.h>
Hante Meuleman122d3d02014-10-28 14:56:18 +010029#include "core.h"
Hante Meulemana8e8ed32014-10-28 14:56:13 +010030#include "debug.h"
Arend van Spriel40c1c242013-04-05 10:57:44 +020031#include "tracepoint.h"
Hante Meuleman7a5c1f62013-02-08 15:53:44 +010032#include "fwil_types.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010033#include "p2p.h"
Piotr Haber61730d42013-04-23 12:53:12 +020034#include "btcoex.h"
Hante Meulemanbfe81972014-10-28 14:56:16 +010035#include "cfg80211.h"
Arend van Sprielc08437b2014-07-12 08:49:39 +020036#include "feature.h"
Hante Meuleman81f5dcb2012-10-22 10:36:14 -070037#include "fwil.h"
Hante Meuleman8851cce2014-07-30 13:20:02 +020038#include "proto.h"
Franky Lin1bacb042014-06-21 12:11:16 +020039#include "vendor.h"
Hante Meulemand14f78b2014-10-28 14:56:14 +010040#include "bus.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020041
Arend van Spriele5806072012-09-19 22:21:08 +020042#define BRCMF_SCAN_IE_LEN_MAX 2048
43#define BRCMF_PNO_VERSION 2
44#define BRCMF_PNO_TIME 30
45#define BRCMF_PNO_REPEAT 4
46#define BRCMF_PNO_FREQ_EXPO_MAX 3
47#define BRCMF_PNO_MAX_PFN_COUNT 16
48#define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
49#define BRCMF_PNO_HIDDEN_BIT 2
50#define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
51#define BRCMF_PNO_SCAN_COMPLETE 1
52#define BRCMF_PNO_SCAN_INCOMPLETE 0
53
Arend van Spriel9f440b72013-02-08 15:53:36 +010054#define BRCMF_IFACE_MAX_CNT 3
Arend van Spriel3eacf862012-10-22 13:55:30 -070055
Hante Meuleman1a873342012-09-27 14:17:54 +020056#define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
57#define WPA_OUI_TYPE 1
58#define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
59#define WME_OUI_TYPE 2
Hante Meuleman89286dc2013-02-08 15:53:46 +010060#define WPS_OUI_TYPE 4
Hante Meuleman1a873342012-09-27 14:17:54 +020061
62#define VS_IE_FIXED_HDR_LEN 6
63#define WPA_IE_VERSION_LEN 2
64#define WPA_IE_MIN_OUI_LEN 4
65#define WPA_IE_SUITE_COUNT_LEN 2
66
67#define WPA_CIPHER_NONE 0 /* None */
68#define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
69#define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
70#define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
71#define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
72
73#define RSN_AKM_NONE 0 /* None (IBSS) */
74#define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
75#define RSN_AKM_PSK 2 /* Pre-shared Key */
76#define RSN_CAP_LEN 2 /* Length of RSN capabilities */
77#define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
78
79#define VNDR_IE_CMD_LEN 4 /* length of the set command
80 * string :"add", "del" (+ NUL)
81 */
82#define VNDR_IE_COUNT_OFFSET 4
83#define VNDR_IE_PKTFLAG_OFFSET 8
84#define VNDR_IE_VSIE_OFFSET 12
85#define VNDR_IE_HDR_SIZE 12
Arend van Spriel9f440b72013-02-08 15:53:36 +010086#define VNDR_IE_PARSE_LIMIT 5
Hante Meuleman1a873342012-09-27 14:17:54 +020087
88#define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
89#define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
Hante Meuleman04012892012-09-27 14:17:49 +020090
Hante Meuleman89286dc2013-02-08 15:53:46 +010091#define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
92#define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
93#define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
94
Arend van Spriel5b435de2011-10-05 13:19:03 +020095#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
96 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
97
Arend van Sprielce81e312012-10-22 13:55:37 -070098static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +020099{
Arend van Sprielc1179032012-10-22 13:55:33 -0700100 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100101 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
102 vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200103 return false;
104 }
105 return true;
106}
107
Arend van Spriel5b435de2011-10-05 13:19:03 +0200108#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
109#define RATETAB_ENT(_rateid, _flags) \
110 { \
111 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
112 .hw_value = (_rateid), \
113 .flags = (_flags), \
114 }
115
116static struct ieee80211_rate __wl_rates[] = {
117 RATETAB_ENT(BRCM_RATE_1M, 0),
118 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
119 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
120 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
121 RATETAB_ENT(BRCM_RATE_6M, 0),
122 RATETAB_ENT(BRCM_RATE_9M, 0),
123 RATETAB_ENT(BRCM_RATE_12M, 0),
124 RATETAB_ENT(BRCM_RATE_18M, 0),
125 RATETAB_ENT(BRCM_RATE_24M, 0),
126 RATETAB_ENT(BRCM_RATE_36M, 0),
127 RATETAB_ENT(BRCM_RATE_48M, 0),
128 RATETAB_ENT(BRCM_RATE_54M, 0),
129};
130
131#define wl_a_rates (__wl_rates + 4)
132#define wl_a_rates_size 8
133#define wl_g_rates (__wl_rates + 0)
134#define wl_g_rates_size 12
135
Arend van Sprielb48d8912014-07-12 08:49:41 +0200136/* Band templates duplicated per wiphy. The channel info
137 * is filled in after querying the device.
138 */
139static const struct ieee80211_supported_band __wl_band_2ghz = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200140 .band = IEEE80211_BAND_2GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200141 .bitrates = wl_g_rates,
142 .n_bitrates = wl_g_rates_size,
143};
144
Arend van Sprielb48d8912014-07-12 08:49:41 +0200145static const struct ieee80211_supported_band __wl_band_5ghz_a = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200146 .band = IEEE80211_BAND_5GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200147 .bitrates = wl_a_rates,
148 .n_bitrates = wl_a_rates_size,
149};
150
Hante Meulemand48200b2013-04-03 12:40:29 +0200151/* This is to override regulatory domains defined in cfg80211 module (reg.c)
152 * By default world regulatory domain defined in reg.c puts the flags
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200153 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
154 * With respect to these flags, wpa_supplicant doesn't * start p2p
155 * operations on 5GHz channels. All the changes in world regulatory
Hante Meulemand48200b2013-04-03 12:40:29 +0200156 * domain are to be done here.
157 */
158static const struct ieee80211_regdomain brcmf_regdom = {
159 .n_reg_rules = 4,
160 .alpha2 = "99",
161 .reg_rules = {
162 /* IEEE 802.11b/g, channels 1..11 */
163 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
164 /* If any */
165 /* IEEE 802.11 channel 14 - Only JP enables
166 * this and for 802.11b only
167 */
168 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
169 /* IEEE 802.11a, channel 36..64 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200170 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
Hante Meulemand48200b2013-04-03 12:40:29 +0200171 /* IEEE 802.11a, channel 100..165 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200172 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200173};
174
175static const u32 __wl_cipher_suites[] = {
176 WLAN_CIPHER_SUITE_WEP40,
177 WLAN_CIPHER_SUITE_WEP104,
178 WLAN_CIPHER_SUITE_TKIP,
179 WLAN_CIPHER_SUITE_CCMP,
180 WLAN_CIPHER_SUITE_AES_CMAC,
181};
182
Hante Meuleman1a873342012-09-27 14:17:54 +0200183/* Vendor specific ie. id = 221, oui and type defines exact ie */
184struct brcmf_vs_tlv {
185 u8 id;
186 u8 len;
187 u8 oui[3];
188 u8 oui_type;
189};
190
191struct parsed_vndr_ie_info {
192 u8 *ie_ptr;
193 u32 ie_len; /* total length including id & length field */
194 struct brcmf_vs_tlv vndrie;
195};
196
197struct parsed_vndr_ies {
198 u32 count;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100199 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
Hante Meuleman1a873342012-09-27 14:17:54 +0200200};
201
Hante Meuleman68ca3952014-02-25 20:30:26 +0100202static int brcmf_roamoff;
203module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
204MODULE_PARM_DESC(roamoff, "do not use internal roaming engine");
205
Alwin Beukersef6ac172011-10-12 20:51:26 +0200206/* Quarter dBm units to mW
207 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
208 * Table is offset so the last entry is largest mW value that fits in
209 * a u16.
210 */
211
212#define QDBM_OFFSET 153 /* Offset for first entry */
213#define QDBM_TABLE_LEN 40 /* Table size */
214
215/* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
216 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
217 */
218#define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
219
220/* Largest mW value that will round down to the last table entry,
221 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
222 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
223 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
224 */
225#define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
226
227static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
228/* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
229/* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
230/* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
231/* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
232/* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
233/* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
234};
235
236static u16 brcmf_qdbm_to_mw(u8 qdbm)
237{
238 uint factor = 1;
239 int idx = qdbm - QDBM_OFFSET;
240
241 if (idx >= QDBM_TABLE_LEN)
242 /* clamp to max u16 mW value */
243 return 0xFFFF;
244
245 /* scale the qdBm index up to the range of the table 0-40
246 * where an offset of 40 qdBm equals a factor of 10 mW.
247 */
248 while (idx < 0) {
249 idx += 40;
250 factor *= 10;
251 }
252
253 /* return the mW value scaled down to the correct factor of 10,
254 * adding in factor/2 to get proper rounding.
255 */
256 return (nqdBm_to_mW_map[idx] + factor / 2) / factor;
257}
258
259static u8 brcmf_mw_to_qdbm(u16 mw)
260{
261 u8 qdbm;
262 int offset;
263 uint mw_uint = mw;
264 uint boundary;
265
266 /* handle boundary case */
267 if (mw_uint <= 1)
268 return 0;
269
270 offset = QDBM_OFFSET;
271
272 /* move mw into the range of the table */
273 while (mw_uint < QDBM_TABLE_LOW_BOUND) {
274 mw_uint *= 10;
275 offset -= 40;
276 }
277
278 for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) {
279 boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] -
280 nqdBm_to_mW_map[qdbm]) / 2;
281 if (mw_uint < boundary)
282 break;
283 }
284
285 qdbm += (u8) offset;
286
287 return qdbm;
288}
289
Arend van Spriel5a394eb2014-05-27 12:56:15 +0200290static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
291 struct cfg80211_chan_def *ch)
Arend van Spriel600a8972014-05-12 10:47:39 +0200292{
293 struct brcmu_chan ch_inf;
294 s32 primary_offset;
295
296 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
297 ch->chan->center_freq, ch->center_freq1, ch->width);
298 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
299 primary_offset = ch->center_freq1 - ch->chan->center_freq;
300 switch (ch->width) {
301 case NL80211_CHAN_WIDTH_20:
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100302 case NL80211_CHAN_WIDTH_20_NOHT:
Arend van Spriel600a8972014-05-12 10:47:39 +0200303 ch_inf.bw = BRCMU_CHAN_BW_20;
304 WARN_ON(primary_offset != 0);
305 break;
306 case NL80211_CHAN_WIDTH_40:
307 ch_inf.bw = BRCMU_CHAN_BW_40;
308 if (primary_offset < 0)
309 ch_inf.sb = BRCMU_CHAN_SB_U;
310 else
311 ch_inf.sb = BRCMU_CHAN_SB_L;
312 break;
313 case NL80211_CHAN_WIDTH_80:
314 ch_inf.bw = BRCMU_CHAN_BW_80;
315 if (primary_offset < 0) {
316 if (primary_offset < -CH_10MHZ_APART)
317 ch_inf.sb = BRCMU_CHAN_SB_UU;
318 else
319 ch_inf.sb = BRCMU_CHAN_SB_UL;
320 } else {
321 if (primary_offset > CH_10MHZ_APART)
322 ch_inf.sb = BRCMU_CHAN_SB_LL;
323 else
324 ch_inf.sb = BRCMU_CHAN_SB_LU;
325 }
326 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100327 case NL80211_CHAN_WIDTH_80P80:
328 case NL80211_CHAN_WIDTH_160:
329 case NL80211_CHAN_WIDTH_5:
330 case NL80211_CHAN_WIDTH_10:
Arend van Spriel600a8972014-05-12 10:47:39 +0200331 default:
332 WARN_ON_ONCE(1);
333 }
334 switch (ch->chan->band) {
335 case IEEE80211_BAND_2GHZ:
336 ch_inf.band = BRCMU_CHAN_BAND_2G;
337 break;
338 case IEEE80211_BAND_5GHZ:
339 ch_inf.band = BRCMU_CHAN_BAND_5G;
340 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100341 case IEEE80211_BAND_60GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200342 default:
343 WARN_ON_ONCE(1);
344 }
345 d11inf->encchspec(&ch_inf);
346
347 return ch_inf.chspec;
348}
349
Franky Lin83cf17a2013-04-11 13:28:50 +0200350u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
351 struct ieee80211_channel *ch)
Arend van Spriel6e186162012-10-22 10:36:22 -0700352{
Franky Lin83cf17a2013-04-11 13:28:50 +0200353 struct brcmu_chan ch_inf;
Arend van Spriel6e186162012-10-22 10:36:22 -0700354
Franky Lin83cf17a2013-04-11 13:28:50 +0200355 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
356 ch_inf.bw = BRCMU_CHAN_BW_20;
357 d11inf->encchspec(&ch_inf);
Arend van Spriel6e186162012-10-22 10:36:22 -0700358
Franky Lin83cf17a2013-04-11 13:28:50 +0200359 return ch_inf.chspec;
Arend van Spriel6e186162012-10-22 10:36:22 -0700360}
361
Hante Meuleman89286dc2013-02-08 15:53:46 +0100362/* Traverse a string of 1-byte tag/1-byte length/variable-length value
363 * triples, returning a pointer to the substring whose first element
364 * matches tag
365 */
Johannes Berg4b5800f2014-01-15 14:55:59 +0100366const struct brcmf_tlv *
367brcmf_parse_tlvs(const void *buf, int buflen, uint key)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100368{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100369 const struct brcmf_tlv *elt = buf;
370 int totlen = buflen;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100371
372 /* find tagged parameter */
373 while (totlen >= TLV_HDR_LEN) {
374 int len = elt->len;
375
376 /* validate remaining totlen */
377 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
378 return elt;
379
380 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
381 totlen -= (len + TLV_HDR_LEN);
382 }
383
384 return NULL;
385}
386
387/* Is any of the tlvs the expected entry? If
388 * not update the tlvs buffer pointer/length.
389 */
390static bool
Johannes Berg4b5800f2014-01-15 14:55:59 +0100391brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
392 const u8 *oui, u32 oui_len, u8 type)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100393{
394 /* If the contents match the OUI and the type */
395 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
396 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
397 type == ie[TLV_BODY_OFF + oui_len]) {
398 return true;
399 }
400
401 if (tlvs == NULL)
402 return false;
403 /* point to the next ie */
404 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
405 /* calculate the length of the rest of the buffer */
406 *tlvs_len -= (int)(ie - *tlvs);
407 /* update the pointer to the start of the buffer */
408 *tlvs = ie;
409
410 return false;
411}
412
413static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100414brcmf_find_wpaie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100415{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100416 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100417
418 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
Johannes Berg4b5800f2014-01-15 14:55:59 +0100419 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
Hante Meuleman89286dc2013-02-08 15:53:46 +0100420 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
421 return (struct brcmf_vs_tlv *)ie;
422 }
423 return NULL;
424}
425
426static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100427brcmf_find_wpsie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100428{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100429 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100430
431 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
432 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
433 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
434 return (struct brcmf_vs_tlv *)ie;
435 }
436 return NULL;
437}
438
439
Arend van Spriel5b435de2011-10-05 13:19:03 +0200440static void convert_key_from_CPU(struct brcmf_wsec_key *key,
441 struct brcmf_wsec_key_le *key_le)
442{
443 key_le->index = cpu_to_le32(key->index);
444 key_le->len = cpu_to_le32(key->len);
445 key_le->algo = cpu_to_le32(key->algo);
446 key_le->flags = cpu_to_le32(key->flags);
447 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
448 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
449 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
450 memcpy(key_le->data, key->data, sizeof(key->data));
451 memcpy(key_le->ea, key->ea, sizeof(key->ea));
452}
453
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200454static int
Arend van Spriel2eaba7e2012-10-22 10:36:26 -0700455send_key_to_dongle(struct net_device *ndev, struct brcmf_wsec_key *key)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200456{
457 int err;
458 struct brcmf_wsec_key_le key_le;
459
460 convert_key_from_CPU(key, &key_le);
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200461
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700462 brcmf_netdev_wait_pend8021x(ndev);
463
Arend van Sprielac24be62012-10-22 10:36:23 -0700464 err = brcmf_fil_bsscfg_data_set(netdev_priv(ndev), "wsec_key", &key_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700465 sizeof(key_le));
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200466
Arend van Spriel5b435de2011-10-05 13:19:03 +0200467 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +0100468 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200469 return err;
470}
471
Hante Meulemanb3657452013-05-27 21:09:53 +0200472static s32
473brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable)
474{
475 s32 err;
476 u32 mode;
477
478 if (enable)
479 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
480 else
481 mode = 0;
482
483 /* Try to set and enable ARP offload feature, this may fail, then it */
484 /* is simply not supported and err 0 will be returned */
485 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
486 if (err) {
487 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
488 mode, err);
489 err = 0;
490 } else {
491 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
492 if (err) {
493 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
494 enable, err);
495 err = 0;
496 } else
497 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
498 enable, mode);
499 }
500
501 return err;
502}
503
Hante Meuleman8851cce2014-07-30 13:20:02 +0200504static void
505brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
506{
Arend van Spriel8f2b4592014-09-11 22:51:32 +0200507 struct brcmf_cfg80211_vif *vif;
508 struct brcmf_if *ifp;
509
510 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
511 ifp = vif->ifp;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200512
513 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
514 (wdev->iftype == NL80211_IFTYPE_AP) ||
515 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
516 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
517 ADDR_DIRECT);
518 else
519 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
520 ADDR_INDIRECT);
521}
522
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100523static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
524{
525 enum nl80211_iftype iftype;
526
527 iftype = vif->wdev.iftype;
528 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
529}
530
531static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
532{
533 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
534}
535
Arend van Spriel9f440b72013-02-08 15:53:36 +0100536static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
537 const char *name,
538 enum nl80211_iftype type,
539 u32 *flags,
540 struct vif_params *params)
541{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200542 struct wireless_dev *wdev;
543
Arend van Spriel9f440b72013-02-08 15:53:36 +0100544 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
545 switch (type) {
546 case NL80211_IFTYPE_ADHOC:
547 case NL80211_IFTYPE_STATION:
548 case NL80211_IFTYPE_AP:
549 case NL80211_IFTYPE_AP_VLAN:
550 case NL80211_IFTYPE_WDS:
551 case NL80211_IFTYPE_MONITOR:
552 case NL80211_IFTYPE_MESH_POINT:
553 return ERR_PTR(-EOPNOTSUPP);
554 case NL80211_IFTYPE_P2P_CLIENT:
555 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200556 case NL80211_IFTYPE_P2P_DEVICE:
Hante Meuleman8851cce2014-07-30 13:20:02 +0200557 wdev = brcmf_p2p_add_vif(wiphy, name, type, flags, params);
558 if (!IS_ERR(wdev))
559 brcmf_cfg80211_update_proto_addr_mode(wdev);
560 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100561 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100562 default:
563 return ERR_PTR(-EINVAL);
564 }
565}
566
Daniel Kim5e787f72014-06-21 12:11:18 +0200567static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
568{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200569 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200570 brcmf_set_mpc(ifp, mpc);
571}
572
Arend van Sprielf96aa072013-04-05 10:57:48 +0200573void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100574{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100575 s32 err = 0;
576
577 if (check_vif_up(ifp->vif)) {
578 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
579 if (err) {
580 brcmf_err("fail to set mpc\n");
581 return;
582 }
583 brcmf_dbg(INFO, "MPC : %d\n", mpc);
584 }
585}
586
Arend van Spriela0f472a2013-04-05 10:57:49 +0200587s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
588 struct brcmf_if *ifp, bool aborted,
589 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100590{
591 struct brcmf_scan_params_le params_le;
592 struct cfg80211_scan_request *scan_request;
593 s32 err = 0;
594
595 brcmf_dbg(SCAN, "Enter\n");
596
597 /* clear scan request, because the FW abort can cause a second call */
598 /* to this functon and might cause a double cfg80211_scan_done */
599 scan_request = cfg->scan_request;
600 cfg->scan_request = NULL;
601
602 if (timer_pending(&cfg->escan_timeout))
603 del_timer_sync(&cfg->escan_timeout);
604
605 if (fw_abort) {
606 /* Do a scan abort to stop the driver's scan engine */
607 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
608 memset(&params_le, 0, sizeof(params_le));
609 memset(params_le.bssid, 0xFF, ETH_ALEN);
610 params_le.bss_type = DOT11_BSSTYPE_ANY;
611 params_le.scan_type = 0;
612 params_le.channel_num = cpu_to_le32(1);
613 params_le.nprobes = cpu_to_le32(1);
614 params_le.active_time = cpu_to_le32(-1);
615 params_le.passive_time = cpu_to_le32(-1);
616 params_le.home_time = cpu_to_le32(-1);
617 /* Scan is aborted by setting channel_list[0] to -1 */
618 params_le.channel_list[0] = cpu_to_le16(-1);
619 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200620 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100621 &params_le, sizeof(params_le));
622 if (err)
623 brcmf_err("Scan abort failed\n");
624 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200625
Daniel Kim5e787f72014-06-21 12:11:18 +0200626 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200627
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100628 /*
629 * e-scan can be initiated by scheduled scan
630 * which takes precedence.
631 */
632 if (cfg->sched_escan) {
633 brcmf_dbg(SCAN, "scheduled scan completed\n");
634 cfg->sched_escan = false;
635 if (!aborted)
636 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100637 } else if (scan_request) {
638 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
639 aborted ? "Aborted" : "Done");
640 cfg80211_scan_done(scan_request, aborted);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100641 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100642 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
643 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100644
645 return err;
646}
647
Arend van Spriel9f440b72013-02-08 15:53:36 +0100648static
649int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
650{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100651 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
652 struct net_device *ndev = wdev->netdev;
653
654 /* vif event pending in firmware */
655 if (brcmf_cfg80211_vif_event_armed(cfg))
656 return -EBUSY;
657
658 if (ndev) {
659 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200660 cfg->escan_info.ifp == netdev_priv(ndev))
661 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
662 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100663
664 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
665 }
666
Arend van Spriel9f440b72013-02-08 15:53:36 +0100667 switch (wdev->iftype) {
668 case NL80211_IFTYPE_ADHOC:
669 case NL80211_IFTYPE_STATION:
670 case NL80211_IFTYPE_AP:
671 case NL80211_IFTYPE_AP_VLAN:
672 case NL80211_IFTYPE_WDS:
673 case NL80211_IFTYPE_MONITOR:
674 case NL80211_IFTYPE_MESH_POINT:
675 return -EOPNOTSUPP;
676 case NL80211_IFTYPE_P2P_CLIENT:
677 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200678 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100679 return brcmf_p2p_del_vif(wiphy, wdev);
680 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100681 default:
682 return -EINVAL;
683 }
684 return -EOPNOTSUPP;
685}
686
Arend van Spriel5b435de2011-10-05 13:19:03 +0200687static s32
688brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
689 enum nl80211_iftype type, u32 *flags,
690 struct vif_params *params)
691{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100692 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700693 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100694 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200695 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200696 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200697 s32 err = 0;
698
Arend van Sprield96b8012012-12-05 15:26:02 +0100699 brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200700
701 switch (type) {
702 case NL80211_IFTYPE_MONITOR:
703 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100704 brcmf_err("type (%d) : currently we do not support this type\n",
705 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200706 return -EOPNOTSUPP;
707 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200708 infra = 0;
709 break;
710 case NL80211_IFTYPE_STATION:
Hante Meuleman1bc7c652013-02-08 15:53:56 +0100711 /* Ignore change for p2p IF. Unclear why supplicant does this */
712 if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
713 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) {
714 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
715 /* WAR: It is unexpected to get a change of VIF for P2P
716 * IF, but it happens. The request can not be handled
717 * but returning EPERM causes a crash. Returning 0
718 * without setting ieee80211_ptr->iftype causes trace
719 * (WARN_ON) but it works with wpa_supplicant
720 */
721 return 0;
722 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200723 infra = 1;
724 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200725 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100726 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200727 ap = 1;
728 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200729 default:
730 err = -EINVAL;
731 goto done;
732 }
733
Hante Meuleman1a873342012-09-27 14:17:54 +0200734 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100735 if (type == NL80211_IFTYPE_P2P_GO) {
736 brcmf_dbg(INFO, "IF Type = P2P GO\n");
737 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
738 }
739 if (!err) {
740 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state);
741 brcmf_dbg(INFO, "IF Type = AP\n");
742 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200743 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100744 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200745 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100746 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200747 err = -EAGAIN;
748 goto done;
749 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100750 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100751 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200752 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200753 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200754
Hante Meuleman8851cce2014-07-30 13:20:02 +0200755 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
756
Arend van Spriel5b435de2011-10-05 13:19:03 +0200757done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100758 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200759
760 return err;
761}
762
Franky Lin83cf17a2013-04-11 13:28:50 +0200763static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
764 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200765 struct cfg80211_scan_request *request)
766{
767 u32 n_ssids;
768 u32 n_channels;
769 s32 i;
770 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200771 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200772 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200773 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200774
Arend van Sprielba40d162012-10-22 13:55:38 -0700775 memset(params_le->bssid, 0xFF, ETH_ALEN);
Hante Meulemane756af52012-09-11 21:18:52 +0200776 params_le->bss_type = DOT11_BSSTYPE_ANY;
777 params_le->scan_type = 0;
778 params_le->channel_num = 0;
779 params_le->nprobes = cpu_to_le32(-1);
780 params_le->active_time = cpu_to_le32(-1);
781 params_le->passive_time = cpu_to_le32(-1);
782 params_le->home_time = cpu_to_le32(-1);
783 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
784
785 /* if request is null exit so it will be all channel broadcast scan */
786 if (!request)
787 return;
788
789 n_ssids = request->n_ssids;
790 n_channels = request->n_channels;
791 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100792 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
793 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200794 if (n_channels > 0) {
795 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200796 chanspec = channel_to_chanspec(&cfg->d11inf,
797 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100798 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
799 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200800 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200801 }
802 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100803 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200804 }
805 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100806 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200807 if (n_ssids > 0) {
808 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
809 n_channels * sizeof(u16);
810 offset = roundup(offset, sizeof(u32));
811 ptr = (char *)params_le + offset;
812 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +0200813 memset(&ssid_le, 0, sizeof(ssid_le));
814 ssid_le.SSID_len =
815 cpu_to_le32(request->ssids[i].ssid_len);
816 memcpy(ssid_le.SSID, request->ssids[i].ssid,
817 request->ssids[i].ssid_len);
818 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100819 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +0200820 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100821 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
822 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +0200823 memcpy(ptr, &ssid_le, sizeof(ssid_le));
824 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +0200825 }
826 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100827 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200828 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100829 brcmf_dbg(SCAN, "SSID %s len=%d\n",
830 params_le->ssid_le.SSID,
831 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200832 params_le->ssid_le.SSID_len =
833 cpu_to_le32(request->ssids->ssid_len);
834 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
835 request->ssids->ssid_len);
836 }
837 }
838 /* Adding mask to channel numbers */
839 params_le->channel_num =
840 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
841 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
842}
843
844static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200845brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +0200846 struct cfg80211_scan_request *request, u16 action)
847{
848 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
849 offsetof(struct brcmf_escan_params_le, params_le);
850 struct brcmf_escan_params_le *params;
851 s32 err = 0;
852
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100853 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200854
855 if (request != NULL) {
856 /* Allocate space for populating ssids in struct */
857 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
858
859 /* Allocate space for populating ssids in struct */
860 params_size += sizeof(struct brcmf_ssid) * request->n_ssids;
861 }
862
863 params = kzalloc(params_size, GFP_KERNEL);
864 if (!params) {
865 err = -ENOMEM;
866 goto exit;
867 }
868 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +0200869 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +0200870 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
871 params->action = cpu_to_le16(action);
872 params->sync_id = cpu_to_le16(0x1234);
873
Arend van Spriela0f472a2013-04-05 10:57:49 +0200874 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +0200875 if (err) {
876 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100877 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200878 else
Arend van Spriel57d6e912012-12-05 15:26:00 +0100879 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200880 }
881
882 kfree(params);
883exit:
884 return err;
885}
886
887static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200888brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
Arend van Spriela0f472a2013-04-05 10:57:49 +0200889 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200890{
891 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700892 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +0200893 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100894 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +0200895
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100896 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +0200897 escan->ifp = ifp;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100898 escan->wiphy = wiphy;
899 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700900 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +0200901 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700902 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +0200903 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100904 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200905 return err;
906 }
Daniel Kim5e787f72014-06-21 12:11:18 +0200907 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200908 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +0200909 results->version = 0;
910 results->count = 0;
911 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
912
Arend van Spriela0f472a2013-04-05 10:57:49 +0200913 err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +0200914 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +0200915 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +0200916 return err;
917}
918
919static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200920brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +0200921 struct cfg80211_scan_request *request,
922 struct cfg80211_ssid *this_ssid)
923{
Arend van Spriela0f472a2013-04-05 10:57:49 +0200924 struct brcmf_if *ifp = vif->ifp;
925 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +0200926 struct cfg80211_ssid *ssids;
Hante Meulemanf07998952012-11-05 16:22:13 -0800927 struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700928 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +0200929 bool escan_req;
930 bool spec_scan;
931 s32 err;
932 u32 SSID_len;
933
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100934 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200935
Arend van Sprielc1179032012-10-22 13:55:33 -0700936 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100937 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +0200938 return -EAGAIN;
939 }
Arend van Sprielc1179032012-10-22 13:55:33 -0700940 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100941 brcmf_err("Scanning being aborted: status (%lu)\n",
942 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +0200943 return -EAGAIN;
944 }
Arend van Spriel1687eee2013-04-23 12:53:11 +0200945 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
946 brcmf_err("Scanning suppressed: status (%lu)\n",
947 cfg->scan_status);
948 return -EAGAIN;
949 }
Arend van Sprielc1179032012-10-22 13:55:33 -0700950 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100951 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +0200952 return -EAGAIN;
953 }
954
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100955 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +0200956 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
957 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100958
Hante Meulemane756af52012-09-11 21:18:52 +0200959 /* Arm scan timeout timer */
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200960 mod_timer(&cfg->escan_timeout, jiffies +
Hante Meulemane756af52012-09-11 21:18:52 +0200961 WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
962
963 escan_req = false;
964 if (request) {
965 /* scan bss */
966 ssids = request->ssids;
967 escan_req = true;
968 } else {
969 /* scan in ibss */
970 /* we don't do escan in ibss */
971 ssids = this_ssid;
972 }
973
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200974 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -0700975 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +0200976 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +0100977 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +0200978 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100979 if (err)
980 goto scan_out;
981
Arend van Spriela0f472a2013-04-05 10:57:49 +0200982 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -0800983 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +0200984 goto scan_out;
985 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100986 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
987 ssids->ssid, ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200988 memset(&sr->ssid_le, 0, sizeof(sr->ssid_le));
989 SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len);
990 sr->ssid_le.SSID_len = cpu_to_le32(0);
991 spec_scan = false;
992 if (SSID_len) {
993 memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len);
994 sr->ssid_le.SSID_len = cpu_to_le32(SSID_len);
995 spec_scan = true;
996 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100997 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200998
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700999 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -07001000 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001001 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001002 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001003 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001004 goto scan_out;
1005 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001006 brcmf_scan_config_mpc(ifp, 0);
Arend van Sprielc1179032012-10-22 13:55:33 -07001007 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Sprielac24be62012-10-22 10:36:23 -07001008 &sr->ssid_le, sizeof(sr->ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001009 if (err) {
1010 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001011 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
1012 sr->ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001013 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001014 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001015
Daniel Kim5e787f72014-06-21 12:11:18 +02001016 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001017 goto scan_out;
1018 }
1019 }
1020
1021 return 0;
1022
1023scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001024 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001025 if (timer_pending(&cfg->escan_timeout))
1026 del_timer_sync(&cfg->escan_timeout);
1027 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001028 return err;
1029}
1030
Arend van Spriel5b435de2011-10-05 13:19:03 +02001031static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001032brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001033{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001034 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001035 s32 err = 0;
1036
Arend van Sprield96b8012012-12-05 15:26:02 +01001037 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001038 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1039 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001040 return -EIO;
1041
Arend van Spriela0f472a2013-04-05 10:57:49 +02001042 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001043
Arend van Spriel5b435de2011-10-05 13:19:03 +02001044 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001045 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001046
Arend van Sprield96b8012012-12-05 15:26:02 +01001047 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001048 return err;
1049}
1050
1051static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1052{
1053 s32 err = 0;
1054
Arend van Sprielac24be62012-10-22 10:36:23 -07001055 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1056 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001057 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001058 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001059
1060 return err;
1061}
1062
1063static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1064{
1065 s32 err = 0;
1066
Arend van Sprielac24be62012-10-22 10:36:23 -07001067 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1068 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001069 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001070 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001071
1072 return err;
1073}
1074
1075static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1076{
1077 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001078 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001079
Arend van Sprielac24be62012-10-22 10:36:23 -07001080 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001081 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001082 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001083 return err;
1084 }
1085 return err;
1086}
1087
1088static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1089{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001090 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1091 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001092 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001093 s32 err = 0;
1094
Arend van Sprield96b8012012-12-05 15:26:02 +01001095 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001096 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001097 return -EIO;
1098
1099 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001100 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1101 cfg->conf->rts_threshold = wiphy->rts_threshold;
1102 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001103 if (!err)
1104 goto done;
1105 }
1106 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001107 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1108 cfg->conf->frag_threshold = wiphy->frag_threshold;
1109 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001110 if (!err)
1111 goto done;
1112 }
1113 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001114 && (cfg->conf->retry_long != wiphy->retry_long)) {
1115 cfg->conf->retry_long = wiphy->retry_long;
1116 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001117 if (!err)
1118 goto done;
1119 }
1120 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001121 && (cfg->conf->retry_short != wiphy->retry_short)) {
1122 cfg->conf->retry_short = wiphy->retry_short;
1123 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001124 if (!err)
1125 goto done;
1126 }
1127
1128done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001129 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001130 return err;
1131}
1132
Arend van Spriel5b435de2011-10-05 13:19:03 +02001133static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1134{
1135 memset(prof, 0, sizeof(*prof));
1136}
1137
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001138static void brcmf_link_down(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001139{
Piotr Haber61730d42013-04-23 12:53:12 +02001140 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001141 s32 err = 0;
1142
Arend van Sprield96b8012012-12-05 15:26:02 +01001143 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001144
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001145 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001146 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001147 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001148 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001149 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001150 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001151 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001152 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001153 cfg80211_disconnected(vif->wdev.netdev, 0, NULL, 0, GFP_KERNEL);
1154
Arend van Spriel5b435de2011-10-05 13:19:03 +02001155 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001156 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001157 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1158 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001159 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001160}
1161
1162static s32
1163brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1164 struct cfg80211_ibss_params *params)
1165{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001166 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001167 struct brcmf_if *ifp = netdev_priv(ndev);
1168 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001169 struct brcmf_join_params join_params;
1170 size_t join_params_size = 0;
1171 s32 err = 0;
1172 s32 wsec = 0;
1173 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001174 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001175
Arend van Sprield96b8012012-12-05 15:26:02 +01001176 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001177 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001178 return -EIO;
1179
1180 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001181 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001182 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001183 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001184 return -EOPNOTSUPP;
1185 }
1186
Arend van Sprielc1179032012-10-22 13:55:33 -07001187 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001188
1189 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001190 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001191 else
Arend van Spriel16886732012-12-05 15:26:04 +01001192 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001193
Johannes Berg683b6d32012-11-08 21:25:48 +01001194 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001195 brcmf_dbg(CONN, "channel: %d\n",
1196 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001197 else
Arend van Spriel16886732012-12-05 15:26:04 +01001198 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001199
1200 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001201 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001202 else
Arend van Spriel16886732012-12-05 15:26:04 +01001203 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001204
1205 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001206 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001207 else
Arend van Spriel16886732012-12-05 15:26:04 +01001208 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001209
1210 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001211 brcmf_dbg(CONN, "beacon interval: %d\n",
1212 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001213 else
Arend van Spriel16886732012-12-05 15:26:04 +01001214 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001215
1216 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001217 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001218 else
Arend van Spriel16886732012-12-05 15:26:04 +01001219 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001220
1221 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001222 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001223 else
Arend van Spriel16886732012-12-05 15:26:04 +01001224 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001225
1226 /* Configure Privacy for starter */
1227 if (params->privacy)
1228 wsec |= WEP_ENABLED;
1229
Arend van Sprielc1179032012-10-22 13:55:33 -07001230 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001231 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001232 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001233 goto done;
1234 }
1235
1236 /* Configure Beacon Interval for starter */
1237 if (params->beacon_interval)
1238 bcnprd = params->beacon_interval;
1239 else
1240 bcnprd = 100;
1241
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001242 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001243 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001244 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001245 goto done;
1246 }
1247
1248 /* Configure required join parameter */
1249 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1250
1251 /* SSID */
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001252 profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32);
1253 memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len);
1254 memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len);
1255 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001256 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001257
1258 /* BSSID */
1259 if (params->bssid) {
1260 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
1261 join_params_size = sizeof(join_params.ssid_le) +
1262 BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001263 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001264 } else {
Arend van Sprielba40d162012-10-22 13:55:38 -07001265 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001266 memset(profile->bssid, 0, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001267 }
1268
Arend van Spriel5b435de2011-10-05 13:19:03 +02001269 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001270 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001271 u32 target_channel;
1272
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001273 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001274 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001275 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001276 if (params->channel_fixed) {
1277 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001278 chanspec = chandef_to_chanspec(&cfg->d11inf,
1279 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001280 join_params.params_le.chanspec_list[0] =
1281 cpu_to_le16(chanspec);
1282 join_params.params_le.chanspec_num = cpu_to_le32(1);
1283 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001284 }
1285
1286 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001287 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001288 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001289 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001290 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001291 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001292 goto done;
1293 }
1294 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001295 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001296
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001297 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001298
1299
Arend van Sprielc1179032012-10-22 13:55:33 -07001300 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001301 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001302 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001303 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001304 goto done;
1305 }
1306
1307done:
1308 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001309 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001310 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001311 return err;
1312}
1313
1314static s32
1315brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1316{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001317 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001318
Arend van Sprield96b8012012-12-05 15:26:02 +01001319 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001320 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001321 return -EIO;
1322
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001323 brcmf_link_down(ifp->vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001324
Arend van Sprield96b8012012-12-05 15:26:02 +01001325 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001326
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001327 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001328}
1329
1330static s32 brcmf_set_wpa_version(struct net_device *ndev,
1331 struct cfg80211_connect_params *sme)
1332{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001333 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001334 struct brcmf_cfg80211_security *sec;
1335 s32 val = 0;
1336 s32 err = 0;
1337
1338 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1339 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1340 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1341 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1342 else
1343 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001344 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001345 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001346 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001347 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001348 return err;
1349 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001350 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001351 sec->wpa_versions = sme->crypto.wpa_versions;
1352 return err;
1353}
1354
1355static s32 brcmf_set_auth_type(struct net_device *ndev,
1356 struct cfg80211_connect_params *sme)
1357{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001358 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001359 struct brcmf_cfg80211_security *sec;
1360 s32 val = 0;
1361 s32 err = 0;
1362
1363 switch (sme->auth_type) {
1364 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1365 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001366 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001367 break;
1368 case NL80211_AUTHTYPE_SHARED_KEY:
1369 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001370 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001371 break;
1372 case NL80211_AUTHTYPE_AUTOMATIC:
1373 val = 2;
Arend van Spriel16886732012-12-05 15:26:04 +01001374 brcmf_dbg(CONN, "automatic\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001375 break;
1376 case NL80211_AUTHTYPE_NETWORK_EAP:
Arend van Spriel16886732012-12-05 15:26:04 +01001377 brcmf_dbg(CONN, "network eap\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001378 default:
1379 val = 2;
Arend van Spriel57d6e912012-12-05 15:26:00 +01001380 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001381 break;
1382 }
1383
Hante Meuleman89286dc2013-02-08 15:53:46 +01001384 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001385 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001386 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001387 return err;
1388 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001389 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001390 sec->auth_type = sme->auth_type;
1391 return err;
1392}
1393
1394static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001395brcmf_set_wsec_mode(struct net_device *ndev,
1396 struct cfg80211_connect_params *sme, bool mfp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001397{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001398 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001399 struct brcmf_cfg80211_security *sec;
1400 s32 pval = 0;
1401 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001402 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001403 s32 err = 0;
1404
1405 if (sme->crypto.n_ciphers_pairwise) {
1406 switch (sme->crypto.ciphers_pairwise[0]) {
1407 case WLAN_CIPHER_SUITE_WEP40:
1408 case WLAN_CIPHER_SUITE_WEP104:
1409 pval = WEP_ENABLED;
1410 break;
1411 case WLAN_CIPHER_SUITE_TKIP:
1412 pval = TKIP_ENABLED;
1413 break;
1414 case WLAN_CIPHER_SUITE_CCMP:
1415 pval = AES_ENABLED;
1416 break;
1417 case WLAN_CIPHER_SUITE_AES_CMAC:
1418 pval = AES_ENABLED;
1419 break;
1420 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001421 brcmf_err("invalid cipher pairwise (%d)\n",
1422 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001423 return -EINVAL;
1424 }
1425 }
1426 if (sme->crypto.cipher_group) {
1427 switch (sme->crypto.cipher_group) {
1428 case WLAN_CIPHER_SUITE_WEP40:
1429 case WLAN_CIPHER_SUITE_WEP104:
1430 gval = WEP_ENABLED;
1431 break;
1432 case WLAN_CIPHER_SUITE_TKIP:
1433 gval = TKIP_ENABLED;
1434 break;
1435 case WLAN_CIPHER_SUITE_CCMP:
1436 gval = AES_ENABLED;
1437 break;
1438 case WLAN_CIPHER_SUITE_AES_CMAC:
1439 gval = AES_ENABLED;
1440 break;
1441 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001442 brcmf_err("invalid cipher group (%d)\n",
1443 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001444 return -EINVAL;
1445 }
1446 }
1447
Arend van Spriel16886732012-12-05 15:26:04 +01001448 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001449 /* In case of privacy, but no security and WPS then simulate */
1450 /* setting AES. WPS-2.0 allows no security */
1451 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1452 sme->privacy)
1453 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001454
1455 if (mfp)
1456 wsec = pval | gval | MFP_CAPABLE;
1457 else
1458 wsec = pval | gval;
1459 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001460 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001461 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001462 return err;
1463 }
1464
Arend van Spriel06bb1232012-09-27 14:17:56 +02001465 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001466 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1467 sec->cipher_group = sme->crypto.cipher_group;
1468
1469 return err;
1470}
1471
1472static s32
1473brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1474{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001475 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001476 struct brcmf_cfg80211_security *sec;
1477 s32 val = 0;
1478 s32 err = 0;
1479
1480 if (sme->crypto.n_akm_suites) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01001481 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
1482 "wpa_auth", &val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001483 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001484 brcmf_err("could not get wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001485 return err;
1486 }
1487 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1488 switch (sme->crypto.akm_suites[0]) {
1489 case WLAN_AKM_SUITE_8021X:
1490 val = WPA_AUTH_UNSPECIFIED;
1491 break;
1492 case WLAN_AKM_SUITE_PSK:
1493 val = WPA_AUTH_PSK;
1494 break;
1495 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001496 brcmf_err("invalid cipher group (%d)\n",
1497 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001498 return -EINVAL;
1499 }
1500 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1501 switch (sme->crypto.akm_suites[0]) {
1502 case WLAN_AKM_SUITE_8021X:
1503 val = WPA2_AUTH_UNSPECIFIED;
1504 break;
1505 case WLAN_AKM_SUITE_PSK:
1506 val = WPA2_AUTH_PSK;
1507 break;
1508 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001509 brcmf_err("invalid cipher group (%d)\n",
1510 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001511 return -EINVAL;
1512 }
1513 }
1514
Arend van Spriel16886732012-12-05 15:26:04 +01001515 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001516 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
1517 "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001518 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001519 brcmf_err("could not set wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001520 return err;
1521 }
1522 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001523 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001524 sec->wpa_auth = sme->crypto.akm_suites[0];
1525
1526 return err;
1527}
1528
1529static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001530brcmf_set_sharedkey(struct net_device *ndev,
1531 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001532{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001533 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001534 struct brcmf_cfg80211_security *sec;
1535 struct brcmf_wsec_key key;
1536 s32 val;
1537 s32 err = 0;
1538
Arend van Spriel16886732012-12-05 15:26:04 +01001539 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001540
Roland Vossena718e2f2011-10-12 20:51:24 +02001541 if (sme->key_len == 0)
1542 return 0;
1543
Arend van Spriel06bb1232012-09-27 14:17:56 +02001544 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001545 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1546 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001547
1548 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1549 return 0;
1550
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001551 if (!(sec->cipher_pairwise &
1552 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1553 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001554
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001555 memset(&key, 0, sizeof(key));
1556 key.len = (u32) sme->key_len;
1557 key.index = (u32) sme->key_idx;
1558 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001559 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001560 return -EINVAL;
1561 }
1562 memcpy(key.data, sme->key, key.len);
1563 key.flags = BRCMF_PRIMARY_KEY;
1564 switch (sec->cipher_pairwise) {
1565 case WLAN_CIPHER_SUITE_WEP40:
1566 key.algo = CRYPTO_ALGO_WEP1;
1567 break;
1568 case WLAN_CIPHER_SUITE_WEP104:
1569 key.algo = CRYPTO_ALGO_WEP128;
1570 break;
1571 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001572 brcmf_err("Invalid algorithm (%d)\n",
1573 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001574 return -EINVAL;
1575 }
1576 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001577 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1578 key.len, key.index, key.algo);
1579 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07001580 err = send_key_to_dongle(ndev, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001581 if (err)
1582 return err;
1583
1584 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001585 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001586 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001587 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001588 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001589 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001590 }
1591 return err;
1592}
1593
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001594static
1595enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1596 enum nl80211_auth_type type)
1597{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001598 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1599 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1600 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1601 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001602 }
1603 return type;
1604}
1605
Arend van Spriel5b435de2011-10-05 13:19:03 +02001606static s32
1607brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001608 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001609{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001610 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001611 struct brcmf_if *ifp = netdev_priv(ndev);
1612 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001613 struct ieee80211_channel *chan = sme->channel;
1614 struct brcmf_join_params join_params;
1615 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001616 const struct brcmf_tlv *rsn_ie;
1617 const struct brcmf_vs_tlv *wpa_ie;
1618 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001619 u32 ie_len;
1620 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001621 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001622 s32 err = 0;
1623
Arend van Sprield96b8012012-12-05 15:26:02 +01001624 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001625 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001626 return -EIO;
1627
1628 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001629 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001630 return -EOPNOTSUPP;
1631 }
1632
Hante Meuleman89286dc2013-02-08 15:53:46 +01001633 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1634 /* A normal (non P2P) connection request setup. */
1635 ie = NULL;
1636 ie_len = 0;
1637 /* find the WPA_IE */
1638 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1639 if (wpa_ie) {
1640 ie = wpa_ie;
1641 ie_len = wpa_ie->len + TLV_HDR_LEN;
1642 } else {
1643 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001644 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1645 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001646 WLAN_EID_RSN);
1647 if (rsn_ie) {
1648 ie = rsn_ie;
1649 ie_len = rsn_ie->len + TLV_HDR_LEN;
1650 }
1651 }
1652 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1653 }
1654
1655 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1656 sme->ie, sme->ie_len);
1657 if (err)
1658 brcmf_err("Set Assoc REQ IE Failed\n");
1659 else
1660 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1661
Arend van Sprielc1179032012-10-22 13:55:33 -07001662 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001663
1664 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001665 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001666 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001667 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001668 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1669 cfg->channel, chan->center_freq, chanspec);
1670 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001671 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001672 chanspec = 0;
1673 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001674
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001675 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001676
1677 err = brcmf_set_wpa_version(ndev, sme);
1678 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001679 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001680 goto done;
1681 }
1682
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001683 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001684 err = brcmf_set_auth_type(ndev, sme);
1685 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001686 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001687 goto done;
1688 }
1689
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001690 err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001691 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001692 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001693 goto done;
1694 }
1695
1696 err = brcmf_set_key_mgmt(ndev, sme);
1697 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001698 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001699 goto done;
1700 }
1701
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001702 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001703 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001704 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001705 goto done;
1706 }
1707
Hante Meuleman89286dc2013-02-08 15:53:46 +01001708 profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID),
1709 (u32)sme->ssid_len);
1710 memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len);
1711 if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1712 profile->ssid.SSID[profile->ssid.SSID_len] = 0;
1713 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID,
1714 profile->ssid.SSID_len);
1715 }
1716
1717 /* Join with specific BSSID and cached SSID
1718 * If SSID is zero join based on BSSID only
1719 */
1720 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1721 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1722 if (cfg->channel)
1723 join_params_size += sizeof(u16);
1724 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1725 if (ext_join_params == NULL) {
1726 err = -ENOMEM;
1727 goto done;
1728 }
1729 ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
1730 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid,
1731 profile->ssid.SSID_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001732
Hante Meuleman89286dc2013-02-08 15:53:46 +01001733 /* Set up join scan parameters */
1734 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001735 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1736
1737 if (sme->bssid)
1738 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1739 else
1740 memset(&ext_join_params->assoc_le.bssid, 0xFF, ETH_ALEN);
1741
1742 if (cfg->channel) {
1743 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
1744
1745 ext_join_params->assoc_le.chanspec_list[0] =
1746 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001747 /* Increase dwell time to receive probe response or detect
1748 * beacon from target AP at a noisy air only during connect
1749 * command.
1750 */
1751 ext_join_params->scan_le.active_time =
1752 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
1753 ext_join_params->scan_le.passive_time =
1754 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
1755 /* To sync with presence period of VSDB GO send probe request
1756 * more frequently. Probe request will be stopped when it gets
1757 * probe response from target AP/GO.
1758 */
1759 ext_join_params->scan_le.nprobes =
1760 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
1761 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
1762 } else {
1763 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
1764 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
1765 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001766 }
1767
1768 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
1769 join_params_size);
1770 kfree(ext_join_params);
1771 if (!err)
1772 /* This is it. join command worked, we are done */
1773 goto done;
1774
1775 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02001776 memset(&join_params, 0, sizeof(join_params));
1777 join_params_size = sizeof(join_params.ssid_le);
1778
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001779 memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001780 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001781
Hante Meuleman89286dc2013-02-08 15:53:46 +01001782 if (sme->bssid)
1783 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
1784 else
1785 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001786
Hante Meuleman17012612013-02-06 18:40:44 +01001787 if (cfg->channel) {
1788 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
1789 join_params.params_le.chanspec_num = cpu_to_le32(1);
1790 join_params_size += sizeof(join_params.params_le);
1791 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001792 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001793 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001794 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01001795 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001796
1797done:
1798 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001799 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001800 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001801 return err;
1802}
1803
1804static s32
1805brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1806 u16 reason_code)
1807{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001808 struct brcmf_if *ifp = netdev_priv(ndev);
1809 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001810 struct brcmf_scb_val_le scbval;
1811 s32 err = 0;
1812
Arend van Sprield96b8012012-12-05 15:26:02 +01001813 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
Arend van Sprielce81e312012-10-22 13:55:37 -07001814 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001815 return -EIO;
1816
Arend van Sprielc1179032012-10-22 13:55:33 -07001817 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001818 cfg80211_disconnected(ndev, reason_code, NULL, 0, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001819
Arend van Spriel06bb1232012-09-27 14:17:56 +02001820 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001821 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07001822 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07001823 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001824 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001825 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001826
Arend van Sprield96b8012012-12-05 15:26:02 +01001827 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001828 return err;
1829}
1830
1831static s32
Johannes Bergc8442112012-10-24 10:17:18 +02001832brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001833 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001834{
1835
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001836 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001837 struct net_device *ndev = cfg_to_ndev(cfg);
1838 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001839 u16 txpwrmw;
1840 s32 err = 0;
1841 s32 disable = 0;
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001842 s32 dbm = MBM_TO_DBM(mbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001843
Arend van Sprield96b8012012-12-05 15:26:02 +01001844 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001845 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001846 return -EIO;
1847
1848 switch (type) {
1849 case NL80211_TX_POWER_AUTOMATIC:
1850 break;
1851 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02001852 case NL80211_TX_POWER_FIXED:
1853 if (dbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001854 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001855 err = -EINVAL;
1856 goto done;
1857 }
1858 break;
1859 }
1860 /* Make sure radio is off or on as far as software is concerned */
1861 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07001862 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001863 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001864 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001865
1866 if (dbm > 0xffff)
1867 txpwrmw = 0xffff;
1868 else
1869 txpwrmw = (u16) dbm;
Arend van Sprielac24be62012-10-22 10:36:23 -07001870 err = brcmf_fil_iovar_int_set(ifp, "qtxpower",
1871 (s32)brcmf_mw_to_qdbm(txpwrmw));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001872 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001873 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001874 cfg->conf->tx_power = dbm;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001875
1876done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001877 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001878 return err;
1879}
1880
Johannes Bergc8442112012-10-24 10:17:18 +02001881static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy,
1882 struct wireless_dev *wdev,
1883 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001884{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001885 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001886 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001887 s32 txpwrdbm;
1888 u8 result;
1889 s32 err = 0;
1890
Arend van Sprield96b8012012-12-05 15:26:02 +01001891 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001892 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001893 return -EIO;
1894
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001895 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &txpwrdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001896 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001897 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001898 goto done;
1899 }
1900
1901 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
Alwin Beukersef6ac172011-10-12 20:51:26 +02001902 *dbm = (s32) brcmf_qdbm_to_mw(result);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001903
1904done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001905 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001906 return err;
1907}
1908
1909static s32
1910brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
1911 u8 key_idx, bool unicast, bool multicast)
1912{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001913 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001914 u32 index;
1915 u32 wsec;
1916 s32 err = 0;
1917
Arend van Sprield96b8012012-12-05 15:26:02 +01001918 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01001919 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07001920 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001921 return -EIO;
1922
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001923 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001924 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001925 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001926 goto done;
1927 }
1928
1929 if (wsec & WEP_ENABLED) {
1930 /* Just select a new current key */
1931 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001932 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001933 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001934 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001935 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001936 }
1937done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001938 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001939 return err;
1940}
1941
1942static s32
1943brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
1944 u8 key_idx, const u8 *mac_addr, struct key_params *params)
1945{
Hante Meuleman992f6062013-04-02 21:06:17 +02001946 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001947 struct brcmf_wsec_key key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001948 s32 err = 0;
Hante Meuleman992f6062013-04-02 21:06:17 +02001949 u8 keybuf[8];
Arend van Spriel5b435de2011-10-05 13:19:03 +02001950
1951 memset(&key, 0, sizeof(key));
1952 key.index = (u32) key_idx;
1953 /* Instead of bcast for ea address for default wep keys,
1954 driver needs it to be Null */
1955 if (!is_multicast_ether_addr(mac_addr))
1956 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
1957 key.len = (u32) params->key_len;
1958 /* check for key index change */
1959 if (key.len == 0) {
1960 /* key delete */
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07001961 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001962 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001963 brcmf_err("key delete error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001964 } else {
1965 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001966 brcmf_err("Invalid key length (%d)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001967 return -EINVAL;
1968 }
1969
Arend van Spriel16886732012-12-05 15:26:04 +01001970 brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001971 memcpy(key.data, params->key, key.len);
1972
Arend van Spriel967fe2c2014-03-15 17:18:21 +01001973 if (!brcmf_is_apmode(ifp->vif) &&
Hante Meuleman992f6062013-04-02 21:06:17 +02001974 (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
1975 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001976 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1977 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1978 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1979 }
1980
1981 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1982 if (params->seq && params->seq_len == 6) {
1983 /* rx iv */
1984 u8 *ivptr;
1985 ivptr = (u8 *) params->seq;
1986 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
1987 (ivptr[3] << 8) | ivptr[2];
1988 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
1989 key.iv_initialized = true;
1990 }
1991
1992 switch (params->cipher) {
1993 case WLAN_CIPHER_SUITE_WEP40:
1994 key.algo = CRYPTO_ALGO_WEP1;
Arend van Spriel16886732012-12-05 15:26:04 +01001995 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001996 break;
1997 case WLAN_CIPHER_SUITE_WEP104:
1998 key.algo = CRYPTO_ALGO_WEP128;
Arend van Spriel16886732012-12-05 15:26:04 +01001999 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002000 break;
2001 case WLAN_CIPHER_SUITE_TKIP:
2002 key.algo = CRYPTO_ALGO_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002003 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002004 break;
2005 case WLAN_CIPHER_SUITE_AES_CMAC:
2006 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002007 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002008 break;
2009 case WLAN_CIPHER_SUITE_CCMP:
2010 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002011 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002012 break;
2013 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002014 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002015 return -EINVAL;
2016 }
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002017 err = send_key_to_dongle(ndev, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002018 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002019 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002020 }
2021 return err;
2022}
2023
2024static s32
2025brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2026 u8 key_idx, bool pairwise, const u8 *mac_addr,
2027 struct key_params *params)
2028{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002029 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002030 struct brcmf_wsec_key key;
2031 s32 val;
2032 s32 wsec;
2033 s32 err = 0;
2034 u8 keybuf[8];
2035
Arend van Sprield96b8012012-12-05 15:26:02 +01002036 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002037 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002038 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002039 return -EIO;
2040
Daniel Kim787eb032014-01-29 15:32:23 +01002041 if (mac_addr &&
2042 (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2043 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01002044 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002045 return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
2046 }
2047 memset(&key, 0, sizeof(key));
2048
2049 key.len = (u32) params->key_len;
2050 key.index = (u32) key_idx;
2051
2052 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002053 brcmf_err("Too long key length (%u)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002054 err = -EINVAL;
2055 goto done;
2056 }
2057 memcpy(key.data, params->key, key.len);
2058
2059 key.flags = BRCMF_PRIMARY_KEY;
2060 switch (params->cipher) {
2061 case WLAN_CIPHER_SUITE_WEP40:
2062 key.algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002063 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002064 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002065 break;
2066 case WLAN_CIPHER_SUITE_WEP104:
2067 key.algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002068 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002069 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002070 break;
2071 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002072 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002073 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02002074 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2075 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2076 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2077 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002078 key.algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002079 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002080 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002081 break;
2082 case WLAN_CIPHER_SUITE_AES_CMAC:
2083 key.algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002084 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002085 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002086 break;
2087 case WLAN_CIPHER_SUITE_CCMP:
2088 key.algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002089 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002090 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002091 break;
2092 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002093 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002094 err = -EINVAL;
2095 goto done;
2096 }
2097
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002098 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002099 if (err)
2100 goto done;
2101
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002102 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002103 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002104 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002105 goto done;
2106 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002107 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002108 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002109 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002110 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002111 goto done;
2112 }
2113
Arend van Spriel5b435de2011-10-05 13:19:03 +02002114done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002115 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002116 return err;
2117}
2118
2119static s32
2120brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2121 u8 key_idx, bool pairwise, const u8 *mac_addr)
2122{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002123 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002124 struct brcmf_wsec_key key;
2125 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002126
Arend van Sprield96b8012012-12-05 15:26:02 +01002127 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002128 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002129 return -EIO;
2130
Hante Meuleman256c3742012-11-05 16:22:28 -08002131 if (key_idx >= DOT11_MAX_DEFAULT_KEYS) {
2132 /* we ignore this key index in this case */
Arend van Spriel57d6e912012-12-05 15:26:00 +01002133 brcmf_err("invalid key index (%d)\n", key_idx);
Hante Meuleman256c3742012-11-05 16:22:28 -08002134 return -EINVAL;
2135 }
2136
Arend van Spriel5b435de2011-10-05 13:19:03 +02002137 memset(&key, 0, sizeof(key));
2138
2139 key.index = (u32) key_idx;
2140 key.flags = BRCMF_PRIMARY_KEY;
2141 key.algo = CRYPTO_ALGO_OFF;
2142
Arend van Spriel16886732012-12-05 15:26:04 +01002143 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002144
2145 /* Set the new key/index */
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002146 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002147
Arend van Sprield96b8012012-12-05 15:26:02 +01002148 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002149 return err;
2150}
2151
2152static s32
2153brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2154 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
2155 void (*callback) (void *cookie, struct key_params * params))
2156{
2157 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002158 struct brcmf_if *ifp = netdev_priv(ndev);
2159 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002160 struct brcmf_cfg80211_security *sec;
2161 s32 wsec;
2162 s32 err = 0;
2163
Arend van Sprield96b8012012-12-05 15:26:02 +01002164 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002165 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002166 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002167 return -EIO;
2168
2169 memset(&params, 0, sizeof(params));
2170
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002171 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002172 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002173 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002174 /* Ignore this error, may happen during DISASSOC */
2175 err = -EAGAIN;
2176 goto done;
2177 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002178 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002179 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002180 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2181 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002182 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002183 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2184 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002185 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002186 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002187 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002188 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002189 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002190 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002191 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002192 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002193 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002194 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002195 err = -EINVAL;
2196 goto done;
2197 }
2198 callback(cookie, &params);
2199
2200done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002201 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002202 return err;
2203}
2204
2205static s32
2206brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2207 struct net_device *ndev, u8 key_idx)
2208{
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002209 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002210
2211 return -EOPNOTSUPP;
2212}
2213
2214static s32
2215brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002216 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002217{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002218 struct brcmf_if *ifp = netdev_priv(ndev);
2219 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002220 struct brcmf_scb_val_le scb_val;
2221 int rssi;
2222 s32 rate;
2223 s32 err = 0;
Arend van Spriel06bb1232012-09-27 14:17:56 +02002224 u8 *bssid = profile->bssid;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002225 struct brcmf_sta_info_le sta_info_le;
Hante Meuleman9ee66d12014-01-29 15:32:11 +01002226 u32 beacon_period;
2227 u32 dtim_period;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002228
Arend van Sprield96b8012012-12-05 15:26:02 +01002229 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002230 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002231 return -EIO;
2232
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002233 if (brcmf_is_apmode(ifp->vif)) {
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002234 memcpy(&sta_info_le, mac, ETH_ALEN);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002235 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002236 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002237 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002238 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002239 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002240 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002241 }
Hante Meuleman1a873342012-09-27 14:17:54 +02002242 sinfo->filled = STATION_INFO_INACTIVE_TIME;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002243 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2244 if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002245 sinfo->filled |= STATION_INFO_CONNECTED_TIME;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002246 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
Hante Meuleman1a873342012-09-27 14:17:54 +02002247 }
Arend van Sprield96b8012012-12-05 15:26:02 +01002248 brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n",
2249 sinfo->inactive_time, sinfo->connected_time);
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002250 } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002251 if (memcmp(mac, bssid, ETH_ALEN)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002252 brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
2253 mac, bssid);
Hante Meuleman1a873342012-09-27 14:17:54 +02002254 err = -ENOENT;
2255 goto done;
2256 }
2257 /* Report the current tx rate */
Hante Meuleman89286dc2013-02-08 15:53:46 +01002258 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
Hante Meuleman1a873342012-09-27 14:17:54 +02002259 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002260 brcmf_err("Could not get rate (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002261 goto done;
2262 } else {
2263 sinfo->filled |= STATION_INFO_TX_BITRATE;
2264 sinfo->txrate.legacy = rate * 5;
Arend van Spriel16886732012-12-05 15:26:04 +01002265 brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2);
Hante Meuleman1a873342012-09-27 14:17:54 +02002266 }
2267
Arend van Sprielc1179032012-10-22 13:55:33 -07002268 if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
2269 &ifp->vif->sme_state)) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002270 memset(&scb_val, 0, sizeof(scb_val));
Arend van Sprielc1179032012-10-22 13:55:33 -07002271 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
2272 &scb_val, sizeof(scb_val));
Hante Meuleman1a873342012-09-27 14:17:54 +02002273 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002274 brcmf_err("Could not get rssi (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002275 goto done;
2276 } else {
2277 rssi = le32_to_cpu(scb_val.val);
2278 sinfo->filled |= STATION_INFO_SIGNAL;
2279 sinfo->signal = rssi;
Arend van Spriel16886732012-12-05 15:26:04 +01002280 brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
Hante Meuleman1a873342012-09-27 14:17:54 +02002281 }
Hante Meuleman9ee66d12014-01-29 15:32:11 +01002282 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD,
2283 &beacon_period);
2284 if (err) {
2285 brcmf_err("Could not get beacon period (%d)\n",
2286 err);
2287 goto done;
2288 } else {
2289 sinfo->bss_param.beacon_interval =
2290 beacon_period;
2291 brcmf_dbg(CONN, "Beacon peroid %d\n",
2292 beacon_period);
2293 }
2294 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD,
2295 &dtim_period);
2296 if (err) {
2297 brcmf_err("Could not get DTIM period (%d)\n",
2298 err);
2299 goto done;
2300 } else {
2301 sinfo->bss_param.dtim_period = dtim_period;
2302 brcmf_dbg(CONN, "DTIM peroid %d\n",
2303 dtim_period);
2304 }
2305 sinfo->filled |= STATION_INFO_BSS_PARAM;
Hante Meuleman1a873342012-09-27 14:17:54 +02002306 }
2307 } else
2308 err = -EPERM;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002309done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002310 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002311 return err;
2312}
2313
2314static s32
2315brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2316 bool enabled, s32 timeout)
2317{
2318 s32 pm;
2319 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002320 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002321 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002322
Arend van Sprield96b8012012-12-05 15:26:02 +01002323 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002324
2325 /*
2326 * Powersave enable/disable request is coming from the
2327 * cfg80211 even before the interface is up. In that
2328 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002329 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002330 * FW later while initializing the dongle
2331 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002332 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002333 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002334
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002335 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002336 goto done;
2337 }
2338
2339 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002340 /* Do not enable the power save after assoc if it is a p2p interface */
2341 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2342 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2343 pm = PM_OFF;
2344 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002345 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002346
Arend van Sprielc1179032012-10-22 13:55:33 -07002347 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002348 if (err) {
2349 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002350 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002351 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002352 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002353 }
2354done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002355 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002356 return err;
2357}
2358
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002359static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002360 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002361{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002362 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002363 struct ieee80211_channel *notify_channel;
2364 struct cfg80211_bss *bss;
2365 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002366 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002367 u16 channel;
2368 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002369 u16 notify_capability;
2370 u16 notify_interval;
2371 u8 *notify_ie;
2372 size_t notify_ielen;
2373 s32 notify_signal;
2374
2375 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002376 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002377 return 0;
2378 }
2379
Franky Lin83cf17a2013-04-11 13:28:50 +02002380 if (!bi->ctl_ch) {
2381 ch.chspec = le16_to_cpu(bi->chanspec);
2382 cfg->d11inf.decchspec(&ch);
2383 bi->ctl_ch = ch.chnum;
2384 }
2385 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002386
2387 if (channel <= CH_MAX_2G_CHANNEL)
2388 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2389 else
2390 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2391
2392 freq = ieee80211_channel_to_frequency(channel, band->band);
2393 notify_channel = ieee80211_get_channel(wiphy, freq);
2394
Arend van Spriel5b435de2011-10-05 13:19:03 +02002395 notify_capability = le16_to_cpu(bi->capability);
2396 notify_interval = le16_to_cpu(bi->beacon_period);
2397 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2398 notify_ielen = le32_to_cpu(bi->ie_length);
2399 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2400
Arend van Spriel16886732012-12-05 15:26:04 +01002401 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2402 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2403 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2404 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2405 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002406
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002407 bss = cfg80211_inform_bss(wiphy, notify_channel,
2408 CFG80211_BSS_FTYPE_UNKNOWN,
2409 (const u8 *)bi->BSSID,
2410 0, notify_capability,
2411 notify_interval, notify_ie,
2412 notify_ielen, notify_signal,
2413 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002414
Franky Line78946e2011-11-10 20:30:34 +01002415 if (!bss)
2416 return -ENOMEM;
2417
Johannes Berg5b112d32013-02-01 01:49:58 +01002418 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002419
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002420 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002421}
2422
Roland Vossen6f09be02011-10-18 14:03:02 +02002423static struct brcmf_bss_info_le *
2424next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2425{
2426 if (bss == NULL)
2427 return list->bss_info_le;
2428 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2429 le32_to_cpu(bss->length));
2430}
2431
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002432static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002433{
2434 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002435 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002436 s32 err = 0;
2437 int i;
2438
Hante Meulemanef8596e2014-09-30 10:23:13 +02002439 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002440 if (bss_list->count != 0 &&
2441 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002442 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2443 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002444 return -EOPNOTSUPP;
2445 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002446 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002447 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002448 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002449 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002450 if (err)
2451 break;
2452 }
2453 return err;
2454}
2455
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002456static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002457 struct net_device *ndev, const u8 *bssid)
2458{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002459 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002460 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002461 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002462 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002463 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002464 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002465 u8 *buf = NULL;
2466 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002467 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002468 u16 notify_capability;
2469 u16 notify_interval;
2470 u8 *notify_ie;
2471 size_t notify_ielen;
2472 s32 notify_signal;
2473
Arend van Sprield96b8012012-12-05 15:26:02 +01002474 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002475
2476 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2477 if (buf == NULL) {
2478 err = -ENOMEM;
2479 goto CleanUp;
2480 }
2481
2482 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2483
Arend van Sprielac24be62012-10-22 10:36:23 -07002484 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2485 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002486 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002487 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002488 goto CleanUp;
2489 }
2490
Roland Vossend34bf642011-10-18 14:03:01 +02002491 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002492
Franky Lin83cf17a2013-04-11 13:28:50 +02002493 ch.chspec = le16_to_cpu(bi->chanspec);
2494 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002495
Franky Lin83cf17a2013-04-11 13:28:50 +02002496 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002497 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2498 else
2499 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2500
Franky Lin83cf17a2013-04-11 13:28:50 +02002501 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002502 notify_channel = ieee80211_get_channel(wiphy, freq);
2503
Arend van Spriel5b435de2011-10-05 13:19:03 +02002504 notify_capability = le16_to_cpu(bi->capability);
2505 notify_interval = le16_to_cpu(bi->beacon_period);
2506 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2507 notify_ielen = le32_to_cpu(bi->ie_length);
2508 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2509
Franky Lin83cf17a2013-04-11 13:28:50 +02002510 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002511 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2512 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2513 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002514
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002515 bss = cfg80211_inform_bss(wiphy, notify_channel,
2516 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2517 notify_capability, notify_interval,
2518 notify_ie, notify_ielen, notify_signal,
2519 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002520
Franky Line78946e2011-11-10 20:30:34 +01002521 if (!bss) {
2522 err = -ENOMEM;
2523 goto CleanUp;
2524 }
2525
Johannes Berg5b112d32013-02-01 01:49:58 +01002526 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002527
Arend van Spriel5b435de2011-10-05 13:19:03 +02002528CleanUp:
2529
2530 kfree(buf);
2531
Arend van Sprield96b8012012-12-05 15:26:02 +01002532 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002533
2534 return err;
2535}
2536
Hante Meuleman89286dc2013-02-08 15:53:46 +01002537static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2538 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002539{
Hante Meuleman89286dc2013-02-08 15:53:46 +01002540 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev);
Roland Vossend34bf642011-10-18 14:03:01 +02002541 struct brcmf_bss_info_le *bi;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002542 struct brcmf_ssid *ssid;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002543 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002544 u16 beacon_interval;
2545 u8 dtim_period;
2546 size_t ie_len;
2547 u8 *ie;
2548 s32 err = 0;
2549
Arend van Sprield96b8012012-12-05 15:26:02 +01002550 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002551 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002552 return err;
2553
Arend van Spriel06bb1232012-09-27 14:17:56 +02002554 ssid = &profile->ssid;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002555
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002556 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002557 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002558 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002559 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002560 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002561 goto update_bss_info_out;
2562 }
2563
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002564 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2565 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002566 if (err)
2567 goto update_bss_info_out;
2568
2569 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2570 ie_len = le32_to_cpu(bi->ie_length);
2571 beacon_interval = le16_to_cpu(bi->beacon_period);
2572
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002573 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002574 if (tim)
2575 dtim_period = tim->data[1];
2576 else {
2577 /*
2578 * active scan was done so we could not get dtim
2579 * information out of probe response.
2580 * so we speficially query dtim information to dongle.
2581 */
2582 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002583 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002584 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002585 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002586 goto update_bss_info_out;
2587 }
2588 dtim_period = (u8)var;
2589 }
2590
Arend van Spriel5b435de2011-10-05 13:19:03 +02002591update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01002592 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002593 return err;
2594}
2595
Hante Meuleman18e2f612013-02-08 15:53:49 +01002596void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002597{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002598 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002599
Arend van Sprielc1179032012-10-22 13:55:33 -07002600 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Hante Meulemanf07998952012-11-05 16:22:13 -08002601 if (cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02002602 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002603 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02002604 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002605 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2606 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002607}
2608
Hante Meulemane756af52012-09-11 21:18:52 +02002609static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2610{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002611 struct brcmf_cfg80211_info *cfg =
2612 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02002613 escan_timeout_work);
2614
Hante Meulemanef8596e2014-09-30 10:23:13 +02002615 brcmf_inform_bss(cfg);
Arend van Spriela0f472a2013-04-05 10:57:49 +02002616 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02002617}
2618
2619static void brcmf_escan_timeout(unsigned long data)
2620{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002621 struct brcmf_cfg80211_info *cfg =
2622 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02002623
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002624 if (cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002625 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08002626 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02002627 }
2628}
2629
2630static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02002631brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2632 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02002633 struct brcmf_bss_info_le *bss_info_le)
2634{
Franky Lin83cf17a2013-04-11 13:28:50 +02002635 struct brcmu_chan ch_bss, ch_bss_info_le;
2636
2637 ch_bss.chspec = le16_to_cpu(bss->chanspec);
2638 cfg->d11inf.decchspec(&ch_bss);
2639 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
2640 cfg->d11inf.decchspec(&ch_bss_info_le);
2641
Hante Meulemane756af52012-09-11 21:18:52 +02002642 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02002643 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02002644 bss_info_le->SSID_len == bss->SSID_len &&
2645 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002646 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
2647 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02002648 s16 bss_rssi = le16_to_cpu(bss->RSSI);
2649 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
2650
Hante Meulemane756af52012-09-11 21:18:52 +02002651 /* preserve max RSSI if the measurements are
2652 * both on-channel or both off-channel
2653 */
Arend van Spriel029591f2012-09-19 22:21:06 +02002654 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02002655 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002656 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
2657 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02002658 /* preserve the on-channel rssi measurement
2659 * if the new measurement is off channel
2660 */
2661 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002662 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02002663 }
2664 return 1;
2665 }
2666 return 0;
2667}
2668
2669static s32
Arend van Spriel19937322012-11-05 16:22:32 -08002670brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02002671 const struct brcmf_event_msg *e, void *data)
2672{
Arend van Spriel19937322012-11-05 16:22:32 -08002673 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02002674 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02002675 struct brcmf_escan_result_le *escan_result_le;
2676 struct brcmf_bss_info_le *bss_info_le;
2677 struct brcmf_bss_info_le *bss = NULL;
2678 u32 bi_length;
2679 struct brcmf_scan_results *list;
2680 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002681 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02002682
Arend van Spriel5c36b992012-11-14 18:46:05 -08002683 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02002684
Arend van Spriela0f472a2013-04-05 10:57:49 +02002685 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
2686 brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx);
Hante Meulemane756af52012-09-11 21:18:52 +02002687 return -EPERM;
2688 }
2689
2690 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002691 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002692 escan_result_le = (struct brcmf_escan_result_le *) data;
2693 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002694 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002695 goto exit;
2696 }
Hante Meulemane756af52012-09-11 21:18:52 +02002697 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002698 brcmf_err("Invalid bss_count %d: ignoring\n",
2699 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02002700 goto exit;
2701 }
2702 bss_info_le = &escan_result_le->bss_info_le;
2703
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002704 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
2705 goto exit;
2706
2707 if (!cfg->scan_request) {
2708 brcmf_dbg(SCAN, "result without cfg80211 request\n");
2709 goto exit;
2710 }
2711
Hante Meulemane756af52012-09-11 21:18:52 +02002712 bi_length = le32_to_cpu(bss_info_le->length);
2713 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
2714 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002715 brcmf_err("Invalid bss_info length %d: ignoring\n",
2716 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02002717 goto exit;
2718 }
2719
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002720 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02002721 BIT(NL80211_IFTYPE_ADHOC))) {
2722 if (le16_to_cpu(bss_info_le->capability) &
2723 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002724 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002725 goto exit;
2726 }
2727 }
2728
2729 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002730 cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02002731 if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002732 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002733 goto exit;
2734 }
2735
2736 for (i = 0; i < list->count; i++) {
2737 bss = bss ? (struct brcmf_bss_info_le *)
2738 ((unsigned char *)bss +
2739 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02002740 if (brcmf_compare_update_same_bss(cfg, bss,
2741 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02002742 goto exit;
2743 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002744 memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
Hante Meulemane756af52012-09-11 21:18:52 +02002745 bss_info_le, bi_length);
2746 list->version = le32_to_cpu(bss_info_le->version);
2747 list->buflen += bi_length;
2748 list->count++;
2749 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002750 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002751 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
2752 goto exit;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002753 if (cfg->scan_request) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002754 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002755 aborted = status != BRCMF_E_STATUS_SUCCESS;
Hante Meulemanef8596e2014-09-30 10:23:13 +02002756 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
Hante Meulemane756af52012-09-11 21:18:52 +02002757 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002758 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
2759 status);
Hante Meulemane756af52012-09-11 21:18:52 +02002760 }
2761exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002762 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02002763}
2764
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002765static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02002766{
Arend van Spriel5c36b992012-11-14 18:46:05 -08002767 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
2768 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08002769 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
2770 /* Init scan_timeout timer */
2771 init_timer(&cfg->escan_timeout);
2772 cfg->escan_timeout.data = (unsigned long) cfg;
2773 cfg->escan_timeout.function = brcmf_escan_timeout;
2774 INIT_WORK(&cfg->escan_timeout_work,
2775 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02002776}
2777
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05002778static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002779{
2780 if (ms < 1000 / HZ) {
2781 cond_resched();
2782 mdelay(ms);
2783 } else {
2784 msleep(ms);
2785 }
2786}
2787
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002788static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
2789 u8 *pattern, u32 patternsize, u8 *mask,
2790 u32 packet_offset)
2791{
2792 struct brcmf_fil_wowl_pattern_le *filter;
2793 u32 masksize;
2794 u32 patternoffset;
2795 u8 *buf;
2796 u32 bufsize;
2797 s32 ret;
2798
2799 masksize = (patternsize + 7) / 8;
2800 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
2801
2802 bufsize = sizeof(*filter) + patternsize + masksize;
2803 buf = kzalloc(bufsize, GFP_KERNEL);
2804 if (!buf)
2805 return -ENOMEM;
2806 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
2807
2808 memcpy(filter->cmd, cmd, 4);
2809 filter->masksize = cpu_to_le32(masksize);
2810 filter->offset = cpu_to_le32(packet_offset);
2811 filter->patternoffset = cpu_to_le32(patternoffset);
2812 filter->patternsize = cpu_to_le32(patternsize);
2813 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
2814
2815 if ((mask) && (masksize))
2816 memcpy(buf + sizeof(*filter), mask, masksize);
2817 if ((pattern) && (patternsize))
2818 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
2819
2820 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
2821
2822 kfree(buf);
2823 return ret;
2824}
2825
Arend van Spriel5b435de2011-10-05 13:19:03 +02002826static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
2827{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002828 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2829 struct net_device *ndev = cfg_to_ndev(cfg);
2830 struct brcmf_if *ifp = netdev_priv(ndev);
2831
Arend van Sprield96b8012012-12-05 15:26:02 +01002832 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002833
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002834 if (cfg->wowl_enabled) {
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002835 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002836 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
2837 cfg->pre_wowl_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002838 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002839 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002840 cfg->wowl_enabled = false;
2841 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002842 return 0;
2843}
2844
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002845static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
2846 struct brcmf_if *ifp,
2847 struct cfg80211_wowlan *wowl)
2848{
2849 u32 wowl_config;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002850 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002851
2852 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
2853
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002854 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002855 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode);
2856 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
2857
2858 wowl_config = 0;
2859 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002860 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002861 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002862 wowl_config |= BRCMF_WOWL_MAGIC;
2863 if ((wowl->patterns) && (wowl->n_patterns)) {
2864 wowl_config |= BRCMF_WOWL_NET;
2865 for (i = 0; i < wowl->n_patterns; i++) {
2866 brcmf_config_wowl_pattern(ifp, "add",
2867 (u8 *)wowl->patterns[i].pattern,
2868 wowl->patterns[i].pattern_len,
2869 (u8 *)wowl->patterns[i].mask,
2870 wowl->patterns[i].pkt_offset);
2871 }
2872 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002873 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
2874 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
2875 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
2876 cfg->wowl_enabled = true;
2877}
2878
Arend van Spriel5b435de2011-10-05 13:19:03 +02002879static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002880 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002881{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002882 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2883 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002884 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07002885 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002886
Arend van Sprield96b8012012-12-05 15:26:02 +01002887 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002888
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002889 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07002890 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02002891 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002892 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07002893 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002894
Arend van Spriel7d641072012-10-22 13:55:39 -07002895 /* end any scanning */
2896 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002897 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002898
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002899 if (wowl == NULL) {
2900 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
2901 list_for_each_entry(vif, &cfg->vif_list, list) {
2902 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
2903 continue;
2904 /* While going to suspend if associated with AP
2905 * disassociate from AP to save power while system is
2906 * in suspended state
2907 */
2908 brcmf_link_down(vif);
2909 /* Make sure WPA_Supplicant receives all the event
2910 * generated due to DISASSOC call to the fw to keep
2911 * the state fw and WPA_Supplicant state consistent
2912 */
2913 brcmf_delay(500);
2914 }
2915 /* Configure MPC */
2916 brcmf_set_mpc(ifp, 1);
2917
2918 } else {
2919 /* Configure WOWL paramaters */
2920 brcmf_configure_wowl(cfg, ifp, wowl);
2921 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002922
Arend van Spriel7d641072012-10-22 13:55:39 -07002923exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01002924 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07002925 /* clear any scanning activity */
2926 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002927 return 0;
2928}
2929
2930static __used s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02002931brcmf_update_pmklist(struct net_device *ndev,
2932 struct brcmf_cfg80211_pmk_list *pmk_list, s32 err)
2933{
2934 int i, j;
Arend van Sprielc15d7892014-11-20 22:26:59 +01002935 u32 pmkid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002936
Arend van Spriel40c8e952011-10-12 20:51:20 +02002937 pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid);
2938
Arend van Spriel16886732012-12-05 15:26:04 +01002939 brcmf_dbg(CONN, "No of elements %d\n", pmkid_len);
Arend van Spriel40c8e952011-10-12 20:51:20 +02002940 for (i = 0; i < pmkid_len; i++) {
Arend van Spriel16886732012-12-05 15:26:04 +01002941 brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i,
2942 &pmk_list->pmkids.pmkid[i].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002943 for (j = 0; j < WLAN_PMKID_LEN; j++)
Arend van Spriel16886732012-12-05 15:26:04 +01002944 brcmf_dbg(CONN, "%02x\n",
2945 pmk_list->pmkids.pmkid[i].PMKID[j]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002946 }
2947
2948 if (!err)
Arend van Sprielac24be62012-10-22 10:36:23 -07002949 brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info",
2950 (char *)pmk_list, sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002951
2952 return err;
2953}
2954
2955static s32
2956brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
2957 struct cfg80211_pmksa *pmksa)
2958{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002959 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002960 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002961 struct pmkid_list *pmkids = &cfg->pmk_list->pmkids;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002962 s32 err = 0;
Arend van Sprielc15d7892014-11-20 22:26:59 +01002963 u32 pmkid_len, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002964
Arend van Sprield96b8012012-12-05 15:26:02 +01002965 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002966 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002967 return -EIO;
2968
Arend van Spriel40c8e952011-10-12 20:51:20 +02002969 pmkid_len = le32_to_cpu(pmkids->npmkid);
2970 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002971 if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN))
2972 break;
2973 if (i < WL_NUM_PMKIDS_MAX) {
2974 memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN);
2975 memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
Arend van Spriel40c8e952011-10-12 20:51:20 +02002976 if (i == pmkid_len) {
2977 pmkid_len++;
2978 pmkids->npmkid = cpu_to_le32(pmkid_len);
2979 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002980 } else
2981 err = -EINVAL;
2982
Arend van Spriel16886732012-12-05 15:26:04 +01002983 brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2984 pmkids->pmkid[pmkid_len].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002985 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01002986 brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002987
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002988 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002989
Arend van Sprield96b8012012-12-05 15:26:02 +01002990 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002991 return err;
2992}
2993
2994static s32
2995brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
2996 struct cfg80211_pmksa *pmksa)
2997{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002998 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002999 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003000 struct pmkid_list pmkid;
3001 s32 err = 0;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003002 u32 pmkid_len, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003003
Arend van Sprield96b8012012-12-05 15:26:02 +01003004 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003005 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003006 return -EIO;
3007
3008 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
3009 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
3010
Arend van Spriel16886732012-12-05 15:26:04 +01003011 brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3012 &pmkid.pmkid[0].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003013 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01003014 brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003015
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003016 pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003017 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003018 if (!memcmp
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003019 (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003020 ETH_ALEN))
3021 break;
3022
Arend van Spriel40c8e952011-10-12 20:51:20 +02003023 if ((pmkid_len > 0)
3024 && (i < pmkid_len)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003025 memset(&cfg->pmk_list->pmkids.pmkid[i], 0,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003026 sizeof(struct pmkid));
Arend van Spriel40c8e952011-10-12 20:51:20 +02003027 for (; i < (pmkid_len - 1); i++) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003028 memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID,
3029 &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003030 ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003031 memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID,
3032 &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003033 WLAN_PMKID_LEN);
3034 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003035 cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003036 } else
3037 err = -EINVAL;
3038
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003039 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003040
Arend van Sprield96b8012012-12-05 15:26:02 +01003041 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003042 return err;
3043
3044}
3045
3046static s32
3047brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3048{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003049 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003050 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003051 s32 err = 0;
3052
Arend van Sprield96b8012012-12-05 15:26:02 +01003053 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003054 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003055 return -EIO;
3056
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003057 memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list));
3058 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003059
Arend van Sprield96b8012012-12-05 15:26:02 +01003060 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003061 return err;
3062
3063}
3064
Arend van Spriele5806072012-09-19 22:21:08 +02003065/*
3066 * PFN result doesn't have all the info which are
3067 * required by the supplicant
3068 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3069 * via wl_inform_single_bss in the required format. Escan does require the
3070 * scan request in the form of cfg80211_scan_request. For timebeing, create
3071 * cfg80211_scan_request one out of the received PNO event.
3072 */
3073static s32
Arend van Spriel19937322012-11-05 16:22:32 -08003074brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
Arend van Spriele5806072012-09-19 22:21:08 +02003075 const struct brcmf_event_msg *e, void *data)
3076{
Arend van Spriel19937322012-11-05 16:22:32 -08003077 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriele5806072012-09-19 22:21:08 +02003078 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3079 struct cfg80211_scan_request *request = NULL;
3080 struct cfg80211_ssid *ssid = NULL;
3081 struct ieee80211_channel *channel = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003082 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003083 int err = 0;
3084 int channel_req = 0;
3085 int band = 0;
3086 struct brcmf_pno_scanresults_le *pfn_result;
3087 u32 result_count;
3088 u32 status;
3089
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003090 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003091
Arend van Spriel5c36b992012-11-14 18:46:05 -08003092 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003093 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003094 return 0;
3095 }
3096
3097 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3098 result_count = le32_to_cpu(pfn_result->count);
3099 status = le32_to_cpu(pfn_result->status);
3100
3101 /*
3102 * PFN event is limited to fit 512 bytes so we may get
3103 * multiple NET_FOUND events. For now place a warning here.
3104 */
3105 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003106 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
Arend van Spriele5806072012-09-19 22:21:08 +02003107 if (result_count > 0) {
3108 int i;
3109
3110 request = kzalloc(sizeof(*request), GFP_KERNEL);
Dan Carpenter58901d12012-09-26 10:21:48 +03003111 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3112 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
Arend van Spriele5806072012-09-19 22:21:08 +02003113 if (!request || !ssid || !channel) {
3114 err = -ENOMEM;
3115 goto out_err;
3116 }
3117
3118 request->wiphy = wiphy;
3119 data += sizeof(struct brcmf_pno_scanresults_le);
3120 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3121
3122 for (i = 0; i < result_count; i++) {
3123 netinfo = &netinfo_start[i];
3124 if (!netinfo) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003125 brcmf_err("Invalid netinfo ptr. index: %d\n",
3126 i);
Arend van Spriele5806072012-09-19 22:21:08 +02003127 err = -EINVAL;
3128 goto out_err;
3129 }
3130
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003131 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3132 netinfo->SSID, netinfo->channel);
Arend van Spriele5806072012-09-19 22:21:08 +02003133 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3134 ssid[i].ssid_len = netinfo->SSID_len;
3135 request->n_ssids++;
3136
3137 channel_req = netinfo->channel;
3138 if (channel_req <= CH_MAX_2G_CHANNEL)
3139 band = NL80211_BAND_2GHZ;
3140 else
3141 band = NL80211_BAND_5GHZ;
3142 channel[i].center_freq =
3143 ieee80211_channel_to_frequency(channel_req,
3144 band);
3145 channel[i].band = band;
3146 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3147 request->channels[i] = &channel[i];
3148 request->n_channels++;
3149 }
3150
3151 /* assign parsed ssid array */
3152 if (request->n_ssids)
3153 request->ssids = &ssid[0];
3154
Arend van Sprielc1179032012-10-22 13:55:33 -07003155 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriele5806072012-09-19 22:21:08 +02003156 /* Abort any on-going scan */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003157 brcmf_abort_scanning(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003158 }
3159
Arend van Sprielc1179032012-10-22 13:55:33 -07003160 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel2668b0b2014-01-13 22:20:28 +01003161 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02003162 err = brcmf_do_escan(cfg, wiphy, ifp, request);
Arend van Spriele5806072012-09-19 22:21:08 +02003163 if (err) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003164 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003165 goto out_err;
3166 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003167 cfg->sched_escan = true;
3168 cfg->scan_request = request;
Arend van Spriele5806072012-09-19 22:21:08 +02003169 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003170 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003171 goto out_err;
3172 }
3173
3174 kfree(ssid);
3175 kfree(channel);
3176 kfree(request);
3177 return 0;
3178
3179out_err:
3180 kfree(ssid);
3181 kfree(channel);
3182 kfree(request);
3183 cfg80211_sched_scan_stopped(wiphy);
3184 return err;
3185}
3186
Arend van Spriele5806072012-09-19 22:21:08 +02003187static int brcmf_dev_pno_clean(struct net_device *ndev)
3188{
Arend van Spriele5806072012-09-19 22:21:08 +02003189 int ret;
3190
3191 /* Disable pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003192 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003193 if (ret == 0) {
3194 /* clear pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003195 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3196 NULL, 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003197 }
3198 if (ret < 0)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003199 brcmf_err("failed code %d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003200
3201 return ret;
3202}
3203
3204static int brcmf_dev_pno_config(struct net_device *ndev)
3205{
3206 struct brcmf_pno_param_le pfn_param;
Arend van Spriele5806072012-09-19 22:21:08 +02003207
3208 memset(&pfn_param, 0, sizeof(pfn_param));
3209 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3210
3211 /* set extra pno params */
3212 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3213 pfn_param.repeat = BRCMF_PNO_REPEAT;
3214 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3215
3216 /* set up pno scan fr */
3217 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3218
Arend van Sprielac24be62012-10-22 10:36:23 -07003219 return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set",
3220 &pfn_param, sizeof(pfn_param));
Arend van Spriele5806072012-09-19 22:21:08 +02003221}
3222
3223static int
3224brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3225 struct net_device *ndev,
3226 struct cfg80211_sched_scan_request *request)
3227{
Arend van Sprielc1179032012-10-22 13:55:33 -07003228 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003229 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003230 struct brcmf_pno_net_param_le pfn;
3231 int i;
3232 int ret = 0;
3233
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003234 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003235 request->n_match_sets, request->n_ssids);
Arend van Sprielc1179032012-10-22 13:55:33 -07003236 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003237 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003238 return -EAGAIN;
3239 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02003240 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3241 brcmf_err("Scanning suppressed: status (%lu)\n",
3242 cfg->scan_status);
3243 return -EAGAIN;
3244 }
Arend van Spriele5806072012-09-19 22:21:08 +02003245
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003246 if (!request->n_ssids || !request->n_match_sets) {
Arend van Spriel181f2d12014-05-27 12:56:13 +02003247 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003248 request->n_ssids);
Arend van Spriele5806072012-09-19 22:21:08 +02003249 return -EINVAL;
3250 }
3251
3252 if (request->n_ssids > 0) {
3253 for (i = 0; i < request->n_ssids; i++) {
3254 /* Active scan req for ssids */
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003255 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3256 request->ssids[i].ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003257
3258 /*
3259 * match_set ssids is a supert set of n_ssid list,
3260 * so we need not add these set seperately.
3261 */
3262 }
3263 }
3264
3265 if (request->n_match_sets > 0) {
3266 /* clean up everything */
3267 ret = brcmf_dev_pno_clean(ndev);
3268 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003269 brcmf_err("failed error=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003270 return ret;
3271 }
3272
3273 /* configure pno */
3274 ret = brcmf_dev_pno_config(ndev);
3275 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003276 brcmf_err("PNO setup failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003277 return -EINVAL;
3278 }
3279
3280 /* configure each match set */
3281 for (i = 0; i < request->n_match_sets; i++) {
3282 struct cfg80211_ssid *ssid;
3283 u32 ssid_len;
3284
3285 ssid = &request->match_sets[i].ssid;
3286 ssid_len = ssid->ssid_len;
3287
3288 if (!ssid_len) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003289 brcmf_err("skip broadcast ssid\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003290 continue;
3291 }
3292 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3293 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3294 pfn.wsec = cpu_to_le32(0);
3295 pfn.infra = cpu_to_le32(1);
3296 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3297 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3298 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
Arend van Sprielc1179032012-10-22 13:55:33 -07003299 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
Arend van Sprielac24be62012-10-22 10:36:23 -07003300 sizeof(pfn));
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003301 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3302 ret == 0 ? "set" : "failed", ssid->ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003303 }
3304 /* Enable the PNO */
Arend van Sprielc1179032012-10-22 13:55:33 -07003305 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003306 brcmf_err("PNO enable failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003307 return -EINVAL;
3308 }
3309 } else {
3310 return -EINVAL;
3311 }
3312
3313 return 0;
3314}
3315
3316static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3317 struct net_device *ndev)
3318{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003319 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003320
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003321 brcmf_dbg(SCAN, "enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003322 brcmf_dev_pno_clean(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003323 if (cfg->sched_escan)
Arend van Spriela0f472a2013-04-05 10:57:49 +02003324 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
Arend van Spriele5806072012-09-19 22:21:08 +02003325 return 0;
3326}
Arend van Spriele5806072012-09-19 22:21:08 +02003327
Hante Meuleman1f170112013-02-06 18:40:38 +01003328static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003329{
3330 s32 err;
3331
3332 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003333 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003334 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003335 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003336 return err;
3337 }
3338 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003339 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003340 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003341 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003342 return err;
3343 }
3344 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003345 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003346 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003347 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003348 return err;
3349 }
3350
3351 return 0;
3352}
3353
3354static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3355{
3356 if (is_rsn_ie)
3357 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3358
3359 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3360}
3361
3362static s32
Johannes Berg4b5800f2014-01-15 14:55:59 +01003363brcmf_configure_wpaie(struct net_device *ndev,
3364 const struct brcmf_vs_tlv *wpa_ie,
3365 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003366{
Arend van Sprielac24be62012-10-22 10:36:23 -07003367 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02003368 u32 auth = 0; /* d11 open authentication */
3369 u16 count;
3370 s32 err = 0;
3371 s32 len = 0;
3372 u32 i;
3373 u32 wsec;
3374 u32 pval = 0;
3375 u32 gval = 0;
3376 u32 wpa_auth = 0;
3377 u32 offset;
3378 u8 *data;
3379 u16 rsn_cap;
3380 u32 wme_bss_disable;
3381
Arend van Sprield96b8012012-12-05 15:26:02 +01003382 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003383 if (wpa_ie == NULL)
3384 goto exit;
3385
3386 len = wpa_ie->len + TLV_HDR_LEN;
3387 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003388 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003389 if (!is_rsn_ie)
3390 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003391 else
3392 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003393
3394 /* check for multicast cipher suite */
3395 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3396 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003397 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003398 goto exit;
3399 }
3400
3401 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3402 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003403 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003404 goto exit;
3405 }
3406 offset += TLV_OUI_LEN;
3407
3408 /* pick up multicast cipher */
3409 switch (data[offset]) {
3410 case WPA_CIPHER_NONE:
3411 gval = 0;
3412 break;
3413 case WPA_CIPHER_WEP_40:
3414 case WPA_CIPHER_WEP_104:
3415 gval = WEP_ENABLED;
3416 break;
3417 case WPA_CIPHER_TKIP:
3418 gval = TKIP_ENABLED;
3419 break;
3420 case WPA_CIPHER_AES_CCM:
3421 gval = AES_ENABLED;
3422 break;
3423 default:
3424 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003425 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003426 goto exit;
3427 }
3428
3429 offset++;
3430 /* walk thru unicast cipher list and pick up what we recognize */
3431 count = data[offset] + (data[offset + 1] << 8);
3432 offset += WPA_IE_SUITE_COUNT_LEN;
3433 /* Check for unicast suite(s) */
3434 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3435 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003436 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003437 goto exit;
3438 }
3439 for (i = 0; i < count; i++) {
3440 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3441 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003442 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003443 goto exit;
3444 }
3445 offset += TLV_OUI_LEN;
3446 switch (data[offset]) {
3447 case WPA_CIPHER_NONE:
3448 break;
3449 case WPA_CIPHER_WEP_40:
3450 case WPA_CIPHER_WEP_104:
3451 pval |= WEP_ENABLED;
3452 break;
3453 case WPA_CIPHER_TKIP:
3454 pval |= TKIP_ENABLED;
3455 break;
3456 case WPA_CIPHER_AES_CCM:
3457 pval |= AES_ENABLED;
3458 break;
3459 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003460 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003461 }
3462 offset++;
3463 }
3464 /* walk thru auth management suite list and pick up what we recognize */
3465 count = data[offset] + (data[offset + 1] << 8);
3466 offset += WPA_IE_SUITE_COUNT_LEN;
3467 /* Check for auth key management suite(s) */
3468 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3469 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003470 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003471 goto exit;
3472 }
3473 for (i = 0; i < count; i++) {
3474 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3475 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003476 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003477 goto exit;
3478 }
3479 offset += TLV_OUI_LEN;
3480 switch (data[offset]) {
3481 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003482 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003483 wpa_auth |= WPA_AUTH_NONE;
3484 break;
3485 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003486 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003487 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3488 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3489 break;
3490 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01003491 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003492 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3493 (wpa_auth |= WPA_AUTH_PSK);
3494 break;
3495 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003496 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003497 }
3498 offset++;
3499 }
3500
3501 if (is_rsn_ie) {
3502 wme_bss_disable = 1;
3503 if ((offset + RSN_CAP_LEN) <= len) {
3504 rsn_cap = data[offset] + (data[offset + 1] << 8);
3505 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3506 wme_bss_disable = 0;
3507 }
3508 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07003509 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003510 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02003511 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003512 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003513 goto exit;
3514 }
3515 }
3516 /* FOR WPS , set SES_OW_ENABLED */
3517 wsec = (pval | gval | SES_OW_ENABLED);
3518
3519 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003520 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003521 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003522 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003523 goto exit;
3524 }
3525 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003526 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02003527 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003528 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003529 goto exit;
3530 }
3531 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003532 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003533 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003534 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003535 goto exit;
3536 }
3537
3538exit:
3539 return err;
3540}
3541
3542static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08003543brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02003544 struct parsed_vndr_ies *vndr_ies)
3545{
Hante Meuleman1a873342012-09-27 14:17:54 +02003546 struct brcmf_vs_tlv *vndrie;
3547 struct brcmf_tlv *ie;
3548 struct parsed_vndr_ie_info *parsed_info;
3549 s32 remaining_len;
3550
3551 remaining_len = (s32)vndr_ie_len;
3552 memset(vndr_ies, 0, sizeof(*vndr_ies));
3553
3554 ie = (struct brcmf_tlv *)vndr_ie_buf;
3555 while (ie) {
3556 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
3557 goto next;
3558 vndrie = (struct brcmf_vs_tlv *)ie;
3559 /* len should be bigger than OUI length + one */
3560 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003561 brcmf_err("invalid vndr ie. length is too small %d\n",
3562 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003563 goto next;
3564 }
3565 /* if wpa or wme ie, do not add ie */
3566 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
3567 ((vndrie->oui_type == WPA_OUI_TYPE) ||
3568 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003569 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003570 goto next;
3571 }
3572
3573 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
3574
3575 /* save vndr ie information */
3576 parsed_info->ie_ptr = (char *)vndrie;
3577 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
3578 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
3579
3580 vndr_ies->count++;
3581
Arend van Sprield96b8012012-12-05 15:26:02 +01003582 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
3583 parsed_info->vndrie.oui[0],
3584 parsed_info->vndrie.oui[1],
3585 parsed_info->vndrie.oui[2],
3586 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02003587
Arend van Spriel9f440b72013-02-08 15:53:36 +01003588 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02003589 break;
3590next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003591 remaining_len -= (ie->len + TLV_HDR_LEN);
3592 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02003593 ie = NULL;
3594 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003595 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
3596 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02003597 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003598 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02003599}
3600
3601static u32
3602brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
3603{
3604
3605 __le32 iecount_le;
3606 __le32 pktflag_le;
3607
3608 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
3609 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
3610
3611 iecount_le = cpu_to_le32(1);
3612 memcpy(&iebuf[VNDR_IE_COUNT_OFFSET], &iecount_le, sizeof(iecount_le));
3613
3614 pktflag_le = cpu_to_le32(pktflag);
3615 memcpy(&iebuf[VNDR_IE_PKTFLAG_OFFSET], &pktflag_le, sizeof(pktflag_le));
3616
3617 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
3618
3619 return ie_len + VNDR_IE_HDR_SIZE;
3620}
3621
Arend van Spriel1332e262012-11-05 16:22:18 -08003622s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
3623 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02003624{
Arend van Spriel1332e262012-11-05 16:22:18 -08003625 struct brcmf_if *ifp;
3626 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003627 s32 err = 0;
3628 u8 *iovar_ie_buf;
3629 u8 *curr_ie_buf;
3630 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003631 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07003632 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003633 u32 del_add_ie_buf_len = 0;
3634 u32 total_ie_buf_len = 0;
3635 u32 parsed_ie_buf_len = 0;
3636 struct parsed_vndr_ies old_vndr_ies;
3637 struct parsed_vndr_ies new_vndr_ies;
3638 struct parsed_vndr_ie_info *vndrie_info;
3639 s32 i;
3640 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003641 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003642
Arend van Spriel1332e262012-11-05 16:22:18 -08003643 if (!vif)
3644 return -ENODEV;
3645 ifp = vif->ifp;
3646 saved_ie = &vif->saved_ie;
3647
Arend van Sprield96b8012012-12-05 15:26:02 +01003648 brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02003649 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
3650 if (!iovar_ie_buf)
3651 return -ENOMEM;
3652 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01003653 switch (pktflag) {
3654 case BRCMF_VNDR_IE_PRBREQ_FLAG:
3655 mgmt_ie_buf = saved_ie->probe_req_ie;
3656 mgmt_ie_len = &saved_ie->probe_req_ie_len;
3657 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
3658 break;
3659 case BRCMF_VNDR_IE_PRBRSP_FLAG:
3660 mgmt_ie_buf = saved_ie->probe_res_ie;
3661 mgmt_ie_len = &saved_ie->probe_res_ie_len;
3662 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
3663 break;
3664 case BRCMF_VNDR_IE_BEACON_FLAG:
3665 mgmt_ie_buf = saved_ie->beacon_ie;
3666 mgmt_ie_len = &saved_ie->beacon_ie_len;
3667 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
3668 break;
3669 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
3670 mgmt_ie_buf = saved_ie->assoc_req_ie;
3671 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
3672 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
3673 break;
3674 default:
3675 err = -EPERM;
3676 brcmf_err("not suitable type\n");
3677 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003678 }
3679
3680 if (vndr_ie_len > mgmt_ie_buf_len) {
3681 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003682 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003683 goto exit;
3684 }
3685
3686 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3687 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
3688 ptr = curr_ie_buf;
3689 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
3690 for (i = 0; i < new_vndr_ies.count; i++) {
3691 vndrie_info = &new_vndr_ies.ie_info[i];
3692 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
3693 vndrie_info->ie_len);
3694 parsed_ie_buf_len += vndrie_info->ie_len;
3695 }
3696 }
3697
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003698 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02003699 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
3700 (memcmp(mgmt_ie_buf, curr_ie_buf,
3701 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003702 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003703 goto exit;
3704 }
3705
3706 /* parse old vndr_ie */
3707 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
3708
3709 /* make a command to delete old ie */
3710 for (i = 0; i < old_vndr_ies.count; i++) {
3711 vndrie_info = &old_vndr_ies.ie_info[i];
3712
Arend van Sprield96b8012012-12-05 15:26:02 +01003713 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3714 vndrie_info->vndrie.id,
3715 vndrie_info->vndrie.len,
3716 vndrie_info->vndrie.oui[0],
3717 vndrie_info->vndrie.oui[1],
3718 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003719
3720 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3721 vndrie_info->ie_ptr,
3722 vndrie_info->ie_len,
3723 "del");
3724 curr_ie_buf += del_add_ie_buf_len;
3725 total_ie_buf_len += del_add_ie_buf_len;
3726 }
3727 }
3728
3729 *mgmt_ie_len = 0;
3730 /* Add if there is any extra IE */
3731 if (mgmt_ie_buf && parsed_ie_buf_len) {
3732 ptr = mgmt_ie_buf;
3733
3734 remained_buf_len = mgmt_ie_buf_len;
3735
3736 /* make a command to add new ie */
3737 for (i = 0; i < new_vndr_ies.count; i++) {
3738 vndrie_info = &new_vndr_ies.ie_info[i];
3739
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003740 /* verify remained buf size before copy data */
3741 if (remained_buf_len < (vndrie_info->vndrie.len +
3742 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003743 brcmf_err("no space in mgmt_ie_buf: len left %d",
3744 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003745 break;
3746 }
3747 remained_buf_len -= (vndrie_info->ie_len +
3748 VNDR_IE_VSIE_OFFSET);
3749
Arend van Sprield96b8012012-12-05 15:26:02 +01003750 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3751 vndrie_info->vndrie.id,
3752 vndrie_info->vndrie.len,
3753 vndrie_info->vndrie.oui[0],
3754 vndrie_info->vndrie.oui[1],
3755 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003756
3757 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3758 vndrie_info->ie_ptr,
3759 vndrie_info->ie_len,
3760 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02003761
3762 /* save the parsed IE in wl struct */
3763 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
3764 vndrie_info->ie_len);
3765 *mgmt_ie_len += vndrie_info->ie_len;
3766
3767 curr_ie_buf += del_add_ie_buf_len;
3768 total_ie_buf_len += del_add_ie_buf_len;
3769 }
3770 }
3771 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003772 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003773 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003774 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003775 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003776 }
3777
3778exit:
3779 kfree(iovar_ie_buf);
3780 return err;
3781}
3782
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01003783s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
3784{
3785 s32 pktflags[] = {
3786 BRCMF_VNDR_IE_PRBREQ_FLAG,
3787 BRCMF_VNDR_IE_PRBRSP_FLAG,
3788 BRCMF_VNDR_IE_BEACON_FLAG
3789 };
3790 int i;
3791
3792 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
3793 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
3794
3795 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
3796 return 0;
3797}
3798
Hante Meuleman1a873342012-09-27 14:17:54 +02003799static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01003800brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
3801 struct cfg80211_beacon_data *beacon)
3802{
3803 s32 err;
3804
3805 /* Set Beacon IEs to FW */
3806 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
3807 beacon->tail, beacon->tail_len);
3808 if (err) {
3809 brcmf_err("Set Beacon IE Failed\n");
3810 return err;
3811 }
3812 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
3813
3814 /* Set Probe Response IEs to FW */
3815 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
3816 beacon->proberesp_ies,
3817 beacon->proberesp_ies_len);
3818 if (err)
3819 brcmf_err("Set Probe Resp IE Failed\n");
3820 else
3821 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
3822
3823 return err;
3824}
3825
3826static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02003827brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
3828 struct cfg80211_ap_settings *settings)
3829{
3830 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003831 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07003832 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01003833 const struct brcmf_tlv *ssid_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003834 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02003835 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01003836 const struct brcmf_tlv *rsn_ie;
3837 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003838 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01003839 enum nl80211_iftype dev_role;
3840 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02003841 u16 chanspec;
Hante Meuleman1a873342012-09-27 14:17:54 +02003842
Arend van Spriel06c01582014-05-12 10:47:37 +02003843 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3844 settings->chandef.chan->hw_value,
3845 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02003846 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01003847 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3848 settings->ssid, settings->ssid_len, settings->auth_type,
3849 settings->inactivity_timeout);
Hante Meuleman1a873342012-09-27 14:17:54 +02003850
Hante Meuleman426d0a52013-02-08 15:53:53 +01003851 dev_role = ifp->vif->wdev.iftype;
Hante Meuleman1a873342012-09-27 14:17:54 +02003852
3853 memset(&ssid_le, 0, sizeof(ssid_le));
3854 if (settings->ssid == NULL || settings->ssid_len == 0) {
3855 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
3856 ssid_ie = brcmf_parse_tlvs(
3857 (u8 *)&settings->beacon.head[ie_offset],
3858 settings->beacon.head_len - ie_offset,
3859 WLAN_EID_SSID);
3860 if (!ssid_ie)
3861 return -EINVAL;
3862
3863 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
3864 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01003865 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02003866 } else {
3867 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
3868 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
3869 }
3870
Arend van Sprielf96aa072013-04-05 10:57:48 +02003871 brcmf_set_mpc(ifp, 0);
Hante Meulemanb3657452013-05-27 21:09:53 +02003872 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02003873
3874 /* find the RSN_IE */
3875 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
3876 settings->beacon.tail_len, WLAN_EID_RSN);
3877
3878 /* find the WPA_IE */
3879 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
3880 settings->beacon.tail_len);
3881
Hante Meuleman1a873342012-09-27 14:17:54 +02003882 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003883 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003884 if (wpa_ie != NULL) {
3885 /* WPA IE */
Arend van Spriel34778522012-11-05 16:22:19 -08003886 err = brcmf_configure_wpaie(ndev, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02003887 if (err < 0)
3888 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003889 } else {
3890 /* RSN IE */
3891 err = brcmf_configure_wpaie(ndev,
Arend van Spriel34778522012-11-05 16:22:19 -08003892 (struct brcmf_vs_tlv *)rsn_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02003893 if (err < 0)
3894 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003895 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003896 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01003897 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01003898 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02003899 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003900
Hante Meulemana0f07952013-02-08 15:53:47 +01003901 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02003902
Arend van Spriel600a8972014-05-12 10:47:39 +02003903 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef);
Arend van Spriel06c01582014-05-12 10:47:37 +02003904 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003905 if (err < 0) {
Arend van Spriel06c01582014-05-12 10:47:37 +02003906 brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec, err);
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003907 goto exit;
3908 }
3909
Hante Meuleman1a873342012-09-27 14:17:54 +02003910 if (settings->beacon_interval) {
Arend van Sprielac24be62012-10-22 10:36:23 -07003911 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003912 settings->beacon_interval);
Hante Meuleman1a873342012-09-27 14:17:54 +02003913 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003914 brcmf_err("Beacon Interval Set Error, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003915 goto exit;
3916 }
3917 }
3918 if (settings->dtim_period) {
Arend van Sprielac24be62012-10-22 10:36:23 -07003919 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003920 settings->dtim_period);
Hante Meuleman1a873342012-09-27 14:17:54 +02003921 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003922 brcmf_err("DTIM Interval Set Error, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003923 goto exit;
3924 }
3925 }
Hante Meulemana0f07952013-02-08 15:53:47 +01003926
3927 if (dev_role == NL80211_IFTYPE_AP) {
3928 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
3929 if (err < 0) {
3930 brcmf_err("BRCMF_C_DOWN error %d\n", err);
3931 goto exit;
3932 }
Hante Meuleman2880b862013-02-08 12:06:31 +01003933 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003934 }
3935
Hante Meulemana0f07952013-02-08 15:53:47 +01003936 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02003937 if (err < 0) {
Hante Meulemana0f07952013-02-08 15:53:47 +01003938 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003939 goto exit;
3940 }
Hante Meulemana0f07952013-02-08 15:53:47 +01003941 if (dev_role == NL80211_IFTYPE_AP) {
3942 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
3943 if (err < 0) {
3944 brcmf_err("setting AP mode failed %d\n", err);
3945 goto exit;
3946 }
3947 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
3948 if (err < 0) {
3949 brcmf_err("BRCMF_C_UP error (%d)\n", err);
3950 goto exit;
3951 }
3952
3953 memset(&join_params, 0, sizeof(join_params));
3954 /* join parameters starts with ssid */
3955 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
3956 /* create softap */
3957 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
3958 &join_params, sizeof(join_params));
3959 if (err < 0) {
3960 brcmf_err("SET SSID error (%d)\n", err);
3961 goto exit;
3962 }
3963 brcmf_dbg(TRACE, "AP mode configuration complete\n");
3964 } else {
3965 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
3966 sizeof(ssid_le));
3967 if (err < 0) {
3968 brcmf_err("setting ssid failed %d\n", err);
3969 goto exit;
3970 }
3971 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
3972 bss_enable.enable = cpu_to_le32(1);
3973 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
3974 sizeof(bss_enable));
3975 if (err < 0) {
3976 brcmf_err("bss_enable config failed %d\n", err);
3977 goto exit;
3978 }
3979
3980 brcmf_dbg(TRACE, "GO mode configuration complete\n");
3981 }
Arend van Sprielc1179032012-10-22 13:55:33 -07003982 clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
3983 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman1a873342012-09-27 14:17:54 +02003984
3985exit:
Hante Meulemanb3657452013-05-27 21:09:53 +02003986 if (err) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02003987 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02003988 brcmf_configure_arp_offload(ifp, true);
3989 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003990 return err;
3991}
3992
3993static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
3994{
Arend van Sprielc1179032012-10-22 13:55:33 -07003995 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02003996 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01003997 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02003998 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02003999
Arend van Sprield96b8012012-12-05 15:26:02 +01004000 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004001
Hante Meuleman426d0a52013-02-08 15:53:53 +01004002 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004003 /* Due to most likely deauths outstanding we sleep */
4004 /* first to make sure they get processed by fw. */
4005 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004006
4007 memset(&join_params, 0, sizeof(join_params));
4008 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4009 &join_params, sizeof(join_params));
4010 if (err < 0)
4011 brcmf_err("SET SSID error (%d)\n", err);
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004012 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004013 if (err < 0)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004014 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004015 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4016 if (err < 0)
4017 brcmf_err("setting AP mode failed %d\n", err);
4018 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4019 if (err < 0)
4020 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004021 } else {
4022 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
4023 bss_enable.enable = cpu_to_le32(0);
4024 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4025 sizeof(bss_enable));
4026 if (err < 0)
4027 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004028 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02004029 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004030 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004031 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
4032 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
4033
Hante Meuleman1a873342012-09-27 14:17:54 +02004034 return err;
4035}
4036
Hante Meulemana0f07952013-02-08 15:53:47 +01004037static s32
4038brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4039 struct cfg80211_beacon_data *info)
4040{
Hante Meulemana0f07952013-02-08 15:53:47 +01004041 struct brcmf_if *ifp = netdev_priv(ndev);
4042 s32 err;
4043
4044 brcmf_dbg(TRACE, "Enter\n");
4045
Hante Meulemana0f07952013-02-08 15:53:47 +01004046 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4047
4048 return err;
4049}
4050
Hante Meuleman1a873342012-09-27 14:17:54 +02004051static int
4052brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03004053 struct station_del_parameters *params)
Hante Meuleman1a873342012-09-27 14:17:54 +02004054{
Hante Meulemana0f07952013-02-08 15:53:47 +01004055 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02004056 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004057 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02004058 s32 err;
4059
Jouni Malinen89c771e2014-10-10 20:52:40 +03004060 if (!params->mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02004061 return -EFAULT;
4062
Jouni Malinen89c771e2014-10-10 20:52:40 +03004063 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02004064
Hante Meulemana0f07952013-02-08 15:53:47 +01004065 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4066 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07004067 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02004068 return -EIO;
4069
Jouni Malinen89c771e2014-10-10 20:52:40 +03004070 memcpy(&scbval.ea, params->mac, ETH_ALEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02004071 scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004072 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004073 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02004074 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004075 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01004076
Arend van Sprield96b8012012-12-05 15:26:02 +01004077 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004078 return err;
4079}
4080
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004081
4082static void
4083brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4084 struct wireless_dev *wdev,
4085 u16 frame_type, bool reg)
4086{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004087 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004088 u16 mgmt_type;
4089
4090 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4091
4092 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004093 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004094 if (reg)
4095 vif->mgmt_rx_reg |= BIT(mgmt_type);
4096 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01004097 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004098}
4099
4100
4101static int
4102brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004103 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004104{
4105 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004106 struct ieee80211_channel *chan = params->chan;
4107 const u8 *buf = params->buf;
4108 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004109 const struct ieee80211_mgmt *mgmt;
4110 struct brcmf_cfg80211_vif *vif;
4111 s32 err = 0;
4112 s32 ie_offset;
4113 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004114 struct brcmf_fil_action_frame_le *action_frame;
4115 struct brcmf_fil_af_params_le *af_params;
4116 bool ack;
4117 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004118 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004119
4120 brcmf_dbg(TRACE, "Enter\n");
4121
4122 *cookie = 0;
4123
4124 mgmt = (const struct ieee80211_mgmt *)buf;
4125
Hante Meulemana0f07952013-02-08 15:53:47 +01004126 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4127 brcmf_err("Driver only allows MGMT packet type\n");
4128 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004129 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004130
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004131 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4132
Hante Meulemana0f07952013-02-08 15:53:47 +01004133 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4134 /* Right now the only reason to get a probe response */
4135 /* is for p2p listen response or for p2p GO from */
4136 /* wpa_supplicant. Unfortunately the probe is send */
4137 /* on primary ndev, while dongle wants it on the p2p */
4138 /* vif. Since this is only reason for a probe */
4139 /* response to be sent, the vif is taken from cfg. */
4140 /* If ever desired to send proberesp for non p2p */
4141 /* response then data should be checked for */
4142 /* "DIRECT-". Note in future supplicant will take */
4143 /* dedicated p2p wdev to do this and then this 'hack'*/
4144 /* is not needed anymore. */
4145 ie_offset = DOT11_MGMT_HDR_LEN +
4146 DOT11_BCN_PRB_FIXED_LEN;
4147 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004148 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4149 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4150 err = brcmf_vif_set_mgmt_ie(vif,
4151 BRCMF_VNDR_IE_PRBRSP_FLAG,
4152 &buf[ie_offset],
4153 ie_len);
4154 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4155 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004156 } else if (ieee80211_is_action(mgmt->frame_control)) {
4157 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4158 if (af_params == NULL) {
4159 brcmf_err("unable to allocate frame\n");
4160 err = -ENOMEM;
4161 goto exit;
4162 }
4163 action_frame = &af_params->action_frame;
4164 /* Add the packet Id */
4165 action_frame->packet_id = cpu_to_le32(*cookie);
4166 /* Add BSSID */
4167 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4168 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4169 /* Add the length exepted for 802.11 header */
4170 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004171 /* Add the channel. Use the one specified as parameter if any or
4172 * the current one (got from the firmware) otherwise
4173 */
4174 if (chan)
4175 freq = chan->center_freq;
4176 else
4177 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4178 &freq);
4179 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004180 af_params->channel = cpu_to_le32(chan_nr);
4181
4182 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4183 le16_to_cpu(action_frame->len));
4184
4185 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004186 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004187
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004188 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004189 af_params);
4190
4191 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4192 GFP_KERNEL);
4193 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004194 } else {
4195 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4196 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4197 }
4198
Hante Meuleman18e2f612013-02-08 15:53:49 +01004199exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004200 return err;
4201}
4202
4203
4204static int
4205brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4206 struct wireless_dev *wdev,
4207 u64 cookie)
4208{
4209 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4210 struct brcmf_cfg80211_vif *vif;
4211 int err = 0;
4212
4213 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4214
4215 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4216 if (vif == NULL) {
4217 brcmf_err("No p2p device available for probe response\n");
4218 err = -ENODEV;
4219 goto exit;
4220 }
4221 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4222exit:
4223 return err;
4224}
4225
Piotr Haber61730d42013-04-23 12:53:12 +02004226static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4227 struct wireless_dev *wdev,
4228 enum nl80211_crit_proto_id proto,
4229 u16 duration)
4230{
4231 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4232 struct brcmf_cfg80211_vif *vif;
4233
4234 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4235
4236 /* only DHCP support for now */
4237 if (proto != NL80211_CRIT_PROTO_DHCP)
4238 return -EINVAL;
4239
4240 /* suppress and abort scanning */
4241 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4242 brcmf_abort_scanning(cfg);
4243
4244 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4245}
4246
4247static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4248 struct wireless_dev *wdev)
4249{
4250 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4251 struct brcmf_cfg80211_vif *vif;
4252
4253 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4254
4255 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4256 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4257}
4258
Hante Meuleman70b7d942014-07-30 13:20:07 +02004259static s32
4260brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4261 const struct brcmf_event_msg *e, void *data)
4262{
4263 switch (e->reason) {
4264 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4265 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4266 break;
4267 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4268 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4269 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4270 break;
4271 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4272 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4273 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4274 break;
4275 }
4276
4277 return 0;
4278}
4279
Arend van Spriel89c2f382013-08-10 12:27:25 +02004280static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4281{
4282 int ret;
4283
4284 switch (oper) {
4285 case NL80211_TDLS_DISCOVERY_REQ:
4286 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4287 break;
4288 case NL80211_TDLS_SETUP:
4289 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4290 break;
4291 case NL80211_TDLS_TEARDOWN:
4292 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4293 break;
4294 default:
4295 brcmf_err("unsupported operation: %d\n", oper);
4296 ret = -EOPNOTSUPP;
4297 }
4298 return ret;
4299}
4300
4301static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004302 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004303 enum nl80211_tdls_operation oper)
4304{
4305 struct brcmf_if *ifp;
4306 struct brcmf_tdls_iovar_le info;
4307 int ret = 0;
4308
4309 ret = brcmf_convert_nl80211_tdls_oper(oper);
4310 if (ret < 0)
4311 return ret;
4312
4313 ifp = netdev_priv(ndev);
4314 memset(&info, 0, sizeof(info));
4315 info.mode = (u8)ret;
4316 if (peer)
4317 memcpy(info.ea, peer, ETH_ALEN);
4318
4319 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4320 &info, sizeof(info));
4321 if (ret < 0)
4322 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4323
4324 return ret;
4325}
4326
Arend van Spriel5b435de2011-10-05 13:19:03 +02004327static struct cfg80211_ops wl_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01004328 .add_virtual_intf = brcmf_cfg80211_add_iface,
4329 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004330 .change_virtual_intf = brcmf_cfg80211_change_iface,
4331 .scan = brcmf_cfg80211_scan,
4332 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4333 .join_ibss = brcmf_cfg80211_join_ibss,
4334 .leave_ibss = brcmf_cfg80211_leave_ibss,
4335 .get_station = brcmf_cfg80211_get_station,
4336 .set_tx_power = brcmf_cfg80211_set_tx_power,
4337 .get_tx_power = brcmf_cfg80211_get_tx_power,
4338 .add_key = brcmf_cfg80211_add_key,
4339 .del_key = brcmf_cfg80211_del_key,
4340 .get_key = brcmf_cfg80211_get_key,
4341 .set_default_key = brcmf_cfg80211_config_default_key,
4342 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4343 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004344 .connect = brcmf_cfg80211_connect,
4345 .disconnect = brcmf_cfg80211_disconnect,
4346 .suspend = brcmf_cfg80211_suspend,
4347 .resume = brcmf_cfg80211_resume,
4348 .set_pmksa = brcmf_cfg80211_set_pmksa,
4349 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02004350 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02004351 .start_ap = brcmf_cfg80211_start_ap,
4352 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01004353 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02004354 .del_station = brcmf_cfg80211_del_station,
Arend van Spriele5806072012-09-19 22:21:08 +02004355 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4356 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004357 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4358 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4359 .remain_on_channel = brcmf_p2p_remain_on_channel,
4360 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02004361 .start_p2p_device = brcmf_p2p_start_device,
4362 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02004363 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4364 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004365 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004366};
4367
Arend van Spriel3eacf862012-10-22 13:55:30 -07004368struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01004369 enum nl80211_iftype type,
4370 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004371{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004372 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004373
Arend van Spriel33a6b152013-02-08 15:53:39 +01004374 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01004375 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07004376 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4377 if (!vif)
4378 return ERR_PTR(-ENOMEM);
4379
4380 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01004381 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004382
Arend van Spriel3eacf862012-10-22 13:55:30 -07004383 vif->pm_block = pm_block;
4384 vif->roam_off = -1;
4385
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004386 brcmf_init_prof(&vif->profile);
4387
Arend van Spriel3eacf862012-10-22 13:55:30 -07004388 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004389 return vif;
4390}
4391
Arend van Spriel427dec52014-01-06 12:40:47 +01004392void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07004393{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004394 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004395 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004396}
4397
Arend van Spriel9df4d542014-01-06 12:40:49 +01004398void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4399{
4400 struct brcmf_cfg80211_vif *vif;
4401 struct brcmf_if *ifp;
4402
4403 ifp = netdev_priv(ndev);
4404 vif = ifp->vif;
4405
4406 brcmf_free_vif(vif);
4407 free_netdev(ndev);
4408}
4409
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004410static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004411{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004412 u32 event = e->event_code;
4413 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004414
4415 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004416 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004417 return true;
4418 }
4419
4420 return false;
4421}
4422
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004423static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004424{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004425 u32 event = e->event_code;
4426 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004427
Hante Meuleman68ca3952014-02-25 20:30:26 +01004428 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4429 (event == BRCMF_E_DISASSOC_IND) ||
4430 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01004431 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004432 return true;
4433 }
4434 return false;
4435}
4436
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004437static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004438 const struct brcmf_event_msg *e)
4439{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004440 u32 event = e->event_code;
4441 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004442
4443 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004444 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
4445 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004446 return true;
4447 }
4448
4449 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004450 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004451 return true;
4452 }
4453
4454 return false;
4455}
4456
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004457static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004458{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004459 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004460
4461 kfree(conn_info->req_ie);
4462 conn_info->req_ie = NULL;
4463 conn_info->req_ie_len = 0;
4464 kfree(conn_info->resp_ie);
4465 conn_info->resp_ie = NULL;
4466 conn_info->resp_ie_len = 0;
4467}
4468
Hante Meuleman89286dc2013-02-08 15:53:46 +01004469static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
4470 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004471{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004472 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004473 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004474 u32 req_len;
4475 u32 resp_len;
4476 s32 err = 0;
4477
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004478 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004479
Arend van Sprielac24be62012-10-22 10:36:23 -07004480 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
4481 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004482 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004483 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004484 return err;
4485 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004486 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004487 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004488 req_len = le32_to_cpu(assoc_info->req_len);
4489 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004490 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004491 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004492 cfg->extra_buf,
4493 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004494 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004495 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004496 return err;
4497 }
4498 conn_info->req_ie_len = req_len;
4499 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004500 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004501 GFP_KERNEL);
4502 } else {
4503 conn_info->req_ie_len = 0;
4504 conn_info->req_ie = NULL;
4505 }
4506 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004507 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004508 cfg->extra_buf,
4509 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004510 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004511 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004512 return err;
4513 }
4514 conn_info->resp_ie_len = resp_len;
4515 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004516 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004517 GFP_KERNEL);
4518 } else {
4519 conn_info->resp_ie_len = 0;
4520 conn_info->resp_ie = NULL;
4521 }
Arend van Spriel16886732012-12-05 15:26:04 +01004522 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
4523 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004524
4525 return err;
4526}
4527
4528static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004529brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004530 struct net_device *ndev,
4531 const struct brcmf_event_msg *e)
4532{
Arend van Sprielc1179032012-10-22 13:55:33 -07004533 struct brcmf_if *ifp = netdev_priv(ndev);
4534 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004535 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4536 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07004537 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004538 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07004539 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02004540 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004541 u32 freq;
4542 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07004543 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004544
Arend van Sprield96b8012012-12-05 15:26:02 +01004545 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004546
Hante Meuleman89286dc2013-02-08 15:53:46 +01004547 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004548 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004549 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004550
Franky Lina180b832012-10-10 11:13:09 -07004551 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
4552 if (buf == NULL) {
4553 err = -ENOMEM;
4554 goto done;
4555 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02004556
Franky Lina180b832012-10-10 11:13:09 -07004557 /* data sent to dongle has to be little endian */
4558 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07004559 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07004560 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07004561
4562 if (err)
4563 goto done;
4564
4565 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02004566 ch.chspec = le16_to_cpu(bi->chanspec);
4567 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004568
Franky Lin83cf17a2013-04-11 13:28:50 +02004569 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004570 band = wiphy->bands[IEEE80211_BAND_2GHZ];
4571 else
4572 band = wiphy->bands[IEEE80211_BAND_5GHZ];
4573
Franky Lin83cf17a2013-04-11 13:28:50 +02004574 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004575 notify_channel = ieee80211_get_channel(wiphy, freq);
4576
Franky Lina180b832012-10-10 11:13:09 -07004577done:
4578 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02004579 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004580 conn_info->req_ie, conn_info->req_ie_len,
4581 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004582 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004583
Arend van Sprielc1179032012-10-22 13:55:33 -07004584 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01004585 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004586 return err;
4587}
4588
4589static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004590brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004591 struct net_device *ndev, const struct brcmf_event_msg *e,
4592 bool completed)
4593{
Arend van Sprielc1179032012-10-22 13:55:33 -07004594 struct brcmf_if *ifp = netdev_priv(ndev);
4595 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004596 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004597
Arend van Sprield96b8012012-12-05 15:26:02 +01004598 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004599
Arend van Sprielc1179032012-10-22 13:55:33 -07004600 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4601 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02004602 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01004603 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004604 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004605 brcmf_update_bss_info(cfg, ifp);
4606 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4607 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004608 }
4609 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02004610 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004611 conn_info->req_ie,
4612 conn_info->req_ie_len,
4613 conn_info->resp_ie,
4614 conn_info->resp_ie_len,
4615 completed ? WLAN_STATUS_SUCCESS :
4616 WLAN_STATUS_AUTH_TIMEOUT,
4617 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004618 brcmf_dbg(CONN, "Report connect result - connection %s\n",
4619 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004620 }
Arend van Sprield96b8012012-12-05 15:26:02 +01004621 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004622 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004623}
4624
4625static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004626brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02004627 struct net_device *ndev,
4628 const struct brcmf_event_msg *e, void *data)
4629{
Hante Meuleman7ee29602013-02-06 18:40:43 +01004630 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004631 u32 event = e->event_code;
4632 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02004633 struct station_info sinfo;
4634
Arend van Spriel16886732012-12-05 15:26:04 +01004635 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004636 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
4637 ndev != cfg_to_ndev(cfg)) {
4638 brcmf_dbg(CONN, "AP mode link down\n");
4639 complete(&cfg->vif_disabled);
4640 return 0;
4641 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004642
Hante Meuleman1a873342012-09-27 14:17:54 +02004643 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01004644 (reason == BRCMF_E_STATUS_SUCCESS)) {
4645 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02004646 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
4647 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004648 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02004649 return -EINVAL;
4650 }
4651 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01004652 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02004653 generation++;
4654 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01004655 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02004656 } else if ((event == BRCMF_E_DISASSOC_IND) ||
4657 (event == BRCMF_E_DEAUTH_IND) ||
4658 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01004659 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02004660 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01004661 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004662}
4663
4664static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004665brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004666 const struct brcmf_event_msg *e, void *data)
4667{
Arend van Spriel19937322012-11-05 16:22:32 -08004668 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4669 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07004670 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004671 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004672 s32 err = 0;
4673
Hante Meuleman8851cce2014-07-30 13:20:02 +02004674 if ((e->event_code == BRCMF_E_DEAUTH) ||
4675 (e->event_code == BRCMF_E_DEAUTH_IND) ||
4676 (e->event_code == BRCMF_E_DISASSOC_IND) ||
4677 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
4678 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4679 }
4680
Arend van Spriel967fe2c2014-03-15 17:18:21 +01004681 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004682 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004683 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01004684 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004685 if (brcmf_is_ibssmode(ifp->vif)) {
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004686 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004687 memcpy(profile->bssid, e->addr, ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004688 wl_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004689 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07004690 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4691 &ifp->vif->sme_state);
4692 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4693 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004694 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004695 brcmf_bss_connect_done(cfg, ndev, e, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004696 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01004697 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004698 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004699 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004700 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004701 brcmf_link_down(ifp->vif);
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004702 brcmf_init_prof(ndev_to_prof(ndev));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004703 if (ndev != cfg_to_ndev(cfg))
4704 complete(&cfg->vif_disabled);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004705 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004706 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07004707 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4708 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004709 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004710 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004711 }
4712
4713 return err;
4714}
4715
4716static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004717brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004718 const struct brcmf_event_msg *e, void *data)
4719{
Arend van Spriel19937322012-11-05 16:22:32 -08004720 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004721 u32 event = e->event_code;
4722 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004723
4724 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004725 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08004726 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004727 else
Arend van Spriel19937322012-11-05 16:22:32 -08004728 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004729 }
4730
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004731 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004732}
4733
4734static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004735brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004736 const struct brcmf_event_msg *e, void *data)
4737{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004738 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004739 enum nl80211_key_type key_type;
4740
4741 if (flags & BRCMF_EVENT_MSG_GROUP)
4742 key_type = NL80211_KEYTYPE_GROUP;
4743 else
4744 key_type = NL80211_KEYTYPE_PAIRWISE;
4745
Arend van Spriel19937322012-11-05 16:22:32 -08004746 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004747 NULL, GFP_KERNEL);
4748
4749 return 0;
4750}
4751
Arend van Sprield3c0b632013-02-08 15:53:37 +01004752static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
4753 const struct brcmf_event_msg *e, void *data)
4754{
4755 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4756 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
4757 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
4758 struct brcmf_cfg80211_vif *vif;
4759
4760 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4761 ifevent->action, ifevent->flags, ifevent->ifidx,
4762 ifevent->bssidx);
4763
Arend van Sprield3c0b632013-02-08 15:53:37 +01004764 mutex_lock(&event->vif_event_lock);
4765 event->action = ifevent->action;
4766 vif = event->vif;
4767
4768 switch (ifevent->action) {
4769 case BRCMF_E_IF_ADD:
4770 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08004771 if (!cfg->vif_event.vif) {
4772 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004773 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08004774 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01004775
4776 ifp->vif = vif;
4777 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02004778 if (ifp->ndev) {
4779 vif->wdev.netdev = ifp->ndev;
4780 ifp->ndev->ieee80211_ptr = &vif->wdev;
4781 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
4782 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01004783 mutex_unlock(&event->vif_event_lock);
4784 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01004785 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01004786
4787 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01004788 mutex_unlock(&event->vif_event_lock);
4789 /* event may not be upon user request */
4790 if (brcmf_cfg80211_vif_event_armed(cfg))
4791 wake_up(&event->vif_wq);
4792 return 0;
4793
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01004794 case BRCMF_E_IF_CHANGE:
4795 mutex_unlock(&event->vif_event_lock);
4796 wake_up(&event->vif_wq);
4797 return 0;
4798
Arend van Sprield3c0b632013-02-08 15:53:37 +01004799 default:
4800 mutex_unlock(&event->vif_event_lock);
4801 break;
4802 }
4803 return -EINVAL;
4804}
4805
Arend van Spriel5b435de2011-10-05 13:19:03 +02004806static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
4807{
Arend van Spriel5b435de2011-10-05 13:19:03 +02004808 conf->frag_threshold = (u32)-1;
4809 conf->rts_threshold = (u32)-1;
4810 conf->retry_short = (u32)-1;
4811 conf->retry_long = (u32)-1;
4812 conf->tx_power = -1;
4813}
4814
Arend van Spriel5c36b992012-11-14 18:46:05 -08004815static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004816{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004817 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
4818 brcmf_notify_connect_status);
4819 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
4820 brcmf_notify_connect_status);
4821 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
4822 brcmf_notify_connect_status);
4823 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
4824 brcmf_notify_connect_status);
4825 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
4826 brcmf_notify_connect_status);
4827 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
4828 brcmf_notify_connect_status);
4829 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
4830 brcmf_notify_roaming_status);
4831 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
4832 brcmf_notify_mic_status);
4833 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
4834 brcmf_notify_connect_status);
4835 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
4836 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004837 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
4838 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004839 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01004840 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004841 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
4842 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01004843 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
4844 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004845 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
4846 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01004847 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
4848 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004849}
4850
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004851static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004852{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004853 kfree(cfg->conf);
4854 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004855 kfree(cfg->escan_ioctl_buf);
4856 cfg->escan_ioctl_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004857 kfree(cfg->extra_buf);
4858 cfg->extra_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004859 kfree(cfg->pmk_list);
4860 cfg->pmk_list = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004861}
4862
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004863static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004864{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004865 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
4866 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004867 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004868 cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
4869 if (!cfg->escan_ioctl_buf)
Hante Meulemane756af52012-09-11 21:18:52 +02004870 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004871 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4872 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004873 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004874 cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL);
4875 if (!cfg->pmk_list)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004876 goto init_priv_mem_out;
4877
4878 return 0;
4879
4880init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004881 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004882
4883 return -ENOMEM;
4884}
4885
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004886static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004887{
4888 s32 err = 0;
4889
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004890 cfg->scan_request = NULL;
4891 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01004892 cfg->active_scan = true; /* we do active scan per default */
4893 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004894 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004895 if (err)
4896 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004897 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004898 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004899 brcmf_init_escan(cfg);
4900 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004901 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004902 return err;
4903}
4904
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004905static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004906{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004907 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004908 brcmf_abort_scanning(cfg);
4909 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004910}
4911
Arend van Sprield3c0b632013-02-08 15:53:37 +01004912static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
4913{
4914 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004915 mutex_init(&event->vif_event_lock);
4916}
4917
Arend van Spriel5b435de2011-10-05 13:19:03 +02004918static s32
Hante Meuleman68ca3952014-02-25 20:30:26 +01004919brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004920{
Arend van Spriel5b435de2011-10-05 13:19:03 +02004921 s32 err = 0;
Arend van Sprielf588bc02011-10-12 20:51:22 +02004922 __le32 roamtrigger[2];
4923 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02004924
4925 /*
4926 * Setup timeout if Beacons are lost and roam is
4927 * off to report link down
4928 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01004929 if (brcmf_roamoff) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004930 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004931 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004932 brcmf_err("bcn_timeout error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004933 goto dongle_rom_out;
4934 }
4935 }
4936
4937 /*
4938 * Enable/Disable built-in roaming to allow supplicant
4939 * to take care of roaming
4940 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01004941 brcmf_dbg(INFO, "Internal Roaming = %s\n",
4942 brcmf_roamoff ? "Off" : "On");
4943 err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff));
Arend van Spriel5b435de2011-10-05 13:19:03 +02004944 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004945 brcmf_err("roam_off error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004946 goto dongle_rom_out;
4947 }
4948
Arend van Sprielf588bc02011-10-12 20:51:22 +02004949 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
4950 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07004951 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004952 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02004953 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004954 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004955 goto dongle_rom_out;
4956 }
4957
Arend van Sprielf588bc02011-10-12 20:51:22 +02004958 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
4959 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07004960 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004961 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02004962 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004963 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004964 goto dongle_rom_out;
4965 }
4966
4967dongle_rom_out:
4968 return err;
4969}
4970
4971static s32
Hante Meuleman40a23292013-01-02 15:22:51 +01004972brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time,
Arend van Sprielc68cdc02011-10-12 20:51:23 +02004973 s32 scan_unassoc_time, s32 scan_passive_time)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004974{
4975 s32 err = 0;
4976
Arend van Sprielac24be62012-10-22 10:36:23 -07004977 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004978 scan_assoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004979 if (err) {
4980 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01004981 brcmf_dbg(INFO, "Scan assoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004982 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01004983 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004984 goto dongle_scantime_out;
4985 }
Arend van Sprielac24be62012-10-22 10:36:23 -07004986 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004987 scan_unassoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004988 if (err) {
4989 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01004990 brcmf_dbg(INFO, "Scan unassoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004991 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01004992 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004993 goto dongle_scantime_out;
4994 }
4995
Arend van Sprielac24be62012-10-22 10:36:23 -07004996 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004997 scan_passive_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004998 if (err) {
4999 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005000 brcmf_dbg(INFO, "Scan passive time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005001 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005002 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005003 goto dongle_scantime_out;
5004 }
5005
5006dongle_scantime_out:
5007 return err;
5008}
5009
Arend van Sprielb48d8912014-07-12 08:49:41 +02005010/* Filter the list of channels received from firmware counting only
5011 * the 20MHz channels. The wiphy band data only needs those which get
5012 * flagged to indicate if they can take part in higher bandwidth.
5013 */
5014static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
5015 struct brcmf_chanspec_list *chlist,
5016 u32 chcnt[])
5017{
5018 u32 total = le32_to_cpu(chlist->count);
5019 struct brcmu_chan ch;
5020 int i;
Hante Meulemand48200b2013-04-03 12:40:29 +02005021
Emil Goodef8adaf0a2014-09-23 00:49:55 +02005022 for (i = 0; i < total; i++) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005023 ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
5024 cfg->d11inf.decchspec(&ch);
5025
5026 /* Firmware gives a ordered list. We skip non-20MHz
5027 * channels is 2G. For 5G we can abort upon reaching
5028 * a non-20MHz channel in the list.
5029 */
5030 if (ch.bw != BRCMU_CHAN_BW_20) {
5031 if (ch.band == BRCMU_CHAN_BAND_5G)
5032 break;
5033 else
5034 continue;
5035 }
5036
5037 if (ch.band == BRCMU_CHAN_BAND_2G)
5038 chcnt[0] += 1;
5039 else if (ch.band == BRCMU_CHAN_BAND_5G)
5040 chcnt[1] += 1;
5041 }
5042}
5043
5044static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5045 struct brcmu_chan *ch)
5046{
5047 u32 ht40_flag;
5048
5049 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5050 if (ch->sb == BRCMU_CHAN_SB_U) {
5051 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5052 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5053 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5054 } else {
5055 /* It should be one of
5056 * IEEE80211_CHAN_NO_HT40 or
5057 * IEEE80211_CHAN_NO_HT40PLUS
5058 */
5059 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5060 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5061 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5062 }
5063}
5064
5065static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5066 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005067{
5068 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005069 struct ieee80211_supported_band *band;
5070 struct ieee80211_channel *channel;
5071 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005072 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005073 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005074 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005075 u8 *pbuf;
5076 u32 i, j;
5077 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005078 u32 chaninfo;
5079 u32 chcnt[2] = { 0, 0 };
Hante Meulemand48200b2013-04-03 12:40:29 +02005080 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02005081
5082 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5083
5084 if (pbuf == NULL)
5085 return -ENOMEM;
5086
5087 list = (struct brcmf_chanspec_list *)pbuf;
5088
5089 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5090 BRCMF_DCMD_MEDLEN);
5091 if (err) {
5092 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005093 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005094 }
5095
Arend van Sprielb48d8912014-07-12 08:49:41 +02005096 brcmf_count_20mhz_channels(cfg, list, chcnt);
5097 wiphy = cfg_to_wiphy(cfg);
5098 if (chcnt[0]) {
5099 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
5100 GFP_KERNEL);
5101 if (band == NULL) {
5102 err = -ENOMEM;
5103 goto fail_pbuf;
5104 }
5105 band->channels = kcalloc(chcnt[0], sizeof(*channel),
5106 GFP_KERNEL);
5107 if (band->channels == NULL) {
5108 kfree(band);
5109 err = -ENOMEM;
5110 goto fail_pbuf;
5111 }
5112 band->n_channels = 0;
5113 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5114 }
5115 if (chcnt[1]) {
5116 band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a),
5117 GFP_KERNEL);
5118 if (band == NULL) {
5119 err = -ENOMEM;
5120 goto fail_band2g;
5121 }
5122 band->channels = kcalloc(chcnt[1], sizeof(*channel),
5123 GFP_KERNEL);
5124 if (band->channels == NULL) {
5125 kfree(band);
5126 err = -ENOMEM;
5127 goto fail_band2g;
5128 }
5129 band->n_channels = 0;
5130 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5131 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005132
5133 total = le32_to_cpu(list->count);
5134 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005135 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5136 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005137
Franky Lin83cf17a2013-04-11 13:28:50 +02005138 if (ch.band == BRCMU_CHAN_BAND_2G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005139 band = wiphy->bands[IEEE80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005140 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005141 band = wiphy->bands[IEEE80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005142 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005143 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005144 continue;
5145 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005146 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005147 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005148 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005149 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005150 ch.bw == BRCMU_CHAN_BW_80)
5151 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005152
5153 channel = band->channels;
5154 index = band->n_channels;
5155 for (j = 0; j < band->n_channels; j++) {
5156 if (channel[j].hw_value == ch.chnum) {
5157 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005158 break;
5159 }
5160 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005161 channel[index].center_freq =
5162 ieee80211_channel_to_frequency(ch.chnum, band->band);
5163 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005164
Arend van Sprielb48d8912014-07-12 08:49:41 +02005165 /* assuming the chanspecs order is HT20,
5166 * HT40 upper, HT40 lower, and VHT80.
5167 */
5168 if (ch.bw == BRCMU_CHAN_BW_80) {
5169 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5170 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5171 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5172 } else {
5173 /* disable other bandwidths for now as mentioned
5174 * order assure they are enabled for subsequent
5175 * chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005176 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005177 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5178 IEEE80211_CHAN_NO_80MHZ;
5179 ch.bw = BRCMU_CHAN_BW_20;
5180 cfg->d11inf.encchspec(&ch);
5181 chaninfo = ch.chspec;
5182 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5183 &chaninfo);
5184 if (!err) {
5185 if (chaninfo & WL_CHAN_RADAR)
5186 channel[index].flags |=
5187 (IEEE80211_CHAN_RADAR |
5188 IEEE80211_CHAN_NO_IR);
5189 if (chaninfo & WL_CHAN_PASSIVE)
5190 channel[index].flags |=
5191 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005192 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005193 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005194 if (index == band->n_channels)
5195 band->n_channels++;
Hante Meulemand48200b2013-04-03 12:40:29 +02005196 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005197 kfree(pbuf);
5198 return 0;
5199
5200fail_band2g:
5201 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5202 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5203 wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
5204fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005205 kfree(pbuf);
5206 return err;
5207}
5208
Arend van Sprielb48d8912014-07-12 08:49:41 +02005209static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005210{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005211 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5212 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005213 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005214 struct brcmf_chanspec_list *list;
5215 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005216 u32 val;
5217 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005218 struct brcmu_chan ch;
5219 u32 num_chan;
5220 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005221
5222 /* verify support for bw_cap command */
5223 val = WLC_BAND_5G;
5224 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5225
5226 if (!err) {
5227 /* only set 2G bandwidth using bw_cap command */
5228 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5229 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5230 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5231 sizeof(band_bwcap));
5232 } else {
5233 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5234 val = WLC_N_BW_40ALL;
5235 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5236 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005237
5238 if (!err) {
5239 /* update channel info in 2G band */
5240 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5241
5242 if (pbuf == NULL)
5243 return -ENOMEM;
5244
5245 ch.band = BRCMU_CHAN_BAND_2G;
5246 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005247 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005248 ch.chnum = 0;
5249 cfg->d11inf.encchspec(&ch);
5250
5251 /* pass encoded chanspec in query */
5252 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5253
5254 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5255 BRCMF_DCMD_MEDLEN);
5256 if (err) {
5257 brcmf_err("get chanspecs error (%d)\n", err);
5258 kfree(pbuf);
5259 return err;
5260 }
5261
5262 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5263 list = (struct brcmf_chanspec_list *)pbuf;
5264 num_chan = le32_to_cpu(list->count);
5265 for (i = 0; i < num_chan; i++) {
5266 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5267 cfg->d11inf.decchspec(&ch);
5268 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5269 continue;
5270 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5271 continue;
5272 for (j = 0; j < band->n_channels; j++) {
5273 if (band->channels[j].hw_value == ch.chnum)
5274 break;
5275 }
5276 if (WARN_ON(j == band->n_channels))
5277 continue;
5278
5279 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5280 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005281 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005282 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005283 return err;
5284}
5285
Arend van Spriel2375d972014-01-06 12:40:41 +01005286static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5287{
5288 u32 band, mimo_bwcap;
5289 int err;
5290
5291 band = WLC_BAND_2G;
5292 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5293 if (!err) {
5294 bw_cap[IEEE80211_BAND_2GHZ] = band;
5295 band = WLC_BAND_5G;
5296 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5297 if (!err) {
5298 bw_cap[IEEE80211_BAND_5GHZ] = band;
5299 return;
5300 }
5301 WARN_ON(1);
5302 return;
5303 }
5304 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5305 mimo_bwcap = 0;
5306 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5307 if (err)
5308 /* assume 20MHz if firmware does not give a clue */
5309 mimo_bwcap = WLC_N_BW_20ALL;
5310
5311 switch (mimo_bwcap) {
5312 case WLC_N_BW_40ALL:
5313 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5314 /* fall-thru */
5315 case WLC_N_BW_20IN2G_40IN5G:
5316 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5317 /* fall-thru */
5318 case WLC_N_BW_20ALL:
5319 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5320 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5321 break;
5322 default:
5323 brcmf_err("invalid mimo_bw_cap value\n");
5324 }
5325}
Hante Meulemand48200b2013-04-03 12:40:29 +02005326
Arend van Spriel18d6c532014-05-12 10:47:35 +02005327static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5328 u32 bw_cap[2], u32 nchain)
5329{
5330 band->ht_cap.ht_supported = true;
5331 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5332 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5333 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5334 }
5335 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5336 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5337 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5338 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5339 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5340 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5341}
5342
5343static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5344{
5345 u16 mcs_map;
5346 int i;
5347
5348 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5349 mcs_map = (mcs_map << 2) | supp;
5350
5351 return cpu_to_le16(mcs_map);
5352}
5353
5354static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
5355 u32 bw_cap[2], u32 nchain)
5356{
5357 __le16 mcs_map;
5358
5359 /* not allowed in 2.4G band */
5360 if (band->band == IEEE80211_BAND_2GHZ)
5361 return;
5362
5363 band->vht_cap.vht_supported = true;
5364 /* 80MHz is mandatory */
5365 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5366 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5367 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5368 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5369 }
5370 /* all support 256-QAM */
5371 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5372 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5373 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
5374}
5375
Arend van Sprielb48d8912014-07-12 08:49:41 +02005376static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005377{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005378 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07005379 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02005380 u32 nmode = 0;
5381 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005382 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01005383 u32 rxchain;
5384 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005385 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005386 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01005387 struct ieee80211_supported_band *band;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005388
Arend van Spriel18d6c532014-05-12 10:47:35 +02005389 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02005390 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5391 if (err) {
5392 brcmf_err("nmode error (%d)\n", err);
5393 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005394 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005395 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005396 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5397 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5398 bw_cap[IEEE80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02005399
Daniel Kim4aca7a12014-02-25 20:30:36 +01005400 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5401 if (err) {
5402 brcmf_err("rxchain error (%d)\n", err);
5403 nchain = 1;
5404 } else {
5405 for (nchain = 0; rxchain; nchain++)
5406 rxchain = rxchain & (rxchain - 1);
5407 }
5408 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5409
Arend van Sprielb48d8912014-07-12 08:49:41 +02005410 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005411 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005412 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02005413 return err;
5414 }
5415
Arend van Sprielb48d8912014-07-12 08:49:41 +02005416 wiphy = cfg_to_wiphy(cfg);
5417 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5418 band = wiphy->bands[i];
5419 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01005420 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02005421
Arend van Spriel18d6c532014-05-12 10:47:35 +02005422 if (nmode)
5423 brcmf_update_ht_cap(band, bw_cap, nchain);
5424 if (vhtmode)
5425 brcmf_update_vht_cap(band, bw_cap, nchain);
Hante Meulemand48200b2013-04-03 12:40:29 +02005426 }
5427
Arend van Sprielb48d8912014-07-12 08:49:41 +02005428 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005429}
5430
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005431static const struct ieee80211_iface_limit brcmf_iface_limits[] = {
5432 {
5433 .max = 2,
5434 .types = BIT(NL80211_IFTYPE_STATION) |
5435 BIT(NL80211_IFTYPE_ADHOC) |
5436 BIT(NL80211_IFTYPE_AP)
5437 },
5438 {
5439 .max = 1,
5440 .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
5441 BIT(NL80211_IFTYPE_P2P_GO)
5442 },
5443 {
5444 .max = 1,
5445 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5446 }
5447};
5448static struct ieee80211_iface_combination brcmf_iface_combos[] = {
5449 {
5450 .max_interfaces = BRCMF_IFACE_MAX_CNT,
5451 .num_different_channels = 1,
5452 .n_limits = ARRAY_SIZE(brcmf_iface_limits),
5453 .limits = brcmf_iface_limits
5454 }
5455};
5456
5457static const struct ieee80211_txrx_stypes
5458brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5459 [NL80211_IFTYPE_STATION] = {
5460 .tx = 0xffff,
5461 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5462 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5463 },
5464 [NL80211_IFTYPE_P2P_CLIENT] = {
5465 .tx = 0xffff,
5466 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5467 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5468 },
5469 [NL80211_IFTYPE_P2P_GO] = {
5470 .tx = 0xffff,
5471 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5472 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5473 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5474 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5475 BIT(IEEE80211_STYPE_AUTH >> 4) |
5476 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5477 BIT(IEEE80211_STYPE_ACTION >> 4)
5478 },
5479 [NL80211_IFTYPE_P2P_DEVICE] = {
5480 .tx = 0xffff,
5481 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5482 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5483 }
5484};
5485
5486static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
5487{
5488 /* scheduled scan settings */
5489 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
5490 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
5491 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5492 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
5493}
5494
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005495#ifdef CONFIG_PM
5496static const struct wiphy_wowlan_support brcmf_wowlan_support = {
5497 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01005498 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
5499 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
5500 .pattern_min_len = 1,
5501 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005502};
5503#endif
5504
5505static void brcmf_wiphy_wowl_params(struct wiphy *wiphy)
5506{
5507#ifdef CONFIG_PM
5508 /* wowl settings */
5509 wiphy->wowlan = &brcmf_wowlan_support;
5510#endif
5511}
5512
Arend van Sprielb48d8912014-07-12 08:49:41 +02005513static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005514{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005515 struct ieee80211_iface_combination ifc_combo;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005516 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
5517 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5518 wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
5519 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
5520 BIT(NL80211_IFTYPE_ADHOC) |
5521 BIT(NL80211_IFTYPE_AP) |
5522 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5523 BIT(NL80211_IFTYPE_P2P_GO) |
5524 BIT(NL80211_IFTYPE_P2P_DEVICE);
5525 /* need VSDB firmware feature for concurrent channels */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005526 ifc_combo = brcmf_iface_combos[0];
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005527 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
Arend van Sprielb48d8912014-07-12 08:49:41 +02005528 ifc_combo.num_different_channels = 2;
5529 wiphy->iface_combinations = kmemdup(&ifc_combo,
5530 sizeof(ifc_combo),
5531 GFP_KERNEL);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005532 wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005533 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
5534 wiphy->cipher_suites = __wl_cipher_suites;
5535 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
5536 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
5537 WIPHY_FLAG_OFFCHAN_TX |
5538 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5539 WIPHY_FLAG_SUPPORTS_TDLS;
5540 if (!brcmf_roamoff)
5541 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
5542 wiphy->mgmt_stypes = brcmf_txrx_stypes;
5543 wiphy->max_remain_on_channel_duration = 5000;
5544 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005545
5546 /* vendor commands/events support */
5547 wiphy->vendor_commands = brcmf_vendor_cmds;
5548 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
5549
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005550 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
5551 brcmf_wiphy_wowl_params(wiphy);
5552
Arend van Sprielb48d8912014-07-12 08:49:41 +02005553 return brcmf_setup_wiphybands(wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005554}
5555
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005556static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005557{
5558 struct net_device *ndev;
5559 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01005560 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005561 s32 power_mode;
5562 s32 err = 0;
5563
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005564 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005565 return err;
5566
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005567 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005568 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01005569 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005570
Hante Meuleman40a23292013-01-02 15:22:51 +01005571 /* make sure RF is ready for work */
5572 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
5573
5574 brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME,
5575 WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005576
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005577 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01005578 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005579 if (err)
5580 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005581 brcmf_dbg(INFO, "power save set to %s\n",
5582 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005583
Hante Meuleman68ca3952014-02-25 20:30:26 +01005584 err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005585 if (err)
5586 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07005587 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
5588 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01005589 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005590 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005591
Hante Meulemanb3657452013-05-27 21:09:53 +02005592 brcmf_configure_arp_offload(ifp, true);
5593
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005594 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01005595default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005596
5597 return err;
5598
5599}
5600
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005601static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005602{
Arend van Sprielc1179032012-10-22 13:55:33 -07005603 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005604
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005605 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005606}
5607
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005608static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005609{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005610 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07005611
Arend van Spriel5b435de2011-10-05 13:19:03 +02005612 /*
5613 * While going down, if associated with AP disassociate
5614 * from AP to save power
5615 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005616 if (check_vif_up(ifp->vif)) {
5617 brcmf_link_down(ifp->vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005618
5619 /* Make sure WPA_Supplicant receives all the event
5620 generated due to DISASSOC call to the fw to keep
5621 the state fw and WPA_Supplicant state consistent
5622 */
5623 brcmf_delay(500);
5624 }
5625
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005626 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07005627 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005628
Arend van Spriel5b435de2011-10-05 13:19:03 +02005629 return 0;
5630}
5631
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005632s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005633{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005634 struct brcmf_if *ifp = netdev_priv(ndev);
5635 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005636 s32 err = 0;
5637
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005638 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005639 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005640 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005641
5642 return err;
5643}
5644
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005645s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005646{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005647 struct brcmf_if *ifp = netdev_priv(ndev);
5648 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005649 s32 err = 0;
5650
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005651 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005652 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005653 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005654
5655 return err;
5656}
5657
Arend van Spriela7965fb2013-04-11 17:08:37 +02005658enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
5659{
5660 struct wireless_dev *wdev = &ifp->vif->wdev;
5661
5662 return wdev->iftype;
5663}
5664
Hante Meulemanbfe81972014-10-28 14:56:16 +01005665bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
5666 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01005667{
5668 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005669
5670 list_for_each_entry(vif, &cfg->vif_list, list) {
5671 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005672 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005673 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005674 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005675}
Arend van Sprield3c0b632013-02-08 15:53:37 +01005676
5677static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
5678 u8 action)
5679{
5680 u8 evt_action;
5681
5682 mutex_lock(&event->vif_event_lock);
5683 evt_action = event->action;
5684 mutex_unlock(&event->vif_event_lock);
5685 return evt_action == action;
5686}
5687
5688void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
5689 struct brcmf_cfg80211_vif *vif)
5690{
5691 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5692
5693 mutex_lock(&event->vif_event_lock);
5694 event->vif = vif;
5695 event->action = 0;
5696 mutex_unlock(&event->vif_event_lock);
5697}
5698
5699bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
5700{
5701 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5702 bool armed;
5703
5704 mutex_lock(&event->vif_event_lock);
5705 armed = event->vif != NULL;
5706 mutex_unlock(&event->vif_event_lock);
5707
5708 return armed;
5709}
5710int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
5711 u8 action, ulong timeout)
5712{
5713 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5714
5715 return wait_event_timeout(event->vif_wq,
5716 vif_event_equals(event, action), timeout);
5717}
5718
Arend van Sprielb48d8912014-07-12 08:49:41 +02005719static void brcmf_free_wiphy(struct wiphy *wiphy)
5720{
5721 kfree(wiphy->iface_combinations);
5722 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5723 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5724 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5725 }
5726 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
5727 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
5728 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
5729 }
5730 wiphy_free(wiphy);
5731}
5732
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005733struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
5734 struct device *busdev)
5735{
5736 struct net_device *ndev = drvr->iflist[0]->ndev;
5737 struct brcmf_cfg80211_info *cfg;
5738 struct wiphy *wiphy;
5739 struct brcmf_cfg80211_vif *vif;
5740 struct brcmf_if *ifp;
5741 s32 err = 0;
5742 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005743 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005744
5745 if (!ndev) {
5746 brcmf_err("ndev is invalid\n");
5747 return NULL;
5748 }
5749
5750 ifp = netdev_priv(ndev);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005751 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
5752 if (!wiphy) {
5753 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005754 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005755 }
5756 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005757
5758 cfg = wiphy_priv(wiphy);
5759 cfg->wiphy = wiphy;
5760 cfg->pub = drvr;
5761 init_vif_event(&cfg->vif_event);
5762 INIT_LIST_HEAD(&cfg->vif_list);
5763
5764 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005765 if (IS_ERR(vif))
5766 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005767
5768 vif->ifp = ifp;
5769 vif->wdev.netdev = ndev;
5770 ndev->ieee80211_ptr = &vif->wdev;
5771 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
5772
5773 err = wl_init_priv(cfg);
5774 if (err) {
5775 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005776 brcmf_free_vif(vif);
5777 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005778 }
5779 ifp->vif = vif;
5780
Arend van Sprielb48d8912014-07-12 08:49:41 +02005781 /* determine d11 io type before wiphy setup */
5782 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005783 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005784 brcmf_err("Failed to get D11 version (%d)\n", err);
5785 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005786 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005787 cfg->d11inf.io_type = (u8)io_type;
5788 brcmu_d11_attach(&cfg->d11inf);
5789
5790 err = brcmf_setup_wiphy(wiphy, ifp);
5791 if (err < 0)
5792 goto priv_out;
5793
5794 brcmf_dbg(INFO, "Registering custom regulatory\n");
5795 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
5796 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
5797
5798 /* firmware defaults to 40MHz disabled in 2G band. We signal
5799 * cfg80211 here that we do and have it decide we can enable
5800 * it. But first check if device does support 2G operation.
5801 */
5802 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5803 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
5804 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5805 }
5806 err = wiphy_register(wiphy);
5807 if (err < 0) {
5808 brcmf_err("Could not register wiphy device (%d)\n", err);
5809 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005810 }
5811
5812 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
5813 * setup 40MHz in 2GHz band and enable OBSS scanning.
5814 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005815 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
5816 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005817 if (!err)
5818 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
5819 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005820 else
5821 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005822 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005823
5824 err = brcmf_p2p_attach(cfg);
5825 if (err) {
5826 brcmf_err("P2P initilisation failed (%d)\n", err);
5827 goto wiphy_unreg_out;
5828 }
5829 err = brcmf_btcoex_attach(cfg);
5830 if (err) {
5831 brcmf_err("BT-coex initialisation failed (%d)\n", err);
5832 brcmf_p2p_detach(&cfg->p2p);
5833 goto wiphy_unreg_out;
5834 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005835
5836 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
5837 if (err) {
5838 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
5839 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman70b7d942014-07-30 13:20:07 +02005840 } else {
5841 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
5842 brcmf_notify_tdls_peer_event);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005843 }
5844
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005845 return cfg;
5846
Arend van Sprielb48d8912014-07-12 08:49:41 +02005847wiphy_unreg_out:
5848 wiphy_unregister(cfg->wiphy);
5849priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005850 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005851 brcmf_free_vif(vif);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005852wiphy_out:
5853 brcmf_free_wiphy(wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005854 return NULL;
5855}
5856
5857void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
5858{
5859 if (!cfg)
5860 return;
5861
5862 WARN_ON(!list_empty(&cfg->vif_list));
5863 wiphy_unregister(cfg->wiphy);
5864 brcmf_btcoex_detach(cfg);
Arend van Sprielc3da74b2014-07-12 08:49:42 +02005865 brcmf_p2p_detach(&cfg->p2p);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005866 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005867 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005868}