blob: 4a88b2381a686b6ee0b369bc8c28bec8df05d124 [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
Hante Meulemana44aa402014-12-03 21:05:33 +0100523static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
524{
525 struct brcmf_mbss_ssid_le mbss_ssid_le;
526 int bsscfgidx;
527 int err;
528
529 memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
530 bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr);
531 if (bsscfgidx < 0)
532 return bsscfgidx;
533
534 mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
535 mbss_ssid_le.SSID_len = cpu_to_le32(5);
536 sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
537
538 err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
539 sizeof(mbss_ssid_le));
540 if (err < 0)
541 brcmf_err("setting ssid failed %d\n", err);
542
543 return err;
544}
545
546/**
547 * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
548 *
549 * @wiphy: wiphy device of new interface.
550 * @name: name of the new interface.
551 * @flags: not used.
552 * @params: contains mac address for AP device.
553 */
554static
555struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
556 u32 *flags, struct vif_params *params)
557{
558 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
559 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
560 struct brcmf_cfg80211_vif *vif;
561 int err;
562
563 if (brcmf_cfg80211_vif_event_armed(cfg))
564 return ERR_PTR(-EBUSY);
565
566 brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
567
568 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false);
569 if (IS_ERR(vif))
570 return (struct wireless_dev *)vif;
571
572 brcmf_cfg80211_arm_vif_event(cfg, vif);
573
574 err = brcmf_cfg80211_request_ap_if(ifp);
575 if (err) {
576 brcmf_cfg80211_arm_vif_event(cfg, NULL);
577 goto fail;
578 }
579
580 /* wait for firmware event */
581 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
582 msecs_to_jiffies(1500));
583 brcmf_cfg80211_arm_vif_event(cfg, NULL);
584 if (!err) {
585 brcmf_err("timeout occurred\n");
586 err = -EIO;
587 goto fail;
588 }
589
590 /* interface created in firmware */
591 ifp = vif->ifp;
592 if (!ifp) {
593 brcmf_err("no if pointer provided\n");
594 err = -ENOENT;
595 goto fail;
596 }
597
598 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
599 err = brcmf_net_attach(ifp, true);
600 if (err) {
601 brcmf_err("Registering netdevice failed\n");
602 goto fail;
603 }
604
605 return &ifp->vif->wdev;
606
607fail:
608 brcmf_free_vif(vif);
609 return ERR_PTR(err);
610}
611
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100612static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
613{
614 enum nl80211_iftype iftype;
615
616 iftype = vif->wdev.iftype;
617 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
618}
619
620static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
621{
622 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
623}
624
Arend van Spriel9f440b72013-02-08 15:53:36 +0100625static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
626 const char *name,
627 enum nl80211_iftype type,
628 u32 *flags,
629 struct vif_params *params)
630{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200631 struct wireless_dev *wdev;
632
Arend van Spriel9f440b72013-02-08 15:53:36 +0100633 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
634 switch (type) {
635 case NL80211_IFTYPE_ADHOC:
636 case NL80211_IFTYPE_STATION:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100637 case NL80211_IFTYPE_AP_VLAN:
638 case NL80211_IFTYPE_WDS:
639 case NL80211_IFTYPE_MONITOR:
640 case NL80211_IFTYPE_MESH_POINT:
641 return ERR_PTR(-EOPNOTSUPP);
Hante Meulemana44aa402014-12-03 21:05:33 +0100642 case NL80211_IFTYPE_AP:
643 wdev = brcmf_ap_add_vif(wiphy, name, flags, params);
644 if (!IS_ERR(wdev))
645 brcmf_cfg80211_update_proto_addr_mode(wdev);
646 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100647 case NL80211_IFTYPE_P2P_CLIENT:
648 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200649 case NL80211_IFTYPE_P2P_DEVICE:
Hante Meuleman8851cce2014-07-30 13:20:02 +0200650 wdev = brcmf_p2p_add_vif(wiphy, name, type, flags, params);
651 if (!IS_ERR(wdev))
652 brcmf_cfg80211_update_proto_addr_mode(wdev);
653 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100654 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100655 default:
656 return ERR_PTR(-EINVAL);
657 }
658}
659
Daniel Kim5e787f72014-06-21 12:11:18 +0200660static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
661{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200662 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200663 brcmf_set_mpc(ifp, mpc);
664}
665
Arend van Sprielf96aa072013-04-05 10:57:48 +0200666void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100667{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100668 s32 err = 0;
669
670 if (check_vif_up(ifp->vif)) {
671 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
672 if (err) {
673 brcmf_err("fail to set mpc\n");
674 return;
675 }
676 brcmf_dbg(INFO, "MPC : %d\n", mpc);
677 }
678}
679
Arend van Spriela0f472a2013-04-05 10:57:49 +0200680s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
681 struct brcmf_if *ifp, bool aborted,
682 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100683{
684 struct brcmf_scan_params_le params_le;
685 struct cfg80211_scan_request *scan_request;
686 s32 err = 0;
687
688 brcmf_dbg(SCAN, "Enter\n");
689
690 /* clear scan request, because the FW abort can cause a second call */
691 /* to this functon and might cause a double cfg80211_scan_done */
692 scan_request = cfg->scan_request;
693 cfg->scan_request = NULL;
694
695 if (timer_pending(&cfg->escan_timeout))
696 del_timer_sync(&cfg->escan_timeout);
697
698 if (fw_abort) {
699 /* Do a scan abort to stop the driver's scan engine */
700 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
701 memset(&params_le, 0, sizeof(params_le));
702 memset(params_le.bssid, 0xFF, ETH_ALEN);
703 params_le.bss_type = DOT11_BSSTYPE_ANY;
704 params_le.scan_type = 0;
705 params_le.channel_num = cpu_to_le32(1);
706 params_le.nprobes = cpu_to_le32(1);
707 params_le.active_time = cpu_to_le32(-1);
708 params_le.passive_time = cpu_to_le32(-1);
709 params_le.home_time = cpu_to_le32(-1);
710 /* Scan is aborted by setting channel_list[0] to -1 */
711 params_le.channel_list[0] = cpu_to_le16(-1);
712 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200713 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100714 &params_le, sizeof(params_le));
715 if (err)
716 brcmf_err("Scan abort failed\n");
717 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200718
Daniel Kim5e787f72014-06-21 12:11:18 +0200719 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200720
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100721 /*
722 * e-scan can be initiated by scheduled scan
723 * which takes precedence.
724 */
725 if (cfg->sched_escan) {
726 brcmf_dbg(SCAN, "scheduled scan completed\n");
727 cfg->sched_escan = false;
728 if (!aborted)
729 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100730 } else if (scan_request) {
731 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
732 aborted ? "Aborted" : "Done");
733 cfg80211_scan_done(scan_request, aborted);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100734 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100735 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
736 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100737
738 return err;
739}
740
Arend van Spriel9f440b72013-02-08 15:53:36 +0100741static
742int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
743{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100744 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
745 struct net_device *ndev = wdev->netdev;
746
747 /* vif event pending in firmware */
748 if (brcmf_cfg80211_vif_event_armed(cfg))
749 return -EBUSY;
750
751 if (ndev) {
752 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200753 cfg->escan_info.ifp == netdev_priv(ndev))
754 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
755 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100756
757 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
758 }
759
Arend van Spriel9f440b72013-02-08 15:53:36 +0100760 switch (wdev->iftype) {
761 case NL80211_IFTYPE_ADHOC:
762 case NL80211_IFTYPE_STATION:
763 case NL80211_IFTYPE_AP:
764 case NL80211_IFTYPE_AP_VLAN:
765 case NL80211_IFTYPE_WDS:
766 case NL80211_IFTYPE_MONITOR:
767 case NL80211_IFTYPE_MESH_POINT:
768 return -EOPNOTSUPP;
769 case NL80211_IFTYPE_P2P_CLIENT:
770 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200771 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100772 return brcmf_p2p_del_vif(wiphy, wdev);
773 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100774 default:
775 return -EINVAL;
776 }
777 return -EOPNOTSUPP;
778}
779
Arend van Spriel5b435de2011-10-05 13:19:03 +0200780static s32
781brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
782 enum nl80211_iftype type, u32 *flags,
783 struct vif_params *params)
784{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100785 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700786 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100787 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200788 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200789 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200790 s32 err = 0;
791
Arend van Sprield96b8012012-12-05 15:26:02 +0100792 brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200793
794 switch (type) {
795 case NL80211_IFTYPE_MONITOR:
796 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100797 brcmf_err("type (%d) : currently we do not support this type\n",
798 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200799 return -EOPNOTSUPP;
800 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200801 infra = 0;
802 break;
803 case NL80211_IFTYPE_STATION:
Hante Meuleman1bc7c652013-02-08 15:53:56 +0100804 /* Ignore change for p2p IF. Unclear why supplicant does this */
805 if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
806 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) {
807 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
808 /* WAR: It is unexpected to get a change of VIF for P2P
809 * IF, but it happens. The request can not be handled
810 * but returning EPERM causes a crash. Returning 0
811 * without setting ieee80211_ptr->iftype causes trace
812 * (WARN_ON) but it works with wpa_supplicant
813 */
814 return 0;
815 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200816 infra = 1;
817 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200818 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100819 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200820 ap = 1;
821 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200822 default:
823 err = -EINVAL;
824 goto done;
825 }
826
Hante Meuleman1a873342012-09-27 14:17:54 +0200827 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100828 if (type == NL80211_IFTYPE_P2P_GO) {
829 brcmf_dbg(INFO, "IF Type = P2P GO\n");
830 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
831 }
832 if (!err) {
833 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state);
834 brcmf_dbg(INFO, "IF Type = AP\n");
835 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200836 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100837 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200838 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100839 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200840 err = -EAGAIN;
841 goto done;
842 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100843 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100844 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200845 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200846 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200847
Hante Meuleman8851cce2014-07-30 13:20:02 +0200848 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
849
Arend van Spriel5b435de2011-10-05 13:19:03 +0200850done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100851 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200852
853 return err;
854}
855
Franky Lin83cf17a2013-04-11 13:28:50 +0200856static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
857 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200858 struct cfg80211_scan_request *request)
859{
860 u32 n_ssids;
861 u32 n_channels;
862 s32 i;
863 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200864 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200865 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200866 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200867
Arend van Sprielba40d162012-10-22 13:55:38 -0700868 memset(params_le->bssid, 0xFF, ETH_ALEN);
Hante Meulemane756af52012-09-11 21:18:52 +0200869 params_le->bss_type = DOT11_BSSTYPE_ANY;
870 params_le->scan_type = 0;
871 params_le->channel_num = 0;
872 params_le->nprobes = cpu_to_le32(-1);
873 params_le->active_time = cpu_to_le32(-1);
874 params_le->passive_time = cpu_to_le32(-1);
875 params_le->home_time = cpu_to_le32(-1);
876 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
877
878 /* if request is null exit so it will be all channel broadcast scan */
879 if (!request)
880 return;
881
882 n_ssids = request->n_ssids;
883 n_channels = request->n_channels;
884 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100885 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
886 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200887 if (n_channels > 0) {
888 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200889 chanspec = channel_to_chanspec(&cfg->d11inf,
890 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100891 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
892 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200893 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200894 }
895 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100896 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200897 }
898 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100899 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200900 if (n_ssids > 0) {
901 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
902 n_channels * sizeof(u16);
903 offset = roundup(offset, sizeof(u32));
904 ptr = (char *)params_le + offset;
905 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +0200906 memset(&ssid_le, 0, sizeof(ssid_le));
907 ssid_le.SSID_len =
908 cpu_to_le32(request->ssids[i].ssid_len);
909 memcpy(ssid_le.SSID, request->ssids[i].ssid,
910 request->ssids[i].ssid_len);
911 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100912 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +0200913 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100914 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
915 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +0200916 memcpy(ptr, &ssid_le, sizeof(ssid_le));
917 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +0200918 }
919 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100920 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200921 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100922 brcmf_dbg(SCAN, "SSID %s len=%d\n",
923 params_le->ssid_le.SSID,
924 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200925 params_le->ssid_le.SSID_len =
926 cpu_to_le32(request->ssids->ssid_len);
927 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
928 request->ssids->ssid_len);
929 }
930 }
931 /* Adding mask to channel numbers */
932 params_le->channel_num =
933 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
934 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
935}
936
937static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200938brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +0200939 struct cfg80211_scan_request *request, u16 action)
940{
941 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
942 offsetof(struct brcmf_escan_params_le, params_le);
943 struct brcmf_escan_params_le *params;
944 s32 err = 0;
945
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100946 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200947
948 if (request != NULL) {
949 /* Allocate space for populating ssids in struct */
950 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
951
952 /* Allocate space for populating ssids in struct */
953 params_size += sizeof(struct brcmf_ssid) * request->n_ssids;
954 }
955
956 params = kzalloc(params_size, GFP_KERNEL);
957 if (!params) {
958 err = -ENOMEM;
959 goto exit;
960 }
961 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +0200962 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +0200963 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
964 params->action = cpu_to_le16(action);
965 params->sync_id = cpu_to_le16(0x1234);
966
Arend van Spriela0f472a2013-04-05 10:57:49 +0200967 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +0200968 if (err) {
969 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100970 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200971 else
Arend van Spriel57d6e912012-12-05 15:26:00 +0100972 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200973 }
974
975 kfree(params);
976exit:
977 return err;
978}
979
980static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200981brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
Arend van Spriela0f472a2013-04-05 10:57:49 +0200982 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200983{
984 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700985 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +0200986 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100987 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +0200988
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100989 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +0200990 escan->ifp = ifp;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100991 escan->wiphy = wiphy;
992 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700993 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +0200994 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700995 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +0200996 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100997 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200998 return err;
999 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001000 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001001 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02001002 results->version = 0;
1003 results->count = 0;
1004 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
1005
Arend van Spriela0f472a2013-04-05 10:57:49 +02001006 err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +02001007 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +02001008 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001009 return err;
1010}
1011
1012static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001013brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +02001014 struct cfg80211_scan_request *request,
1015 struct cfg80211_ssid *this_ssid)
1016{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001017 struct brcmf_if *ifp = vif->ifp;
1018 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +02001019 struct cfg80211_ssid *ssids;
Hante Meulemanf07998952012-11-05 16:22:13 -08001020 struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001021 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001022 bool escan_req;
1023 bool spec_scan;
1024 s32 err;
1025 u32 SSID_len;
1026
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001027 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001028
Arend van Sprielc1179032012-10-22 13:55:33 -07001029 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001030 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001031 return -EAGAIN;
1032 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001033 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001034 brcmf_err("Scanning being aborted: status (%lu)\n",
1035 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001036 return -EAGAIN;
1037 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02001038 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
1039 brcmf_err("Scanning suppressed: status (%lu)\n",
1040 cfg->scan_status);
1041 return -EAGAIN;
1042 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001043 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001044 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +02001045 return -EAGAIN;
1046 }
1047
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001048 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001049 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
1050 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001051
Hante Meulemane756af52012-09-11 21:18:52 +02001052 /* Arm scan timeout timer */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001053 mod_timer(&cfg->escan_timeout, jiffies +
Hante Meulemane756af52012-09-11 21:18:52 +02001054 WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
1055
1056 escan_req = false;
1057 if (request) {
1058 /* scan bss */
1059 ssids = request->ssids;
1060 escan_req = true;
1061 } else {
1062 /* scan in ibss */
1063 /* we don't do escan in ibss */
1064 ssids = this_ssid;
1065 }
1066
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001067 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -07001068 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001069 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +01001070 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001071 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001072 if (err)
1073 goto scan_out;
1074
Arend van Spriela0f472a2013-04-05 10:57:49 +02001075 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -08001076 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +02001077 goto scan_out;
1078 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001079 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
1080 ssids->ssid, ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +02001081 memset(&sr->ssid_le, 0, sizeof(sr->ssid_le));
1082 SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len);
1083 sr->ssid_le.SSID_len = cpu_to_le32(0);
1084 spec_scan = false;
1085 if (SSID_len) {
1086 memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len);
1087 sr->ssid_le.SSID_len = cpu_to_le32(SSID_len);
1088 spec_scan = true;
1089 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001090 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001091
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001092 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -07001093 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001094 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001095 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001096 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001097 goto scan_out;
1098 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001099 brcmf_scan_config_mpc(ifp, 0);
Arend van Sprielc1179032012-10-22 13:55:33 -07001100 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Sprielac24be62012-10-22 10:36:23 -07001101 &sr->ssid_le, sizeof(sr->ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001102 if (err) {
1103 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001104 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
1105 sr->ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001106 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001107 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001108
Daniel Kim5e787f72014-06-21 12:11:18 +02001109 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001110 goto scan_out;
1111 }
1112 }
1113
1114 return 0;
1115
1116scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001117 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001118 if (timer_pending(&cfg->escan_timeout))
1119 del_timer_sync(&cfg->escan_timeout);
1120 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001121 return err;
1122}
1123
Arend van Spriel5b435de2011-10-05 13:19:03 +02001124static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001125brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001126{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001127 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001128 s32 err = 0;
1129
Arend van Sprield96b8012012-12-05 15:26:02 +01001130 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001131 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1132 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001133 return -EIO;
1134
Arend van Spriela0f472a2013-04-05 10:57:49 +02001135 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001136
Arend van Spriel5b435de2011-10-05 13:19:03 +02001137 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001138 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001139
Arend van Sprield96b8012012-12-05 15:26:02 +01001140 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001141 return err;
1142}
1143
1144static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1145{
1146 s32 err = 0;
1147
Arend van Sprielac24be62012-10-22 10:36:23 -07001148 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1149 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001150 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001151 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001152
1153 return err;
1154}
1155
1156static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1157{
1158 s32 err = 0;
1159
Arend van Sprielac24be62012-10-22 10:36:23 -07001160 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1161 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001162 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001163 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001164
1165 return err;
1166}
1167
1168static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1169{
1170 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001171 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001172
Arend van Sprielac24be62012-10-22 10:36:23 -07001173 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001174 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001175 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001176 return err;
1177 }
1178 return err;
1179}
1180
1181static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1182{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001183 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1184 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001185 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001186 s32 err = 0;
1187
Arend van Sprield96b8012012-12-05 15:26:02 +01001188 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001189 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001190 return -EIO;
1191
1192 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001193 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1194 cfg->conf->rts_threshold = wiphy->rts_threshold;
1195 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001196 if (!err)
1197 goto done;
1198 }
1199 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001200 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1201 cfg->conf->frag_threshold = wiphy->frag_threshold;
1202 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001203 if (!err)
1204 goto done;
1205 }
1206 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001207 && (cfg->conf->retry_long != wiphy->retry_long)) {
1208 cfg->conf->retry_long = wiphy->retry_long;
1209 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001210 if (!err)
1211 goto done;
1212 }
1213 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001214 && (cfg->conf->retry_short != wiphy->retry_short)) {
1215 cfg->conf->retry_short = wiphy->retry_short;
1216 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001217 if (!err)
1218 goto done;
1219 }
1220
1221done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001222 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001223 return err;
1224}
1225
Arend van Spriel5b435de2011-10-05 13:19:03 +02001226static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1227{
1228 memset(prof, 0, sizeof(*prof));
1229}
1230
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001231static void brcmf_link_down(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001232{
Piotr Haber61730d42013-04-23 12:53:12 +02001233 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001234 s32 err = 0;
1235
Arend van Sprield96b8012012-12-05 15:26:02 +01001236 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001237
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001238 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001239 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001240 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001241 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001242 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001243 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001244 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001245 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001246 cfg80211_disconnected(vif->wdev.netdev, 0, NULL, 0, GFP_KERNEL);
1247
Arend van Spriel5b435de2011-10-05 13:19:03 +02001248 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001249 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001250 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1251 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001252 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001253}
1254
1255static s32
1256brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1257 struct cfg80211_ibss_params *params)
1258{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001259 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001260 struct brcmf_if *ifp = netdev_priv(ndev);
1261 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001262 struct brcmf_join_params join_params;
1263 size_t join_params_size = 0;
1264 s32 err = 0;
1265 s32 wsec = 0;
1266 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001267 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001268
Arend van Sprield96b8012012-12-05 15:26:02 +01001269 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001270 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001271 return -EIO;
1272
1273 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001274 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001275 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001276 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001277 return -EOPNOTSUPP;
1278 }
1279
Arend van Sprielc1179032012-10-22 13:55:33 -07001280 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001281
1282 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001283 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001284 else
Arend van Spriel16886732012-12-05 15:26:04 +01001285 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001286
Johannes Berg683b6d32012-11-08 21:25:48 +01001287 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001288 brcmf_dbg(CONN, "channel: %d\n",
1289 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001290 else
Arend van Spriel16886732012-12-05 15:26:04 +01001291 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001292
1293 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001294 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001295 else
Arend van Spriel16886732012-12-05 15:26:04 +01001296 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001297
1298 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001299 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001300 else
Arend van Spriel16886732012-12-05 15:26:04 +01001301 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001302
1303 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001304 brcmf_dbg(CONN, "beacon interval: %d\n",
1305 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001306 else
Arend van Spriel16886732012-12-05 15:26:04 +01001307 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001308
1309 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001310 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001311 else
Arend van Spriel16886732012-12-05 15:26:04 +01001312 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001313
1314 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001315 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001316 else
Arend van Spriel16886732012-12-05 15:26:04 +01001317 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001318
1319 /* Configure Privacy for starter */
1320 if (params->privacy)
1321 wsec |= WEP_ENABLED;
1322
Arend van Sprielc1179032012-10-22 13:55:33 -07001323 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001324 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001325 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001326 goto done;
1327 }
1328
1329 /* Configure Beacon Interval for starter */
1330 if (params->beacon_interval)
1331 bcnprd = params->beacon_interval;
1332 else
1333 bcnprd = 100;
1334
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001335 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001336 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001337 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001338 goto done;
1339 }
1340
1341 /* Configure required join parameter */
1342 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1343
1344 /* SSID */
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001345 profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32);
1346 memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len);
1347 memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len);
1348 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001349 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001350
1351 /* BSSID */
1352 if (params->bssid) {
1353 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
1354 join_params_size = sizeof(join_params.ssid_le) +
1355 BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001356 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001357 } else {
Arend van Sprielba40d162012-10-22 13:55:38 -07001358 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001359 memset(profile->bssid, 0, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001360 }
1361
Arend van Spriel5b435de2011-10-05 13:19:03 +02001362 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001363 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001364 u32 target_channel;
1365
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001366 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001367 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001368 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001369 if (params->channel_fixed) {
1370 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001371 chanspec = chandef_to_chanspec(&cfg->d11inf,
1372 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001373 join_params.params_le.chanspec_list[0] =
1374 cpu_to_le16(chanspec);
1375 join_params.params_le.chanspec_num = cpu_to_le32(1);
1376 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001377 }
1378
1379 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001380 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001381 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001382 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001383 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001384 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001385 goto done;
1386 }
1387 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001388 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001389
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001390 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001391
1392
Arend van Sprielc1179032012-10-22 13:55:33 -07001393 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001394 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001395 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001396 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001397 goto done;
1398 }
1399
1400done:
1401 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001402 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001403 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001404 return err;
1405}
1406
1407static s32
1408brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1409{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001410 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001411
Arend van Sprield96b8012012-12-05 15:26:02 +01001412 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001413 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001414 return -EIO;
1415
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001416 brcmf_link_down(ifp->vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001417
Arend van Sprield96b8012012-12-05 15:26:02 +01001418 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001419
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001420 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001421}
1422
1423static s32 brcmf_set_wpa_version(struct net_device *ndev,
1424 struct cfg80211_connect_params *sme)
1425{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001426 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001427 struct brcmf_cfg80211_security *sec;
1428 s32 val = 0;
1429 s32 err = 0;
1430
1431 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1432 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1433 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1434 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1435 else
1436 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001437 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001438 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001439 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001440 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001441 return err;
1442 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001443 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001444 sec->wpa_versions = sme->crypto.wpa_versions;
1445 return err;
1446}
1447
1448static s32 brcmf_set_auth_type(struct net_device *ndev,
1449 struct cfg80211_connect_params *sme)
1450{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001451 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001452 struct brcmf_cfg80211_security *sec;
1453 s32 val = 0;
1454 s32 err = 0;
1455
1456 switch (sme->auth_type) {
1457 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1458 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001459 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001460 break;
1461 case NL80211_AUTHTYPE_SHARED_KEY:
1462 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001463 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001464 break;
1465 case NL80211_AUTHTYPE_AUTOMATIC:
1466 val = 2;
Arend van Spriel16886732012-12-05 15:26:04 +01001467 brcmf_dbg(CONN, "automatic\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001468 break;
1469 case NL80211_AUTHTYPE_NETWORK_EAP:
Arend van Spriel16886732012-12-05 15:26:04 +01001470 brcmf_dbg(CONN, "network eap\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001471 default:
1472 val = 2;
Arend van Spriel57d6e912012-12-05 15:26:00 +01001473 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001474 break;
1475 }
1476
Hante Meuleman89286dc2013-02-08 15:53:46 +01001477 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001478 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001479 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001480 return err;
1481 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001482 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001483 sec->auth_type = sme->auth_type;
1484 return err;
1485}
1486
1487static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001488brcmf_set_wsec_mode(struct net_device *ndev,
1489 struct cfg80211_connect_params *sme, bool mfp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001490{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001491 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001492 struct brcmf_cfg80211_security *sec;
1493 s32 pval = 0;
1494 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001495 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001496 s32 err = 0;
1497
1498 if (sme->crypto.n_ciphers_pairwise) {
1499 switch (sme->crypto.ciphers_pairwise[0]) {
1500 case WLAN_CIPHER_SUITE_WEP40:
1501 case WLAN_CIPHER_SUITE_WEP104:
1502 pval = WEP_ENABLED;
1503 break;
1504 case WLAN_CIPHER_SUITE_TKIP:
1505 pval = TKIP_ENABLED;
1506 break;
1507 case WLAN_CIPHER_SUITE_CCMP:
1508 pval = AES_ENABLED;
1509 break;
1510 case WLAN_CIPHER_SUITE_AES_CMAC:
1511 pval = AES_ENABLED;
1512 break;
1513 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001514 brcmf_err("invalid cipher pairwise (%d)\n",
1515 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001516 return -EINVAL;
1517 }
1518 }
1519 if (sme->crypto.cipher_group) {
1520 switch (sme->crypto.cipher_group) {
1521 case WLAN_CIPHER_SUITE_WEP40:
1522 case WLAN_CIPHER_SUITE_WEP104:
1523 gval = WEP_ENABLED;
1524 break;
1525 case WLAN_CIPHER_SUITE_TKIP:
1526 gval = TKIP_ENABLED;
1527 break;
1528 case WLAN_CIPHER_SUITE_CCMP:
1529 gval = AES_ENABLED;
1530 break;
1531 case WLAN_CIPHER_SUITE_AES_CMAC:
1532 gval = AES_ENABLED;
1533 break;
1534 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001535 brcmf_err("invalid cipher group (%d)\n",
1536 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001537 return -EINVAL;
1538 }
1539 }
1540
Arend van Spriel16886732012-12-05 15:26:04 +01001541 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001542 /* In case of privacy, but no security and WPS then simulate */
1543 /* setting AES. WPS-2.0 allows no security */
1544 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1545 sme->privacy)
1546 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001547
1548 if (mfp)
1549 wsec = pval | gval | MFP_CAPABLE;
1550 else
1551 wsec = pval | gval;
1552 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001553 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001554 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001555 return err;
1556 }
1557
Arend van Spriel06bb1232012-09-27 14:17:56 +02001558 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001559 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1560 sec->cipher_group = sme->crypto.cipher_group;
1561
1562 return err;
1563}
1564
1565static s32
1566brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1567{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001568 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001569 struct brcmf_cfg80211_security *sec;
1570 s32 val = 0;
1571 s32 err = 0;
1572
1573 if (sme->crypto.n_akm_suites) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01001574 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
1575 "wpa_auth", &val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001576 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001577 brcmf_err("could not get wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001578 return err;
1579 }
1580 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1581 switch (sme->crypto.akm_suites[0]) {
1582 case WLAN_AKM_SUITE_8021X:
1583 val = WPA_AUTH_UNSPECIFIED;
1584 break;
1585 case WLAN_AKM_SUITE_PSK:
1586 val = WPA_AUTH_PSK;
1587 break;
1588 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001589 brcmf_err("invalid cipher group (%d)\n",
1590 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001591 return -EINVAL;
1592 }
1593 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1594 switch (sme->crypto.akm_suites[0]) {
1595 case WLAN_AKM_SUITE_8021X:
1596 val = WPA2_AUTH_UNSPECIFIED;
1597 break;
1598 case WLAN_AKM_SUITE_PSK:
1599 val = WPA2_AUTH_PSK;
1600 break;
1601 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001602 brcmf_err("invalid cipher group (%d)\n",
1603 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001604 return -EINVAL;
1605 }
1606 }
1607
Arend van Spriel16886732012-12-05 15:26:04 +01001608 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001609 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
1610 "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001611 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001612 brcmf_err("could not set wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001613 return err;
1614 }
1615 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001616 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001617 sec->wpa_auth = sme->crypto.akm_suites[0];
1618
1619 return err;
1620}
1621
1622static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001623brcmf_set_sharedkey(struct net_device *ndev,
1624 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001625{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001626 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001627 struct brcmf_cfg80211_security *sec;
1628 struct brcmf_wsec_key key;
1629 s32 val;
1630 s32 err = 0;
1631
Arend van Spriel16886732012-12-05 15:26:04 +01001632 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001633
Roland Vossena718e2f2011-10-12 20:51:24 +02001634 if (sme->key_len == 0)
1635 return 0;
1636
Arend van Spriel06bb1232012-09-27 14:17:56 +02001637 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001638 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1639 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001640
1641 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1642 return 0;
1643
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001644 if (!(sec->cipher_pairwise &
1645 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1646 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001647
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001648 memset(&key, 0, sizeof(key));
1649 key.len = (u32) sme->key_len;
1650 key.index = (u32) sme->key_idx;
1651 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001652 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001653 return -EINVAL;
1654 }
1655 memcpy(key.data, sme->key, key.len);
1656 key.flags = BRCMF_PRIMARY_KEY;
1657 switch (sec->cipher_pairwise) {
1658 case WLAN_CIPHER_SUITE_WEP40:
1659 key.algo = CRYPTO_ALGO_WEP1;
1660 break;
1661 case WLAN_CIPHER_SUITE_WEP104:
1662 key.algo = CRYPTO_ALGO_WEP128;
1663 break;
1664 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001665 brcmf_err("Invalid algorithm (%d)\n",
1666 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001667 return -EINVAL;
1668 }
1669 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001670 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1671 key.len, key.index, key.algo);
1672 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07001673 err = send_key_to_dongle(ndev, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001674 if (err)
1675 return err;
1676
1677 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001678 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001679 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001680 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001681 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001682 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001683 }
1684 return err;
1685}
1686
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001687static
1688enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1689 enum nl80211_auth_type type)
1690{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001691 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1692 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1693 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1694 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001695 }
1696 return type;
1697}
1698
Arend van Spriel5b435de2011-10-05 13:19:03 +02001699static s32
1700brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001701 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001702{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001703 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001704 struct brcmf_if *ifp = netdev_priv(ndev);
1705 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001706 struct ieee80211_channel *chan = sme->channel;
1707 struct brcmf_join_params join_params;
1708 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001709 const struct brcmf_tlv *rsn_ie;
1710 const struct brcmf_vs_tlv *wpa_ie;
1711 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001712 u32 ie_len;
1713 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001714 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001715 s32 err = 0;
1716
Arend van Sprield96b8012012-12-05 15:26:02 +01001717 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001718 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001719 return -EIO;
1720
1721 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001722 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001723 return -EOPNOTSUPP;
1724 }
1725
Hante Meuleman89286dc2013-02-08 15:53:46 +01001726 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1727 /* A normal (non P2P) connection request setup. */
1728 ie = NULL;
1729 ie_len = 0;
1730 /* find the WPA_IE */
1731 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1732 if (wpa_ie) {
1733 ie = wpa_ie;
1734 ie_len = wpa_ie->len + TLV_HDR_LEN;
1735 } else {
1736 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001737 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1738 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001739 WLAN_EID_RSN);
1740 if (rsn_ie) {
1741 ie = rsn_ie;
1742 ie_len = rsn_ie->len + TLV_HDR_LEN;
1743 }
1744 }
1745 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1746 }
1747
1748 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1749 sme->ie, sme->ie_len);
1750 if (err)
1751 brcmf_err("Set Assoc REQ IE Failed\n");
1752 else
1753 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1754
Arend van Sprielc1179032012-10-22 13:55:33 -07001755 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001756
1757 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001758 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001759 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001760 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001761 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1762 cfg->channel, chan->center_freq, chanspec);
1763 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001764 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001765 chanspec = 0;
1766 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001767
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001768 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001769
1770 err = brcmf_set_wpa_version(ndev, sme);
1771 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001772 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001773 goto done;
1774 }
1775
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001776 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001777 err = brcmf_set_auth_type(ndev, sme);
1778 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001779 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001780 goto done;
1781 }
1782
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001783 err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001784 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001785 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001786 goto done;
1787 }
1788
1789 err = brcmf_set_key_mgmt(ndev, sme);
1790 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001791 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001792 goto done;
1793 }
1794
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001795 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001796 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001797 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001798 goto done;
1799 }
1800
Hante Meuleman89286dc2013-02-08 15:53:46 +01001801 profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID),
1802 (u32)sme->ssid_len);
1803 memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len);
1804 if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1805 profile->ssid.SSID[profile->ssid.SSID_len] = 0;
1806 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID,
1807 profile->ssid.SSID_len);
1808 }
1809
1810 /* Join with specific BSSID and cached SSID
1811 * If SSID is zero join based on BSSID only
1812 */
1813 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1814 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1815 if (cfg->channel)
1816 join_params_size += sizeof(u16);
1817 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1818 if (ext_join_params == NULL) {
1819 err = -ENOMEM;
1820 goto done;
1821 }
1822 ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
1823 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid,
1824 profile->ssid.SSID_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001825
Hante Meuleman89286dc2013-02-08 15:53:46 +01001826 /* Set up join scan parameters */
1827 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001828 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1829
1830 if (sme->bssid)
1831 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1832 else
1833 memset(&ext_join_params->assoc_le.bssid, 0xFF, ETH_ALEN);
1834
1835 if (cfg->channel) {
1836 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
1837
1838 ext_join_params->assoc_le.chanspec_list[0] =
1839 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001840 /* Increase dwell time to receive probe response or detect
1841 * beacon from target AP at a noisy air only during connect
1842 * command.
1843 */
1844 ext_join_params->scan_le.active_time =
1845 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
1846 ext_join_params->scan_le.passive_time =
1847 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
1848 /* To sync with presence period of VSDB GO send probe request
1849 * more frequently. Probe request will be stopped when it gets
1850 * probe response from target AP/GO.
1851 */
1852 ext_join_params->scan_le.nprobes =
1853 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
1854 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
1855 } else {
1856 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
1857 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
1858 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001859 }
1860
1861 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
1862 join_params_size);
1863 kfree(ext_join_params);
1864 if (!err)
1865 /* This is it. join command worked, we are done */
1866 goto done;
1867
1868 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02001869 memset(&join_params, 0, sizeof(join_params));
1870 join_params_size = sizeof(join_params.ssid_le);
1871
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001872 memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001873 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001874
Hante Meuleman89286dc2013-02-08 15:53:46 +01001875 if (sme->bssid)
1876 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
1877 else
1878 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001879
Hante Meuleman17012612013-02-06 18:40:44 +01001880 if (cfg->channel) {
1881 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
1882 join_params.params_le.chanspec_num = cpu_to_le32(1);
1883 join_params_size += sizeof(join_params.params_le);
1884 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001885 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001886 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001887 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01001888 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001889
1890done:
1891 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001892 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001893 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001894 return err;
1895}
1896
1897static s32
1898brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1899 u16 reason_code)
1900{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001901 struct brcmf_if *ifp = netdev_priv(ndev);
1902 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001903 struct brcmf_scb_val_le scbval;
1904 s32 err = 0;
1905
Arend van Sprield96b8012012-12-05 15:26:02 +01001906 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
Arend van Sprielce81e312012-10-22 13:55:37 -07001907 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001908 return -EIO;
1909
Arend van Sprielc1179032012-10-22 13:55:33 -07001910 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel4f3fff12014-11-20 22:27:02 +01001911 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001912 cfg80211_disconnected(ndev, reason_code, NULL, 0, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001913
Arend van Spriel06bb1232012-09-27 14:17:56 +02001914 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001915 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07001916 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07001917 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001918 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001919 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001920
Arend van Sprield96b8012012-12-05 15:26:02 +01001921 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001922 return err;
1923}
1924
1925static s32
Johannes Bergc8442112012-10-24 10:17:18 +02001926brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001927 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001928{
1929
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001930 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001931 struct net_device *ndev = cfg_to_ndev(cfg);
1932 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001933 u16 txpwrmw;
1934 s32 err = 0;
1935 s32 disable = 0;
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001936 s32 dbm = MBM_TO_DBM(mbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001937
Arend van Sprield96b8012012-12-05 15:26:02 +01001938 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001939 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001940 return -EIO;
1941
1942 switch (type) {
1943 case NL80211_TX_POWER_AUTOMATIC:
1944 break;
1945 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02001946 case NL80211_TX_POWER_FIXED:
1947 if (dbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001948 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001949 err = -EINVAL;
1950 goto done;
1951 }
1952 break;
1953 }
1954 /* Make sure radio is off or on as far as software is concerned */
1955 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07001956 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001957 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001958 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001959
1960 if (dbm > 0xffff)
1961 txpwrmw = 0xffff;
1962 else
1963 txpwrmw = (u16) dbm;
Arend van Sprielac24be62012-10-22 10:36:23 -07001964 err = brcmf_fil_iovar_int_set(ifp, "qtxpower",
1965 (s32)brcmf_mw_to_qdbm(txpwrmw));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001966 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001967 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001968 cfg->conf->tx_power = dbm;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001969
1970done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001971 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001972 return err;
1973}
1974
Johannes Bergc8442112012-10-24 10:17:18 +02001975static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy,
1976 struct wireless_dev *wdev,
1977 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001978{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001979 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001980 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001981 s32 txpwrdbm;
1982 u8 result;
1983 s32 err = 0;
1984
Arend van Sprield96b8012012-12-05 15:26:02 +01001985 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001986 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001987 return -EIO;
1988
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001989 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &txpwrdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001990 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001991 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001992 goto done;
1993 }
1994
1995 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
Alwin Beukersef6ac172011-10-12 20:51:26 +02001996 *dbm = (s32) brcmf_qdbm_to_mw(result);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001997
1998done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001999 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002000 return err;
2001}
2002
2003static s32
2004brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
2005 u8 key_idx, bool unicast, bool multicast)
2006{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002007 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002008 u32 index;
2009 u32 wsec;
2010 s32 err = 0;
2011
Arend van Sprield96b8012012-12-05 15:26:02 +01002012 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002013 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002014 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002015 return -EIO;
2016
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002017 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002018 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002019 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002020 goto done;
2021 }
2022
2023 if (wsec & WEP_ENABLED) {
2024 /* Just select a new current key */
2025 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002026 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07002027 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002028 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002029 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002030 }
2031done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002032 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002033 return err;
2034}
2035
2036static s32
2037brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
2038 u8 key_idx, const u8 *mac_addr, struct key_params *params)
2039{
Hante Meuleman992f6062013-04-02 21:06:17 +02002040 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002041 struct brcmf_wsec_key key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002042 s32 err = 0;
Hante Meuleman992f6062013-04-02 21:06:17 +02002043 u8 keybuf[8];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002044
2045 memset(&key, 0, sizeof(key));
2046 key.index = (u32) key_idx;
2047 /* Instead of bcast for ea address for default wep keys,
2048 driver needs it to be Null */
2049 if (!is_multicast_ether_addr(mac_addr))
2050 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
2051 key.len = (u32) params->key_len;
2052 /* check for key index change */
2053 if (key.len == 0) {
2054 /* key delete */
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002055 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002056 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002057 brcmf_err("key delete error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002058 } else {
2059 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002060 brcmf_err("Invalid key length (%d)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002061 return -EINVAL;
2062 }
2063
Arend van Spriel16886732012-12-05 15:26:04 +01002064 brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002065 memcpy(key.data, params->key, key.len);
2066
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002067 if (!brcmf_is_apmode(ifp->vif) &&
Hante Meuleman992f6062013-04-02 21:06:17 +02002068 (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
2069 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002070 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2071 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2072 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2073 }
2074
2075 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
2076 if (params->seq && params->seq_len == 6) {
2077 /* rx iv */
2078 u8 *ivptr;
2079 ivptr = (u8 *) params->seq;
2080 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2081 (ivptr[3] << 8) | ivptr[2];
2082 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2083 key.iv_initialized = true;
2084 }
2085
2086 switch (params->cipher) {
2087 case WLAN_CIPHER_SUITE_WEP40:
2088 key.algo = CRYPTO_ALGO_WEP1;
Arend van Spriel16886732012-12-05 15:26:04 +01002089 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002090 break;
2091 case WLAN_CIPHER_SUITE_WEP104:
2092 key.algo = CRYPTO_ALGO_WEP128;
Arend van Spriel16886732012-12-05 15:26:04 +01002093 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002094 break;
2095 case WLAN_CIPHER_SUITE_TKIP:
2096 key.algo = CRYPTO_ALGO_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002097 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002098 break;
2099 case WLAN_CIPHER_SUITE_AES_CMAC:
2100 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002101 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002102 break;
2103 case WLAN_CIPHER_SUITE_CCMP:
2104 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002105 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002106 break;
2107 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002108 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002109 return -EINVAL;
2110 }
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002111 err = send_key_to_dongle(ndev, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002112 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002113 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002114 }
2115 return err;
2116}
2117
2118static s32
2119brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2120 u8 key_idx, bool pairwise, const u8 *mac_addr,
2121 struct key_params *params)
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 val;
2126 s32 wsec;
2127 s32 err = 0;
2128 u8 keybuf[8];
2129
Arend van Sprield96b8012012-12-05 15:26:02 +01002130 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002131 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002132 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002133 return -EIO;
2134
Daniel Kim787eb032014-01-29 15:32:23 +01002135 if (mac_addr &&
2136 (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2137 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01002138 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002139 return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
2140 }
2141 memset(&key, 0, sizeof(key));
2142
2143 key.len = (u32) params->key_len;
2144 key.index = (u32) key_idx;
2145
2146 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002147 brcmf_err("Too long key length (%u)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002148 err = -EINVAL;
2149 goto done;
2150 }
2151 memcpy(key.data, params->key, key.len);
2152
2153 key.flags = BRCMF_PRIMARY_KEY;
2154 switch (params->cipher) {
2155 case WLAN_CIPHER_SUITE_WEP40:
2156 key.algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002157 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002158 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002159 break;
2160 case WLAN_CIPHER_SUITE_WEP104:
2161 key.algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002162 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002163 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002164 break;
2165 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002166 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002167 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02002168 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2169 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2170 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2171 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002172 key.algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002173 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002174 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002175 break;
2176 case WLAN_CIPHER_SUITE_AES_CMAC:
2177 key.algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002178 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002179 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002180 break;
2181 case WLAN_CIPHER_SUITE_CCMP:
2182 key.algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002183 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002184 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002185 break;
2186 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002187 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002188 err = -EINVAL;
2189 goto done;
2190 }
2191
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002192 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002193 if (err)
2194 goto done;
2195
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002196 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002197 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002198 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002199 goto done;
2200 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002201 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002202 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002203 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002204 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002205 goto done;
2206 }
2207
Arend van Spriel5b435de2011-10-05 13:19:03 +02002208done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002209 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002210 return err;
2211}
2212
2213static s32
2214brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2215 u8 key_idx, bool pairwise, const u8 *mac_addr)
2216{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002217 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002218 struct brcmf_wsec_key key;
2219 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002220
Arend van Sprield96b8012012-12-05 15:26:02 +01002221 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002222 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002223 return -EIO;
2224
Hante Meuleman256c3742012-11-05 16:22:28 -08002225 if (key_idx >= DOT11_MAX_DEFAULT_KEYS) {
2226 /* we ignore this key index in this case */
Arend van Spriel57d6e912012-12-05 15:26:00 +01002227 brcmf_err("invalid key index (%d)\n", key_idx);
Hante Meuleman256c3742012-11-05 16:22:28 -08002228 return -EINVAL;
2229 }
2230
Arend van Spriel5b435de2011-10-05 13:19:03 +02002231 memset(&key, 0, sizeof(key));
2232
2233 key.index = (u32) key_idx;
2234 key.flags = BRCMF_PRIMARY_KEY;
2235 key.algo = CRYPTO_ALGO_OFF;
2236
Arend van Spriel16886732012-12-05 15:26:04 +01002237 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002238
2239 /* Set the new key/index */
Arend van Spriel2eaba7e2012-10-22 10:36:26 -07002240 err = send_key_to_dongle(ndev, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002241
Arend van Sprield96b8012012-12-05 15:26:02 +01002242 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002243 return err;
2244}
2245
2246static s32
2247brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2248 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
2249 void (*callback) (void *cookie, struct key_params * params))
2250{
2251 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002252 struct brcmf_if *ifp = netdev_priv(ndev);
2253 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002254 struct brcmf_cfg80211_security *sec;
2255 s32 wsec;
2256 s32 err = 0;
2257
Arend van Sprield96b8012012-12-05 15:26:02 +01002258 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002259 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002260 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002261 return -EIO;
2262
2263 memset(&params, 0, sizeof(params));
2264
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002265 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002266 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002267 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002268 /* Ignore this error, may happen during DISASSOC */
2269 err = -EAGAIN;
2270 goto done;
2271 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002272 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002273 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002274 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2275 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002276 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002277 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2278 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002279 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002280 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002281 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002282 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002283 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002284 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002285 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002286 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002287 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002288 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002289 err = -EINVAL;
2290 goto done;
2291 }
2292 callback(cookie, &params);
2293
2294done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002295 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002296 return err;
2297}
2298
2299static s32
2300brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2301 struct net_device *ndev, u8 key_idx)
2302{
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002303 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002304
2305 return -EOPNOTSUPP;
2306}
2307
2308static s32
2309brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002310 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002311{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002312 struct brcmf_if *ifp = netdev_priv(ndev);
2313 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002314 struct brcmf_scb_val_le scb_val;
2315 int rssi;
2316 s32 rate;
2317 s32 err = 0;
Arend van Spriel06bb1232012-09-27 14:17:56 +02002318 u8 *bssid = profile->bssid;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002319 struct brcmf_sta_info_le sta_info_le;
Hante Meuleman9ee66d12014-01-29 15:32:11 +01002320 u32 beacon_period;
2321 u32 dtim_period;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002322
Arend van Sprield96b8012012-12-05 15:26:02 +01002323 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002324 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002325 return -EIO;
2326
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002327 if (brcmf_is_apmode(ifp->vif)) {
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002328 memcpy(&sta_info_le, mac, ETH_ALEN);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002329 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002330 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002331 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002332 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002333 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002334 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002335 }
Johannes Berg319090b2014-11-17 14:08:11 +01002336 sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME);
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002337 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2338 if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) {
Johannes Berg319090b2014-11-17 14:08:11 +01002339 sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002340 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
Hante Meuleman1a873342012-09-27 14:17:54 +02002341 }
Arend van Sprield96b8012012-12-05 15:26:02 +01002342 brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n",
2343 sinfo->inactive_time, sinfo->connected_time);
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002344 } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002345 if (memcmp(mac, bssid, ETH_ALEN)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002346 brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
2347 mac, bssid);
Hante Meuleman1a873342012-09-27 14:17:54 +02002348 err = -ENOENT;
2349 goto done;
2350 }
2351 /* Report the current tx rate */
Hante Meuleman89286dc2013-02-08 15:53:46 +01002352 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
Hante Meuleman1a873342012-09-27 14:17:54 +02002353 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002354 brcmf_err("Could not get rate (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002355 goto done;
2356 } else {
Johannes Berg319090b2014-11-17 14:08:11 +01002357 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Hante Meuleman1a873342012-09-27 14:17:54 +02002358 sinfo->txrate.legacy = rate * 5;
Arend van Spriel16886732012-12-05 15:26:04 +01002359 brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2);
Hante Meuleman1a873342012-09-27 14:17:54 +02002360 }
2361
Arend van Sprielc1179032012-10-22 13:55:33 -07002362 if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
2363 &ifp->vif->sme_state)) {
Hante Meuleman1a873342012-09-27 14:17:54 +02002364 memset(&scb_val, 0, sizeof(scb_val));
Arend van Sprielc1179032012-10-22 13:55:33 -07002365 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
2366 &scb_val, sizeof(scb_val));
Hante Meuleman1a873342012-09-27 14:17:54 +02002367 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002368 brcmf_err("Could not get rssi (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002369 goto done;
2370 } else {
2371 rssi = le32_to_cpu(scb_val.val);
Johannes Berg319090b2014-11-17 14:08:11 +01002372 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Hante Meuleman1a873342012-09-27 14:17:54 +02002373 sinfo->signal = rssi;
Arend van Spriel16886732012-12-05 15:26:04 +01002374 brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
Hante Meuleman1a873342012-09-27 14:17:54 +02002375 }
Hante Meuleman9ee66d12014-01-29 15:32:11 +01002376 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD,
2377 &beacon_period);
2378 if (err) {
2379 brcmf_err("Could not get beacon period (%d)\n",
2380 err);
2381 goto done;
2382 } else {
2383 sinfo->bss_param.beacon_interval =
2384 beacon_period;
2385 brcmf_dbg(CONN, "Beacon peroid %d\n",
2386 beacon_period);
2387 }
2388 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD,
2389 &dtim_period);
2390 if (err) {
2391 brcmf_err("Could not get DTIM period (%d)\n",
2392 err);
2393 goto done;
2394 } else {
2395 sinfo->bss_param.dtim_period = dtim_period;
2396 brcmf_dbg(CONN, "DTIM peroid %d\n",
2397 dtim_period);
2398 }
Johannes Berg319090b2014-11-17 14:08:11 +01002399 sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
Hante Meuleman1a873342012-09-27 14:17:54 +02002400 }
2401 } else
2402 err = -EPERM;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002403done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002404 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002405 return err;
2406}
2407
2408static s32
2409brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2410 bool enabled, s32 timeout)
2411{
2412 s32 pm;
2413 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002414 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002415 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002416
Arend van Sprield96b8012012-12-05 15:26:02 +01002417 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002418
2419 /*
2420 * Powersave enable/disable request is coming from the
2421 * cfg80211 even before the interface is up. In that
2422 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002423 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002424 * FW later while initializing the dongle
2425 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002426 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002427 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002428
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002429 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002430 goto done;
2431 }
2432
2433 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002434 /* Do not enable the power save after assoc if it is a p2p interface */
2435 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2436 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2437 pm = PM_OFF;
2438 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002439 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002440
Arend van Sprielc1179032012-10-22 13:55:33 -07002441 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002442 if (err) {
2443 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002444 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002445 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002446 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002447 }
2448done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002449 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002450 return err;
2451}
2452
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002453static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002454 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002455{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002456 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002457 struct ieee80211_channel *notify_channel;
2458 struct cfg80211_bss *bss;
2459 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002460 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002461 u16 channel;
2462 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002463 u16 notify_capability;
2464 u16 notify_interval;
2465 u8 *notify_ie;
2466 size_t notify_ielen;
2467 s32 notify_signal;
2468
2469 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002470 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002471 return 0;
2472 }
2473
Franky Lin83cf17a2013-04-11 13:28:50 +02002474 if (!bi->ctl_ch) {
2475 ch.chspec = le16_to_cpu(bi->chanspec);
2476 cfg->d11inf.decchspec(&ch);
2477 bi->ctl_ch = ch.chnum;
2478 }
2479 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002480
2481 if (channel <= CH_MAX_2G_CHANNEL)
2482 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2483 else
2484 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2485
2486 freq = ieee80211_channel_to_frequency(channel, band->band);
2487 notify_channel = ieee80211_get_channel(wiphy, freq);
2488
Arend van Spriel5b435de2011-10-05 13:19:03 +02002489 notify_capability = le16_to_cpu(bi->capability);
2490 notify_interval = le16_to_cpu(bi->beacon_period);
2491 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2492 notify_ielen = le32_to_cpu(bi->ie_length);
2493 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2494
Arend van Spriel16886732012-12-05 15:26:04 +01002495 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2496 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2497 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2498 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2499 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002500
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002501 bss = cfg80211_inform_bss(wiphy, notify_channel,
2502 CFG80211_BSS_FTYPE_UNKNOWN,
2503 (const u8 *)bi->BSSID,
2504 0, notify_capability,
2505 notify_interval, notify_ie,
2506 notify_ielen, notify_signal,
2507 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002508
Franky Line78946e2011-11-10 20:30:34 +01002509 if (!bss)
2510 return -ENOMEM;
2511
Johannes Berg5b112d32013-02-01 01:49:58 +01002512 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002513
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002514 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002515}
2516
Roland Vossen6f09be02011-10-18 14:03:02 +02002517static struct brcmf_bss_info_le *
2518next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2519{
2520 if (bss == NULL)
2521 return list->bss_info_le;
2522 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2523 le32_to_cpu(bss->length));
2524}
2525
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002526static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002527{
2528 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002529 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002530 s32 err = 0;
2531 int i;
2532
Hante Meulemanef8596e2014-09-30 10:23:13 +02002533 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002534 if (bss_list->count != 0 &&
2535 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002536 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2537 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002538 return -EOPNOTSUPP;
2539 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002540 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002541 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002542 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002543 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002544 if (err)
2545 break;
2546 }
2547 return err;
2548}
2549
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002550static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002551 struct net_device *ndev, const u8 *bssid)
2552{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002553 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002554 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002555 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002556 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002557 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002558 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002559 u8 *buf = NULL;
2560 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002561 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002562 u16 notify_capability;
2563 u16 notify_interval;
2564 u8 *notify_ie;
2565 size_t notify_ielen;
2566 s32 notify_signal;
2567
Arend van Sprield96b8012012-12-05 15:26:02 +01002568 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002569
2570 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2571 if (buf == NULL) {
2572 err = -ENOMEM;
2573 goto CleanUp;
2574 }
2575
2576 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2577
Arend van Sprielac24be62012-10-22 10:36:23 -07002578 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2579 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002580 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002581 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002582 goto CleanUp;
2583 }
2584
Roland Vossend34bf642011-10-18 14:03:01 +02002585 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002586
Franky Lin83cf17a2013-04-11 13:28:50 +02002587 ch.chspec = le16_to_cpu(bi->chanspec);
2588 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002589
Franky Lin83cf17a2013-04-11 13:28:50 +02002590 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002591 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2592 else
2593 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2594
Franky Lin83cf17a2013-04-11 13:28:50 +02002595 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002596 notify_channel = ieee80211_get_channel(wiphy, freq);
2597
Arend van Spriel5b435de2011-10-05 13:19:03 +02002598 notify_capability = le16_to_cpu(bi->capability);
2599 notify_interval = le16_to_cpu(bi->beacon_period);
2600 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2601 notify_ielen = le32_to_cpu(bi->ie_length);
2602 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2603
Franky Lin83cf17a2013-04-11 13:28:50 +02002604 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002605 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2606 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2607 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002608
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002609 bss = cfg80211_inform_bss(wiphy, notify_channel,
2610 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2611 notify_capability, notify_interval,
2612 notify_ie, notify_ielen, notify_signal,
2613 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002614
Franky Line78946e2011-11-10 20:30:34 +01002615 if (!bss) {
2616 err = -ENOMEM;
2617 goto CleanUp;
2618 }
2619
Johannes Berg5b112d32013-02-01 01:49:58 +01002620 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002621
Arend van Spriel5b435de2011-10-05 13:19:03 +02002622CleanUp:
2623
2624 kfree(buf);
2625
Arend van Sprield96b8012012-12-05 15:26:02 +01002626 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002627
2628 return err;
2629}
2630
Hante Meuleman89286dc2013-02-08 15:53:46 +01002631static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2632 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002633{
Hante Meuleman89286dc2013-02-08 15:53:46 +01002634 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev);
Roland Vossend34bf642011-10-18 14:03:01 +02002635 struct brcmf_bss_info_le *bi;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002636 struct brcmf_ssid *ssid;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002637 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002638 u16 beacon_interval;
2639 u8 dtim_period;
2640 size_t ie_len;
2641 u8 *ie;
2642 s32 err = 0;
2643
Arend van Sprield96b8012012-12-05 15:26:02 +01002644 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002645 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002646 return err;
2647
Arend van Spriel06bb1232012-09-27 14:17:56 +02002648 ssid = &profile->ssid;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002649
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002650 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002651 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002652 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002653 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002654 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002655 goto update_bss_info_out;
2656 }
2657
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002658 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2659 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002660 if (err)
2661 goto update_bss_info_out;
2662
2663 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2664 ie_len = le32_to_cpu(bi->ie_length);
2665 beacon_interval = le16_to_cpu(bi->beacon_period);
2666
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002667 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002668 if (tim)
2669 dtim_period = tim->data[1];
2670 else {
2671 /*
2672 * active scan was done so we could not get dtim
2673 * information out of probe response.
2674 * so we speficially query dtim information to dongle.
2675 */
2676 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002677 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002678 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002679 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002680 goto update_bss_info_out;
2681 }
2682 dtim_period = (u8)var;
2683 }
2684
Arend van Spriel5b435de2011-10-05 13:19:03 +02002685update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01002686 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002687 return err;
2688}
2689
Hante Meuleman18e2f612013-02-08 15:53:49 +01002690void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002691{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002692 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002693
Arend van Sprielc1179032012-10-22 13:55:33 -07002694 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Hante Meulemanf07998952012-11-05 16:22:13 -08002695 if (cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02002696 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002697 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02002698 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002699 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2700 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002701}
2702
Hante Meulemane756af52012-09-11 21:18:52 +02002703static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2704{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002705 struct brcmf_cfg80211_info *cfg =
2706 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02002707 escan_timeout_work);
2708
Hante Meulemanef8596e2014-09-30 10:23:13 +02002709 brcmf_inform_bss(cfg);
Arend van Spriela0f472a2013-04-05 10:57:49 +02002710 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02002711}
2712
2713static void brcmf_escan_timeout(unsigned long data)
2714{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002715 struct brcmf_cfg80211_info *cfg =
2716 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02002717
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002718 if (cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002719 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08002720 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02002721 }
2722}
2723
2724static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02002725brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2726 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02002727 struct brcmf_bss_info_le *bss_info_le)
2728{
Franky Lin83cf17a2013-04-11 13:28:50 +02002729 struct brcmu_chan ch_bss, ch_bss_info_le;
2730
2731 ch_bss.chspec = le16_to_cpu(bss->chanspec);
2732 cfg->d11inf.decchspec(&ch_bss);
2733 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
2734 cfg->d11inf.decchspec(&ch_bss_info_le);
2735
Hante Meulemane756af52012-09-11 21:18:52 +02002736 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02002737 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02002738 bss_info_le->SSID_len == bss->SSID_len &&
2739 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002740 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
2741 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02002742 s16 bss_rssi = le16_to_cpu(bss->RSSI);
2743 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
2744
Hante Meulemane756af52012-09-11 21:18:52 +02002745 /* preserve max RSSI if the measurements are
2746 * both on-channel or both off-channel
2747 */
Arend van Spriel029591f2012-09-19 22:21:06 +02002748 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02002749 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002750 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
2751 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02002752 /* preserve the on-channel rssi measurement
2753 * if the new measurement is off channel
2754 */
2755 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002756 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02002757 }
2758 return 1;
2759 }
2760 return 0;
2761}
2762
2763static s32
Arend van Spriel19937322012-11-05 16:22:32 -08002764brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02002765 const struct brcmf_event_msg *e, void *data)
2766{
Arend van Spriel19937322012-11-05 16:22:32 -08002767 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02002768 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02002769 struct brcmf_escan_result_le *escan_result_le;
2770 struct brcmf_bss_info_le *bss_info_le;
2771 struct brcmf_bss_info_le *bss = NULL;
2772 u32 bi_length;
2773 struct brcmf_scan_results *list;
2774 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002775 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02002776
Arend van Spriel5c36b992012-11-14 18:46:05 -08002777 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02002778
Arend van Spriela0f472a2013-04-05 10:57:49 +02002779 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
2780 brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx);
Hante Meulemane756af52012-09-11 21:18:52 +02002781 return -EPERM;
2782 }
2783
2784 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002785 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002786 escan_result_le = (struct brcmf_escan_result_le *) data;
2787 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002788 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002789 goto exit;
2790 }
Hante Meulemane756af52012-09-11 21:18:52 +02002791 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002792 brcmf_err("Invalid bss_count %d: ignoring\n",
2793 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02002794 goto exit;
2795 }
2796 bss_info_le = &escan_result_le->bss_info_le;
2797
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002798 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
2799 goto exit;
2800
2801 if (!cfg->scan_request) {
2802 brcmf_dbg(SCAN, "result without cfg80211 request\n");
2803 goto exit;
2804 }
2805
Hante Meulemane756af52012-09-11 21:18:52 +02002806 bi_length = le32_to_cpu(bss_info_le->length);
2807 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
2808 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002809 brcmf_err("Invalid bss_info length %d: ignoring\n",
2810 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02002811 goto exit;
2812 }
2813
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002814 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02002815 BIT(NL80211_IFTYPE_ADHOC))) {
2816 if (le16_to_cpu(bss_info_le->capability) &
2817 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002818 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002819 goto exit;
2820 }
2821 }
2822
2823 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002824 cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02002825 if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002826 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002827 goto exit;
2828 }
2829
2830 for (i = 0; i < list->count; i++) {
2831 bss = bss ? (struct brcmf_bss_info_le *)
2832 ((unsigned char *)bss +
2833 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02002834 if (brcmf_compare_update_same_bss(cfg, bss,
2835 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02002836 goto exit;
2837 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002838 memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
Hante Meulemane756af52012-09-11 21:18:52 +02002839 bss_info_le, bi_length);
2840 list->version = le32_to_cpu(bss_info_le->version);
2841 list->buflen += bi_length;
2842 list->count++;
2843 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002844 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002845 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
2846 goto exit;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002847 if (cfg->scan_request) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002848 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002849 aborted = status != BRCMF_E_STATUS_SUCCESS;
Hante Meulemanef8596e2014-09-30 10:23:13 +02002850 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
Hante Meulemane756af52012-09-11 21:18:52 +02002851 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002852 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
2853 status);
Hante Meulemane756af52012-09-11 21:18:52 +02002854 }
2855exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002856 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02002857}
2858
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002859static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02002860{
Arend van Spriel5c36b992012-11-14 18:46:05 -08002861 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
2862 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08002863 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
2864 /* Init scan_timeout timer */
2865 init_timer(&cfg->escan_timeout);
2866 cfg->escan_timeout.data = (unsigned long) cfg;
2867 cfg->escan_timeout.function = brcmf_escan_timeout;
2868 INIT_WORK(&cfg->escan_timeout_work,
2869 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02002870}
2871
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05002872static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002873{
2874 if (ms < 1000 / HZ) {
2875 cond_resched();
2876 mdelay(ms);
2877 } else {
2878 msleep(ms);
2879 }
2880}
2881
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002882static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
2883 u8 *pattern, u32 patternsize, u8 *mask,
2884 u32 packet_offset)
2885{
2886 struct brcmf_fil_wowl_pattern_le *filter;
2887 u32 masksize;
2888 u32 patternoffset;
2889 u8 *buf;
2890 u32 bufsize;
2891 s32 ret;
2892
2893 masksize = (patternsize + 7) / 8;
2894 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
2895
2896 bufsize = sizeof(*filter) + patternsize + masksize;
2897 buf = kzalloc(bufsize, GFP_KERNEL);
2898 if (!buf)
2899 return -ENOMEM;
2900 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
2901
2902 memcpy(filter->cmd, cmd, 4);
2903 filter->masksize = cpu_to_le32(masksize);
2904 filter->offset = cpu_to_le32(packet_offset);
2905 filter->patternoffset = cpu_to_le32(patternoffset);
2906 filter->patternsize = cpu_to_le32(patternsize);
2907 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
2908
2909 if ((mask) && (masksize))
2910 memcpy(buf + sizeof(*filter), mask, masksize);
2911 if ((pattern) && (patternsize))
2912 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
2913
2914 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
2915
2916 kfree(buf);
2917 return ret;
2918}
2919
Arend van Spriel5b435de2011-10-05 13:19:03 +02002920static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
2921{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002922 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2923 struct net_device *ndev = cfg_to_ndev(cfg);
2924 struct brcmf_if *ifp = netdev_priv(ndev);
2925
Arend van Sprield96b8012012-12-05 15:26:02 +01002926 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002927
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002928 if (cfg->wowl_enabled) {
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002929 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002930 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
2931 cfg->pre_wowl_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002932 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002933 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002934 cfg->wowl_enabled = false;
2935 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002936 return 0;
2937}
2938
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002939static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
2940 struct brcmf_if *ifp,
2941 struct cfg80211_wowlan *wowl)
2942{
2943 u32 wowl_config;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002944 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002945
2946 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
2947
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002948 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002949 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode);
2950 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
2951
2952 wowl_config = 0;
2953 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002954 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002955 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01002956 wowl_config |= BRCMF_WOWL_MAGIC;
2957 if ((wowl->patterns) && (wowl->n_patterns)) {
2958 wowl_config |= BRCMF_WOWL_NET;
2959 for (i = 0; i < wowl->n_patterns; i++) {
2960 brcmf_config_wowl_pattern(ifp, "add",
2961 (u8 *)wowl->patterns[i].pattern,
2962 wowl->patterns[i].pattern_len,
2963 (u8 *)wowl->patterns[i].mask,
2964 wowl->patterns[i].pkt_offset);
2965 }
2966 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002967 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
2968 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
2969 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
2970 cfg->wowl_enabled = true;
2971}
2972
Arend van Spriel5b435de2011-10-05 13:19:03 +02002973static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002974 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002975{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002976 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2977 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002978 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07002979 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002980
Arend van Sprield96b8012012-12-05 15:26:02 +01002981 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002982
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002983 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07002984 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02002985 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002986 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07002987 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002988
Arend van Spriel7d641072012-10-22 13:55:39 -07002989 /* end any scanning */
2990 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002991 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002992
Hante Meuleman4eb3af72014-09-30 10:23:18 +02002993 if (wowl == NULL) {
2994 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
2995 list_for_each_entry(vif, &cfg->vif_list, list) {
2996 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
2997 continue;
2998 /* While going to suspend if associated with AP
2999 * disassociate from AP to save power while system is
3000 * in suspended state
3001 */
3002 brcmf_link_down(vif);
3003 /* Make sure WPA_Supplicant receives all the event
3004 * generated due to DISASSOC call to the fw to keep
3005 * the state fw and WPA_Supplicant state consistent
3006 */
3007 brcmf_delay(500);
3008 }
3009 /* Configure MPC */
3010 brcmf_set_mpc(ifp, 1);
3011
3012 } else {
3013 /* Configure WOWL paramaters */
3014 brcmf_configure_wowl(cfg, ifp, wowl);
3015 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003016
Arend van Spriel7d641072012-10-22 13:55:39 -07003017exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01003018 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07003019 /* clear any scanning activity */
3020 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003021 return 0;
3022}
3023
3024static __used s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02003025brcmf_update_pmklist(struct net_device *ndev,
3026 struct brcmf_cfg80211_pmk_list *pmk_list, s32 err)
3027{
3028 int i, j;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003029 u32 pmkid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003030
Arend van Spriel40c8e952011-10-12 20:51:20 +02003031 pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid);
3032
Arend van Spriel16886732012-12-05 15:26:04 +01003033 brcmf_dbg(CONN, "No of elements %d\n", pmkid_len);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003034 for (i = 0; i < pmkid_len; i++) {
Arend van Spriel16886732012-12-05 15:26:04 +01003035 brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i,
3036 &pmk_list->pmkids.pmkid[i].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003037 for (j = 0; j < WLAN_PMKID_LEN; j++)
Arend van Spriel16886732012-12-05 15:26:04 +01003038 brcmf_dbg(CONN, "%02x\n",
3039 pmk_list->pmkids.pmkid[i].PMKID[j]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003040 }
3041
3042 if (!err)
Arend van Sprielac24be62012-10-22 10:36:23 -07003043 brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info",
3044 (char *)pmk_list, sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02003045
3046 return err;
3047}
3048
3049static s32
3050brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3051 struct cfg80211_pmksa *pmksa)
3052{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003053 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003054 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003055 struct pmkid_list *pmkids = &cfg->pmk_list->pmkids;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003056 s32 err = 0;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003057 u32 pmkid_len, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003058
Arend van Sprield96b8012012-12-05 15:26:02 +01003059 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003060 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003061 return -EIO;
3062
Arend van Spriel40c8e952011-10-12 20:51:20 +02003063 pmkid_len = le32_to_cpu(pmkids->npmkid);
3064 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003065 if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN))
3066 break;
3067 if (i < WL_NUM_PMKIDS_MAX) {
3068 memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN);
3069 memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003070 if (i == pmkid_len) {
3071 pmkid_len++;
3072 pmkids->npmkid = cpu_to_le32(pmkid_len);
3073 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003074 } else
3075 err = -EINVAL;
3076
Arend van Spriel16886732012-12-05 15:26:04 +01003077 brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
3078 pmkids->pmkid[pmkid_len].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003079 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01003080 brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003081
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003082 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003083
Arend van Sprield96b8012012-12-05 15:26:02 +01003084 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003085 return err;
3086}
3087
3088static s32
3089brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3090 struct cfg80211_pmksa *pmksa)
3091{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003092 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003093 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003094 struct pmkid_list pmkid;
3095 s32 err = 0;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003096 u32 pmkid_len, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003097
Arend van Sprield96b8012012-12-05 15:26:02 +01003098 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003099 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003100 return -EIO;
3101
3102 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
3103 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
3104
Arend van Spriel16886732012-12-05 15:26:04 +01003105 brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3106 &pmkid.pmkid[0].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003107 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01003108 brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003109
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003110 pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003111 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003112 if (!memcmp
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003113 (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003114 ETH_ALEN))
3115 break;
3116
Arend van Spriel40c8e952011-10-12 20:51:20 +02003117 if ((pmkid_len > 0)
3118 && (i < pmkid_len)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003119 memset(&cfg->pmk_list->pmkids.pmkid[i], 0,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003120 sizeof(struct pmkid));
Arend van Spriel40c8e952011-10-12 20:51:20 +02003121 for (; i < (pmkid_len - 1); i++) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003122 memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID,
3123 &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003124 ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003125 memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID,
3126 &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003127 WLAN_PMKID_LEN);
3128 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003129 cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003130 } else
3131 err = -EINVAL;
3132
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003133 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003134
Arend van Sprield96b8012012-12-05 15:26:02 +01003135 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003136 return err;
3137
3138}
3139
3140static s32
3141brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3142{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003143 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003144 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003145 s32 err = 0;
3146
Arend van Sprield96b8012012-12-05 15:26:02 +01003147 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003148 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003149 return -EIO;
3150
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003151 memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list));
3152 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003153
Arend van Sprield96b8012012-12-05 15:26:02 +01003154 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003155 return err;
3156
3157}
3158
Arend van Spriele5806072012-09-19 22:21:08 +02003159/*
3160 * PFN result doesn't have all the info which are
3161 * required by the supplicant
3162 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3163 * via wl_inform_single_bss in the required format. Escan does require the
3164 * scan request in the form of cfg80211_scan_request. For timebeing, create
3165 * cfg80211_scan_request one out of the received PNO event.
3166 */
3167static s32
Arend van Spriel19937322012-11-05 16:22:32 -08003168brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
Arend van Spriele5806072012-09-19 22:21:08 +02003169 const struct brcmf_event_msg *e, void *data)
3170{
Arend van Spriel19937322012-11-05 16:22:32 -08003171 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriele5806072012-09-19 22:21:08 +02003172 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3173 struct cfg80211_scan_request *request = NULL;
3174 struct cfg80211_ssid *ssid = NULL;
3175 struct ieee80211_channel *channel = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003176 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003177 int err = 0;
3178 int channel_req = 0;
3179 int band = 0;
3180 struct brcmf_pno_scanresults_le *pfn_result;
3181 u32 result_count;
3182 u32 status;
3183
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003184 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003185
Arend van Spriel5c36b992012-11-14 18:46:05 -08003186 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003187 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003188 return 0;
3189 }
3190
3191 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3192 result_count = le32_to_cpu(pfn_result->count);
3193 status = le32_to_cpu(pfn_result->status);
3194
3195 /*
3196 * PFN event is limited to fit 512 bytes so we may get
3197 * multiple NET_FOUND events. For now place a warning here.
3198 */
3199 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003200 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
Arend van Spriele5806072012-09-19 22:21:08 +02003201 if (result_count > 0) {
3202 int i;
3203
3204 request = kzalloc(sizeof(*request), GFP_KERNEL);
Dan Carpenter58901d12012-09-26 10:21:48 +03003205 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3206 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
Arend van Spriele5806072012-09-19 22:21:08 +02003207 if (!request || !ssid || !channel) {
3208 err = -ENOMEM;
3209 goto out_err;
3210 }
3211
3212 request->wiphy = wiphy;
3213 data += sizeof(struct brcmf_pno_scanresults_le);
3214 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3215
3216 for (i = 0; i < result_count; i++) {
3217 netinfo = &netinfo_start[i];
3218 if (!netinfo) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003219 brcmf_err("Invalid netinfo ptr. index: %d\n",
3220 i);
Arend van Spriele5806072012-09-19 22:21:08 +02003221 err = -EINVAL;
3222 goto out_err;
3223 }
3224
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003225 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3226 netinfo->SSID, netinfo->channel);
Arend van Spriele5806072012-09-19 22:21:08 +02003227 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3228 ssid[i].ssid_len = netinfo->SSID_len;
3229 request->n_ssids++;
3230
3231 channel_req = netinfo->channel;
3232 if (channel_req <= CH_MAX_2G_CHANNEL)
3233 band = NL80211_BAND_2GHZ;
3234 else
3235 band = NL80211_BAND_5GHZ;
3236 channel[i].center_freq =
3237 ieee80211_channel_to_frequency(channel_req,
3238 band);
3239 channel[i].band = band;
3240 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3241 request->channels[i] = &channel[i];
3242 request->n_channels++;
3243 }
3244
3245 /* assign parsed ssid array */
3246 if (request->n_ssids)
3247 request->ssids = &ssid[0];
3248
Arend van Sprielc1179032012-10-22 13:55:33 -07003249 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriele5806072012-09-19 22:21:08 +02003250 /* Abort any on-going scan */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003251 brcmf_abort_scanning(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003252 }
3253
Arend van Sprielc1179032012-10-22 13:55:33 -07003254 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel2668b0b2014-01-13 22:20:28 +01003255 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02003256 err = brcmf_do_escan(cfg, wiphy, ifp, request);
Arend van Spriele5806072012-09-19 22:21:08 +02003257 if (err) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003258 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003259 goto out_err;
3260 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003261 cfg->sched_escan = true;
3262 cfg->scan_request = request;
Arend van Spriele5806072012-09-19 22:21:08 +02003263 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003264 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003265 goto out_err;
3266 }
3267
3268 kfree(ssid);
3269 kfree(channel);
3270 kfree(request);
3271 return 0;
3272
3273out_err:
3274 kfree(ssid);
3275 kfree(channel);
3276 kfree(request);
3277 cfg80211_sched_scan_stopped(wiphy);
3278 return err;
3279}
3280
Arend van Spriele5806072012-09-19 22:21:08 +02003281static int brcmf_dev_pno_clean(struct net_device *ndev)
3282{
Arend van Spriele5806072012-09-19 22:21:08 +02003283 int ret;
3284
3285 /* Disable pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003286 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003287 if (ret == 0) {
3288 /* clear pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003289 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3290 NULL, 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003291 }
3292 if (ret < 0)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003293 brcmf_err("failed code %d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003294
3295 return ret;
3296}
3297
3298static int brcmf_dev_pno_config(struct net_device *ndev)
3299{
3300 struct brcmf_pno_param_le pfn_param;
Arend van Spriele5806072012-09-19 22:21:08 +02003301
3302 memset(&pfn_param, 0, sizeof(pfn_param));
3303 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3304
3305 /* set extra pno params */
3306 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3307 pfn_param.repeat = BRCMF_PNO_REPEAT;
3308 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3309
3310 /* set up pno scan fr */
3311 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3312
Arend van Sprielac24be62012-10-22 10:36:23 -07003313 return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set",
3314 &pfn_param, sizeof(pfn_param));
Arend van Spriele5806072012-09-19 22:21:08 +02003315}
3316
3317static int
3318brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3319 struct net_device *ndev,
3320 struct cfg80211_sched_scan_request *request)
3321{
Arend van Sprielc1179032012-10-22 13:55:33 -07003322 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003323 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003324 struct brcmf_pno_net_param_le pfn;
3325 int i;
3326 int ret = 0;
3327
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003328 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003329 request->n_match_sets, request->n_ssids);
Arend van Sprielc1179032012-10-22 13:55:33 -07003330 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003331 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003332 return -EAGAIN;
3333 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02003334 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3335 brcmf_err("Scanning suppressed: status (%lu)\n",
3336 cfg->scan_status);
3337 return -EAGAIN;
3338 }
Arend van Spriele5806072012-09-19 22:21:08 +02003339
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003340 if (!request->n_ssids || !request->n_match_sets) {
Arend van Spriel181f2d12014-05-27 12:56:13 +02003341 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003342 request->n_ssids);
Arend van Spriele5806072012-09-19 22:21:08 +02003343 return -EINVAL;
3344 }
3345
3346 if (request->n_ssids > 0) {
3347 for (i = 0; i < request->n_ssids; i++) {
3348 /* Active scan req for ssids */
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003349 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3350 request->ssids[i].ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003351
3352 /*
3353 * match_set ssids is a supert set of n_ssid list,
3354 * so we need not add these set seperately.
3355 */
3356 }
3357 }
3358
3359 if (request->n_match_sets > 0) {
3360 /* clean up everything */
3361 ret = brcmf_dev_pno_clean(ndev);
3362 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003363 brcmf_err("failed error=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003364 return ret;
3365 }
3366
3367 /* configure pno */
3368 ret = brcmf_dev_pno_config(ndev);
3369 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003370 brcmf_err("PNO setup failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003371 return -EINVAL;
3372 }
3373
3374 /* configure each match set */
3375 for (i = 0; i < request->n_match_sets; i++) {
3376 struct cfg80211_ssid *ssid;
3377 u32 ssid_len;
3378
3379 ssid = &request->match_sets[i].ssid;
3380 ssid_len = ssid->ssid_len;
3381
3382 if (!ssid_len) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003383 brcmf_err("skip broadcast ssid\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003384 continue;
3385 }
3386 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3387 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3388 pfn.wsec = cpu_to_le32(0);
3389 pfn.infra = cpu_to_le32(1);
3390 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3391 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3392 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
Arend van Sprielc1179032012-10-22 13:55:33 -07003393 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
Arend van Sprielac24be62012-10-22 10:36:23 -07003394 sizeof(pfn));
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003395 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3396 ret == 0 ? "set" : "failed", ssid->ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003397 }
3398 /* Enable the PNO */
Arend van Sprielc1179032012-10-22 13:55:33 -07003399 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003400 brcmf_err("PNO enable failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003401 return -EINVAL;
3402 }
3403 } else {
3404 return -EINVAL;
3405 }
3406
3407 return 0;
3408}
3409
3410static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3411 struct net_device *ndev)
3412{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003413 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003414
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003415 brcmf_dbg(SCAN, "enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003416 brcmf_dev_pno_clean(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003417 if (cfg->sched_escan)
Arend van Spriela0f472a2013-04-05 10:57:49 +02003418 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
Arend van Spriele5806072012-09-19 22:21:08 +02003419 return 0;
3420}
Arend van Spriele5806072012-09-19 22:21:08 +02003421
Hante Meuleman1f170112013-02-06 18:40:38 +01003422static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003423{
3424 s32 err;
3425
3426 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003427 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003428 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003429 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003430 return err;
3431 }
3432 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003433 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003434 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003435 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003436 return err;
3437 }
3438 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003439 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003440 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003441 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003442 return err;
3443 }
3444
3445 return 0;
3446}
3447
3448static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3449{
3450 if (is_rsn_ie)
3451 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3452
3453 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3454}
3455
3456static s32
Hante Meulemana44aa402014-12-03 21:05:33 +01003457brcmf_configure_wpaie(struct brcmf_if *ifp,
Johannes Berg4b5800f2014-01-15 14:55:59 +01003458 const struct brcmf_vs_tlv *wpa_ie,
3459 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003460{
3461 u32 auth = 0; /* d11 open authentication */
3462 u16 count;
3463 s32 err = 0;
3464 s32 len = 0;
3465 u32 i;
3466 u32 wsec;
3467 u32 pval = 0;
3468 u32 gval = 0;
3469 u32 wpa_auth = 0;
3470 u32 offset;
3471 u8 *data;
3472 u16 rsn_cap;
3473 u32 wme_bss_disable;
3474
Arend van Sprield96b8012012-12-05 15:26:02 +01003475 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003476 if (wpa_ie == NULL)
3477 goto exit;
3478
3479 len = wpa_ie->len + TLV_HDR_LEN;
3480 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003481 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003482 if (!is_rsn_ie)
3483 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003484 else
3485 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003486
3487 /* check for multicast cipher suite */
3488 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3489 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003490 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003491 goto exit;
3492 }
3493
3494 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3495 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003496 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003497 goto exit;
3498 }
3499 offset += TLV_OUI_LEN;
3500
3501 /* pick up multicast cipher */
3502 switch (data[offset]) {
3503 case WPA_CIPHER_NONE:
3504 gval = 0;
3505 break;
3506 case WPA_CIPHER_WEP_40:
3507 case WPA_CIPHER_WEP_104:
3508 gval = WEP_ENABLED;
3509 break;
3510 case WPA_CIPHER_TKIP:
3511 gval = TKIP_ENABLED;
3512 break;
3513 case WPA_CIPHER_AES_CCM:
3514 gval = AES_ENABLED;
3515 break;
3516 default:
3517 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003518 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003519 goto exit;
3520 }
3521
3522 offset++;
3523 /* walk thru unicast cipher list and pick up what we recognize */
3524 count = data[offset] + (data[offset + 1] << 8);
3525 offset += WPA_IE_SUITE_COUNT_LEN;
3526 /* Check for unicast suite(s) */
3527 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3528 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003529 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003530 goto exit;
3531 }
3532 for (i = 0; i < count; i++) {
3533 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3534 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003535 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003536 goto exit;
3537 }
3538 offset += TLV_OUI_LEN;
3539 switch (data[offset]) {
3540 case WPA_CIPHER_NONE:
3541 break;
3542 case WPA_CIPHER_WEP_40:
3543 case WPA_CIPHER_WEP_104:
3544 pval |= WEP_ENABLED;
3545 break;
3546 case WPA_CIPHER_TKIP:
3547 pval |= TKIP_ENABLED;
3548 break;
3549 case WPA_CIPHER_AES_CCM:
3550 pval |= AES_ENABLED;
3551 break;
3552 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003553 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003554 }
3555 offset++;
3556 }
3557 /* walk thru auth management suite list and pick up what we recognize */
3558 count = data[offset] + (data[offset + 1] << 8);
3559 offset += WPA_IE_SUITE_COUNT_LEN;
3560 /* Check for auth key management suite(s) */
3561 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3562 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003563 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003564 goto exit;
3565 }
3566 for (i = 0; i < count; i++) {
3567 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3568 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003569 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003570 goto exit;
3571 }
3572 offset += TLV_OUI_LEN;
3573 switch (data[offset]) {
3574 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003575 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003576 wpa_auth |= WPA_AUTH_NONE;
3577 break;
3578 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003579 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003580 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3581 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3582 break;
3583 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01003584 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003585 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3586 (wpa_auth |= WPA_AUTH_PSK);
3587 break;
3588 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003589 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003590 }
3591 offset++;
3592 }
3593
3594 if (is_rsn_ie) {
3595 wme_bss_disable = 1;
3596 if ((offset + RSN_CAP_LEN) <= len) {
3597 rsn_cap = data[offset] + (data[offset + 1] << 8);
3598 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3599 wme_bss_disable = 0;
3600 }
3601 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07003602 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003603 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02003604 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003605 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003606 goto exit;
3607 }
3608 }
3609 /* FOR WPS , set SES_OW_ENABLED */
3610 wsec = (pval | gval | SES_OW_ENABLED);
3611
3612 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003613 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003614 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003615 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003616 goto exit;
3617 }
3618 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003619 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02003620 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003621 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003622 goto exit;
3623 }
3624 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003625 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003626 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003627 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003628 goto exit;
3629 }
3630
3631exit:
3632 return err;
3633}
3634
3635static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08003636brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02003637 struct parsed_vndr_ies *vndr_ies)
3638{
Hante Meuleman1a873342012-09-27 14:17:54 +02003639 struct brcmf_vs_tlv *vndrie;
3640 struct brcmf_tlv *ie;
3641 struct parsed_vndr_ie_info *parsed_info;
3642 s32 remaining_len;
3643
3644 remaining_len = (s32)vndr_ie_len;
3645 memset(vndr_ies, 0, sizeof(*vndr_ies));
3646
3647 ie = (struct brcmf_tlv *)vndr_ie_buf;
3648 while (ie) {
3649 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
3650 goto next;
3651 vndrie = (struct brcmf_vs_tlv *)ie;
3652 /* len should be bigger than OUI length + one */
3653 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003654 brcmf_err("invalid vndr ie. length is too small %d\n",
3655 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003656 goto next;
3657 }
3658 /* if wpa or wme ie, do not add ie */
3659 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
3660 ((vndrie->oui_type == WPA_OUI_TYPE) ||
3661 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003662 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003663 goto next;
3664 }
3665
3666 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
3667
3668 /* save vndr ie information */
3669 parsed_info->ie_ptr = (char *)vndrie;
3670 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
3671 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
3672
3673 vndr_ies->count++;
3674
Arend van Sprield96b8012012-12-05 15:26:02 +01003675 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
3676 parsed_info->vndrie.oui[0],
3677 parsed_info->vndrie.oui[1],
3678 parsed_info->vndrie.oui[2],
3679 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02003680
Arend van Spriel9f440b72013-02-08 15:53:36 +01003681 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02003682 break;
3683next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003684 remaining_len -= (ie->len + TLV_HDR_LEN);
3685 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02003686 ie = NULL;
3687 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003688 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
3689 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02003690 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003691 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02003692}
3693
3694static u32
3695brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
3696{
3697
3698 __le32 iecount_le;
3699 __le32 pktflag_le;
3700
3701 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
3702 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
3703
3704 iecount_le = cpu_to_le32(1);
3705 memcpy(&iebuf[VNDR_IE_COUNT_OFFSET], &iecount_le, sizeof(iecount_le));
3706
3707 pktflag_le = cpu_to_le32(pktflag);
3708 memcpy(&iebuf[VNDR_IE_PKTFLAG_OFFSET], &pktflag_le, sizeof(pktflag_le));
3709
3710 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
3711
3712 return ie_len + VNDR_IE_HDR_SIZE;
3713}
3714
Arend van Spriel1332e262012-11-05 16:22:18 -08003715s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
3716 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02003717{
Arend van Spriel1332e262012-11-05 16:22:18 -08003718 struct brcmf_if *ifp;
3719 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003720 s32 err = 0;
3721 u8 *iovar_ie_buf;
3722 u8 *curr_ie_buf;
3723 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003724 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07003725 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003726 u32 del_add_ie_buf_len = 0;
3727 u32 total_ie_buf_len = 0;
3728 u32 parsed_ie_buf_len = 0;
3729 struct parsed_vndr_ies old_vndr_ies;
3730 struct parsed_vndr_ies new_vndr_ies;
3731 struct parsed_vndr_ie_info *vndrie_info;
3732 s32 i;
3733 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003734 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003735
Arend van Spriel1332e262012-11-05 16:22:18 -08003736 if (!vif)
3737 return -ENODEV;
3738 ifp = vif->ifp;
3739 saved_ie = &vif->saved_ie;
3740
Arend van Sprield96b8012012-12-05 15:26:02 +01003741 brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02003742 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
3743 if (!iovar_ie_buf)
3744 return -ENOMEM;
3745 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01003746 switch (pktflag) {
3747 case BRCMF_VNDR_IE_PRBREQ_FLAG:
3748 mgmt_ie_buf = saved_ie->probe_req_ie;
3749 mgmt_ie_len = &saved_ie->probe_req_ie_len;
3750 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
3751 break;
3752 case BRCMF_VNDR_IE_PRBRSP_FLAG:
3753 mgmt_ie_buf = saved_ie->probe_res_ie;
3754 mgmt_ie_len = &saved_ie->probe_res_ie_len;
3755 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
3756 break;
3757 case BRCMF_VNDR_IE_BEACON_FLAG:
3758 mgmt_ie_buf = saved_ie->beacon_ie;
3759 mgmt_ie_len = &saved_ie->beacon_ie_len;
3760 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
3761 break;
3762 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
3763 mgmt_ie_buf = saved_ie->assoc_req_ie;
3764 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
3765 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
3766 break;
3767 default:
3768 err = -EPERM;
3769 brcmf_err("not suitable type\n");
3770 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003771 }
3772
3773 if (vndr_ie_len > mgmt_ie_buf_len) {
3774 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003775 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003776 goto exit;
3777 }
3778
3779 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3780 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
3781 ptr = curr_ie_buf;
3782 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
3783 for (i = 0; i < new_vndr_ies.count; i++) {
3784 vndrie_info = &new_vndr_ies.ie_info[i];
3785 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
3786 vndrie_info->ie_len);
3787 parsed_ie_buf_len += vndrie_info->ie_len;
3788 }
3789 }
3790
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003791 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02003792 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
3793 (memcmp(mgmt_ie_buf, curr_ie_buf,
3794 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003795 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003796 goto exit;
3797 }
3798
3799 /* parse old vndr_ie */
3800 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
3801
3802 /* make a command to delete old ie */
3803 for (i = 0; i < old_vndr_ies.count; i++) {
3804 vndrie_info = &old_vndr_ies.ie_info[i];
3805
Arend van Sprield96b8012012-12-05 15:26:02 +01003806 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3807 vndrie_info->vndrie.id,
3808 vndrie_info->vndrie.len,
3809 vndrie_info->vndrie.oui[0],
3810 vndrie_info->vndrie.oui[1],
3811 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003812
3813 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3814 vndrie_info->ie_ptr,
3815 vndrie_info->ie_len,
3816 "del");
3817 curr_ie_buf += del_add_ie_buf_len;
3818 total_ie_buf_len += del_add_ie_buf_len;
3819 }
3820 }
3821
3822 *mgmt_ie_len = 0;
3823 /* Add if there is any extra IE */
3824 if (mgmt_ie_buf && parsed_ie_buf_len) {
3825 ptr = mgmt_ie_buf;
3826
3827 remained_buf_len = mgmt_ie_buf_len;
3828
3829 /* make a command to add new ie */
3830 for (i = 0; i < new_vndr_ies.count; i++) {
3831 vndrie_info = &new_vndr_ies.ie_info[i];
3832
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003833 /* verify remained buf size before copy data */
3834 if (remained_buf_len < (vndrie_info->vndrie.len +
3835 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003836 brcmf_err("no space in mgmt_ie_buf: len left %d",
3837 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003838 break;
3839 }
3840 remained_buf_len -= (vndrie_info->ie_len +
3841 VNDR_IE_VSIE_OFFSET);
3842
Arend van Sprield96b8012012-12-05 15:26:02 +01003843 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3844 vndrie_info->vndrie.id,
3845 vndrie_info->vndrie.len,
3846 vndrie_info->vndrie.oui[0],
3847 vndrie_info->vndrie.oui[1],
3848 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003849
3850 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3851 vndrie_info->ie_ptr,
3852 vndrie_info->ie_len,
3853 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02003854
3855 /* save the parsed IE in wl struct */
3856 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
3857 vndrie_info->ie_len);
3858 *mgmt_ie_len += vndrie_info->ie_len;
3859
3860 curr_ie_buf += del_add_ie_buf_len;
3861 total_ie_buf_len += del_add_ie_buf_len;
3862 }
3863 }
3864 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003865 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003866 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003867 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003868 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003869 }
3870
3871exit:
3872 kfree(iovar_ie_buf);
3873 return err;
3874}
3875
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01003876s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
3877{
3878 s32 pktflags[] = {
3879 BRCMF_VNDR_IE_PRBREQ_FLAG,
3880 BRCMF_VNDR_IE_PRBRSP_FLAG,
3881 BRCMF_VNDR_IE_BEACON_FLAG
3882 };
3883 int i;
3884
3885 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
3886 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
3887
3888 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
3889 return 0;
3890}
3891
Hante Meuleman1a873342012-09-27 14:17:54 +02003892static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01003893brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
3894 struct cfg80211_beacon_data *beacon)
3895{
3896 s32 err;
3897
3898 /* Set Beacon IEs to FW */
3899 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
3900 beacon->tail, beacon->tail_len);
3901 if (err) {
3902 brcmf_err("Set Beacon IE Failed\n");
3903 return err;
3904 }
3905 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
3906
3907 /* Set Probe Response IEs to FW */
3908 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
3909 beacon->proberesp_ies,
3910 beacon->proberesp_ies_len);
3911 if (err)
3912 brcmf_err("Set Probe Resp IE Failed\n");
3913 else
3914 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
3915
3916 return err;
3917}
3918
3919static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02003920brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
3921 struct cfg80211_ap_settings *settings)
3922{
3923 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02003924 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07003925 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01003926 const struct brcmf_tlv *ssid_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003927 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02003928 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01003929 const struct brcmf_tlv *rsn_ie;
3930 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003931 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01003932 enum nl80211_iftype dev_role;
3933 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02003934 u16 chanspec;
Hante Meulemana44aa402014-12-03 21:05:33 +01003935 bool mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02003936
Arend van Spriel06c01582014-05-12 10:47:37 +02003937 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3938 settings->chandef.chan->hw_value,
3939 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02003940 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01003941 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3942 settings->ssid, settings->ssid_len, settings->auth_type,
3943 settings->inactivity_timeout);
Hante Meuleman1a873342012-09-27 14:17:54 +02003944
Hante Meuleman426d0a52013-02-08 15:53:53 +01003945 dev_role = ifp->vif->wdev.iftype;
Hante Meulemana44aa402014-12-03 21:05:33 +01003946 mbss = ifp->vif->mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02003947
3948 memset(&ssid_le, 0, sizeof(ssid_le));
3949 if (settings->ssid == NULL || settings->ssid_len == 0) {
3950 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
3951 ssid_ie = brcmf_parse_tlvs(
3952 (u8 *)&settings->beacon.head[ie_offset],
3953 settings->beacon.head_len - ie_offset,
3954 WLAN_EID_SSID);
3955 if (!ssid_ie)
3956 return -EINVAL;
3957
3958 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
3959 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01003960 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02003961 } else {
3962 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
3963 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
3964 }
3965
Hante Meulemana44aa402014-12-03 21:05:33 +01003966 if (!mbss) {
3967 brcmf_set_mpc(ifp, 0);
3968 brcmf_configure_arp_offload(ifp, false);
3969 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003970
3971 /* find the RSN_IE */
3972 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
3973 settings->beacon.tail_len, WLAN_EID_RSN);
3974
3975 /* find the WPA_IE */
3976 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
3977 settings->beacon.tail_len);
3978
Hante Meuleman1a873342012-09-27 14:17:54 +02003979 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003980 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003981 if (wpa_ie != NULL) {
3982 /* WPA IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01003983 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02003984 if (err < 0)
3985 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003986 } else {
Hante Meulemana44aa402014-12-03 21:05:33 +01003987 struct brcmf_vs_tlv *tmp_ie;
3988
3989 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
3990
Hante Meuleman1a873342012-09-27 14:17:54 +02003991 /* RSN IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01003992 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02003993 if (err < 0)
3994 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003995 }
Hante Meuleman1a873342012-09-27 14:17:54 +02003996 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01003997 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01003998 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02003999 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004000
Hante Meulemana0f07952013-02-08 15:53:47 +01004001 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02004002
Hante Meulemana44aa402014-12-03 21:05:33 +01004003 if (!mbss) {
4004 chanspec = chandef_to_chanspec(&cfg->d11inf,
4005 &settings->chandef);
4006 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004007 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004008 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4009 chanspec, err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004010 goto exit;
4011 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004012
4013 if (settings->beacon_interval) {
4014 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
4015 settings->beacon_interval);
4016 if (err < 0) {
4017 brcmf_err("Beacon Interval Set Error, %d\n",
4018 err);
4019 goto exit;
4020 }
4021 }
4022 if (settings->dtim_period) {
4023 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
4024 settings->dtim_period);
4025 if (err < 0) {
4026 brcmf_err("DTIM Interval Set Error, %d\n", err);
4027 goto exit;
4028 }
4029 }
4030
4031 if (dev_role == NL80211_IFTYPE_AP) {
4032 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4033 if (err < 0) {
4034 brcmf_err("BRCMF_C_DOWN error %d\n", err);
4035 goto exit;
4036 }
4037 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
4038 }
4039
4040 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02004041 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004042 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004043 goto exit;
4044 }
4045 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004046 if (dev_role == NL80211_IFTYPE_AP) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004047 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
4048 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
4049
Hante Meulemana0f07952013-02-08 15:53:47 +01004050 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
4051 if (err < 0) {
4052 brcmf_err("setting AP mode failed %d\n", err);
4053 goto exit;
4054 }
4055 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4056 if (err < 0) {
4057 brcmf_err("BRCMF_C_UP error (%d)\n", err);
4058 goto exit;
4059 }
4060
4061 memset(&join_params, 0, sizeof(join_params));
4062 /* join parameters starts with ssid */
4063 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
4064 /* create softap */
4065 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4066 &join_params, sizeof(join_params));
4067 if (err < 0) {
4068 brcmf_err("SET SSID error (%d)\n", err);
4069 goto exit;
4070 }
4071 brcmf_dbg(TRACE, "AP mode configuration complete\n");
4072 } else {
4073 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
4074 sizeof(ssid_le));
4075 if (err < 0) {
4076 brcmf_err("setting ssid failed %d\n", err);
4077 goto exit;
4078 }
4079 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
4080 bss_enable.enable = cpu_to_le32(1);
4081 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4082 sizeof(bss_enable));
4083 if (err < 0) {
4084 brcmf_err("bss_enable config failed %d\n", err);
4085 goto exit;
4086 }
4087
4088 brcmf_dbg(TRACE, "GO mode configuration complete\n");
4089 }
Arend van Sprielc1179032012-10-22 13:55:33 -07004090 clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
4091 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman1a873342012-09-27 14:17:54 +02004092
4093exit:
Hante Meulemana44aa402014-12-03 21:05:33 +01004094 if ((err) && (!mbss)) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02004095 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004096 brcmf_configure_arp_offload(ifp, true);
4097 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004098 return err;
4099}
4100
4101static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
4102{
Arend van Sprielc1179032012-10-22 13:55:33 -07004103 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004104 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01004105 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02004106 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02004107
Arend van Sprield96b8012012-12-05 15:26:02 +01004108 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004109
Hante Meuleman426d0a52013-02-08 15:53:53 +01004110 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004111 /* Due to most likely deauths outstanding we sleep */
4112 /* first to make sure they get processed by fw. */
4113 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004114
Hante Meulemana44aa402014-12-03 21:05:33 +01004115 if (ifp->vif->mbss) {
4116 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4117 return err;
4118 }
4119
Hante Meuleman5c33a942013-04-02 21:06:18 +02004120 memset(&join_params, 0, sizeof(join_params));
4121 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4122 &join_params, sizeof(join_params));
4123 if (err < 0)
4124 brcmf_err("SET SSID error (%d)\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004125 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004126 if (err < 0)
Hante Meulemana44aa402014-12-03 21:05:33 +01004127 brcmf_err("BRCMF_C_DOWN error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004128 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4129 if (err < 0)
4130 brcmf_err("setting AP mode failed %d\n", err);
4131 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4132 if (err < 0)
4133 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004134 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
4135 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
4136 /* Bring device back up so it can be used again */
4137 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4138 if (err < 0)
4139 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004140 } else {
4141 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
4142 bss_enable.enable = cpu_to_le32(0);
4143 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4144 sizeof(bss_enable));
4145 if (err < 0)
4146 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004147 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02004148 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004149 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004150 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
4151 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
4152
Hante Meuleman1a873342012-09-27 14:17:54 +02004153 return err;
4154}
4155
Hante Meulemana0f07952013-02-08 15:53:47 +01004156static s32
4157brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4158 struct cfg80211_beacon_data *info)
4159{
Hante Meulemana0f07952013-02-08 15:53:47 +01004160 struct brcmf_if *ifp = netdev_priv(ndev);
4161 s32 err;
4162
4163 brcmf_dbg(TRACE, "Enter\n");
4164
Hante Meulemana0f07952013-02-08 15:53:47 +01004165 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4166
4167 return err;
4168}
4169
Hante Meuleman1a873342012-09-27 14:17:54 +02004170static int
4171brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03004172 struct station_del_parameters *params)
Hante Meuleman1a873342012-09-27 14:17:54 +02004173{
Hante Meulemana0f07952013-02-08 15:53:47 +01004174 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02004175 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004176 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02004177 s32 err;
4178
Jouni Malinen89c771e2014-10-10 20:52:40 +03004179 if (!params->mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02004180 return -EFAULT;
4181
Jouni Malinen89c771e2014-10-10 20:52:40 +03004182 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02004183
Hante Meulemana0f07952013-02-08 15:53:47 +01004184 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4185 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07004186 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02004187 return -EIO;
4188
Jouni Malinen89c771e2014-10-10 20:52:40 +03004189 memcpy(&scbval.ea, params->mac, ETH_ALEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02004190 scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004191 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004192 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02004193 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004194 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01004195
Arend van Sprield96b8012012-12-05 15:26:02 +01004196 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004197 return err;
4198}
4199
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004200
4201static void
4202brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4203 struct wireless_dev *wdev,
4204 u16 frame_type, bool reg)
4205{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004206 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004207 u16 mgmt_type;
4208
4209 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4210
4211 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004212 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004213 if (reg)
4214 vif->mgmt_rx_reg |= BIT(mgmt_type);
4215 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01004216 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004217}
4218
4219
4220static int
4221brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004222 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004223{
4224 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004225 struct ieee80211_channel *chan = params->chan;
4226 const u8 *buf = params->buf;
4227 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004228 const struct ieee80211_mgmt *mgmt;
4229 struct brcmf_cfg80211_vif *vif;
4230 s32 err = 0;
4231 s32 ie_offset;
4232 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004233 struct brcmf_fil_action_frame_le *action_frame;
4234 struct brcmf_fil_af_params_le *af_params;
4235 bool ack;
4236 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004237 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004238
4239 brcmf_dbg(TRACE, "Enter\n");
4240
4241 *cookie = 0;
4242
4243 mgmt = (const struct ieee80211_mgmt *)buf;
4244
Hante Meulemana0f07952013-02-08 15:53:47 +01004245 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4246 brcmf_err("Driver only allows MGMT packet type\n");
4247 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004248 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004249
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004250 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4251
Hante Meulemana0f07952013-02-08 15:53:47 +01004252 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4253 /* Right now the only reason to get a probe response */
4254 /* is for p2p listen response or for p2p GO from */
4255 /* wpa_supplicant. Unfortunately the probe is send */
4256 /* on primary ndev, while dongle wants it on the p2p */
4257 /* vif. Since this is only reason for a probe */
4258 /* response to be sent, the vif is taken from cfg. */
4259 /* If ever desired to send proberesp for non p2p */
4260 /* response then data should be checked for */
4261 /* "DIRECT-". Note in future supplicant will take */
4262 /* dedicated p2p wdev to do this and then this 'hack'*/
4263 /* is not needed anymore. */
4264 ie_offset = DOT11_MGMT_HDR_LEN +
4265 DOT11_BCN_PRB_FIXED_LEN;
4266 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004267 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4268 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4269 err = brcmf_vif_set_mgmt_ie(vif,
4270 BRCMF_VNDR_IE_PRBRSP_FLAG,
4271 &buf[ie_offset],
4272 ie_len);
4273 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4274 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004275 } else if (ieee80211_is_action(mgmt->frame_control)) {
4276 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4277 if (af_params == NULL) {
4278 brcmf_err("unable to allocate frame\n");
4279 err = -ENOMEM;
4280 goto exit;
4281 }
4282 action_frame = &af_params->action_frame;
4283 /* Add the packet Id */
4284 action_frame->packet_id = cpu_to_le32(*cookie);
4285 /* Add BSSID */
4286 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4287 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4288 /* Add the length exepted for 802.11 header */
4289 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004290 /* Add the channel. Use the one specified as parameter if any or
4291 * the current one (got from the firmware) otherwise
4292 */
4293 if (chan)
4294 freq = chan->center_freq;
4295 else
4296 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4297 &freq);
4298 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004299 af_params->channel = cpu_to_le32(chan_nr);
4300
4301 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4302 le16_to_cpu(action_frame->len));
4303
4304 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004305 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004306
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004307 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004308 af_params);
4309
4310 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4311 GFP_KERNEL);
4312 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004313 } else {
4314 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4315 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4316 }
4317
Hante Meuleman18e2f612013-02-08 15:53:49 +01004318exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004319 return err;
4320}
4321
4322
4323static int
4324brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4325 struct wireless_dev *wdev,
4326 u64 cookie)
4327{
4328 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4329 struct brcmf_cfg80211_vif *vif;
4330 int err = 0;
4331
4332 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4333
4334 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4335 if (vif == NULL) {
4336 brcmf_err("No p2p device available for probe response\n");
4337 err = -ENODEV;
4338 goto exit;
4339 }
4340 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4341exit:
4342 return err;
4343}
4344
Piotr Haber61730d42013-04-23 12:53:12 +02004345static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4346 struct wireless_dev *wdev,
4347 enum nl80211_crit_proto_id proto,
4348 u16 duration)
4349{
4350 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4351 struct brcmf_cfg80211_vif *vif;
4352
4353 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4354
4355 /* only DHCP support for now */
4356 if (proto != NL80211_CRIT_PROTO_DHCP)
4357 return -EINVAL;
4358
4359 /* suppress and abort scanning */
4360 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4361 brcmf_abort_scanning(cfg);
4362
4363 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4364}
4365
4366static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4367 struct wireless_dev *wdev)
4368{
4369 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4370 struct brcmf_cfg80211_vif *vif;
4371
4372 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4373
4374 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4375 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4376}
4377
Hante Meuleman70b7d942014-07-30 13:20:07 +02004378static s32
4379brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4380 const struct brcmf_event_msg *e, void *data)
4381{
4382 switch (e->reason) {
4383 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4384 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4385 break;
4386 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4387 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4388 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4389 break;
4390 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4391 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4392 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4393 break;
4394 }
4395
4396 return 0;
4397}
4398
Arend van Spriel89c2f382013-08-10 12:27:25 +02004399static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4400{
4401 int ret;
4402
4403 switch (oper) {
4404 case NL80211_TDLS_DISCOVERY_REQ:
4405 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4406 break;
4407 case NL80211_TDLS_SETUP:
4408 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4409 break;
4410 case NL80211_TDLS_TEARDOWN:
4411 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4412 break;
4413 default:
4414 brcmf_err("unsupported operation: %d\n", oper);
4415 ret = -EOPNOTSUPP;
4416 }
4417 return ret;
4418}
4419
4420static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004421 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004422 enum nl80211_tdls_operation oper)
4423{
4424 struct brcmf_if *ifp;
4425 struct brcmf_tdls_iovar_le info;
4426 int ret = 0;
4427
4428 ret = brcmf_convert_nl80211_tdls_oper(oper);
4429 if (ret < 0)
4430 return ret;
4431
4432 ifp = netdev_priv(ndev);
4433 memset(&info, 0, sizeof(info));
4434 info.mode = (u8)ret;
4435 if (peer)
4436 memcpy(info.ea, peer, ETH_ALEN);
4437
4438 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4439 &info, sizeof(info));
4440 if (ret < 0)
4441 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4442
4443 return ret;
4444}
4445
Arend van Spriel5b435de2011-10-05 13:19:03 +02004446static struct cfg80211_ops wl_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01004447 .add_virtual_intf = brcmf_cfg80211_add_iface,
4448 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004449 .change_virtual_intf = brcmf_cfg80211_change_iface,
4450 .scan = brcmf_cfg80211_scan,
4451 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4452 .join_ibss = brcmf_cfg80211_join_ibss,
4453 .leave_ibss = brcmf_cfg80211_leave_ibss,
4454 .get_station = brcmf_cfg80211_get_station,
4455 .set_tx_power = brcmf_cfg80211_set_tx_power,
4456 .get_tx_power = brcmf_cfg80211_get_tx_power,
4457 .add_key = brcmf_cfg80211_add_key,
4458 .del_key = brcmf_cfg80211_del_key,
4459 .get_key = brcmf_cfg80211_get_key,
4460 .set_default_key = brcmf_cfg80211_config_default_key,
4461 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4462 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004463 .connect = brcmf_cfg80211_connect,
4464 .disconnect = brcmf_cfg80211_disconnect,
4465 .suspend = brcmf_cfg80211_suspend,
4466 .resume = brcmf_cfg80211_resume,
4467 .set_pmksa = brcmf_cfg80211_set_pmksa,
4468 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02004469 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02004470 .start_ap = brcmf_cfg80211_start_ap,
4471 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01004472 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02004473 .del_station = brcmf_cfg80211_del_station,
Arend van Spriele5806072012-09-19 22:21:08 +02004474 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4475 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004476 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4477 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4478 .remain_on_channel = brcmf_p2p_remain_on_channel,
4479 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02004480 .start_p2p_device = brcmf_p2p_start_device,
4481 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02004482 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4483 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004484 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004485};
4486
Arend van Spriel3eacf862012-10-22 13:55:30 -07004487struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01004488 enum nl80211_iftype type,
4489 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004490{
Hante Meulemana44aa402014-12-03 21:05:33 +01004491 struct brcmf_cfg80211_vif *vif_walk;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004492 struct brcmf_cfg80211_vif *vif;
Hante Meulemana44aa402014-12-03 21:05:33 +01004493 bool mbss;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004494
Arend van Spriel33a6b152013-02-08 15:53:39 +01004495 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01004496 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07004497 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4498 if (!vif)
4499 return ERR_PTR(-ENOMEM);
4500
4501 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01004502 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004503
Arend van Spriel3eacf862012-10-22 13:55:30 -07004504 vif->pm_block = pm_block;
4505 vif->roam_off = -1;
4506
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004507 brcmf_init_prof(&vif->profile);
4508
Hante Meulemana44aa402014-12-03 21:05:33 +01004509 if (type == NL80211_IFTYPE_AP) {
4510 mbss = false;
4511 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
4512 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
4513 mbss = true;
4514 break;
4515 }
4516 }
4517 vif->mbss = mbss;
4518 }
4519
Arend van Spriel3eacf862012-10-22 13:55:30 -07004520 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004521 return vif;
4522}
4523
Arend van Spriel427dec52014-01-06 12:40:47 +01004524void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07004525{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004526 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004527 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004528}
4529
Arend van Spriel9df4d542014-01-06 12:40:49 +01004530void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4531{
4532 struct brcmf_cfg80211_vif *vif;
4533 struct brcmf_if *ifp;
4534
4535 ifp = netdev_priv(ndev);
4536 vif = ifp->vif;
4537
4538 brcmf_free_vif(vif);
4539 free_netdev(ndev);
4540}
4541
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004542static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004543{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004544 u32 event = e->event_code;
4545 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004546
4547 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004548 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004549 return true;
4550 }
4551
4552 return false;
4553}
4554
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004555static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004556{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004557 u32 event = e->event_code;
4558 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004559
Hante Meuleman68ca3952014-02-25 20:30:26 +01004560 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4561 (event == BRCMF_E_DISASSOC_IND) ||
4562 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01004563 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004564 return true;
4565 }
4566 return false;
4567}
4568
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004569static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004570 const struct brcmf_event_msg *e)
4571{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004572 u32 event = e->event_code;
4573 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004574
4575 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004576 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
4577 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004578 return true;
4579 }
4580
4581 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004582 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004583 return true;
4584 }
4585
4586 return false;
4587}
4588
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004589static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004590{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004591 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004592
4593 kfree(conn_info->req_ie);
4594 conn_info->req_ie = NULL;
4595 conn_info->req_ie_len = 0;
4596 kfree(conn_info->resp_ie);
4597 conn_info->resp_ie = NULL;
4598 conn_info->resp_ie_len = 0;
4599}
4600
Hante Meuleman89286dc2013-02-08 15:53:46 +01004601static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
4602 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004603{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004604 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004605 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004606 u32 req_len;
4607 u32 resp_len;
4608 s32 err = 0;
4609
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004610 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004611
Arend van Sprielac24be62012-10-22 10:36:23 -07004612 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
4613 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004614 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004615 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004616 return err;
4617 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004618 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004619 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004620 req_len = le32_to_cpu(assoc_info->req_len);
4621 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004622 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004623 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004624 cfg->extra_buf,
4625 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004626 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004627 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004628 return err;
4629 }
4630 conn_info->req_ie_len = req_len;
4631 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004632 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004633 GFP_KERNEL);
4634 } else {
4635 conn_info->req_ie_len = 0;
4636 conn_info->req_ie = NULL;
4637 }
4638 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004639 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004640 cfg->extra_buf,
4641 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004642 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004643 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004644 return err;
4645 }
4646 conn_info->resp_ie_len = resp_len;
4647 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004648 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004649 GFP_KERNEL);
4650 } else {
4651 conn_info->resp_ie_len = 0;
4652 conn_info->resp_ie = NULL;
4653 }
Arend van Spriel16886732012-12-05 15:26:04 +01004654 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
4655 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004656
4657 return err;
4658}
4659
4660static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004661brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004662 struct net_device *ndev,
4663 const struct brcmf_event_msg *e)
4664{
Arend van Sprielc1179032012-10-22 13:55:33 -07004665 struct brcmf_if *ifp = netdev_priv(ndev);
4666 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004667 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4668 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07004669 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004670 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07004671 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02004672 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004673 u32 freq;
4674 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07004675 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004676
Arend van Sprield96b8012012-12-05 15:26:02 +01004677 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004678
Hante Meuleman89286dc2013-02-08 15:53:46 +01004679 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004680 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004681 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004682
Franky Lina180b832012-10-10 11:13:09 -07004683 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
4684 if (buf == NULL) {
4685 err = -ENOMEM;
4686 goto done;
4687 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02004688
Franky Lina180b832012-10-10 11:13:09 -07004689 /* data sent to dongle has to be little endian */
4690 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07004691 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07004692 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07004693
4694 if (err)
4695 goto done;
4696
4697 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02004698 ch.chspec = le16_to_cpu(bi->chanspec);
4699 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004700
Franky Lin83cf17a2013-04-11 13:28:50 +02004701 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004702 band = wiphy->bands[IEEE80211_BAND_2GHZ];
4703 else
4704 band = wiphy->bands[IEEE80211_BAND_5GHZ];
4705
Franky Lin83cf17a2013-04-11 13:28:50 +02004706 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004707 notify_channel = ieee80211_get_channel(wiphy, freq);
4708
Franky Lina180b832012-10-10 11:13:09 -07004709done:
4710 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02004711 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004712 conn_info->req_ie, conn_info->req_ie_len,
4713 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004714 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004715
Arend van Sprielc1179032012-10-22 13:55:33 -07004716 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01004717 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004718 return err;
4719}
4720
4721static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004722brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004723 struct net_device *ndev, const struct brcmf_event_msg *e,
4724 bool completed)
4725{
Arend van Sprielc1179032012-10-22 13:55:33 -07004726 struct brcmf_if *ifp = netdev_priv(ndev);
4727 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004728 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004729
Arend van Sprield96b8012012-12-05 15:26:02 +01004730 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004731
Arend van Sprielc1179032012-10-22 13:55:33 -07004732 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4733 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02004734 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01004735 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004736 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004737 brcmf_update_bss_info(cfg, ifp);
4738 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4739 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004740 }
4741 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02004742 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004743 conn_info->req_ie,
4744 conn_info->req_ie_len,
4745 conn_info->resp_ie,
4746 conn_info->resp_ie_len,
4747 completed ? WLAN_STATUS_SUCCESS :
4748 WLAN_STATUS_AUTH_TIMEOUT,
4749 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004750 brcmf_dbg(CONN, "Report connect result - connection %s\n",
4751 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004752 }
Arend van Sprield96b8012012-12-05 15:26:02 +01004753 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004754 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004755}
4756
4757static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004758brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02004759 struct net_device *ndev,
4760 const struct brcmf_event_msg *e, void *data)
4761{
Hante Meulemana44aa402014-12-03 21:05:33 +01004762 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman7ee29602013-02-06 18:40:43 +01004763 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004764 u32 event = e->event_code;
4765 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02004766 struct station_info sinfo;
4767
Arend van Spriel16886732012-12-05 15:26:04 +01004768 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004769 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
4770 ndev != cfg_to_ndev(cfg)) {
4771 brcmf_dbg(CONN, "AP mode link down\n");
4772 complete(&cfg->vif_disabled);
Hante Meulemana44aa402014-12-03 21:05:33 +01004773 if (ifp->vif->mbss)
4774 brcmf_remove_interface(ifp->drvr, ifp->bssidx);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004775 return 0;
4776 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004777
Hante Meuleman1a873342012-09-27 14:17:54 +02004778 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01004779 (reason == BRCMF_E_STATUS_SUCCESS)) {
4780 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02004781 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004782 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02004783 return -EINVAL;
4784 }
4785 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01004786 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02004787 generation++;
4788 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01004789 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02004790 } else if ((event == BRCMF_E_DISASSOC_IND) ||
4791 (event == BRCMF_E_DEAUTH_IND) ||
4792 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01004793 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02004794 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01004795 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004796}
4797
4798static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004799brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004800 const struct brcmf_event_msg *e, void *data)
4801{
Arend van Spriel19937322012-11-05 16:22:32 -08004802 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4803 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07004804 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004805 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004806 s32 err = 0;
4807
Hante Meuleman8851cce2014-07-30 13:20:02 +02004808 if ((e->event_code == BRCMF_E_DEAUTH) ||
4809 (e->event_code == BRCMF_E_DEAUTH_IND) ||
4810 (e->event_code == BRCMF_E_DISASSOC_IND) ||
4811 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
4812 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4813 }
4814
Arend van Spriel967fe2c2014-03-15 17:18:21 +01004815 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004816 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004817 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01004818 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004819 if (brcmf_is_ibssmode(ifp->vif)) {
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004820 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004821 memcpy(profile->bssid, e->addr, ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004822 wl_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01004823 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07004824 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4825 &ifp->vif->sme_state);
4826 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4827 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004828 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004829 brcmf_bss_connect_done(cfg, ndev, e, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004830 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01004831 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004832 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004833 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004834 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004835 brcmf_link_down(ifp->vif);
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004836 brcmf_init_prof(ndev_to_prof(ndev));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004837 if (ndev != cfg_to_ndev(cfg))
4838 complete(&cfg->vif_disabled);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004839 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01004840 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07004841 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4842 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004843 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004844 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004845 }
4846
4847 return err;
4848}
4849
4850static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004851brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004852 const struct brcmf_event_msg *e, void *data)
4853{
Arend van Spriel19937322012-11-05 16:22:32 -08004854 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08004855 u32 event = e->event_code;
4856 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004857
4858 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004859 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08004860 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004861 else
Arend van Spriel19937322012-11-05 16:22:32 -08004862 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004863 }
4864
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004865 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004866}
4867
4868static s32
Arend van Spriel19937322012-11-05 16:22:32 -08004869brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004870 const struct brcmf_event_msg *e, void *data)
4871{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004872 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004873 enum nl80211_key_type key_type;
4874
4875 if (flags & BRCMF_EVENT_MSG_GROUP)
4876 key_type = NL80211_KEYTYPE_GROUP;
4877 else
4878 key_type = NL80211_KEYTYPE_PAIRWISE;
4879
Arend van Spriel19937322012-11-05 16:22:32 -08004880 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004881 NULL, GFP_KERNEL);
4882
4883 return 0;
4884}
4885
Arend van Sprield3c0b632013-02-08 15:53:37 +01004886static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
4887 const struct brcmf_event_msg *e, void *data)
4888{
4889 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4890 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
4891 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
4892 struct brcmf_cfg80211_vif *vif;
4893
4894 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4895 ifevent->action, ifevent->flags, ifevent->ifidx,
4896 ifevent->bssidx);
4897
Arend van Sprield3c0b632013-02-08 15:53:37 +01004898 mutex_lock(&event->vif_event_lock);
4899 event->action = ifevent->action;
4900 vif = event->vif;
4901
4902 switch (ifevent->action) {
4903 case BRCMF_E_IF_ADD:
4904 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08004905 if (!cfg->vif_event.vif) {
4906 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004907 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08004908 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01004909
4910 ifp->vif = vif;
4911 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02004912 if (ifp->ndev) {
4913 vif->wdev.netdev = ifp->ndev;
4914 ifp->ndev->ieee80211_ptr = &vif->wdev;
4915 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
4916 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01004917 mutex_unlock(&event->vif_event_lock);
4918 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01004919 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01004920
4921 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01004922 mutex_unlock(&event->vif_event_lock);
4923 /* event may not be upon user request */
4924 if (brcmf_cfg80211_vif_event_armed(cfg))
4925 wake_up(&event->vif_wq);
4926 return 0;
4927
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01004928 case BRCMF_E_IF_CHANGE:
4929 mutex_unlock(&event->vif_event_lock);
4930 wake_up(&event->vif_wq);
4931 return 0;
4932
Arend van Sprield3c0b632013-02-08 15:53:37 +01004933 default:
4934 mutex_unlock(&event->vif_event_lock);
4935 break;
4936 }
4937 return -EINVAL;
4938}
4939
Arend van Spriel5b435de2011-10-05 13:19:03 +02004940static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
4941{
Arend van Spriel5b435de2011-10-05 13:19:03 +02004942 conf->frag_threshold = (u32)-1;
4943 conf->rts_threshold = (u32)-1;
4944 conf->retry_short = (u32)-1;
4945 conf->retry_long = (u32)-1;
4946 conf->tx_power = -1;
4947}
4948
Arend van Spriel5c36b992012-11-14 18:46:05 -08004949static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004950{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004951 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
4952 brcmf_notify_connect_status);
4953 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
4954 brcmf_notify_connect_status);
4955 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
4956 brcmf_notify_connect_status);
4957 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
4958 brcmf_notify_connect_status);
4959 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
4960 brcmf_notify_connect_status);
4961 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
4962 brcmf_notify_connect_status);
4963 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
4964 brcmf_notify_roaming_status);
4965 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
4966 brcmf_notify_mic_status);
4967 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
4968 brcmf_notify_connect_status);
4969 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
4970 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01004971 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
4972 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004973 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01004974 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004975 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
4976 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01004977 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
4978 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004979 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
4980 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01004981 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
4982 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004983}
4984
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004985static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004986{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004987 kfree(cfg->conf);
4988 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004989 kfree(cfg->escan_ioctl_buf);
4990 cfg->escan_ioctl_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004991 kfree(cfg->extra_buf);
4992 cfg->extra_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004993 kfree(cfg->pmk_list);
4994 cfg->pmk_list = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004995}
4996
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004997static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004998{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004999 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
5000 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005001 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005002 cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5003 if (!cfg->escan_ioctl_buf)
Hante Meulemane756af52012-09-11 21:18:52 +02005004 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005005 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
5006 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005007 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005008 cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL);
5009 if (!cfg->pmk_list)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005010 goto init_priv_mem_out;
5011
5012 return 0;
5013
5014init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005015 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005016
5017 return -ENOMEM;
5018}
5019
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005020static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005021{
5022 s32 err = 0;
5023
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005024 cfg->scan_request = NULL;
5025 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01005026 cfg->active_scan = true; /* we do active scan per default */
5027 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005028 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005029 if (err)
5030 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005031 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005032 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005033 brcmf_init_escan(cfg);
5034 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005035 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005036 return err;
5037}
5038
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005039static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005040{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005041 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005042 brcmf_abort_scanning(cfg);
5043 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005044}
5045
Arend van Sprield3c0b632013-02-08 15:53:37 +01005046static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
5047{
5048 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005049 mutex_init(&event->vif_event_lock);
5050}
5051
Arend van Spriel5b435de2011-10-05 13:19:03 +02005052static s32
Hante Meuleman68ca3952014-02-25 20:30:26 +01005053brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005054{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005055 s32 err = 0;
Arend van Sprielf588bc02011-10-12 20:51:22 +02005056 __le32 roamtrigger[2];
5057 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005058
5059 /*
5060 * Setup timeout if Beacons are lost and roam is
5061 * off to report link down
5062 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005063 if (brcmf_roamoff) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005064 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005065 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005066 brcmf_err("bcn_timeout error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005067 goto dongle_rom_out;
5068 }
5069 }
5070
5071 /*
5072 * Enable/Disable built-in roaming to allow supplicant
5073 * to take care of roaming
5074 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005075 brcmf_dbg(INFO, "Internal Roaming = %s\n",
5076 brcmf_roamoff ? "Off" : "On");
5077 err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005078 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005079 brcmf_err("roam_off error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005080 goto dongle_rom_out;
5081 }
5082
Arend van Sprielf588bc02011-10-12 20:51:22 +02005083 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
5084 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005085 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005086 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005087 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005088 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005089 goto dongle_rom_out;
5090 }
5091
Arend van Sprielf588bc02011-10-12 20:51:22 +02005092 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
5093 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005094 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005095 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005096 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005097 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005098 goto dongle_rom_out;
5099 }
5100
5101dongle_rom_out:
5102 return err;
5103}
5104
5105static s32
Hante Meuleman40a23292013-01-02 15:22:51 +01005106brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time,
Arend van Sprielc68cdc02011-10-12 20:51:23 +02005107 s32 scan_unassoc_time, s32 scan_passive_time)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005108{
5109 s32 err = 0;
5110
Arend van Sprielac24be62012-10-22 10:36:23 -07005111 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005112 scan_assoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005113 if (err) {
5114 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005115 brcmf_dbg(INFO, "Scan assoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005116 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005117 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005118 goto dongle_scantime_out;
5119 }
Arend van Sprielac24be62012-10-22 10:36:23 -07005120 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005121 scan_unassoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005122 if (err) {
5123 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005124 brcmf_dbg(INFO, "Scan unassoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005125 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005126 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005127 goto dongle_scantime_out;
5128 }
5129
Arend van Sprielac24be62012-10-22 10:36:23 -07005130 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005131 scan_passive_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005132 if (err) {
5133 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005134 brcmf_dbg(INFO, "Scan passive time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005135 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005136 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005137 goto dongle_scantime_out;
5138 }
5139
5140dongle_scantime_out:
5141 return err;
5142}
5143
Arend van Sprielb48d8912014-07-12 08:49:41 +02005144/* Filter the list of channels received from firmware counting only
5145 * the 20MHz channels. The wiphy band data only needs those which get
5146 * flagged to indicate if they can take part in higher bandwidth.
5147 */
5148static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
5149 struct brcmf_chanspec_list *chlist,
5150 u32 chcnt[])
5151{
5152 u32 total = le32_to_cpu(chlist->count);
5153 struct brcmu_chan ch;
5154 int i;
Hante Meulemand48200b2013-04-03 12:40:29 +02005155
Emil Goodef8adaf0a2014-09-23 00:49:55 +02005156 for (i = 0; i < total; i++) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005157 ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
5158 cfg->d11inf.decchspec(&ch);
5159
5160 /* Firmware gives a ordered list. We skip non-20MHz
5161 * channels is 2G. For 5G we can abort upon reaching
5162 * a non-20MHz channel in the list.
5163 */
5164 if (ch.bw != BRCMU_CHAN_BW_20) {
5165 if (ch.band == BRCMU_CHAN_BAND_5G)
5166 break;
5167 else
5168 continue;
5169 }
5170
5171 if (ch.band == BRCMU_CHAN_BAND_2G)
5172 chcnt[0] += 1;
5173 else if (ch.band == BRCMU_CHAN_BAND_5G)
5174 chcnt[1] += 1;
5175 }
5176}
5177
5178static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5179 struct brcmu_chan *ch)
5180{
5181 u32 ht40_flag;
5182
5183 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5184 if (ch->sb == BRCMU_CHAN_SB_U) {
5185 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5186 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5187 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5188 } else {
5189 /* It should be one of
5190 * IEEE80211_CHAN_NO_HT40 or
5191 * IEEE80211_CHAN_NO_HT40PLUS
5192 */
5193 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5194 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5195 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5196 }
5197}
5198
5199static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5200 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005201{
5202 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005203 struct ieee80211_supported_band *band;
5204 struct ieee80211_channel *channel;
5205 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005206 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005207 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005208 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005209 u8 *pbuf;
5210 u32 i, j;
5211 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005212 u32 chaninfo;
5213 u32 chcnt[2] = { 0, 0 };
Hante Meulemand48200b2013-04-03 12:40:29 +02005214 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02005215
5216 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5217
5218 if (pbuf == NULL)
5219 return -ENOMEM;
5220
5221 list = (struct brcmf_chanspec_list *)pbuf;
5222
5223 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5224 BRCMF_DCMD_MEDLEN);
5225 if (err) {
5226 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005227 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005228 }
5229
Arend van Sprielb48d8912014-07-12 08:49:41 +02005230 brcmf_count_20mhz_channels(cfg, list, chcnt);
5231 wiphy = cfg_to_wiphy(cfg);
5232 if (chcnt[0]) {
5233 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
5234 GFP_KERNEL);
5235 if (band == NULL) {
5236 err = -ENOMEM;
5237 goto fail_pbuf;
5238 }
5239 band->channels = kcalloc(chcnt[0], sizeof(*channel),
5240 GFP_KERNEL);
5241 if (band->channels == NULL) {
5242 kfree(band);
5243 err = -ENOMEM;
5244 goto fail_pbuf;
5245 }
5246 band->n_channels = 0;
5247 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5248 }
5249 if (chcnt[1]) {
5250 band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a),
5251 GFP_KERNEL);
5252 if (band == NULL) {
5253 err = -ENOMEM;
5254 goto fail_band2g;
5255 }
5256 band->channels = kcalloc(chcnt[1], sizeof(*channel),
5257 GFP_KERNEL);
5258 if (band->channels == NULL) {
5259 kfree(band);
5260 err = -ENOMEM;
5261 goto fail_band2g;
5262 }
5263 band->n_channels = 0;
5264 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5265 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005266
5267 total = le32_to_cpu(list->count);
5268 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005269 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5270 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005271
Franky Lin83cf17a2013-04-11 13:28:50 +02005272 if (ch.band == BRCMU_CHAN_BAND_2G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005273 band = wiphy->bands[IEEE80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005274 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005275 band = wiphy->bands[IEEE80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005276 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005277 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005278 continue;
5279 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005280 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005281 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005282 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005283 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005284 ch.bw == BRCMU_CHAN_BW_80)
5285 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005286
5287 channel = band->channels;
5288 index = band->n_channels;
5289 for (j = 0; j < band->n_channels; j++) {
5290 if (channel[j].hw_value == ch.chnum) {
5291 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005292 break;
5293 }
5294 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005295 channel[index].center_freq =
5296 ieee80211_channel_to_frequency(ch.chnum, band->band);
5297 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005298
Arend van Sprielb48d8912014-07-12 08:49:41 +02005299 /* assuming the chanspecs order is HT20,
5300 * HT40 upper, HT40 lower, and VHT80.
5301 */
5302 if (ch.bw == BRCMU_CHAN_BW_80) {
5303 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5304 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5305 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5306 } else {
5307 /* disable other bandwidths for now as mentioned
5308 * order assure they are enabled for subsequent
5309 * chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005310 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005311 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5312 IEEE80211_CHAN_NO_80MHZ;
5313 ch.bw = BRCMU_CHAN_BW_20;
5314 cfg->d11inf.encchspec(&ch);
5315 chaninfo = ch.chspec;
5316 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5317 &chaninfo);
5318 if (!err) {
5319 if (chaninfo & WL_CHAN_RADAR)
5320 channel[index].flags |=
5321 (IEEE80211_CHAN_RADAR |
5322 IEEE80211_CHAN_NO_IR);
5323 if (chaninfo & WL_CHAN_PASSIVE)
5324 channel[index].flags |=
5325 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005326 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005327 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005328 if (index == band->n_channels)
5329 band->n_channels++;
Hante Meulemand48200b2013-04-03 12:40:29 +02005330 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005331 kfree(pbuf);
5332 return 0;
5333
5334fail_band2g:
5335 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5336 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5337 wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
5338fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005339 kfree(pbuf);
5340 return err;
5341}
5342
Arend van Sprielb48d8912014-07-12 08:49:41 +02005343static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005344{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005345 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5346 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005347 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005348 struct brcmf_chanspec_list *list;
5349 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005350 u32 val;
5351 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005352 struct brcmu_chan ch;
5353 u32 num_chan;
5354 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005355
5356 /* verify support for bw_cap command */
5357 val = WLC_BAND_5G;
5358 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5359
5360 if (!err) {
5361 /* only set 2G bandwidth using bw_cap command */
5362 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5363 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5364 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5365 sizeof(band_bwcap));
5366 } else {
5367 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5368 val = WLC_N_BW_40ALL;
5369 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5370 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005371
5372 if (!err) {
5373 /* update channel info in 2G band */
5374 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5375
5376 if (pbuf == NULL)
5377 return -ENOMEM;
5378
5379 ch.band = BRCMU_CHAN_BAND_2G;
5380 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005381 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005382 ch.chnum = 0;
5383 cfg->d11inf.encchspec(&ch);
5384
5385 /* pass encoded chanspec in query */
5386 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5387
5388 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5389 BRCMF_DCMD_MEDLEN);
5390 if (err) {
5391 brcmf_err("get chanspecs error (%d)\n", err);
5392 kfree(pbuf);
5393 return err;
5394 }
5395
5396 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5397 list = (struct brcmf_chanspec_list *)pbuf;
5398 num_chan = le32_to_cpu(list->count);
5399 for (i = 0; i < num_chan; i++) {
5400 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5401 cfg->d11inf.decchspec(&ch);
5402 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5403 continue;
5404 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5405 continue;
5406 for (j = 0; j < band->n_channels; j++) {
5407 if (band->channels[j].hw_value == ch.chnum)
5408 break;
5409 }
5410 if (WARN_ON(j == band->n_channels))
5411 continue;
5412
5413 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5414 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005415 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005416 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005417 return err;
5418}
5419
Arend van Spriel2375d972014-01-06 12:40:41 +01005420static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5421{
5422 u32 band, mimo_bwcap;
5423 int err;
5424
5425 band = WLC_BAND_2G;
5426 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5427 if (!err) {
5428 bw_cap[IEEE80211_BAND_2GHZ] = band;
5429 band = WLC_BAND_5G;
5430 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5431 if (!err) {
5432 bw_cap[IEEE80211_BAND_5GHZ] = band;
5433 return;
5434 }
5435 WARN_ON(1);
5436 return;
5437 }
5438 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5439 mimo_bwcap = 0;
5440 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5441 if (err)
5442 /* assume 20MHz if firmware does not give a clue */
5443 mimo_bwcap = WLC_N_BW_20ALL;
5444
5445 switch (mimo_bwcap) {
5446 case WLC_N_BW_40ALL:
5447 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5448 /* fall-thru */
5449 case WLC_N_BW_20IN2G_40IN5G:
5450 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5451 /* fall-thru */
5452 case WLC_N_BW_20ALL:
5453 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5454 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5455 break;
5456 default:
5457 brcmf_err("invalid mimo_bw_cap value\n");
5458 }
5459}
Hante Meulemand48200b2013-04-03 12:40:29 +02005460
Arend van Spriel18d6c532014-05-12 10:47:35 +02005461static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5462 u32 bw_cap[2], u32 nchain)
5463{
5464 band->ht_cap.ht_supported = true;
5465 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5466 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5467 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5468 }
5469 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5470 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5471 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5472 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5473 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5474 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5475}
5476
5477static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5478{
5479 u16 mcs_map;
5480 int i;
5481
5482 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5483 mcs_map = (mcs_map << 2) | supp;
5484
5485 return cpu_to_le16(mcs_map);
5486}
5487
5488static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
5489 u32 bw_cap[2], u32 nchain)
5490{
5491 __le16 mcs_map;
5492
5493 /* not allowed in 2.4G band */
5494 if (band->band == IEEE80211_BAND_2GHZ)
5495 return;
5496
5497 band->vht_cap.vht_supported = true;
5498 /* 80MHz is mandatory */
5499 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5500 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5501 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5502 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5503 }
5504 /* all support 256-QAM */
5505 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5506 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5507 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
5508}
5509
Arend van Sprielb48d8912014-07-12 08:49:41 +02005510static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005511{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005512 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07005513 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02005514 u32 nmode = 0;
5515 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005516 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01005517 u32 rxchain;
5518 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005519 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005520 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01005521 struct ieee80211_supported_band *band;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005522
Arend van Spriel18d6c532014-05-12 10:47:35 +02005523 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02005524 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5525 if (err) {
5526 brcmf_err("nmode error (%d)\n", err);
5527 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005528 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005529 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005530 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5531 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5532 bw_cap[IEEE80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02005533
Daniel Kim4aca7a12014-02-25 20:30:36 +01005534 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5535 if (err) {
5536 brcmf_err("rxchain error (%d)\n", err);
5537 nchain = 1;
5538 } else {
5539 for (nchain = 0; rxchain; nchain++)
5540 rxchain = rxchain & (rxchain - 1);
5541 }
5542 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5543
Arend van Sprielb48d8912014-07-12 08:49:41 +02005544 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005545 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005546 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02005547 return err;
5548 }
5549
Arend van Sprielb48d8912014-07-12 08:49:41 +02005550 wiphy = cfg_to_wiphy(cfg);
5551 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5552 band = wiphy->bands[i];
5553 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01005554 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02005555
Arend van Spriel18d6c532014-05-12 10:47:35 +02005556 if (nmode)
5557 brcmf_update_ht_cap(band, bw_cap, nchain);
5558 if (vhtmode)
5559 brcmf_update_vht_cap(band, bw_cap, nchain);
Hante Meulemand48200b2013-04-03 12:40:29 +02005560 }
5561
Arend van Sprielb48d8912014-07-12 08:49:41 +02005562 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005563}
5564
Hante Meulemana44aa402014-12-03 21:05:33 +01005565static const struct ieee80211_iface_limit brcmf_iface_limits_mbss[] = {
5566 {
5567 .max = 1,
5568 .types = BIT(NL80211_IFTYPE_STATION) |
5569 BIT(NL80211_IFTYPE_ADHOC)
5570 },
5571 {
5572 .max = 4,
5573 .types = BIT(NL80211_IFTYPE_AP)
5574 },
5575 {
5576 .max = 1,
5577 .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
5578 BIT(NL80211_IFTYPE_P2P_GO)
5579 },
5580 {
5581 .max = 1,
5582 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5583 }
5584};
5585
5586static const struct ieee80211_iface_limit brcmf_iface_limits_sbss[] = {
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005587 {
5588 .max = 2,
5589 .types = BIT(NL80211_IFTYPE_STATION) |
5590 BIT(NL80211_IFTYPE_ADHOC) |
5591 BIT(NL80211_IFTYPE_AP)
5592 },
5593 {
5594 .max = 1,
5595 .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
5596 BIT(NL80211_IFTYPE_P2P_GO)
5597 },
5598 {
5599 .max = 1,
5600 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5601 }
5602};
5603static struct ieee80211_iface_combination brcmf_iface_combos[] = {
5604 {
5605 .max_interfaces = BRCMF_IFACE_MAX_CNT,
5606 .num_different_channels = 1,
Hante Meulemana44aa402014-12-03 21:05:33 +01005607 .n_limits = ARRAY_SIZE(brcmf_iface_limits_sbss),
5608 .limits = brcmf_iface_limits_sbss,
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005609 }
5610};
5611
5612static const struct ieee80211_txrx_stypes
5613brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5614 [NL80211_IFTYPE_STATION] = {
5615 .tx = 0xffff,
5616 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5617 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5618 },
5619 [NL80211_IFTYPE_P2P_CLIENT] = {
5620 .tx = 0xffff,
5621 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5622 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5623 },
5624 [NL80211_IFTYPE_P2P_GO] = {
5625 .tx = 0xffff,
5626 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5627 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5628 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5629 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5630 BIT(IEEE80211_STYPE_AUTH >> 4) |
5631 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5632 BIT(IEEE80211_STYPE_ACTION >> 4)
5633 },
5634 [NL80211_IFTYPE_P2P_DEVICE] = {
5635 .tx = 0xffff,
5636 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5637 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5638 }
5639};
5640
5641static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
5642{
5643 /* scheduled scan settings */
5644 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
5645 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
5646 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5647 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
5648}
5649
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005650#ifdef CONFIG_PM
5651static const struct wiphy_wowlan_support brcmf_wowlan_support = {
5652 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01005653 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
5654 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
5655 .pattern_min_len = 1,
5656 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005657};
5658#endif
5659
5660static void brcmf_wiphy_wowl_params(struct wiphy *wiphy)
5661{
5662#ifdef CONFIG_PM
5663 /* wowl settings */
5664 wiphy->wowlan = &brcmf_wowlan_support;
5665#endif
5666}
5667
Arend van Sprielb48d8912014-07-12 08:49:41 +02005668static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005669{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005670 struct ieee80211_iface_combination ifc_combo;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005671 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
5672 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5673 wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
5674 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
5675 BIT(NL80211_IFTYPE_ADHOC) |
5676 BIT(NL80211_IFTYPE_AP) |
5677 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5678 BIT(NL80211_IFTYPE_P2P_GO) |
5679 BIT(NL80211_IFTYPE_P2P_DEVICE);
5680 /* need VSDB firmware feature for concurrent channels */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005681 ifc_combo = brcmf_iface_combos[0];
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005682 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
Arend van Sprielb48d8912014-07-12 08:49:41 +02005683 ifc_combo.num_different_channels = 2;
Hante Meulemana44aa402014-12-03 21:05:33 +01005684 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) {
5685 ifc_combo.n_limits = ARRAY_SIZE(brcmf_iface_limits_mbss),
5686 ifc_combo.limits = brcmf_iface_limits_mbss;
5687 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005688 wiphy->iface_combinations = kmemdup(&ifc_combo,
5689 sizeof(ifc_combo),
5690 GFP_KERNEL);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005691 wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005692 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
5693 wiphy->cipher_suites = __wl_cipher_suites;
5694 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
5695 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
5696 WIPHY_FLAG_OFFCHAN_TX |
5697 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5698 WIPHY_FLAG_SUPPORTS_TDLS;
5699 if (!brcmf_roamoff)
5700 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
5701 wiphy->mgmt_stypes = brcmf_txrx_stypes;
5702 wiphy->max_remain_on_channel_duration = 5000;
5703 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005704
5705 /* vendor commands/events support */
5706 wiphy->vendor_commands = brcmf_vendor_cmds;
5707 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
5708
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005709 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
5710 brcmf_wiphy_wowl_params(wiphy);
5711
Arend van Sprielb48d8912014-07-12 08:49:41 +02005712 return brcmf_setup_wiphybands(wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005713}
5714
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005715static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005716{
5717 struct net_device *ndev;
5718 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01005719 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005720 s32 power_mode;
5721 s32 err = 0;
5722
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005723 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005724 return err;
5725
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005726 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005727 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01005728 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005729
Hante Meuleman40a23292013-01-02 15:22:51 +01005730 /* make sure RF is ready for work */
5731 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
5732
5733 brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME,
5734 WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005735
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005736 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01005737 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005738 if (err)
5739 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005740 brcmf_dbg(INFO, "power save set to %s\n",
5741 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005742
Hante Meuleman68ca3952014-02-25 20:30:26 +01005743 err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005744 if (err)
5745 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07005746 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
5747 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01005748 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005749 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005750
Hante Meulemanb3657452013-05-27 21:09:53 +02005751 brcmf_configure_arp_offload(ifp, true);
5752
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005753 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01005754default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005755
5756 return err;
5757
5758}
5759
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005760static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005761{
Arend van Sprielc1179032012-10-22 13:55:33 -07005762 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005763
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005764 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005765}
5766
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005767static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005768{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005769 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07005770
Arend van Spriel5b435de2011-10-05 13:19:03 +02005771 /*
5772 * While going down, if associated with AP disassociate
5773 * from AP to save power
5774 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005775 if (check_vif_up(ifp->vif)) {
5776 brcmf_link_down(ifp->vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005777
5778 /* Make sure WPA_Supplicant receives all the event
5779 generated due to DISASSOC call to the fw to keep
5780 the state fw and WPA_Supplicant state consistent
5781 */
5782 brcmf_delay(500);
5783 }
5784
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005785 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07005786 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005787
Arend van Spriel5b435de2011-10-05 13:19:03 +02005788 return 0;
5789}
5790
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005791s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005792{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005793 struct brcmf_if *ifp = netdev_priv(ndev);
5794 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005795 s32 err = 0;
5796
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005797 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005798 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005799 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005800
5801 return err;
5802}
5803
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005804s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005805{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005806 struct brcmf_if *ifp = netdev_priv(ndev);
5807 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005808 s32 err = 0;
5809
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005810 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08005811 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005812 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005813
5814 return err;
5815}
5816
Arend van Spriela7965fb2013-04-11 17:08:37 +02005817enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
5818{
5819 struct wireless_dev *wdev = &ifp->vif->wdev;
5820
5821 return wdev->iftype;
5822}
5823
Hante Meulemanbfe81972014-10-28 14:56:16 +01005824bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
5825 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01005826{
5827 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005828
5829 list_for_each_entry(vif, &cfg->vif_list, list) {
5830 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005831 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005832 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02005833 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01005834}
Arend van Sprield3c0b632013-02-08 15:53:37 +01005835
5836static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
5837 u8 action)
5838{
5839 u8 evt_action;
5840
5841 mutex_lock(&event->vif_event_lock);
5842 evt_action = event->action;
5843 mutex_unlock(&event->vif_event_lock);
5844 return evt_action == action;
5845}
5846
5847void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
5848 struct brcmf_cfg80211_vif *vif)
5849{
5850 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5851
5852 mutex_lock(&event->vif_event_lock);
5853 event->vif = vif;
5854 event->action = 0;
5855 mutex_unlock(&event->vif_event_lock);
5856}
5857
5858bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
5859{
5860 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5861 bool armed;
5862
5863 mutex_lock(&event->vif_event_lock);
5864 armed = event->vif != NULL;
5865 mutex_unlock(&event->vif_event_lock);
5866
5867 return armed;
5868}
5869int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
5870 u8 action, ulong timeout)
5871{
5872 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5873
5874 return wait_event_timeout(event->vif_wq,
5875 vif_event_equals(event, action), timeout);
5876}
5877
Arend van Sprielb48d8912014-07-12 08:49:41 +02005878static void brcmf_free_wiphy(struct wiphy *wiphy)
5879{
5880 kfree(wiphy->iface_combinations);
5881 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5882 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5883 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5884 }
5885 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
5886 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
5887 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
5888 }
5889 wiphy_free(wiphy);
5890}
5891
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005892struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
5893 struct device *busdev)
5894{
5895 struct net_device *ndev = drvr->iflist[0]->ndev;
5896 struct brcmf_cfg80211_info *cfg;
5897 struct wiphy *wiphy;
5898 struct brcmf_cfg80211_vif *vif;
5899 struct brcmf_if *ifp;
5900 s32 err = 0;
5901 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005902 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005903
5904 if (!ndev) {
5905 brcmf_err("ndev is invalid\n");
5906 return NULL;
5907 }
5908
5909 ifp = netdev_priv(ndev);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005910 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
5911 if (!wiphy) {
5912 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005913 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005914 }
5915 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005916
5917 cfg = wiphy_priv(wiphy);
5918 cfg->wiphy = wiphy;
5919 cfg->pub = drvr;
5920 init_vif_event(&cfg->vif_event);
5921 INIT_LIST_HEAD(&cfg->vif_list);
5922
5923 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005924 if (IS_ERR(vif))
5925 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005926
5927 vif->ifp = ifp;
5928 vif->wdev.netdev = ndev;
5929 ndev->ieee80211_ptr = &vif->wdev;
5930 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
5931
5932 err = wl_init_priv(cfg);
5933 if (err) {
5934 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005935 brcmf_free_vif(vif);
5936 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005937 }
5938 ifp->vif = vif;
5939
Arend van Sprielb48d8912014-07-12 08:49:41 +02005940 /* determine d11 io type before wiphy setup */
5941 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005942 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005943 brcmf_err("Failed to get D11 version (%d)\n", err);
5944 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005945 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005946 cfg->d11inf.io_type = (u8)io_type;
5947 brcmu_d11_attach(&cfg->d11inf);
5948
5949 err = brcmf_setup_wiphy(wiphy, ifp);
5950 if (err < 0)
5951 goto priv_out;
5952
5953 brcmf_dbg(INFO, "Registering custom regulatory\n");
5954 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
5955 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
5956
5957 /* firmware defaults to 40MHz disabled in 2G band. We signal
5958 * cfg80211 here that we do and have it decide we can enable
5959 * it. But first check if device does support 2G operation.
5960 */
5961 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5962 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
5963 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5964 }
5965 err = wiphy_register(wiphy);
5966 if (err < 0) {
5967 brcmf_err("Could not register wiphy device (%d)\n", err);
5968 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005969 }
5970
5971 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
5972 * setup 40MHz in 2GHz band and enable OBSS scanning.
5973 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005974 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
5975 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005976 if (!err)
5977 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
5978 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005979 else
5980 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005981 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005982
5983 err = brcmf_p2p_attach(cfg);
5984 if (err) {
5985 brcmf_err("P2P initilisation failed (%d)\n", err);
5986 goto wiphy_unreg_out;
5987 }
5988 err = brcmf_btcoex_attach(cfg);
5989 if (err) {
5990 brcmf_err("BT-coex initialisation failed (%d)\n", err);
5991 brcmf_p2p_detach(&cfg->p2p);
5992 goto wiphy_unreg_out;
5993 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02005994
5995 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
5996 if (err) {
5997 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
5998 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman70b7d942014-07-30 13:20:07 +02005999 } else {
6000 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
6001 brcmf_notify_tdls_peer_event);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006002 }
6003
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006004 return cfg;
6005
Arend van Sprielb48d8912014-07-12 08:49:41 +02006006wiphy_unreg_out:
6007 wiphy_unregister(cfg->wiphy);
6008priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006009 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006010 brcmf_free_vif(vif);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006011wiphy_out:
6012 brcmf_free_wiphy(wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006013 return NULL;
6014}
6015
6016void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
6017{
6018 if (!cfg)
6019 return;
6020
6021 WARN_ON(!list_empty(&cfg->vif_list));
6022 wiphy_unregister(cfg->wiphy);
6023 brcmf_btcoex_detach(cfg);
Arend van Sprielc3da74b2014-07-12 08:49:42 +02006024 brcmf_p2p_detach(&cfg->p2p);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006025 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006026 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006027}