blob: 53831f50676275c63dd86baa98419184a66d9052 [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
18
19#include <linux/kernel.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020020#include <linux/etherdevice.h>
Hante Meuleman68ca3952014-02-25 20:30:26 +010021#include <linux/module.h>
Franky Lin1bacb042014-06-21 12:11:16 +020022#include <linux/vmalloc.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020023#include <net/cfg80211.h>
Arend van Sprielcbaa1772012-08-30 19:43:02 +020024#include <net/netlink.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020025
26#include <brcmu_utils.h>
27#include <defs.h>
28#include <brcmu_wifi.h>
Hante Meuleman122d3d02014-10-28 14:56:18 +010029#include "core.h"
Hante Meulemana8e8ed32014-10-28 14:56:13 +010030#include "debug.h"
Arend van Spriel40c1c242013-04-05 10:57:44 +020031#include "tracepoint.h"
Hante Meuleman7a5c1f62013-02-08 15:53:44 +010032#include "fwil_types.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010033#include "p2p.h"
Piotr Haber61730d42013-04-23 12:53:12 +020034#include "btcoex.h"
Hante Meulemanbfe81972014-10-28 14:56:16 +010035#include "cfg80211.h"
Arend van Sprielc08437b2014-07-12 08:49:39 +020036#include "feature.h"
Hante Meuleman81f5dcb2012-10-22 10:36:14 -070037#include "fwil.h"
Hante Meuleman8851cce2014-07-30 13:20:02 +020038#include "proto.h"
Franky Lin1bacb042014-06-21 12:11:16 +020039#include "vendor.h"
Hante Meulemand14f78b2014-10-28 14:56:14 +010040#include "bus.h"
Hante Meuleman6b89dcb2014-12-21 12:43:52 +010041#include "common.h"
Arend van Spriel5b435de2011-10-05 13:19:03 +020042
Arend van Spriele5806072012-09-19 22:21:08 +020043#define BRCMF_SCAN_IE_LEN_MAX 2048
44#define BRCMF_PNO_VERSION 2
45#define BRCMF_PNO_TIME 30
46#define BRCMF_PNO_REPEAT 4
47#define BRCMF_PNO_FREQ_EXPO_MAX 3
48#define BRCMF_PNO_MAX_PFN_COUNT 16
49#define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
50#define BRCMF_PNO_HIDDEN_BIT 2
51#define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
52#define BRCMF_PNO_SCAN_COMPLETE 1
53#define BRCMF_PNO_SCAN_INCOMPLETE 0
54
Hante Meuleman1a873342012-09-27 14:17:54 +020055#define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
56#define WPA_OUI_TYPE 1
57#define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
58#define WME_OUI_TYPE 2
Hante Meuleman89286dc2013-02-08 15:53:46 +010059#define WPS_OUI_TYPE 4
Hante Meuleman1a873342012-09-27 14:17:54 +020060
61#define VS_IE_FIXED_HDR_LEN 6
62#define WPA_IE_VERSION_LEN 2
63#define WPA_IE_MIN_OUI_LEN 4
64#define WPA_IE_SUITE_COUNT_LEN 2
65
66#define WPA_CIPHER_NONE 0 /* None */
67#define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
68#define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
69#define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
70#define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
71
72#define RSN_AKM_NONE 0 /* None (IBSS) */
73#define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
74#define RSN_AKM_PSK 2 /* Pre-shared Key */
75#define RSN_CAP_LEN 2 /* Length of RSN capabilities */
76#define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
77
78#define VNDR_IE_CMD_LEN 4 /* length of the set command
79 * string :"add", "del" (+ NUL)
80 */
81#define VNDR_IE_COUNT_OFFSET 4
82#define VNDR_IE_PKTFLAG_OFFSET 8
83#define VNDR_IE_VSIE_OFFSET 12
84#define VNDR_IE_HDR_SIZE 12
Arend van Spriel9f440b72013-02-08 15:53:36 +010085#define VNDR_IE_PARSE_LIMIT 5
Hante Meuleman1a873342012-09-27 14:17:54 +020086
87#define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
88#define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
Hante Meuleman04012892012-09-27 14:17:49 +020089
Hante Meuleman89286dc2013-02-08 15:53:46 +010090#define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
91#define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
92#define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
93
Arend van Spriel5b435de2011-10-05 13:19:03 +020094#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
95 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
96
Arend van Sprielce81e312012-10-22 13:55:37 -070097static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +020098{
Arend van Sprielc1179032012-10-22 13:55:33 -070099 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100100 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
101 vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200102 return false;
103 }
104 return true;
105}
106
Arend van Spriel5b435de2011-10-05 13:19:03 +0200107#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
108#define RATETAB_ENT(_rateid, _flags) \
109 { \
110 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
111 .hw_value = (_rateid), \
112 .flags = (_flags), \
113 }
114
115static struct ieee80211_rate __wl_rates[] = {
116 RATETAB_ENT(BRCM_RATE_1M, 0),
117 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
118 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
119 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
120 RATETAB_ENT(BRCM_RATE_6M, 0),
121 RATETAB_ENT(BRCM_RATE_9M, 0),
122 RATETAB_ENT(BRCM_RATE_12M, 0),
123 RATETAB_ENT(BRCM_RATE_18M, 0),
124 RATETAB_ENT(BRCM_RATE_24M, 0),
125 RATETAB_ENT(BRCM_RATE_36M, 0),
126 RATETAB_ENT(BRCM_RATE_48M, 0),
127 RATETAB_ENT(BRCM_RATE_54M, 0),
128};
129
Arend van Spriel5b435de2011-10-05 13:19:03 +0200130#define wl_g_rates (__wl_rates + 0)
Arend van Spriel58de92d2015-04-14 20:10:24 +0200131#define wl_g_rates_size ARRAY_SIZE(__wl_rates)
132#define wl_a_rates (__wl_rates + 4)
133#define wl_a_rates_size (wl_g_rates_size - 4)
134
135#define CHAN2G(_channel, _freq) { \
136 .band = IEEE80211_BAND_2GHZ, \
137 .center_freq = (_freq), \
138 .hw_value = (_channel), \
139 .flags = IEEE80211_CHAN_DISABLED, \
140 .max_antenna_gain = 0, \
141 .max_power = 30, \
142}
143
144#define CHAN5G(_channel) { \
145 .band = IEEE80211_BAND_5GHZ, \
146 .center_freq = 5000 + (5 * (_channel)), \
147 .hw_value = (_channel), \
148 .flags = IEEE80211_CHAN_DISABLED, \
149 .max_antenna_gain = 0, \
150 .max_power = 30, \
151}
152
153static struct ieee80211_channel __wl_2ghz_channels[] = {
154 CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427),
155 CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447),
156 CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467),
157 CHAN2G(13, 2472), CHAN2G(14, 2484)
158};
159
160static struct ieee80211_channel __wl_5ghz_channels[] = {
161 CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42),
162 CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56),
163 CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108),
164 CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128),
165 CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149),
166 CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165)
167};
Arend van Spriel5b435de2011-10-05 13:19:03 +0200168
Arend van Sprielb48d8912014-07-12 08:49:41 +0200169/* Band templates duplicated per wiphy. The channel info
Arend van Spriel58de92d2015-04-14 20:10:24 +0200170 * above is added to the band during setup.
Arend van Sprielb48d8912014-07-12 08:49:41 +0200171 */
172static const struct ieee80211_supported_band __wl_band_2ghz = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200173 .band = IEEE80211_BAND_2GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200174 .bitrates = wl_g_rates,
175 .n_bitrates = wl_g_rates_size,
176};
177
Arend van Spriel58de92d2015-04-14 20:10:24 +0200178static const struct ieee80211_supported_band __wl_band_5ghz = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200179 .band = IEEE80211_BAND_5GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200180 .bitrates = wl_a_rates,
181 .n_bitrates = wl_a_rates_size,
182};
183
Hante Meulemand48200b2013-04-03 12:40:29 +0200184/* This is to override regulatory domains defined in cfg80211 module (reg.c)
185 * By default world regulatory domain defined in reg.c puts the flags
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200186 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
187 * With respect to these flags, wpa_supplicant doesn't * start p2p
188 * operations on 5GHz channels. All the changes in world regulatory
Hante Meulemand48200b2013-04-03 12:40:29 +0200189 * domain are to be done here.
190 */
191static const struct ieee80211_regdomain brcmf_regdom = {
192 .n_reg_rules = 4,
193 .alpha2 = "99",
194 .reg_rules = {
195 /* IEEE 802.11b/g, channels 1..11 */
196 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
197 /* If any */
198 /* IEEE 802.11 channel 14 - Only JP enables
199 * this and for 802.11b only
200 */
201 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
202 /* IEEE 802.11a, channel 36..64 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200203 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
Hante Meulemand48200b2013-04-03 12:40:29 +0200204 /* IEEE 802.11a, channel 100..165 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200205 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200206};
207
208static const u32 __wl_cipher_suites[] = {
209 WLAN_CIPHER_SUITE_WEP40,
210 WLAN_CIPHER_SUITE_WEP104,
211 WLAN_CIPHER_SUITE_TKIP,
212 WLAN_CIPHER_SUITE_CCMP,
213 WLAN_CIPHER_SUITE_AES_CMAC,
214};
215
Hante Meuleman1a873342012-09-27 14:17:54 +0200216/* Vendor specific ie. id = 221, oui and type defines exact ie */
217struct brcmf_vs_tlv {
218 u8 id;
219 u8 len;
220 u8 oui[3];
221 u8 oui_type;
222};
223
224struct parsed_vndr_ie_info {
225 u8 *ie_ptr;
226 u32 ie_len; /* total length including id & length field */
227 struct brcmf_vs_tlv vndrie;
228};
229
230struct parsed_vndr_ies {
231 u32 count;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100232 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
Hante Meuleman1a873342012-09-27 14:17:54 +0200233};
234
Hante Meuleman68ca3952014-02-25 20:30:26 +0100235static int brcmf_roamoff;
236module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
237MODULE_PARM_DESC(roamoff, "do not use internal roaming engine");
238
Alwin Beukersef6ac172011-10-12 20:51:26 +0200239
Arend van Spriel5a394eb2014-05-27 12:56:15 +0200240static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
241 struct cfg80211_chan_def *ch)
Arend van Spriel600a8972014-05-12 10:47:39 +0200242{
243 struct brcmu_chan ch_inf;
244 s32 primary_offset;
245
246 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
247 ch->chan->center_freq, ch->center_freq1, ch->width);
248 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
249 primary_offset = ch->center_freq1 - ch->chan->center_freq;
250 switch (ch->width) {
251 case NL80211_CHAN_WIDTH_20:
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100252 case NL80211_CHAN_WIDTH_20_NOHT:
Arend van Spriel600a8972014-05-12 10:47:39 +0200253 ch_inf.bw = BRCMU_CHAN_BW_20;
254 WARN_ON(primary_offset != 0);
255 break;
256 case NL80211_CHAN_WIDTH_40:
257 ch_inf.bw = BRCMU_CHAN_BW_40;
258 if (primary_offset < 0)
259 ch_inf.sb = BRCMU_CHAN_SB_U;
260 else
261 ch_inf.sb = BRCMU_CHAN_SB_L;
262 break;
263 case NL80211_CHAN_WIDTH_80:
264 ch_inf.bw = BRCMU_CHAN_BW_80;
265 if (primary_offset < 0) {
266 if (primary_offset < -CH_10MHZ_APART)
267 ch_inf.sb = BRCMU_CHAN_SB_UU;
268 else
269 ch_inf.sb = BRCMU_CHAN_SB_UL;
270 } else {
271 if (primary_offset > CH_10MHZ_APART)
272 ch_inf.sb = BRCMU_CHAN_SB_LL;
273 else
274 ch_inf.sb = BRCMU_CHAN_SB_LU;
275 }
276 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100277 case NL80211_CHAN_WIDTH_80P80:
278 case NL80211_CHAN_WIDTH_160:
279 case NL80211_CHAN_WIDTH_5:
280 case NL80211_CHAN_WIDTH_10:
Arend van Spriel600a8972014-05-12 10:47:39 +0200281 default:
282 WARN_ON_ONCE(1);
283 }
284 switch (ch->chan->band) {
285 case IEEE80211_BAND_2GHZ:
286 ch_inf.band = BRCMU_CHAN_BAND_2G;
287 break;
288 case IEEE80211_BAND_5GHZ:
289 ch_inf.band = BRCMU_CHAN_BAND_5G;
290 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100291 case IEEE80211_BAND_60GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200292 default:
293 WARN_ON_ONCE(1);
294 }
295 d11inf->encchspec(&ch_inf);
296
297 return ch_inf.chspec;
298}
299
Franky Lin83cf17a2013-04-11 13:28:50 +0200300u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
301 struct ieee80211_channel *ch)
Arend van Spriel6e186162012-10-22 10:36:22 -0700302{
Franky Lin83cf17a2013-04-11 13:28:50 +0200303 struct brcmu_chan ch_inf;
Arend van Spriel6e186162012-10-22 10:36:22 -0700304
Franky Lin83cf17a2013-04-11 13:28:50 +0200305 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
306 ch_inf.bw = BRCMU_CHAN_BW_20;
307 d11inf->encchspec(&ch_inf);
Arend van Spriel6e186162012-10-22 10:36:22 -0700308
Franky Lin83cf17a2013-04-11 13:28:50 +0200309 return ch_inf.chspec;
Arend van Spriel6e186162012-10-22 10:36:22 -0700310}
311
Hante Meuleman89286dc2013-02-08 15:53:46 +0100312/* Traverse a string of 1-byte tag/1-byte length/variable-length value
313 * triples, returning a pointer to the substring whose first element
314 * matches tag
315 */
Johannes Berg4b5800f2014-01-15 14:55:59 +0100316const struct brcmf_tlv *
317brcmf_parse_tlvs(const void *buf, int buflen, uint key)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100318{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100319 const struct brcmf_tlv *elt = buf;
320 int totlen = buflen;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100321
322 /* find tagged parameter */
323 while (totlen >= TLV_HDR_LEN) {
324 int len = elt->len;
325
326 /* validate remaining totlen */
327 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
328 return elt;
329
330 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
331 totlen -= (len + TLV_HDR_LEN);
332 }
333
334 return NULL;
335}
336
337/* Is any of the tlvs the expected entry? If
338 * not update the tlvs buffer pointer/length.
339 */
340static bool
Johannes Berg4b5800f2014-01-15 14:55:59 +0100341brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
342 const u8 *oui, u32 oui_len, u8 type)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100343{
344 /* If the contents match the OUI and the type */
345 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
346 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
347 type == ie[TLV_BODY_OFF + oui_len]) {
348 return true;
349 }
350
351 if (tlvs == NULL)
352 return false;
353 /* point to the next ie */
354 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
355 /* calculate the length of the rest of the buffer */
356 *tlvs_len -= (int)(ie - *tlvs);
357 /* update the pointer to the start of the buffer */
358 *tlvs = ie;
359
360 return false;
361}
362
363static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100364brcmf_find_wpaie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100365{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100366 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100367
368 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
Johannes Berg4b5800f2014-01-15 14:55:59 +0100369 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
Hante Meuleman89286dc2013-02-08 15:53:46 +0100370 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
371 return (struct brcmf_vs_tlv *)ie;
372 }
373 return NULL;
374}
375
376static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100377brcmf_find_wpsie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100378{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100379 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100380
381 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
382 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
383 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
384 return (struct brcmf_vs_tlv *)ie;
385 }
386 return NULL;
387}
388
Arend van Spriel39504a22015-08-20 22:06:05 +0200389static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
390 struct brcmf_cfg80211_vif *vif,
391 enum nl80211_iftype new_type)
392{
393 int iftype_num[NUM_NL80211_IFTYPES];
394 struct brcmf_cfg80211_vif *pos;
395
396 memset(&iftype_num[0], 0, sizeof(iftype_num));
397 list_for_each_entry(pos, &cfg->vif_list, list)
398 if (pos == vif)
399 iftype_num[new_type]++;
400 else
401 iftype_num[pos->wdev.iftype]++;
402
403 return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
404}
405
406static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
407 enum nl80211_iftype new_type)
408{
409 int iftype_num[NUM_NL80211_IFTYPES];
410 struct brcmf_cfg80211_vif *pos;
411
412 memset(&iftype_num[0], 0, sizeof(iftype_num));
413 list_for_each_entry(pos, &cfg->vif_list, list)
414 iftype_num[pos->wdev.iftype]++;
415
416 iftype_num[new_type]++;
417 return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
418}
Hante Meuleman89286dc2013-02-08 15:53:46 +0100419
Arend van Spriel5b435de2011-10-05 13:19:03 +0200420static void convert_key_from_CPU(struct brcmf_wsec_key *key,
421 struct brcmf_wsec_key_le *key_le)
422{
423 key_le->index = cpu_to_le32(key->index);
424 key_le->len = cpu_to_le32(key->len);
425 key_le->algo = cpu_to_le32(key->algo);
426 key_le->flags = cpu_to_le32(key->flags);
427 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
428 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
429 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
430 memcpy(key_le->data, key->data, sizeof(key->data));
431 memcpy(key_le->ea, key->ea, sizeof(key->ea));
432}
433
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200434static int
Hante Meuleman118eb302014-12-21 12:43:49 +0100435send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200436{
437 int err;
438 struct brcmf_wsec_key_le key_le;
439
440 convert_key_from_CPU(key, &key_le);
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200441
Hante Meuleman118eb302014-12-21 12:43:49 +0100442 brcmf_netdev_wait_pend8021x(ifp);
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700443
Hante Meuleman118eb302014-12-21 12:43:49 +0100444 err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700445 sizeof(key_le));
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200446
Arend van Spriel5b435de2011-10-05 13:19:03 +0200447 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +0100448 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200449 return err;
450}
451
Hante Meulemanb3657452013-05-27 21:09:53 +0200452static s32
453brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable)
454{
455 s32 err;
456 u32 mode;
457
458 if (enable)
459 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
460 else
461 mode = 0;
462
463 /* Try to set and enable ARP offload feature, this may fail, then it */
464 /* is simply not supported and err 0 will be returned */
465 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
466 if (err) {
467 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
468 mode, err);
469 err = 0;
470 } else {
471 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
472 if (err) {
473 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
474 enable, err);
475 err = 0;
476 } else
477 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
478 enable, mode);
479 }
480
481 return err;
482}
483
Hante Meuleman8851cce2014-07-30 13:20:02 +0200484static void
485brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
486{
Arend van Spriel8f2b4592014-09-11 22:51:32 +0200487 struct brcmf_cfg80211_vif *vif;
488 struct brcmf_if *ifp;
489
490 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
491 ifp = vif->ifp;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200492
493 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
494 (wdev->iftype == NL80211_IFTYPE_AP) ||
495 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
496 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
497 ADDR_DIRECT);
498 else
499 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
500 ADDR_INDIRECT);
501}
502
Hante Meulemana44aa402014-12-03 21:05:33 +0100503static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
504{
505 struct brcmf_mbss_ssid_le mbss_ssid_le;
506 int bsscfgidx;
507 int err;
508
509 memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
510 bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr);
511 if (bsscfgidx < 0)
512 return bsscfgidx;
513
514 mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
515 mbss_ssid_le.SSID_len = cpu_to_le32(5);
516 sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
517
518 err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
519 sizeof(mbss_ssid_le));
520 if (err < 0)
521 brcmf_err("setting ssid failed %d\n", err);
522
523 return err;
524}
525
526/**
527 * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
528 *
529 * @wiphy: wiphy device of new interface.
530 * @name: name of the new interface.
531 * @flags: not used.
532 * @params: contains mac address for AP device.
533 */
534static
535struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
536 u32 *flags, struct vif_params *params)
537{
538 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
539 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
540 struct brcmf_cfg80211_vif *vif;
541 int err;
542
543 if (brcmf_cfg80211_vif_event_armed(cfg))
544 return ERR_PTR(-EBUSY);
545
546 brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
547
548 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false);
549 if (IS_ERR(vif))
550 return (struct wireless_dev *)vif;
551
552 brcmf_cfg80211_arm_vif_event(cfg, vif);
553
554 err = brcmf_cfg80211_request_ap_if(ifp);
555 if (err) {
556 brcmf_cfg80211_arm_vif_event(cfg, NULL);
557 goto fail;
558 }
559
560 /* wait for firmware event */
561 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
562 msecs_to_jiffies(1500));
563 brcmf_cfg80211_arm_vif_event(cfg, NULL);
564 if (!err) {
565 brcmf_err("timeout occurred\n");
566 err = -EIO;
567 goto fail;
568 }
569
570 /* interface created in firmware */
571 ifp = vif->ifp;
572 if (!ifp) {
573 brcmf_err("no if pointer provided\n");
574 err = -ENOENT;
575 goto fail;
576 }
577
578 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
579 err = brcmf_net_attach(ifp, true);
580 if (err) {
581 brcmf_err("Registering netdevice failed\n");
582 goto fail;
583 }
584
585 return &ifp->vif->wdev;
586
587fail:
588 brcmf_free_vif(vif);
589 return ERR_PTR(err);
590}
591
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100592static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
593{
594 enum nl80211_iftype iftype;
595
596 iftype = vif->wdev.iftype;
597 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
598}
599
600static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
601{
602 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
603}
604
Arend van Spriel9f440b72013-02-08 15:53:36 +0100605static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
606 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100607 unsigned char name_assign_type,
Arend van Spriel9f440b72013-02-08 15:53:36 +0100608 enum nl80211_iftype type,
609 u32 *flags,
610 struct vif_params *params)
611{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200612 struct wireless_dev *wdev;
Arend van Spriel39504a22015-08-20 22:06:05 +0200613 int err;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200614
Arend van Spriel9f440b72013-02-08 15:53:36 +0100615 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
Arend van Spriel39504a22015-08-20 22:06:05 +0200616 err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
617 if (err) {
618 brcmf_err("iface validation failed: err=%d\n", err);
619 return ERR_PTR(err);
620 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100621 switch (type) {
622 case NL80211_IFTYPE_ADHOC:
623 case NL80211_IFTYPE_STATION:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100624 case NL80211_IFTYPE_AP_VLAN:
625 case NL80211_IFTYPE_WDS:
626 case NL80211_IFTYPE_MONITOR:
627 case NL80211_IFTYPE_MESH_POINT:
628 return ERR_PTR(-EOPNOTSUPP);
Hante Meulemana44aa402014-12-03 21:05:33 +0100629 case NL80211_IFTYPE_AP:
630 wdev = brcmf_ap_add_vif(wiphy, name, flags, params);
631 if (!IS_ERR(wdev))
632 brcmf_cfg80211_update_proto_addr_mode(wdev);
633 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100634 case NL80211_IFTYPE_P2P_CLIENT:
635 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200636 case NL80211_IFTYPE_P2P_DEVICE:
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100637 wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, flags, params);
Hante Meuleman8851cce2014-07-30 13:20:02 +0200638 if (!IS_ERR(wdev))
639 brcmf_cfg80211_update_proto_addr_mode(wdev);
640 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100641 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100642 default:
643 return ERR_PTR(-EINVAL);
644 }
645}
646
Daniel Kim5e787f72014-06-21 12:11:18 +0200647static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
648{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200649 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200650 brcmf_set_mpc(ifp, mpc);
651}
652
Arend van Sprielf96aa072013-04-05 10:57:48 +0200653void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100654{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100655 s32 err = 0;
656
657 if (check_vif_up(ifp->vif)) {
658 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
659 if (err) {
660 brcmf_err("fail to set mpc\n");
661 return;
662 }
663 brcmf_dbg(INFO, "MPC : %d\n", mpc);
664 }
665}
666
Arend van Spriela0f472a2013-04-05 10:57:49 +0200667s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
668 struct brcmf_if *ifp, bool aborted,
669 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100670{
671 struct brcmf_scan_params_le params_le;
672 struct cfg80211_scan_request *scan_request;
673 s32 err = 0;
674
675 brcmf_dbg(SCAN, "Enter\n");
676
677 /* clear scan request, because the FW abort can cause a second call */
678 /* to this functon and might cause a double cfg80211_scan_done */
679 scan_request = cfg->scan_request;
680 cfg->scan_request = NULL;
681
682 if (timer_pending(&cfg->escan_timeout))
683 del_timer_sync(&cfg->escan_timeout);
684
685 if (fw_abort) {
686 /* Do a scan abort to stop the driver's scan engine */
687 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
688 memset(&params_le, 0, sizeof(params_le));
Joe Perches93803b32015-03-02 19:54:49 -0800689 eth_broadcast_addr(params_le.bssid);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100690 params_le.bss_type = DOT11_BSSTYPE_ANY;
691 params_le.scan_type = 0;
692 params_le.channel_num = cpu_to_le32(1);
693 params_le.nprobes = cpu_to_le32(1);
694 params_le.active_time = cpu_to_le32(-1);
695 params_le.passive_time = cpu_to_le32(-1);
696 params_le.home_time = cpu_to_le32(-1);
697 /* Scan is aborted by setting channel_list[0] to -1 */
698 params_le.channel_list[0] = cpu_to_le16(-1);
699 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200700 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100701 &params_le, sizeof(params_le));
702 if (err)
703 brcmf_err("Scan abort failed\n");
704 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200705
Daniel Kim5e787f72014-06-21 12:11:18 +0200706 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200707
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100708 /*
709 * e-scan can be initiated by scheduled scan
710 * which takes precedence.
711 */
712 if (cfg->sched_escan) {
713 brcmf_dbg(SCAN, "scheduled scan completed\n");
714 cfg->sched_escan = false;
715 if (!aborted)
716 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100717 } else if (scan_request) {
718 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
719 aborted ? "Aborted" : "Done");
720 cfg80211_scan_done(scan_request, aborted);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100721 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100722 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
723 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100724
725 return err;
726}
727
Arend van Spriel9f440b72013-02-08 15:53:36 +0100728static
729int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
730{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100731 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
732 struct net_device *ndev = wdev->netdev;
733
734 /* vif event pending in firmware */
735 if (brcmf_cfg80211_vif_event_armed(cfg))
736 return -EBUSY;
737
738 if (ndev) {
739 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200740 cfg->escan_info.ifp == netdev_priv(ndev))
741 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
742 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100743
744 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
745 }
746
Arend van Spriel9f440b72013-02-08 15:53:36 +0100747 switch (wdev->iftype) {
748 case NL80211_IFTYPE_ADHOC:
749 case NL80211_IFTYPE_STATION:
750 case NL80211_IFTYPE_AP:
751 case NL80211_IFTYPE_AP_VLAN:
752 case NL80211_IFTYPE_WDS:
753 case NL80211_IFTYPE_MONITOR:
754 case NL80211_IFTYPE_MESH_POINT:
755 return -EOPNOTSUPP;
756 case NL80211_IFTYPE_P2P_CLIENT:
757 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200758 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100759 return brcmf_p2p_del_vif(wiphy, wdev);
760 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100761 default:
762 return -EINVAL;
763 }
764 return -EOPNOTSUPP;
765}
766
Arend van Spriel5b435de2011-10-05 13:19:03 +0200767static s32
768brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
769 enum nl80211_iftype type, u32 *flags,
770 struct vif_params *params)
771{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100772 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700773 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100774 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200775 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200776 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200777 s32 err = 0;
778
Hante Meuleman37a869e2015-10-29 20:33:17 +0100779 brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx,
780 type);
Hante Meuleman178e9ef2015-09-18 22:08:11 +0200781
782 /* WAR: There are a number of p2p interface related problems which
783 * need to be handled initially (before doing the validate).
784 * wpa_supplicant tends to do iface changes on p2p device/client/go
785 * which are not always possible/allowed. However we need to return
786 * OK otherwise the wpa_supplicant wont start. The situation differs
787 * on configuration and setup (p2pon=1 module param). The first check
788 * is to see if the request is a change to station for p2p iface.
789 */
790 if ((type == NL80211_IFTYPE_STATION) &&
791 ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
792 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) ||
793 (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) {
794 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
795 /* Now depending on whether module param p2pon=1 was used the
796 * response needs to be either 0 or EOPNOTSUPP. The reason is
797 * that if p2pon=1 is used, but a newer supplicant is used then
798 * we should return an error, as this combination wont work.
799 * In other situations 0 is returned and supplicant will start
800 * normally. It will give a trace in cfg80211, but it is the
801 * only way to get it working. Unfortunately this will result
802 * in situation where we wont support new supplicant in
803 * combination with module param p2pon=1, but that is the way
804 * it is. If the user tries this then unloading of driver might
805 * fail/lock.
806 */
807 if (cfg->p2p.p2pdev_dynamically)
808 return -EOPNOTSUPP;
809 else
810 return 0;
811 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200812 err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
813 if (err) {
814 brcmf_err("iface validation failed: err=%d\n", err);
815 return err;
816 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200817 switch (type) {
818 case NL80211_IFTYPE_MONITOR:
819 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100820 brcmf_err("type (%d) : currently we do not support this type\n",
821 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200822 return -EOPNOTSUPP;
823 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200824 infra = 0;
825 break;
826 case NL80211_IFTYPE_STATION:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200827 infra = 1;
828 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200829 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100830 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200831 ap = 1;
832 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200833 default:
834 err = -EINVAL;
835 goto done;
836 }
837
Hante Meuleman1a873342012-09-27 14:17:54 +0200838 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100839 if (type == NL80211_IFTYPE_P2P_GO) {
840 brcmf_dbg(INFO, "IF Type = P2P GO\n");
841 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
842 }
843 if (!err) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100844 brcmf_dbg(INFO, "IF Type = AP\n");
845 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200846 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100847 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200848 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100849 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200850 err = -EAGAIN;
851 goto done;
852 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100853 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100854 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200855 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200856 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200857
Hante Meuleman8851cce2014-07-30 13:20:02 +0200858 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
859
Arend van Spriel5b435de2011-10-05 13:19:03 +0200860done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100861 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200862
863 return err;
864}
865
Franky Lin83cf17a2013-04-11 13:28:50 +0200866static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
867 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200868 struct cfg80211_scan_request *request)
869{
870 u32 n_ssids;
871 u32 n_channels;
872 s32 i;
873 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200874 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200875 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200876 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200877
Joe Perches93803b32015-03-02 19:54:49 -0800878 eth_broadcast_addr(params_le->bssid);
Hante Meulemane756af52012-09-11 21:18:52 +0200879 params_le->bss_type = DOT11_BSSTYPE_ANY;
880 params_le->scan_type = 0;
881 params_le->channel_num = 0;
882 params_le->nprobes = cpu_to_le32(-1);
883 params_le->active_time = cpu_to_le32(-1);
884 params_le->passive_time = cpu_to_le32(-1);
885 params_le->home_time = cpu_to_le32(-1);
886 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
887
888 /* if request is null exit so it will be all channel broadcast scan */
889 if (!request)
890 return;
891
892 n_ssids = request->n_ssids;
893 n_channels = request->n_channels;
894 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100895 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
896 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200897 if (n_channels > 0) {
898 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200899 chanspec = channel_to_chanspec(&cfg->d11inf,
900 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100901 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
902 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200903 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200904 }
905 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100906 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200907 }
908 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100909 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200910 if (n_ssids > 0) {
911 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
912 n_channels * sizeof(u16);
913 offset = roundup(offset, sizeof(u32));
914 ptr = (char *)params_le + offset;
915 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +0200916 memset(&ssid_le, 0, sizeof(ssid_le));
917 ssid_le.SSID_len =
918 cpu_to_le32(request->ssids[i].ssid_len);
919 memcpy(ssid_le.SSID, request->ssids[i].ssid,
920 request->ssids[i].ssid_len);
921 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100922 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +0200923 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100924 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
925 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +0200926 memcpy(ptr, &ssid_le, sizeof(ssid_le));
927 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +0200928 }
929 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100930 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200931 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100932 brcmf_dbg(SCAN, "SSID %s len=%d\n",
933 params_le->ssid_le.SSID,
934 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200935 params_le->ssid_le.SSID_len =
936 cpu_to_le32(request->ssids->ssid_len);
937 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
938 request->ssids->ssid_len);
939 }
940 }
941 /* Adding mask to channel numbers */
942 params_le->channel_num =
943 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
944 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
945}
946
947static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200948brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemanc4958102015-11-25 11:32:41 +0100949 struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200950{
951 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
952 offsetof(struct brcmf_escan_params_le, params_le);
953 struct brcmf_escan_params_le *params;
954 s32 err = 0;
955
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100956 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200957
958 if (request != NULL) {
959 /* Allocate space for populating ssids in struct */
960 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
961
962 /* Allocate space for populating ssids in struct */
Hante Meulemane9a6ca82015-11-25 11:32:37 +0100963 params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids;
Hante Meulemane756af52012-09-11 21:18:52 +0200964 }
965
966 params = kzalloc(params_size, GFP_KERNEL);
967 if (!params) {
968 err = -ENOMEM;
969 goto exit;
970 }
971 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +0200972 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +0200973 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
Hante Meulemanc4958102015-11-25 11:32:41 +0100974 params->action = cpu_to_le16(WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +0200975 params->sync_id = cpu_to_le16(0x1234);
976
Arend van Spriela0f472a2013-04-05 10:57:49 +0200977 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +0200978 if (err) {
979 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100980 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200981 else
Arend van Spriel57d6e912012-12-05 15:26:00 +0100982 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200983 }
984
985 kfree(params);
986exit:
987 return err;
988}
989
990static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200991brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
Arend van Spriela0f472a2013-04-05 10:57:49 +0200992 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200993{
994 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700995 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +0200996 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100997 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +0200998
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100999 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001000 escan->ifp = ifp;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001001 escan->wiphy = wiphy;
1002 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001003 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +02001004 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001005 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001006 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001007 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001008 return err;
1009 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001010 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001011 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02001012 results->version = 0;
1013 results->count = 0;
1014 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
1015
Hante Meulemanc4958102015-11-25 11:32:41 +01001016 err = escan->run(cfg, ifp, request);
Hante Meulemane756af52012-09-11 21:18:52 +02001017 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +02001018 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001019 return err;
1020}
1021
1022static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001023brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +02001024 struct cfg80211_scan_request *request,
1025 struct cfg80211_ssid *this_ssid)
1026{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001027 struct brcmf_if *ifp = vif->ifp;
1028 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +02001029 struct cfg80211_ssid *ssids;
Hante Meulemanf07998952012-11-05 16:22:13 -08001030 struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001031 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001032 bool escan_req;
1033 bool spec_scan;
1034 s32 err;
1035 u32 SSID_len;
1036
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001037 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001038
Arend van Sprielc1179032012-10-22 13:55:33 -07001039 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001040 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001041 return -EAGAIN;
1042 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001043 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001044 brcmf_err("Scanning being aborted: status (%lu)\n",
1045 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001046 return -EAGAIN;
1047 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02001048 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
1049 brcmf_err("Scanning suppressed: status (%lu)\n",
1050 cfg->scan_status);
1051 return -EAGAIN;
1052 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001053 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001054 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +02001055 return -EAGAIN;
1056 }
1057
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001058 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001059 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
1060 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001061
Hante Meulemane756af52012-09-11 21:18:52 +02001062 escan_req = false;
1063 if (request) {
1064 /* scan bss */
1065 ssids = request->ssids;
1066 escan_req = true;
1067 } else {
1068 /* scan in ibss */
1069 /* we don't do escan in ibss */
1070 ssids = this_ssid;
1071 }
1072
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001073 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -07001074 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001075 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +01001076 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001077 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001078 if (err)
1079 goto scan_out;
1080
Arend van Spriela0f472a2013-04-05 10:57:49 +02001081 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -08001082 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +02001083 goto scan_out;
1084 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001085 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
1086 ssids->ssid, ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +02001087 memset(&sr->ssid_le, 0, sizeof(sr->ssid_le));
1088 SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len);
1089 sr->ssid_le.SSID_len = cpu_to_le32(0);
1090 spec_scan = false;
1091 if (SSID_len) {
1092 memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len);
1093 sr->ssid_le.SSID_len = cpu_to_le32(SSID_len);
1094 spec_scan = true;
1095 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001096 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001097
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001098 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -07001099 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001100 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001101 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001102 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001103 goto scan_out;
1104 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001105 brcmf_scan_config_mpc(ifp, 0);
Arend van Sprielc1179032012-10-22 13:55:33 -07001106 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Sprielac24be62012-10-22 10:36:23 -07001107 &sr->ssid_le, sizeof(sr->ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001108 if (err) {
1109 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001110 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
1111 sr->ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001112 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001113 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001114
Daniel Kim5e787f72014-06-21 12:11:18 +02001115 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001116 goto scan_out;
1117 }
1118 }
1119
Hante Meuleman661fa952015-02-06 18:36:47 +01001120 /* Arm scan timeout timer */
1121 mod_timer(&cfg->escan_timeout, jiffies +
1122 WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
1123
Hante Meulemane756af52012-09-11 21:18:52 +02001124 return 0;
1125
1126scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001127 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001128 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001129 return err;
1130}
1131
Arend van Spriel5b435de2011-10-05 13:19:03 +02001132static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001133brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001134{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001135 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001136 s32 err = 0;
1137
Arend van Sprield96b8012012-12-05 15:26:02 +01001138 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001139 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1140 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001141 return -EIO;
1142
Arend van Spriela0f472a2013-04-05 10:57:49 +02001143 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001144
Arend van Spriel5b435de2011-10-05 13:19:03 +02001145 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001146 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001147
Arend van Sprield96b8012012-12-05 15:26:02 +01001148 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001149 return err;
1150}
1151
1152static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1153{
1154 s32 err = 0;
1155
Arend van Sprielac24be62012-10-22 10:36:23 -07001156 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1157 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001158 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001159 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001160
1161 return err;
1162}
1163
1164static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1165{
1166 s32 err = 0;
1167
Arend van Sprielac24be62012-10-22 10:36:23 -07001168 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1169 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001170 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001171 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001172
1173 return err;
1174}
1175
1176static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1177{
1178 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001179 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001180
Arend van Sprielac24be62012-10-22 10:36:23 -07001181 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001182 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001183 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001184 return err;
1185 }
1186 return err;
1187}
1188
1189static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1190{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001191 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1192 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001193 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001194 s32 err = 0;
1195
Arend van Sprield96b8012012-12-05 15:26:02 +01001196 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001197 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001198 return -EIO;
1199
1200 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001201 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1202 cfg->conf->rts_threshold = wiphy->rts_threshold;
1203 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001204 if (!err)
1205 goto done;
1206 }
1207 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001208 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1209 cfg->conf->frag_threshold = wiphy->frag_threshold;
1210 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001211 if (!err)
1212 goto done;
1213 }
1214 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001215 && (cfg->conf->retry_long != wiphy->retry_long)) {
1216 cfg->conf->retry_long = wiphy->retry_long;
1217 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001218 if (!err)
1219 goto done;
1220 }
1221 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001222 && (cfg->conf->retry_short != wiphy->retry_short)) {
1223 cfg->conf->retry_short = wiphy->retry_short;
1224 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001225 if (!err)
1226 goto done;
1227 }
1228
1229done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001230 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001231 return err;
1232}
1233
Arend van Spriel5b435de2011-10-05 13:19:03 +02001234static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1235{
1236 memset(prof, 0, sizeof(*prof));
1237}
1238
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001239static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
1240{
1241 u16 reason;
1242
1243 switch (e->event_code) {
1244 case BRCMF_E_DEAUTH:
1245 case BRCMF_E_DEAUTH_IND:
1246 case BRCMF_E_DISASSOC_IND:
1247 reason = e->reason;
1248 break;
1249 case BRCMF_E_LINK:
1250 default:
1251 reason = 0;
1252 break;
1253 }
1254 return reason;
1255}
1256
1257static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001258{
Piotr Haber61730d42013-04-23 12:53:12 +02001259 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001260 s32 err = 0;
1261
Arend van Sprield96b8012012-12-05 15:26:02 +01001262 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001263
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001264 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001265 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001266 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001267 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001268 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001269 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001270 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001271 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001272 cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
Johannes Berg80279fb2015-05-22 16:22:20 +02001273 true, GFP_KERNEL);
Arend van Spriel43dffbc2014-01-06 12:40:46 +01001274
Arend van Spriel5b435de2011-10-05 13:19:03 +02001275 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001276 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001277 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1278 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001279 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001280}
1281
1282static s32
1283brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1284 struct cfg80211_ibss_params *params)
1285{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001286 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001287 struct brcmf_if *ifp = netdev_priv(ndev);
1288 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001289 struct brcmf_join_params join_params;
1290 size_t join_params_size = 0;
1291 s32 err = 0;
1292 s32 wsec = 0;
1293 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001294 u16 chanspec;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001295 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001296
Arend van Sprield96b8012012-12-05 15:26:02 +01001297 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001298 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001299 return -EIO;
1300
1301 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001302 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001303 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001304 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001305 return -EOPNOTSUPP;
1306 }
1307
Arend van Sprielc1179032012-10-22 13:55:33 -07001308 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001309
1310 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001311 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001312 else
Arend van Spriel16886732012-12-05 15:26:04 +01001313 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001314
Johannes Berg683b6d32012-11-08 21:25:48 +01001315 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001316 brcmf_dbg(CONN, "channel: %d\n",
1317 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001318 else
Arend van Spriel16886732012-12-05 15:26:04 +01001319 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001320
1321 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001322 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001323 else
Arend van Spriel16886732012-12-05 15:26:04 +01001324 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001325
1326 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001327 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001328 else
Arend van Spriel16886732012-12-05 15:26:04 +01001329 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001330
1331 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001332 brcmf_dbg(CONN, "beacon interval: %d\n",
1333 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001334 else
Arend van Spriel16886732012-12-05 15:26:04 +01001335 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001336
1337 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001338 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001339 else
Arend van Spriel16886732012-12-05 15:26:04 +01001340 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001341
1342 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001343 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001344 else
Arend van Spriel16886732012-12-05 15:26:04 +01001345 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001346
1347 /* Configure Privacy for starter */
1348 if (params->privacy)
1349 wsec |= WEP_ENABLED;
1350
Arend van Sprielc1179032012-10-22 13:55:33 -07001351 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001352 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001353 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001354 goto done;
1355 }
1356
1357 /* Configure Beacon Interval for starter */
1358 if (params->beacon_interval)
1359 bcnprd = params->beacon_interval;
1360 else
1361 bcnprd = 100;
1362
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001363 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001364 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001365 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001366 goto done;
1367 }
1368
1369 /* Configure required join parameter */
1370 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1371
1372 /* SSID */
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001373 ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN);
1374 memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len);
1375 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001376 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001377
1378 /* BSSID */
1379 if (params->bssid) {
1380 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001381 join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001382 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001383 } else {
Joe Perches93803b32015-03-02 19:54:49 -08001384 eth_broadcast_addr(join_params.params_le.bssid);
1385 eth_zero_addr(profile->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001386 }
1387
Arend van Spriel5b435de2011-10-05 13:19:03 +02001388 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001389 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001390 u32 target_channel;
1391
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001392 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001393 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001394 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001395 if (params->channel_fixed) {
1396 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001397 chanspec = chandef_to_chanspec(&cfg->d11inf,
1398 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001399 join_params.params_le.chanspec_list[0] =
1400 cpu_to_le16(chanspec);
1401 join_params.params_le.chanspec_num = cpu_to_le32(1);
1402 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001403 }
1404
1405 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001406 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001407 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001408 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001409 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001410 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001411 goto done;
1412 }
1413 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001414 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001415
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001416 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001417
1418
Arend van Sprielc1179032012-10-22 13:55:33 -07001419 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001420 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001421 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001422 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001423 goto done;
1424 }
1425
1426done:
1427 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001428 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001429 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001430 return err;
1431}
1432
1433static s32
1434brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1435{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001436 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001437
Arend van Sprield96b8012012-12-05 15:26:02 +01001438 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001439 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001440 return -EIO;
1441
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001442 brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001443
Arend van Sprield96b8012012-12-05 15:26:02 +01001444 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001445
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001446 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001447}
1448
1449static s32 brcmf_set_wpa_version(struct net_device *ndev,
1450 struct cfg80211_connect_params *sme)
1451{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001452 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001453 struct brcmf_cfg80211_security *sec;
1454 s32 val = 0;
1455 s32 err = 0;
1456
1457 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1458 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1459 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1460 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1461 else
1462 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001463 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001464 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001465 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001466 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001467 return err;
1468 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001469 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001470 sec->wpa_versions = sme->crypto.wpa_versions;
1471 return err;
1472}
1473
1474static s32 brcmf_set_auth_type(struct net_device *ndev,
1475 struct cfg80211_connect_params *sme)
1476{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001477 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001478 struct brcmf_cfg80211_security *sec;
1479 s32 val = 0;
1480 s32 err = 0;
1481
1482 switch (sme->auth_type) {
1483 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1484 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001485 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001486 break;
1487 case NL80211_AUTHTYPE_SHARED_KEY:
1488 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001489 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001490 break;
1491 case NL80211_AUTHTYPE_AUTOMATIC:
1492 val = 2;
Arend van Spriel16886732012-12-05 15:26:04 +01001493 brcmf_dbg(CONN, "automatic\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001494 break;
1495 case NL80211_AUTHTYPE_NETWORK_EAP:
Arend van Spriel16886732012-12-05 15:26:04 +01001496 brcmf_dbg(CONN, "network eap\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001497 default:
1498 val = 2;
Arend van Spriel57d6e912012-12-05 15:26:00 +01001499 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001500 break;
1501 }
1502
Hante Meuleman89286dc2013-02-08 15:53:46 +01001503 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001504 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001505 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001506 return err;
1507 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001508 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001509 sec->auth_type = sme->auth_type;
1510 return err;
1511}
1512
1513static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001514brcmf_set_wsec_mode(struct net_device *ndev,
1515 struct cfg80211_connect_params *sme, bool mfp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001516{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001517 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001518 struct brcmf_cfg80211_security *sec;
1519 s32 pval = 0;
1520 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001521 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001522 s32 err = 0;
1523
1524 if (sme->crypto.n_ciphers_pairwise) {
1525 switch (sme->crypto.ciphers_pairwise[0]) {
1526 case WLAN_CIPHER_SUITE_WEP40:
1527 case WLAN_CIPHER_SUITE_WEP104:
1528 pval = WEP_ENABLED;
1529 break;
1530 case WLAN_CIPHER_SUITE_TKIP:
1531 pval = TKIP_ENABLED;
1532 break;
1533 case WLAN_CIPHER_SUITE_CCMP:
1534 pval = AES_ENABLED;
1535 break;
1536 case WLAN_CIPHER_SUITE_AES_CMAC:
1537 pval = AES_ENABLED;
1538 break;
1539 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001540 brcmf_err("invalid cipher pairwise (%d)\n",
1541 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001542 return -EINVAL;
1543 }
1544 }
1545 if (sme->crypto.cipher_group) {
1546 switch (sme->crypto.cipher_group) {
1547 case WLAN_CIPHER_SUITE_WEP40:
1548 case WLAN_CIPHER_SUITE_WEP104:
1549 gval = WEP_ENABLED;
1550 break;
1551 case WLAN_CIPHER_SUITE_TKIP:
1552 gval = TKIP_ENABLED;
1553 break;
1554 case WLAN_CIPHER_SUITE_CCMP:
1555 gval = AES_ENABLED;
1556 break;
1557 case WLAN_CIPHER_SUITE_AES_CMAC:
1558 gval = AES_ENABLED;
1559 break;
1560 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001561 brcmf_err("invalid cipher group (%d)\n",
1562 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001563 return -EINVAL;
1564 }
1565 }
1566
Arend van Spriel16886732012-12-05 15:26:04 +01001567 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001568 /* In case of privacy, but no security and WPS then simulate */
1569 /* setting AES. WPS-2.0 allows no security */
1570 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1571 sme->privacy)
1572 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001573
1574 if (mfp)
1575 wsec = pval | gval | MFP_CAPABLE;
1576 else
1577 wsec = pval | gval;
1578 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001579 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001580 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001581 return err;
1582 }
1583
Arend van Spriel06bb1232012-09-27 14:17:56 +02001584 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001585 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1586 sec->cipher_group = sme->crypto.cipher_group;
1587
1588 return err;
1589}
1590
1591static s32
1592brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1593{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001594 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001595 struct brcmf_cfg80211_security *sec;
1596 s32 val = 0;
1597 s32 err = 0;
1598
1599 if (sme->crypto.n_akm_suites) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01001600 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
1601 "wpa_auth", &val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001602 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001603 brcmf_err("could not get wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001604 return err;
1605 }
1606 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1607 switch (sme->crypto.akm_suites[0]) {
1608 case WLAN_AKM_SUITE_8021X:
1609 val = WPA_AUTH_UNSPECIFIED;
1610 break;
1611 case WLAN_AKM_SUITE_PSK:
1612 val = WPA_AUTH_PSK;
1613 break;
1614 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001615 brcmf_err("invalid cipher group (%d)\n",
1616 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001617 return -EINVAL;
1618 }
1619 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1620 switch (sme->crypto.akm_suites[0]) {
1621 case WLAN_AKM_SUITE_8021X:
1622 val = WPA2_AUTH_UNSPECIFIED;
1623 break;
1624 case WLAN_AKM_SUITE_PSK:
1625 val = WPA2_AUTH_PSK;
1626 break;
1627 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001628 brcmf_err("invalid cipher group (%d)\n",
1629 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001630 return -EINVAL;
1631 }
1632 }
1633
Arend van Spriel16886732012-12-05 15:26:04 +01001634 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001635 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
1636 "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001637 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001638 brcmf_err("could not set wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001639 return err;
1640 }
1641 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001642 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001643 sec->wpa_auth = sme->crypto.akm_suites[0];
1644
1645 return err;
1646}
1647
1648static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001649brcmf_set_sharedkey(struct net_device *ndev,
1650 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001651{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001652 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001653 struct brcmf_cfg80211_security *sec;
1654 struct brcmf_wsec_key key;
1655 s32 val;
1656 s32 err = 0;
1657
Arend van Spriel16886732012-12-05 15:26:04 +01001658 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001659
Roland Vossena718e2f2011-10-12 20:51:24 +02001660 if (sme->key_len == 0)
1661 return 0;
1662
Arend van Spriel06bb1232012-09-27 14:17:56 +02001663 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001664 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1665 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001666
1667 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1668 return 0;
1669
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001670 if (!(sec->cipher_pairwise &
1671 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1672 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001673
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001674 memset(&key, 0, sizeof(key));
1675 key.len = (u32) sme->key_len;
1676 key.index = (u32) sme->key_idx;
1677 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001678 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001679 return -EINVAL;
1680 }
1681 memcpy(key.data, sme->key, key.len);
1682 key.flags = BRCMF_PRIMARY_KEY;
1683 switch (sec->cipher_pairwise) {
1684 case WLAN_CIPHER_SUITE_WEP40:
1685 key.algo = CRYPTO_ALGO_WEP1;
1686 break;
1687 case WLAN_CIPHER_SUITE_WEP104:
1688 key.algo = CRYPTO_ALGO_WEP128;
1689 break;
1690 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001691 brcmf_err("Invalid algorithm (%d)\n",
1692 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001693 return -EINVAL;
1694 }
1695 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001696 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1697 key.len, key.index, key.algo);
1698 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Hante Meuleman118eb302014-12-21 12:43:49 +01001699 err = send_key_to_dongle(netdev_priv(ndev), &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001700 if (err)
1701 return err;
1702
1703 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001704 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001705 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001706 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001707 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001708 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001709 }
1710 return err;
1711}
1712
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001713static
1714enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1715 enum nl80211_auth_type type)
1716{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001717 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1718 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1719 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1720 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001721 }
1722 return type;
1723}
1724
Arend van Spriel5b435de2011-10-05 13:19:03 +02001725static s32
1726brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001727 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001728{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001729 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001730 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001731 struct ieee80211_channel *chan = sme->channel;
1732 struct brcmf_join_params join_params;
1733 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001734 const struct brcmf_tlv *rsn_ie;
1735 const struct brcmf_vs_tlv *wpa_ie;
1736 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001737 u32 ie_len;
1738 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001739 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001740 s32 err = 0;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001741 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001742
Arend van Sprield96b8012012-12-05 15:26:02 +01001743 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001744 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001745 return -EIO;
1746
1747 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001748 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001749 return -EOPNOTSUPP;
1750 }
1751
Hante Meuleman89286dc2013-02-08 15:53:46 +01001752 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1753 /* A normal (non P2P) connection request setup. */
1754 ie = NULL;
1755 ie_len = 0;
1756 /* find the WPA_IE */
1757 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1758 if (wpa_ie) {
1759 ie = wpa_ie;
1760 ie_len = wpa_ie->len + TLV_HDR_LEN;
1761 } else {
1762 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001763 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1764 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001765 WLAN_EID_RSN);
1766 if (rsn_ie) {
1767 ie = rsn_ie;
1768 ie_len = rsn_ie->len + TLV_HDR_LEN;
1769 }
1770 }
1771 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1772 }
1773
1774 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1775 sme->ie, sme->ie_len);
1776 if (err)
1777 brcmf_err("Set Assoc REQ IE Failed\n");
1778 else
1779 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1780
Arend van Sprielc1179032012-10-22 13:55:33 -07001781 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001782
1783 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001784 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001785 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001786 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001787 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1788 cfg->channel, chan->center_freq, chanspec);
1789 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001790 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001791 chanspec = 0;
1792 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001793
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001794 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001795
1796 err = brcmf_set_wpa_version(ndev, sme);
1797 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001798 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001799 goto done;
1800 }
1801
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001802 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001803 err = brcmf_set_auth_type(ndev, sme);
1804 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001805 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001806 goto done;
1807 }
1808
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001809 err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001810 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001811 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001812 goto done;
1813 }
1814
1815 err = brcmf_set_key_mgmt(ndev, sme);
1816 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001817 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001818 goto done;
1819 }
1820
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001821 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001822 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001823 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001824 goto done;
1825 }
1826
Hante Meuleman89286dc2013-02-08 15:53:46 +01001827 /* Join with specific BSSID and cached SSID
1828 * If SSID is zero join based on BSSID only
1829 */
1830 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1831 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1832 if (cfg->channel)
1833 join_params_size += sizeof(u16);
1834 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1835 if (ext_join_params == NULL) {
1836 err = -ENOMEM;
1837 goto done;
1838 }
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001839 ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN);
1840 ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len);
1841 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len);
1842 if (ssid_len < IEEE80211_MAX_SSID_LEN)
1843 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n",
1844 ext_join_params->ssid_le.SSID, ssid_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001845
Hante Meuleman89286dc2013-02-08 15:53:46 +01001846 /* Set up join scan parameters */
1847 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001848 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1849
1850 if (sme->bssid)
1851 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1852 else
Joe Perches93803b32015-03-02 19:54:49 -08001853 eth_broadcast_addr(ext_join_params->assoc_le.bssid);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001854
1855 if (cfg->channel) {
1856 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
1857
1858 ext_join_params->assoc_le.chanspec_list[0] =
1859 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001860 /* Increase dwell time to receive probe response or detect
1861 * beacon from target AP at a noisy air only during connect
1862 * command.
1863 */
1864 ext_join_params->scan_le.active_time =
1865 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
1866 ext_join_params->scan_le.passive_time =
1867 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
1868 /* To sync with presence period of VSDB GO send probe request
1869 * more frequently. Probe request will be stopped when it gets
1870 * probe response from target AP/GO.
1871 */
1872 ext_join_params->scan_le.nprobes =
1873 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
1874 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
1875 } else {
1876 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
1877 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
1878 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001879 }
1880
1881 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
1882 join_params_size);
1883 kfree(ext_join_params);
1884 if (!err)
1885 /* This is it. join command worked, we are done */
1886 goto done;
1887
1888 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02001889 memset(&join_params, 0, sizeof(join_params));
1890 join_params_size = sizeof(join_params.ssid_le);
1891
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001892 memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len);
1893 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001894
Hante Meuleman89286dc2013-02-08 15:53:46 +01001895 if (sme->bssid)
1896 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
1897 else
Joe Perches93803b32015-03-02 19:54:49 -08001898 eth_broadcast_addr(join_params.params_le.bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001899
Hante Meuleman17012612013-02-06 18:40:44 +01001900 if (cfg->channel) {
1901 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
1902 join_params.params_le.chanspec_num = cpu_to_le32(1);
1903 join_params_size += sizeof(join_params.params_le);
1904 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001905 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001906 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001907 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01001908 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001909
1910done:
1911 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001912 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001913 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001914 return err;
1915}
1916
1917static s32
1918brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1919 u16 reason_code)
1920{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001921 struct brcmf_if *ifp = netdev_priv(ndev);
1922 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001923 struct brcmf_scb_val_le scbval;
1924 s32 err = 0;
1925
Arend van Sprield96b8012012-12-05 15:26:02 +01001926 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
Arend van Sprielce81e312012-10-22 13:55:37 -07001927 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001928 return -EIO;
1929
Arend van Sprielc1179032012-10-22 13:55:33 -07001930 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel4f3fff12014-11-20 22:27:02 +01001931 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Johannes Berg80279fb2015-05-22 16:22:20 +02001932 cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001933
Arend van Spriel06bb1232012-09-27 14:17:56 +02001934 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001935 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07001936 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07001937 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001938 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001939 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001940
Arend van Sprield96b8012012-12-05 15:26:02 +01001941 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001942 return err;
1943}
1944
1945static s32
Johannes Bergc8442112012-10-24 10:17:18 +02001946brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001947 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001948{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001949 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001950 struct net_device *ndev = cfg_to_ndev(cfg);
1951 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001952 s32 err;
1953 s32 disable;
1954 u32 qdbm = 127;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001955
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001956 brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm);
Arend van Sprielce81e312012-10-22 13:55:37 -07001957 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001958 return -EIO;
1959
1960 switch (type) {
1961 case NL80211_TX_POWER_AUTOMATIC:
1962 break;
1963 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02001964 case NL80211_TX_POWER_FIXED:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001965 if (mbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001966 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001967 err = -EINVAL;
1968 goto done;
1969 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001970 qdbm = MBM_TO_DBM(4 * mbm);
1971 if (qdbm > 127)
1972 qdbm = 127;
1973 qdbm |= WL_TXPWR_OVERRIDE;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001974 break;
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001975 default:
1976 brcmf_err("Unsupported type %d\n", type);
1977 err = -EINVAL;
1978 goto done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001979 }
1980 /* Make sure radio is off or on as far as software is concerned */
1981 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07001982 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001983 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001984 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001985
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001986 err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001987 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001988 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001989
1990done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001991 brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001992 return err;
1993}
1994
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001995static s32
1996brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1997 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001998{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001999 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002000 struct net_device *ndev = cfg_to_ndev(cfg);
2001 struct brcmf_if *ifp = netdev_priv(ndev);
2002 s32 qdbm = 0;
2003 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002004
Arend van Sprield96b8012012-12-05 15:26:02 +01002005 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002006 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002007 return -EIO;
2008
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002009 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002010 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002011 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002012 goto done;
2013 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002014 *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002015
2016done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002017 brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002018 return err;
2019}
2020
2021static s32
2022brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002023 u8 key_idx, bool unicast, bool multicast)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002024{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002025 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002026 u32 index;
2027 u32 wsec;
2028 s32 err = 0;
2029
Arend van Sprield96b8012012-12-05 15:26:02 +01002030 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002031 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002032 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002033 return -EIO;
2034
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002035 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002036 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002037 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002038 goto done;
2039 }
2040
2041 if (wsec & WEP_ENABLED) {
2042 /* Just select a new current key */
2043 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002044 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07002045 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002046 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002047 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002048 }
2049done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002050 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002051 return err;
2052}
2053
2054static s32
2055brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
2056 u8 key_idx, const u8 *mac_addr, struct key_params *params)
2057{
Hante Meuleman992f6062013-04-02 21:06:17 +02002058 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002059 struct brcmf_wsec_key key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002060 s32 err = 0;
Hante Meuleman992f6062013-04-02 21:06:17 +02002061 u8 keybuf[8];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002062
2063 memset(&key, 0, sizeof(key));
2064 key.index = (u32) key_idx;
2065 /* Instead of bcast for ea address for default wep keys,
2066 driver needs it to be Null */
2067 if (!is_multicast_ether_addr(mac_addr))
2068 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
2069 key.len = (u32) params->key_len;
2070 /* check for key index change */
2071 if (key.len == 0) {
2072 /* key delete */
Hante Meuleman118eb302014-12-21 12:43:49 +01002073 err = send_key_to_dongle(ifp, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002074 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002075 brcmf_err("key delete error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002076 } else {
2077 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002078 brcmf_err("Invalid key length (%d)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002079 return -EINVAL;
2080 }
2081
Arend van Spriel16886732012-12-05 15:26:04 +01002082 brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002083 memcpy(key.data, params->key, key.len);
2084
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002085 if (!brcmf_is_apmode(ifp->vif) &&
Hante Meuleman992f6062013-04-02 21:06:17 +02002086 (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
2087 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002088 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2089 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2090 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2091 }
2092
2093 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
2094 if (params->seq && params->seq_len == 6) {
2095 /* rx iv */
2096 u8 *ivptr;
2097 ivptr = (u8 *) params->seq;
2098 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2099 (ivptr[3] << 8) | ivptr[2];
2100 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2101 key.iv_initialized = true;
2102 }
2103
2104 switch (params->cipher) {
2105 case WLAN_CIPHER_SUITE_WEP40:
2106 key.algo = CRYPTO_ALGO_WEP1;
Arend van Spriel16886732012-12-05 15:26:04 +01002107 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002108 break;
2109 case WLAN_CIPHER_SUITE_WEP104:
2110 key.algo = CRYPTO_ALGO_WEP128;
Arend van Spriel16886732012-12-05 15:26:04 +01002111 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002112 break;
2113 case WLAN_CIPHER_SUITE_TKIP:
2114 key.algo = CRYPTO_ALGO_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002115 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002116 break;
2117 case WLAN_CIPHER_SUITE_AES_CMAC:
2118 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002119 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002120 break;
2121 case WLAN_CIPHER_SUITE_CCMP:
2122 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002123 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002124 break;
2125 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002126 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002127 return -EINVAL;
2128 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002129 err = send_key_to_dongle(ifp, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002130 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002131 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002132 }
2133 return err;
2134}
2135
2136static s32
2137brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2138 u8 key_idx, bool pairwise, const u8 *mac_addr,
2139 struct key_params *params)
2140{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002141 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman118eb302014-12-21 12:43:49 +01002142 struct brcmf_wsec_key *key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002143 s32 val;
2144 s32 wsec;
2145 s32 err = 0;
2146 u8 keybuf[8];
2147
Arend van Sprield96b8012012-12-05 15:26:02 +01002148 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002149 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002150 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002151 return -EIO;
2152
Hante Meuleman118eb302014-12-21 12:43:49 +01002153 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2154 /* we ignore this key index in this case */
2155 brcmf_err("invalid key index (%d)\n", key_idx);
2156 return -EINVAL;
2157 }
2158
Daniel Kim787eb032014-01-29 15:32:23 +01002159 if (mac_addr &&
2160 (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2161 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01002162 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002163 return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
2164 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002165
Hante Meuleman118eb302014-12-21 12:43:49 +01002166 key = &ifp->vif->profile.key[key_idx];
2167 memset(key, 0, sizeof(*key));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002168
Hante Meuleman118eb302014-12-21 12:43:49 +01002169 if (params->key_len > sizeof(key->data)) {
2170 brcmf_err("Too long key length (%u)\n", params->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002171 err = -EINVAL;
2172 goto done;
2173 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002174 key->len = params->key_len;
2175 key->index = key_idx;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002176
Hante Meuleman118eb302014-12-21 12:43:49 +01002177 memcpy(key->data, params->key, key->len);
2178
2179 key->flags = BRCMF_PRIMARY_KEY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002180 switch (params->cipher) {
2181 case WLAN_CIPHER_SUITE_WEP40:
Hante Meuleman118eb302014-12-21 12:43:49 +01002182 key->algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002183 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002184 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002185 break;
2186 case WLAN_CIPHER_SUITE_WEP104:
Hante Meuleman118eb302014-12-21 12:43:49 +01002187 key->algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002188 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002189 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002190 break;
2191 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002192 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002193 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman118eb302014-12-21 12:43:49 +01002194 memcpy(keybuf, &key->data[24], sizeof(keybuf));
2195 memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
2196 memcpy(&key->data[16], keybuf, sizeof(keybuf));
Hante Meuleman1a873342012-09-27 14:17:54 +02002197 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002198 key->algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002199 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002200 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002201 break;
2202 case WLAN_CIPHER_SUITE_AES_CMAC:
Hante Meuleman118eb302014-12-21 12:43:49 +01002203 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002204 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002205 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002206 break;
2207 case WLAN_CIPHER_SUITE_CCMP:
Hante Meuleman118eb302014-12-21 12:43:49 +01002208 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002209 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002210 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002211 break;
2212 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002213 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002214 err = -EINVAL;
2215 goto done;
2216 }
2217
Hante Meuleman118eb302014-12-21 12:43:49 +01002218 err = send_key_to_dongle(ifp, key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002219 if (err)
2220 goto done;
2221
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002222 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002223 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002224 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002225 goto done;
2226 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002227 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002228 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002229 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002230 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002231 goto done;
2232 }
2233
Arend van Spriel5b435de2011-10-05 13:19:03 +02002234done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002235 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002236 return err;
2237}
2238
2239static s32
2240brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2241 u8 key_idx, bool pairwise, const u8 *mac_addr)
2242{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002243 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002244 struct brcmf_wsec_key key;
2245 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002246
Arend van Sprield96b8012012-12-05 15:26:02 +01002247 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002248 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002249 return -EIO;
2250
Hante Meuleman118eb302014-12-21 12:43:49 +01002251 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
Hante Meuleman256c3742012-11-05 16:22:28 -08002252 /* we ignore this key index in this case */
Hante Meuleman256c3742012-11-05 16:22:28 -08002253 return -EINVAL;
2254 }
2255
Arend van Spriel5b435de2011-10-05 13:19:03 +02002256 memset(&key, 0, sizeof(key));
2257
2258 key.index = (u32) key_idx;
2259 key.flags = BRCMF_PRIMARY_KEY;
2260 key.algo = CRYPTO_ALGO_OFF;
2261
Arend van Spriel16886732012-12-05 15:26:04 +01002262 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002263
2264 /* Set the new key/index */
Hante Meuleman118eb302014-12-21 12:43:49 +01002265 err = send_key_to_dongle(ifp, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002266
Arend van Sprield96b8012012-12-05 15:26:02 +01002267 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002268 return err;
2269}
2270
2271static s32
2272brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2273 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
2274 void (*callback) (void *cookie, struct key_params * params))
2275{
2276 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002277 struct brcmf_if *ifp = netdev_priv(ndev);
2278 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002279 struct brcmf_cfg80211_security *sec;
2280 s32 wsec;
2281 s32 err = 0;
2282
Arend van Sprield96b8012012-12-05 15:26:02 +01002283 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002284 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002285 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002286 return -EIO;
2287
2288 memset(&params, 0, sizeof(params));
2289
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002290 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002291 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002292 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002293 /* Ignore this error, may happen during DISASSOC */
2294 err = -EAGAIN;
2295 goto done;
2296 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002297 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002298 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002299 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2300 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002301 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002302 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2303 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002304 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002305 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002306 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002307 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002308 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002309 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002310 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002311 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002312 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002313 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002314 err = -EINVAL;
2315 goto done;
2316 }
2317 callback(cookie, &params);
2318
2319done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002320 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002321 return err;
2322}
2323
2324static s32
2325brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2326 struct net_device *ndev, u8 key_idx)
2327{
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002328 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002329
2330 return -EOPNOTSUPP;
2331}
2332
Hante Meuleman118eb302014-12-21 12:43:49 +01002333static void
2334brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
2335{
2336 s32 err;
2337 u8 key_idx;
2338 struct brcmf_wsec_key *key;
2339 s32 wsec;
2340
2341 for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
2342 key = &ifp->vif->profile.key[key_idx];
2343 if ((key->algo == CRYPTO_ALGO_WEP1) ||
2344 (key->algo == CRYPTO_ALGO_WEP128))
2345 break;
2346 }
2347 if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
2348 return;
2349
2350 err = send_key_to_dongle(ifp, key);
2351 if (err) {
2352 brcmf_err("Setting WEP key failed (%d)\n", err);
2353 return;
2354 }
2355 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2356 if (err) {
2357 brcmf_err("get wsec error (%d)\n", err);
2358 return;
2359 }
2360 wsec |= WEP_ENABLED;
2361 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2362 if (err)
2363 brcmf_err("set wsec error (%d)\n", err);
2364}
2365
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002366static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si)
2367{
2368 struct nl80211_sta_flag_update *sfu;
2369
2370 brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags);
2371 si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS);
2372 sfu = &si->sta_flags;
2373 sfu->mask = BIT(NL80211_STA_FLAG_WME) |
2374 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2375 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2376 BIT(NL80211_STA_FLAG_AUTHORIZED);
2377 if (fw_sta_flags & BRCMF_STA_WME)
2378 sfu->set |= BIT(NL80211_STA_FLAG_WME);
2379 if (fw_sta_flags & BRCMF_STA_AUTHE)
2380 sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2381 if (fw_sta_flags & BRCMF_STA_ASSOC)
2382 sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2383 if (fw_sta_flags & BRCMF_STA_AUTHO)
2384 sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2385}
2386
2387static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si)
2388{
2389 struct {
2390 __le32 len;
2391 struct brcmf_bss_info_le bss_le;
2392 } *buf;
2393 u16 capability;
2394 int err;
2395
2396 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2397 if (!buf)
2398 return;
2399
2400 buf->len = cpu_to_le32(WL_BSS_INFO_MAX);
2401 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf,
2402 WL_BSS_INFO_MAX);
2403 if (err) {
2404 brcmf_err("Failed to get bss info (%d)\n", err);
2405 return;
2406 }
2407 si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
2408 si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period);
2409 si->bss_param.dtim_period = buf->bss_le.dtim_period;
2410 capability = le16_to_cpu(buf->bss_le.capability);
2411 if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT)
2412 si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2413 if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2414 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2415 if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2416 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2417}
2418
Arend van Spriel5b435de2011-10-05 13:19:03 +02002419static s32
2420brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002421 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002422{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002423 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002424 s32 err = 0;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002425 struct brcmf_sta_info_le sta_info_le;
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002426 u32 sta_flags;
2427 u32 is_tdls_peer;
Hante Meulemancae355d2015-10-08 20:33:17 +02002428 s32 total_rssi;
2429 s32 count_rssi;
2430 u32 i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002431
Arend van Sprield96b8012012-12-05 15:26:02 +01002432 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002433 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002434 return -EIO;
2435
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002436 memset(&sta_info_le, 0, sizeof(sta_info_le));
2437 memcpy(&sta_info_le, mac, ETH_ALEN);
2438 err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info",
2439 &sta_info_le,
2440 sizeof(sta_info_le));
2441 is_tdls_peer = !err;
2442 if (err) {
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002443 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002444 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002445 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002446 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002447 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002448 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002449 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002450 }
2451 brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver));
2452 sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME);
2453 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2454 sta_flags = le32_to_cpu(sta_info_le.flags);
2455 brcmf_convert_sta_flags(sta_flags, sinfo);
2456 sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2457 if (is_tdls_peer)
2458 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2459 else
2460 sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2461 if (sta_flags & BRCMF_STA_ASSOC) {
2462 sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
2463 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
2464 brcmf_fill_bss_param(ifp, sinfo);
2465 }
2466 if (sta_flags & BRCMF_STA_SCBSTATS) {
2467 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
2468 sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures);
2469 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
2470 sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts);
2471 sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts);
2472 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
2473 sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts);
2474 sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts);
2475 if (sinfo->tx_packets) {
Johannes Berg319090b2014-11-17 14:08:11 +01002476 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002477 sinfo->txrate.legacy =
2478 le32_to_cpu(sta_info_le.tx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002479 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002480 if (sinfo->rx_packets) {
2481 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002482 sinfo->rxrate.legacy =
2483 le32_to_cpu(sta_info_le.rx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002484 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002485 if (le16_to_cpu(sta_info_le.ver) >= 4) {
2486 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES);
2487 sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes);
2488 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES);
2489 sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes);
2490 }
Hante Meulemancae355d2015-10-08 20:33:17 +02002491 total_rssi = 0;
2492 count_rssi = 0;
2493 for (i = 0; i < BRCMF_ANT_MAX; i++) {
2494 if (sta_info_le.rssi[i]) {
2495 sinfo->chain_signal_avg[count_rssi] =
2496 sta_info_le.rssi[i];
2497 sinfo->chain_signal[count_rssi] =
2498 sta_info_le.rssi[i];
2499 total_rssi += sta_info_le.rssi[i];
2500 count_rssi++;
2501 }
2502 }
2503 if (count_rssi) {
2504 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
2505 sinfo->chains = count_rssi;
2506
2507 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2508 total_rssi /= count_rssi;
2509 sinfo->signal = total_rssi;
2510 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002511 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002512done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002513 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002514 return err;
2515}
2516
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02002517static int
2518brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
2519 int idx, u8 *mac, struct station_info *sinfo)
2520{
2521 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2522 struct brcmf_if *ifp = netdev_priv(ndev);
2523 s32 err;
2524
2525 brcmf_dbg(TRACE, "Enter, idx %d\n", idx);
2526
2527 if (idx == 0) {
2528 cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST);
2529 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST,
2530 &cfg->assoclist,
2531 sizeof(cfg->assoclist));
2532 if (err) {
2533 brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n",
2534 err);
2535 cfg->assoclist.count = 0;
2536 return -EOPNOTSUPP;
2537 }
2538 }
2539 if (idx < le32_to_cpu(cfg->assoclist.count)) {
2540 memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN);
2541 return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo);
2542 }
2543 return -ENOENT;
2544}
2545
Arend van Spriel5b435de2011-10-05 13:19:03 +02002546static s32
2547brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2548 bool enabled, s32 timeout)
2549{
2550 s32 pm;
2551 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002552 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002553 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002554
Arend van Sprield96b8012012-12-05 15:26:02 +01002555 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002556
2557 /*
2558 * Powersave enable/disable request is coming from the
2559 * cfg80211 even before the interface is up. In that
2560 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002561 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002562 * FW later while initializing the dongle
2563 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002564 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002565 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002566
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002567 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002568 goto done;
2569 }
2570
2571 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002572 /* Do not enable the power save after assoc if it is a p2p interface */
2573 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2574 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2575 pm = PM_OFF;
2576 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002577 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002578
Arend van Sprielc1179032012-10-22 13:55:33 -07002579 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002580 if (err) {
2581 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002582 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002583 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002584 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002585 }
2586done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002587 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002588 return err;
2589}
2590
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002591static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002592 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002593{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002594 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002595 struct ieee80211_channel *notify_channel;
2596 struct cfg80211_bss *bss;
2597 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002598 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002599 u16 channel;
2600 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002601 u16 notify_capability;
2602 u16 notify_interval;
2603 u8 *notify_ie;
2604 size_t notify_ielen;
2605 s32 notify_signal;
2606
2607 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002608 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002609 return 0;
2610 }
2611
Franky Lin83cf17a2013-04-11 13:28:50 +02002612 if (!bi->ctl_ch) {
2613 ch.chspec = le16_to_cpu(bi->chanspec);
2614 cfg->d11inf.decchspec(&ch);
2615 bi->ctl_ch = ch.chnum;
2616 }
2617 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002618
2619 if (channel <= CH_MAX_2G_CHANNEL)
2620 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2621 else
2622 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2623
2624 freq = ieee80211_channel_to_frequency(channel, band->band);
2625 notify_channel = ieee80211_get_channel(wiphy, freq);
2626
Arend van Spriel5b435de2011-10-05 13:19:03 +02002627 notify_capability = le16_to_cpu(bi->capability);
2628 notify_interval = le16_to_cpu(bi->beacon_period);
2629 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2630 notify_ielen = le32_to_cpu(bi->ie_length);
2631 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2632
Arend van Spriel16886732012-12-05 15:26:04 +01002633 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2634 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2635 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2636 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2637 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002638
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002639 bss = cfg80211_inform_bss(wiphy, notify_channel,
2640 CFG80211_BSS_FTYPE_UNKNOWN,
2641 (const u8 *)bi->BSSID,
2642 0, notify_capability,
2643 notify_interval, notify_ie,
2644 notify_ielen, notify_signal,
2645 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002646
Franky Line78946e2011-11-10 20:30:34 +01002647 if (!bss)
2648 return -ENOMEM;
2649
Johannes Berg5b112d32013-02-01 01:49:58 +01002650 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002651
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002652 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002653}
2654
Roland Vossen6f09be02011-10-18 14:03:02 +02002655static struct brcmf_bss_info_le *
2656next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2657{
2658 if (bss == NULL)
2659 return list->bss_info_le;
2660 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2661 le32_to_cpu(bss->length));
2662}
2663
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002664static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002665{
2666 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002667 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002668 s32 err = 0;
2669 int i;
2670
Hante Meulemanef8596e2014-09-30 10:23:13 +02002671 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002672 if (bss_list->count != 0 &&
2673 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002674 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2675 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002676 return -EOPNOTSUPP;
2677 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002678 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002679 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002680 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002681 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002682 if (err)
2683 break;
2684 }
2685 return err;
2686}
2687
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002688static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02002689 struct net_device *ndev, const u8 *bssid)
2690{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002691 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002692 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002693 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002694 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002695 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002696 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002697 u8 *buf = NULL;
2698 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002699 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002700 u16 notify_capability;
2701 u16 notify_interval;
2702 u8 *notify_ie;
2703 size_t notify_ielen;
2704 s32 notify_signal;
2705
Arend van Sprield96b8012012-12-05 15:26:02 +01002706 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002707
2708 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2709 if (buf == NULL) {
2710 err = -ENOMEM;
2711 goto CleanUp;
2712 }
2713
2714 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2715
Arend van Sprielac24be62012-10-22 10:36:23 -07002716 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2717 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002718 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002719 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002720 goto CleanUp;
2721 }
2722
Roland Vossend34bf642011-10-18 14:03:01 +02002723 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002724
Franky Lin83cf17a2013-04-11 13:28:50 +02002725 ch.chspec = le16_to_cpu(bi->chanspec);
2726 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002727
Franky Lin83cf17a2013-04-11 13:28:50 +02002728 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002729 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2730 else
2731 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2732
Franky Lin83cf17a2013-04-11 13:28:50 +02002733 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002734 notify_channel = ieee80211_get_channel(wiphy, freq);
2735
Arend van Spriel5b435de2011-10-05 13:19:03 +02002736 notify_capability = le16_to_cpu(bi->capability);
2737 notify_interval = le16_to_cpu(bi->beacon_period);
2738 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2739 notify_ielen = le32_to_cpu(bi->ie_length);
2740 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2741
Franky Lin83cf17a2013-04-11 13:28:50 +02002742 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002743 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2744 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2745 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002746
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002747 bss = cfg80211_inform_bss(wiphy, notify_channel,
2748 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2749 notify_capability, notify_interval,
2750 notify_ie, notify_ielen, notify_signal,
2751 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002752
Franky Line78946e2011-11-10 20:30:34 +01002753 if (!bss) {
2754 err = -ENOMEM;
2755 goto CleanUp;
2756 }
2757
Johannes Berg5b112d32013-02-01 01:49:58 +01002758 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002759
Arend van Spriel5b435de2011-10-05 13:19:03 +02002760CleanUp:
2761
2762 kfree(buf);
2763
Arend van Sprield96b8012012-12-05 15:26:02 +01002764 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002765
2766 return err;
2767}
2768
Hante Meuleman89286dc2013-02-08 15:53:46 +01002769static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2770 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002771{
Roland Vossend34bf642011-10-18 14:03:01 +02002772 struct brcmf_bss_info_le *bi;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002773 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002774 u16 beacon_interval;
2775 u8 dtim_period;
2776 size_t ie_len;
2777 u8 *ie;
2778 s32 err = 0;
2779
Arend van Sprield96b8012012-12-05 15:26:02 +01002780 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002781 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002782 return err;
2783
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002784 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002785 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002786 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002787 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002788 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002789 goto update_bss_info_out;
2790 }
2791
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002792 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2793 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002794 if (err)
2795 goto update_bss_info_out;
2796
2797 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2798 ie_len = le32_to_cpu(bi->ie_length);
2799 beacon_interval = le16_to_cpu(bi->beacon_period);
2800
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002801 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002802 if (tim)
2803 dtim_period = tim->data[1];
2804 else {
2805 /*
2806 * active scan was done so we could not get dtim
2807 * information out of probe response.
2808 * so we speficially query dtim information to dongle.
2809 */
2810 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002811 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002812 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002813 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002814 goto update_bss_info_out;
2815 }
2816 dtim_period = (u8)var;
2817 }
2818
Arend van Spriel5b435de2011-10-05 13:19:03 +02002819update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01002820 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002821 return err;
2822}
2823
Hante Meuleman18e2f612013-02-08 15:53:49 +01002824void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002825{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002826 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002827
Arend van Sprielc1179032012-10-22 13:55:33 -07002828 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Hante Meulemanf07998952012-11-05 16:22:13 -08002829 if (cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02002830 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002831 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02002832 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002833 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2834 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002835}
2836
Hante Meulemane756af52012-09-11 21:18:52 +02002837static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2838{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002839 struct brcmf_cfg80211_info *cfg =
2840 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02002841 escan_timeout_work);
2842
Hante Meulemanef8596e2014-09-30 10:23:13 +02002843 brcmf_inform_bss(cfg);
Arend van Spriela0f472a2013-04-05 10:57:49 +02002844 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02002845}
2846
2847static void brcmf_escan_timeout(unsigned long data)
2848{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002849 struct brcmf_cfg80211_info *cfg =
2850 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02002851
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002852 if (cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002853 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08002854 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02002855 }
2856}
2857
2858static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02002859brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2860 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02002861 struct brcmf_bss_info_le *bss_info_le)
2862{
Franky Lin83cf17a2013-04-11 13:28:50 +02002863 struct brcmu_chan ch_bss, ch_bss_info_le;
2864
2865 ch_bss.chspec = le16_to_cpu(bss->chanspec);
2866 cfg->d11inf.decchspec(&ch_bss);
2867 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
2868 cfg->d11inf.decchspec(&ch_bss_info_le);
2869
Hante Meulemane756af52012-09-11 21:18:52 +02002870 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02002871 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02002872 bss_info_le->SSID_len == bss->SSID_len &&
2873 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002874 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
2875 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02002876 s16 bss_rssi = le16_to_cpu(bss->RSSI);
2877 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
2878
Hante Meulemane756af52012-09-11 21:18:52 +02002879 /* preserve max RSSI if the measurements are
2880 * both on-channel or both off-channel
2881 */
Arend van Spriel029591f2012-09-19 22:21:06 +02002882 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02002883 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002884 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
2885 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02002886 /* preserve the on-channel rssi measurement
2887 * if the new measurement is off channel
2888 */
2889 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002890 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02002891 }
2892 return 1;
2893 }
2894 return 0;
2895}
2896
2897static s32
Arend van Spriel19937322012-11-05 16:22:32 -08002898brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02002899 const struct brcmf_event_msg *e, void *data)
2900{
Arend van Spriel19937322012-11-05 16:22:32 -08002901 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02002902 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02002903 struct brcmf_escan_result_le *escan_result_le;
2904 struct brcmf_bss_info_le *bss_info_le;
2905 struct brcmf_bss_info_le *bss = NULL;
2906 u32 bi_length;
2907 struct brcmf_scan_results *list;
2908 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002909 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02002910
Arend van Spriel5c36b992012-11-14 18:46:05 -08002911 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02002912
Arend van Spriela0f472a2013-04-05 10:57:49 +02002913 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Hante Meuleman37a869e2015-10-29 20:33:17 +01002914 brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx);
Hante Meulemane756af52012-09-11 21:18:52 +02002915 return -EPERM;
2916 }
2917
2918 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002919 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002920 escan_result_le = (struct brcmf_escan_result_le *) data;
2921 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002922 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002923 goto exit;
2924 }
Hante Meulemane756af52012-09-11 21:18:52 +02002925 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002926 brcmf_err("Invalid bss_count %d: ignoring\n",
2927 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02002928 goto exit;
2929 }
2930 bss_info_le = &escan_result_le->bss_info_le;
2931
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002932 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
2933 goto exit;
2934
2935 if (!cfg->scan_request) {
2936 brcmf_dbg(SCAN, "result without cfg80211 request\n");
2937 goto exit;
2938 }
2939
Hante Meulemane756af52012-09-11 21:18:52 +02002940 bi_length = le32_to_cpu(bss_info_le->length);
2941 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
2942 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002943 brcmf_err("Invalid bss_info length %d: ignoring\n",
2944 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02002945 goto exit;
2946 }
2947
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002948 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02002949 BIT(NL80211_IFTYPE_ADHOC))) {
2950 if (le16_to_cpu(bss_info_le->capability) &
2951 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002952 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002953 goto exit;
2954 }
2955 }
2956
2957 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002958 cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02002959 if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002960 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002961 goto exit;
2962 }
2963
2964 for (i = 0; i < list->count; i++) {
2965 bss = bss ? (struct brcmf_bss_info_le *)
2966 ((unsigned char *)bss +
2967 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02002968 if (brcmf_compare_update_same_bss(cfg, bss,
2969 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02002970 goto exit;
2971 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002972 memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
Hante Meulemane756af52012-09-11 21:18:52 +02002973 bss_info_le, bi_length);
2974 list->version = le32_to_cpu(bss_info_le->version);
2975 list->buflen += bi_length;
2976 list->count++;
2977 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002978 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002979 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
2980 goto exit;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002981 if (cfg->scan_request) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002982 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002983 aborted = status != BRCMF_E_STATUS_SUCCESS;
Hante Meulemanef8596e2014-09-30 10:23:13 +02002984 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
Hante Meulemane756af52012-09-11 21:18:52 +02002985 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002986 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
2987 status);
Hante Meulemane756af52012-09-11 21:18:52 +02002988 }
2989exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002990 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02002991}
2992
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002993static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02002994{
Arend van Spriel5c36b992012-11-14 18:46:05 -08002995 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
2996 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08002997 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
2998 /* Init scan_timeout timer */
2999 init_timer(&cfg->escan_timeout);
3000 cfg->escan_timeout.data = (unsigned long) cfg;
3001 cfg->escan_timeout.function = brcmf_escan_timeout;
3002 INIT_WORK(&cfg->escan_timeout_work,
3003 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02003004}
3005
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05003006static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003007{
3008 if (ms < 1000 / HZ) {
3009 cond_resched();
3010 mdelay(ms);
3011 } else {
3012 msleep(ms);
3013 }
3014}
3015
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003016static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
3017 u8 *pattern, u32 patternsize, u8 *mask,
3018 u32 packet_offset)
3019{
3020 struct brcmf_fil_wowl_pattern_le *filter;
3021 u32 masksize;
3022 u32 patternoffset;
3023 u8 *buf;
3024 u32 bufsize;
3025 s32 ret;
3026
3027 masksize = (patternsize + 7) / 8;
3028 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
3029
3030 bufsize = sizeof(*filter) + patternsize + masksize;
3031 buf = kzalloc(bufsize, GFP_KERNEL);
3032 if (!buf)
3033 return -ENOMEM;
3034 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
3035
3036 memcpy(filter->cmd, cmd, 4);
3037 filter->masksize = cpu_to_le32(masksize);
3038 filter->offset = cpu_to_le32(packet_offset);
3039 filter->patternoffset = cpu_to_le32(patternoffset);
3040 filter->patternsize = cpu_to_le32(patternsize);
3041 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
3042
3043 if ((mask) && (masksize))
3044 memcpy(buf + sizeof(*filter), mask, masksize);
3045 if ((pattern) && (patternsize))
3046 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
3047
3048 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
3049
3050 kfree(buf);
3051 return ret;
3052}
3053
Hante Meulemanaeb64222015-10-29 20:33:19 +01003054#ifdef CONFIG_PM
3055
3056static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3057{
3058 struct brcmf_wowl_wakeind_le wake_ind_le;
3059 struct cfg80211_wowlan_wakeup wakeup_data;
3060 struct cfg80211_wowlan_wakeup *wakeup;
3061 u32 wakeind;
3062 s32 err;
3063
3064 err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
3065 sizeof(wake_ind_le));
3066 if (!err) {
3067 brcmf_err("Get wowl_wakeind failed, err = %d\n", err);
3068 return;
3069 }
3070
3071 wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
3072 if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
3073 BRCMF_WOWL_RETR | BRCMF_WOWL_NET)) {
3074 wakeup = &wakeup_data;
3075 memset(&wakeup_data, 0, sizeof(wakeup_data));
3076 wakeup_data.pattern_idx = -1;
3077
3078 if (wakeind & BRCMF_WOWL_MAGIC) {
3079 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
3080 wakeup_data.magic_pkt = true;
3081 }
3082 if (wakeind & BRCMF_WOWL_DIS) {
3083 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
3084 wakeup_data.disconnect = true;
3085 }
3086 if (wakeind & BRCMF_WOWL_BCN) {
3087 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
3088 wakeup_data.disconnect = true;
3089 }
3090 if (wakeind & BRCMF_WOWL_RETR) {
3091 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
3092 wakeup_data.disconnect = true;
3093 }
3094 if (wakeind & BRCMF_WOWL_NET) {
3095 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
3096 /* For now always map to pattern 0, no API to get
3097 * correct information available at the moment.
3098 */
3099 wakeup_data.pattern_idx = 0;
3100 }
3101 } else {
3102 wakeup = NULL;
3103 }
3104 cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
3105}
3106
3107#else
3108
3109static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3110{
3111}
3112
3113#endif /* CONFIG_PM */
3114
Arend van Spriel5b435de2011-10-05 13:19:03 +02003115static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
3116{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003117 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3118 struct net_device *ndev = cfg_to_ndev(cfg);
3119 struct brcmf_if *ifp = netdev_priv(ndev);
3120
Arend van Sprield96b8012012-12-05 15:26:02 +01003121 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003122
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003123 if (cfg->wowl_enabled) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003124 brcmf_report_wowl_wakeind(wiphy, ifp);
3125 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
3126 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003127 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003128 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
3129 cfg->pre_wowl_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003130 cfg->wowl_enabled = false;
3131 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003132 return 0;
3133}
3134
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003135static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
3136 struct brcmf_if *ifp,
3137 struct cfg80211_wowlan *wowl)
3138{
3139 u32 wowl_config;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003140 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003141
3142 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
3143
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003144 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003145 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode);
3146 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
3147
3148 wowl_config = 0;
3149 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003150 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003151 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003152 wowl_config |= BRCMF_WOWL_MAGIC;
3153 if ((wowl->patterns) && (wowl->n_patterns)) {
3154 wowl_config |= BRCMF_WOWL_NET;
3155 for (i = 0; i < wowl->n_patterns; i++) {
3156 brcmf_config_wowl_pattern(ifp, "add",
3157 (u8 *)wowl->patterns[i].pattern,
3158 wowl->patterns[i].pattern_len,
3159 (u8 *)wowl->patterns[i].mask,
3160 wowl->patterns[i].pkt_offset);
3161 }
3162 }
Hante Meulemanaeb64222015-10-29 20:33:19 +01003163 brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", "clear", strlen("clear"));
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003164 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
3165 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
3166 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
3167 cfg->wowl_enabled = true;
3168}
3169
Arend van Spriel5b435de2011-10-05 13:19:03 +02003170static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003171 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003172{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003173 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3174 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003175 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07003176 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003177
Arend van Sprield96b8012012-12-05 15:26:02 +01003178 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003179
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003180 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07003181 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02003182 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003183 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07003184 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003185
Arend van Spriel7d641072012-10-22 13:55:39 -07003186 /* end any scanning */
3187 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003188 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003189
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003190 if (wowl == NULL) {
3191 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
3192 list_for_each_entry(vif, &cfg->vif_list, list) {
3193 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
3194 continue;
3195 /* While going to suspend if associated with AP
3196 * disassociate from AP to save power while system is
3197 * in suspended state
3198 */
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01003199 brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003200 /* Make sure WPA_Supplicant receives all the event
3201 * generated due to DISASSOC call to the fw to keep
3202 * the state fw and WPA_Supplicant state consistent
3203 */
3204 brcmf_delay(500);
3205 }
3206 /* Configure MPC */
3207 brcmf_set_mpc(ifp, 1);
3208
3209 } else {
3210 /* Configure WOWL paramaters */
3211 brcmf_configure_wowl(cfg, ifp, wowl);
3212 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003213
Arend van Spriel7d641072012-10-22 13:55:39 -07003214exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01003215 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07003216 /* clear any scanning activity */
3217 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003218 return 0;
3219}
3220
3221static __used s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02003222brcmf_update_pmklist(struct net_device *ndev,
3223 struct brcmf_cfg80211_pmk_list *pmk_list, s32 err)
3224{
3225 int i, j;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003226 u32 pmkid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003227
Arend van Spriel40c8e952011-10-12 20:51:20 +02003228 pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid);
3229
Arend van Spriel16886732012-12-05 15:26:04 +01003230 brcmf_dbg(CONN, "No of elements %d\n", pmkid_len);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003231 for (i = 0; i < pmkid_len; i++) {
Arend van Spriel16886732012-12-05 15:26:04 +01003232 brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i,
3233 &pmk_list->pmkids.pmkid[i].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003234 for (j = 0; j < WLAN_PMKID_LEN; j++)
Arend van Spriel16886732012-12-05 15:26:04 +01003235 brcmf_dbg(CONN, "%02x\n",
3236 pmk_list->pmkids.pmkid[i].PMKID[j]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003237 }
3238
3239 if (!err)
Arend van Sprielac24be62012-10-22 10:36:23 -07003240 brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info",
3241 (char *)pmk_list, sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02003242
3243 return err;
3244}
3245
3246static s32
3247brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3248 struct cfg80211_pmksa *pmksa)
3249{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003250 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003251 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003252 struct pmkid_list *pmkids = &cfg->pmk_list->pmkids;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003253 s32 err = 0;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003254 u32 pmkid_len, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003255
Arend van Sprield96b8012012-12-05 15:26:02 +01003256 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003257 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003258 return -EIO;
3259
Arend van Spriel40c8e952011-10-12 20:51:20 +02003260 pmkid_len = le32_to_cpu(pmkids->npmkid);
3261 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003262 if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN))
3263 break;
3264 if (i < WL_NUM_PMKIDS_MAX) {
3265 memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN);
3266 memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003267 if (i == pmkid_len) {
3268 pmkid_len++;
3269 pmkids->npmkid = cpu_to_le32(pmkid_len);
3270 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003271 } else
3272 err = -EINVAL;
3273
Arend van Spriel16886732012-12-05 15:26:04 +01003274 brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
3275 pmkids->pmkid[pmkid_len].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003276 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01003277 brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003278
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003279 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003280
Arend van Sprield96b8012012-12-05 15:26:02 +01003281 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003282 return err;
3283}
3284
3285static s32
3286brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3287 struct cfg80211_pmksa *pmksa)
3288{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003289 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003290 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003291 struct pmkid_list pmkid;
3292 s32 err = 0;
Arend van Sprielc15d7892014-11-20 22:26:59 +01003293 u32 pmkid_len, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003294
Arend van Sprield96b8012012-12-05 15:26:02 +01003295 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003296 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003297 return -EIO;
3298
3299 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
3300 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
3301
Arend van Spriel16886732012-12-05 15:26:04 +01003302 brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3303 &pmkid.pmkid[0].BSSID);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003304 for (i = 0; i < WLAN_PMKID_LEN; i++)
Arend van Spriel16886732012-12-05 15:26:04 +01003305 brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003306
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003307 pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003308 for (i = 0; i < pmkid_len; i++)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003309 if (!memcmp
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003310 (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003311 ETH_ALEN))
3312 break;
3313
Arend van Spriel40c8e952011-10-12 20:51:20 +02003314 if ((pmkid_len > 0)
3315 && (i < pmkid_len)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003316 memset(&cfg->pmk_list->pmkids.pmkid[i], 0,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003317 sizeof(struct pmkid));
Arend van Spriel40c8e952011-10-12 20:51:20 +02003318 for (; i < (pmkid_len - 1); i++) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003319 memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID,
3320 &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003321 ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003322 memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID,
3323 &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003324 WLAN_PMKID_LEN);
3325 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003326 cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003327 } else
3328 err = -EINVAL;
3329
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003330 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003331
Arend van Sprield96b8012012-12-05 15:26:02 +01003332 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003333 return err;
3334
3335}
3336
3337static s32
3338brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3339{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003340 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003341 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003342 s32 err = 0;
3343
Arend van Sprield96b8012012-12-05 15:26:02 +01003344 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003345 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003346 return -EIO;
3347
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003348 memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list));
3349 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003350
Arend van Sprield96b8012012-12-05 15:26:02 +01003351 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003352 return err;
3353
3354}
3355
Arend van Spriele5806072012-09-19 22:21:08 +02003356/*
3357 * PFN result doesn't have all the info which are
3358 * required by the supplicant
3359 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3360 * via wl_inform_single_bss in the required format. Escan does require the
3361 * scan request in the form of cfg80211_scan_request. For timebeing, create
3362 * cfg80211_scan_request one out of the received PNO event.
3363 */
3364static s32
Arend van Spriel19937322012-11-05 16:22:32 -08003365brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
Arend van Spriele5806072012-09-19 22:21:08 +02003366 const struct brcmf_event_msg *e, void *data)
3367{
Arend van Spriel19937322012-11-05 16:22:32 -08003368 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriele5806072012-09-19 22:21:08 +02003369 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3370 struct cfg80211_scan_request *request = NULL;
3371 struct cfg80211_ssid *ssid = NULL;
3372 struct ieee80211_channel *channel = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003373 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003374 int err = 0;
3375 int channel_req = 0;
3376 int band = 0;
3377 struct brcmf_pno_scanresults_le *pfn_result;
3378 u32 result_count;
3379 u32 status;
3380
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003381 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003382
Arend van Spriel5c36b992012-11-14 18:46:05 -08003383 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003384 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003385 return 0;
3386 }
3387
3388 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3389 result_count = le32_to_cpu(pfn_result->count);
3390 status = le32_to_cpu(pfn_result->status);
3391
3392 /*
3393 * PFN event is limited to fit 512 bytes so we may get
3394 * multiple NET_FOUND events. For now place a warning here.
3395 */
3396 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003397 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
Arend van Spriele5806072012-09-19 22:21:08 +02003398 if (result_count > 0) {
3399 int i;
3400
3401 request = kzalloc(sizeof(*request), GFP_KERNEL);
Dan Carpenter58901d12012-09-26 10:21:48 +03003402 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3403 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
Arend van Spriele5806072012-09-19 22:21:08 +02003404 if (!request || !ssid || !channel) {
3405 err = -ENOMEM;
3406 goto out_err;
3407 }
3408
3409 request->wiphy = wiphy;
3410 data += sizeof(struct brcmf_pno_scanresults_le);
3411 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3412
3413 for (i = 0; i < result_count; i++) {
3414 netinfo = &netinfo_start[i];
3415 if (!netinfo) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003416 brcmf_err("Invalid netinfo ptr. index: %d\n",
3417 i);
Arend van Spriele5806072012-09-19 22:21:08 +02003418 err = -EINVAL;
3419 goto out_err;
3420 }
3421
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003422 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3423 netinfo->SSID, netinfo->channel);
Arend van Spriele5806072012-09-19 22:21:08 +02003424 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3425 ssid[i].ssid_len = netinfo->SSID_len;
3426 request->n_ssids++;
3427
3428 channel_req = netinfo->channel;
3429 if (channel_req <= CH_MAX_2G_CHANNEL)
3430 band = NL80211_BAND_2GHZ;
3431 else
3432 band = NL80211_BAND_5GHZ;
3433 channel[i].center_freq =
3434 ieee80211_channel_to_frequency(channel_req,
3435 band);
3436 channel[i].band = band;
3437 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3438 request->channels[i] = &channel[i];
3439 request->n_channels++;
3440 }
3441
3442 /* assign parsed ssid array */
3443 if (request->n_ssids)
3444 request->ssids = &ssid[0];
3445
Arend van Sprielc1179032012-10-22 13:55:33 -07003446 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriele5806072012-09-19 22:21:08 +02003447 /* Abort any on-going scan */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003448 brcmf_abort_scanning(cfg);
Arend van Spriele5806072012-09-19 22:21:08 +02003449 }
3450
Arend van Sprielc1179032012-10-22 13:55:33 -07003451 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel2668b0b2014-01-13 22:20:28 +01003452 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02003453 err = brcmf_do_escan(cfg, wiphy, ifp, request);
Arend van Spriele5806072012-09-19 22:21:08 +02003454 if (err) {
Arend van Sprielc1179032012-10-22 13:55:33 -07003455 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003456 goto out_err;
3457 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003458 cfg->sched_escan = true;
3459 cfg->scan_request = request;
Arend van Spriele5806072012-09-19 22:21:08 +02003460 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003461 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003462 goto out_err;
3463 }
3464
3465 kfree(ssid);
3466 kfree(channel);
3467 kfree(request);
3468 return 0;
3469
3470out_err:
3471 kfree(ssid);
3472 kfree(channel);
3473 kfree(request);
3474 cfg80211_sched_scan_stopped(wiphy);
3475 return err;
3476}
3477
Arend van Spriele5806072012-09-19 22:21:08 +02003478static int brcmf_dev_pno_clean(struct net_device *ndev)
3479{
Arend van Spriele5806072012-09-19 22:21:08 +02003480 int ret;
3481
3482 /* Disable pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003483 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003484 if (ret == 0) {
3485 /* clear pfn */
Arend van Sprielac24be62012-10-22 10:36:23 -07003486 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3487 NULL, 0);
Arend van Spriele5806072012-09-19 22:21:08 +02003488 }
3489 if (ret < 0)
Arend van Spriel57d6e912012-12-05 15:26:00 +01003490 brcmf_err("failed code %d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003491
3492 return ret;
3493}
3494
3495static int brcmf_dev_pno_config(struct net_device *ndev)
3496{
3497 struct brcmf_pno_param_le pfn_param;
Arend van Spriele5806072012-09-19 22:21:08 +02003498
3499 memset(&pfn_param, 0, sizeof(pfn_param));
3500 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3501
3502 /* set extra pno params */
3503 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3504 pfn_param.repeat = BRCMF_PNO_REPEAT;
3505 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3506
3507 /* set up pno scan fr */
3508 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3509
Arend van Sprielac24be62012-10-22 10:36:23 -07003510 return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set",
3511 &pfn_param, sizeof(pfn_param));
Arend van Spriele5806072012-09-19 22:21:08 +02003512}
3513
3514static int
3515brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3516 struct net_device *ndev,
3517 struct cfg80211_sched_scan_request *request)
3518{
Arend van Sprielc1179032012-10-22 13:55:33 -07003519 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003520 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003521 struct brcmf_pno_net_param_le pfn;
3522 int i;
3523 int ret = 0;
3524
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003525 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003526 request->n_match_sets, request->n_ssids);
Arend van Sprielc1179032012-10-22 13:55:33 -07003527 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003528 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Arend van Spriele5806072012-09-19 22:21:08 +02003529 return -EAGAIN;
3530 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02003531 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3532 brcmf_err("Scanning suppressed: status (%lu)\n",
3533 cfg->scan_status);
3534 return -EAGAIN;
3535 }
Arend van Spriele5806072012-09-19 22:21:08 +02003536
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003537 if (!request->n_ssids || !request->n_match_sets) {
Arend van Spriel181f2d12014-05-27 12:56:13 +02003538 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
Arend van Sprieldc7bdbf2013-03-03 12:45:25 +01003539 request->n_ssids);
Arend van Spriele5806072012-09-19 22:21:08 +02003540 return -EINVAL;
3541 }
3542
3543 if (request->n_ssids > 0) {
3544 for (i = 0; i < request->n_ssids; i++) {
3545 /* Active scan req for ssids */
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003546 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3547 request->ssids[i].ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003548
3549 /*
3550 * match_set ssids is a supert set of n_ssid list,
3551 * so we need not add these set seperately.
3552 */
3553 }
3554 }
3555
3556 if (request->n_match_sets > 0) {
3557 /* clean up everything */
3558 ret = brcmf_dev_pno_clean(ndev);
3559 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003560 brcmf_err("failed error=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003561 return ret;
3562 }
3563
3564 /* configure pno */
3565 ret = brcmf_dev_pno_config(ndev);
3566 if (ret < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003567 brcmf_err("PNO setup failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003568 return -EINVAL;
3569 }
3570
3571 /* configure each match set */
3572 for (i = 0; i < request->n_match_sets; i++) {
3573 struct cfg80211_ssid *ssid;
3574 u32 ssid_len;
3575
3576 ssid = &request->match_sets[i].ssid;
3577 ssid_len = ssid->ssid_len;
3578
3579 if (!ssid_len) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003580 brcmf_err("skip broadcast ssid\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003581 continue;
3582 }
3583 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3584 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3585 pfn.wsec = cpu_to_le32(0);
3586 pfn.infra = cpu_to_le32(1);
3587 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3588 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3589 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
Arend van Sprielc1179032012-10-22 13:55:33 -07003590 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
Arend van Sprielac24be62012-10-22 10:36:23 -07003591 sizeof(pfn));
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003592 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3593 ret == 0 ? "set" : "failed", ssid->ssid);
Arend van Spriele5806072012-09-19 22:21:08 +02003594 }
3595 /* Enable the PNO */
Arend van Sprielc1179032012-10-22 13:55:33 -07003596 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003597 brcmf_err("PNO enable failed!! ret=%d\n", ret);
Arend van Spriele5806072012-09-19 22:21:08 +02003598 return -EINVAL;
3599 }
3600 } else {
3601 return -EINVAL;
3602 }
3603
3604 return 0;
3605}
3606
3607static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3608 struct net_device *ndev)
3609{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003610 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriele5806072012-09-19 22:21:08 +02003611
Arend van Spriel4e8a0082012-12-05 15:26:03 +01003612 brcmf_dbg(SCAN, "enter\n");
Arend van Spriele5806072012-09-19 22:21:08 +02003613 brcmf_dev_pno_clean(ndev);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003614 if (cfg->sched_escan)
Arend van Spriela0f472a2013-04-05 10:57:49 +02003615 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
Arend van Spriele5806072012-09-19 22:21:08 +02003616 return 0;
3617}
Arend van Spriele5806072012-09-19 22:21:08 +02003618
Hante Meuleman1f170112013-02-06 18:40:38 +01003619static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003620{
3621 s32 err;
3622
3623 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003624 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003625 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003626 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003627 return err;
3628 }
3629 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003630 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003631 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003632 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003633 return err;
3634 }
3635 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003636 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003637 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003638 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003639 return err;
3640 }
3641
3642 return 0;
3643}
3644
3645static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3646{
3647 if (is_rsn_ie)
3648 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3649
3650 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3651}
3652
3653static s32
Hante Meulemana44aa402014-12-03 21:05:33 +01003654brcmf_configure_wpaie(struct brcmf_if *ifp,
Johannes Berg4b5800f2014-01-15 14:55:59 +01003655 const struct brcmf_vs_tlv *wpa_ie,
3656 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003657{
3658 u32 auth = 0; /* d11 open authentication */
3659 u16 count;
3660 s32 err = 0;
3661 s32 len = 0;
3662 u32 i;
3663 u32 wsec;
3664 u32 pval = 0;
3665 u32 gval = 0;
3666 u32 wpa_auth = 0;
3667 u32 offset;
3668 u8 *data;
3669 u16 rsn_cap;
3670 u32 wme_bss_disable;
3671
Arend van Sprield96b8012012-12-05 15:26:02 +01003672 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003673 if (wpa_ie == NULL)
3674 goto exit;
3675
3676 len = wpa_ie->len + TLV_HDR_LEN;
3677 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003678 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003679 if (!is_rsn_ie)
3680 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003681 else
3682 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003683
3684 /* check for multicast cipher suite */
3685 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3686 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003687 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003688 goto exit;
3689 }
3690
3691 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3692 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003693 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003694 goto exit;
3695 }
3696 offset += TLV_OUI_LEN;
3697
3698 /* pick up multicast cipher */
3699 switch (data[offset]) {
3700 case WPA_CIPHER_NONE:
3701 gval = 0;
3702 break;
3703 case WPA_CIPHER_WEP_40:
3704 case WPA_CIPHER_WEP_104:
3705 gval = WEP_ENABLED;
3706 break;
3707 case WPA_CIPHER_TKIP:
3708 gval = TKIP_ENABLED;
3709 break;
3710 case WPA_CIPHER_AES_CCM:
3711 gval = AES_ENABLED;
3712 break;
3713 default:
3714 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003715 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003716 goto exit;
3717 }
3718
3719 offset++;
3720 /* walk thru unicast cipher list and pick up what we recognize */
3721 count = data[offset] + (data[offset + 1] << 8);
3722 offset += WPA_IE_SUITE_COUNT_LEN;
3723 /* Check for unicast suite(s) */
3724 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3725 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003726 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003727 goto exit;
3728 }
3729 for (i = 0; i < count; i++) {
3730 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3731 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003732 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003733 goto exit;
3734 }
3735 offset += TLV_OUI_LEN;
3736 switch (data[offset]) {
3737 case WPA_CIPHER_NONE:
3738 break;
3739 case WPA_CIPHER_WEP_40:
3740 case WPA_CIPHER_WEP_104:
3741 pval |= WEP_ENABLED;
3742 break;
3743 case WPA_CIPHER_TKIP:
3744 pval |= TKIP_ENABLED;
3745 break;
3746 case WPA_CIPHER_AES_CCM:
3747 pval |= AES_ENABLED;
3748 break;
3749 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003750 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003751 }
3752 offset++;
3753 }
3754 /* walk thru auth management suite list and pick up what we recognize */
3755 count = data[offset] + (data[offset + 1] << 8);
3756 offset += WPA_IE_SUITE_COUNT_LEN;
3757 /* Check for auth key management suite(s) */
3758 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3759 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003760 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003761 goto exit;
3762 }
3763 for (i = 0; i < count; i++) {
3764 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3765 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003766 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003767 goto exit;
3768 }
3769 offset += TLV_OUI_LEN;
3770 switch (data[offset]) {
3771 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003772 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003773 wpa_auth |= WPA_AUTH_NONE;
3774 break;
3775 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003776 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003777 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3778 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3779 break;
3780 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01003781 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003782 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3783 (wpa_auth |= WPA_AUTH_PSK);
3784 break;
3785 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003786 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003787 }
3788 offset++;
3789 }
3790
3791 if (is_rsn_ie) {
3792 wme_bss_disable = 1;
3793 if ((offset + RSN_CAP_LEN) <= len) {
3794 rsn_cap = data[offset] + (data[offset + 1] << 8);
3795 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3796 wme_bss_disable = 0;
3797 }
3798 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07003799 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003800 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02003801 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003802 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003803 goto exit;
3804 }
3805 }
3806 /* FOR WPS , set SES_OW_ENABLED */
3807 wsec = (pval | gval | SES_OW_ENABLED);
3808
3809 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003810 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003811 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003812 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003813 goto exit;
3814 }
3815 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003816 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02003817 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003818 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003819 goto exit;
3820 }
3821 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003822 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003823 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003824 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003825 goto exit;
3826 }
3827
3828exit:
3829 return err;
3830}
3831
3832static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08003833brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02003834 struct parsed_vndr_ies *vndr_ies)
3835{
Hante Meuleman1a873342012-09-27 14:17:54 +02003836 struct brcmf_vs_tlv *vndrie;
3837 struct brcmf_tlv *ie;
3838 struct parsed_vndr_ie_info *parsed_info;
3839 s32 remaining_len;
3840
3841 remaining_len = (s32)vndr_ie_len;
3842 memset(vndr_ies, 0, sizeof(*vndr_ies));
3843
3844 ie = (struct brcmf_tlv *)vndr_ie_buf;
3845 while (ie) {
3846 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
3847 goto next;
3848 vndrie = (struct brcmf_vs_tlv *)ie;
3849 /* len should be bigger than OUI length + one */
3850 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003851 brcmf_err("invalid vndr ie. length is too small %d\n",
3852 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02003853 goto next;
3854 }
3855 /* if wpa or wme ie, do not add ie */
3856 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
3857 ((vndrie->oui_type == WPA_OUI_TYPE) ||
3858 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003859 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003860 goto next;
3861 }
3862
3863 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
3864
3865 /* save vndr ie information */
3866 parsed_info->ie_ptr = (char *)vndrie;
3867 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
3868 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
3869
3870 vndr_ies->count++;
3871
Arend van Sprield96b8012012-12-05 15:26:02 +01003872 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
3873 parsed_info->vndrie.oui[0],
3874 parsed_info->vndrie.oui[1],
3875 parsed_info->vndrie.oui[2],
3876 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02003877
Arend van Spriel9f440b72013-02-08 15:53:36 +01003878 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02003879 break;
3880next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003881 remaining_len -= (ie->len + TLV_HDR_LEN);
3882 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02003883 ie = NULL;
3884 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003885 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
3886 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02003887 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003888 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02003889}
3890
3891static u32
3892brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
3893{
3894
Hante Meuleman1a873342012-09-27 14:17:54 +02003895 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
3896 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
3897
Vaishali Thakkar362126c2015-01-16 21:36:14 +05303898 put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003899
Vaishali Thakkar362126c2015-01-16 21:36:14 +05303900 put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02003901
3902 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
3903
3904 return ie_len + VNDR_IE_HDR_SIZE;
3905}
3906
Arend van Spriel1332e262012-11-05 16:22:18 -08003907s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
3908 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02003909{
Arend van Spriel1332e262012-11-05 16:22:18 -08003910 struct brcmf_if *ifp;
3911 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02003912 s32 err = 0;
3913 u8 *iovar_ie_buf;
3914 u8 *curr_ie_buf;
3915 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003916 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07003917 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003918 u32 del_add_ie_buf_len = 0;
3919 u32 total_ie_buf_len = 0;
3920 u32 parsed_ie_buf_len = 0;
3921 struct parsed_vndr_ies old_vndr_ies;
3922 struct parsed_vndr_ies new_vndr_ies;
3923 struct parsed_vndr_ie_info *vndrie_info;
3924 s32 i;
3925 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07003926 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02003927
Arend van Spriel1332e262012-11-05 16:22:18 -08003928 if (!vif)
3929 return -ENODEV;
3930 ifp = vif->ifp;
3931 saved_ie = &vif->saved_ie;
3932
Hante Meuleman37a869e2015-10-29 20:33:17 +01003933 brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
3934 pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02003935 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
3936 if (!iovar_ie_buf)
3937 return -ENOMEM;
3938 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01003939 switch (pktflag) {
3940 case BRCMF_VNDR_IE_PRBREQ_FLAG:
3941 mgmt_ie_buf = saved_ie->probe_req_ie;
3942 mgmt_ie_len = &saved_ie->probe_req_ie_len;
3943 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
3944 break;
3945 case BRCMF_VNDR_IE_PRBRSP_FLAG:
3946 mgmt_ie_buf = saved_ie->probe_res_ie;
3947 mgmt_ie_len = &saved_ie->probe_res_ie_len;
3948 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
3949 break;
3950 case BRCMF_VNDR_IE_BEACON_FLAG:
3951 mgmt_ie_buf = saved_ie->beacon_ie;
3952 mgmt_ie_len = &saved_ie->beacon_ie_len;
3953 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
3954 break;
3955 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
3956 mgmt_ie_buf = saved_ie->assoc_req_ie;
3957 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
3958 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
3959 break;
3960 default:
3961 err = -EPERM;
3962 brcmf_err("not suitable type\n");
3963 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02003964 }
3965
3966 if (vndr_ie_len > mgmt_ie_buf_len) {
3967 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003968 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003969 goto exit;
3970 }
3971
3972 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3973 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
3974 ptr = curr_ie_buf;
3975 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
3976 for (i = 0; i < new_vndr_ies.count; i++) {
3977 vndrie_info = &new_vndr_ies.ie_info[i];
3978 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
3979 vndrie_info->ie_len);
3980 parsed_ie_buf_len += vndrie_info->ie_len;
3981 }
3982 }
3983
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01003984 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02003985 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
3986 (memcmp(mgmt_ie_buf, curr_ie_buf,
3987 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01003988 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003989 goto exit;
3990 }
3991
3992 /* parse old vndr_ie */
3993 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
3994
3995 /* make a command to delete old ie */
3996 for (i = 0; i < old_vndr_ies.count; i++) {
3997 vndrie_info = &old_vndr_ies.ie_info[i];
3998
Arend van Sprield96b8012012-12-05 15:26:02 +01003999 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
4000 vndrie_info->vndrie.id,
4001 vndrie_info->vndrie.len,
4002 vndrie_info->vndrie.oui[0],
4003 vndrie_info->vndrie.oui[1],
4004 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004005
4006 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4007 vndrie_info->ie_ptr,
4008 vndrie_info->ie_len,
4009 "del");
4010 curr_ie_buf += del_add_ie_buf_len;
4011 total_ie_buf_len += del_add_ie_buf_len;
4012 }
4013 }
4014
4015 *mgmt_ie_len = 0;
4016 /* Add if there is any extra IE */
4017 if (mgmt_ie_buf && parsed_ie_buf_len) {
4018 ptr = mgmt_ie_buf;
4019
4020 remained_buf_len = mgmt_ie_buf_len;
4021
4022 /* make a command to add new ie */
4023 for (i = 0; i < new_vndr_ies.count; i++) {
4024 vndrie_info = &new_vndr_ies.ie_info[i];
4025
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004026 /* verify remained buf size before copy data */
4027 if (remained_buf_len < (vndrie_info->vndrie.len +
4028 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004029 brcmf_err("no space in mgmt_ie_buf: len left %d",
4030 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004031 break;
4032 }
4033 remained_buf_len -= (vndrie_info->ie_len +
4034 VNDR_IE_VSIE_OFFSET);
4035
Arend van Sprield96b8012012-12-05 15:26:02 +01004036 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
4037 vndrie_info->vndrie.id,
4038 vndrie_info->vndrie.len,
4039 vndrie_info->vndrie.oui[0],
4040 vndrie_info->vndrie.oui[1],
4041 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004042
4043 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4044 vndrie_info->ie_ptr,
4045 vndrie_info->ie_len,
4046 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02004047
4048 /* save the parsed IE in wl struct */
4049 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
4050 vndrie_info->ie_len);
4051 *mgmt_ie_len += vndrie_info->ie_len;
4052
4053 curr_ie_buf += del_add_ie_buf_len;
4054 total_ie_buf_len += del_add_ie_buf_len;
4055 }
4056 }
4057 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004058 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004059 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004060 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004061 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004062 }
4063
4064exit:
4065 kfree(iovar_ie_buf);
4066 return err;
4067}
4068
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004069s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
4070{
4071 s32 pktflags[] = {
4072 BRCMF_VNDR_IE_PRBREQ_FLAG,
4073 BRCMF_VNDR_IE_PRBRSP_FLAG,
4074 BRCMF_VNDR_IE_BEACON_FLAG
4075 };
4076 int i;
4077
4078 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
4079 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
4080
4081 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
4082 return 0;
4083}
4084
Hante Meuleman1a873342012-09-27 14:17:54 +02004085static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01004086brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
4087 struct cfg80211_beacon_data *beacon)
4088{
4089 s32 err;
4090
4091 /* Set Beacon IEs to FW */
4092 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
4093 beacon->tail, beacon->tail_len);
4094 if (err) {
4095 brcmf_err("Set Beacon IE Failed\n");
4096 return err;
4097 }
4098 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
4099
4100 /* Set Probe Response IEs to FW */
4101 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
4102 beacon->proberesp_ies,
4103 beacon->proberesp_ies_len);
4104 if (err)
4105 brcmf_err("Set Probe Resp IE Failed\n");
4106 else
4107 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
4108
4109 return err;
4110}
4111
4112static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02004113brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
4114 struct cfg80211_ap_settings *settings)
4115{
4116 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02004117 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07004118 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01004119 const struct brcmf_tlv *ssid_ie;
Arend van Spriel98027762014-12-21 12:43:53 +01004120 const struct brcmf_tlv *country_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004121 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02004122 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01004123 const struct brcmf_tlv *rsn_ie;
4124 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004125 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01004126 enum nl80211_iftype dev_role;
4127 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02004128 u16 chanspec;
Hante Meulemana44aa402014-12-03 21:05:33 +01004129 bool mbss;
Arend van Spriel98027762014-12-21 12:43:53 +01004130 int is_11d;
Hante Meuleman1a873342012-09-27 14:17:54 +02004131
Arend van Spriel06c01582014-05-12 10:47:37 +02004132 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
4133 settings->chandef.chan->hw_value,
4134 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02004135 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01004136 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
4137 settings->ssid, settings->ssid_len, settings->auth_type,
4138 settings->inactivity_timeout);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004139 dev_role = ifp->vif->wdev.iftype;
Hante Meulemana44aa402014-12-03 21:05:33 +01004140 mbss = ifp->vif->mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02004141
Arend van Spriel98027762014-12-21 12:43:53 +01004142 /* store current 11d setting */
4143 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d);
4144 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4145 settings->beacon.tail_len,
4146 WLAN_EID_COUNTRY);
4147 is_11d = country_ie ? 1 : 0;
4148
Hante Meuleman1a873342012-09-27 14:17:54 +02004149 memset(&ssid_le, 0, sizeof(ssid_le));
4150 if (settings->ssid == NULL || settings->ssid_len == 0) {
4151 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
4152 ssid_ie = brcmf_parse_tlvs(
4153 (u8 *)&settings->beacon.head[ie_offset],
4154 settings->beacon.head_len - ie_offset,
4155 WLAN_EID_SSID);
4156 if (!ssid_ie)
4157 return -EINVAL;
4158
4159 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
4160 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01004161 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02004162 } else {
4163 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
4164 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
4165 }
4166
Hante Meulemana44aa402014-12-03 21:05:33 +01004167 if (!mbss) {
4168 brcmf_set_mpc(ifp, 0);
4169 brcmf_configure_arp_offload(ifp, false);
4170 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004171
4172 /* find the RSN_IE */
4173 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4174 settings->beacon.tail_len, WLAN_EID_RSN);
4175
4176 /* find the WPA_IE */
4177 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
4178 settings->beacon.tail_len);
4179
Hante Meuleman1a873342012-09-27 14:17:54 +02004180 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004181 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004182 if (wpa_ie != NULL) {
4183 /* WPA IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004184 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02004185 if (err < 0)
4186 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004187 } else {
Hante Meulemana44aa402014-12-03 21:05:33 +01004188 struct brcmf_vs_tlv *tmp_ie;
4189
4190 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
4191
Hante Meuleman1a873342012-09-27 14:17:54 +02004192 /* RSN IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004193 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004194 if (err < 0)
4195 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004196 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004197 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01004198 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01004199 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02004200 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004201
Hante Meulemana0f07952013-02-08 15:53:47 +01004202 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02004203
Hante Meulemana44aa402014-12-03 21:05:33 +01004204 if (!mbss) {
4205 chanspec = chandef_to_chanspec(&cfg->d11inf,
4206 &settings->chandef);
4207 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004208 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004209 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4210 chanspec, err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004211 goto exit;
4212 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004213
Arend van Spriel98027762014-12-21 12:43:53 +01004214 if (is_11d != ifp->vif->is_11d) {
4215 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4216 is_11d);
4217 if (err < 0) {
4218 brcmf_err("Regulatory Set Error, %d\n", err);
4219 goto exit;
4220 }
4221 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004222 if (settings->beacon_interval) {
4223 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
4224 settings->beacon_interval);
4225 if (err < 0) {
4226 brcmf_err("Beacon Interval Set Error, %d\n",
4227 err);
4228 goto exit;
4229 }
4230 }
4231 if (settings->dtim_period) {
4232 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
4233 settings->dtim_period);
4234 if (err < 0) {
4235 brcmf_err("DTIM Interval Set Error, %d\n", err);
4236 goto exit;
4237 }
4238 }
4239
Hante Meuleman8abffd82015-10-29 20:33:16 +01004240 if ((dev_role == NL80211_IFTYPE_AP) &&
4241 ((ifp->ifidx == 0) ||
4242 !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004243 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4244 if (err < 0) {
4245 brcmf_err("BRCMF_C_DOWN error %d\n", err);
4246 goto exit;
4247 }
4248 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
4249 }
4250
4251 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02004252 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004253 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004254 goto exit;
4255 }
Arend van Spriel98027762014-12-21 12:43:53 +01004256 } else if (WARN_ON(is_11d != ifp->vif->is_11d)) {
4257 /* Multiple-BSS should use same 11d configuration */
4258 err = -EINVAL;
4259 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004260 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004261 if (dev_role == NL80211_IFTYPE_AP) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004262 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
4263 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
4264
Hante Meulemana0f07952013-02-08 15:53:47 +01004265 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
4266 if (err < 0) {
4267 brcmf_err("setting AP mode failed %d\n", err);
4268 goto exit;
4269 }
4270 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4271 if (err < 0) {
4272 brcmf_err("BRCMF_C_UP error (%d)\n", err);
4273 goto exit;
4274 }
Hante Meuleman118eb302014-12-21 12:43:49 +01004275 /* On DOWN the firmware removes the WEP keys, reconfigure
4276 * them if they were set.
4277 */
4278 brcmf_cfg80211_reconfigure_wep(ifp);
Hante Meulemana0f07952013-02-08 15:53:47 +01004279
4280 memset(&join_params, 0, sizeof(join_params));
4281 /* join parameters starts with ssid */
4282 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
4283 /* create softap */
4284 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4285 &join_params, sizeof(join_params));
4286 if (err < 0) {
4287 brcmf_err("SET SSID error (%d)\n", err);
4288 goto exit;
4289 }
4290 brcmf_dbg(TRACE, "AP mode configuration complete\n");
4291 } else {
4292 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
4293 sizeof(ssid_le));
4294 if (err < 0) {
4295 brcmf_err("setting ssid failed %d\n", err);
4296 goto exit;
4297 }
Hante Meuleman37a869e2015-10-29 20:33:17 +01004298 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meulemana0f07952013-02-08 15:53:47 +01004299 bss_enable.enable = cpu_to_le32(1);
4300 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4301 sizeof(bss_enable));
4302 if (err < 0) {
4303 brcmf_err("bss_enable config failed %d\n", err);
4304 goto exit;
4305 }
4306
4307 brcmf_dbg(TRACE, "GO mode configuration complete\n");
4308 }
Arend van Sprielc1179032012-10-22 13:55:33 -07004309 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004310 brcmf_net_setcarrier(ifp, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004311
4312exit:
Hante Meulemana44aa402014-12-03 21:05:33 +01004313 if ((err) && (!mbss)) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02004314 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004315 brcmf_configure_arp_offload(ifp, true);
4316 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004317 return err;
4318}
4319
4320static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
4321{
Arend van Sprielc1179032012-10-22 13:55:33 -07004322 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004323 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01004324 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02004325 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02004326
Arend van Sprield96b8012012-12-05 15:26:02 +01004327 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004328
Hante Meuleman426d0a52013-02-08 15:53:53 +01004329 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004330 /* Due to most likely deauths outstanding we sleep */
4331 /* first to make sure they get processed by fw. */
4332 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004333
Hante Meulemana44aa402014-12-03 21:05:33 +01004334 if (ifp->vif->mbss) {
4335 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4336 return err;
4337 }
4338
Hante Meuleman5c33a942013-04-02 21:06:18 +02004339 memset(&join_params, 0, sizeof(join_params));
4340 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4341 &join_params, sizeof(join_params));
4342 if (err < 0)
4343 brcmf_err("SET SSID error (%d)\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004344 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004345 if (err < 0)
Hante Meulemana44aa402014-12-03 21:05:33 +01004346 brcmf_err("BRCMF_C_DOWN error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004347 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4348 if (err < 0)
4349 brcmf_err("setting AP mode failed %d\n", err);
4350 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4351 if (err < 0)
4352 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004353 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
4354 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
Arend van Spriel98027762014-12-21 12:43:53 +01004355 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4356 ifp->vif->is_11d);
4357 if (err < 0)
4358 brcmf_err("restoring REGULATORY setting failed %d\n",
4359 err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004360 /* Bring device back up so it can be used again */
4361 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4362 if (err < 0)
4363 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004364 } else {
Hante Meuleman37a869e2015-10-29 20:33:17 +01004365 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004366 bss_enable.enable = cpu_to_le32(0);
4367 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4368 sizeof(bss_enable));
4369 if (err < 0)
4370 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004371 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02004372 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004373 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004374 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004375 brcmf_net_setcarrier(ifp, false);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004376
Hante Meuleman1a873342012-09-27 14:17:54 +02004377 return err;
4378}
4379
Hante Meulemana0f07952013-02-08 15:53:47 +01004380static s32
4381brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4382 struct cfg80211_beacon_data *info)
4383{
Hante Meulemana0f07952013-02-08 15:53:47 +01004384 struct brcmf_if *ifp = netdev_priv(ndev);
4385 s32 err;
4386
4387 brcmf_dbg(TRACE, "Enter\n");
4388
Hante Meulemana0f07952013-02-08 15:53:47 +01004389 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4390
4391 return err;
4392}
4393
Hante Meuleman1a873342012-09-27 14:17:54 +02004394static int
4395brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03004396 struct station_del_parameters *params)
Hante Meuleman1a873342012-09-27 14:17:54 +02004397{
Hante Meulemana0f07952013-02-08 15:53:47 +01004398 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02004399 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004400 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02004401 s32 err;
4402
Jouni Malinen89c771e2014-10-10 20:52:40 +03004403 if (!params->mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02004404 return -EFAULT;
4405
Jouni Malinen89c771e2014-10-10 20:52:40 +03004406 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02004407
Hante Meulemana0f07952013-02-08 15:53:47 +01004408 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4409 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07004410 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02004411 return -EIO;
4412
Jouni Malinen89c771e2014-10-10 20:52:40 +03004413 memcpy(&scbval.ea, params->mac, ETH_ALEN);
Rafał Miłeckiba8b6ae2015-02-08 11:51:47 +01004414 scbval.val = cpu_to_le32(params->reason_code);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004415 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004416 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02004417 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004418 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01004419
Arend van Sprield96b8012012-12-05 15:26:02 +01004420 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004421 return err;
4422}
4423
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004424static int
4425brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
4426 const u8 *mac, struct station_parameters *params)
4427{
4428 struct brcmf_if *ifp = netdev_priv(ndev);
4429 s32 err;
4430
4431 brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
4432 params->sta_flags_mask, params->sta_flags_set);
4433
4434 /* Ignore all 00 MAC */
4435 if (is_zero_ether_addr(mac))
4436 return 0;
4437
4438 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4439 return 0;
4440
4441 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
4442 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
4443 (void *)mac, ETH_ALEN);
4444 else
4445 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
4446 (void *)mac, ETH_ALEN);
4447 if (err < 0)
4448 brcmf_err("Setting SCB (de-)authorize failed, %d\n", err);
4449
4450 return err;
4451}
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004452
4453static void
4454brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4455 struct wireless_dev *wdev,
4456 u16 frame_type, bool reg)
4457{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004458 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004459 u16 mgmt_type;
4460
4461 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4462
4463 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004464 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004465 if (reg)
4466 vif->mgmt_rx_reg |= BIT(mgmt_type);
4467 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01004468 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004469}
4470
4471
4472static int
4473brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004474 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004475{
4476 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004477 struct ieee80211_channel *chan = params->chan;
4478 const u8 *buf = params->buf;
4479 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004480 const struct ieee80211_mgmt *mgmt;
4481 struct brcmf_cfg80211_vif *vif;
4482 s32 err = 0;
4483 s32 ie_offset;
4484 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004485 struct brcmf_fil_action_frame_le *action_frame;
4486 struct brcmf_fil_af_params_le *af_params;
4487 bool ack;
4488 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004489 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004490
4491 brcmf_dbg(TRACE, "Enter\n");
4492
4493 *cookie = 0;
4494
4495 mgmt = (const struct ieee80211_mgmt *)buf;
4496
Hante Meulemana0f07952013-02-08 15:53:47 +01004497 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4498 brcmf_err("Driver only allows MGMT packet type\n");
4499 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004500 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004501
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004502 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4503
Hante Meulemana0f07952013-02-08 15:53:47 +01004504 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4505 /* Right now the only reason to get a probe response */
4506 /* is for p2p listen response or for p2p GO from */
4507 /* wpa_supplicant. Unfortunately the probe is send */
4508 /* on primary ndev, while dongle wants it on the p2p */
4509 /* vif. Since this is only reason for a probe */
4510 /* response to be sent, the vif is taken from cfg. */
4511 /* If ever desired to send proberesp for non p2p */
4512 /* response then data should be checked for */
4513 /* "DIRECT-". Note in future supplicant will take */
4514 /* dedicated p2p wdev to do this and then this 'hack'*/
4515 /* is not needed anymore. */
4516 ie_offset = DOT11_MGMT_HDR_LEN +
4517 DOT11_BCN_PRB_FIXED_LEN;
4518 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004519 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4520 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4521 err = brcmf_vif_set_mgmt_ie(vif,
4522 BRCMF_VNDR_IE_PRBRSP_FLAG,
4523 &buf[ie_offset],
4524 ie_len);
4525 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4526 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004527 } else if (ieee80211_is_action(mgmt->frame_control)) {
4528 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4529 if (af_params == NULL) {
4530 brcmf_err("unable to allocate frame\n");
4531 err = -ENOMEM;
4532 goto exit;
4533 }
4534 action_frame = &af_params->action_frame;
4535 /* Add the packet Id */
4536 action_frame->packet_id = cpu_to_le32(*cookie);
4537 /* Add BSSID */
4538 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4539 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4540 /* Add the length exepted for 802.11 header */
4541 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004542 /* Add the channel. Use the one specified as parameter if any or
4543 * the current one (got from the firmware) otherwise
4544 */
4545 if (chan)
4546 freq = chan->center_freq;
4547 else
4548 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4549 &freq);
4550 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004551 af_params->channel = cpu_to_le32(chan_nr);
4552
4553 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4554 le16_to_cpu(action_frame->len));
4555
4556 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004557 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004558
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004559 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004560 af_params);
4561
4562 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4563 GFP_KERNEL);
4564 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004565 } else {
4566 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4567 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4568 }
4569
Hante Meuleman18e2f612013-02-08 15:53:49 +01004570exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004571 return err;
4572}
4573
4574
4575static int
4576brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4577 struct wireless_dev *wdev,
4578 u64 cookie)
4579{
4580 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4581 struct brcmf_cfg80211_vif *vif;
4582 int err = 0;
4583
4584 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4585
4586 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4587 if (vif == NULL) {
4588 brcmf_err("No p2p device available for probe response\n");
4589 err = -ENODEV;
4590 goto exit;
4591 }
4592 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4593exit:
4594 return err;
4595}
4596
Piotr Haber61730d42013-04-23 12:53:12 +02004597static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4598 struct wireless_dev *wdev,
4599 enum nl80211_crit_proto_id proto,
4600 u16 duration)
4601{
4602 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4603 struct brcmf_cfg80211_vif *vif;
4604
4605 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4606
4607 /* only DHCP support for now */
4608 if (proto != NL80211_CRIT_PROTO_DHCP)
4609 return -EINVAL;
4610
4611 /* suppress and abort scanning */
4612 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4613 brcmf_abort_scanning(cfg);
4614
4615 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4616}
4617
4618static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4619 struct wireless_dev *wdev)
4620{
4621 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4622 struct brcmf_cfg80211_vif *vif;
4623
4624 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4625
4626 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4627 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4628}
4629
Hante Meuleman70b7d942014-07-30 13:20:07 +02004630static s32
4631brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4632 const struct brcmf_event_msg *e, void *data)
4633{
4634 switch (e->reason) {
4635 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4636 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4637 break;
4638 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4639 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4640 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4641 break;
4642 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4643 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4644 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4645 break;
4646 }
4647
4648 return 0;
4649}
4650
Arend van Spriel89c2f382013-08-10 12:27:25 +02004651static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4652{
4653 int ret;
4654
4655 switch (oper) {
4656 case NL80211_TDLS_DISCOVERY_REQ:
4657 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4658 break;
4659 case NL80211_TDLS_SETUP:
4660 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4661 break;
4662 case NL80211_TDLS_TEARDOWN:
4663 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4664 break;
4665 default:
4666 brcmf_err("unsupported operation: %d\n", oper);
4667 ret = -EOPNOTSUPP;
4668 }
4669 return ret;
4670}
4671
4672static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004673 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004674 enum nl80211_tdls_operation oper)
4675{
4676 struct brcmf_if *ifp;
4677 struct brcmf_tdls_iovar_le info;
4678 int ret = 0;
4679
4680 ret = brcmf_convert_nl80211_tdls_oper(oper);
4681 if (ret < 0)
4682 return ret;
4683
4684 ifp = netdev_priv(ndev);
4685 memset(&info, 0, sizeof(info));
4686 info.mode = (u8)ret;
4687 if (peer)
4688 memcpy(info.ea, peer, ETH_ALEN);
4689
4690 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4691 &info, sizeof(info));
4692 if (ret < 0)
4693 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4694
4695 return ret;
4696}
4697
Arend van Spriel5b435de2011-10-05 13:19:03 +02004698static struct cfg80211_ops wl_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01004699 .add_virtual_intf = brcmf_cfg80211_add_iface,
4700 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004701 .change_virtual_intf = brcmf_cfg80211_change_iface,
4702 .scan = brcmf_cfg80211_scan,
4703 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4704 .join_ibss = brcmf_cfg80211_join_ibss,
4705 .leave_ibss = brcmf_cfg80211_leave_ibss,
4706 .get_station = brcmf_cfg80211_get_station,
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02004707 .dump_station = brcmf_cfg80211_dump_station,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004708 .set_tx_power = brcmf_cfg80211_set_tx_power,
4709 .get_tx_power = brcmf_cfg80211_get_tx_power,
4710 .add_key = brcmf_cfg80211_add_key,
4711 .del_key = brcmf_cfg80211_del_key,
4712 .get_key = brcmf_cfg80211_get_key,
4713 .set_default_key = brcmf_cfg80211_config_default_key,
4714 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4715 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004716 .connect = brcmf_cfg80211_connect,
4717 .disconnect = brcmf_cfg80211_disconnect,
4718 .suspend = brcmf_cfg80211_suspend,
4719 .resume = brcmf_cfg80211_resume,
4720 .set_pmksa = brcmf_cfg80211_set_pmksa,
4721 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02004722 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02004723 .start_ap = brcmf_cfg80211_start_ap,
4724 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01004725 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02004726 .del_station = brcmf_cfg80211_del_station,
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004727 .change_station = brcmf_cfg80211_change_station,
Arend van Spriele5806072012-09-19 22:21:08 +02004728 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4729 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004730 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4731 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4732 .remain_on_channel = brcmf_p2p_remain_on_channel,
4733 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02004734 .start_p2p_device = brcmf_p2p_start_device,
4735 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02004736 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4737 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004738 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004739};
4740
Arend van Spriel3eacf862012-10-22 13:55:30 -07004741struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01004742 enum nl80211_iftype type,
4743 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004744{
Hante Meulemana44aa402014-12-03 21:05:33 +01004745 struct brcmf_cfg80211_vif *vif_walk;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004746 struct brcmf_cfg80211_vif *vif;
Hante Meulemana44aa402014-12-03 21:05:33 +01004747 bool mbss;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004748
Arend van Spriel33a6b152013-02-08 15:53:39 +01004749 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01004750 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07004751 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4752 if (!vif)
4753 return ERR_PTR(-ENOMEM);
4754
4755 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01004756 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004757
Arend van Spriel3eacf862012-10-22 13:55:30 -07004758 vif->pm_block = pm_block;
4759 vif->roam_off = -1;
4760
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004761 brcmf_init_prof(&vif->profile);
4762
Hante Meulemana44aa402014-12-03 21:05:33 +01004763 if (type == NL80211_IFTYPE_AP) {
4764 mbss = false;
4765 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
4766 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
4767 mbss = true;
4768 break;
4769 }
4770 }
4771 vif->mbss = mbss;
4772 }
4773
Arend van Spriel3eacf862012-10-22 13:55:30 -07004774 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004775 return vif;
4776}
4777
Arend van Spriel427dec52014-01-06 12:40:47 +01004778void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07004779{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004780 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004781 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004782}
4783
Arend van Spriel9df4d542014-01-06 12:40:49 +01004784void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4785{
4786 struct brcmf_cfg80211_vif *vif;
4787 struct brcmf_if *ifp;
4788
4789 ifp = netdev_priv(ndev);
4790 vif = ifp->vif;
4791
Arend van Spriel95ef1232015-08-26 22:15:04 +02004792 if (vif)
4793 brcmf_free_vif(vif);
Arend van Spriel9df4d542014-01-06 12:40:49 +01004794 free_netdev(ndev);
4795}
4796
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004797static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004798{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004799 u32 event = e->event_code;
4800 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004801
4802 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004803 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004804 return true;
4805 }
4806
4807 return false;
4808}
4809
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004810static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004811{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004812 u32 event = e->event_code;
4813 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004814
Hante Meuleman68ca3952014-02-25 20:30:26 +01004815 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4816 (event == BRCMF_E_DISASSOC_IND) ||
4817 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01004818 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004819 return true;
4820 }
4821 return false;
4822}
4823
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004824static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004825 const struct brcmf_event_msg *e)
4826{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004827 u32 event = e->event_code;
4828 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004829
4830 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004831 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
4832 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004833 return true;
4834 }
4835
4836 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004837 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004838 return true;
4839 }
4840
4841 return false;
4842}
4843
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004844static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004845{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004846 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004847
4848 kfree(conn_info->req_ie);
4849 conn_info->req_ie = NULL;
4850 conn_info->req_ie_len = 0;
4851 kfree(conn_info->resp_ie);
4852 conn_info->resp_ie = NULL;
4853 conn_info->resp_ie_len = 0;
4854}
4855
Hante Meuleman89286dc2013-02-08 15:53:46 +01004856static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
4857 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004858{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004859 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004860 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004861 u32 req_len;
4862 u32 resp_len;
4863 s32 err = 0;
4864
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004865 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004866
Arend van Sprielac24be62012-10-22 10:36:23 -07004867 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
4868 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004869 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004870 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004871 return err;
4872 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004873 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004874 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02004875 req_len = le32_to_cpu(assoc_info->req_len);
4876 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004877 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004878 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004879 cfg->extra_buf,
4880 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004881 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004882 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004883 return err;
4884 }
4885 conn_info->req_ie_len = req_len;
4886 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004887 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004888 GFP_KERNEL);
4889 } else {
4890 conn_info->req_ie_len = 0;
4891 conn_info->req_ie = NULL;
4892 }
4893 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07004894 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004895 cfg->extra_buf,
4896 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004897 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004898 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004899 return err;
4900 }
4901 conn_info->resp_ie_len = resp_len;
4902 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004903 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004904 GFP_KERNEL);
4905 } else {
4906 conn_info->resp_ie_len = 0;
4907 conn_info->resp_ie = NULL;
4908 }
Arend van Spriel16886732012-12-05 15:26:04 +01004909 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
4910 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004911
4912 return err;
4913}
4914
4915static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004916brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004917 struct net_device *ndev,
4918 const struct brcmf_event_msg *e)
4919{
Arend van Sprielc1179032012-10-22 13:55:33 -07004920 struct brcmf_if *ifp = netdev_priv(ndev);
4921 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004922 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4923 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07004924 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004925 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07004926 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02004927 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004928 u32 freq;
4929 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07004930 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004931
Arend van Sprield96b8012012-12-05 15:26:02 +01004932 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004933
Hante Meuleman89286dc2013-02-08 15:53:46 +01004934 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004935 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004936 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004937
Franky Lina180b832012-10-10 11:13:09 -07004938 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
4939 if (buf == NULL) {
4940 err = -ENOMEM;
4941 goto done;
4942 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02004943
Franky Lina180b832012-10-10 11:13:09 -07004944 /* data sent to dongle has to be little endian */
4945 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07004946 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07004947 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07004948
4949 if (err)
4950 goto done;
4951
4952 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02004953 ch.chspec = le16_to_cpu(bi->chanspec);
4954 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004955
Franky Lin83cf17a2013-04-11 13:28:50 +02004956 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004957 band = wiphy->bands[IEEE80211_BAND_2GHZ];
4958 else
4959 band = wiphy->bands[IEEE80211_BAND_5GHZ];
4960
Franky Lin83cf17a2013-04-11 13:28:50 +02004961 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004962 notify_channel = ieee80211_get_channel(wiphy, freq);
4963
Franky Lina180b832012-10-10 11:13:09 -07004964done:
4965 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02004966 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004967 conn_info->req_ie, conn_info->req_ie_len,
4968 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01004969 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004970
Arend van Sprielc1179032012-10-22 13:55:33 -07004971 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01004972 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004973 return err;
4974}
4975
4976static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004977brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004978 struct net_device *ndev, const struct brcmf_event_msg *e,
4979 bool completed)
4980{
Arend van Sprielc1179032012-10-22 13:55:33 -07004981 struct brcmf_if *ifp = netdev_priv(ndev);
4982 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004983 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004984
Arend van Sprield96b8012012-12-05 15:26:02 +01004985 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004986
Arend van Sprielc1179032012-10-22 13:55:33 -07004987 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4988 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02004989 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01004990 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02004991 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01004992 brcmf_update_bss_info(cfg, ifp);
4993 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4994 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004995 }
4996 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02004997 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004998 conn_info->req_ie,
4999 conn_info->req_ie_len,
5000 conn_info->resp_ie,
5001 conn_info->resp_ie_len,
5002 completed ? WLAN_STATUS_SUCCESS :
5003 WLAN_STATUS_AUTH_TIMEOUT,
5004 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005005 brcmf_dbg(CONN, "Report connect result - connection %s\n",
5006 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005007 }
Arend van Sprield96b8012012-12-05 15:26:02 +01005008 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005009 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005010}
5011
5012static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005013brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02005014 struct net_device *ndev,
5015 const struct brcmf_event_msg *e, void *data)
5016{
Hante Meulemana44aa402014-12-03 21:05:33 +01005017 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman7ee29602013-02-06 18:40:43 +01005018 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005019 u32 event = e->event_code;
5020 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02005021 struct station_info sinfo;
5022
Arend van Spriel16886732012-12-05 15:26:04 +01005023 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005024 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
5025 ndev != cfg_to_ndev(cfg)) {
5026 brcmf_dbg(CONN, "AP mode link down\n");
5027 complete(&cfg->vif_disabled);
Hante Meulemana44aa402014-12-03 21:05:33 +01005028 if (ifp->vif->mbss)
Arend van Sprielee6e3a32015-08-26 22:14:55 +02005029 brcmf_remove_interface(ifp);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005030 return 0;
5031 }
Hante Meuleman1a873342012-09-27 14:17:54 +02005032
Hante Meuleman1a873342012-09-27 14:17:54 +02005033 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01005034 (reason == BRCMF_E_STATUS_SUCCESS)) {
5035 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02005036 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005037 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02005038 return -EINVAL;
5039 }
5040 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005041 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02005042 generation++;
5043 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005044 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005045 } else if ((event == BRCMF_E_DISASSOC_IND) ||
5046 (event == BRCMF_E_DEAUTH_IND) ||
5047 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01005048 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005049 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01005050 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02005051}
5052
5053static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005054brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005055 const struct brcmf_event_msg *e, void *data)
5056{
Arend van Spriel19937322012-11-05 16:22:32 -08005057 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5058 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07005059 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005060 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005061 s32 err = 0;
5062
Hante Meuleman8851cce2014-07-30 13:20:02 +02005063 if ((e->event_code == BRCMF_E_DEAUTH) ||
5064 (e->event_code == BRCMF_E_DEAUTH_IND) ||
5065 (e->event_code == BRCMF_E_DISASSOC_IND) ||
5066 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
5067 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5068 }
5069
Arend van Spriel967fe2c2014-03-15 17:18:21 +01005070 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005071 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005072 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005073 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005074 if (brcmf_is_ibssmode(ifp->vif)) {
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005075 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005076 memcpy(profile->bssid, e->addr, ETH_ALEN);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005077 wl_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005078 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07005079 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5080 &ifp->vif->sme_state);
5081 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5082 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005083 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005084 brcmf_bss_connect_done(cfg, ndev, e, true);
Hante Meuleman92121e62015-10-08 20:33:21 +02005085 brcmf_net_setcarrier(ifp, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005086 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005087 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005088 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005089 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005090 }
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01005091 brcmf_link_down(ifp->vif, brcmf_map_fw_linkdown_reason(e));
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07005092 brcmf_init_prof(ndev_to_prof(ndev));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005093 if (ndev != cfg_to_ndev(cfg))
5094 complete(&cfg->vif_disabled);
Hante Meuleman92121e62015-10-08 20:33:21 +02005095 brcmf_net_setcarrier(ifp, false);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005096 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005097 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07005098 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5099 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005100 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005101 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005102 }
5103
5104 return err;
5105}
5106
5107static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005108brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005109 const struct brcmf_event_msg *e, void *data)
5110{
Arend van Spriel19937322012-11-05 16:22:32 -08005111 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005112 u32 event = e->event_code;
5113 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005114
5115 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07005116 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08005117 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005118 else
Arend van Spriel19937322012-11-05 16:22:32 -08005119 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005120 }
5121
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005122 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005123}
5124
5125static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005126brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005127 const struct brcmf_event_msg *e, void *data)
5128{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005129 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005130 enum nl80211_key_type key_type;
5131
5132 if (flags & BRCMF_EVENT_MSG_GROUP)
5133 key_type = NL80211_KEYTYPE_GROUP;
5134 else
5135 key_type = NL80211_KEYTYPE_PAIRWISE;
5136
Arend van Spriel19937322012-11-05 16:22:32 -08005137 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005138 NULL, GFP_KERNEL);
5139
5140 return 0;
5141}
5142
Arend van Sprield3c0b632013-02-08 15:53:37 +01005143static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
5144 const struct brcmf_event_msg *e, void *data)
5145{
5146 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5147 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
5148 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5149 struct brcmf_cfg80211_vif *vif;
5150
Hante Meuleman37a869e2015-10-29 20:33:17 +01005151 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
Arend van Sprield3c0b632013-02-08 15:53:37 +01005152 ifevent->action, ifevent->flags, ifevent->ifidx,
Hante Meuleman37a869e2015-10-29 20:33:17 +01005153 ifevent->bsscfgidx);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005154
Arend van Sprield3c0b632013-02-08 15:53:37 +01005155 mutex_lock(&event->vif_event_lock);
5156 event->action = ifevent->action;
5157 vif = event->vif;
5158
5159 switch (ifevent->action) {
5160 case BRCMF_E_IF_ADD:
5161 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08005162 if (!cfg->vif_event.vif) {
5163 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005164 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08005165 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005166
5167 ifp->vif = vif;
5168 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02005169 if (ifp->ndev) {
5170 vif->wdev.netdev = ifp->ndev;
5171 ifp->ndev->ieee80211_ptr = &vif->wdev;
5172 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
5173 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005174 mutex_unlock(&event->vif_event_lock);
5175 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01005176 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01005177
5178 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01005179 mutex_unlock(&event->vif_event_lock);
5180 /* event may not be upon user request */
5181 if (brcmf_cfg80211_vif_event_armed(cfg))
5182 wake_up(&event->vif_wq);
5183 return 0;
5184
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01005185 case BRCMF_E_IF_CHANGE:
5186 mutex_unlock(&event->vif_event_lock);
5187 wake_up(&event->vif_wq);
5188 return 0;
5189
Arend van Sprield3c0b632013-02-08 15:53:37 +01005190 default:
5191 mutex_unlock(&event->vif_event_lock);
5192 break;
5193 }
5194 return -EINVAL;
5195}
5196
Arend van Spriel5b435de2011-10-05 13:19:03 +02005197static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
5198{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005199 conf->frag_threshold = (u32)-1;
5200 conf->rts_threshold = (u32)-1;
5201 conf->retry_short = (u32)-1;
5202 conf->retry_long = (u32)-1;
5203 conf->tx_power = -1;
5204}
5205
Arend van Spriel5c36b992012-11-14 18:46:05 -08005206static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005207{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005208 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
5209 brcmf_notify_connect_status);
5210 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
5211 brcmf_notify_connect_status);
5212 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
5213 brcmf_notify_connect_status);
5214 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
5215 brcmf_notify_connect_status);
5216 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
5217 brcmf_notify_connect_status);
5218 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
5219 brcmf_notify_connect_status);
5220 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
5221 brcmf_notify_roaming_status);
5222 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
5223 brcmf_notify_mic_status);
5224 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
5225 brcmf_notify_connect_status);
5226 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
5227 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005228 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
5229 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005230 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005231 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005232 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
5233 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01005234 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
5235 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01005236 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
5237 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005238 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
5239 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005240}
5241
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005242static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005243{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005244 kfree(cfg->conf);
5245 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005246 kfree(cfg->escan_ioctl_buf);
5247 cfg->escan_ioctl_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005248 kfree(cfg->extra_buf);
5249 cfg->extra_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005250 kfree(cfg->pmk_list);
5251 cfg->pmk_list = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005252}
5253
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005254static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005255{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005256 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
5257 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005258 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005259 cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5260 if (!cfg->escan_ioctl_buf)
Hante Meulemane756af52012-09-11 21:18:52 +02005261 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005262 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
5263 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005264 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005265 cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL);
5266 if (!cfg->pmk_list)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005267 goto init_priv_mem_out;
5268
5269 return 0;
5270
5271init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005272 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005273
5274 return -ENOMEM;
5275}
5276
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005277static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005278{
5279 s32 err = 0;
5280
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005281 cfg->scan_request = NULL;
5282 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01005283 cfg->active_scan = true; /* we do active scan per default */
5284 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005285 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005286 if (err)
5287 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005288 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005289 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005290 brcmf_init_escan(cfg);
5291 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005292 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005293 return err;
5294}
5295
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005296static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005297{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005298 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005299 brcmf_abort_scanning(cfg);
5300 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005301}
5302
Arend van Sprield3c0b632013-02-08 15:53:37 +01005303static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
5304{
5305 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005306 mutex_init(&event->vif_event_lock);
5307}
5308
Arend van Spriel5b435de2011-10-05 13:19:03 +02005309static s32
Hante Meuleman68ca3952014-02-25 20:30:26 +01005310brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005311{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005312 s32 err = 0;
Arend van Sprielf588bc02011-10-12 20:51:22 +02005313 __le32 roamtrigger[2];
5314 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005315
5316 /*
5317 * Setup timeout if Beacons are lost and roam is
5318 * off to report link down
5319 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005320 if (brcmf_roamoff) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005321 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005322 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005323 brcmf_err("bcn_timeout error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005324 goto dongle_rom_out;
5325 }
5326 }
5327
5328 /*
5329 * Enable/Disable built-in roaming to allow supplicant
5330 * to take care of roaming
5331 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005332 brcmf_dbg(INFO, "Internal Roaming = %s\n",
5333 brcmf_roamoff ? "Off" : "On");
5334 err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005335 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005336 brcmf_err("roam_off error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005337 goto dongle_rom_out;
5338 }
5339
Arend van Sprielf588bc02011-10-12 20:51:22 +02005340 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
5341 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005342 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005343 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005344 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005345 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005346 goto dongle_rom_out;
5347 }
5348
Arend van Sprielf588bc02011-10-12 20:51:22 +02005349 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
5350 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005351 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005352 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005353 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005354 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005355 goto dongle_rom_out;
5356 }
5357
5358dongle_rom_out:
5359 return err;
5360}
5361
5362static s32
Hante Meuleman40a23292013-01-02 15:22:51 +01005363brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time,
Arend van Sprielc68cdc02011-10-12 20:51:23 +02005364 s32 scan_unassoc_time, s32 scan_passive_time)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005365{
5366 s32 err = 0;
5367
Arend van Sprielac24be62012-10-22 10:36:23 -07005368 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005369 scan_assoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005370 if (err) {
5371 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005372 brcmf_dbg(INFO, "Scan assoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005373 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005374 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005375 goto dongle_scantime_out;
5376 }
Arend van Sprielac24be62012-10-22 10:36:23 -07005377 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005378 scan_unassoc_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005379 if (err) {
5380 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005381 brcmf_dbg(INFO, "Scan unassoc time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005382 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005383 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005384 goto dongle_scantime_out;
5385 }
5386
Arend van Sprielac24be62012-10-22 10:36:23 -07005387 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005388 scan_passive_time);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005389 if (err) {
5390 if (err == -EOPNOTSUPP)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01005391 brcmf_dbg(INFO, "Scan passive time is not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005392 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01005393 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005394 goto dongle_scantime_out;
5395 }
5396
5397dongle_scantime_out:
5398 return err;
5399}
5400
Arend van Sprielb48d8912014-07-12 08:49:41 +02005401static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5402 struct brcmu_chan *ch)
5403{
5404 u32 ht40_flag;
5405
5406 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5407 if (ch->sb == BRCMU_CHAN_SB_U) {
5408 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5409 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5410 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5411 } else {
5412 /* It should be one of
5413 * IEEE80211_CHAN_NO_HT40 or
5414 * IEEE80211_CHAN_NO_HT40PLUS
5415 */
5416 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5417 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5418 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5419 }
5420}
5421
5422static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5423 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005424{
5425 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005426 struct ieee80211_supported_band *band;
5427 struct ieee80211_channel *channel;
5428 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005429 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005430 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005431 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005432 u8 *pbuf;
5433 u32 i, j;
5434 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005435 u32 chaninfo;
Hante Meulemand48200b2013-04-03 12:40:29 +02005436 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02005437
5438 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5439
5440 if (pbuf == NULL)
5441 return -ENOMEM;
5442
5443 list = (struct brcmf_chanspec_list *)pbuf;
5444
5445 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5446 BRCMF_DCMD_MEDLEN);
5447 if (err) {
5448 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005449 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005450 }
5451
Arend van Sprielb48d8912014-07-12 08:49:41 +02005452 wiphy = cfg_to_wiphy(cfg);
Arend van Spriel58de92d2015-04-14 20:10:24 +02005453 band = wiphy->bands[IEEE80211_BAND_2GHZ];
5454 if (band)
5455 for (i = 0; i < band->n_channels; i++)
5456 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
5457 band = wiphy->bands[IEEE80211_BAND_5GHZ];
5458 if (band)
5459 for (i = 0; i < band->n_channels; i++)
5460 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Hante Meulemand48200b2013-04-03 12:40:29 +02005461
5462 total = le32_to_cpu(list->count);
5463 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005464 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5465 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005466
Franky Lin83cf17a2013-04-11 13:28:50 +02005467 if (ch.band == BRCMU_CHAN_BAND_2G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005468 band = wiphy->bands[IEEE80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005469 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005470 band = wiphy->bands[IEEE80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005471 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005472 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005473 continue;
5474 }
Arend van Spriel58de92d2015-04-14 20:10:24 +02005475 if (!band)
5476 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005477 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005478 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005479 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005480 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005481 ch.bw == BRCMU_CHAN_BW_80)
5482 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005483
5484 channel = band->channels;
5485 index = band->n_channels;
5486 for (j = 0; j < band->n_channels; j++) {
5487 if (channel[j].hw_value == ch.chnum) {
5488 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005489 break;
5490 }
5491 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005492 channel[index].center_freq =
5493 ieee80211_channel_to_frequency(ch.chnum, band->band);
5494 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005495
Arend van Sprielb48d8912014-07-12 08:49:41 +02005496 /* assuming the chanspecs order is HT20,
5497 * HT40 upper, HT40 lower, and VHT80.
5498 */
5499 if (ch.bw == BRCMU_CHAN_BW_80) {
5500 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5501 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5502 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5503 } else {
Arend van Spriel58de92d2015-04-14 20:10:24 +02005504 /* enable the channel and disable other bandwidths
5505 * for now as mentioned order assure they are enabled
5506 * for subsequent chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005507 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005508 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5509 IEEE80211_CHAN_NO_80MHZ;
5510 ch.bw = BRCMU_CHAN_BW_20;
5511 cfg->d11inf.encchspec(&ch);
5512 chaninfo = ch.chspec;
5513 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5514 &chaninfo);
5515 if (!err) {
5516 if (chaninfo & WL_CHAN_RADAR)
5517 channel[index].flags |=
5518 (IEEE80211_CHAN_RADAR |
5519 IEEE80211_CHAN_NO_IR);
5520 if (chaninfo & WL_CHAN_PASSIVE)
5521 channel[index].flags |=
5522 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005523 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005524 }
5525 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005526
Arend van Sprielb48d8912014-07-12 08:49:41 +02005527fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005528 kfree(pbuf);
5529 return err;
5530}
5531
Arend van Sprielb48d8912014-07-12 08:49:41 +02005532static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005533{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005534 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5535 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005536 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005537 struct brcmf_chanspec_list *list;
5538 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005539 u32 val;
5540 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005541 struct brcmu_chan ch;
5542 u32 num_chan;
5543 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005544
5545 /* verify support for bw_cap command */
5546 val = WLC_BAND_5G;
5547 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5548
5549 if (!err) {
5550 /* only set 2G bandwidth using bw_cap command */
5551 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5552 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5553 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5554 sizeof(band_bwcap));
5555 } else {
5556 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5557 val = WLC_N_BW_40ALL;
5558 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5559 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005560
5561 if (!err) {
5562 /* update channel info in 2G band */
5563 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5564
5565 if (pbuf == NULL)
5566 return -ENOMEM;
5567
5568 ch.band = BRCMU_CHAN_BAND_2G;
5569 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005570 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005571 ch.chnum = 0;
5572 cfg->d11inf.encchspec(&ch);
5573
5574 /* pass encoded chanspec in query */
5575 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5576
5577 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5578 BRCMF_DCMD_MEDLEN);
5579 if (err) {
5580 brcmf_err("get chanspecs error (%d)\n", err);
5581 kfree(pbuf);
5582 return err;
5583 }
5584
5585 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5586 list = (struct brcmf_chanspec_list *)pbuf;
5587 num_chan = le32_to_cpu(list->count);
5588 for (i = 0; i < num_chan; i++) {
5589 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5590 cfg->d11inf.decchspec(&ch);
5591 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5592 continue;
5593 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5594 continue;
5595 for (j = 0; j < band->n_channels; j++) {
5596 if (band->channels[j].hw_value == ch.chnum)
5597 break;
5598 }
5599 if (WARN_ON(j == band->n_channels))
5600 continue;
5601
5602 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5603 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005604 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005605 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005606 return err;
5607}
5608
Arend van Spriel2375d972014-01-06 12:40:41 +01005609static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5610{
5611 u32 band, mimo_bwcap;
5612 int err;
5613
5614 band = WLC_BAND_2G;
5615 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5616 if (!err) {
5617 bw_cap[IEEE80211_BAND_2GHZ] = band;
5618 band = WLC_BAND_5G;
5619 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5620 if (!err) {
5621 bw_cap[IEEE80211_BAND_5GHZ] = band;
5622 return;
5623 }
5624 WARN_ON(1);
5625 return;
5626 }
5627 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5628 mimo_bwcap = 0;
5629 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5630 if (err)
5631 /* assume 20MHz if firmware does not give a clue */
5632 mimo_bwcap = WLC_N_BW_20ALL;
5633
5634 switch (mimo_bwcap) {
5635 case WLC_N_BW_40ALL:
5636 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5637 /* fall-thru */
5638 case WLC_N_BW_20IN2G_40IN5G:
5639 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5640 /* fall-thru */
5641 case WLC_N_BW_20ALL:
5642 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5643 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5644 break;
5645 default:
5646 brcmf_err("invalid mimo_bw_cap value\n");
5647 }
5648}
Hante Meulemand48200b2013-04-03 12:40:29 +02005649
Arend van Spriel18d6c532014-05-12 10:47:35 +02005650static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5651 u32 bw_cap[2], u32 nchain)
5652{
5653 band->ht_cap.ht_supported = true;
5654 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5655 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5656 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5657 }
5658 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5659 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5660 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5661 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5662 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5663 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5664}
5665
5666static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5667{
5668 u16 mcs_map;
5669 int i;
5670
5671 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5672 mcs_map = (mcs_map << 2) | supp;
5673
5674 return cpu_to_le16(mcs_map);
5675}
5676
5677static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
5678 u32 bw_cap[2], u32 nchain)
5679{
5680 __le16 mcs_map;
5681
5682 /* not allowed in 2.4G band */
5683 if (band->band == IEEE80211_BAND_2GHZ)
5684 return;
5685
5686 band->vht_cap.vht_supported = true;
5687 /* 80MHz is mandatory */
5688 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5689 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5690 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5691 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5692 }
5693 /* all support 256-QAM */
5694 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5695 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5696 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
5697}
5698
Arend van Sprielb48d8912014-07-12 08:49:41 +02005699static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005700{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005701 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07005702 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02005703 u32 nmode = 0;
5704 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005705 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01005706 u32 rxchain;
5707 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005708 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005709 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01005710 struct ieee80211_supported_band *band;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005711
Arend van Spriel18d6c532014-05-12 10:47:35 +02005712 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02005713 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5714 if (err) {
5715 brcmf_err("nmode error (%d)\n", err);
5716 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005717 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005718 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005719 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5720 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5721 bw_cap[IEEE80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02005722
Daniel Kim4aca7a12014-02-25 20:30:36 +01005723 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5724 if (err) {
5725 brcmf_err("rxchain error (%d)\n", err);
5726 nchain = 1;
5727 } else {
5728 for (nchain = 0; rxchain; nchain++)
5729 rxchain = rxchain & (rxchain - 1);
5730 }
5731 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5732
Arend van Sprielb48d8912014-07-12 08:49:41 +02005733 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005734 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005735 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02005736 return err;
5737 }
5738
Arend van Sprielb48d8912014-07-12 08:49:41 +02005739 wiphy = cfg_to_wiphy(cfg);
5740 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5741 band = wiphy->bands[i];
5742 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01005743 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02005744
Arend van Spriel18d6c532014-05-12 10:47:35 +02005745 if (nmode)
5746 brcmf_update_ht_cap(band, bw_cap, nchain);
5747 if (vhtmode)
5748 brcmf_update_vht_cap(band, bw_cap, nchain);
Hante Meulemand48200b2013-04-03 12:40:29 +02005749 }
5750
Arend van Sprielb48d8912014-07-12 08:49:41 +02005751 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005752}
5753
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005754static const struct ieee80211_txrx_stypes
5755brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5756 [NL80211_IFTYPE_STATION] = {
5757 .tx = 0xffff,
5758 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5759 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5760 },
5761 [NL80211_IFTYPE_P2P_CLIENT] = {
5762 .tx = 0xffff,
5763 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5764 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5765 },
5766 [NL80211_IFTYPE_P2P_GO] = {
5767 .tx = 0xffff,
5768 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5769 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5770 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5771 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5772 BIT(IEEE80211_STYPE_AUTH >> 4) |
5773 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5774 BIT(IEEE80211_STYPE_ACTION >> 4)
5775 },
5776 [NL80211_IFTYPE_P2P_DEVICE] = {
5777 .tx = 0xffff,
5778 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5779 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5780 }
5781};
5782
Arend van Spriel0882dda2015-08-20 22:06:03 +02005783/**
5784 * brcmf_setup_ifmodes() - determine interface modes and combinations.
5785 *
5786 * @wiphy: wiphy object.
5787 * @ifp: interface object needed for feat module api.
5788 *
5789 * The interface modes and combinations are determined dynamically here
5790 * based on firmware functionality.
5791 *
5792 * no p2p and no mbss:
5793 *
5794 * #STA <= 1, #AP <= 1, channels = 1, 2 total
5795 *
5796 * no p2p and mbss:
5797 *
5798 * #STA <= 1, #AP <= 1, channels = 1, 2 total
5799 * #AP <= 4, matching BI, channels = 1, 4 total
5800 *
5801 * p2p, no mchan, and mbss:
5802 *
5803 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
5804 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
5805 * #AP <= 4, matching BI, channels = 1, 4 total
5806 *
5807 * p2p, mchan, and mbss:
5808 *
5809 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
5810 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
5811 * #AP <= 4, matching BI, channels = 1, 4 total
5812 */
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005813static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
5814{
5815 struct ieee80211_iface_combination *combo = NULL;
Arend van Spriel0882dda2015-08-20 22:06:03 +02005816 struct ieee80211_iface_limit *c0_limits = NULL;
5817 struct ieee80211_iface_limit *p2p_limits = NULL;
5818 struct ieee80211_iface_limit *mbss_limits = NULL;
5819 bool mbss, p2p;
5820 int i, c, n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005821
Arend van Spriel0882dda2015-08-20 22:06:03 +02005822 mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
5823 p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
5824
5825 n_combos = 1 + !!p2p + !!mbss;
5826 combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005827 if (!combo)
5828 goto err;
5829
Arend van Spriel0882dda2015-08-20 22:06:03 +02005830 c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
5831 if (!c0_limits)
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005832 goto err;
5833
Arend van Spriel0882dda2015-08-20 22:06:03 +02005834 if (p2p) {
5835 p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
5836 if (!p2p_limits)
5837 goto err;
5838 }
5839
5840 if (mbss) {
5841 mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
5842 if (!mbss_limits)
5843 goto err;
5844 }
5845
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005846 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
5847 BIT(NL80211_IFTYPE_ADHOC) |
5848 BIT(NL80211_IFTYPE_AP);
5849
Arend van Spriel0882dda2015-08-20 22:06:03 +02005850 c = 0;
5851 i = 0;
5852 combo[c].num_different_channels = 1;
5853 c0_limits[i].max = 1;
5854 c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
5855 if (p2p) {
5856 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
5857 combo[c].num_different_channels = 2;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005858 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
5859 BIT(NL80211_IFTYPE_P2P_GO) |
5860 BIT(NL80211_IFTYPE_P2P_DEVICE);
Arend van Spriel0882dda2015-08-20 22:06:03 +02005861 c0_limits[i].max = 1;
5862 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
5863 c0_limits[i].max = 1;
5864 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
5865 BIT(NL80211_IFTYPE_P2P_GO);
5866 } else {
5867 c0_limits[i].max = 1;
5868 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005869 }
Arend van Spriel0882dda2015-08-20 22:06:03 +02005870 combo[c].max_interfaces = i;
5871 combo[c].n_limits = i;
5872 combo[c].limits = c0_limits;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005873
Arend van Spriel0882dda2015-08-20 22:06:03 +02005874 if (p2p) {
5875 c++;
5876 i = 0;
5877 combo[c].num_different_channels = 1;
5878 p2p_limits[i].max = 1;
5879 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
5880 p2p_limits[i].max = 1;
5881 p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
5882 p2p_limits[i].max = 1;
5883 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
5884 p2p_limits[i].max = 1;
5885 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
5886 combo[c].max_interfaces = i;
5887 combo[c].n_limits = i;
5888 combo[c].limits = p2p_limits;
5889 }
5890
5891 if (mbss) {
5892 c++;
5893 combo[c].beacon_int_infra_match = true;
5894 combo[c].num_different_channels = 1;
5895 mbss_limits[0].max = 4;
5896 mbss_limits[0].types = BIT(NL80211_IFTYPE_AP);
5897 combo[c].max_interfaces = 4;
5898 combo[c].n_limits = 1;
5899 combo[c].limits = mbss_limits;
5900 }
5901 wiphy->n_iface_combinations = n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005902 wiphy->iface_combinations = combo;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005903 return 0;
5904
5905err:
Arend van Spriel0882dda2015-08-20 22:06:03 +02005906 kfree(c0_limits);
5907 kfree(p2p_limits);
5908 kfree(mbss_limits);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005909 kfree(combo);
5910 return -ENOMEM;
5911}
5912
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005913static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
5914{
5915 /* scheduled scan settings */
5916 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
5917 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
5918 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5919 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
5920}
5921
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005922#ifdef CONFIG_PM
5923static const struct wiphy_wowlan_support brcmf_wowlan_support = {
5924 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01005925 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
5926 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
5927 .pattern_min_len = 1,
5928 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005929};
5930#endif
5931
5932static void brcmf_wiphy_wowl_params(struct wiphy *wiphy)
5933{
5934#ifdef CONFIG_PM
5935 /* wowl settings */
5936 wiphy->wowlan = &brcmf_wowlan_support;
5937#endif
5938}
5939
Arend van Sprielb48d8912014-07-12 08:49:41 +02005940static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005941{
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02005942 struct brcmf_pub *drvr = ifp->drvr;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02005943 const struct ieee80211_iface_combination *combo;
Arend van Spriel58de92d2015-04-14 20:10:24 +02005944 struct ieee80211_supported_band *band;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02005945 u16 max_interfaces = 0;
Arend van Spriel58de92d2015-04-14 20:10:24 +02005946 __le32 bandlist[3];
5947 u32 n_bands;
5948 int err, i;
5949
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005950 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
5951 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5952 wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02005953
5954 err = brcmf_setup_ifmodes(wiphy, ifp);
5955 if (err)
5956 return err;
5957
Rafał Miłecki50f32e22015-08-20 00:16:42 +02005958 for (i = 0, combo = wiphy->iface_combinations;
5959 i < wiphy->n_iface_combinations; i++, combo++) {
5960 max_interfaces = max(max_interfaces, combo->max_interfaces);
5961 }
5962
5963 for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
5964 i++) {
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02005965 u8 *addr = drvr->addresses[i].addr;
5966
5967 memcpy(addr, drvr->mac, ETH_ALEN);
5968 if (i) {
5969 addr[0] |= BIT(1);
5970 addr[ETH_ALEN - 1] ^= i;
5971 }
5972 }
5973 wiphy->addresses = drvr->addresses;
5974 wiphy->n_addresses = i;
5975
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005976 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
5977 wiphy->cipher_suites = __wl_cipher_suites;
5978 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
5979 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
5980 WIPHY_FLAG_OFFCHAN_TX |
5981 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5982 WIPHY_FLAG_SUPPORTS_TDLS;
5983 if (!brcmf_roamoff)
5984 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
5985 wiphy->mgmt_stypes = brcmf_txrx_stypes;
5986 wiphy->max_remain_on_channel_duration = 5000;
Arend van Spriel7a7a87d2015-04-14 20:10:27 +02005987 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
5988 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005989
5990 /* vendor commands/events support */
5991 wiphy->vendor_commands = brcmf_vendor_cmds;
5992 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
5993
Hante Meuleman4eb3af72014-09-30 10:23:18 +02005994 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
5995 brcmf_wiphy_wowl_params(wiphy);
5996
Arend van Spriel58de92d2015-04-14 20:10:24 +02005997 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
5998 sizeof(bandlist));
5999 if (err) {
6000 brcmf_err("could not obtain band info: err=%d\n", err);
6001 return err;
6002 }
6003 /* first entry in bandlist is number of bands */
6004 n_bands = le32_to_cpu(bandlist[0]);
6005 for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
6006 if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
6007 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
6008 GFP_KERNEL);
6009 if (!band)
6010 return -ENOMEM;
6011
6012 band->channels = kmemdup(&__wl_2ghz_channels,
6013 sizeof(__wl_2ghz_channels),
6014 GFP_KERNEL);
6015 if (!band->channels) {
6016 kfree(band);
6017 return -ENOMEM;
6018 }
6019
6020 band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
6021 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6022 }
6023 if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
6024 band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
6025 GFP_KERNEL);
6026 if (!band)
6027 return -ENOMEM;
6028
6029 band->channels = kmemdup(&__wl_5ghz_channels,
6030 sizeof(__wl_5ghz_channels),
6031 GFP_KERNEL);
6032 if (!band->channels) {
6033 kfree(band);
6034 return -ENOMEM;
6035 }
6036
6037 band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
6038 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6039 }
6040 }
6041 err = brcmf_setup_wiphybands(wiphy);
6042 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006043}
6044
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006045static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006046{
6047 struct net_device *ndev;
6048 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01006049 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006050 s32 power_mode;
6051 s32 err = 0;
6052
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006053 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006054 return err;
6055
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006056 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006057 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01006058 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006059
Hante Meuleman40a23292013-01-02 15:22:51 +01006060 /* make sure RF is ready for work */
6061 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
6062
6063 brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME,
6064 WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006065
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006066 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01006067 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006068 if (err)
6069 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01006070 brcmf_dbg(INFO, "power save set to %s\n",
6071 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02006072
Hante Meuleman68ca3952014-02-25 20:30:26 +01006073 err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006074 if (err)
6075 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07006076 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
6077 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01006078 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006079 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006080
Hante Meulemanb3657452013-05-27 21:09:53 +02006081 brcmf_configure_arp_offload(ifp, true);
6082
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006083 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01006084default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02006085
6086 return err;
6087
6088}
6089
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006090static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006091{
Arend van Sprielc1179032012-10-22 13:55:33 -07006092 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006093
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006094 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006095}
6096
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006097static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006098{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006099 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07006100
Arend van Spriel5b435de2011-10-05 13:19:03 +02006101 /*
6102 * While going down, if associated with AP disassociate
6103 * from AP to save power
6104 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01006105 if (check_vif_up(ifp->vif)) {
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01006106 brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006107
6108 /* Make sure WPA_Supplicant receives all the event
6109 generated due to DISASSOC call to the fw to keep
6110 the state fw and WPA_Supplicant state consistent
6111 */
6112 brcmf_delay(500);
6113 }
6114
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006115 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07006116 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006117
Arend van Spriel5b435de2011-10-05 13:19:03 +02006118 return 0;
6119}
6120
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006121s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006122{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006123 struct brcmf_if *ifp = netdev_priv(ndev);
6124 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006125 s32 err = 0;
6126
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006127 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006128 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006129 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006130
6131 return err;
6132}
6133
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006134s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006135{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006136 struct brcmf_if *ifp = netdev_priv(ndev);
6137 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006138 s32 err = 0;
6139
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006140 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006141 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006142 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006143
6144 return err;
6145}
6146
Arend van Spriela7965fb2013-04-11 17:08:37 +02006147enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
6148{
6149 struct wireless_dev *wdev = &ifp->vif->wdev;
6150
6151 return wdev->iftype;
6152}
6153
Hante Meulemanbfe81972014-10-28 14:56:16 +01006154bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
6155 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01006156{
6157 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006158
6159 list_for_each_entry(vif, &cfg->vif_list, list) {
6160 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006161 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006162 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006163 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006164}
Arend van Sprield3c0b632013-02-08 15:53:37 +01006165
6166static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
6167 u8 action)
6168{
6169 u8 evt_action;
6170
6171 mutex_lock(&event->vif_event_lock);
6172 evt_action = event->action;
6173 mutex_unlock(&event->vif_event_lock);
6174 return evt_action == action;
6175}
6176
6177void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
6178 struct brcmf_cfg80211_vif *vif)
6179{
6180 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6181
6182 mutex_lock(&event->vif_event_lock);
6183 event->vif = vif;
6184 event->action = 0;
6185 mutex_unlock(&event->vif_event_lock);
6186}
6187
6188bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
6189{
6190 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6191 bool armed;
6192
6193 mutex_lock(&event->vif_event_lock);
6194 armed = event->vif != NULL;
6195 mutex_unlock(&event->vif_event_lock);
6196
6197 return armed;
6198}
6199int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
6200 u8 action, ulong timeout)
6201{
6202 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6203
6204 return wait_event_timeout(event->vif_wq,
6205 vif_event_equals(event, action), timeout);
6206}
6207
Arend van Spriel63db1a42014-12-21 12:43:51 +01006208static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
6209 struct regulatory_request *req)
6210{
6211 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6212 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6213 struct brcmf_fil_country_le ccreq;
6214 int i;
6215
6216 brcmf_dbg(TRACE, "enter: initiator=%d, alpha=%c%c\n", req->initiator,
6217 req->alpha2[0], req->alpha2[1]);
6218
6219 /* ignore non-ISO3166 country codes */
6220 for (i = 0; i < sizeof(req->alpha2); i++)
6221 if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
6222 brcmf_err("not a ISO3166 code\n");
6223 return;
6224 }
6225 memset(&ccreq, 0, sizeof(ccreq));
6226 ccreq.rev = cpu_to_le32(-1);
6227 memcpy(ccreq.ccode, req->alpha2, sizeof(req->alpha2));
Arend van Spriel8afe0ec2015-04-14 20:10:25 +02006228 if (brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq))) {
6229 brcmf_err("firmware rejected country setting\n");
6230 return;
6231 }
6232 brcmf_setup_wiphybands(wiphy);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006233}
6234
Arend van Sprielb48d8912014-07-12 08:49:41 +02006235static void brcmf_free_wiphy(struct wiphy *wiphy)
6236{
Arend van Spriel0882dda2015-08-20 22:06:03 +02006237 int i;
6238
Arend van Spriel58de92d2015-04-14 20:10:24 +02006239 if (!wiphy)
6240 return;
6241
Arend van Spriel0882dda2015-08-20 22:06:03 +02006242 if (wiphy->iface_combinations) {
6243 for (i = 0; i < wiphy->n_iface_combinations; i++)
6244 kfree(wiphy->iface_combinations[i].limits);
6245 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006246 kfree(wiphy->iface_combinations);
6247 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
6248 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
6249 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
6250 }
6251 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
6252 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
6253 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
6254 }
6255 wiphy_free(wiphy);
6256}
6257
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006258struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006259 struct device *busdev,
6260 bool p2pdev_forced)
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006261{
Arend van Spriel46f3b6e2015-08-26 22:14:58 +02006262 struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006263 struct brcmf_cfg80211_info *cfg;
6264 struct wiphy *wiphy;
6265 struct brcmf_cfg80211_vif *vif;
6266 struct brcmf_if *ifp;
6267 s32 err = 0;
6268 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006269 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006270
6271 if (!ndev) {
6272 brcmf_err("ndev is invalid\n");
6273 return NULL;
6274 }
6275
6276 ifp = netdev_priv(ndev);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006277 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
6278 if (!wiphy) {
6279 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006280 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006281 }
Rafał Miłecki6896f4f2015-05-31 02:52:26 +02006282 memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006283 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006284
6285 cfg = wiphy_priv(wiphy);
6286 cfg->wiphy = wiphy;
6287 cfg->pub = drvr;
6288 init_vif_event(&cfg->vif_event);
6289 INIT_LIST_HEAD(&cfg->vif_list);
6290
6291 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006292 if (IS_ERR(vif))
6293 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006294
6295 vif->ifp = ifp;
6296 vif->wdev.netdev = ndev;
6297 ndev->ieee80211_ptr = &vif->wdev;
6298 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
6299
6300 err = wl_init_priv(cfg);
6301 if (err) {
6302 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006303 brcmf_free_vif(vif);
6304 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006305 }
6306 ifp->vif = vif;
6307
Arend van Sprielb48d8912014-07-12 08:49:41 +02006308 /* determine d11 io type before wiphy setup */
6309 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006310 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006311 brcmf_err("Failed to get D11 version (%d)\n", err);
6312 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006313 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006314 cfg->d11inf.io_type = (u8)io_type;
6315 brcmu_d11_attach(&cfg->d11inf);
6316
6317 err = brcmf_setup_wiphy(wiphy, ifp);
6318 if (err < 0)
6319 goto priv_out;
6320
6321 brcmf_dbg(INFO, "Registering custom regulatory\n");
Arend van Spriel63db1a42014-12-21 12:43:51 +01006322 wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006323 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
6324 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
6325
6326 /* firmware defaults to 40MHz disabled in 2G band. We signal
6327 * cfg80211 here that we do and have it decide we can enable
6328 * it. But first check if device does support 2G operation.
6329 */
6330 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
6331 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
6332 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6333 }
6334 err = wiphy_register(wiphy);
6335 if (err < 0) {
6336 brcmf_err("Could not register wiphy device (%d)\n", err);
6337 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006338 }
6339
6340 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
6341 * setup 40MHz in 2GHz band and enable OBSS scanning.
6342 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02006343 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
6344 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006345 if (!err)
6346 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
6347 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006348 else
6349 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006350 }
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006351 /* p2p might require that "if-events" get processed by fweh. So
6352 * activate the already registered event handlers now and activate
6353 * the rest when initialization has completed. drvr->config needs to
6354 * be assigned before activating events.
6355 */
6356 drvr->config = cfg;
6357 err = brcmf_fweh_activate_events(ifp);
6358 if (err) {
6359 brcmf_err("FWEH activation failed (%d)\n", err);
6360 goto wiphy_unreg_out;
6361 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006362
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006363 err = brcmf_p2p_attach(cfg, p2pdev_forced);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006364 if (err) {
6365 brcmf_err("P2P initilisation failed (%d)\n", err);
6366 goto wiphy_unreg_out;
6367 }
6368 err = brcmf_btcoex_attach(cfg);
6369 if (err) {
6370 brcmf_err("BT-coex initialisation failed (%d)\n", err);
6371 brcmf_p2p_detach(&cfg->p2p);
6372 goto wiphy_unreg_out;
6373 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006374
6375 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
6376 if (err) {
6377 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
6378 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman70b7d942014-07-30 13:20:07 +02006379 } else {
6380 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
6381 brcmf_notify_tdls_peer_event);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006382 }
6383
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006384 /* (re-) activate FWEH event handling */
6385 err = brcmf_fweh_activate_events(ifp);
6386 if (err) {
6387 brcmf_err("FWEH activation failed (%d)\n", err);
6388 goto wiphy_unreg_out;
6389 }
6390
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006391 return cfg;
6392
Arend van Sprielb48d8912014-07-12 08:49:41 +02006393wiphy_unreg_out:
6394 wiphy_unregister(cfg->wiphy);
6395priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006396 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006397 brcmf_free_vif(vif);
Hante Meuleman2b5d3482015-09-18 22:08:04 +02006398 ifp->vif = NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006399wiphy_out:
6400 brcmf_free_wiphy(wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006401 return NULL;
6402}
6403
6404void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
6405{
6406 if (!cfg)
6407 return;
6408
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006409 brcmf_btcoex_detach(cfg);
Arend van Sprielf7a40872015-06-11 00:12:23 +02006410 wiphy_unregister(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006411 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006412 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006413}