blob: 6cc8fdc9fcc81edda84957cc45b27f7d1c841380 [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
Hante Meuleman1678ba82015-12-10 13:43:00 +010094#define BRCMF_SCAN_CHANNEL_TIME 40
95#define BRCMF_SCAN_UNASSOC_TIME 40
96#define BRCMF_SCAN_PASSIVE_TIME 120
97
Hante Meuleman3021ad92016-01-05 11:05:45 +010098#define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000)
99
Arend van Spriel5b435de2011-10-05 13:19:03 +0200100#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
101 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
102
Arend van Sprielce81e312012-10-22 13:55:37 -0700103static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200104{
Arend van Sprielc1179032012-10-22 13:55:33 -0700105 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100106 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
107 vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200108 return false;
109 }
110 return true;
111}
112
Arend van Spriel5b435de2011-10-05 13:19:03 +0200113#define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
114#define RATETAB_ENT(_rateid, _flags) \
115 { \
116 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
117 .hw_value = (_rateid), \
118 .flags = (_flags), \
119 }
120
121static struct ieee80211_rate __wl_rates[] = {
122 RATETAB_ENT(BRCM_RATE_1M, 0),
123 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
124 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
125 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
126 RATETAB_ENT(BRCM_RATE_6M, 0),
127 RATETAB_ENT(BRCM_RATE_9M, 0),
128 RATETAB_ENT(BRCM_RATE_12M, 0),
129 RATETAB_ENT(BRCM_RATE_18M, 0),
130 RATETAB_ENT(BRCM_RATE_24M, 0),
131 RATETAB_ENT(BRCM_RATE_36M, 0),
132 RATETAB_ENT(BRCM_RATE_48M, 0),
133 RATETAB_ENT(BRCM_RATE_54M, 0),
134};
135
Arend van Spriel5b435de2011-10-05 13:19:03 +0200136#define wl_g_rates (__wl_rates + 0)
Arend van Spriel58de92d2015-04-14 20:10:24 +0200137#define wl_g_rates_size ARRAY_SIZE(__wl_rates)
138#define wl_a_rates (__wl_rates + 4)
139#define wl_a_rates_size (wl_g_rates_size - 4)
140
141#define CHAN2G(_channel, _freq) { \
142 .band = IEEE80211_BAND_2GHZ, \
143 .center_freq = (_freq), \
144 .hw_value = (_channel), \
145 .flags = IEEE80211_CHAN_DISABLED, \
146 .max_antenna_gain = 0, \
147 .max_power = 30, \
148}
149
150#define CHAN5G(_channel) { \
151 .band = IEEE80211_BAND_5GHZ, \
152 .center_freq = 5000 + (5 * (_channel)), \
153 .hw_value = (_channel), \
154 .flags = IEEE80211_CHAN_DISABLED, \
155 .max_antenna_gain = 0, \
156 .max_power = 30, \
157}
158
159static struct ieee80211_channel __wl_2ghz_channels[] = {
160 CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427),
161 CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447),
162 CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467),
163 CHAN2G(13, 2472), CHAN2G(14, 2484)
164};
165
166static struct ieee80211_channel __wl_5ghz_channels[] = {
167 CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42),
168 CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56),
169 CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108),
170 CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128),
171 CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149),
172 CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165)
173};
Arend van Spriel5b435de2011-10-05 13:19:03 +0200174
Arend van Sprielb48d8912014-07-12 08:49:41 +0200175/* Band templates duplicated per wiphy. The channel info
Arend van Spriel58de92d2015-04-14 20:10:24 +0200176 * above is added to the band during setup.
Arend van Sprielb48d8912014-07-12 08:49:41 +0200177 */
178static const struct ieee80211_supported_band __wl_band_2ghz = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200179 .band = IEEE80211_BAND_2GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200180 .bitrates = wl_g_rates,
181 .n_bitrates = wl_g_rates_size,
182};
183
Arend van Spriel58de92d2015-04-14 20:10:24 +0200184static const struct ieee80211_supported_band __wl_band_5ghz = {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200185 .band = IEEE80211_BAND_5GHZ,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200186 .bitrates = wl_a_rates,
187 .n_bitrates = wl_a_rates_size,
188};
189
Hante Meulemand48200b2013-04-03 12:40:29 +0200190/* This is to override regulatory domains defined in cfg80211 module (reg.c)
191 * By default world regulatory domain defined in reg.c puts the flags
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200192 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
193 * With respect to these flags, wpa_supplicant doesn't * start p2p
194 * operations on 5GHz channels. All the changes in world regulatory
Hante Meulemand48200b2013-04-03 12:40:29 +0200195 * domain are to be done here.
196 */
197static const struct ieee80211_regdomain brcmf_regdom = {
198 .n_reg_rules = 4,
199 .alpha2 = "99",
200 .reg_rules = {
201 /* IEEE 802.11b/g, channels 1..11 */
202 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
203 /* If any */
204 /* IEEE 802.11 channel 14 - Only JP enables
205 * this and for 802.11b only
206 */
207 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
208 /* IEEE 802.11a, channel 36..64 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200209 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
Hante Meulemand48200b2013-04-03 12:40:29 +0200210 /* IEEE 802.11a, channel 100..165 */
Arend van Sprielc555ecd2014-05-12 10:47:36 +0200211 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200212};
213
214static const u32 __wl_cipher_suites[] = {
215 WLAN_CIPHER_SUITE_WEP40,
216 WLAN_CIPHER_SUITE_WEP104,
217 WLAN_CIPHER_SUITE_TKIP,
218 WLAN_CIPHER_SUITE_CCMP,
219 WLAN_CIPHER_SUITE_AES_CMAC,
220};
221
Hante Meuleman1a873342012-09-27 14:17:54 +0200222/* Vendor specific ie. id = 221, oui and type defines exact ie */
223struct brcmf_vs_tlv {
224 u8 id;
225 u8 len;
226 u8 oui[3];
227 u8 oui_type;
228};
229
230struct parsed_vndr_ie_info {
231 u8 *ie_ptr;
232 u32 ie_len; /* total length including id & length field */
233 struct brcmf_vs_tlv vndrie;
234};
235
236struct parsed_vndr_ies {
237 u32 count;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100238 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
Hante Meuleman1a873342012-09-27 14:17:54 +0200239};
240
Arend van Spriel5a394eb2014-05-27 12:56:15 +0200241static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
242 struct cfg80211_chan_def *ch)
Arend van Spriel600a8972014-05-12 10:47:39 +0200243{
244 struct brcmu_chan ch_inf;
245 s32 primary_offset;
246
247 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
248 ch->chan->center_freq, ch->center_freq1, ch->width);
249 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
Rafał Miłecki36e80722016-01-20 16:46:04 +0100250 primary_offset = ch->chan->center_freq - ch->center_freq1;
Arend van Spriel600a8972014-05-12 10:47:39 +0200251 switch (ch->width) {
252 case NL80211_CHAN_WIDTH_20:
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100253 case NL80211_CHAN_WIDTH_20_NOHT:
Arend van Spriel600a8972014-05-12 10:47:39 +0200254 ch_inf.bw = BRCMU_CHAN_BW_20;
255 WARN_ON(primary_offset != 0);
256 break;
257 case NL80211_CHAN_WIDTH_40:
258 ch_inf.bw = BRCMU_CHAN_BW_40;
Rafał Miłecki36e80722016-01-20 16:46:04 +0100259 if (primary_offset > 0)
Arend van Spriel600a8972014-05-12 10:47:39 +0200260 ch_inf.sb = BRCMU_CHAN_SB_U;
261 else
262 ch_inf.sb = BRCMU_CHAN_SB_L;
263 break;
264 case NL80211_CHAN_WIDTH_80:
265 ch_inf.bw = BRCMU_CHAN_BW_80;
Rafał Miłecki36e80722016-01-20 16:46:04 +0100266 if (primary_offset == -30)
267 ch_inf.sb = BRCMU_CHAN_SB_LL;
268 else if (primary_offset == -10)
269 ch_inf.sb = BRCMU_CHAN_SB_LU;
270 else if (primary_offset == 10)
271 ch_inf.sb = BRCMU_CHAN_SB_UL;
272 else
273 ch_inf.sb = BRCMU_CHAN_SB_UU;
Arend van Spriel600a8972014-05-12 10:47:39 +0200274 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100275 case NL80211_CHAN_WIDTH_80P80:
276 case NL80211_CHAN_WIDTH_160:
277 case NL80211_CHAN_WIDTH_5:
278 case NL80211_CHAN_WIDTH_10:
Arend van Spriel600a8972014-05-12 10:47:39 +0200279 default:
280 WARN_ON_ONCE(1);
281 }
282 switch (ch->chan->band) {
283 case IEEE80211_BAND_2GHZ:
284 ch_inf.band = BRCMU_CHAN_BAND_2G;
285 break;
286 case IEEE80211_BAND_5GHZ:
287 ch_inf.band = BRCMU_CHAN_BAND_5G;
288 break;
Arend van Spriel0cd75b12014-11-11 13:58:44 +0100289 case IEEE80211_BAND_60GHZ:
Arend van Spriel600a8972014-05-12 10:47:39 +0200290 default:
291 WARN_ON_ONCE(1);
292 }
293 d11inf->encchspec(&ch_inf);
294
295 return ch_inf.chspec;
296}
297
Franky Lin83cf17a2013-04-11 13:28:50 +0200298u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
299 struct ieee80211_channel *ch)
Arend van Spriel6e186162012-10-22 10:36:22 -0700300{
Franky Lin83cf17a2013-04-11 13:28:50 +0200301 struct brcmu_chan ch_inf;
Arend van Spriel6e186162012-10-22 10:36:22 -0700302
Franky Lin83cf17a2013-04-11 13:28:50 +0200303 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
304 ch_inf.bw = BRCMU_CHAN_BW_20;
305 d11inf->encchspec(&ch_inf);
Arend van Spriel6e186162012-10-22 10:36:22 -0700306
Franky Lin83cf17a2013-04-11 13:28:50 +0200307 return ch_inf.chspec;
Arend van Spriel6e186162012-10-22 10:36:22 -0700308}
309
Hante Meuleman89286dc2013-02-08 15:53:46 +0100310/* Traverse a string of 1-byte tag/1-byte length/variable-length value
311 * triples, returning a pointer to the substring whose first element
312 * matches tag
313 */
Johannes Berg4b5800f2014-01-15 14:55:59 +0100314const struct brcmf_tlv *
315brcmf_parse_tlvs(const void *buf, int buflen, uint key)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100316{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100317 const struct brcmf_tlv *elt = buf;
318 int totlen = buflen;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100319
320 /* find tagged parameter */
321 while (totlen >= TLV_HDR_LEN) {
322 int len = elt->len;
323
324 /* validate remaining totlen */
325 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
326 return elt;
327
328 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
329 totlen -= (len + TLV_HDR_LEN);
330 }
331
332 return NULL;
333}
334
335/* Is any of the tlvs the expected entry? If
336 * not update the tlvs buffer pointer/length.
337 */
338static bool
Johannes Berg4b5800f2014-01-15 14:55:59 +0100339brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
340 const u8 *oui, u32 oui_len, u8 type)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100341{
342 /* If the contents match the OUI and the type */
343 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
344 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
345 type == ie[TLV_BODY_OFF + oui_len]) {
346 return true;
347 }
348
349 if (tlvs == NULL)
350 return false;
351 /* point to the next ie */
352 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
353 /* calculate the length of the rest of the buffer */
354 *tlvs_len -= (int)(ie - *tlvs);
355 /* update the pointer to the start of the buffer */
356 *tlvs = ie;
357
358 return false;
359}
360
361static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100362brcmf_find_wpaie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100363{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100364 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100365
366 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
Johannes Berg4b5800f2014-01-15 14:55:59 +0100367 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
Hante Meuleman89286dc2013-02-08 15:53:46 +0100368 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
369 return (struct brcmf_vs_tlv *)ie;
370 }
371 return NULL;
372}
373
374static struct brcmf_vs_tlv *
Johannes Berg4b5800f2014-01-15 14:55:59 +0100375brcmf_find_wpsie(const u8 *parse, u32 len)
Hante Meuleman89286dc2013-02-08 15:53:46 +0100376{
Johannes Berg4b5800f2014-01-15 14:55:59 +0100377 const struct brcmf_tlv *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +0100378
379 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
380 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
381 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
382 return (struct brcmf_vs_tlv *)ie;
383 }
384 return NULL;
385}
386
Arend van Spriel39504a22015-08-20 22:06:05 +0200387static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
388 struct brcmf_cfg80211_vif *vif,
389 enum nl80211_iftype new_type)
390{
391 int iftype_num[NUM_NL80211_IFTYPES];
392 struct brcmf_cfg80211_vif *pos;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100393 bool check_combos = false;
394 int ret = 0;
Arend van Spriel39504a22015-08-20 22:06:05 +0200395
396 memset(&iftype_num[0], 0, sizeof(iftype_num));
397 list_for_each_entry(pos, &cfg->vif_list, list)
Arend van Spriel353c46a2015-12-10 13:43:06 +0100398 if (pos == vif) {
Arend van Spriel39504a22015-08-20 22:06:05 +0200399 iftype_num[new_type]++;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100400 } else {
401 /* concurrent interfaces so need check combinations */
402 check_combos = true;
Arend van Spriel39504a22015-08-20 22:06:05 +0200403 iftype_num[pos->wdev.iftype]++;
Arend van Spriel353c46a2015-12-10 13:43:06 +0100404 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200405
Arend van Spriel353c46a2015-12-10 13:43:06 +0100406 if (check_combos)
407 ret = cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
408
409 return ret;
Arend van Spriel39504a22015-08-20 22:06:05 +0200410}
411
412static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
413 enum nl80211_iftype new_type)
414{
415 int iftype_num[NUM_NL80211_IFTYPES];
416 struct brcmf_cfg80211_vif *pos;
417
418 memset(&iftype_num[0], 0, sizeof(iftype_num));
419 list_for_each_entry(pos, &cfg->vif_list, list)
420 iftype_num[pos->wdev.iftype]++;
421
422 iftype_num[new_type]++;
423 return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
424}
Hante Meuleman89286dc2013-02-08 15:53:46 +0100425
Arend van Spriel5b435de2011-10-05 13:19:03 +0200426static void convert_key_from_CPU(struct brcmf_wsec_key *key,
427 struct brcmf_wsec_key_le *key_le)
428{
429 key_le->index = cpu_to_le32(key->index);
430 key_le->len = cpu_to_le32(key->len);
431 key_le->algo = cpu_to_le32(key->algo);
432 key_le->flags = cpu_to_le32(key->flags);
433 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
434 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
435 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
436 memcpy(key_le->data, key->data, sizeof(key->data));
437 memcpy(key_le->ea, key->ea, sizeof(key->ea));
438}
439
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200440static int
Hante Meuleman118eb302014-12-21 12:43:49 +0100441send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200442{
443 int err;
444 struct brcmf_wsec_key_le key_le;
445
446 convert_key_from_CPU(key, &key_le);
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200447
Hante Meuleman118eb302014-12-21 12:43:49 +0100448 brcmf_netdev_wait_pend8021x(ifp);
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700449
Hante Meuleman118eb302014-12-21 12:43:49 +0100450 err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -0700451 sizeof(key_le));
Hante Meulemanf09d0c02012-09-27 14:17:48 +0200452
Arend van Spriel5b435de2011-10-05 13:19:03 +0200453 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +0100454 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200455 return err;
456}
457
Hante Meulemanb3657452013-05-27 21:09:53 +0200458static s32
459brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable)
460{
461 s32 err;
462 u32 mode;
463
464 if (enable)
465 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
466 else
467 mode = 0;
468
469 /* Try to set and enable ARP offload feature, this may fail, then it */
470 /* is simply not supported and err 0 will be returned */
471 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
472 if (err) {
473 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
474 mode, err);
475 err = 0;
476 } else {
477 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
478 if (err) {
479 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
480 enable, err);
481 err = 0;
482 } else
483 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
484 enable, mode);
485 }
486
487 return err;
488}
489
Hante Meuleman8851cce2014-07-30 13:20:02 +0200490static void
491brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
492{
Arend van Spriel8f2b4592014-09-11 22:51:32 +0200493 struct brcmf_cfg80211_vif *vif;
494 struct brcmf_if *ifp;
495
496 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
497 ifp = vif->ifp;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200498
499 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
500 (wdev->iftype == NL80211_IFTYPE_AP) ||
501 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
502 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
503 ADDR_DIRECT);
504 else
505 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
506 ADDR_INDIRECT);
507}
508
Hante Meulemana44aa402014-12-03 21:05:33 +0100509static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
510{
511 struct brcmf_mbss_ssid_le mbss_ssid_le;
512 int bsscfgidx;
513 int err;
514
515 memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
516 bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr);
517 if (bsscfgidx < 0)
518 return bsscfgidx;
519
520 mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
521 mbss_ssid_le.SSID_len = cpu_to_le32(5);
522 sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
523
524 err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
525 sizeof(mbss_ssid_le));
526 if (err < 0)
527 brcmf_err("setting ssid failed %d\n", err);
528
529 return err;
530}
531
532/**
533 * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
534 *
535 * @wiphy: wiphy device of new interface.
536 * @name: name of the new interface.
537 * @flags: not used.
538 * @params: contains mac address for AP device.
539 */
540static
541struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
542 u32 *flags, struct vif_params *params)
543{
544 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
545 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
546 struct brcmf_cfg80211_vif *vif;
547 int err;
548
549 if (brcmf_cfg80211_vif_event_armed(cfg))
550 return ERR_PTR(-EBUSY);
551
552 brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
553
554 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false);
555 if (IS_ERR(vif))
556 return (struct wireless_dev *)vif;
557
558 brcmf_cfg80211_arm_vif_event(cfg, vif);
559
560 err = brcmf_cfg80211_request_ap_if(ifp);
561 if (err) {
562 brcmf_cfg80211_arm_vif_event(cfg, NULL);
563 goto fail;
564 }
565
566 /* wait for firmware event */
Arend van Spriela9eb0c42016-02-17 11:26:50 +0100567 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD,
568 BRCMF_VIF_EVENT_TIMEOUT);
Hante Meulemana44aa402014-12-03 21:05:33 +0100569 brcmf_cfg80211_arm_vif_event(cfg, NULL);
570 if (!err) {
571 brcmf_err("timeout occurred\n");
572 err = -EIO;
573 goto fail;
574 }
575
576 /* interface created in firmware */
577 ifp = vif->ifp;
578 if (!ifp) {
579 brcmf_err("no if pointer provided\n");
580 err = -ENOENT;
581 goto fail;
582 }
583
584 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
585 err = brcmf_net_attach(ifp, true);
586 if (err) {
587 brcmf_err("Registering netdevice failed\n");
588 goto fail;
589 }
590
591 return &ifp->vif->wdev;
592
593fail:
594 brcmf_free_vif(vif);
595 return ERR_PTR(err);
596}
597
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100598static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
599{
600 enum nl80211_iftype iftype;
601
602 iftype = vif->wdev.iftype;
603 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
604}
605
606static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
607{
608 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
609}
610
Arend van Spriel9f440b72013-02-08 15:53:36 +0100611static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
612 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100613 unsigned char name_assign_type,
Arend van Spriel9f440b72013-02-08 15:53:36 +0100614 enum nl80211_iftype type,
615 u32 *flags,
616 struct vif_params *params)
617{
Hante Meuleman8851cce2014-07-30 13:20:02 +0200618 struct wireless_dev *wdev;
Arend van Spriel39504a22015-08-20 22:06:05 +0200619 int err;
Hante Meuleman8851cce2014-07-30 13:20:02 +0200620
Arend van Spriel9f440b72013-02-08 15:53:36 +0100621 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
Arend van Spriel39504a22015-08-20 22:06:05 +0200622 err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
623 if (err) {
624 brcmf_err("iface validation failed: err=%d\n", err);
625 return ERR_PTR(err);
626 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100627 switch (type) {
628 case NL80211_IFTYPE_ADHOC:
629 case NL80211_IFTYPE_STATION:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100630 case NL80211_IFTYPE_AP_VLAN:
631 case NL80211_IFTYPE_WDS:
632 case NL80211_IFTYPE_MONITOR:
633 case NL80211_IFTYPE_MESH_POINT:
634 return ERR_PTR(-EOPNOTSUPP);
Hante Meulemana44aa402014-12-03 21:05:33 +0100635 case NL80211_IFTYPE_AP:
636 wdev = brcmf_ap_add_vif(wiphy, name, flags, params);
637 if (!IS_ERR(wdev))
638 brcmf_cfg80211_update_proto_addr_mode(wdev);
639 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100640 case NL80211_IFTYPE_P2P_CLIENT:
641 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200642 case NL80211_IFTYPE_P2P_DEVICE:
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100643 wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, flags, params);
Hante Meuleman8851cce2014-07-30 13:20:02 +0200644 if (!IS_ERR(wdev))
645 brcmf_cfg80211_update_proto_addr_mode(wdev);
646 return wdev;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100647 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100648 default:
649 return ERR_PTR(-EINVAL);
650 }
651}
652
Daniel Kim5e787f72014-06-21 12:11:18 +0200653static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
654{
Arend van Sprielc08437b2014-07-12 08:49:39 +0200655 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
Daniel Kim5e787f72014-06-21 12:11:18 +0200656 brcmf_set_mpc(ifp, mpc);
657}
658
Arend van Sprielf96aa072013-04-05 10:57:48 +0200659void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100660{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100661 s32 err = 0;
662
663 if (check_vif_up(ifp->vif)) {
664 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
665 if (err) {
666 brcmf_err("fail to set mpc\n");
667 return;
668 }
669 brcmf_dbg(INFO, "MPC : %d\n", mpc);
670 }
671}
672
Arend van Spriela0f472a2013-04-05 10:57:49 +0200673s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
674 struct brcmf_if *ifp, bool aborted,
675 bool fw_abort)
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100676{
677 struct brcmf_scan_params_le params_le;
678 struct cfg80211_scan_request *scan_request;
679 s32 err = 0;
680
681 brcmf_dbg(SCAN, "Enter\n");
682
683 /* clear scan request, because the FW abort can cause a second call */
684 /* to this functon and might cause a double cfg80211_scan_done */
685 scan_request = cfg->scan_request;
686 cfg->scan_request = NULL;
687
688 if (timer_pending(&cfg->escan_timeout))
689 del_timer_sync(&cfg->escan_timeout);
690
691 if (fw_abort) {
692 /* Do a scan abort to stop the driver's scan engine */
693 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
694 memset(&params_le, 0, sizeof(params_le));
Joe Perches93803b32015-03-02 19:54:49 -0800695 eth_broadcast_addr(params_le.bssid);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100696 params_le.bss_type = DOT11_BSSTYPE_ANY;
697 params_le.scan_type = 0;
698 params_le.channel_num = cpu_to_le32(1);
699 params_le.nprobes = cpu_to_le32(1);
700 params_le.active_time = cpu_to_le32(-1);
701 params_le.passive_time = cpu_to_le32(-1);
702 params_le.home_time = cpu_to_le32(-1);
703 /* Scan is aborted by setting channel_list[0] to -1 */
704 params_le.channel_list[0] = cpu_to_le16(-1);
705 /* E-Scan (or anyother type) can be aborted by SCAN */
Arend van Sprielf96aa072013-04-05 10:57:48 +0200706 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100707 &params_le, sizeof(params_le));
708 if (err)
709 brcmf_err("Scan abort failed\n");
710 }
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200711
Daniel Kim5e787f72014-06-21 12:11:18 +0200712 brcmf_scan_config_mpc(ifp, 1);
Arend van Spriel0f0fe992014-05-27 12:56:14 +0200713
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100714 /*
715 * e-scan can be initiated by scheduled scan
716 * which takes precedence.
717 */
718 if (cfg->sched_escan) {
719 brcmf_dbg(SCAN, "scheduled scan completed\n");
720 cfg->sched_escan = false;
721 if (!aborted)
722 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100723 } else if (scan_request) {
724 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
725 aborted ? "Aborted" : "Done");
726 cfg80211_scan_done(scan_request, aborted);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100727 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100728 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
729 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100730
731 return err;
732}
733
Arend van Spriel9f440b72013-02-08 15:53:36 +0100734static
735int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
736{
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100737 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
738 struct net_device *ndev = wdev->netdev;
739
740 /* vif event pending in firmware */
741 if (brcmf_cfg80211_vif_event_armed(cfg))
742 return -EBUSY;
743
744 if (ndev) {
745 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
Arend van Spriela0f472a2013-04-05 10:57:49 +0200746 cfg->escan_info.ifp == netdev_priv(ndev))
747 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
748 true, true);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +0100749
750 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
751 }
752
Arend van Spriel9f440b72013-02-08 15:53:36 +0100753 switch (wdev->iftype) {
754 case NL80211_IFTYPE_ADHOC:
755 case NL80211_IFTYPE_STATION:
756 case NL80211_IFTYPE_AP:
757 case NL80211_IFTYPE_AP_VLAN:
758 case NL80211_IFTYPE_WDS:
759 case NL80211_IFTYPE_MONITOR:
760 case NL80211_IFTYPE_MESH_POINT:
761 return -EOPNOTSUPP;
762 case NL80211_IFTYPE_P2P_CLIENT:
763 case NL80211_IFTYPE_P2P_GO:
Arend van Spriel27f10e32013-04-05 10:57:50 +0200764 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100765 return brcmf_p2p_del_vif(wiphy, wdev);
766 case NL80211_IFTYPE_UNSPECIFIED:
Arend van Spriel9f440b72013-02-08 15:53:36 +0100767 default:
768 return -EINVAL;
769 }
770 return -EOPNOTSUPP;
771}
772
Arend van Spriel5b435de2011-10-05 13:19:03 +0200773static s32
774brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
775 enum nl80211_iftype type, u32 *flags,
776 struct vif_params *params)
777{
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100778 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -0700779 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100780 struct brcmf_cfg80211_vif *vif = ifp->vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200781 s32 infra = 0;
Hante Meuleman1a873342012-09-27 14:17:54 +0200782 s32 ap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200783 s32 err = 0;
784
Hante Meuleman37a869e2015-10-29 20:33:17 +0100785 brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx,
786 type);
Hante Meuleman178e9ef2015-09-18 22:08:11 +0200787
788 /* WAR: There are a number of p2p interface related problems which
789 * need to be handled initially (before doing the validate).
790 * wpa_supplicant tends to do iface changes on p2p device/client/go
791 * which are not always possible/allowed. However we need to return
792 * OK otherwise the wpa_supplicant wont start. The situation differs
793 * on configuration and setup (p2pon=1 module param). The first check
794 * is to see if the request is a change to station for p2p iface.
795 */
796 if ((type == NL80211_IFTYPE_STATION) &&
797 ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
798 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) ||
799 (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) {
800 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
801 /* Now depending on whether module param p2pon=1 was used the
802 * response needs to be either 0 or EOPNOTSUPP. The reason is
803 * that if p2pon=1 is used, but a newer supplicant is used then
804 * we should return an error, as this combination wont work.
805 * In other situations 0 is returned and supplicant will start
806 * normally. It will give a trace in cfg80211, but it is the
807 * only way to get it working. Unfortunately this will result
808 * in situation where we wont support new supplicant in
809 * combination with module param p2pon=1, but that is the way
810 * it is. If the user tries this then unloading of driver might
811 * fail/lock.
812 */
813 if (cfg->p2p.p2pdev_dynamically)
814 return -EOPNOTSUPP;
815 else
816 return 0;
817 }
Arend van Spriel39504a22015-08-20 22:06:05 +0200818 err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
819 if (err) {
820 brcmf_err("iface validation failed: err=%d\n", err);
821 return err;
822 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200823 switch (type) {
824 case NL80211_IFTYPE_MONITOR:
825 case NL80211_IFTYPE_WDS:
Arend van Spriel57d6e912012-12-05 15:26:00 +0100826 brcmf_err("type (%d) : currently we do not support this type\n",
827 type);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200828 return -EOPNOTSUPP;
829 case NL80211_IFTYPE_ADHOC:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200830 infra = 0;
831 break;
832 case NL80211_IFTYPE_STATION:
Arend van Spriel5b435de2011-10-05 13:19:03 +0200833 infra = 1;
834 break;
Hante Meuleman1a873342012-09-27 14:17:54 +0200835 case NL80211_IFTYPE_AP:
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100836 case NL80211_IFTYPE_P2P_GO:
Hante Meuleman1a873342012-09-27 14:17:54 +0200837 ap = 1;
838 break;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200839 default:
840 err = -EINVAL;
841 goto done;
842 }
843
Hante Meuleman1a873342012-09-27 14:17:54 +0200844 if (ap) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100845 if (type == NL80211_IFTYPE_P2P_GO) {
846 brcmf_dbg(INFO, "IF Type = P2P GO\n");
847 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
848 }
849 if (!err) {
Hante Meuleman7a5c1f62013-02-08 15:53:44 +0100850 brcmf_dbg(INFO, "IF Type = AP\n");
851 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200852 } else {
Arend van Spriel128ce3b2012-11-28 21:44:12 +0100853 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
Hante Meuleman1a873342012-09-27 14:17:54 +0200854 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +0100855 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +0200856 err = -EAGAIN;
857 goto done;
858 }
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100859 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100860 "Adhoc" : "Infra");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200861 }
Hante Meuleman1a873342012-09-27 14:17:54 +0200862 ndev->ieee80211_ptr->iftype = type;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200863
Hante Meuleman8851cce2014-07-30 13:20:02 +0200864 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
865
Arend van Spriel5b435de2011-10-05 13:19:03 +0200866done:
Arend van Sprield96b8012012-12-05 15:26:02 +0100867 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200868
869 return err;
870}
871
Franky Lin83cf17a2013-04-11 13:28:50 +0200872static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
873 struct brcmf_scan_params_le *params_le,
Hante Meulemane756af52012-09-11 21:18:52 +0200874 struct cfg80211_scan_request *request)
875{
876 u32 n_ssids;
877 u32 n_channels;
878 s32 i;
879 s32 offset;
Arend van Spriel029591f2012-09-19 22:21:06 +0200880 u16 chanspec;
Hante Meulemane756af52012-09-11 21:18:52 +0200881 char *ptr;
Arend van Spriel029591f2012-09-19 22:21:06 +0200882 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +0200883
Joe Perches93803b32015-03-02 19:54:49 -0800884 eth_broadcast_addr(params_le->bssid);
Hante Meulemane756af52012-09-11 21:18:52 +0200885 params_le->bss_type = DOT11_BSSTYPE_ANY;
886 params_le->scan_type = 0;
887 params_le->channel_num = 0;
888 params_le->nprobes = cpu_to_le32(-1);
889 params_le->active_time = cpu_to_le32(-1);
890 params_le->passive_time = cpu_to_le32(-1);
891 params_le->home_time = cpu_to_le32(-1);
892 memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
893
894 /* if request is null exit so it will be all channel broadcast scan */
895 if (!request)
896 return;
897
898 n_ssids = request->n_ssids;
899 n_channels = request->n_channels;
900 /* Copy channel array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100901 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
902 n_channels);
Hante Meulemane756af52012-09-11 21:18:52 +0200903 if (n_channels > 0) {
904 for (i = 0; i < n_channels; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +0200905 chanspec = channel_to_chanspec(&cfg->d11inf,
906 request->channels[i]);
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100907 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
908 request->channels[i]->hw_value, chanspec);
Arend van Spriel029591f2012-09-19 22:21:06 +0200909 params_le->channel_list[i] = cpu_to_le16(chanspec);
Hante Meulemane756af52012-09-11 21:18:52 +0200910 }
911 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100912 brcmf_dbg(SCAN, "Scanning all channels\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200913 }
914 /* Copy ssid array if applicable */
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100915 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200916 if (n_ssids > 0) {
917 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
918 n_channels * sizeof(u16);
919 offset = roundup(offset, sizeof(u32));
920 ptr = (char *)params_le + offset;
921 for (i = 0; i < n_ssids; i++) {
Arend van Spriel029591f2012-09-19 22:21:06 +0200922 memset(&ssid_le, 0, sizeof(ssid_le));
923 ssid_le.SSID_len =
924 cpu_to_le32(request->ssids[i].ssid_len);
925 memcpy(ssid_le.SSID, request->ssids[i].ssid,
926 request->ssids[i].ssid_len);
927 if (!ssid_le.SSID_len)
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100928 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
Hante Meulemane756af52012-09-11 21:18:52 +0200929 else
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100930 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
931 i, ssid_le.SSID, ssid_le.SSID_len);
Arend van Spriel029591f2012-09-19 22:21:06 +0200932 memcpy(ptr, &ssid_le, sizeof(ssid_le));
933 ptr += sizeof(ssid_le);
Hante Meulemane756af52012-09-11 21:18:52 +0200934 }
935 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100936 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
Hante Meulemane756af52012-09-11 21:18:52 +0200937 if ((request->ssids) && request->ssids->ssid_len) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100938 brcmf_dbg(SCAN, "SSID %s len=%d\n",
939 params_le->ssid_le.SSID,
940 request->ssids->ssid_len);
Hante Meulemane756af52012-09-11 21:18:52 +0200941 params_le->ssid_le.SSID_len =
942 cpu_to_le32(request->ssids->ssid_len);
943 memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
944 request->ssids->ssid_len);
945 }
946 }
947 /* Adding mask to channel numbers */
948 params_le->channel_num =
949 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
950 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
951}
952
953static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +0200954brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
Hante Meulemanc4958102015-11-25 11:32:41 +0100955 struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200956{
957 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
958 offsetof(struct brcmf_escan_params_le, params_le);
959 struct brcmf_escan_params_le *params;
960 s32 err = 0;
961
Arend van Spriel4e8a0082012-12-05 15:26:03 +0100962 brcmf_dbg(SCAN, "E-SCAN START\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200963
964 if (request != NULL) {
965 /* Allocate space for populating ssids in struct */
966 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
967
968 /* Allocate space for populating ssids in struct */
Hante Meulemane9a6ca82015-11-25 11:32:37 +0100969 params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids;
Hante Meulemane756af52012-09-11 21:18:52 +0200970 }
971
972 params = kzalloc(params_size, GFP_KERNEL);
973 if (!params) {
974 err = -ENOMEM;
975 goto exit;
976 }
977 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
Franky Lin83cf17a2013-04-11 13:28:50 +0200978 brcmf_escan_prep(cfg, &params->params_le, request);
Hante Meulemane756af52012-09-11 21:18:52 +0200979 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
Hante Meulemanc4958102015-11-25 11:32:41 +0100980 params->action = cpu_to_le16(WL_ESCAN_ACTION_START);
Hante Meulemane756af52012-09-11 21:18:52 +0200981 params->sync_id = cpu_to_le16(0x1234);
982
Arend van Spriela0f472a2013-04-05 10:57:49 +0200983 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
Hante Meulemane756af52012-09-11 21:18:52 +0200984 if (err) {
985 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +0100986 brcmf_dbg(INFO, "system busy : escan canceled\n");
Hante Meulemane756af52012-09-11 21:18:52 +0200987 else
Arend van Spriel57d6e912012-12-05 15:26:00 +0100988 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +0200989 }
990
991 kfree(params);
992exit:
993 return err;
994}
995
996static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +0200997brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
Arend van Spriela0f472a2013-04-05 10:57:49 +0200998 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
Hante Meulemane756af52012-09-11 21:18:52 +0200999{
1000 s32 err;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001001 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001002 struct brcmf_scan_results *results;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001003 struct escan_info *escan = &cfg->escan_info;
Hante Meulemane756af52012-09-11 21:18:52 +02001004
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001005 brcmf_dbg(SCAN, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001006 escan->ifp = ifp;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001007 escan->wiphy = wiphy;
1008 escan->escan_state = WL_ESCAN_STATE_SCANNING;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001009 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielf96aa072013-04-05 10:57:48 +02001010 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001011 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001012 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001013 brcmf_err("error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001014 return err;
1015 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001016 brcmf_scan_config_mpc(ifp, 0);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001017 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Hante Meulemane756af52012-09-11 21:18:52 +02001018 results->version = 0;
1019 results->count = 0;
1020 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
1021
Hante Meulemanc4958102015-11-25 11:32:41 +01001022 err = escan->run(cfg, ifp, request);
Hante Meulemane756af52012-09-11 21:18:52 +02001023 if (err)
Daniel Kim5e787f72014-06-21 12:11:18 +02001024 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001025 return err;
1026}
1027
1028static s32
Arend van Spriela0f472a2013-04-05 10:57:49 +02001029brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
Hante Meulemane756af52012-09-11 21:18:52 +02001030 struct cfg80211_scan_request *request,
1031 struct cfg80211_ssid *this_ssid)
1032{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001033 struct brcmf_if *ifp = vif->ifp;
1034 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemane756af52012-09-11 21:18:52 +02001035 struct cfg80211_ssid *ssids;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001036 u32 passive_scan;
Hante Meulemane756af52012-09-11 21:18:52 +02001037 bool escan_req;
1038 bool spec_scan;
1039 s32 err;
Hante Meuleman675f5d82015-12-10 13:43:01 +01001040 struct brcmf_ssid_le ssid_le;
Hante Meulemane756af52012-09-11 21:18:52 +02001041 u32 SSID_len;
1042
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001043 brcmf_dbg(SCAN, "START ESCAN\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001044
Arend van Sprielc1179032012-10-22 13:55:33 -07001045 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001046 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001047 return -EAGAIN;
1048 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001049 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001050 brcmf_err("Scanning being aborted: status (%lu)\n",
1051 cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001052 return -EAGAIN;
1053 }
Arend van Spriel1687eee2013-04-23 12:53:11 +02001054 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
1055 brcmf_err("Scanning suppressed: status (%lu)\n",
1056 cfg->scan_status);
1057 return -EAGAIN;
1058 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001059 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001060 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
Hante Meulemane756af52012-09-11 21:18:52 +02001061 return -EAGAIN;
1062 }
1063
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001064 /* If scan req comes for p2p0, send it over primary I/F */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001065 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
1066 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
Hante Meuleman0f8ffe12013-02-08 15:53:42 +01001067
Hante Meulemane756af52012-09-11 21:18:52 +02001068 escan_req = false;
1069 if (request) {
1070 /* scan bss */
1071 ssids = request->ssids;
1072 escan_req = true;
1073 } else {
1074 /* scan in ibss */
1075 /* we don't do escan in ibss */
1076 ssids = this_ssid;
1077 }
1078
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001079 cfg->scan_request = request;
Arend van Sprielc1179032012-10-22 13:55:33 -07001080 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Hante Meulemane756af52012-09-11 21:18:52 +02001081 if (escan_req) {
Arend van Spriel9f440b72013-02-08 15:53:36 +01001082 cfg->escan_info.run = brcmf_run_escan;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001083 err = brcmf_p2p_scan_prep(wiphy, request, vif);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001084 if (err)
1085 goto scan_out;
1086
Arend van Spriela0f472a2013-04-05 10:57:49 +02001087 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
Arend van Spriel2cb941c2012-11-05 16:22:10 -08001088 if (err)
Hante Meulemane756af52012-09-11 21:18:52 +02001089 goto scan_out;
1090 } else {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001091 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
1092 ssids->ssid, ssids->ssid_len);
Hante Meuleman675f5d82015-12-10 13:43:01 +01001093 memset(&ssid_le, 0, sizeof(ssid_le));
1094 SSID_len = min_t(u8, sizeof(ssid_le.SSID), ssids->ssid_len);
1095 ssid_le.SSID_len = cpu_to_le32(0);
Hante Meulemane756af52012-09-11 21:18:52 +02001096 spec_scan = false;
1097 if (SSID_len) {
Hante Meuleman675f5d82015-12-10 13:43:01 +01001098 memcpy(ssid_le.SSID, ssids->ssid, SSID_len);
1099 ssid_le.SSID_len = cpu_to_le32(SSID_len);
Hante Meulemane756af52012-09-11 21:18:52 +02001100 spec_scan = true;
1101 } else
Arend van Spriel4e8a0082012-12-05 15:26:03 +01001102 brcmf_dbg(SCAN, "Broadcast scan\n");
Hante Meulemane756af52012-09-11 21:18:52 +02001103
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001104 passive_scan = cfg->active_scan ? 0 : 1;
Arend van Sprielc1179032012-10-22 13:55:33 -07001105 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001106 passive_scan);
Hante Meulemane756af52012-09-11 21:18:52 +02001107 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001108 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001109 goto scan_out;
1110 }
Daniel Kim5e787f72014-06-21 12:11:18 +02001111 brcmf_scan_config_mpc(ifp, 0);
Hante Meuleman675f5d82015-12-10 13:43:01 +01001112 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, &ssid_le,
1113 sizeof(ssid_le));
Hante Meulemane756af52012-09-11 21:18:52 +02001114 if (err) {
1115 if (err == -EBUSY)
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001116 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
Hante Meuleman675f5d82015-12-10 13:43:01 +01001117 ssid_le.SSID);
Hante Meulemane756af52012-09-11 21:18:52 +02001118 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01001119 brcmf_err("WLC_SCAN error (%d)\n", err);
Hante Meulemane756af52012-09-11 21:18:52 +02001120
Daniel Kim5e787f72014-06-21 12:11:18 +02001121 brcmf_scan_config_mpc(ifp, 1);
Hante Meulemane756af52012-09-11 21:18:52 +02001122 goto scan_out;
1123 }
1124 }
1125
Hante Meuleman661fa952015-02-06 18:36:47 +01001126 /* Arm scan timeout timer */
1127 mod_timer(&cfg->escan_timeout, jiffies +
Hante Meulemand5367332016-02-17 11:26:51 +01001128 BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
Hante Meuleman661fa952015-02-06 18:36:47 +01001129
Hante Meulemane756af52012-09-11 21:18:52 +02001130 return 0;
1131
1132scan_out:
Arend van Sprielc1179032012-10-22 13:55:33 -07001133 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001134 cfg->scan_request = NULL;
Hante Meulemane756af52012-09-11 21:18:52 +02001135 return err;
1136}
1137
Arend van Spriel5b435de2011-10-05 13:19:03 +02001138static s32
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001139brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001140{
Arend van Spriela0f472a2013-04-05 10:57:49 +02001141 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001142 s32 err = 0;
1143
Arend van Sprield96b8012012-12-05 15:26:02 +01001144 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriela0f472a2013-04-05 10:57:49 +02001145 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1146 if (!check_vif_up(vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001147 return -EIO;
1148
Arend van Spriela0f472a2013-04-05 10:57:49 +02001149 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
Hante Meulemane756af52012-09-11 21:18:52 +02001150
Arend van Spriel5b435de2011-10-05 13:19:03 +02001151 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001152 brcmf_err("scan error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001153
Arend van Sprield96b8012012-12-05 15:26:02 +01001154 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001155 return err;
1156}
1157
1158static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1159{
1160 s32 err = 0;
1161
Arend van Sprielac24be62012-10-22 10:36:23 -07001162 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1163 rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001164 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001165 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001166
1167 return err;
1168}
1169
1170static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1171{
1172 s32 err = 0;
1173
Arend van Sprielac24be62012-10-22 10:36:23 -07001174 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1175 frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001176 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001177 brcmf_err("Error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001178
1179 return err;
1180}
1181
1182static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1183{
1184 s32 err = 0;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001185 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001186
Arend van Sprielac24be62012-10-22 10:36:23 -07001187 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001188 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001189 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001190 return err;
1191 }
1192 return err;
1193}
1194
1195static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1196{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001197 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1198 struct net_device *ndev = cfg_to_ndev(cfg);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001199 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001200 s32 err = 0;
1201
Arend van Sprield96b8012012-12-05 15:26:02 +01001202 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001203 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001204 return -EIO;
1205
1206 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001207 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1208 cfg->conf->rts_threshold = wiphy->rts_threshold;
1209 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001210 if (!err)
1211 goto done;
1212 }
1213 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001214 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1215 cfg->conf->frag_threshold = wiphy->frag_threshold;
1216 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001217 if (!err)
1218 goto done;
1219 }
1220 if (changed & WIPHY_PARAM_RETRY_LONG
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001221 && (cfg->conf->retry_long != wiphy->retry_long)) {
1222 cfg->conf->retry_long = wiphy->retry_long;
1223 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001224 if (!err)
1225 goto done;
1226 }
1227 if (changed & WIPHY_PARAM_RETRY_SHORT
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001228 && (cfg->conf->retry_short != wiphy->retry_short)) {
1229 cfg->conf->retry_short = wiphy->retry_short;
1230 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001231 if (!err)
1232 goto done;
1233 }
1234
1235done:
Arend van Sprield96b8012012-12-05 15:26:02 +01001236 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001237 return err;
1238}
1239
Arend van Spriel5b435de2011-10-05 13:19:03 +02001240static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1241{
1242 memset(prof, 0, sizeof(*prof));
1243}
1244
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001245static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
1246{
1247 u16 reason;
1248
1249 switch (e->event_code) {
1250 case BRCMF_E_DEAUTH:
1251 case BRCMF_E_DEAUTH_IND:
1252 case BRCMF_E_DISASSOC_IND:
1253 reason = e->reason;
1254 break;
1255 case BRCMF_E_LINK:
1256 default:
1257 reason = 0;
1258 break;
1259 }
1260 return reason;
1261}
1262
1263static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001264{
Piotr Haber61730d42013-04-23 12:53:12 +02001265 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001266 s32 err = 0;
1267
Arend van Sprield96b8012012-12-05 15:26:02 +01001268 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001269
Hante Meulemanb0a79082015-12-10 13:43:07 +01001270 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001271 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001272 err = brcmf_fil_cmd_data_set(vif->ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07001273 BRCMF_C_DISASSOC, NULL, 0);
Arend van Spriela538ae32013-07-25 23:01:34 +02001274 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001275 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
Arend van Spriela538ae32013-07-25 23:01:34 +02001276 }
Hante Meulemanb0a79082015-12-10 13:43:07 +01001277 if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) ||
1278 (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT))
1279 cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
1280 true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001281 }
Arend van Spriel903e0ee2012-11-28 21:44:11 +01001282 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
Piotr Haber61730d42013-04-23 12:53:12 +02001283 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1284 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
Arend van Sprield96b8012012-12-05 15:26:02 +01001285 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001286}
1287
1288static s32
1289brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1290 struct cfg80211_ibss_params *params)
1291{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001292 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001293 struct brcmf_if *ifp = netdev_priv(ndev);
1294 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001295 struct brcmf_join_params join_params;
1296 size_t join_params_size = 0;
1297 s32 err = 0;
1298 s32 wsec = 0;
1299 s32 bcnprd;
Hante Meuleman17012612013-02-06 18:40:44 +01001300 u16 chanspec;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001301 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001302
Arend van Sprield96b8012012-12-05 15:26:02 +01001303 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001304 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001305 return -EIO;
1306
1307 if (params->ssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001308 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001309 else {
Arend van Spriel16886732012-12-05 15:26:04 +01001310 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001311 return -EOPNOTSUPP;
1312 }
1313
Arend van Sprielc1179032012-10-22 13:55:33 -07001314 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001315
1316 if (params->bssid)
Arend van Spriel16886732012-12-05 15:26:04 +01001317 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001318 else
Arend van Spriel16886732012-12-05 15:26:04 +01001319 brcmf_dbg(CONN, "No BSSID specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001320
Johannes Berg683b6d32012-11-08 21:25:48 +01001321 if (params->chandef.chan)
Arend van Spriel16886732012-12-05 15:26:04 +01001322 brcmf_dbg(CONN, "channel: %d\n",
1323 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001324 else
Arend van Spriel16886732012-12-05 15:26:04 +01001325 brcmf_dbg(CONN, "no channel specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001326
1327 if (params->channel_fixed)
Arend van Spriel16886732012-12-05 15:26:04 +01001328 brcmf_dbg(CONN, "fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001329 else
Arend van Spriel16886732012-12-05 15:26:04 +01001330 brcmf_dbg(CONN, "no fixed channel required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001331
1332 if (params->ie && params->ie_len)
Arend van Spriel16886732012-12-05 15:26:04 +01001333 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001334 else
Arend van Spriel16886732012-12-05 15:26:04 +01001335 brcmf_dbg(CONN, "no ie specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001336
1337 if (params->beacon_interval)
Arend van Spriel16886732012-12-05 15:26:04 +01001338 brcmf_dbg(CONN, "beacon interval: %d\n",
1339 params->beacon_interval);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001340 else
Arend van Spriel16886732012-12-05 15:26:04 +01001341 brcmf_dbg(CONN, "no beacon interval specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001342
1343 if (params->basic_rates)
Arend van Spriel16886732012-12-05 15:26:04 +01001344 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001345 else
Arend van Spriel16886732012-12-05 15:26:04 +01001346 brcmf_dbg(CONN, "no basic rates specified\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001347
1348 if (params->privacy)
Arend van Spriel16886732012-12-05 15:26:04 +01001349 brcmf_dbg(CONN, "privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001350 else
Arend van Spriel16886732012-12-05 15:26:04 +01001351 brcmf_dbg(CONN, "no privacy required\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001352
1353 /* Configure Privacy for starter */
1354 if (params->privacy)
1355 wsec |= WEP_ENABLED;
1356
Arend van Sprielc1179032012-10-22 13:55:33 -07001357 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001358 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001359 brcmf_err("wsec failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001360 goto done;
1361 }
1362
1363 /* Configure Beacon Interval for starter */
1364 if (params->beacon_interval)
1365 bcnprd = params->beacon_interval;
1366 else
1367 bcnprd = 100;
1368
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001369 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001370 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001371 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001372 goto done;
1373 }
1374
1375 /* Configure required join parameter */
1376 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1377
1378 /* SSID */
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001379 ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN);
1380 memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len);
1381 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001382 join_params_size = sizeof(join_params.ssid_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001383
1384 /* BSSID */
1385 if (params->bssid) {
1386 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001387 join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE;
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02001388 memcpy(profile->bssid, params->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001389 } else {
Joe Perches93803b32015-03-02 19:54:49 -08001390 eth_broadcast_addr(join_params.params_le.bssid);
1391 eth_zero_addr(profile->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001392 }
1393
Arend van Spriel5b435de2011-10-05 13:19:03 +02001394 /* Channel */
Johannes Berg683b6d32012-11-08 21:25:48 +01001395 if (params->chandef.chan) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001396 u32 target_channel;
1397
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001398 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001399 ieee80211_frequency_to_channel(
Johannes Berg683b6d32012-11-08 21:25:48 +01001400 params->chandef.chan->center_freq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001401 if (params->channel_fixed) {
1402 /* adding chanspec */
Arend van Spriel600a8972014-05-12 10:47:39 +02001403 chanspec = chandef_to_chanspec(&cfg->d11inf,
1404 &params->chandef);
Hante Meuleman17012612013-02-06 18:40:44 +01001405 join_params.params_le.chanspec_list[0] =
1406 cpu_to_le16(chanspec);
1407 join_params.params_le.chanspec_num = cpu_to_le32(1);
1408 join_params_size += sizeof(join_params.params_le);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001409 }
1410
1411 /* set channel for starter */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001412 target_channel = cfg->channel;
Hante Meulemanb87e2c42012-11-14 18:46:23 -08001413 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001414 target_channel);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001415 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001416 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001417 goto done;
1418 }
1419 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001420 cfg->channel = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001421
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001422 cfg->ibss_starter = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001423
1424
Arend van Sprielc1179032012-10-22 13:55:33 -07001425 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001426 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001427 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001428 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001429 goto done;
1430 }
1431
1432done:
1433 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001434 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001435 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001436 return err;
1437}
1438
1439static s32
1440brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1441{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001442 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001443
Arend van Sprield96b8012012-12-05 15:26:02 +01001444 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman6a98d642016-01-02 09:41:40 +01001445 if (!check_vif_up(ifp->vif)) {
1446 /* When driver is being unloaded, it can end up here. If an
1447 * error is returned then later on a debug trace in the wireless
1448 * core module will be printed. To avoid this 0 is returned.
1449 */
1450 return 0;
1451 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001452
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01001453 brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01001454 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001455
Arend van Sprield96b8012012-12-05 15:26:02 +01001456 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001457
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03001458 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001459}
1460
1461static s32 brcmf_set_wpa_version(struct net_device *ndev,
1462 struct cfg80211_connect_params *sme)
1463{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001464 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001465 struct brcmf_cfg80211_security *sec;
1466 s32 val = 0;
1467 s32 err = 0;
1468
1469 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1470 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1471 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1472 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1473 else
1474 val = WPA_AUTH_DISABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01001475 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001476 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001477 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001478 brcmf_err("set wpa_auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001479 return err;
1480 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001481 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001482 sec->wpa_versions = sme->crypto.wpa_versions;
1483 return err;
1484}
1485
1486static s32 brcmf_set_auth_type(struct net_device *ndev,
1487 struct cfg80211_connect_params *sme)
1488{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001489 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001490 struct brcmf_cfg80211_security *sec;
1491 s32 val = 0;
1492 s32 err = 0;
1493
1494 switch (sme->auth_type) {
1495 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1496 val = 0;
Arend van Spriel16886732012-12-05 15:26:04 +01001497 brcmf_dbg(CONN, "open system\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001498 break;
1499 case NL80211_AUTHTYPE_SHARED_KEY:
1500 val = 1;
Arend van Spriel16886732012-12-05 15:26:04 +01001501 brcmf_dbg(CONN, "shared key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001502 break;
1503 case NL80211_AUTHTYPE_AUTOMATIC:
1504 val = 2;
Arend van Spriel16886732012-12-05 15:26:04 +01001505 brcmf_dbg(CONN, "automatic\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001506 break;
1507 case NL80211_AUTHTYPE_NETWORK_EAP:
Arend van Spriel16886732012-12-05 15:26:04 +01001508 brcmf_dbg(CONN, "network eap\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001509 default:
1510 val = 2;
Arend van Spriel57d6e912012-12-05 15:26:00 +01001511 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001512 break;
1513 }
1514
Hante Meuleman89286dc2013-02-08 15:53:46 +01001515 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001516 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001517 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001518 return err;
1519 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001520 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001521 sec->auth_type = sme->auth_type;
1522 return err;
1523}
1524
1525static s32
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001526brcmf_set_wsec_mode(struct net_device *ndev,
1527 struct cfg80211_connect_params *sme, bool mfp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001528{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001529 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001530 struct brcmf_cfg80211_security *sec;
1531 s32 pval = 0;
1532 s32 gval = 0;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001533 s32 wsec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001534 s32 err = 0;
1535
1536 if (sme->crypto.n_ciphers_pairwise) {
1537 switch (sme->crypto.ciphers_pairwise[0]) {
1538 case WLAN_CIPHER_SUITE_WEP40:
1539 case WLAN_CIPHER_SUITE_WEP104:
1540 pval = WEP_ENABLED;
1541 break;
1542 case WLAN_CIPHER_SUITE_TKIP:
1543 pval = TKIP_ENABLED;
1544 break;
1545 case WLAN_CIPHER_SUITE_CCMP:
1546 pval = AES_ENABLED;
1547 break;
1548 case WLAN_CIPHER_SUITE_AES_CMAC:
1549 pval = AES_ENABLED;
1550 break;
1551 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001552 brcmf_err("invalid cipher pairwise (%d)\n",
1553 sme->crypto.ciphers_pairwise[0]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001554 return -EINVAL;
1555 }
1556 }
1557 if (sme->crypto.cipher_group) {
1558 switch (sme->crypto.cipher_group) {
1559 case WLAN_CIPHER_SUITE_WEP40:
1560 case WLAN_CIPHER_SUITE_WEP104:
1561 gval = WEP_ENABLED;
1562 break;
1563 case WLAN_CIPHER_SUITE_TKIP:
1564 gval = TKIP_ENABLED;
1565 break;
1566 case WLAN_CIPHER_SUITE_CCMP:
1567 gval = AES_ENABLED;
1568 break;
1569 case WLAN_CIPHER_SUITE_AES_CMAC:
1570 gval = AES_ENABLED;
1571 break;
1572 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001573 brcmf_err("invalid cipher group (%d)\n",
1574 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001575 return -EINVAL;
1576 }
1577 }
1578
Arend van Spriel16886732012-12-05 15:26:04 +01001579 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001580 /* In case of privacy, but no security and WPS then simulate */
1581 /* setting AES. WPS-2.0 allows no security */
1582 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1583 sme->privacy)
1584 pval = AES_ENABLED;
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001585
1586 if (mfp)
1587 wsec = pval | gval | MFP_CAPABLE;
1588 else
1589 wsec = pval | gval;
1590 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001591 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001592 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001593 return err;
1594 }
1595
Arend van Spriel06bb1232012-09-27 14:17:56 +02001596 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001597 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1598 sec->cipher_group = sme->crypto.cipher_group;
1599
1600 return err;
1601}
1602
1603static s32
1604brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1605{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001606 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001607 struct brcmf_cfg80211_security *sec;
1608 s32 val = 0;
1609 s32 err = 0;
1610
1611 if (sme->crypto.n_akm_suites) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01001612 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
1613 "wpa_auth", &val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001614 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001615 brcmf_err("could not get wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001616 return err;
1617 }
1618 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1619 switch (sme->crypto.akm_suites[0]) {
1620 case WLAN_AKM_SUITE_8021X:
1621 val = WPA_AUTH_UNSPECIFIED;
1622 break;
1623 case WLAN_AKM_SUITE_PSK:
1624 val = WPA_AUTH_PSK;
1625 break;
1626 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001627 brcmf_err("invalid cipher group (%d)\n",
1628 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001629 return -EINVAL;
1630 }
1631 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1632 switch (sme->crypto.akm_suites[0]) {
1633 case WLAN_AKM_SUITE_8021X:
1634 val = WPA2_AUTH_UNSPECIFIED;
1635 break;
1636 case WLAN_AKM_SUITE_PSK:
1637 val = WPA2_AUTH_PSK;
1638 break;
1639 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001640 brcmf_err("invalid cipher group (%d)\n",
1641 sme->crypto.cipher_group);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001642 return -EINVAL;
1643 }
1644 }
1645
Arend van Spriel16886732012-12-05 15:26:04 +01001646 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001647 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
1648 "wpa_auth", val);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001649 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001650 brcmf_err("could not set wpa_auth (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001651 return err;
1652 }
1653 }
Arend van Spriel06bb1232012-09-27 14:17:56 +02001654 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001655 sec->wpa_auth = sme->crypto.akm_suites[0];
1656
1657 return err;
1658}
1659
1660static s32
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001661brcmf_set_sharedkey(struct net_device *ndev,
1662 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001663{
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07001664 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001665 struct brcmf_cfg80211_security *sec;
1666 struct brcmf_wsec_key key;
1667 s32 val;
1668 s32 err = 0;
1669
Arend van Spriel16886732012-12-05 15:26:04 +01001670 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001671
Roland Vossena718e2f2011-10-12 20:51:24 +02001672 if (sme->key_len == 0)
1673 return 0;
1674
Arend van Spriel06bb1232012-09-27 14:17:56 +02001675 sec = &profile->sec;
Arend van Spriel16886732012-12-05 15:26:04 +01001676 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1677 sec->wpa_versions, sec->cipher_pairwise);
Roland Vossena718e2f2011-10-12 20:51:24 +02001678
1679 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1680 return 0;
1681
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001682 if (!(sec->cipher_pairwise &
1683 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1684 return 0;
Roland Vossena718e2f2011-10-12 20:51:24 +02001685
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001686 memset(&key, 0, sizeof(key));
1687 key.len = (u32) sme->key_len;
1688 key.index = (u32) sme->key_idx;
1689 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001690 brcmf_err("Too long key length (%u)\n", key.len);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001691 return -EINVAL;
1692 }
1693 memcpy(key.data, sme->key, key.len);
1694 key.flags = BRCMF_PRIMARY_KEY;
1695 switch (sec->cipher_pairwise) {
1696 case WLAN_CIPHER_SUITE_WEP40:
1697 key.algo = CRYPTO_ALGO_WEP1;
1698 break;
1699 case WLAN_CIPHER_SUITE_WEP104:
1700 key.algo = CRYPTO_ALGO_WEP128;
1701 break;
1702 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01001703 brcmf_err("Invalid algorithm (%d)\n",
1704 sme->crypto.ciphers_pairwise[0]);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001705 return -EINVAL;
1706 }
1707 /* Set the new key/index */
Arend van Spriel16886732012-12-05 15:26:04 +01001708 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1709 key.len, key.index, key.algo);
1710 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
Hante Meuleman118eb302014-12-21 12:43:49 +01001711 err = send_key_to_dongle(netdev_priv(ndev), &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001712 if (err)
1713 return err;
1714
1715 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
Arend van Spriel16886732012-12-05 15:26:04 +01001716 brcmf_dbg(CONN, "set auth_type to shared key\n");
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001717 val = WL_AUTH_SHARED_KEY; /* shared key */
Arend van Sprielac24be62012-10-22 10:36:23 -07001718 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001719 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001720 brcmf_err("set auth failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001721 }
1722 return err;
1723}
1724
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001725static
1726enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1727 enum nl80211_auth_type type)
1728{
Arend van Sprielc08437b2014-07-12 08:49:39 +02001729 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1730 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1731 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1732 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001733 }
1734 return type;
1735}
1736
Arend van Spriel5b435de2011-10-05 13:19:03 +02001737static s32
1738brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001739 struct cfg80211_connect_params *sme)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001740{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001741 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001742 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001743 struct ieee80211_channel *chan = sme->channel;
1744 struct brcmf_join_params join_params;
1745 size_t join_params_size;
Johannes Berg4b5800f2014-01-15 14:55:59 +01001746 const struct brcmf_tlv *rsn_ie;
1747 const struct brcmf_vs_tlv *wpa_ie;
1748 const void *ie;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001749 u32 ie_len;
1750 struct brcmf_ext_join_params_le *ext_join_params;
Hante Meuleman17012612013-02-06 18:40:44 +01001751 u16 chanspec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001752 s32 err = 0;
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001753 u32 ssid_len;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001754
Arend van Sprield96b8012012-12-05 15:26:02 +01001755 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07001756 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001757 return -EIO;
1758
1759 if (!sme->ssid) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001760 brcmf_err("Invalid ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001761 return -EOPNOTSUPP;
1762 }
1763
Hante Meuleman89286dc2013-02-08 15:53:46 +01001764 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1765 /* A normal (non P2P) connection request setup. */
1766 ie = NULL;
1767 ie_len = 0;
1768 /* find the WPA_IE */
1769 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1770 if (wpa_ie) {
1771 ie = wpa_ie;
1772 ie_len = wpa_ie->len + TLV_HDR_LEN;
1773 } else {
1774 /* find the RSN_IE */
Johannes Berg4b5800f2014-01-15 14:55:59 +01001775 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1776 sme->ie_len,
Hante Meuleman89286dc2013-02-08 15:53:46 +01001777 WLAN_EID_RSN);
1778 if (rsn_ie) {
1779 ie = rsn_ie;
1780 ie_len = rsn_ie->len + TLV_HDR_LEN;
1781 }
1782 }
1783 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1784 }
1785
1786 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1787 sme->ie, sme->ie_len);
1788 if (err)
1789 brcmf_err("Set Assoc REQ IE Failed\n");
1790 else
1791 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1792
Arend van Sprielc1179032012-10-22 13:55:33 -07001793 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001794
1795 if (chan) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001796 cfg->channel =
Arend van Spriel5b435de2011-10-05 13:19:03 +02001797 ieee80211_frequency_to_channel(chan->center_freq);
Franky Lin83cf17a2013-04-11 13:28:50 +02001798 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
Hante Meuleman17012612013-02-06 18:40:44 +01001799 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1800 cfg->channel, chan->center_freq, chanspec);
1801 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001802 cfg->channel = 0;
Hante Meuleman17012612013-02-06 18:40:44 +01001803 chanspec = 0;
1804 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001805
Arend van Spriel647c9ae2012-12-05 15:26:01 +01001806 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001807
1808 err = brcmf_set_wpa_version(ndev, sme);
1809 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001810 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001811 goto done;
1812 }
1813
Arend van Sprielcbb1ec92013-02-06 18:40:47 +01001814 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001815 err = brcmf_set_auth_type(ndev, sme);
1816 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001817 brcmf_err("wl_set_auth_type failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001818 goto done;
1819 }
1820
Daniel Kim87b7e9e2014-03-25 21:45:09 +01001821 err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001822 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001823 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001824 goto done;
1825 }
1826
1827 err = brcmf_set_key_mgmt(ndev, sme);
1828 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001829 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001830 goto done;
1831 }
1832
Hante Meulemanf09d0c02012-09-27 14:17:48 +02001833 err = brcmf_set_sharedkey(ndev, sme);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001834 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001835 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001836 goto done;
1837 }
1838
Hante Meuleman89286dc2013-02-08 15:53:46 +01001839 /* Join with specific BSSID and cached SSID
1840 * If SSID is zero join based on BSSID only
1841 */
1842 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1843 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1844 if (cfg->channel)
1845 join_params_size += sizeof(u16);
1846 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1847 if (ext_join_params == NULL) {
1848 err = -ENOMEM;
1849 goto done;
1850 }
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001851 ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN);
1852 ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len);
1853 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len);
1854 if (ssid_len < IEEE80211_MAX_SSID_LEN)
1855 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n",
1856 ext_join_params->ssid_le.SSID, ssid_len);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001857
Hante Meuleman89286dc2013-02-08 15:53:46 +01001858 /* Set up join scan parameters */
1859 ext_join_params->scan_le.scan_type = -1;
Hante Meuleman89286dc2013-02-08 15:53:46 +01001860 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1861
1862 if (sme->bssid)
1863 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1864 else
Joe Perches93803b32015-03-02 19:54:49 -08001865 eth_broadcast_addr(ext_join_params->assoc_le.bssid);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001866
1867 if (cfg->channel) {
1868 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
1869
1870 ext_join_params->assoc_le.chanspec_list[0] =
1871 cpu_to_le16(chanspec);
Hante Meuleman63dd99e2014-03-15 17:18:19 +01001872 /* Increase dwell time to receive probe response or detect
1873 * beacon from target AP at a noisy air only during connect
1874 * command.
1875 */
1876 ext_join_params->scan_le.active_time =
1877 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
1878 ext_join_params->scan_le.passive_time =
1879 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
1880 /* To sync with presence period of VSDB GO send probe request
1881 * more frequently. Probe request will be stopped when it gets
1882 * probe response from target AP/GO.
1883 */
1884 ext_join_params->scan_le.nprobes =
1885 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
1886 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
1887 } else {
1888 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
1889 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
1890 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
Hante Meuleman89286dc2013-02-08 15:53:46 +01001891 }
1892
1893 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
1894 join_params_size);
1895 kfree(ext_join_params);
1896 if (!err)
1897 /* This is it. join command worked, we are done */
1898 goto done;
1899
1900 /* join command failed, fallback to set ssid */
Arend van Spriel5b435de2011-10-05 13:19:03 +02001901 memset(&join_params, 0, sizeof(join_params));
1902 join_params_size = sizeof(join_params.ssid_le);
1903
Hante Meulemane9a6ca82015-11-25 11:32:37 +01001904 memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len);
1905 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001906
Hante Meuleman89286dc2013-02-08 15:53:46 +01001907 if (sme->bssid)
1908 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
1909 else
Joe Perches93803b32015-03-02 19:54:49 -08001910 eth_broadcast_addr(join_params.params_le.bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001911
Hante Meuleman17012612013-02-06 18:40:44 +01001912 if (cfg->channel) {
1913 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
1914 join_params.params_le.chanspec_num = cpu_to_le32(1);
1915 join_params_size += sizeof(join_params.params_le);
1916 }
Arend van Sprielc1179032012-10-22 13:55:33 -07001917 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07001918 &join_params, join_params_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001919 if (err)
Hante Meuleman89286dc2013-02-08 15:53:46 +01001920 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001921
1922done:
1923 if (err)
Arend van Sprielc1179032012-10-22 13:55:33 -07001924 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01001925 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001926 return err;
1927}
1928
1929static s32
1930brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1931 u16 reason_code)
1932{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001933 struct brcmf_if *ifp = netdev_priv(ndev);
1934 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001935 struct brcmf_scb_val_le scbval;
1936 s32 err = 0;
1937
Arend van Sprield96b8012012-12-05 15:26:02 +01001938 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
Arend van Sprielce81e312012-10-22 13:55:37 -07001939 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001940 return -EIO;
1941
Arend van Sprielc1179032012-10-22 13:55:33 -07001942 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Spriel4f3fff12014-11-20 22:27:02 +01001943 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
Johannes Berg80279fb2015-05-22 16:22:20 +02001944 cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001945
Arend van Spriel06bb1232012-09-27 14:17:56 +02001946 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001947 scbval.val = cpu_to_le32(reason_code);
Arend van Sprielc1179032012-10-22 13:55:33 -07001948 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
Arend van Sprielac24be62012-10-22 10:36:23 -07001949 &scbval, sizeof(scbval));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001950 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001951 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001952
Arend van Sprield96b8012012-12-05 15:26:02 +01001953 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001954 return err;
1955}
1956
1957static s32
Johannes Bergc8442112012-10-24 10:17:18 +02001958brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
Luis R. Rodriguezd3f31132011-11-28 16:38:48 -05001959 enum nl80211_tx_power_setting type, s32 mbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001960{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02001961 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07001962 struct net_device *ndev = cfg_to_ndev(cfg);
1963 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001964 s32 err;
1965 s32 disable;
1966 u32 qdbm = 127;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001967
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001968 brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm);
Arend van Sprielce81e312012-10-22 13:55:37 -07001969 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001970 return -EIO;
1971
1972 switch (type) {
1973 case NL80211_TX_POWER_AUTOMATIC:
1974 break;
1975 case NL80211_TX_POWER_LIMITED:
Arend van Spriel5b435de2011-10-05 13:19:03 +02001976 case NL80211_TX_POWER_FIXED:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001977 if (mbm < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01001978 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001979 err = -EINVAL;
1980 goto done;
1981 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001982 qdbm = MBM_TO_DBM(4 * mbm);
1983 if (qdbm > 127)
1984 qdbm = 127;
1985 qdbm |= WL_TXPWR_OVERRIDE;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001986 break;
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001987 default:
1988 brcmf_err("Unsupported type %d\n", type);
1989 err = -EINVAL;
1990 goto done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001991 }
1992 /* Make sure radio is off or on as far as software is concerned */
1993 disable = WL_RADIO_SW_DISABLE << 16;
Arend van Sprielac24be62012-10-22 10:36:23 -07001994 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001995 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01001996 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001997
Hante Meuleman60dc35e2015-09-18 22:08:06 +02001998 err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001999 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002000 brcmf_err("qtxpower error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002001
2002done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002003 brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002004 return err;
2005}
2006
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002007static s32
2008brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2009 s32 *dbm)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002010{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002011 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002012 struct net_device *ndev = cfg_to_ndev(cfg);
2013 struct brcmf_if *ifp = netdev_priv(ndev);
2014 s32 qdbm = 0;
2015 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002016
Arend van Sprield96b8012012-12-05 15:26:02 +01002017 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002018 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002019 return -EIO;
2020
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002021 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &qdbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002022 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002023 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002024 goto done;
2025 }
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002026 *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002027
2028done:
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002029 brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002030 return err;
2031}
2032
2033static s32
2034brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman60dc35e2015-09-18 22:08:06 +02002035 u8 key_idx, bool unicast, bool multicast)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002036{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002037 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002038 u32 index;
2039 u32 wsec;
2040 s32 err = 0;
2041
Arend van Sprield96b8012012-12-05 15:26:02 +01002042 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002043 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002044 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002045 return -EIO;
2046
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002047 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002048 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002049 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002050 goto done;
2051 }
2052
2053 if (wsec & WEP_ENABLED) {
2054 /* Just select a new current key */
2055 index = key_idx;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002056 err = brcmf_fil_cmd_int_set(ifp,
Arend van Sprielac24be62012-10-22 10:36:23 -07002057 BRCMF_C_SET_KEY_PRIMARY, index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002058 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002059 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002060 }
2061done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002062 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002063 return err;
2064}
2065
2066static s32
2067brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
2068 u8 key_idx, const u8 *mac_addr, struct key_params *params)
2069{
Hante Meuleman992f6062013-04-02 21:06:17 +02002070 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002071 struct brcmf_wsec_key key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002072 s32 err = 0;
Hante Meuleman992f6062013-04-02 21:06:17 +02002073 u8 keybuf[8];
Arend van Spriel5b435de2011-10-05 13:19:03 +02002074
2075 memset(&key, 0, sizeof(key));
2076 key.index = (u32) key_idx;
2077 /* Instead of bcast for ea address for default wep keys,
2078 driver needs it to be Null */
2079 if (!is_multicast_ether_addr(mac_addr))
2080 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
2081 key.len = (u32) params->key_len;
2082 /* check for key index change */
2083 if (key.len == 0) {
2084 /* key delete */
Hante Meuleman118eb302014-12-21 12:43:49 +01002085 err = send_key_to_dongle(ifp, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002086 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002087 brcmf_err("key delete error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002088 } else {
2089 if (key.len > sizeof(key.data)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002090 brcmf_err("Invalid key length (%d)\n", key.len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002091 return -EINVAL;
2092 }
2093
Arend van Spriel16886732012-12-05 15:26:04 +01002094 brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002095 memcpy(key.data, params->key, key.len);
2096
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002097 if (!brcmf_is_apmode(ifp->vif) &&
Hante Meuleman992f6062013-04-02 21:06:17 +02002098 (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
2099 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002100 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2101 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2102 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2103 }
2104
2105 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
2106 if (params->seq && params->seq_len == 6) {
2107 /* rx iv */
2108 u8 *ivptr;
2109 ivptr = (u8 *) params->seq;
2110 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2111 (ivptr[3] << 8) | ivptr[2];
2112 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2113 key.iv_initialized = true;
2114 }
2115
2116 switch (params->cipher) {
2117 case WLAN_CIPHER_SUITE_WEP40:
2118 key.algo = CRYPTO_ALGO_WEP1;
Arend van Spriel16886732012-12-05 15:26:04 +01002119 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002120 break;
2121 case WLAN_CIPHER_SUITE_WEP104:
2122 key.algo = CRYPTO_ALGO_WEP128;
Arend van Spriel16886732012-12-05 15:26:04 +01002123 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002124 break;
2125 case WLAN_CIPHER_SUITE_TKIP:
2126 key.algo = CRYPTO_ALGO_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002127 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002128 break;
2129 case WLAN_CIPHER_SUITE_AES_CMAC:
2130 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002131 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002132 break;
2133 case WLAN_CIPHER_SUITE_CCMP:
2134 key.algo = CRYPTO_ALGO_AES_CCM;
Arend van Spriel16886732012-12-05 15:26:04 +01002135 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002136 break;
2137 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002138 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002139 return -EINVAL;
2140 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002141 err = send_key_to_dongle(ifp, &key);
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002142 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002143 brcmf_err("wsec_key error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002144 }
2145 return err;
2146}
2147
2148static s32
2149brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2150 u8 key_idx, bool pairwise, const u8 *mac_addr,
2151 struct key_params *params)
2152{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002153 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman118eb302014-12-21 12:43:49 +01002154 struct brcmf_wsec_key *key;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002155 s32 val;
2156 s32 wsec;
2157 s32 err = 0;
2158 u8 keybuf[8];
2159
Arend van Sprield96b8012012-12-05 15:26:02 +01002160 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002161 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002162 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002163 return -EIO;
2164
Hante Meuleman118eb302014-12-21 12:43:49 +01002165 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2166 /* we ignore this key index in this case */
2167 brcmf_err("invalid key index (%d)\n", key_idx);
2168 return -EINVAL;
2169 }
2170
Daniel Kim787eb032014-01-29 15:32:23 +01002171 if (mac_addr &&
2172 (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2173 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01002174 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002175 return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
2176 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002177
Hante Meuleman118eb302014-12-21 12:43:49 +01002178 key = &ifp->vif->profile.key[key_idx];
2179 memset(key, 0, sizeof(*key));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002180
Hante Meuleman118eb302014-12-21 12:43:49 +01002181 if (params->key_len > sizeof(key->data)) {
2182 brcmf_err("Too long key length (%u)\n", params->key_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002183 err = -EINVAL;
2184 goto done;
2185 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002186 key->len = params->key_len;
2187 key->index = key_idx;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002188
Hante Meuleman118eb302014-12-21 12:43:49 +01002189 memcpy(key->data, params->key, key->len);
2190
2191 key->flags = BRCMF_PRIMARY_KEY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002192 switch (params->cipher) {
2193 case WLAN_CIPHER_SUITE_WEP40:
Hante Meuleman118eb302014-12-21 12:43:49 +01002194 key->algo = CRYPTO_ALGO_WEP1;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002195 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002196 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002197 break;
2198 case WLAN_CIPHER_SUITE_WEP104:
Hante Meuleman118eb302014-12-21 12:43:49 +01002199 key->algo = CRYPTO_ALGO_WEP128;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002200 val = WEP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002201 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002202 break;
2203 case WLAN_CIPHER_SUITE_TKIP:
Arend van Spriel967fe2c2014-03-15 17:18:21 +01002204 if (!brcmf_is_apmode(ifp->vif)) {
Hante Meuleman992f6062013-04-02 21:06:17 +02002205 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
Hante Meuleman118eb302014-12-21 12:43:49 +01002206 memcpy(keybuf, &key->data[24], sizeof(keybuf));
2207 memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
2208 memcpy(&key->data[16], keybuf, sizeof(keybuf));
Hante Meuleman1a873342012-09-27 14:17:54 +02002209 }
Hante Meuleman118eb302014-12-21 12:43:49 +01002210 key->algo = CRYPTO_ALGO_TKIP;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002211 val = TKIP_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002212 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002213 break;
2214 case WLAN_CIPHER_SUITE_AES_CMAC:
Hante Meuleman118eb302014-12-21 12:43:49 +01002215 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002216 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002217 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002218 break;
2219 case WLAN_CIPHER_SUITE_CCMP:
Hante Meuleman118eb302014-12-21 12:43:49 +01002220 key->algo = CRYPTO_ALGO_AES_CCM;
Hante Meulemanf09d0c02012-09-27 14:17:48 +02002221 val = AES_ENABLED;
Arend van Spriel16886732012-12-05 15:26:04 +01002222 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002223 break;
2224 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01002225 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002226 err = -EINVAL;
2227 goto done;
2228 }
2229
Hante Meuleman118eb302014-12-21 12:43:49 +01002230 err = send_key_to_dongle(ifp, key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002231 if (err)
2232 goto done;
2233
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002234 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002235 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002236 brcmf_err("get wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002237 goto done;
2238 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002239 wsec |= val;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002240 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002241 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002242 brcmf_err("set wsec error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002243 goto done;
2244 }
2245
Arend van Spriel5b435de2011-10-05 13:19:03 +02002246done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002247 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002248 return err;
2249}
2250
2251static s32
2252brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2253 u8 key_idx, bool pairwise, const u8 *mac_addr)
2254{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002255 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002256 struct brcmf_wsec_key key;
2257 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002258
Arend van Sprield96b8012012-12-05 15:26:02 +01002259 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07002260 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002261 return -EIO;
2262
Hante Meuleman118eb302014-12-21 12:43:49 +01002263 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
Hante Meuleman256c3742012-11-05 16:22:28 -08002264 /* we ignore this key index in this case */
Hante Meuleman256c3742012-11-05 16:22:28 -08002265 return -EINVAL;
2266 }
2267
Arend van Spriel5b435de2011-10-05 13:19:03 +02002268 memset(&key, 0, sizeof(key));
2269
2270 key.index = (u32) key_idx;
2271 key.flags = BRCMF_PRIMARY_KEY;
2272 key.algo = CRYPTO_ALGO_OFF;
2273
Arend van Spriel16886732012-12-05 15:26:04 +01002274 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002275
2276 /* Set the new key/index */
Hante Meuleman118eb302014-12-21 12:43:49 +01002277 err = send_key_to_dongle(ifp, &key);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002278
Arend van Sprield96b8012012-12-05 15:26:02 +01002279 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002280 return err;
2281}
2282
2283static s32
2284brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2285 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
2286 void (*callback) (void *cookie, struct key_params * params))
2287{
2288 struct key_params params;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002289 struct brcmf_if *ifp = netdev_priv(ndev);
2290 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002291 struct brcmf_cfg80211_security *sec;
2292 s32 wsec;
2293 s32 err = 0;
2294
Arend van Sprield96b8012012-12-05 15:26:02 +01002295 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel16886732012-12-05 15:26:04 +01002296 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
Arend van Sprielce81e312012-10-22 13:55:37 -07002297 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002298 return -EIO;
2299
2300 memset(&params, 0, sizeof(params));
2301
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002302 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002303 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002304 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002305 /* Ignore this error, may happen during DISASSOC */
2306 err = -EAGAIN;
2307 goto done;
2308 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002309 if (wsec & WEP_ENABLED) {
Arend van Spriel06bb1232012-09-27 14:17:56 +02002310 sec = &profile->sec;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002311 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2312 params.cipher = WLAN_CIPHER_SUITE_WEP40;
Arend van Spriel16886732012-12-05 15:26:04 +01002313 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002314 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2315 params.cipher = WLAN_CIPHER_SUITE_WEP104;
Arend van Spriel16886732012-12-05 15:26:04 +01002316 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002317 }
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002318 } else if (wsec & TKIP_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002319 params.cipher = WLAN_CIPHER_SUITE_TKIP;
Arend van Spriel16886732012-12-05 15:26:04 +01002320 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002321 } else if (wsec & AES_ENABLED) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002322 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
Arend van Spriel16886732012-12-05 15:26:04 +01002323 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
Hante Meulemanc5bf53a2013-04-02 21:06:19 +02002324 } else {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002325 brcmf_err("Invalid algo (0x%x)\n", wsec);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002326 err = -EINVAL;
2327 goto done;
2328 }
2329 callback(cookie, &params);
2330
2331done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002332 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002333 return err;
2334}
2335
2336static s32
2337brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2338 struct net_device *ndev, u8 key_idx)
2339{
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002340 brcmf_dbg(INFO, "Not supported\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002341
2342 return -EOPNOTSUPP;
2343}
2344
Hante Meuleman118eb302014-12-21 12:43:49 +01002345static void
2346brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
2347{
2348 s32 err;
2349 u8 key_idx;
2350 struct brcmf_wsec_key *key;
2351 s32 wsec;
2352
2353 for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
2354 key = &ifp->vif->profile.key[key_idx];
2355 if ((key->algo == CRYPTO_ALGO_WEP1) ||
2356 (key->algo == CRYPTO_ALGO_WEP128))
2357 break;
2358 }
2359 if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
2360 return;
2361
2362 err = send_key_to_dongle(ifp, key);
2363 if (err) {
2364 brcmf_err("Setting WEP key failed (%d)\n", err);
2365 return;
2366 }
2367 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2368 if (err) {
2369 brcmf_err("get wsec error (%d)\n", err);
2370 return;
2371 }
2372 wsec |= WEP_ENABLED;
2373 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2374 if (err)
2375 brcmf_err("set wsec error (%d)\n", err);
2376}
2377
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002378static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si)
2379{
2380 struct nl80211_sta_flag_update *sfu;
2381
2382 brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags);
2383 si->filled |= BIT(NL80211_STA_INFO_STA_FLAGS);
2384 sfu = &si->sta_flags;
2385 sfu->mask = BIT(NL80211_STA_FLAG_WME) |
2386 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2387 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2388 BIT(NL80211_STA_FLAG_AUTHORIZED);
2389 if (fw_sta_flags & BRCMF_STA_WME)
2390 sfu->set |= BIT(NL80211_STA_FLAG_WME);
2391 if (fw_sta_flags & BRCMF_STA_AUTHE)
2392 sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2393 if (fw_sta_flags & BRCMF_STA_ASSOC)
2394 sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2395 if (fw_sta_flags & BRCMF_STA_AUTHO)
2396 sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2397}
2398
2399static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si)
2400{
2401 struct {
2402 __le32 len;
2403 struct brcmf_bss_info_le bss_le;
2404 } *buf;
2405 u16 capability;
2406 int err;
2407
2408 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2409 if (!buf)
2410 return;
2411
2412 buf->len = cpu_to_le32(WL_BSS_INFO_MAX);
2413 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf,
2414 WL_BSS_INFO_MAX);
2415 if (err) {
2416 brcmf_err("Failed to get bss info (%d)\n", err);
2417 return;
2418 }
2419 si->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
2420 si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period);
2421 si->bss_param.dtim_period = buf->bss_le.dtim_period;
2422 capability = le16_to_cpu(buf->bss_le.capability);
2423 if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT)
2424 si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2425 if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2426 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2427 if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2428 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2429}
2430
Arend van Spriel5b435de2011-10-05 13:19:03 +02002431static s32
Hante Meuleman3f5893d2016-01-02 09:41:37 +01002432brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp,
2433 struct station_info *sinfo)
2434{
2435 struct brcmf_scb_val_le scbval;
2436 struct brcmf_pktcnt_le pktcnt;
2437 s32 err;
2438 u32 rate;
2439 u32 rssi;
2440
2441 /* Get the current tx rate */
2442 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
2443 if (err < 0) {
2444 brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err);
2445 return err;
2446 }
2447 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
2448 sinfo->txrate.legacy = rate * 5;
2449
2450 memset(&scbval, 0, sizeof(scbval));
2451 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval,
2452 sizeof(scbval));
2453 if (err) {
2454 brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err);
2455 return err;
2456 }
2457 rssi = le32_to_cpu(scbval.val);
2458 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2459 sinfo->signal = rssi;
2460
2461 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt,
2462 sizeof(pktcnt));
2463 if (err) {
2464 brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err);
2465 return err;
2466 }
2467 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS) |
2468 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
2469 BIT(NL80211_STA_INFO_TX_PACKETS) |
2470 BIT(NL80211_STA_INFO_TX_FAILED);
2471 sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt);
2472 sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt);
2473 sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt);
2474 sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt);
2475
2476 return 0;
2477}
2478
2479static s32
Arend van Spriel5b435de2011-10-05 13:19:03 +02002480brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002481 const u8 *mac, struct station_info *sinfo)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002482{
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002483 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002484 s32 err = 0;
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002485 struct brcmf_sta_info_le sta_info_le;
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002486 u32 sta_flags;
2487 u32 is_tdls_peer;
Hante Meulemancae355d2015-10-08 20:33:17 +02002488 s32 total_rssi;
2489 s32 count_rssi;
2490 u32 i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002491
Arend van Sprield96b8012012-12-05 15:26:02 +01002492 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
Arend van Sprielce81e312012-10-22 13:55:37 -07002493 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002494 return -EIO;
2495
Hante Meuleman3f5893d2016-01-02 09:41:37 +01002496 if (brcmf_is_ibssmode(ifp->vif))
2497 return brcmf_cfg80211_get_station_ibss(ifp, sinfo);
2498
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002499 memset(&sta_info_le, 0, sizeof(sta_info_le));
2500 memcpy(&sta_info_le, mac, ETH_ALEN);
2501 err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info",
2502 &sta_info_le,
2503 sizeof(sta_info_le));
2504 is_tdls_peer = !err;
2505 if (err) {
Arend van Spriel0abb5f212012-10-22 13:55:32 -07002506 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
Arend van Sprielac24be62012-10-22 10:36:23 -07002507 &sta_info_le,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002508 sizeof(sta_info_le));
Hante Meuleman1a873342012-09-27 14:17:54 +02002509 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002510 brcmf_err("GET STA INFO failed, %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02002511 goto done;
Hante Meuleman7f6c5622012-08-30 10:05:37 +02002512 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002513 }
2514 brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver));
2515 sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME);
2516 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2517 sta_flags = le32_to_cpu(sta_info_le.flags);
2518 brcmf_convert_sta_flags(sta_flags, sinfo);
2519 sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2520 if (is_tdls_peer)
2521 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2522 else
2523 sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2524 if (sta_flags & BRCMF_STA_ASSOC) {
2525 sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
2526 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
2527 brcmf_fill_bss_param(ifp, sinfo);
2528 }
2529 if (sta_flags & BRCMF_STA_SCBSTATS) {
2530 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
2531 sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures);
2532 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
2533 sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts);
2534 sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts);
2535 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
2536 sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts);
2537 sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts);
2538 if (sinfo->tx_packets) {
Johannes Berg319090b2014-11-17 14:08:11 +01002539 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002540 sinfo->txrate.legacy =
2541 le32_to_cpu(sta_info_le.tx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002542 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002543 if (sinfo->rx_packets) {
2544 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
Hante Meuleman124d5172015-10-08 20:33:16 +02002545 sinfo->rxrate.legacy =
2546 le32_to_cpu(sta_info_le.rx_rate) / 100;
Hante Meuleman1a873342012-09-27 14:17:54 +02002547 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002548 if (le16_to_cpu(sta_info_le.ver) >= 4) {
2549 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES);
2550 sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes);
2551 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES);
2552 sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes);
2553 }
Hante Meulemancae355d2015-10-08 20:33:17 +02002554 total_rssi = 0;
2555 count_rssi = 0;
2556 for (i = 0; i < BRCMF_ANT_MAX; i++) {
2557 if (sta_info_le.rssi[i]) {
2558 sinfo->chain_signal_avg[count_rssi] =
2559 sta_info_le.rssi[i];
2560 sinfo->chain_signal[count_rssi] =
2561 sta_info_le.rssi[i];
2562 total_rssi += sta_info_le.rssi[i];
2563 count_rssi++;
2564 }
2565 }
2566 if (count_rssi) {
2567 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
2568 sinfo->chains = count_rssi;
2569
2570 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2571 total_rssi /= count_rssi;
2572 sinfo->signal = total_rssi;
2573 }
Arend van Spriel1f0dc592015-06-11 00:12:19 +02002574 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02002575done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002576 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002577 return err;
2578}
2579
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02002580static int
2581brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
2582 int idx, u8 *mac, struct station_info *sinfo)
2583{
2584 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2585 struct brcmf_if *ifp = netdev_priv(ndev);
2586 s32 err;
2587
2588 brcmf_dbg(TRACE, "Enter, idx %d\n", idx);
2589
2590 if (idx == 0) {
2591 cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST);
2592 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST,
2593 &cfg->assoclist,
2594 sizeof(cfg->assoclist));
2595 if (err) {
2596 brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n",
2597 err);
2598 cfg->assoclist.count = 0;
2599 return -EOPNOTSUPP;
2600 }
2601 }
2602 if (idx < le32_to_cpu(cfg->assoclist.count)) {
2603 memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN);
2604 return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo);
2605 }
2606 return -ENOENT;
2607}
2608
Arend van Spriel5b435de2011-10-05 13:19:03 +02002609static s32
2610brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2611 bool enabled, s32 timeout)
2612{
2613 s32 pm;
2614 s32 err = 0;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002615 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielc1179032012-10-22 13:55:33 -07002616 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002617
Arend van Sprield96b8012012-12-05 15:26:02 +01002618 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002619
2620 /*
2621 * Powersave enable/disable request is coming from the
2622 * cfg80211 even before the interface is up. In that
2623 * scenario, driver will be storing the power save
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002624 * preference in cfg struct to apply this to
Arend van Spriel5b435de2011-10-05 13:19:03 +02002625 * FW later while initializing the dongle
2626 */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002627 cfg->pwr_save = enabled;
Arend van Sprielce81e312012-10-22 13:55:37 -07002628 if (!check_vif_up(ifp->vif)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02002629
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002630 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002631 goto done;
2632 }
2633
2634 pm = enabled ? PM_FAST : PM_OFF;
Hante Meuleman102fd0d2013-05-27 21:09:59 +02002635 /* Do not enable the power save after assoc if it is a p2p interface */
2636 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2637 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2638 pm = PM_OFF;
2639 }
Arend van Spriel647c9ae2012-12-05 15:26:01 +01002640 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02002641
Arend van Sprielc1179032012-10-22 13:55:33 -07002642 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002643 if (err) {
2644 if (err == -ENODEV)
Arend van Spriel57d6e912012-12-05 15:26:00 +01002645 brcmf_err("net_device is not ready yet\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002646 else
Arend van Spriel57d6e912012-12-05 15:26:00 +01002647 brcmf_err("error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002648 }
2649done:
Arend van Sprield96b8012012-12-05 15:26:02 +01002650 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002651 return err;
2652}
2653
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002654static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
Roland Vossend34bf642011-10-18 14:03:01 +02002655 struct brcmf_bss_info_le *bi)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002656{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002657 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002658 struct ieee80211_channel *notify_channel;
2659 struct cfg80211_bss *bss;
2660 struct ieee80211_supported_band *band;
Franky Lin83cf17a2013-04-11 13:28:50 +02002661 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002662 u16 channel;
2663 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002664 u16 notify_capability;
2665 u16 notify_interval;
2666 u8 *notify_ie;
2667 size_t notify_ielen;
2668 s32 notify_signal;
2669
2670 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002671 brcmf_err("Bss info is larger than buffer. Discarding\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002672 return 0;
2673 }
2674
Franky Lin83cf17a2013-04-11 13:28:50 +02002675 if (!bi->ctl_ch) {
2676 ch.chspec = le16_to_cpu(bi->chanspec);
2677 cfg->d11inf.decchspec(&ch);
2678 bi->ctl_ch = ch.chnum;
2679 }
2680 channel = bi->ctl_ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002681
2682 if (channel <= CH_MAX_2G_CHANNEL)
2683 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2684 else
2685 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2686
2687 freq = ieee80211_channel_to_frequency(channel, band->band);
2688 notify_channel = ieee80211_get_channel(wiphy, freq);
2689
Arend van Spriel5b435de2011-10-05 13:19:03 +02002690 notify_capability = le16_to_cpu(bi->capability);
2691 notify_interval = le16_to_cpu(bi->beacon_period);
2692 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2693 notify_ielen = le32_to_cpu(bi->ie_length);
2694 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2695
Arend van Spriel16886732012-12-05 15:26:04 +01002696 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2697 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2698 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2699 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2700 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002701
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002702 bss = cfg80211_inform_bss(wiphy, notify_channel,
2703 CFG80211_BSS_FTYPE_UNKNOWN,
2704 (const u8 *)bi->BSSID,
2705 0, notify_capability,
2706 notify_interval, notify_ie,
2707 notify_ielen, notify_signal,
2708 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002709
Franky Line78946e2011-11-10 20:30:34 +01002710 if (!bss)
2711 return -ENOMEM;
2712
Johannes Berg5b112d32013-02-01 01:49:58 +01002713 cfg80211_put_bss(wiphy, bss);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002714
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03002715 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002716}
2717
Roland Vossen6f09be02011-10-18 14:03:02 +02002718static struct brcmf_bss_info_le *
2719next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2720{
2721 if (bss == NULL)
2722 return list->bss_info_le;
2723 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2724 le32_to_cpu(bss->length));
2725}
2726
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002727static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002728{
2729 struct brcmf_scan_results *bss_list;
Roland Vossend34bf642011-10-18 14:03:01 +02002730 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
Arend van Spriel5b435de2011-10-05 13:19:03 +02002731 s32 err = 0;
2732 int i;
2733
Hante Meulemanef8596e2014-09-30 10:23:13 +02002734 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
Arend van Spriel0ecd8162012-11-05 16:22:11 -08002735 if (bss_list->count != 0 &&
2736 bss_list->version != BRCMF_BSS_INFO_VERSION) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002737 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2738 bss_list->version);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002739 return -EOPNOTSUPP;
2740 }
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002741 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
Hante Meulemanf07998952012-11-05 16:22:13 -08002742 for (i = 0; i < bss_list->count; i++) {
Roland Vossen6f09be02011-10-18 14:03:02 +02002743 bi = next_bss_le(bss_list, bi);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002744 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002745 if (err)
2746 break;
2747 }
2748 return err;
2749}
2750
Hante Meulemanb0a79082015-12-10 13:43:07 +01002751static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg,
2752 struct net_device *ndev, const u8 *bssid)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002753{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002754 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002755 struct ieee80211_channel *notify_channel;
Roland Vossend34bf642011-10-18 14:03:01 +02002756 struct brcmf_bss_info_le *bi = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002757 struct ieee80211_supported_band *band;
Franky Line78946e2011-11-10 20:30:34 +01002758 struct cfg80211_bss *bss;
Franky Lin83cf17a2013-04-11 13:28:50 +02002759 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002760 u8 *buf = NULL;
2761 s32 err = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002762 u32 freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002763 u16 notify_capability;
2764 u16 notify_interval;
2765 u8 *notify_ie;
2766 size_t notify_ielen;
2767 s32 notify_signal;
2768
Arend van Sprield96b8012012-12-05 15:26:02 +01002769 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002770
2771 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2772 if (buf == NULL) {
2773 err = -ENOMEM;
2774 goto CleanUp;
2775 }
2776
2777 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2778
Arend van Sprielac24be62012-10-22 10:36:23 -07002779 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2780 buf, WL_BSS_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002781 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002782 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002783 goto CleanUp;
2784 }
2785
Roland Vossend34bf642011-10-18 14:03:01 +02002786 bi = (struct brcmf_bss_info_le *)(buf + 4);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002787
Franky Lin83cf17a2013-04-11 13:28:50 +02002788 ch.chspec = le16_to_cpu(bi->chanspec);
2789 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002790
Franky Lin83cf17a2013-04-11 13:28:50 +02002791 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002792 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2793 else
2794 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2795
Franky Lin83cf17a2013-04-11 13:28:50 +02002796 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Hante Meulemanb0a79082015-12-10 13:43:07 +01002797 cfg->channel = freq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002798 notify_channel = ieee80211_get_channel(wiphy, freq);
2799
Arend van Spriel5b435de2011-10-05 13:19:03 +02002800 notify_capability = le16_to_cpu(bi->capability);
2801 notify_interval = le16_to_cpu(bi->beacon_period);
2802 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2803 notify_ielen = le32_to_cpu(bi->ie_length);
2804 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2805
Franky Lin83cf17a2013-04-11 13:28:50 +02002806 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
Arend van Spriel16886732012-12-05 15:26:04 +01002807 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2808 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2809 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002810
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02002811 bss = cfg80211_inform_bss(wiphy, notify_channel,
2812 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2813 notify_capability, notify_interval,
2814 notify_ie, notify_ielen, notify_signal,
2815 GFP_KERNEL);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002816
Franky Line78946e2011-11-10 20:30:34 +01002817 if (!bss) {
2818 err = -ENOMEM;
2819 goto CleanUp;
2820 }
2821
Johannes Berg5b112d32013-02-01 01:49:58 +01002822 cfg80211_put_bss(wiphy, bss);
Franky Line78946e2011-11-10 20:30:34 +01002823
Arend van Spriel5b435de2011-10-05 13:19:03 +02002824CleanUp:
2825
2826 kfree(buf);
2827
Arend van Sprield96b8012012-12-05 15:26:02 +01002828 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002829
2830 return err;
2831}
2832
Hante Meuleman89286dc2013-02-08 15:53:46 +01002833static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2834 struct brcmf_if *ifp)
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002835{
Roland Vossend34bf642011-10-18 14:03:01 +02002836 struct brcmf_bss_info_le *bi;
Johannes Berg4b5800f2014-01-15 14:55:59 +01002837 const struct brcmf_tlv *tim;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002838 u16 beacon_interval;
2839 u8 dtim_period;
2840 size_t ie_len;
2841 u8 *ie;
2842 s32 err = 0;
2843
Arend van Sprield96b8012012-12-05 15:26:02 +01002844 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01002845 if (brcmf_is_ibssmode(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02002846 return err;
2847
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002848 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
Arend van Sprielac24be62012-10-22 10:36:23 -07002849 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07002850 cfg->extra_buf, WL_EXTRA_BUF_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002851 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002852 brcmf_err("Could not get bss info %d\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002853 goto update_bss_info_out;
2854 }
2855
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002856 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2857 err = brcmf_inform_single_bss(cfg, bi);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002858 if (err)
2859 goto update_bss_info_out;
2860
2861 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2862 ie_len = le32_to_cpu(bi->ie_length);
2863 beacon_interval = le16_to_cpu(bi->beacon_period);
2864
Alwin Beukersf8e4b412011-10-12 20:51:28 +02002865 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002866 if (tim)
2867 dtim_period = tim->data[1];
2868 else {
2869 /*
2870 * active scan was done so we could not get dtim
2871 * information out of probe response.
2872 * so we speficially query dtim information to dongle.
2873 */
2874 u32 var;
Arend van Sprielac24be62012-10-22 10:36:23 -07002875 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002876 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002877 brcmf_err("wl dtim_assoc failed (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002878 goto update_bss_info_out;
2879 }
2880 dtim_period = (u8)var;
2881 }
2882
Arend van Spriel5b435de2011-10-05 13:19:03 +02002883update_bss_info_out:
Arend van Sprield96b8012012-12-05 15:26:02 +01002884 brcmf_dbg(TRACE, "Exit");
Arend van Spriel5b435de2011-10-05 13:19:03 +02002885 return err;
2886}
2887
Hante Meuleman18e2f612013-02-08 15:53:49 +01002888void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02002889{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002890 struct escan_info *escan = &cfg->escan_info;
Arend van Spriel5b435de2011-10-05 13:19:03 +02002891
Arend van Sprielc1179032012-10-22 13:55:33 -07002892 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Hante Meulemanf07998952012-11-05 16:22:13 -08002893 if (cfg->scan_request) {
Arend van Spriel108a4be2012-09-19 22:21:07 +02002894 escan->escan_state = WL_ESCAN_STATE_IDLE;
Arend van Spriela0f472a2013-04-05 10:57:49 +02002895 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
Arend van Spriel108a4be2012-09-19 22:21:07 +02002896 }
Arend van Sprielc1179032012-10-22 13:55:33 -07002897 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2898 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
Arend van Spriel5b435de2011-10-05 13:19:03 +02002899}
2900
Hante Meulemane756af52012-09-11 21:18:52 +02002901static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2902{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002903 struct brcmf_cfg80211_info *cfg =
2904 container_of(work, struct brcmf_cfg80211_info,
Hante Meulemane756af52012-09-11 21:18:52 +02002905 escan_timeout_work);
2906
Hante Meulemanef8596e2014-09-30 10:23:13 +02002907 brcmf_inform_bss(cfg);
Arend van Spriela0f472a2013-04-05 10:57:49 +02002908 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
Hante Meulemane756af52012-09-11 21:18:52 +02002909}
2910
2911static void brcmf_escan_timeout(unsigned long data)
2912{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002913 struct brcmf_cfg80211_info *cfg =
2914 (struct brcmf_cfg80211_info *)data;
Hante Meulemane756af52012-09-11 21:18:52 +02002915
Arend van Spriel27a68fe2012-09-27 14:17:55 +02002916 if (cfg->scan_request) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002917 brcmf_err("timer expired\n");
Hante Meulemanf07998952012-11-05 16:22:13 -08002918 schedule_work(&cfg->escan_timeout_work);
Hante Meulemane756af52012-09-11 21:18:52 +02002919 }
2920}
2921
2922static s32
Franky Lin83cf17a2013-04-11 13:28:50 +02002923brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2924 struct brcmf_bss_info_le *bss,
Hante Meulemane756af52012-09-11 21:18:52 +02002925 struct brcmf_bss_info_le *bss_info_le)
2926{
Franky Lin83cf17a2013-04-11 13:28:50 +02002927 struct brcmu_chan ch_bss, ch_bss_info_le;
2928
2929 ch_bss.chspec = le16_to_cpu(bss->chanspec);
2930 cfg->d11inf.decchspec(&ch_bss);
2931 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
2932 cfg->d11inf.decchspec(&ch_bss_info_le);
2933
Hante Meulemane756af52012-09-11 21:18:52 +02002934 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
Franky Lin83cf17a2013-04-11 13:28:50 +02002935 ch_bss.band == ch_bss_info_le.band &&
Hante Meulemane756af52012-09-11 21:18:52 +02002936 bss_info_le->SSID_len == bss->SSID_len &&
2937 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002938 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
2939 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
Arend van Spriel029591f2012-09-19 22:21:06 +02002940 s16 bss_rssi = le16_to_cpu(bss->RSSI);
2941 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
2942
Hante Meulemane756af52012-09-11 21:18:52 +02002943 /* preserve max RSSI if the measurements are
2944 * both on-channel or both off-channel
2945 */
Arend van Spriel029591f2012-09-19 22:21:06 +02002946 if (bss_info_rssi > bss_rssi)
Hante Meulemane756af52012-09-11 21:18:52 +02002947 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002948 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
2949 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
Hante Meulemane756af52012-09-11 21:18:52 +02002950 /* preserve the on-channel rssi measurement
2951 * if the new measurement is off channel
2952 */
2953 bss->RSSI = bss_info_le->RSSI;
Arend van Spriel6f5838a2013-11-29 12:25:19 +01002954 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
Hante Meulemane756af52012-09-11 21:18:52 +02002955 }
2956 return 1;
2957 }
2958 return 0;
2959}
2960
2961static s32
Arend van Spriel19937322012-11-05 16:22:32 -08002962brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
Hante Meulemane756af52012-09-11 21:18:52 +02002963 const struct brcmf_event_msg *e, void *data)
2964{
Arend van Spriel19937322012-11-05 16:22:32 -08002965 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Hante Meulemane756af52012-09-11 21:18:52 +02002966 s32 status;
Hante Meulemane756af52012-09-11 21:18:52 +02002967 struct brcmf_escan_result_le *escan_result_le;
2968 struct brcmf_bss_info_le *bss_info_le;
2969 struct brcmf_bss_info_le *bss = NULL;
2970 u32 bi_length;
2971 struct brcmf_scan_results *list;
2972 u32 i;
Arend van Spriel97ed15c2012-09-13 21:12:06 +02002973 bool aborted;
Hante Meulemane756af52012-09-11 21:18:52 +02002974
Arend van Spriel5c36b992012-11-14 18:46:05 -08002975 status = e->status;
Hante Meulemane756af52012-09-11 21:18:52 +02002976
Arend van Spriela0f472a2013-04-05 10:57:49 +02002977 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
Hante Meuleman37a869e2015-10-29 20:33:17 +01002978 brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx);
Hante Meulemane756af52012-09-11 21:18:52 +02002979 return -EPERM;
2980 }
2981
2982 if (status == BRCMF_E_STATUS_PARTIAL) {
Arend van Spriel4e8a0082012-12-05 15:26:03 +01002983 brcmf_dbg(SCAN, "ESCAN Partial result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002984 escan_result_le = (struct brcmf_escan_result_le *) data;
2985 if (!escan_result_le) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002986 brcmf_err("Invalid escan result (NULL pointer)\n");
Hante Meulemane756af52012-09-11 21:18:52 +02002987 goto exit;
2988 }
Hante Meulemane756af52012-09-11 21:18:52 +02002989 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01002990 brcmf_err("Invalid bss_count %d: ignoring\n",
2991 escan_result_le->bss_count);
Hante Meulemane756af52012-09-11 21:18:52 +02002992 goto exit;
2993 }
2994 bss_info_le = &escan_result_le->bss_info_le;
2995
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002996 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
2997 goto exit;
2998
2999 if (!cfg->scan_request) {
3000 brcmf_dbg(SCAN, "result without cfg80211 request\n");
3001 goto exit;
3002 }
3003
Hante Meulemane756af52012-09-11 21:18:52 +02003004 bi_length = le32_to_cpu(bss_info_le->length);
3005 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
3006 WL_ESCAN_RESULTS_FIXED_SIZE)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003007 brcmf_err("Invalid bss_info length %d: ignoring\n",
3008 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02003009 goto exit;
3010 }
3011
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003012 if (!(cfg_to_wiphy(cfg)->interface_modes &
Hante Meulemane756af52012-09-11 21:18:52 +02003013 BIT(NL80211_IFTYPE_ADHOC))) {
3014 if (le16_to_cpu(bss_info_le->capability) &
3015 WLAN_CAPABILITY_IBSS) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003016 brcmf_err("Ignoring IBSS result\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003017 goto exit;
3018 }
3019 }
3020
3021 list = (struct brcmf_scan_results *)
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003022 cfg->escan_info.escan_buf;
Hante Meulemand5367332016-02-17 11:26:51 +01003023 if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003024 brcmf_err("Buffer is too small: ignoring\n");
Hante Meulemane756af52012-09-11 21:18:52 +02003025 goto exit;
3026 }
3027
3028 for (i = 0; i < list->count; i++) {
3029 bss = bss ? (struct brcmf_bss_info_le *)
3030 ((unsigned char *)bss +
3031 le32_to_cpu(bss->length)) : list->bss_info_le;
Franky Lin83cf17a2013-04-11 13:28:50 +02003032 if (brcmf_compare_update_same_bss(cfg, bss,
3033 bss_info_le))
Hante Meulemane756af52012-09-11 21:18:52 +02003034 goto exit;
3035 }
Hante Meulemand5367332016-02-17 11:26:51 +01003036 memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le,
3037 bi_length);
Hante Meulemane756af52012-09-11 21:18:52 +02003038 list->version = le32_to_cpu(bss_info_le->version);
3039 list->buflen += bi_length;
3040 list->count++;
3041 } else {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003042 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003043 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
3044 goto exit;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003045 if (cfg->scan_request) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003046 brcmf_inform_bss(cfg);
Arend van Spriel97ed15c2012-09-13 21:12:06 +02003047 aborted = status != BRCMF_E_STATUS_SUCCESS;
Hante Meulemanef8596e2014-09-30 10:23:13 +02003048 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
Hante Meulemane756af52012-09-11 21:18:52 +02003049 } else
Hante Meuleman6eda4e22013-02-08 15:54:02 +01003050 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
3051 status);
Hante Meulemane756af52012-09-11 21:18:52 +02003052 }
3053exit:
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03003054 return 0;
Hante Meulemane756af52012-09-11 21:18:52 +02003055}
3056
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003057static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
Hante Meulemane756af52012-09-11 21:18:52 +02003058{
Arend van Spriel5c36b992012-11-14 18:46:05 -08003059 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
3060 brcmf_cfg80211_escan_handler);
Hante Meulemanf07998952012-11-05 16:22:13 -08003061 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
3062 /* Init scan_timeout timer */
3063 init_timer(&cfg->escan_timeout);
3064 cfg->escan_timeout.data = (unsigned long) cfg;
3065 cfg->escan_timeout.function = brcmf_escan_timeout;
3066 INIT_WORK(&cfg->escan_timeout_work,
3067 brcmf_cfg80211_escan_timeout_worker);
Hante Meulemane756af52012-09-11 21:18:52 +02003068}
3069
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003070/* PFN result doesn't have all the info which are required by the supplicant
3071 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3072 * via wl_inform_single_bss in the required format. Escan does require the
3073 * scan request in the form of cfg80211_scan_request. For timebeing, create
3074 * cfg80211_scan_request one out of the received PNO event.
3075 */
3076static s32
3077brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
3078 const struct brcmf_event_msg *e, void *data)
3079{
3080 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3081 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3082 struct cfg80211_scan_request *request = NULL;
3083 struct cfg80211_ssid *ssid = NULL;
3084 struct ieee80211_channel *channel = NULL;
3085 struct wiphy *wiphy = cfg_to_wiphy(cfg);
3086 int err = 0;
3087 int channel_req = 0;
3088 int band = 0;
3089 struct brcmf_pno_scanresults_le *pfn_result;
3090 u32 result_count;
3091 u32 status;
3092
3093 brcmf_dbg(SCAN, "Enter\n");
3094
Hante Meuleman0aedbca2016-02-17 11:26:54 +01003095 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3096 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3097 return 0;
3098 }
3099
Hante Meuleman5419f7f2016-01-05 11:05:46 +01003100 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3101 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
3102 return 0;
3103 }
3104
3105 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3106 result_count = le32_to_cpu(pfn_result->count);
3107 status = le32_to_cpu(pfn_result->status);
3108
3109 /* PFN event is limited to fit 512 bytes so we may get
3110 * multiple NET_FOUND events. For now place a warning here.
3111 */
3112 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
3113 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
3114 if (result_count > 0) {
3115 int i;
3116
3117 request = kzalloc(sizeof(*request), GFP_KERNEL);
3118 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3119 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
3120 if (!request || !ssid || !channel) {
3121 err = -ENOMEM;
3122 goto out_err;
3123 }
3124
3125 request->wiphy = wiphy;
3126 data += sizeof(struct brcmf_pno_scanresults_le);
3127 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3128
3129 for (i = 0; i < result_count; i++) {
3130 netinfo = &netinfo_start[i];
3131 if (!netinfo) {
3132 brcmf_err("Invalid netinfo ptr. index: %d\n",
3133 i);
3134 err = -EINVAL;
3135 goto out_err;
3136 }
3137
3138 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3139 netinfo->SSID, netinfo->channel);
3140 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3141 ssid[i].ssid_len = netinfo->SSID_len;
3142 request->n_ssids++;
3143
3144 channel_req = netinfo->channel;
3145 if (channel_req <= CH_MAX_2G_CHANNEL)
3146 band = NL80211_BAND_2GHZ;
3147 else
3148 band = NL80211_BAND_5GHZ;
3149 channel[i].center_freq =
3150 ieee80211_channel_to_frequency(channel_req,
3151 band);
3152 channel[i].band = band;
3153 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3154 request->channels[i] = &channel[i];
3155 request->n_channels++;
3156 }
3157
3158 /* assign parsed ssid array */
3159 if (request->n_ssids)
3160 request->ssids = &ssid[0];
3161
3162 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3163 /* Abort any on-going scan */
3164 brcmf_abort_scanning(cfg);
3165 }
3166
3167 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3168 cfg->escan_info.run = brcmf_run_escan;
3169 err = brcmf_do_escan(cfg, wiphy, ifp, request);
3170 if (err) {
3171 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3172 goto out_err;
3173 }
3174 cfg->sched_escan = true;
3175 cfg->scan_request = request;
3176 } else {
3177 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3178 goto out_err;
3179 }
3180
3181 kfree(ssid);
3182 kfree(channel);
3183 kfree(request);
3184 return 0;
3185
3186out_err:
3187 kfree(ssid);
3188 kfree(channel);
3189 kfree(request);
3190 cfg80211_sched_scan_stopped(wiphy);
3191 return err;
3192}
3193
3194static int brcmf_dev_pno_clean(struct net_device *ndev)
3195{
3196 int ret;
3197
3198 /* Disable pfn */
3199 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
3200 if (ret == 0) {
3201 /* clear pfn */
3202 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3203 NULL, 0);
3204 }
3205 if (ret < 0)
3206 brcmf_err("failed code %d\n", ret);
3207
3208 return ret;
3209}
3210
3211static int brcmf_dev_pno_config(struct brcmf_if *ifp,
3212 struct cfg80211_sched_scan_request *request)
3213{
3214 struct brcmf_pno_param_le pfn_param;
3215 struct brcmf_pno_macaddr_le pfn_mac;
3216 s32 err;
3217 u8 *mac_mask;
3218 int i;
3219
3220 memset(&pfn_param, 0, sizeof(pfn_param));
3221 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3222
3223 /* set extra pno params */
3224 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3225 pfn_param.repeat = BRCMF_PNO_REPEAT;
3226 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3227
3228 /* set up pno scan fr */
3229 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3230
3231 err = brcmf_fil_iovar_data_set(ifp, "pfn_set", &pfn_param,
3232 sizeof(pfn_param));
3233 if (err) {
3234 brcmf_err("pfn_set failed, err=%d\n", err);
3235 return err;
3236 }
3237
3238 /* Find out if mac randomization should be turned on */
3239 if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR))
3240 return 0;
3241
3242 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
3243 pfn_mac.flags = BRCMF_PFN_MAC_OUI_ONLY | BRCMF_PFN_SET_MAC_UNASSOC;
3244
3245 memcpy(pfn_mac.mac, request->mac_addr, ETH_ALEN);
3246 mac_mask = request->mac_addr_mask;
3247 for (i = 0; i < ETH_ALEN; i++) {
3248 pfn_mac.mac[i] &= mac_mask[i];
3249 pfn_mac.mac[i] |= get_random_int() & ~(mac_mask[i]);
3250 }
3251 /* Clear multi bit */
3252 pfn_mac.mac[0] &= 0xFE;
3253 /* Set locally administered */
3254 pfn_mac.mac[0] |= 0x02;
3255
3256 err = brcmf_fil_iovar_data_set(ifp, "pfn_macaddr", &pfn_mac,
3257 sizeof(pfn_mac));
3258 if (err)
3259 brcmf_err("pfn_macaddr failed, err=%d\n", err);
3260
3261 return err;
3262}
3263
3264static int
3265brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3266 struct net_device *ndev,
3267 struct cfg80211_sched_scan_request *request)
3268{
3269 struct brcmf_if *ifp = netdev_priv(ndev);
3270 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
3271 struct brcmf_pno_net_param_le pfn;
3272 int i;
3273 int ret = 0;
3274
3275 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
3276 request->n_match_sets, request->n_ssids);
3277 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3278 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
3279 return -EAGAIN;
3280 }
3281 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3282 brcmf_err("Scanning suppressed: status (%lu)\n",
3283 cfg->scan_status);
3284 return -EAGAIN;
3285 }
3286
3287 if (!request->n_ssids || !request->n_match_sets) {
3288 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
3289 request->n_ssids);
3290 return -EINVAL;
3291 }
3292
3293 if (request->n_ssids > 0) {
3294 for (i = 0; i < request->n_ssids; i++) {
3295 /* Active scan req for ssids */
3296 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3297 request->ssids[i].ssid);
3298
3299 /* match_set ssids is a supert set of n_ssid list,
3300 * so we need not add these set separately.
3301 */
3302 }
3303 }
3304
3305 if (request->n_match_sets > 0) {
3306 /* clean up everything */
3307 ret = brcmf_dev_pno_clean(ndev);
3308 if (ret < 0) {
3309 brcmf_err("failed error=%d\n", ret);
3310 return ret;
3311 }
3312
3313 /* configure pno */
3314 if (brcmf_dev_pno_config(ifp, request))
3315 return -EINVAL;
3316
3317 /* configure each match set */
3318 for (i = 0; i < request->n_match_sets; i++) {
3319 struct cfg80211_ssid *ssid;
3320 u32 ssid_len;
3321
3322 ssid = &request->match_sets[i].ssid;
3323 ssid_len = ssid->ssid_len;
3324
3325 if (!ssid_len) {
3326 brcmf_err("skip broadcast ssid\n");
3327 continue;
3328 }
3329 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3330 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3331 pfn.wsec = cpu_to_le32(0);
3332 pfn.infra = cpu_to_le32(1);
3333 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3334 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3335 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
3336 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
3337 sizeof(pfn));
3338 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3339 ret == 0 ? "set" : "failed", ssid->ssid);
3340 }
3341 /* Enable the PNO */
3342 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
3343 brcmf_err("PNO enable failed!! ret=%d\n", ret);
3344 return -EINVAL;
3345 }
3346 } else {
3347 return -EINVAL;
3348 }
3349
3350 return 0;
3351}
3352
3353static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3354 struct net_device *ndev)
3355{
3356 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3357
3358 brcmf_dbg(SCAN, "enter\n");
3359 brcmf_dev_pno_clean(ndev);
3360 if (cfg->sched_escan)
3361 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
3362 return 0;
3363}
3364
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05003365static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003366{
3367 if (ms < 1000 / HZ) {
3368 cond_resched();
3369 mdelay(ms);
3370 } else {
3371 msleep(ms);
3372 }
3373}
3374
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003375static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
3376 u8 *pattern, u32 patternsize, u8 *mask,
3377 u32 packet_offset)
3378{
3379 struct brcmf_fil_wowl_pattern_le *filter;
3380 u32 masksize;
3381 u32 patternoffset;
3382 u8 *buf;
3383 u32 bufsize;
3384 s32 ret;
3385
3386 masksize = (patternsize + 7) / 8;
3387 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
3388
3389 bufsize = sizeof(*filter) + patternsize + masksize;
3390 buf = kzalloc(bufsize, GFP_KERNEL);
3391 if (!buf)
3392 return -ENOMEM;
3393 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
3394
3395 memcpy(filter->cmd, cmd, 4);
3396 filter->masksize = cpu_to_le32(masksize);
3397 filter->offset = cpu_to_le32(packet_offset);
3398 filter->patternoffset = cpu_to_le32(patternoffset);
3399 filter->patternsize = cpu_to_le32(patternsize);
3400 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
3401
3402 if ((mask) && (masksize))
3403 memcpy(buf + sizeof(*filter), mask, masksize);
3404 if ((pattern) && (patternsize))
3405 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
3406
3407 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
3408
3409 kfree(buf);
3410 return ret;
3411}
3412
Hante Meuleman3021ad92016-01-05 11:05:45 +01003413static s32
3414brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
3415 void *data)
3416{
3417 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3418 struct brcmf_pno_scanresults_le *pfn_result;
3419 struct brcmf_pno_net_info_le *netinfo;
3420
3421 brcmf_dbg(SCAN, "Enter\n");
3422
Hante Meuleman0aedbca2016-02-17 11:26:54 +01003423 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3424 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3425 return 0;
3426 }
3427
Hante Meuleman3021ad92016-01-05 11:05:45 +01003428 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3429
3430 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3431 brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n");
3432 return 0;
3433 }
3434
3435 if (le32_to_cpu(pfn_result->count) < 1) {
3436 brcmf_err("Invalid result count, expected 1 (%d)\n",
3437 le32_to_cpu(pfn_result->count));
3438 return -EINVAL;
3439 }
3440
3441 data += sizeof(struct brcmf_pno_scanresults_le);
3442 netinfo = (struct brcmf_pno_net_info_le *)data;
3443 memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
3444 cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
3445 cfg->wowl.nd->n_channels = 1;
3446 cfg->wowl.nd->channels[0] =
3447 ieee80211_channel_to_frequency(netinfo->channel,
3448 netinfo->channel <= CH_MAX_2G_CHANNEL ?
3449 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
3450 cfg->wowl.nd_info->n_matches = 1;
3451 cfg->wowl.nd_info->matches[0] = cfg->wowl.nd;
3452
3453 /* Inform (the resume task) that the net detect information was recvd */
3454 cfg->wowl.nd_data_completed = true;
3455 wake_up(&cfg->wowl.nd_data_wait);
3456
3457 return 0;
3458}
3459
Hante Meulemanaeb64222015-10-29 20:33:19 +01003460#ifdef CONFIG_PM
3461
3462static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3463{
Hante Meuleman3021ad92016-01-05 11:05:45 +01003464 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemanaeb64222015-10-29 20:33:19 +01003465 struct brcmf_wowl_wakeind_le wake_ind_le;
3466 struct cfg80211_wowlan_wakeup wakeup_data;
3467 struct cfg80211_wowlan_wakeup *wakeup;
3468 u32 wakeind;
3469 s32 err;
Hante Meuleman3021ad92016-01-05 11:05:45 +01003470 int timeout;
Hante Meulemanaeb64222015-10-29 20:33:19 +01003471
3472 err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
3473 sizeof(wake_ind_le));
Hante Meuleman3021ad92016-01-05 11:05:45 +01003474 if (err) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003475 brcmf_err("Get wowl_wakeind failed, err = %d\n", err);
3476 return;
3477 }
3478
3479 wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
3480 if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
Hante Meuleman3021ad92016-01-05 11:05:45 +01003481 BRCMF_WOWL_RETR | BRCMF_WOWL_NET |
3482 BRCMF_WOWL_PFN_FOUND)) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003483 wakeup = &wakeup_data;
3484 memset(&wakeup_data, 0, sizeof(wakeup_data));
3485 wakeup_data.pattern_idx = -1;
3486
3487 if (wakeind & BRCMF_WOWL_MAGIC) {
3488 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
3489 wakeup_data.magic_pkt = true;
3490 }
3491 if (wakeind & BRCMF_WOWL_DIS) {
3492 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
3493 wakeup_data.disconnect = true;
3494 }
3495 if (wakeind & BRCMF_WOWL_BCN) {
3496 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
3497 wakeup_data.disconnect = true;
3498 }
3499 if (wakeind & BRCMF_WOWL_RETR) {
3500 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
3501 wakeup_data.disconnect = true;
3502 }
3503 if (wakeind & BRCMF_WOWL_NET) {
3504 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
3505 /* For now always map to pattern 0, no API to get
3506 * correct information available at the moment.
3507 */
3508 wakeup_data.pattern_idx = 0;
3509 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003510 if (wakeind & BRCMF_WOWL_PFN_FOUND) {
3511 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n");
3512 timeout = wait_event_timeout(cfg->wowl.nd_data_wait,
3513 cfg->wowl.nd_data_completed,
3514 BRCMF_ND_INFO_TIMEOUT);
3515 if (!timeout)
3516 brcmf_err("No result for wowl net detect\n");
3517 else
3518 wakeup_data.net_detect = cfg->wowl.nd_info;
3519 }
Hante Meulemanaeb64222015-10-29 20:33:19 +01003520 } else {
3521 wakeup = NULL;
3522 }
3523 cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
3524}
3525
3526#else
3527
3528static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3529{
3530}
3531
3532#endif /* CONFIG_PM */
3533
Arend van Spriel5b435de2011-10-05 13:19:03 +02003534static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
3535{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003536 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3537 struct net_device *ndev = cfg_to_ndev(cfg);
3538 struct brcmf_if *ifp = netdev_priv(ndev);
3539
Arend van Sprield96b8012012-12-05 15:26:02 +01003540 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003541
Hante Meuleman3021ad92016-01-05 11:05:45 +01003542 if (cfg->wowl.active) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003543 brcmf_report_wowl_wakeind(wiphy, ifp);
3544 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
3545 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003546 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003547 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
Hante Meuleman3021ad92016-01-05 11:05:45 +01003548 cfg->wowl.pre_pmmode);
3549 cfg->wowl.active = false;
3550 if (cfg->wowl.nd_enabled) {
3551 brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev);
3552 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3553 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3554 brcmf_notify_sched_scan_results);
3555 cfg->wowl.nd_enabled = false;
3556 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003557 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003558 return 0;
3559}
3560
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003561static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
3562 struct brcmf_if *ifp,
3563 struct cfg80211_wowlan *wowl)
3564{
3565 u32 wowl_config;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003566 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003567
3568 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
3569
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003570 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003571 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003572 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
3573
3574 wowl_config = 0;
3575 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003576 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003577 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003578 wowl_config |= BRCMF_WOWL_MAGIC;
3579 if ((wowl->patterns) && (wowl->n_patterns)) {
3580 wowl_config |= BRCMF_WOWL_NET;
3581 for (i = 0; i < wowl->n_patterns; i++) {
3582 brcmf_config_wowl_pattern(ifp, "add",
3583 (u8 *)wowl->patterns[i].pattern,
3584 wowl->patterns[i].pattern_len,
3585 (u8 *)wowl->patterns[i].mask,
3586 wowl->patterns[i].pkt_offset);
3587 }
3588 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003589 if (wowl->nd_config) {
3590 brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev,
3591 wowl->nd_config);
3592 wowl_config |= BRCMF_WOWL_PFN_FOUND;
3593
3594 cfg->wowl.nd_data_completed = false;
3595 cfg->wowl.nd_enabled = true;
3596 /* Now reroute the event for PFN to the wowl function. */
3597 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3598 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3599 brcmf_wowl_nd_results);
3600 }
3601 if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
3602 wowl_config |= BRCMF_WOWL_UNASSOC;
3603
Hante Meulemanaeb64222015-10-29 20:33:19 +01003604 brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", "clear", strlen("clear"));
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003605 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
3606 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
3607 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003608 cfg->wowl.active = true;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003609}
3610
Arend van Spriel5b435de2011-10-05 13:19:03 +02003611static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003612 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003613{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003614 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3615 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003616 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07003617 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003618
Arend van Sprield96b8012012-12-05 15:26:02 +01003619 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003620
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003621 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07003622 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02003623 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003624 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07003625 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003626
Hante Meuleman3021ad92016-01-05 11:05:45 +01003627 /* Stop scheduled scan */
3628 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
3629 brcmf_cfg80211_sched_scan_stop(wiphy, ndev);
3630
Arend van Spriel7d641072012-10-22 13:55:39 -07003631 /* end any scanning */
3632 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003633 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003634
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003635 if (wowl == NULL) {
3636 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
3637 list_for_each_entry(vif, &cfg->vif_list, list) {
3638 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
3639 continue;
3640 /* While going to suspend if associated with AP
3641 * disassociate from AP to save power while system is
3642 * in suspended state
3643 */
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01003644 brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003645 /* Make sure WPA_Supplicant receives all the event
3646 * generated due to DISASSOC call to the fw to keep
3647 * the state fw and WPA_Supplicant state consistent
3648 */
3649 brcmf_delay(500);
3650 }
3651 /* Configure MPC */
3652 brcmf_set_mpc(ifp, 1);
3653
3654 } else {
3655 /* Configure WOWL paramaters */
3656 brcmf_configure_wowl(cfg, ifp, wowl);
3657 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003658
Arend van Spriel7d641072012-10-22 13:55:39 -07003659exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01003660 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07003661 /* clear any scanning activity */
3662 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003663 return 0;
3664}
3665
3666static __used s32
Hante Meuleman6c404f32015-12-10 13:43:03 +01003667brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003668{
Hante Meuleman6c404f32015-12-10 13:43:03 +01003669 struct brcmf_pmk_list_le *pmk_list;
3670 int i;
3671 u32 npmk;
3672 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003673
Hante Meuleman6c404f32015-12-10 13:43:03 +01003674 pmk_list = &cfg->pmk_list;
3675 npmk = le32_to_cpu(pmk_list->npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003676
Hante Meuleman6c404f32015-12-10 13:43:03 +01003677 brcmf_dbg(CONN, "No of elements %d\n", npmk);
3678 for (i = 0; i < npmk; i++)
3679 brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003680
Hante Meuleman6c404f32015-12-10 13:43:03 +01003681 err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list,
3682 sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02003683
3684 return err;
3685}
3686
3687static s32
3688brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3689 struct cfg80211_pmksa *pmksa)
3690{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003691 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003692 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003693 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3694 s32 err;
3695 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003696
Arend van Sprield96b8012012-12-05 15:26:02 +01003697 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003698 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003699 return -EIO;
3700
Hante Meuleman6c404f32015-12-10 13:43:03 +01003701 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3702 for (i = 0; i < npmk; i++)
3703 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003704 break;
Hante Meuleman6c404f32015-12-10 13:43:03 +01003705 if (i < BRCMF_MAXPMKID) {
3706 memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN);
3707 memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
3708 if (i == npmk) {
3709 npmk++;
3710 cfg->pmk_list.npmk = cpu_to_le32(npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003711 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003712 } else {
3713 brcmf_err("Too many PMKSA entries cached %d\n", npmk);
3714 return -EINVAL;
3715 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003716
Hante Meuleman6c404f32015-12-10 13:43:03 +01003717 brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid);
3718 for (i = 0; i < WLAN_PMKID_LEN; i += 4)
3719 brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i],
3720 pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2],
3721 pmk[npmk].pmkid[i + 3]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003722
Hante Meuleman6c404f32015-12-10 13:43:03 +01003723 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003724
Arend van Sprield96b8012012-12-05 15:26:02 +01003725 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003726 return err;
3727}
3728
3729static s32
3730brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman6c404f32015-12-10 13:43:03 +01003731 struct cfg80211_pmksa *pmksa)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003732{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003733 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003734 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003735 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3736 s32 err;
3737 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003738
Arend van Sprield96b8012012-12-05 15:26:02 +01003739 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003740 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003741 return -EIO;
3742
Hante Meuleman6c404f32015-12-10 13:43:03 +01003743 brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", &pmksa->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003744
Hante Meuleman6c404f32015-12-10 13:43:03 +01003745 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3746 for (i = 0; i < npmk; i++)
3747 if (!memcmp(&pmksa->bssid, &pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003748 break;
3749
Hante Meuleman6c404f32015-12-10 13:43:03 +01003750 if ((npmk > 0) && (i < npmk)) {
3751 for (; i < (npmk - 1); i++) {
3752 memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN);
3753 memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003754 WLAN_PMKID_LEN);
3755 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003756 memset(&pmk[i], 0, sizeof(*pmk));
3757 cfg->pmk_list.npmk = cpu_to_le32(npmk - 1);
3758 } else {
3759 brcmf_err("Cache entry not found\n");
3760 return -EINVAL;
3761 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003762
Hante Meuleman6c404f32015-12-10 13:43:03 +01003763 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003764
Arend van Sprield96b8012012-12-05 15:26:02 +01003765 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003766 return err;
3767
3768}
3769
3770static s32
3771brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3772{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003773 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003774 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003775 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003776
Arend van Sprield96b8012012-12-05 15:26:02 +01003777 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003778 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003779 return -EIO;
3780
Hante Meuleman6c404f32015-12-10 13:43:03 +01003781 memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list));
3782 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003783
Arend van Sprield96b8012012-12-05 15:26:02 +01003784 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003785 return err;
3786
3787}
3788
Hante Meuleman1f170112013-02-06 18:40:38 +01003789static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003790{
3791 s32 err;
3792
3793 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003794 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003795 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003796 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003797 return err;
3798 }
3799 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003800 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003801 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003802 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003803 return err;
3804 }
3805 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003806 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003807 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003808 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003809 return err;
3810 }
3811
3812 return 0;
3813}
3814
3815static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3816{
3817 if (is_rsn_ie)
3818 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3819
3820 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3821}
3822
3823static s32
Hante Meulemana44aa402014-12-03 21:05:33 +01003824brcmf_configure_wpaie(struct brcmf_if *ifp,
Johannes Berg4b5800f2014-01-15 14:55:59 +01003825 const struct brcmf_vs_tlv *wpa_ie,
3826 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003827{
3828 u32 auth = 0; /* d11 open authentication */
3829 u16 count;
3830 s32 err = 0;
3831 s32 len = 0;
3832 u32 i;
3833 u32 wsec;
3834 u32 pval = 0;
3835 u32 gval = 0;
3836 u32 wpa_auth = 0;
3837 u32 offset;
3838 u8 *data;
3839 u16 rsn_cap;
3840 u32 wme_bss_disable;
3841
Arend van Sprield96b8012012-12-05 15:26:02 +01003842 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003843 if (wpa_ie == NULL)
3844 goto exit;
3845
3846 len = wpa_ie->len + TLV_HDR_LEN;
3847 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003848 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003849 if (!is_rsn_ie)
3850 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003851 else
3852 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003853
3854 /* check for multicast cipher suite */
3855 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3856 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003857 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003858 goto exit;
3859 }
3860
3861 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3862 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003863 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003864 goto exit;
3865 }
3866 offset += TLV_OUI_LEN;
3867
3868 /* pick up multicast cipher */
3869 switch (data[offset]) {
3870 case WPA_CIPHER_NONE:
3871 gval = 0;
3872 break;
3873 case WPA_CIPHER_WEP_40:
3874 case WPA_CIPHER_WEP_104:
3875 gval = WEP_ENABLED;
3876 break;
3877 case WPA_CIPHER_TKIP:
3878 gval = TKIP_ENABLED;
3879 break;
3880 case WPA_CIPHER_AES_CCM:
3881 gval = AES_ENABLED;
3882 break;
3883 default:
3884 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003885 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003886 goto exit;
3887 }
3888
3889 offset++;
3890 /* walk thru unicast cipher list and pick up what we recognize */
3891 count = data[offset] + (data[offset + 1] << 8);
3892 offset += WPA_IE_SUITE_COUNT_LEN;
3893 /* Check for unicast suite(s) */
3894 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3895 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003896 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003897 goto exit;
3898 }
3899 for (i = 0; i < count; i++) {
3900 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3901 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003902 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003903 goto exit;
3904 }
3905 offset += TLV_OUI_LEN;
3906 switch (data[offset]) {
3907 case WPA_CIPHER_NONE:
3908 break;
3909 case WPA_CIPHER_WEP_40:
3910 case WPA_CIPHER_WEP_104:
3911 pval |= WEP_ENABLED;
3912 break;
3913 case WPA_CIPHER_TKIP:
3914 pval |= TKIP_ENABLED;
3915 break;
3916 case WPA_CIPHER_AES_CCM:
3917 pval |= AES_ENABLED;
3918 break;
3919 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003920 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003921 }
3922 offset++;
3923 }
3924 /* walk thru auth management suite list and pick up what we recognize */
3925 count = data[offset] + (data[offset + 1] << 8);
3926 offset += WPA_IE_SUITE_COUNT_LEN;
3927 /* Check for auth key management suite(s) */
3928 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3929 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003930 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003931 goto exit;
3932 }
3933 for (i = 0; i < count; i++) {
3934 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3935 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003936 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003937 goto exit;
3938 }
3939 offset += TLV_OUI_LEN;
3940 switch (data[offset]) {
3941 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003942 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003943 wpa_auth |= WPA_AUTH_NONE;
3944 break;
3945 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003946 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003947 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3948 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3949 break;
3950 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01003951 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003952 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3953 (wpa_auth |= WPA_AUTH_PSK);
3954 break;
3955 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003956 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003957 }
3958 offset++;
3959 }
3960
3961 if (is_rsn_ie) {
3962 wme_bss_disable = 1;
3963 if ((offset + RSN_CAP_LEN) <= len) {
3964 rsn_cap = data[offset] + (data[offset + 1] << 8);
3965 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3966 wme_bss_disable = 0;
3967 }
3968 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07003969 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003970 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02003971 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003972 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003973 goto exit;
3974 }
3975 }
3976 /* FOR WPS , set SES_OW_ENABLED */
3977 wsec = (pval | gval | SES_OW_ENABLED);
3978
3979 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003980 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003981 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003982 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003983 goto exit;
3984 }
3985 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003986 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02003987 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003988 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003989 goto exit;
3990 }
3991 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003992 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003993 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003994 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003995 goto exit;
3996 }
3997
3998exit:
3999 return err;
4000}
4001
4002static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08004003brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02004004 struct parsed_vndr_ies *vndr_ies)
4005{
Hante Meuleman1a873342012-09-27 14:17:54 +02004006 struct brcmf_vs_tlv *vndrie;
4007 struct brcmf_tlv *ie;
4008 struct parsed_vndr_ie_info *parsed_info;
4009 s32 remaining_len;
4010
4011 remaining_len = (s32)vndr_ie_len;
4012 memset(vndr_ies, 0, sizeof(*vndr_ies));
4013
4014 ie = (struct brcmf_tlv *)vndr_ie_buf;
4015 while (ie) {
4016 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
4017 goto next;
4018 vndrie = (struct brcmf_vs_tlv *)ie;
4019 /* len should be bigger than OUI length + one */
4020 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004021 brcmf_err("invalid vndr ie. length is too small %d\n",
4022 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004023 goto next;
4024 }
4025 /* if wpa or wme ie, do not add ie */
4026 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
4027 ((vndrie->oui_type == WPA_OUI_TYPE) ||
4028 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004029 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004030 goto next;
4031 }
4032
4033 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
4034
4035 /* save vndr ie information */
4036 parsed_info->ie_ptr = (char *)vndrie;
4037 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
4038 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
4039
4040 vndr_ies->count++;
4041
Arend van Sprield96b8012012-12-05 15:26:02 +01004042 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
4043 parsed_info->vndrie.oui[0],
4044 parsed_info->vndrie.oui[1],
4045 parsed_info->vndrie.oui[2],
4046 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02004047
Arend van Spriel9f440b72013-02-08 15:53:36 +01004048 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02004049 break;
4050next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004051 remaining_len -= (ie->len + TLV_HDR_LEN);
4052 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02004053 ie = NULL;
4054 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004055 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
4056 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02004057 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004058 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004059}
4060
4061static u32
4062brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
4063{
4064
Hante Meuleman1a873342012-09-27 14:17:54 +02004065 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
4066 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
4067
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304068 put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004069
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304070 put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004071
4072 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
4073
4074 return ie_len + VNDR_IE_HDR_SIZE;
4075}
4076
Arend van Spriel1332e262012-11-05 16:22:18 -08004077s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
4078 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02004079{
Arend van Spriel1332e262012-11-05 16:22:18 -08004080 struct brcmf_if *ifp;
4081 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004082 s32 err = 0;
4083 u8 *iovar_ie_buf;
4084 u8 *curr_ie_buf;
4085 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004086 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07004087 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004088 u32 del_add_ie_buf_len = 0;
4089 u32 total_ie_buf_len = 0;
4090 u32 parsed_ie_buf_len = 0;
4091 struct parsed_vndr_ies old_vndr_ies;
4092 struct parsed_vndr_ies new_vndr_ies;
4093 struct parsed_vndr_ie_info *vndrie_info;
4094 s32 i;
4095 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004096 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004097
Arend van Spriel1332e262012-11-05 16:22:18 -08004098 if (!vif)
4099 return -ENODEV;
4100 ifp = vif->ifp;
4101 saved_ie = &vif->saved_ie;
4102
Hante Meuleman37a869e2015-10-29 20:33:17 +01004103 brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
4104 pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02004105 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4106 if (!iovar_ie_buf)
4107 return -ENOMEM;
4108 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01004109 switch (pktflag) {
4110 case BRCMF_VNDR_IE_PRBREQ_FLAG:
4111 mgmt_ie_buf = saved_ie->probe_req_ie;
4112 mgmt_ie_len = &saved_ie->probe_req_ie_len;
4113 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
4114 break;
4115 case BRCMF_VNDR_IE_PRBRSP_FLAG:
4116 mgmt_ie_buf = saved_ie->probe_res_ie;
4117 mgmt_ie_len = &saved_ie->probe_res_ie_len;
4118 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
4119 break;
4120 case BRCMF_VNDR_IE_BEACON_FLAG:
4121 mgmt_ie_buf = saved_ie->beacon_ie;
4122 mgmt_ie_len = &saved_ie->beacon_ie_len;
4123 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
4124 break;
4125 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
4126 mgmt_ie_buf = saved_ie->assoc_req_ie;
4127 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
4128 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
4129 break;
4130 default:
4131 err = -EPERM;
4132 brcmf_err("not suitable type\n");
4133 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004134 }
4135
4136 if (vndr_ie_len > mgmt_ie_buf_len) {
4137 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01004138 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004139 goto exit;
4140 }
4141
4142 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
4143 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
4144 ptr = curr_ie_buf;
4145 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
4146 for (i = 0; i < new_vndr_ies.count; i++) {
4147 vndrie_info = &new_vndr_ies.ie_info[i];
4148 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
4149 vndrie_info->ie_len);
4150 parsed_ie_buf_len += vndrie_info->ie_len;
4151 }
4152 }
4153
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004154 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004155 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
4156 (memcmp(mgmt_ie_buf, curr_ie_buf,
4157 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004158 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004159 goto exit;
4160 }
4161
4162 /* parse old vndr_ie */
4163 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
4164
4165 /* make a command to delete old ie */
4166 for (i = 0; i < old_vndr_ies.count; i++) {
4167 vndrie_info = &old_vndr_ies.ie_info[i];
4168
Arend van Sprield96b8012012-12-05 15:26:02 +01004169 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
4170 vndrie_info->vndrie.id,
4171 vndrie_info->vndrie.len,
4172 vndrie_info->vndrie.oui[0],
4173 vndrie_info->vndrie.oui[1],
4174 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004175
4176 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4177 vndrie_info->ie_ptr,
4178 vndrie_info->ie_len,
4179 "del");
4180 curr_ie_buf += del_add_ie_buf_len;
4181 total_ie_buf_len += del_add_ie_buf_len;
4182 }
4183 }
4184
4185 *mgmt_ie_len = 0;
4186 /* Add if there is any extra IE */
4187 if (mgmt_ie_buf && parsed_ie_buf_len) {
4188 ptr = mgmt_ie_buf;
4189
4190 remained_buf_len = mgmt_ie_buf_len;
4191
4192 /* make a command to add new ie */
4193 for (i = 0; i < new_vndr_ies.count; i++) {
4194 vndrie_info = &new_vndr_ies.ie_info[i];
4195
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004196 /* verify remained buf size before copy data */
4197 if (remained_buf_len < (vndrie_info->vndrie.len +
4198 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004199 brcmf_err("no space in mgmt_ie_buf: len left %d",
4200 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004201 break;
4202 }
4203 remained_buf_len -= (vndrie_info->ie_len +
4204 VNDR_IE_VSIE_OFFSET);
4205
Arend van Sprield96b8012012-12-05 15:26:02 +01004206 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
4207 vndrie_info->vndrie.id,
4208 vndrie_info->vndrie.len,
4209 vndrie_info->vndrie.oui[0],
4210 vndrie_info->vndrie.oui[1],
4211 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004212
4213 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4214 vndrie_info->ie_ptr,
4215 vndrie_info->ie_len,
4216 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02004217
4218 /* save the parsed IE in wl struct */
4219 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
4220 vndrie_info->ie_len);
4221 *mgmt_ie_len += vndrie_info->ie_len;
4222
4223 curr_ie_buf += del_add_ie_buf_len;
4224 total_ie_buf_len += del_add_ie_buf_len;
4225 }
4226 }
4227 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004228 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004229 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004230 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004231 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004232 }
4233
4234exit:
4235 kfree(iovar_ie_buf);
4236 return err;
4237}
4238
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004239s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
4240{
4241 s32 pktflags[] = {
4242 BRCMF_VNDR_IE_PRBREQ_FLAG,
4243 BRCMF_VNDR_IE_PRBRSP_FLAG,
4244 BRCMF_VNDR_IE_BEACON_FLAG
4245 };
4246 int i;
4247
4248 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
4249 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
4250
4251 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
4252 return 0;
4253}
4254
Hante Meuleman1a873342012-09-27 14:17:54 +02004255static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01004256brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
4257 struct cfg80211_beacon_data *beacon)
4258{
4259 s32 err;
4260
4261 /* Set Beacon IEs to FW */
4262 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
4263 beacon->tail, beacon->tail_len);
4264 if (err) {
4265 brcmf_err("Set Beacon IE Failed\n");
4266 return err;
4267 }
4268 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
4269
4270 /* Set Probe Response IEs to FW */
4271 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
4272 beacon->proberesp_ies,
4273 beacon->proberesp_ies_len);
4274 if (err)
4275 brcmf_err("Set Probe Resp IE Failed\n");
4276 else
4277 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
4278
4279 return err;
4280}
4281
4282static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02004283brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
4284 struct cfg80211_ap_settings *settings)
4285{
4286 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02004287 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07004288 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01004289 const struct brcmf_tlv *ssid_ie;
Arend van Spriel98027762014-12-21 12:43:53 +01004290 const struct brcmf_tlv *country_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004291 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02004292 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01004293 const struct brcmf_tlv *rsn_ie;
4294 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004295 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01004296 enum nl80211_iftype dev_role;
4297 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02004298 u16 chanspec;
Hante Meulemana44aa402014-12-03 21:05:33 +01004299 bool mbss;
Arend van Spriel98027762014-12-21 12:43:53 +01004300 int is_11d;
Hante Meuleman1a873342012-09-27 14:17:54 +02004301
Arend van Spriel06c01582014-05-12 10:47:37 +02004302 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
4303 settings->chandef.chan->hw_value,
4304 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02004305 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01004306 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
4307 settings->ssid, settings->ssid_len, settings->auth_type,
4308 settings->inactivity_timeout);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004309 dev_role = ifp->vif->wdev.iftype;
Hante Meulemana44aa402014-12-03 21:05:33 +01004310 mbss = ifp->vif->mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02004311
Arend van Spriel98027762014-12-21 12:43:53 +01004312 /* store current 11d setting */
4313 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d);
4314 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4315 settings->beacon.tail_len,
4316 WLAN_EID_COUNTRY);
4317 is_11d = country_ie ? 1 : 0;
4318
Hante Meuleman1a873342012-09-27 14:17:54 +02004319 memset(&ssid_le, 0, sizeof(ssid_le));
4320 if (settings->ssid == NULL || settings->ssid_len == 0) {
4321 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
4322 ssid_ie = brcmf_parse_tlvs(
4323 (u8 *)&settings->beacon.head[ie_offset],
4324 settings->beacon.head_len - ie_offset,
4325 WLAN_EID_SSID);
4326 if (!ssid_ie)
4327 return -EINVAL;
4328
4329 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
4330 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01004331 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02004332 } else {
4333 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
4334 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
4335 }
4336
Hante Meulemana44aa402014-12-03 21:05:33 +01004337 if (!mbss) {
4338 brcmf_set_mpc(ifp, 0);
4339 brcmf_configure_arp_offload(ifp, false);
4340 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004341
4342 /* find the RSN_IE */
4343 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4344 settings->beacon.tail_len, WLAN_EID_RSN);
4345
4346 /* find the WPA_IE */
4347 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
4348 settings->beacon.tail_len);
4349
Hante Meuleman1a873342012-09-27 14:17:54 +02004350 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004351 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004352 if (wpa_ie != NULL) {
4353 /* WPA IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004354 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02004355 if (err < 0)
4356 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004357 } else {
Hante Meulemana44aa402014-12-03 21:05:33 +01004358 struct brcmf_vs_tlv *tmp_ie;
4359
4360 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
4361
Hante Meuleman1a873342012-09-27 14:17:54 +02004362 /* RSN IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004363 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004364 if (err < 0)
4365 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004366 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004367 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01004368 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01004369 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02004370 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004371
Hante Meulemana0f07952013-02-08 15:53:47 +01004372 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02004373
Hante Meulemana44aa402014-12-03 21:05:33 +01004374 if (!mbss) {
4375 chanspec = chandef_to_chanspec(&cfg->d11inf,
4376 &settings->chandef);
4377 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004378 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004379 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4380 chanspec, err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004381 goto exit;
4382 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004383
Arend van Spriel98027762014-12-21 12:43:53 +01004384 if (is_11d != ifp->vif->is_11d) {
4385 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4386 is_11d);
4387 if (err < 0) {
4388 brcmf_err("Regulatory Set Error, %d\n", err);
4389 goto exit;
4390 }
4391 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004392 if (settings->beacon_interval) {
4393 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
4394 settings->beacon_interval);
4395 if (err < 0) {
4396 brcmf_err("Beacon Interval Set Error, %d\n",
4397 err);
4398 goto exit;
4399 }
4400 }
4401 if (settings->dtim_period) {
4402 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
4403 settings->dtim_period);
4404 if (err < 0) {
4405 brcmf_err("DTIM Interval Set Error, %d\n", err);
4406 goto exit;
4407 }
4408 }
4409
Hante Meuleman8abffd82015-10-29 20:33:16 +01004410 if ((dev_role == NL80211_IFTYPE_AP) &&
4411 ((ifp->ifidx == 0) ||
4412 !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004413 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4414 if (err < 0) {
4415 brcmf_err("BRCMF_C_DOWN error %d\n", err);
4416 goto exit;
4417 }
4418 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
4419 }
4420
4421 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02004422 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004423 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004424 goto exit;
4425 }
Arend van Spriel98027762014-12-21 12:43:53 +01004426 } else if (WARN_ON(is_11d != ifp->vif->is_11d)) {
4427 /* Multiple-BSS should use same 11d configuration */
4428 err = -EINVAL;
4429 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004430 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004431 if (dev_role == NL80211_IFTYPE_AP) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004432 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
4433 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
4434
Hante Meulemana0f07952013-02-08 15:53:47 +01004435 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
4436 if (err < 0) {
4437 brcmf_err("setting AP mode failed %d\n", err);
4438 goto exit;
4439 }
4440 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4441 if (err < 0) {
4442 brcmf_err("BRCMF_C_UP error (%d)\n", err);
4443 goto exit;
4444 }
Hante Meuleman118eb302014-12-21 12:43:49 +01004445 /* On DOWN the firmware removes the WEP keys, reconfigure
4446 * them if they were set.
4447 */
4448 brcmf_cfg80211_reconfigure_wep(ifp);
Hante Meulemana0f07952013-02-08 15:53:47 +01004449
4450 memset(&join_params, 0, sizeof(join_params));
4451 /* join parameters starts with ssid */
4452 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
4453 /* create softap */
4454 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4455 &join_params, sizeof(join_params));
4456 if (err < 0) {
4457 brcmf_err("SET SSID error (%d)\n", err);
4458 goto exit;
4459 }
4460 brcmf_dbg(TRACE, "AP mode configuration complete\n");
4461 } else {
4462 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
4463 sizeof(ssid_le));
4464 if (err < 0) {
4465 brcmf_err("setting ssid failed %d\n", err);
4466 goto exit;
4467 }
Hante Meuleman37a869e2015-10-29 20:33:17 +01004468 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meulemana0f07952013-02-08 15:53:47 +01004469 bss_enable.enable = cpu_to_le32(1);
4470 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4471 sizeof(bss_enable));
4472 if (err < 0) {
4473 brcmf_err("bss_enable config failed %d\n", err);
4474 goto exit;
4475 }
4476
4477 brcmf_dbg(TRACE, "GO mode configuration complete\n");
4478 }
Arend van Sprielc1179032012-10-22 13:55:33 -07004479 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004480 brcmf_net_setcarrier(ifp, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004481
4482exit:
Hante Meulemana44aa402014-12-03 21:05:33 +01004483 if ((err) && (!mbss)) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02004484 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004485 brcmf_configure_arp_offload(ifp, true);
4486 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004487 return err;
4488}
4489
4490static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
4491{
Arend van Sprielc1179032012-10-22 13:55:33 -07004492 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004493 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01004494 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02004495 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02004496
Arend van Sprield96b8012012-12-05 15:26:02 +01004497 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004498
Hante Meuleman426d0a52013-02-08 15:53:53 +01004499 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004500 /* Due to most likely deauths outstanding we sleep */
4501 /* first to make sure they get processed by fw. */
4502 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004503
Hante Meulemana44aa402014-12-03 21:05:33 +01004504 if (ifp->vif->mbss) {
4505 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4506 return err;
4507 }
4508
Hante Meuleman5c33a942013-04-02 21:06:18 +02004509 memset(&join_params, 0, sizeof(join_params));
4510 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4511 &join_params, sizeof(join_params));
4512 if (err < 0)
4513 brcmf_err("SET SSID error (%d)\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004514 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004515 if (err < 0)
Hante Meulemana44aa402014-12-03 21:05:33 +01004516 brcmf_err("BRCMF_C_DOWN error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004517 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4518 if (err < 0)
4519 brcmf_err("setting AP mode failed %d\n", err);
4520 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4521 if (err < 0)
4522 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004523 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
4524 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
Arend van Spriel98027762014-12-21 12:43:53 +01004525 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4526 ifp->vif->is_11d);
4527 if (err < 0)
4528 brcmf_err("restoring REGULATORY setting failed %d\n",
4529 err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004530 /* Bring device back up so it can be used again */
4531 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4532 if (err < 0)
4533 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004534 } else {
Hante Meuleman37a869e2015-10-29 20:33:17 +01004535 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004536 bss_enable.enable = cpu_to_le32(0);
4537 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4538 sizeof(bss_enable));
4539 if (err < 0)
4540 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004541 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02004542 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004543 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004544 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004545 brcmf_net_setcarrier(ifp, false);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004546
Hante Meuleman1a873342012-09-27 14:17:54 +02004547 return err;
4548}
4549
Hante Meulemana0f07952013-02-08 15:53:47 +01004550static s32
4551brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4552 struct cfg80211_beacon_data *info)
4553{
Hante Meulemana0f07952013-02-08 15:53:47 +01004554 struct brcmf_if *ifp = netdev_priv(ndev);
4555 s32 err;
4556
4557 brcmf_dbg(TRACE, "Enter\n");
4558
Hante Meulemana0f07952013-02-08 15:53:47 +01004559 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4560
4561 return err;
4562}
4563
Hante Meuleman1a873342012-09-27 14:17:54 +02004564static int
4565brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03004566 struct station_del_parameters *params)
Hante Meuleman1a873342012-09-27 14:17:54 +02004567{
Hante Meulemana0f07952013-02-08 15:53:47 +01004568 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02004569 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004570 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02004571 s32 err;
4572
Jouni Malinen89c771e2014-10-10 20:52:40 +03004573 if (!params->mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02004574 return -EFAULT;
4575
Jouni Malinen89c771e2014-10-10 20:52:40 +03004576 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02004577
Hante Meulemana0f07952013-02-08 15:53:47 +01004578 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4579 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07004580 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02004581 return -EIO;
4582
Jouni Malinen89c771e2014-10-10 20:52:40 +03004583 memcpy(&scbval.ea, params->mac, ETH_ALEN);
Rafał Miłeckiba8b6ae2015-02-08 11:51:47 +01004584 scbval.val = cpu_to_le32(params->reason_code);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004585 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004586 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02004587 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004588 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01004589
Arend van Sprield96b8012012-12-05 15:26:02 +01004590 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004591 return err;
4592}
4593
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004594static int
4595brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
4596 const u8 *mac, struct station_parameters *params)
4597{
4598 struct brcmf_if *ifp = netdev_priv(ndev);
4599 s32 err;
4600
4601 brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
4602 params->sta_flags_mask, params->sta_flags_set);
4603
4604 /* Ignore all 00 MAC */
4605 if (is_zero_ether_addr(mac))
4606 return 0;
4607
4608 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4609 return 0;
4610
4611 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
4612 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
4613 (void *)mac, ETH_ALEN);
4614 else
4615 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
4616 (void *)mac, ETH_ALEN);
4617 if (err < 0)
4618 brcmf_err("Setting SCB (de-)authorize failed, %d\n", err);
4619
4620 return err;
4621}
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004622
4623static void
4624brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4625 struct wireless_dev *wdev,
4626 u16 frame_type, bool reg)
4627{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004628 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004629 u16 mgmt_type;
4630
4631 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4632
4633 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004634 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004635 if (reg)
4636 vif->mgmt_rx_reg |= BIT(mgmt_type);
4637 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01004638 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004639}
4640
4641
4642static int
4643brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004644 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004645{
4646 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004647 struct ieee80211_channel *chan = params->chan;
4648 const u8 *buf = params->buf;
4649 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004650 const struct ieee80211_mgmt *mgmt;
4651 struct brcmf_cfg80211_vif *vif;
4652 s32 err = 0;
4653 s32 ie_offset;
4654 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004655 struct brcmf_fil_action_frame_le *action_frame;
4656 struct brcmf_fil_af_params_le *af_params;
4657 bool ack;
4658 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004659 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004660
4661 brcmf_dbg(TRACE, "Enter\n");
4662
4663 *cookie = 0;
4664
4665 mgmt = (const struct ieee80211_mgmt *)buf;
4666
Hante Meulemana0f07952013-02-08 15:53:47 +01004667 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4668 brcmf_err("Driver only allows MGMT packet type\n");
4669 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004670 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004671
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004672 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4673
Hante Meulemana0f07952013-02-08 15:53:47 +01004674 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4675 /* Right now the only reason to get a probe response */
4676 /* is for p2p listen response or for p2p GO from */
4677 /* wpa_supplicant. Unfortunately the probe is send */
4678 /* on primary ndev, while dongle wants it on the p2p */
4679 /* vif. Since this is only reason for a probe */
4680 /* response to be sent, the vif is taken from cfg. */
4681 /* If ever desired to send proberesp for non p2p */
4682 /* response then data should be checked for */
4683 /* "DIRECT-". Note in future supplicant will take */
4684 /* dedicated p2p wdev to do this and then this 'hack'*/
4685 /* is not needed anymore. */
4686 ie_offset = DOT11_MGMT_HDR_LEN +
4687 DOT11_BCN_PRB_FIXED_LEN;
4688 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004689 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4690 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4691 err = brcmf_vif_set_mgmt_ie(vif,
4692 BRCMF_VNDR_IE_PRBRSP_FLAG,
4693 &buf[ie_offset],
4694 ie_len);
4695 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4696 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004697 } else if (ieee80211_is_action(mgmt->frame_control)) {
4698 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4699 if (af_params == NULL) {
4700 brcmf_err("unable to allocate frame\n");
4701 err = -ENOMEM;
4702 goto exit;
4703 }
4704 action_frame = &af_params->action_frame;
4705 /* Add the packet Id */
4706 action_frame->packet_id = cpu_to_le32(*cookie);
4707 /* Add BSSID */
4708 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4709 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4710 /* Add the length exepted for 802.11 header */
4711 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004712 /* Add the channel. Use the one specified as parameter if any or
4713 * the current one (got from the firmware) otherwise
4714 */
4715 if (chan)
4716 freq = chan->center_freq;
4717 else
4718 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4719 &freq);
4720 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004721 af_params->channel = cpu_to_le32(chan_nr);
4722
4723 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4724 le16_to_cpu(action_frame->len));
4725
4726 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004727 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004728
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004729 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004730 af_params);
4731
4732 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4733 GFP_KERNEL);
4734 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004735 } else {
4736 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4737 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4738 }
4739
Hante Meuleman18e2f612013-02-08 15:53:49 +01004740exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004741 return err;
4742}
4743
4744
4745static int
4746brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4747 struct wireless_dev *wdev,
4748 u64 cookie)
4749{
4750 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4751 struct brcmf_cfg80211_vif *vif;
4752 int err = 0;
4753
4754 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4755
4756 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4757 if (vif == NULL) {
4758 brcmf_err("No p2p device available for probe response\n");
4759 err = -ENODEV;
4760 goto exit;
4761 }
4762 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4763exit:
4764 return err;
4765}
4766
Piotr Haber61730d42013-04-23 12:53:12 +02004767static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4768 struct wireless_dev *wdev,
4769 enum nl80211_crit_proto_id proto,
4770 u16 duration)
4771{
4772 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4773 struct brcmf_cfg80211_vif *vif;
4774
4775 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4776
4777 /* only DHCP support for now */
4778 if (proto != NL80211_CRIT_PROTO_DHCP)
4779 return -EINVAL;
4780
4781 /* suppress and abort scanning */
4782 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4783 brcmf_abort_scanning(cfg);
4784
4785 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4786}
4787
4788static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4789 struct wireless_dev *wdev)
4790{
4791 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4792 struct brcmf_cfg80211_vif *vif;
4793
4794 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4795
4796 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4797 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4798}
4799
Hante Meuleman70b7d942014-07-30 13:20:07 +02004800static s32
4801brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4802 const struct brcmf_event_msg *e, void *data)
4803{
4804 switch (e->reason) {
4805 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4806 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4807 break;
4808 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4809 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4810 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4811 break;
4812 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4813 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4814 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4815 break;
4816 }
4817
4818 return 0;
4819}
4820
Arend van Spriel89c2f382013-08-10 12:27:25 +02004821static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4822{
4823 int ret;
4824
4825 switch (oper) {
4826 case NL80211_TDLS_DISCOVERY_REQ:
4827 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4828 break;
4829 case NL80211_TDLS_SETUP:
4830 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4831 break;
4832 case NL80211_TDLS_TEARDOWN:
4833 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4834 break;
4835 default:
4836 brcmf_err("unsupported operation: %d\n", oper);
4837 ret = -EOPNOTSUPP;
4838 }
4839 return ret;
4840}
4841
4842static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004843 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004844 enum nl80211_tdls_operation oper)
4845{
4846 struct brcmf_if *ifp;
4847 struct brcmf_tdls_iovar_le info;
4848 int ret = 0;
4849
4850 ret = brcmf_convert_nl80211_tdls_oper(oper);
4851 if (ret < 0)
4852 return ret;
4853
4854 ifp = netdev_priv(ndev);
4855 memset(&info, 0, sizeof(info));
4856 info.mode = (u8)ret;
4857 if (peer)
4858 memcpy(info.ea, peer, ETH_ALEN);
4859
4860 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4861 &info, sizeof(info));
4862 if (ret < 0)
4863 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4864
4865 return ret;
4866}
4867
Arend van Spriel5b435de2011-10-05 13:19:03 +02004868static struct cfg80211_ops wl_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01004869 .add_virtual_intf = brcmf_cfg80211_add_iface,
4870 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004871 .change_virtual_intf = brcmf_cfg80211_change_iface,
4872 .scan = brcmf_cfg80211_scan,
4873 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4874 .join_ibss = brcmf_cfg80211_join_ibss,
4875 .leave_ibss = brcmf_cfg80211_leave_ibss,
4876 .get_station = brcmf_cfg80211_get_station,
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02004877 .dump_station = brcmf_cfg80211_dump_station,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004878 .set_tx_power = brcmf_cfg80211_set_tx_power,
4879 .get_tx_power = brcmf_cfg80211_get_tx_power,
4880 .add_key = brcmf_cfg80211_add_key,
4881 .del_key = brcmf_cfg80211_del_key,
4882 .get_key = brcmf_cfg80211_get_key,
4883 .set_default_key = brcmf_cfg80211_config_default_key,
4884 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4885 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004886 .connect = brcmf_cfg80211_connect,
4887 .disconnect = brcmf_cfg80211_disconnect,
4888 .suspend = brcmf_cfg80211_suspend,
4889 .resume = brcmf_cfg80211_resume,
4890 .set_pmksa = brcmf_cfg80211_set_pmksa,
4891 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02004892 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02004893 .start_ap = brcmf_cfg80211_start_ap,
4894 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01004895 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02004896 .del_station = brcmf_cfg80211_del_station,
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004897 .change_station = brcmf_cfg80211_change_station,
Arend van Spriele5806072012-09-19 22:21:08 +02004898 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4899 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004900 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4901 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4902 .remain_on_channel = brcmf_p2p_remain_on_channel,
4903 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02004904 .start_p2p_device = brcmf_p2p_start_device,
4905 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02004906 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4907 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004908 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004909};
4910
Arend van Spriel3eacf862012-10-22 13:55:30 -07004911struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01004912 enum nl80211_iftype type,
4913 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004914{
Hante Meulemana44aa402014-12-03 21:05:33 +01004915 struct brcmf_cfg80211_vif *vif_walk;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004916 struct brcmf_cfg80211_vif *vif;
Hante Meulemana44aa402014-12-03 21:05:33 +01004917 bool mbss;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004918
Arend van Spriel33a6b152013-02-08 15:53:39 +01004919 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01004920 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07004921 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4922 if (!vif)
4923 return ERR_PTR(-ENOMEM);
4924
4925 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01004926 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004927
Arend van Spriel3eacf862012-10-22 13:55:30 -07004928 vif->pm_block = pm_block;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004929
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004930 brcmf_init_prof(&vif->profile);
4931
Hante Meulemana44aa402014-12-03 21:05:33 +01004932 if (type == NL80211_IFTYPE_AP) {
4933 mbss = false;
4934 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
4935 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
4936 mbss = true;
4937 break;
4938 }
4939 }
4940 vif->mbss = mbss;
4941 }
4942
Arend van Spriel3eacf862012-10-22 13:55:30 -07004943 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004944 return vif;
4945}
4946
Arend van Spriel427dec52014-01-06 12:40:47 +01004947void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07004948{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004949 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004950 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004951}
4952
Arend van Spriel9df4d542014-01-06 12:40:49 +01004953void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4954{
4955 struct brcmf_cfg80211_vif *vif;
4956 struct brcmf_if *ifp;
4957
4958 ifp = netdev_priv(ndev);
4959 vif = ifp->vif;
4960
Arend van Spriel95ef1232015-08-26 22:15:04 +02004961 if (vif)
4962 brcmf_free_vif(vif);
Arend van Spriel9df4d542014-01-06 12:40:49 +01004963 free_netdev(ndev);
4964}
4965
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004966static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004967{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004968 u32 event = e->event_code;
4969 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004970
4971 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004972 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004973 return true;
4974 }
4975
4976 return false;
4977}
4978
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004979static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004980{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004981 u32 event = e->event_code;
4982 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004983
Hante Meuleman68ca3952014-02-25 20:30:26 +01004984 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4985 (event == BRCMF_E_DISASSOC_IND) ||
4986 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01004987 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004988 return true;
4989 }
4990 return false;
4991}
4992
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004993static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004994 const struct brcmf_event_msg *e)
4995{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004996 u32 event = e->event_code;
4997 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004998
4999 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005000 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
5001 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005002 return true;
5003 }
5004
5005 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01005006 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005007 return true;
5008 }
5009
5010 return false;
5011}
5012
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005013static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005014{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005015 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005016
5017 kfree(conn_info->req_ie);
5018 conn_info->req_ie = NULL;
5019 conn_info->req_ie_len = 0;
5020 kfree(conn_info->resp_ie);
5021 conn_info->resp_ie = NULL;
5022 conn_info->resp_ie_len = 0;
5023}
5024
Hante Meuleman89286dc2013-02-08 15:53:46 +01005025static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
5026 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005027{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005028 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005029 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005030 u32 req_len;
5031 u32 resp_len;
5032 s32 err = 0;
5033
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005034 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005035
Arend van Sprielac24be62012-10-22 10:36:23 -07005036 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
5037 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005038 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005039 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005040 return err;
5041 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005042 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005043 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005044 req_len = le32_to_cpu(assoc_info->req_len);
5045 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005046 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005047 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005048 cfg->extra_buf,
5049 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005050 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005051 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005052 return err;
5053 }
5054 conn_info->req_ie_len = req_len;
5055 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005056 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005057 GFP_KERNEL);
5058 } else {
5059 conn_info->req_ie_len = 0;
5060 conn_info->req_ie = NULL;
5061 }
5062 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005063 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005064 cfg->extra_buf,
5065 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005066 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005067 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005068 return err;
5069 }
5070 conn_info->resp_ie_len = resp_len;
5071 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005072 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005073 GFP_KERNEL);
5074 } else {
5075 conn_info->resp_ie_len = 0;
5076 conn_info->resp_ie = NULL;
5077 }
Arend van Spriel16886732012-12-05 15:26:04 +01005078 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
5079 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005080
5081 return err;
5082}
5083
5084static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005085brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005086 struct net_device *ndev,
5087 const struct brcmf_event_msg *e)
5088{
Arend van Sprielc1179032012-10-22 13:55:33 -07005089 struct brcmf_if *ifp = netdev_priv(ndev);
5090 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005091 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
5092 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07005093 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005094 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07005095 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02005096 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005097 u32 freq;
5098 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07005099 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005100
Arend van Sprield96b8012012-12-05 15:26:02 +01005101 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005102
Hante Meuleman89286dc2013-02-08 15:53:46 +01005103 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005104 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005105 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005106
Franky Lina180b832012-10-10 11:13:09 -07005107 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
5108 if (buf == NULL) {
5109 err = -ENOMEM;
5110 goto done;
5111 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02005112
Franky Lina180b832012-10-10 11:13:09 -07005113 /* data sent to dongle has to be little endian */
5114 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07005115 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07005116 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07005117
5118 if (err)
5119 goto done;
5120
5121 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02005122 ch.chspec = le16_to_cpu(bi->chanspec);
5123 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005124
Franky Lin83cf17a2013-04-11 13:28:50 +02005125 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005126 band = wiphy->bands[IEEE80211_BAND_2GHZ];
5127 else
5128 band = wiphy->bands[IEEE80211_BAND_5GHZ];
5129
Franky Lin83cf17a2013-04-11 13:28:50 +02005130 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005131 notify_channel = ieee80211_get_channel(wiphy, freq);
5132
Franky Lina180b832012-10-10 11:13:09 -07005133done:
5134 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02005135 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005136 conn_info->req_ie, conn_info->req_ie_len,
5137 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005138 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005139
Arend van Sprielc1179032012-10-22 13:55:33 -07005140 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01005141 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005142 return err;
5143}
5144
5145static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005146brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005147 struct net_device *ndev, const struct brcmf_event_msg *e,
5148 bool completed)
5149{
Arend van Sprielc1179032012-10-22 13:55:33 -07005150 struct brcmf_if *ifp = netdev_priv(ndev);
5151 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005152 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005153
Arend van Sprield96b8012012-12-05 15:26:02 +01005154 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005155
Arend van Sprielc1179032012-10-22 13:55:33 -07005156 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5157 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02005158 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01005159 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005160 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005161 brcmf_update_bss_info(cfg, ifp);
5162 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5163 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005164 }
5165 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02005166 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005167 conn_info->req_ie,
5168 conn_info->req_ie_len,
5169 conn_info->resp_ie,
5170 conn_info->resp_ie_len,
5171 completed ? WLAN_STATUS_SUCCESS :
5172 WLAN_STATUS_AUTH_TIMEOUT,
5173 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005174 brcmf_dbg(CONN, "Report connect result - connection %s\n",
5175 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005176 }
Arend van Sprield96b8012012-12-05 15:26:02 +01005177 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005178 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005179}
5180
5181static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005182brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02005183 struct net_device *ndev,
5184 const struct brcmf_event_msg *e, void *data)
5185{
Hante Meulemana44aa402014-12-03 21:05:33 +01005186 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman7ee29602013-02-06 18:40:43 +01005187 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005188 u32 event = e->event_code;
5189 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02005190 struct station_info sinfo;
5191
Arend van Spriel16886732012-12-05 15:26:04 +01005192 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005193 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
5194 ndev != cfg_to_ndev(cfg)) {
5195 brcmf_dbg(CONN, "AP mode link down\n");
5196 complete(&cfg->vif_disabled);
Hante Meulemana44aa402014-12-03 21:05:33 +01005197 if (ifp->vif->mbss)
Arend van Sprielee6e3a32015-08-26 22:14:55 +02005198 brcmf_remove_interface(ifp);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005199 return 0;
5200 }
Hante Meuleman1a873342012-09-27 14:17:54 +02005201
Hante Meuleman1a873342012-09-27 14:17:54 +02005202 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01005203 (reason == BRCMF_E_STATUS_SUCCESS)) {
5204 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02005205 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005206 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02005207 return -EINVAL;
5208 }
5209 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005210 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02005211 generation++;
5212 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005213 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005214 } else if ((event == BRCMF_E_DISASSOC_IND) ||
5215 (event == BRCMF_E_DEAUTH_IND) ||
5216 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01005217 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005218 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01005219 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02005220}
5221
5222static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005223brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005224 const struct brcmf_event_msg *e, void *data)
5225{
Arend van Spriel19937322012-11-05 16:22:32 -08005226 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5227 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07005228 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005229 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005230 s32 err = 0;
5231
Hante Meuleman8851cce2014-07-30 13:20:02 +02005232 if ((e->event_code == BRCMF_E_DEAUTH) ||
5233 (e->event_code == BRCMF_E_DEAUTH_IND) ||
5234 (e->event_code == BRCMF_E_DISASSOC_IND) ||
5235 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
5236 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5237 }
5238
Arend van Spriel967fe2c2014-03-15 17:18:21 +01005239 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005240 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005241 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005242 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005243 if (brcmf_is_ibssmode(ifp->vif)) {
Hante Meulemanb0a79082015-12-10 13:43:07 +01005244 brcmf_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005245 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005246 memcpy(profile->bssid, e->addr, ETH_ALEN);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005247 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07005248 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5249 &ifp->vif->sme_state);
5250 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5251 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005252 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005253 brcmf_bss_connect_done(cfg, ndev, e, true);
Hante Meuleman92121e62015-10-08 20:33:21 +02005254 brcmf_net_setcarrier(ifp, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005255 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005256 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005257 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005258 brcmf_bss_connect_done(cfg, ndev, e, false);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01005259 brcmf_link_down(ifp->vif,
5260 brcmf_map_fw_linkdown_reason(e));
5261 brcmf_init_prof(ndev_to_prof(ndev));
5262 if (ndev != cfg_to_ndev(cfg))
5263 complete(&cfg->vif_disabled);
5264 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005265 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005266 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005267 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07005268 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5269 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005270 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005271 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005272 }
5273
5274 return err;
5275}
5276
5277static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005278brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005279 const struct brcmf_event_msg *e, void *data)
5280{
Arend van Spriel19937322012-11-05 16:22:32 -08005281 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005282 u32 event = e->event_code;
5283 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005284
5285 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07005286 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08005287 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005288 else
Arend van Spriel19937322012-11-05 16:22:32 -08005289 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005290 }
5291
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005292 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005293}
5294
5295static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005296brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005297 const struct brcmf_event_msg *e, void *data)
5298{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005299 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005300 enum nl80211_key_type key_type;
5301
5302 if (flags & BRCMF_EVENT_MSG_GROUP)
5303 key_type = NL80211_KEYTYPE_GROUP;
5304 else
5305 key_type = NL80211_KEYTYPE_PAIRWISE;
5306
Arend van Spriel19937322012-11-05 16:22:32 -08005307 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005308 NULL, GFP_KERNEL);
5309
5310 return 0;
5311}
5312
Arend van Sprield3c0b632013-02-08 15:53:37 +01005313static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
5314 const struct brcmf_event_msg *e, void *data)
5315{
5316 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5317 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
5318 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5319 struct brcmf_cfg80211_vif *vif;
5320
Hante Meuleman37a869e2015-10-29 20:33:17 +01005321 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
Arend van Sprield3c0b632013-02-08 15:53:37 +01005322 ifevent->action, ifevent->flags, ifevent->ifidx,
Hante Meuleman37a869e2015-10-29 20:33:17 +01005323 ifevent->bsscfgidx);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005324
Arend van Sprield3c0b632013-02-08 15:53:37 +01005325 mutex_lock(&event->vif_event_lock);
5326 event->action = ifevent->action;
5327 vif = event->vif;
5328
5329 switch (ifevent->action) {
5330 case BRCMF_E_IF_ADD:
5331 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08005332 if (!cfg->vif_event.vif) {
5333 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005334 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08005335 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005336
5337 ifp->vif = vif;
5338 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02005339 if (ifp->ndev) {
5340 vif->wdev.netdev = ifp->ndev;
5341 ifp->ndev->ieee80211_ptr = &vif->wdev;
5342 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
5343 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005344 mutex_unlock(&event->vif_event_lock);
5345 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01005346 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01005347
5348 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01005349 mutex_unlock(&event->vif_event_lock);
5350 /* event may not be upon user request */
5351 if (brcmf_cfg80211_vif_event_armed(cfg))
5352 wake_up(&event->vif_wq);
5353 return 0;
5354
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01005355 case BRCMF_E_IF_CHANGE:
5356 mutex_unlock(&event->vif_event_lock);
5357 wake_up(&event->vif_wq);
5358 return 0;
5359
Arend van Sprield3c0b632013-02-08 15:53:37 +01005360 default:
5361 mutex_unlock(&event->vif_event_lock);
5362 break;
5363 }
5364 return -EINVAL;
5365}
5366
Arend van Spriel5b435de2011-10-05 13:19:03 +02005367static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
5368{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005369 conf->frag_threshold = (u32)-1;
5370 conf->rts_threshold = (u32)-1;
5371 conf->retry_short = (u32)-1;
5372 conf->retry_long = (u32)-1;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005373}
5374
Arend van Spriel5c36b992012-11-14 18:46:05 -08005375static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005376{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005377 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
5378 brcmf_notify_connect_status);
5379 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
5380 brcmf_notify_connect_status);
5381 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
5382 brcmf_notify_connect_status);
5383 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
5384 brcmf_notify_connect_status);
5385 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
5386 brcmf_notify_connect_status);
5387 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
5388 brcmf_notify_connect_status);
5389 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
5390 brcmf_notify_roaming_status);
5391 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
5392 brcmf_notify_mic_status);
5393 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
5394 brcmf_notify_connect_status);
5395 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
5396 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005397 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
5398 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005399 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005400 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005401 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
5402 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01005403 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
5404 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01005405 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
5406 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005407 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
5408 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005409}
5410
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005411static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005412{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005413 kfree(cfg->conf);
5414 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005415 kfree(cfg->extra_buf);
5416 cfg->extra_buf = NULL;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005417 kfree(cfg->wowl.nd);
5418 cfg->wowl.nd = NULL;
5419 kfree(cfg->wowl.nd_info);
5420 cfg->wowl.nd_info = NULL;
Hante Meulemand5367332016-02-17 11:26:51 +01005421 kfree(cfg->escan_info.escan_buf);
5422 cfg->escan_info.escan_buf = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005423}
5424
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005425static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005426{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005427 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
5428 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005429 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005430 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
5431 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005432 goto init_priv_mem_out;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005433 cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL);
5434 if (!cfg->wowl.nd)
5435 goto init_priv_mem_out;
5436 cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) +
5437 sizeof(struct cfg80211_wowlan_nd_match *),
5438 GFP_KERNEL);
5439 if (!cfg->wowl.nd_info)
5440 goto init_priv_mem_out;
Hante Meulemand5367332016-02-17 11:26:51 +01005441 cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL);
5442 if (!cfg->escan_info.escan_buf)
5443 goto init_priv_mem_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005444
5445 return 0;
5446
5447init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005448 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005449
5450 return -ENOMEM;
5451}
5452
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005453static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005454{
5455 s32 err = 0;
5456
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005457 cfg->scan_request = NULL;
5458 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01005459 cfg->active_scan = true; /* we do active scan per default */
5460 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005461 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005462 if (err)
5463 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005464 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005465 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005466 brcmf_init_escan(cfg);
5467 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005468 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005469 return err;
5470}
5471
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005472static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005473{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005474 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005475 brcmf_abort_scanning(cfg);
5476 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005477}
5478
Arend van Sprield3c0b632013-02-08 15:53:37 +01005479static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
5480{
5481 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005482 mutex_init(&event->vif_event_lock);
5483}
5484
Hante Meuleman1119e232015-11-25 11:32:42 +01005485static s32 brcmf_dongle_roam(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005486{
Hante Meuleman1119e232015-11-25 11:32:42 +01005487 s32 err;
5488 u32 bcn_timeout;
Arend van Sprielf588bc02011-10-12 20:51:22 +02005489 __le32 roamtrigger[2];
5490 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005491
Hante Meuleman1119e232015-11-25 11:32:42 +01005492 /* Configure beacon timeout value based upon roaming setting */
Hante Meuleman7d34b052016-01-02 09:41:41 +01005493 if (ifp->drvr->settings->roamoff)
Hante Meuleman1119e232015-11-25 11:32:42 +01005494 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF;
5495 else
5496 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON;
5497 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
5498 if (err) {
5499 brcmf_err("bcn_timeout error (%d)\n", err);
5500 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005501 }
5502
Hante Meuleman1119e232015-11-25 11:32:42 +01005503 /* Enable/Disable built-in roaming to allow supplicant to take care of
5504 * roaming.
Arend van Spriel5b435de2011-10-05 13:19:03 +02005505 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005506 brcmf_dbg(INFO, "Internal Roaming = %s\n",
Hante Meuleman7d34b052016-01-02 09:41:41 +01005507 ifp->drvr->settings->roamoff ? "Off" : "On");
5508 err = brcmf_fil_iovar_int_set(ifp, "roam_off",
5509 ifp->drvr->settings->roamoff);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005510 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005511 brcmf_err("roam_off error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005512 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005513 }
5514
Arend van Sprielf588bc02011-10-12 20:51:22 +02005515 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
5516 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005517 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005518 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005519 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005520 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005521 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005522 }
5523
Arend van Sprielf588bc02011-10-12 20:51:22 +02005524 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
5525 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005526 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005527 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005528 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005529 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005530 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005531 }
5532
Hante Meuleman1119e232015-11-25 11:32:42 +01005533roam_setup_done:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005534 return err;
5535}
5536
5537static s32
Hante Meuleman1678ba82015-12-10 13:43:00 +01005538brcmf_dongle_scantime(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005539{
5540 s32 err = 0;
5541
Arend van Sprielac24be62012-10-22 10:36:23 -07005542 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005543 BRCMF_SCAN_CHANNEL_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005544 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005545 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005546 goto dongle_scantime_out;
5547 }
Arend van Sprielac24be62012-10-22 10:36:23 -07005548 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005549 BRCMF_SCAN_UNASSOC_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005550 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005551 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005552 goto dongle_scantime_out;
5553 }
5554
Arend van Sprielac24be62012-10-22 10:36:23 -07005555 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005556 BRCMF_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005557 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005558 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005559 goto dongle_scantime_out;
5560 }
5561
5562dongle_scantime_out:
5563 return err;
5564}
5565
Arend van Sprielb48d8912014-07-12 08:49:41 +02005566static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5567 struct brcmu_chan *ch)
5568{
5569 u32 ht40_flag;
5570
5571 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5572 if (ch->sb == BRCMU_CHAN_SB_U) {
5573 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5574 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5575 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5576 } else {
5577 /* It should be one of
5578 * IEEE80211_CHAN_NO_HT40 or
5579 * IEEE80211_CHAN_NO_HT40PLUS
5580 */
5581 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5582 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5583 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5584 }
5585}
5586
5587static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5588 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005589{
5590 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005591 struct ieee80211_supported_band *band;
5592 struct ieee80211_channel *channel;
5593 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005594 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005595 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005596 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005597 u8 *pbuf;
5598 u32 i, j;
5599 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005600 u32 chaninfo;
Hante Meulemand48200b2013-04-03 12:40:29 +02005601 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02005602
5603 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5604
5605 if (pbuf == NULL)
5606 return -ENOMEM;
5607
5608 list = (struct brcmf_chanspec_list *)pbuf;
5609
5610 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5611 BRCMF_DCMD_MEDLEN);
5612 if (err) {
5613 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005614 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005615 }
5616
Arend van Sprielb48d8912014-07-12 08:49:41 +02005617 wiphy = cfg_to_wiphy(cfg);
Arend van Spriel58de92d2015-04-14 20:10:24 +02005618 band = wiphy->bands[IEEE80211_BAND_2GHZ];
5619 if (band)
5620 for (i = 0; i < band->n_channels; i++)
5621 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
5622 band = wiphy->bands[IEEE80211_BAND_5GHZ];
5623 if (band)
5624 for (i = 0; i < band->n_channels; i++)
5625 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Hante Meulemand48200b2013-04-03 12:40:29 +02005626
5627 total = le32_to_cpu(list->count);
5628 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005629 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5630 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005631
Franky Lin83cf17a2013-04-11 13:28:50 +02005632 if (ch.band == BRCMU_CHAN_BAND_2G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005633 band = wiphy->bands[IEEE80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005634 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005635 band = wiphy->bands[IEEE80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005636 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005637 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005638 continue;
5639 }
Arend van Spriel58de92d2015-04-14 20:10:24 +02005640 if (!band)
5641 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005642 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005643 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005644 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005645 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005646 ch.bw == BRCMU_CHAN_BW_80)
5647 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005648
5649 channel = band->channels;
5650 index = band->n_channels;
5651 for (j = 0; j < band->n_channels; j++) {
5652 if (channel[j].hw_value == ch.chnum) {
5653 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005654 break;
5655 }
5656 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005657 channel[index].center_freq =
5658 ieee80211_channel_to_frequency(ch.chnum, band->band);
5659 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005660
Arend van Sprielb48d8912014-07-12 08:49:41 +02005661 /* assuming the chanspecs order is HT20,
5662 * HT40 upper, HT40 lower, and VHT80.
5663 */
5664 if (ch.bw == BRCMU_CHAN_BW_80) {
5665 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5666 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5667 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5668 } else {
Arend van Spriel58de92d2015-04-14 20:10:24 +02005669 /* enable the channel and disable other bandwidths
5670 * for now as mentioned order assure they are enabled
5671 * for subsequent chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005672 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005673 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5674 IEEE80211_CHAN_NO_80MHZ;
5675 ch.bw = BRCMU_CHAN_BW_20;
5676 cfg->d11inf.encchspec(&ch);
5677 chaninfo = ch.chspec;
5678 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5679 &chaninfo);
5680 if (!err) {
5681 if (chaninfo & WL_CHAN_RADAR)
5682 channel[index].flags |=
5683 (IEEE80211_CHAN_RADAR |
5684 IEEE80211_CHAN_NO_IR);
5685 if (chaninfo & WL_CHAN_PASSIVE)
5686 channel[index].flags |=
5687 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005688 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005689 }
5690 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005691
Arend van Sprielb48d8912014-07-12 08:49:41 +02005692fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005693 kfree(pbuf);
5694 return err;
5695}
5696
Arend van Sprielb48d8912014-07-12 08:49:41 +02005697static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005698{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005699 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5700 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005701 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005702 struct brcmf_chanspec_list *list;
5703 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005704 u32 val;
5705 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005706 struct brcmu_chan ch;
5707 u32 num_chan;
5708 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005709
5710 /* verify support for bw_cap command */
5711 val = WLC_BAND_5G;
5712 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5713
5714 if (!err) {
5715 /* only set 2G bandwidth using bw_cap command */
5716 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5717 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5718 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5719 sizeof(band_bwcap));
5720 } else {
5721 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5722 val = WLC_N_BW_40ALL;
5723 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5724 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005725
5726 if (!err) {
5727 /* update channel info in 2G band */
5728 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5729
5730 if (pbuf == NULL)
5731 return -ENOMEM;
5732
5733 ch.band = BRCMU_CHAN_BAND_2G;
5734 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005735 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005736 ch.chnum = 0;
5737 cfg->d11inf.encchspec(&ch);
5738
5739 /* pass encoded chanspec in query */
5740 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5741
5742 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5743 BRCMF_DCMD_MEDLEN);
5744 if (err) {
5745 brcmf_err("get chanspecs error (%d)\n", err);
5746 kfree(pbuf);
5747 return err;
5748 }
5749
5750 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5751 list = (struct brcmf_chanspec_list *)pbuf;
5752 num_chan = le32_to_cpu(list->count);
5753 for (i = 0; i < num_chan; i++) {
5754 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5755 cfg->d11inf.decchspec(&ch);
5756 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5757 continue;
5758 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5759 continue;
5760 for (j = 0; j < band->n_channels; j++) {
5761 if (band->channels[j].hw_value == ch.chnum)
5762 break;
5763 }
5764 if (WARN_ON(j == band->n_channels))
5765 continue;
5766
5767 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5768 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005769 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005770 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005771 return err;
5772}
5773
Arend van Spriel2375d972014-01-06 12:40:41 +01005774static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5775{
5776 u32 band, mimo_bwcap;
5777 int err;
5778
5779 band = WLC_BAND_2G;
5780 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5781 if (!err) {
5782 bw_cap[IEEE80211_BAND_2GHZ] = band;
5783 band = WLC_BAND_5G;
5784 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5785 if (!err) {
5786 bw_cap[IEEE80211_BAND_5GHZ] = band;
5787 return;
5788 }
5789 WARN_ON(1);
5790 return;
5791 }
5792 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5793 mimo_bwcap = 0;
5794 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5795 if (err)
5796 /* assume 20MHz if firmware does not give a clue */
5797 mimo_bwcap = WLC_N_BW_20ALL;
5798
5799 switch (mimo_bwcap) {
5800 case WLC_N_BW_40ALL:
5801 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5802 /* fall-thru */
5803 case WLC_N_BW_20IN2G_40IN5G:
5804 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5805 /* fall-thru */
5806 case WLC_N_BW_20ALL:
5807 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5808 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5809 break;
5810 default:
5811 brcmf_err("invalid mimo_bw_cap value\n");
5812 }
5813}
Hante Meulemand48200b2013-04-03 12:40:29 +02005814
Arend van Spriel18d6c532014-05-12 10:47:35 +02005815static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5816 u32 bw_cap[2], u32 nchain)
5817{
5818 band->ht_cap.ht_supported = true;
5819 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5820 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5821 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5822 }
5823 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5824 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5825 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5826 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5827 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5828 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5829}
5830
5831static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5832{
5833 u16 mcs_map;
5834 int i;
5835
5836 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5837 mcs_map = (mcs_map << 2) | supp;
5838
5839 return cpu_to_le16(mcs_map);
5840}
5841
5842static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005843 u32 bw_cap[2], u32 nchain, u32 txstreams,
5844 u32 txbf_bfe_cap, u32 txbf_bfr_cap)
Arend van Spriel18d6c532014-05-12 10:47:35 +02005845{
5846 __le16 mcs_map;
5847
5848 /* not allowed in 2.4G band */
5849 if (band->band == IEEE80211_BAND_2GHZ)
5850 return;
5851
5852 band->vht_cap.vht_supported = true;
5853 /* 80MHz is mandatory */
5854 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5855 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5856 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5857 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5858 }
5859 /* all support 256-QAM */
5860 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5861 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5862 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005863
5864 /* Beamforming support information */
5865 if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP)
5866 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
5867 if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP)
5868 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
5869 if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP)
5870 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
5871 if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP)
5872 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
5873
5874 if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) {
5875 band->vht_cap.cap |=
5876 (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
5877 band->vht_cap.cap |= ((txstreams - 1) <<
5878 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
5879 band->vht_cap.cap |=
5880 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
5881 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005882}
5883
Arend van Sprielb48d8912014-07-12 08:49:41 +02005884static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005885{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005886 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07005887 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02005888 u32 nmode = 0;
5889 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005890 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01005891 u32 rxchain;
5892 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005893 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005894 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01005895 struct ieee80211_supported_band *band;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005896 u32 txstreams = 0;
5897 u32 txbf_bfe_cap = 0;
5898 u32 txbf_bfr_cap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005899
Arend van Spriel18d6c532014-05-12 10:47:35 +02005900 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02005901 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5902 if (err) {
5903 brcmf_err("nmode error (%d)\n", err);
5904 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005905 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005906 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005907 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5908 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5909 bw_cap[IEEE80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02005910
Daniel Kim4aca7a12014-02-25 20:30:36 +01005911 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5912 if (err) {
5913 brcmf_err("rxchain error (%d)\n", err);
5914 nchain = 1;
5915 } else {
5916 for (nchain = 0; rxchain; nchain++)
5917 rxchain = rxchain & (rxchain - 1);
5918 }
5919 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5920
Arend van Sprielb48d8912014-07-12 08:49:41 +02005921 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005922 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005923 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02005924 return err;
5925 }
5926
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005927 if (vhtmode) {
5928 (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams);
5929 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap",
5930 &txbf_bfe_cap);
5931 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap",
5932 &txbf_bfr_cap);
5933 }
5934
Arend van Sprielb48d8912014-07-12 08:49:41 +02005935 wiphy = cfg_to_wiphy(cfg);
5936 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5937 band = wiphy->bands[i];
5938 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01005939 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02005940
Arend van Spriel18d6c532014-05-12 10:47:35 +02005941 if (nmode)
5942 brcmf_update_ht_cap(band, bw_cap, nchain);
5943 if (vhtmode)
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005944 brcmf_update_vht_cap(band, bw_cap, nchain, txstreams,
5945 txbf_bfe_cap, txbf_bfr_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005946 }
5947
Arend van Sprielb48d8912014-07-12 08:49:41 +02005948 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005949}
5950
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005951static const struct ieee80211_txrx_stypes
5952brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5953 [NL80211_IFTYPE_STATION] = {
5954 .tx = 0xffff,
5955 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5956 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5957 },
5958 [NL80211_IFTYPE_P2P_CLIENT] = {
5959 .tx = 0xffff,
5960 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5961 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5962 },
5963 [NL80211_IFTYPE_P2P_GO] = {
5964 .tx = 0xffff,
5965 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5966 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5967 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5968 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5969 BIT(IEEE80211_STYPE_AUTH >> 4) |
5970 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5971 BIT(IEEE80211_STYPE_ACTION >> 4)
5972 },
5973 [NL80211_IFTYPE_P2P_DEVICE] = {
5974 .tx = 0xffff,
5975 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5976 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5977 }
5978};
5979
Arend van Spriel0882dda2015-08-20 22:06:03 +02005980/**
5981 * brcmf_setup_ifmodes() - determine interface modes and combinations.
5982 *
5983 * @wiphy: wiphy object.
5984 * @ifp: interface object needed for feat module api.
5985 *
5986 * The interface modes and combinations are determined dynamically here
5987 * based on firmware functionality.
5988 *
5989 * no p2p and no mbss:
5990 *
5991 * #STA <= 1, #AP <= 1, channels = 1, 2 total
5992 *
5993 * no p2p and mbss:
5994 *
5995 * #STA <= 1, #AP <= 1, channels = 1, 2 total
5996 * #AP <= 4, matching BI, channels = 1, 4 total
5997 *
5998 * p2p, no mchan, and mbss:
5999 *
6000 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
6001 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
6002 * #AP <= 4, matching BI, channels = 1, 4 total
6003 *
6004 * p2p, mchan, and mbss:
6005 *
6006 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
6007 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
6008 * #AP <= 4, matching BI, channels = 1, 4 total
6009 */
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006010static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
6011{
6012 struct ieee80211_iface_combination *combo = NULL;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006013 struct ieee80211_iface_limit *c0_limits = NULL;
6014 struct ieee80211_iface_limit *p2p_limits = NULL;
6015 struct ieee80211_iface_limit *mbss_limits = NULL;
6016 bool mbss, p2p;
6017 int i, c, n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006018
Arend van Spriel0882dda2015-08-20 22:06:03 +02006019 mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
6020 p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
6021
6022 n_combos = 1 + !!p2p + !!mbss;
6023 combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006024 if (!combo)
6025 goto err;
6026
Arend van Spriel0882dda2015-08-20 22:06:03 +02006027 c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
6028 if (!c0_limits)
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006029 goto err;
6030
Arend van Spriel0882dda2015-08-20 22:06:03 +02006031 if (p2p) {
6032 p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
6033 if (!p2p_limits)
6034 goto err;
6035 }
6036
6037 if (mbss) {
6038 mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
6039 if (!mbss_limits)
6040 goto err;
6041 }
6042
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006043 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
6044 BIT(NL80211_IFTYPE_ADHOC) |
6045 BIT(NL80211_IFTYPE_AP);
6046
Arend van Spriel0882dda2015-08-20 22:06:03 +02006047 c = 0;
6048 i = 0;
6049 combo[c].num_different_channels = 1;
6050 c0_limits[i].max = 1;
6051 c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6052 if (p2p) {
6053 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
6054 combo[c].num_different_channels = 2;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006055 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
6056 BIT(NL80211_IFTYPE_P2P_GO) |
6057 BIT(NL80211_IFTYPE_P2P_DEVICE);
Arend van Spriel0882dda2015-08-20 22:06:03 +02006058 c0_limits[i].max = 1;
6059 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6060 c0_limits[i].max = 1;
6061 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
6062 BIT(NL80211_IFTYPE_P2P_GO);
6063 } else {
6064 c0_limits[i].max = 1;
6065 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006066 }
Arend van Spriel0882dda2015-08-20 22:06:03 +02006067 combo[c].max_interfaces = i;
6068 combo[c].n_limits = i;
6069 combo[c].limits = c0_limits;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006070
Arend van Spriel0882dda2015-08-20 22:06:03 +02006071 if (p2p) {
6072 c++;
6073 i = 0;
6074 combo[c].num_different_channels = 1;
6075 p2p_limits[i].max = 1;
6076 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6077 p2p_limits[i].max = 1;
6078 p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
6079 p2p_limits[i].max = 1;
6080 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
6081 p2p_limits[i].max = 1;
6082 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6083 combo[c].max_interfaces = i;
6084 combo[c].n_limits = i;
6085 combo[c].limits = p2p_limits;
6086 }
6087
6088 if (mbss) {
6089 c++;
6090 combo[c].beacon_int_infra_match = true;
6091 combo[c].num_different_channels = 1;
6092 mbss_limits[0].max = 4;
6093 mbss_limits[0].types = BIT(NL80211_IFTYPE_AP);
6094 combo[c].max_interfaces = 4;
6095 combo[c].n_limits = 1;
6096 combo[c].limits = mbss_limits;
6097 }
6098 wiphy->n_iface_combinations = n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006099 wiphy->iface_combinations = combo;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006100 return 0;
6101
6102err:
Arend van Spriel0882dda2015-08-20 22:06:03 +02006103 kfree(c0_limits);
6104 kfree(p2p_limits);
6105 kfree(mbss_limits);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006106 kfree(combo);
6107 return -ENOMEM;
6108}
6109
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006110static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
6111{
6112 /* scheduled scan settings */
6113 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
6114 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
6115 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
6116 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
6117}
6118
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006119#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006120static struct wiphy_wowlan_support brcmf_wowlan_support = {
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006121 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01006122 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
6123 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
6124 .pattern_min_len = 1,
6125 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006126};
6127#endif
6128
Hante Meuleman3021ad92016-01-05 11:05:45 +01006129static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp)
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006130{
6131#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006132 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
6133 s32 err;
6134 u32 wowl_cap;
6135
6136 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
6137 err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap);
6138 if (!err) {
6139 if (wowl_cap & BRCMF_WOWL_PFN_FOUND) {
6140 brcmf_wowlan_support.flags |=
6141 WIPHY_WOWLAN_NET_DETECT;
6142 init_waitqueue_head(&cfg->wowl.nd_data_wait);
6143 }
6144 }
6145 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006146 wiphy->wowlan = &brcmf_wowlan_support;
6147#endif
6148}
6149
Arend van Sprielb48d8912014-07-12 08:49:41 +02006150static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006151{
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006152 struct brcmf_pub *drvr = ifp->drvr;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006153 const struct ieee80211_iface_combination *combo;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006154 struct ieee80211_supported_band *band;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006155 u16 max_interfaces = 0;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006156 __le32 bandlist[3];
6157 u32 n_bands;
6158 int err, i;
6159
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006160 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
6161 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
Hante Meuleman6c404f32015-12-10 13:43:03 +01006162 wiphy->max_num_pmkids = BRCMF_MAXPMKID;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006163
6164 err = brcmf_setup_ifmodes(wiphy, ifp);
6165 if (err)
6166 return err;
6167
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006168 for (i = 0, combo = wiphy->iface_combinations;
6169 i < wiphy->n_iface_combinations; i++, combo++) {
6170 max_interfaces = max(max_interfaces, combo->max_interfaces);
6171 }
6172
6173 for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
6174 i++) {
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006175 u8 *addr = drvr->addresses[i].addr;
6176
6177 memcpy(addr, drvr->mac, ETH_ALEN);
6178 if (i) {
6179 addr[0] |= BIT(1);
6180 addr[ETH_ALEN - 1] ^= i;
6181 }
6182 }
6183 wiphy->addresses = drvr->addresses;
6184 wiphy->n_addresses = i;
6185
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006186 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
6187 wiphy->cipher_suites = __wl_cipher_suites;
6188 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
6189 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
6190 WIPHY_FLAG_OFFCHAN_TX |
Hante Meulemana7b82d42015-12-10 13:43:04 +01006191 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6192 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS))
6193 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman7d34b052016-01-02 09:41:41 +01006194 if (!ifp->drvr->settings->roamoff)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006195 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
6196 wiphy->mgmt_stypes = brcmf_txrx_stypes;
6197 wiphy->max_remain_on_channel_duration = 5000;
Arend van Spriel7a7a87d2015-04-14 20:10:27 +02006198 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
6199 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006200
6201 /* vendor commands/events support */
6202 wiphy->vendor_commands = brcmf_vendor_cmds;
6203 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
6204
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006205 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
Hante Meuleman3021ad92016-01-05 11:05:45 +01006206 brcmf_wiphy_wowl_params(wiphy, ifp);
Arend van Spriel58de92d2015-04-14 20:10:24 +02006207 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
6208 sizeof(bandlist));
6209 if (err) {
6210 brcmf_err("could not obtain band info: err=%d\n", err);
6211 return err;
6212 }
6213 /* first entry in bandlist is number of bands */
6214 n_bands = le32_to_cpu(bandlist[0]);
6215 for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
6216 if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
6217 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
6218 GFP_KERNEL);
6219 if (!band)
6220 return -ENOMEM;
6221
6222 band->channels = kmemdup(&__wl_2ghz_channels,
6223 sizeof(__wl_2ghz_channels),
6224 GFP_KERNEL);
6225 if (!band->channels) {
6226 kfree(band);
6227 return -ENOMEM;
6228 }
6229
6230 band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
6231 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6232 }
6233 if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
6234 band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
6235 GFP_KERNEL);
6236 if (!band)
6237 return -ENOMEM;
6238
6239 band->channels = kmemdup(&__wl_5ghz_channels,
6240 sizeof(__wl_5ghz_channels),
6241 GFP_KERNEL);
6242 if (!band->channels) {
6243 kfree(band);
6244 return -ENOMEM;
6245 }
6246
6247 band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
6248 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6249 }
6250 }
6251 err = brcmf_setup_wiphybands(wiphy);
6252 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006253}
6254
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006255static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006256{
6257 struct net_device *ndev;
6258 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01006259 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006260 s32 power_mode;
6261 s32 err = 0;
6262
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006263 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006264 return err;
6265
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006266 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006267 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01006268 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006269
Hante Meuleman40a23292013-01-02 15:22:51 +01006270 /* make sure RF is ready for work */
6271 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
6272
Hante Meuleman1678ba82015-12-10 13:43:00 +01006273 brcmf_dongle_scantime(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006274
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006275 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01006276 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006277 if (err)
6278 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01006279 brcmf_dbg(INFO, "power save set to %s\n",
6280 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02006281
Hante Meuleman1119e232015-11-25 11:32:42 +01006282 err = brcmf_dongle_roam(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006283 if (err)
6284 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07006285 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
6286 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01006287 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006288 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006289
Hante Meulemanb3657452013-05-27 21:09:53 +02006290 brcmf_configure_arp_offload(ifp, true);
6291
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006292 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01006293default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02006294
6295 return err;
6296
6297}
6298
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006299static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006300{
Arend van Sprielc1179032012-10-22 13:55:33 -07006301 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006302
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006303 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006304}
6305
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006306static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006307{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006308 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07006309
Arend van Spriel5b435de2011-10-05 13:19:03 +02006310 /*
6311 * While going down, if associated with AP disassociate
6312 * from AP to save power
6313 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01006314 if (check_vif_up(ifp->vif)) {
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01006315 brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006316
6317 /* Make sure WPA_Supplicant receives all the event
6318 generated due to DISASSOC call to the fw to keep
6319 the state fw and WPA_Supplicant state consistent
6320 */
6321 brcmf_delay(500);
6322 }
6323
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006324 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07006325 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006326
Arend van Spriel5b435de2011-10-05 13:19:03 +02006327 return 0;
6328}
6329
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006330s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006331{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006332 struct brcmf_if *ifp = netdev_priv(ndev);
6333 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006334 s32 err = 0;
6335
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006336 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006337 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006338 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006339
6340 return err;
6341}
6342
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006343s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006344{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006345 struct brcmf_if *ifp = netdev_priv(ndev);
6346 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006347 s32 err = 0;
6348
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006349 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006350 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006351 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006352
6353 return err;
6354}
6355
Arend van Spriela7965fb2013-04-11 17:08:37 +02006356enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
6357{
6358 struct wireless_dev *wdev = &ifp->vif->wdev;
6359
6360 return wdev->iftype;
6361}
6362
Hante Meulemanbfe81972014-10-28 14:56:16 +01006363bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
6364 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01006365{
6366 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006367
6368 list_for_each_entry(vif, &cfg->vif_list, list) {
6369 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006370 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006371 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006372 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006373}
Arend van Sprield3c0b632013-02-08 15:53:37 +01006374
6375static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
6376 u8 action)
6377{
6378 u8 evt_action;
6379
6380 mutex_lock(&event->vif_event_lock);
6381 evt_action = event->action;
6382 mutex_unlock(&event->vif_event_lock);
6383 return evt_action == action;
6384}
6385
6386void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
6387 struct brcmf_cfg80211_vif *vif)
6388{
6389 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6390
6391 mutex_lock(&event->vif_event_lock);
6392 event->vif = vif;
6393 event->action = 0;
6394 mutex_unlock(&event->vif_event_lock);
6395}
6396
6397bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
6398{
6399 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6400 bool armed;
6401
6402 mutex_lock(&event->vif_event_lock);
6403 armed = event->vif != NULL;
6404 mutex_unlock(&event->vif_event_lock);
6405
6406 return armed;
6407}
Arend van Spriela9eb0c42016-02-17 11:26:50 +01006408
6409int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
6410 u8 action, ulong timeout)
Arend van Sprield3c0b632013-02-08 15:53:37 +01006411{
6412 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6413
6414 return wait_event_timeout(event->vif_wq,
6415 vif_event_equals(event, action), timeout);
6416}
6417
Hante Meuleman73345fd2016-02-17 11:26:53 +01006418static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2],
6419 struct brcmf_fil_country_le *ccreq)
6420{
6421 struct cc_translate *country_codes;
6422 struct cc_entry *cc;
6423 s32 found_index;
6424 int i;
6425
6426 country_codes = drvr->settings->country_codes;
6427 if (!country_codes) {
6428 brcmf_dbg(TRACE, "No country codes configured for device\n");
6429 return -EINVAL;
6430 }
6431
6432 if ((alpha2[0] == ccreq->country_abbrev[0]) &&
6433 (alpha2[1] == ccreq->country_abbrev[1])) {
6434 brcmf_dbg(TRACE, "Country code already set\n");
6435 return -EAGAIN;
6436 }
6437
6438 found_index = -1;
6439 for (i = 0; i < country_codes->table_size; i++) {
6440 cc = &country_codes->table[i];
6441 if ((cc->iso3166[0] == '\0') && (found_index == -1))
6442 found_index = i;
6443 if ((cc->iso3166[0] == alpha2[0]) &&
6444 (cc->iso3166[1] == alpha2[1])) {
6445 found_index = i;
6446 break;
6447 }
6448 }
6449 if (found_index == -1) {
6450 brcmf_dbg(TRACE, "No country code match found\n");
6451 return -EINVAL;
6452 }
6453 memset(ccreq, 0, sizeof(*ccreq));
6454 ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev);
6455 memcpy(ccreq->ccode, country_codes->table[found_index].cc,
6456 BRCMF_COUNTRY_BUF_SZ);
6457 ccreq->country_abbrev[0] = alpha2[0];
6458 ccreq->country_abbrev[1] = alpha2[1];
6459 ccreq->country_abbrev[2] = 0;
6460
6461 return 0;
6462}
6463
Arend van Spriel63db1a42014-12-21 12:43:51 +01006464static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
6465 struct regulatory_request *req)
6466{
6467 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6468 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6469 struct brcmf_fil_country_le ccreq;
Hante Meuleman73345fd2016-02-17 11:26:53 +01006470 s32 err;
Arend van Spriel63db1a42014-12-21 12:43:51 +01006471 int i;
6472
Arend van Spriel63db1a42014-12-21 12:43:51 +01006473 /* ignore non-ISO3166 country codes */
6474 for (i = 0; i < sizeof(req->alpha2); i++)
6475 if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
Hante Meuleman73345fd2016-02-17 11:26:53 +01006476 brcmf_err("not a ISO3166 code (0x%02x 0x%02x)\n",
6477 req->alpha2[0], req->alpha2[1]);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006478 return;
6479 }
Hante Meuleman73345fd2016-02-17 11:26:53 +01006480
6481 brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator,
6482 req->alpha2[0], req->alpha2[1]);
6483
6484 err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq));
6485 if (err) {
6486 brcmf_err("Country code iovar returned err = %d\n", err);
6487 return;
6488 }
6489
6490 err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq);
6491 if (err)
6492 return;
6493
6494 err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
6495 if (err) {
6496 brcmf_err("Firmware rejected country setting\n");
Arend van Spriel8afe0ec2015-04-14 20:10:25 +02006497 return;
6498 }
6499 brcmf_setup_wiphybands(wiphy);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006500}
6501
Arend van Sprielb48d8912014-07-12 08:49:41 +02006502static void brcmf_free_wiphy(struct wiphy *wiphy)
6503{
Arend van Spriel0882dda2015-08-20 22:06:03 +02006504 int i;
6505
Arend van Spriel58de92d2015-04-14 20:10:24 +02006506 if (!wiphy)
6507 return;
6508
Arend van Spriel0882dda2015-08-20 22:06:03 +02006509 if (wiphy->iface_combinations) {
6510 for (i = 0; i < wiphy->n_iface_combinations; i++)
6511 kfree(wiphy->iface_combinations[i].limits);
6512 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006513 kfree(wiphy->iface_combinations);
6514 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
6515 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
6516 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
6517 }
6518 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
6519 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
6520 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
6521 }
6522 wiphy_free(wiphy);
6523}
6524
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006525struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006526 struct device *busdev,
6527 bool p2pdev_forced)
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006528{
Arend van Spriel46f3b6e2015-08-26 22:14:58 +02006529 struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006530 struct brcmf_cfg80211_info *cfg;
6531 struct wiphy *wiphy;
6532 struct brcmf_cfg80211_vif *vif;
6533 struct brcmf_if *ifp;
6534 s32 err = 0;
6535 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006536 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006537
6538 if (!ndev) {
6539 brcmf_err("ndev is invalid\n");
6540 return NULL;
6541 }
6542
6543 ifp = netdev_priv(ndev);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006544 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
6545 if (!wiphy) {
6546 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006547 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006548 }
Rafał Miłecki6896f4f2015-05-31 02:52:26 +02006549 memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006550 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006551
6552 cfg = wiphy_priv(wiphy);
6553 cfg->wiphy = wiphy;
6554 cfg->pub = drvr;
6555 init_vif_event(&cfg->vif_event);
6556 INIT_LIST_HEAD(&cfg->vif_list);
6557
6558 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006559 if (IS_ERR(vif))
6560 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006561
6562 vif->ifp = ifp;
6563 vif->wdev.netdev = ndev;
6564 ndev->ieee80211_ptr = &vif->wdev;
6565 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
6566
6567 err = wl_init_priv(cfg);
6568 if (err) {
6569 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006570 brcmf_free_vif(vif);
6571 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006572 }
6573 ifp->vif = vif;
6574
Arend van Sprielb48d8912014-07-12 08:49:41 +02006575 /* determine d11 io type before wiphy setup */
6576 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006577 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006578 brcmf_err("Failed to get D11 version (%d)\n", err);
6579 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006580 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006581 cfg->d11inf.io_type = (u8)io_type;
6582 brcmu_d11_attach(&cfg->d11inf);
6583
6584 err = brcmf_setup_wiphy(wiphy, ifp);
6585 if (err < 0)
6586 goto priv_out;
6587
6588 brcmf_dbg(INFO, "Registering custom regulatory\n");
Arend van Spriel63db1a42014-12-21 12:43:51 +01006589 wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006590 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
6591 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
6592
6593 /* firmware defaults to 40MHz disabled in 2G band. We signal
6594 * cfg80211 here that we do and have it decide we can enable
6595 * it. But first check if device does support 2G operation.
6596 */
6597 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
6598 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
6599 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6600 }
6601 err = wiphy_register(wiphy);
6602 if (err < 0) {
6603 brcmf_err("Could not register wiphy device (%d)\n", err);
6604 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006605 }
6606
6607 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
6608 * setup 40MHz in 2GHz band and enable OBSS scanning.
6609 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02006610 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
6611 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006612 if (!err)
6613 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
6614 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006615 else
6616 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006617 }
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006618 /* p2p might require that "if-events" get processed by fweh. So
6619 * activate the already registered event handlers now and activate
6620 * the rest when initialization has completed. drvr->config needs to
6621 * be assigned before activating events.
6622 */
6623 drvr->config = cfg;
6624 err = brcmf_fweh_activate_events(ifp);
6625 if (err) {
6626 brcmf_err("FWEH activation failed (%d)\n", err);
6627 goto wiphy_unreg_out;
6628 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006629
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006630 err = brcmf_p2p_attach(cfg, p2pdev_forced);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006631 if (err) {
6632 brcmf_err("P2P initilisation failed (%d)\n", err);
6633 goto wiphy_unreg_out;
6634 }
6635 err = brcmf_btcoex_attach(cfg);
6636 if (err) {
6637 brcmf_err("BT-coex initialisation failed (%d)\n", err);
6638 brcmf_p2p_detach(&cfg->p2p);
6639 goto wiphy_unreg_out;
6640 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006641
Hante Meulemana7b82d42015-12-10 13:43:04 +01006642 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) {
6643 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
6644 if (err) {
6645 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
6646 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
6647 } else {
6648 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
6649 brcmf_notify_tdls_peer_event);
6650 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006651 }
6652
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006653 /* (re-) activate FWEH event handling */
6654 err = brcmf_fweh_activate_events(ifp);
6655 if (err) {
6656 brcmf_err("FWEH activation failed (%d)\n", err);
6657 goto wiphy_unreg_out;
6658 }
6659
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006660 /* Fill in some of the advertised nl80211 supported features */
6661 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) {
6662 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6663#ifdef CONFIG_PM
Franky Lin6ea09152016-02-17 11:26:52 +01006664 if (wiphy->wowlan &&
6665 wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT)
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006666 wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6667#endif
6668 }
6669
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006670 return cfg;
6671
Arend van Sprielb48d8912014-07-12 08:49:41 +02006672wiphy_unreg_out:
6673 wiphy_unregister(cfg->wiphy);
6674priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006675 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006676 brcmf_free_vif(vif);
Hante Meuleman2b5d3482015-09-18 22:08:04 +02006677 ifp->vif = NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006678wiphy_out:
6679 brcmf_free_wiphy(wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006680 return NULL;
6681}
6682
6683void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
6684{
6685 if (!cfg)
6686 return;
6687
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006688 brcmf_btcoex_detach(cfg);
Arend van Sprielf7a40872015-06-11 00:12:23 +02006689 wiphy_unregister(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006690 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006691 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006692}