blob: d00c5c1d58bf1ce3c13c56cc22d40429be2d4daa [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 */
567 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
Arend van Spriel63ce3d52016-01-05 11:05:48 +0100568 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 +
1128 WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
1129
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 Meulemane756af52012-09-11 21:18:52 +02003023 if (bi_length > WL_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 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003036 memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
Hante Meulemane756af52012-09-11 21:18:52 +02003037 bss_info_le, bi_length);
3038 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
3095 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3096 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
3097 return 0;
3098 }
3099
3100 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3101 result_count = le32_to_cpu(pfn_result->count);
3102 status = le32_to_cpu(pfn_result->status);
3103
3104 /* PFN event is limited to fit 512 bytes so we may get
3105 * multiple NET_FOUND events. For now place a warning here.
3106 */
3107 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
3108 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
3109 if (result_count > 0) {
3110 int i;
3111
3112 request = kzalloc(sizeof(*request), GFP_KERNEL);
3113 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3114 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
3115 if (!request || !ssid || !channel) {
3116 err = -ENOMEM;
3117 goto out_err;
3118 }
3119
3120 request->wiphy = wiphy;
3121 data += sizeof(struct brcmf_pno_scanresults_le);
3122 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3123
3124 for (i = 0; i < result_count; i++) {
3125 netinfo = &netinfo_start[i];
3126 if (!netinfo) {
3127 brcmf_err("Invalid netinfo ptr. index: %d\n",
3128 i);
3129 err = -EINVAL;
3130 goto out_err;
3131 }
3132
3133 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3134 netinfo->SSID, netinfo->channel);
3135 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3136 ssid[i].ssid_len = netinfo->SSID_len;
3137 request->n_ssids++;
3138
3139 channel_req = netinfo->channel;
3140 if (channel_req <= CH_MAX_2G_CHANNEL)
3141 band = NL80211_BAND_2GHZ;
3142 else
3143 band = NL80211_BAND_5GHZ;
3144 channel[i].center_freq =
3145 ieee80211_channel_to_frequency(channel_req,
3146 band);
3147 channel[i].band = band;
3148 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3149 request->channels[i] = &channel[i];
3150 request->n_channels++;
3151 }
3152
3153 /* assign parsed ssid array */
3154 if (request->n_ssids)
3155 request->ssids = &ssid[0];
3156
3157 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3158 /* Abort any on-going scan */
3159 brcmf_abort_scanning(cfg);
3160 }
3161
3162 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3163 cfg->escan_info.run = brcmf_run_escan;
3164 err = brcmf_do_escan(cfg, wiphy, ifp, request);
3165 if (err) {
3166 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3167 goto out_err;
3168 }
3169 cfg->sched_escan = true;
3170 cfg->scan_request = request;
3171 } else {
3172 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3173 goto out_err;
3174 }
3175
3176 kfree(ssid);
3177 kfree(channel);
3178 kfree(request);
3179 return 0;
3180
3181out_err:
3182 kfree(ssid);
3183 kfree(channel);
3184 kfree(request);
3185 cfg80211_sched_scan_stopped(wiphy);
3186 return err;
3187}
3188
3189static int brcmf_dev_pno_clean(struct net_device *ndev)
3190{
3191 int ret;
3192
3193 /* Disable pfn */
3194 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
3195 if (ret == 0) {
3196 /* clear pfn */
3197 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3198 NULL, 0);
3199 }
3200 if (ret < 0)
3201 brcmf_err("failed code %d\n", ret);
3202
3203 return ret;
3204}
3205
3206static int brcmf_dev_pno_config(struct brcmf_if *ifp,
3207 struct cfg80211_sched_scan_request *request)
3208{
3209 struct brcmf_pno_param_le pfn_param;
3210 struct brcmf_pno_macaddr_le pfn_mac;
3211 s32 err;
3212 u8 *mac_mask;
3213 int i;
3214
3215 memset(&pfn_param, 0, sizeof(pfn_param));
3216 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3217
3218 /* set extra pno params */
3219 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3220 pfn_param.repeat = BRCMF_PNO_REPEAT;
3221 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3222
3223 /* set up pno scan fr */
3224 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3225
3226 err = brcmf_fil_iovar_data_set(ifp, "pfn_set", &pfn_param,
3227 sizeof(pfn_param));
3228 if (err) {
3229 brcmf_err("pfn_set failed, err=%d\n", err);
3230 return err;
3231 }
3232
3233 /* Find out if mac randomization should be turned on */
3234 if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR))
3235 return 0;
3236
3237 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
3238 pfn_mac.flags = BRCMF_PFN_MAC_OUI_ONLY | BRCMF_PFN_SET_MAC_UNASSOC;
3239
3240 memcpy(pfn_mac.mac, request->mac_addr, ETH_ALEN);
3241 mac_mask = request->mac_addr_mask;
3242 for (i = 0; i < ETH_ALEN; i++) {
3243 pfn_mac.mac[i] &= mac_mask[i];
3244 pfn_mac.mac[i] |= get_random_int() & ~(mac_mask[i]);
3245 }
3246 /* Clear multi bit */
3247 pfn_mac.mac[0] &= 0xFE;
3248 /* Set locally administered */
3249 pfn_mac.mac[0] |= 0x02;
3250
3251 err = brcmf_fil_iovar_data_set(ifp, "pfn_macaddr", &pfn_mac,
3252 sizeof(pfn_mac));
3253 if (err)
3254 brcmf_err("pfn_macaddr failed, err=%d\n", err);
3255
3256 return err;
3257}
3258
3259static int
3260brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3261 struct net_device *ndev,
3262 struct cfg80211_sched_scan_request *request)
3263{
3264 struct brcmf_if *ifp = netdev_priv(ndev);
3265 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
3266 struct brcmf_pno_net_param_le pfn;
3267 int i;
3268 int ret = 0;
3269
3270 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
3271 request->n_match_sets, request->n_ssids);
3272 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3273 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
3274 return -EAGAIN;
3275 }
3276 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3277 brcmf_err("Scanning suppressed: status (%lu)\n",
3278 cfg->scan_status);
3279 return -EAGAIN;
3280 }
3281
3282 if (!request->n_ssids || !request->n_match_sets) {
3283 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
3284 request->n_ssids);
3285 return -EINVAL;
3286 }
3287
3288 if (request->n_ssids > 0) {
3289 for (i = 0; i < request->n_ssids; i++) {
3290 /* Active scan req for ssids */
3291 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3292 request->ssids[i].ssid);
3293
3294 /* match_set ssids is a supert set of n_ssid list,
3295 * so we need not add these set separately.
3296 */
3297 }
3298 }
3299
3300 if (request->n_match_sets > 0) {
3301 /* clean up everything */
3302 ret = brcmf_dev_pno_clean(ndev);
3303 if (ret < 0) {
3304 brcmf_err("failed error=%d\n", ret);
3305 return ret;
3306 }
3307
3308 /* configure pno */
3309 if (brcmf_dev_pno_config(ifp, request))
3310 return -EINVAL;
3311
3312 /* configure each match set */
3313 for (i = 0; i < request->n_match_sets; i++) {
3314 struct cfg80211_ssid *ssid;
3315 u32 ssid_len;
3316
3317 ssid = &request->match_sets[i].ssid;
3318 ssid_len = ssid->ssid_len;
3319
3320 if (!ssid_len) {
3321 brcmf_err("skip broadcast ssid\n");
3322 continue;
3323 }
3324 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3325 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3326 pfn.wsec = cpu_to_le32(0);
3327 pfn.infra = cpu_to_le32(1);
3328 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3329 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3330 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
3331 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
3332 sizeof(pfn));
3333 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3334 ret == 0 ? "set" : "failed", ssid->ssid);
3335 }
3336 /* Enable the PNO */
3337 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
3338 brcmf_err("PNO enable failed!! ret=%d\n", ret);
3339 return -EINVAL;
3340 }
3341 } else {
3342 return -EINVAL;
3343 }
3344
3345 return 0;
3346}
3347
3348static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3349 struct net_device *ndev)
3350{
3351 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3352
3353 brcmf_dbg(SCAN, "enter\n");
3354 brcmf_dev_pno_clean(ndev);
3355 if (cfg->sched_escan)
3356 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
3357 return 0;
3358}
3359
Alexandre Oliva5addc0d2012-01-16 14:00:12 -05003360static __always_inline void brcmf_delay(u32 ms)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003361{
3362 if (ms < 1000 / HZ) {
3363 cond_resched();
3364 mdelay(ms);
3365 } else {
3366 msleep(ms);
3367 }
3368}
3369
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003370static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
3371 u8 *pattern, u32 patternsize, u8 *mask,
3372 u32 packet_offset)
3373{
3374 struct brcmf_fil_wowl_pattern_le *filter;
3375 u32 masksize;
3376 u32 patternoffset;
3377 u8 *buf;
3378 u32 bufsize;
3379 s32 ret;
3380
3381 masksize = (patternsize + 7) / 8;
3382 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
3383
3384 bufsize = sizeof(*filter) + patternsize + masksize;
3385 buf = kzalloc(bufsize, GFP_KERNEL);
3386 if (!buf)
3387 return -ENOMEM;
3388 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
3389
3390 memcpy(filter->cmd, cmd, 4);
3391 filter->masksize = cpu_to_le32(masksize);
3392 filter->offset = cpu_to_le32(packet_offset);
3393 filter->patternoffset = cpu_to_le32(patternoffset);
3394 filter->patternsize = cpu_to_le32(patternsize);
3395 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
3396
3397 if ((mask) && (masksize))
3398 memcpy(buf + sizeof(*filter), mask, masksize);
3399 if ((pattern) && (patternsize))
3400 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
3401
3402 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
3403
3404 kfree(buf);
3405 return ret;
3406}
3407
Hante Meuleman3021ad92016-01-05 11:05:45 +01003408static s32
3409brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
3410 void *data)
3411{
3412 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3413 struct brcmf_pno_scanresults_le *pfn_result;
3414 struct brcmf_pno_net_info_le *netinfo;
3415
3416 brcmf_dbg(SCAN, "Enter\n");
3417
3418 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3419
3420 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3421 brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n");
3422 return 0;
3423 }
3424
3425 if (le32_to_cpu(pfn_result->count) < 1) {
3426 brcmf_err("Invalid result count, expected 1 (%d)\n",
3427 le32_to_cpu(pfn_result->count));
3428 return -EINVAL;
3429 }
3430
3431 data += sizeof(struct brcmf_pno_scanresults_le);
3432 netinfo = (struct brcmf_pno_net_info_le *)data;
3433 memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
3434 cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
3435 cfg->wowl.nd->n_channels = 1;
3436 cfg->wowl.nd->channels[0] =
3437 ieee80211_channel_to_frequency(netinfo->channel,
3438 netinfo->channel <= CH_MAX_2G_CHANNEL ?
3439 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
3440 cfg->wowl.nd_info->n_matches = 1;
3441 cfg->wowl.nd_info->matches[0] = cfg->wowl.nd;
3442
3443 /* Inform (the resume task) that the net detect information was recvd */
3444 cfg->wowl.nd_data_completed = true;
3445 wake_up(&cfg->wowl.nd_data_wait);
3446
3447 return 0;
3448}
3449
Hante Meulemanaeb64222015-10-29 20:33:19 +01003450#ifdef CONFIG_PM
3451
3452static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3453{
Hante Meuleman3021ad92016-01-05 11:05:45 +01003454 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meulemanaeb64222015-10-29 20:33:19 +01003455 struct brcmf_wowl_wakeind_le wake_ind_le;
3456 struct cfg80211_wowlan_wakeup wakeup_data;
3457 struct cfg80211_wowlan_wakeup *wakeup;
3458 u32 wakeind;
3459 s32 err;
Hante Meuleman3021ad92016-01-05 11:05:45 +01003460 int timeout;
Hante Meulemanaeb64222015-10-29 20:33:19 +01003461
3462 err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
3463 sizeof(wake_ind_le));
Hante Meuleman3021ad92016-01-05 11:05:45 +01003464 if (err) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003465 brcmf_err("Get wowl_wakeind failed, err = %d\n", err);
3466 return;
3467 }
3468
3469 wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
3470 if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
Hante Meuleman3021ad92016-01-05 11:05:45 +01003471 BRCMF_WOWL_RETR | BRCMF_WOWL_NET |
3472 BRCMF_WOWL_PFN_FOUND)) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003473 wakeup = &wakeup_data;
3474 memset(&wakeup_data, 0, sizeof(wakeup_data));
3475 wakeup_data.pattern_idx = -1;
3476
3477 if (wakeind & BRCMF_WOWL_MAGIC) {
3478 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
3479 wakeup_data.magic_pkt = true;
3480 }
3481 if (wakeind & BRCMF_WOWL_DIS) {
3482 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
3483 wakeup_data.disconnect = true;
3484 }
3485 if (wakeind & BRCMF_WOWL_BCN) {
3486 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
3487 wakeup_data.disconnect = true;
3488 }
3489 if (wakeind & BRCMF_WOWL_RETR) {
3490 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
3491 wakeup_data.disconnect = true;
3492 }
3493 if (wakeind & BRCMF_WOWL_NET) {
3494 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
3495 /* For now always map to pattern 0, no API to get
3496 * correct information available at the moment.
3497 */
3498 wakeup_data.pattern_idx = 0;
3499 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003500 if (wakeind & BRCMF_WOWL_PFN_FOUND) {
3501 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n");
3502 timeout = wait_event_timeout(cfg->wowl.nd_data_wait,
3503 cfg->wowl.nd_data_completed,
3504 BRCMF_ND_INFO_TIMEOUT);
3505 if (!timeout)
3506 brcmf_err("No result for wowl net detect\n");
3507 else
3508 wakeup_data.net_detect = cfg->wowl.nd_info;
3509 }
Hante Meulemanaeb64222015-10-29 20:33:19 +01003510 } else {
3511 wakeup = NULL;
3512 }
3513 cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
3514}
3515
3516#else
3517
3518static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
3519{
3520}
3521
3522#endif /* CONFIG_PM */
3523
Arend van Spriel5b435de2011-10-05 13:19:03 +02003524static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
3525{
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003526 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3527 struct net_device *ndev = cfg_to_ndev(cfg);
3528 struct brcmf_if *ifp = netdev_priv(ndev);
3529
Arend van Sprield96b8012012-12-05 15:26:02 +01003530 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003531
Hante Meuleman3021ad92016-01-05 11:05:45 +01003532 if (cfg->wowl.active) {
Hante Meulemanaeb64222015-10-29 20:33:19 +01003533 brcmf_report_wowl_wakeind(wiphy, ifp);
3534 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
3535 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003536 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003537 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
Hante Meuleman3021ad92016-01-05 11:05:45 +01003538 cfg->wowl.pre_pmmode);
3539 cfg->wowl.active = false;
3540 if (cfg->wowl.nd_enabled) {
3541 brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev);
3542 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3543 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3544 brcmf_notify_sched_scan_results);
3545 cfg->wowl.nd_enabled = false;
3546 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003547 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003548 return 0;
3549}
3550
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003551static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
3552 struct brcmf_if *ifp,
3553 struct cfg80211_wowlan *wowl)
3554{
3555 u32 wowl_config;
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003556 u32 i;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003557
3558 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
3559
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003560 brcmf_configure_arp_offload(ifp, false);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003561 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003562 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
3563
3564 wowl_config = 0;
3565 if (wowl->disconnect)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003566 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003567 if (wowl->magic_pkt)
Hante Meulemanb9a82f82014-10-28 14:56:06 +01003568 wowl_config |= BRCMF_WOWL_MAGIC;
3569 if ((wowl->patterns) && (wowl->n_patterns)) {
3570 wowl_config |= BRCMF_WOWL_NET;
3571 for (i = 0; i < wowl->n_patterns; i++) {
3572 brcmf_config_wowl_pattern(ifp, "add",
3573 (u8 *)wowl->patterns[i].pattern,
3574 wowl->patterns[i].pattern_len,
3575 (u8 *)wowl->patterns[i].mask,
3576 wowl->patterns[i].pkt_offset);
3577 }
3578 }
Hante Meuleman3021ad92016-01-05 11:05:45 +01003579 if (wowl->nd_config) {
3580 brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev,
3581 wowl->nd_config);
3582 wowl_config |= BRCMF_WOWL_PFN_FOUND;
3583
3584 cfg->wowl.nd_data_completed = false;
3585 cfg->wowl.nd_enabled = true;
3586 /* Now reroute the event for PFN to the wowl function. */
3587 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
3588 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
3589 brcmf_wowl_nd_results);
3590 }
3591 if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
3592 wowl_config |= BRCMF_WOWL_UNASSOC;
3593
Hante Meulemanaeb64222015-10-29 20:33:19 +01003594 brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", "clear", strlen("clear"));
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003595 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
3596 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
3597 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
Hante Meuleman3021ad92016-01-05 11:05:45 +01003598 cfg->wowl.active = true;
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003599}
3600
Arend van Spriel5b435de2011-10-05 13:19:03 +02003601static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003602 struct cfg80211_wowlan *wowl)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003603{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003604 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3605 struct net_device *ndev = cfg_to_ndev(cfg);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003606 struct brcmf_if *ifp = netdev_priv(ndev);
Arend van Spriel7d641072012-10-22 13:55:39 -07003607 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003608
Arend van Sprield96b8012012-12-05 15:26:02 +01003609 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003610
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003611 /* if the primary net_device is not READY there is nothing
Arend van Spriel7d641072012-10-22 13:55:39 -07003612 * we can do but pray resume goes smoothly.
Arend van Spriel5b435de2011-10-05 13:19:03 +02003613 */
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003614 if (!check_vif_up(ifp->vif))
Arend van Spriel7d641072012-10-22 13:55:39 -07003615 goto exit;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003616
Hante Meuleman3021ad92016-01-05 11:05:45 +01003617 /* Stop scheduled scan */
3618 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
3619 brcmf_cfg80211_sched_scan_stop(wiphy, ndev);
3620
Arend van Spriel7d641072012-10-22 13:55:39 -07003621 /* end any scanning */
3622 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003623 brcmf_abort_scanning(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003624
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003625 if (wowl == NULL) {
3626 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
3627 list_for_each_entry(vif, &cfg->vif_list, list) {
3628 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
3629 continue;
3630 /* While going to suspend if associated with AP
3631 * disassociate from AP to save power while system is
3632 * in suspended state
3633 */
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01003634 brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
Hante Meuleman4eb3af72014-09-30 10:23:18 +02003635 /* Make sure WPA_Supplicant receives all the event
3636 * generated due to DISASSOC call to the fw to keep
3637 * the state fw and WPA_Supplicant state consistent
3638 */
3639 brcmf_delay(500);
3640 }
3641 /* Configure MPC */
3642 brcmf_set_mpc(ifp, 1);
3643
3644 } else {
3645 /* Configure WOWL paramaters */
3646 brcmf_configure_wowl(cfg, ifp, wowl);
3647 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003648
Arend van Spriel7d641072012-10-22 13:55:39 -07003649exit:
Arend van Sprield96b8012012-12-05 15:26:02 +01003650 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel7d641072012-10-22 13:55:39 -07003651 /* clear any scanning activity */
3652 cfg->scan_status = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003653 return 0;
3654}
3655
3656static __used s32
Hante Meuleman6c404f32015-12-10 13:43:03 +01003657brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003658{
Hante Meuleman6c404f32015-12-10 13:43:03 +01003659 struct brcmf_pmk_list_le *pmk_list;
3660 int i;
3661 u32 npmk;
3662 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003663
Hante Meuleman6c404f32015-12-10 13:43:03 +01003664 pmk_list = &cfg->pmk_list;
3665 npmk = le32_to_cpu(pmk_list->npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003666
Hante Meuleman6c404f32015-12-10 13:43:03 +01003667 brcmf_dbg(CONN, "No of elements %d\n", npmk);
3668 for (i = 0; i < npmk; i++)
3669 brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003670
Hante Meuleman6c404f32015-12-10 13:43:03 +01003671 err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list,
3672 sizeof(*pmk_list));
Arend van Spriel5b435de2011-10-05 13:19:03 +02003673
3674 return err;
3675}
3676
3677static s32
3678brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
3679 struct cfg80211_pmksa *pmksa)
3680{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003681 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003682 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003683 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3684 s32 err;
3685 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003686
Arend van Sprield96b8012012-12-05 15:26:02 +01003687 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003688 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003689 return -EIO;
3690
Hante Meuleman6c404f32015-12-10 13:43:03 +01003691 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3692 for (i = 0; i < npmk; i++)
3693 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003694 break;
Hante Meuleman6c404f32015-12-10 13:43:03 +01003695 if (i < BRCMF_MAXPMKID) {
3696 memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN);
3697 memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
3698 if (i == npmk) {
3699 npmk++;
3700 cfg->pmk_list.npmk = cpu_to_le32(npmk);
Arend van Spriel40c8e952011-10-12 20:51:20 +02003701 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003702 } else {
3703 brcmf_err("Too many PMKSA entries cached %d\n", npmk);
3704 return -EINVAL;
3705 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003706
Hante Meuleman6c404f32015-12-10 13:43:03 +01003707 brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid);
3708 for (i = 0; i < WLAN_PMKID_LEN; i += 4)
3709 brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i],
3710 pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2],
3711 pmk[npmk].pmkid[i + 3]);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003712
Hante Meuleman6c404f32015-12-10 13:43:03 +01003713 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003714
Arend van Sprield96b8012012-12-05 15:26:02 +01003715 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003716 return err;
3717}
3718
3719static s32
3720brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
Hante Meuleman6c404f32015-12-10 13:43:03 +01003721 struct cfg80211_pmksa *pmksa)
Arend van Spriel5b435de2011-10-05 13:19:03 +02003722{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003723 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003724 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003725 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
3726 s32 err;
3727 u32 npmk, i;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003728
Arend van Sprield96b8012012-12-05 15:26:02 +01003729 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003730 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003731 return -EIO;
3732
Hante Meuleman6c404f32015-12-10 13:43:03 +01003733 brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", &pmksa->bssid);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003734
Hante Meuleman6c404f32015-12-10 13:43:03 +01003735 npmk = le32_to_cpu(cfg->pmk_list.npmk);
3736 for (i = 0; i < npmk; i++)
3737 if (!memcmp(&pmksa->bssid, &pmk[i].bssid, ETH_ALEN))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003738 break;
3739
Hante Meuleman6c404f32015-12-10 13:43:03 +01003740 if ((npmk > 0) && (i < npmk)) {
3741 for (; i < (npmk - 1); i++) {
3742 memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN);
3743 memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02003744 WLAN_PMKID_LEN);
3745 }
Hante Meuleman6c404f32015-12-10 13:43:03 +01003746 memset(&pmk[i], 0, sizeof(*pmk));
3747 cfg->pmk_list.npmk = cpu_to_le32(npmk - 1);
3748 } else {
3749 brcmf_err("Cache entry not found\n");
3750 return -EINVAL;
3751 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02003752
Hante Meuleman6c404f32015-12-10 13:43:03 +01003753 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003754
Arend van Sprield96b8012012-12-05 15:26:02 +01003755 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003756 return err;
3757
3758}
3759
3760static s32
3761brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
3762{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02003763 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07003764 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman6c404f32015-12-10 13:43:03 +01003765 s32 err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02003766
Arend van Sprield96b8012012-12-05 15:26:02 +01003767 brcmf_dbg(TRACE, "Enter\n");
Arend van Sprielce81e312012-10-22 13:55:37 -07003768 if (!check_vif_up(ifp->vif))
Arend van Spriel5b435de2011-10-05 13:19:03 +02003769 return -EIO;
3770
Hante Meuleman6c404f32015-12-10 13:43:03 +01003771 memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list));
3772 err = brcmf_update_pmklist(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02003773
Arend van Sprield96b8012012-12-05 15:26:02 +01003774 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02003775 return err;
3776
3777}
3778
Hante Meuleman1f170112013-02-06 18:40:38 +01003779static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
Hante Meuleman1a873342012-09-27 14:17:54 +02003780{
3781 s32 err;
3782
3783 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003784 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003785 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003786 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003787 return err;
3788 }
3789 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003790 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
Hante Meuleman1a873342012-09-27 14:17:54 +02003791 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003792 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003793 return err;
3794 }
3795 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003796 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
Hante Meuleman1a873342012-09-27 14:17:54 +02003797 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003798 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003799 return err;
3800 }
3801
3802 return 0;
3803}
3804
3805static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3806{
3807 if (is_rsn_ie)
3808 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3809
3810 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3811}
3812
3813static s32
Hante Meulemana44aa402014-12-03 21:05:33 +01003814brcmf_configure_wpaie(struct brcmf_if *ifp,
Johannes Berg4b5800f2014-01-15 14:55:59 +01003815 const struct brcmf_vs_tlv *wpa_ie,
3816 bool is_rsn_ie)
Hante Meuleman1a873342012-09-27 14:17:54 +02003817{
3818 u32 auth = 0; /* d11 open authentication */
3819 u16 count;
3820 s32 err = 0;
3821 s32 len = 0;
3822 u32 i;
3823 u32 wsec;
3824 u32 pval = 0;
3825 u32 gval = 0;
3826 u32 wpa_auth = 0;
3827 u32 offset;
3828 u8 *data;
3829 u16 rsn_cap;
3830 u32 wme_bss_disable;
3831
Arend van Sprield96b8012012-12-05 15:26:02 +01003832 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003833 if (wpa_ie == NULL)
3834 goto exit;
3835
3836 len = wpa_ie->len + TLV_HDR_LEN;
3837 data = (u8 *)wpa_ie;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003838 offset = TLV_HDR_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003839 if (!is_rsn_ie)
3840 offset += VS_IE_FIXED_HDR_LEN;
Hante Meuleman619c5a92013-01-02 15:12:39 +01003841 else
3842 offset += WPA_IE_VERSION_LEN;
Hante Meuleman1a873342012-09-27 14:17:54 +02003843
3844 /* check for multicast cipher suite */
3845 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3846 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003847 brcmf_err("no multicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003848 goto exit;
3849 }
3850
3851 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3852 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003853 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003854 goto exit;
3855 }
3856 offset += TLV_OUI_LEN;
3857
3858 /* pick up multicast cipher */
3859 switch (data[offset]) {
3860 case WPA_CIPHER_NONE:
3861 gval = 0;
3862 break;
3863 case WPA_CIPHER_WEP_40:
3864 case WPA_CIPHER_WEP_104:
3865 gval = WEP_ENABLED;
3866 break;
3867 case WPA_CIPHER_TKIP:
3868 gval = TKIP_ENABLED;
3869 break;
3870 case WPA_CIPHER_AES_CCM:
3871 gval = AES_ENABLED;
3872 break;
3873 default:
3874 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003875 brcmf_err("Invalid multi cast cipher info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003876 goto exit;
3877 }
3878
3879 offset++;
3880 /* walk thru unicast cipher list and pick up what we recognize */
3881 count = data[offset] + (data[offset + 1] << 8);
3882 offset += WPA_IE_SUITE_COUNT_LEN;
3883 /* Check for unicast suite(s) */
3884 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3885 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003886 brcmf_err("no unicast cipher suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003887 goto exit;
3888 }
3889 for (i = 0; i < count; i++) {
3890 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3891 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003892 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003893 goto exit;
3894 }
3895 offset += TLV_OUI_LEN;
3896 switch (data[offset]) {
3897 case WPA_CIPHER_NONE:
3898 break;
3899 case WPA_CIPHER_WEP_40:
3900 case WPA_CIPHER_WEP_104:
3901 pval |= WEP_ENABLED;
3902 break;
3903 case WPA_CIPHER_TKIP:
3904 pval |= TKIP_ENABLED;
3905 break;
3906 case WPA_CIPHER_AES_CCM:
3907 pval |= AES_ENABLED;
3908 break;
3909 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003910 brcmf_err("Ivalid unicast security info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003911 }
3912 offset++;
3913 }
3914 /* walk thru auth management suite list and pick up what we recognize */
3915 count = data[offset] + (data[offset + 1] << 8);
3916 offset += WPA_IE_SUITE_COUNT_LEN;
3917 /* Check for auth key management suite(s) */
3918 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3919 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003920 brcmf_err("no auth key mgmt suite\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003921 goto exit;
3922 }
3923 for (i = 0; i < count; i++) {
3924 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3925 err = -EINVAL;
Arend van Spriel57d6e912012-12-05 15:26:00 +01003926 brcmf_err("ivalid OUI\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003927 goto exit;
3928 }
3929 offset += TLV_OUI_LEN;
3930 switch (data[offset]) {
3931 case RSN_AKM_NONE:
Arend van Sprield96b8012012-12-05 15:26:02 +01003932 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003933 wpa_auth |= WPA_AUTH_NONE;
3934 break;
3935 case RSN_AKM_UNSPECIFIED:
Arend van Sprield96b8012012-12-05 15:26:02 +01003936 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003937 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3938 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3939 break;
3940 case RSN_AKM_PSK:
Arend van Sprield96b8012012-12-05 15:26:02 +01003941 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003942 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3943 (wpa_auth |= WPA_AUTH_PSK);
3944 break;
3945 default:
Arend van Spriel57d6e912012-12-05 15:26:00 +01003946 brcmf_err("Ivalid key mgmt info\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02003947 }
3948 offset++;
3949 }
3950
3951 if (is_rsn_ie) {
3952 wme_bss_disable = 1;
3953 if ((offset + RSN_CAP_LEN) <= len) {
3954 rsn_cap = data[offset] + (data[offset + 1] << 8);
3955 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3956 wme_bss_disable = 0;
3957 }
3958 /* set wme_bss_disable to sync RSN Capabilities */
Arend van Sprielac24be62012-10-22 10:36:23 -07003959 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07003960 wme_bss_disable);
Hante Meuleman1a873342012-09-27 14:17:54 +02003961 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003962 brcmf_err("wme_bss_disable error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003963 goto exit;
3964 }
3965 }
3966 /* FOR WPS , set SES_OW_ENABLED */
3967 wsec = (pval | gval | SES_OW_ENABLED);
3968
3969 /* set auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003970 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003971 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003972 brcmf_err("auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003973 goto exit;
3974 }
3975 /* set wsec */
Arend van Sprielac24be62012-10-22 10:36:23 -07003976 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
Hante Meuleman1a873342012-09-27 14:17:54 +02003977 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003978 brcmf_err("wsec error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003979 goto exit;
3980 }
3981 /* set upper-layer auth */
Arend van Sprielac24be62012-10-22 10:36:23 -07003982 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
Hante Meuleman1a873342012-09-27 14:17:54 +02003983 if (err < 0) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01003984 brcmf_err("wpa_auth error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02003985 goto exit;
3986 }
3987
3988exit:
3989 return err;
3990}
3991
3992static s32
Arend van Spriel3082b9b2012-11-05 16:22:12 -08003993brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
Hante Meuleman1a873342012-09-27 14:17:54 +02003994 struct parsed_vndr_ies *vndr_ies)
3995{
Hante Meuleman1a873342012-09-27 14:17:54 +02003996 struct brcmf_vs_tlv *vndrie;
3997 struct brcmf_tlv *ie;
3998 struct parsed_vndr_ie_info *parsed_info;
3999 s32 remaining_len;
4000
4001 remaining_len = (s32)vndr_ie_len;
4002 memset(vndr_ies, 0, sizeof(*vndr_ies));
4003
4004 ie = (struct brcmf_tlv *)vndr_ie_buf;
4005 while (ie) {
4006 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
4007 goto next;
4008 vndrie = (struct brcmf_vs_tlv *)ie;
4009 /* len should be bigger than OUI length + one */
4010 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004011 brcmf_err("invalid vndr ie. length is too small %d\n",
4012 vndrie->len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004013 goto next;
4014 }
4015 /* if wpa or wme ie, do not add ie */
4016 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
4017 ((vndrie->oui_type == WPA_OUI_TYPE) ||
4018 (vndrie->oui_type == WME_OUI_TYPE))) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004019 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004020 goto next;
4021 }
4022
4023 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
4024
4025 /* save vndr ie information */
4026 parsed_info->ie_ptr = (char *)vndrie;
4027 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
4028 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
4029
4030 vndr_ies->count++;
4031
Arend van Sprield96b8012012-12-05 15:26:02 +01004032 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
4033 parsed_info->vndrie.oui[0],
4034 parsed_info->vndrie.oui[1],
4035 parsed_info->vndrie.oui[2],
4036 parsed_info->vndrie.oui_type);
Hante Meuleman1a873342012-09-27 14:17:54 +02004037
Arend van Spriel9f440b72013-02-08 15:53:36 +01004038 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
Hante Meuleman1a873342012-09-27 14:17:54 +02004039 break;
4040next:
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004041 remaining_len -= (ie->len + TLV_HDR_LEN);
4042 if (remaining_len <= TLV_HDR_LEN)
Hante Meuleman1a873342012-09-27 14:17:54 +02004043 ie = NULL;
4044 else
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004045 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
4046 TLV_HDR_LEN);
Hante Meuleman1a873342012-09-27 14:17:54 +02004047 }
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03004048 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02004049}
4050
4051static u32
4052brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
4053{
4054
Hante Meuleman1a873342012-09-27 14:17:54 +02004055 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
4056 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
4057
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304058 put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004059
Vaishali Thakkar362126c2015-01-16 21:36:14 +05304060 put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004061
4062 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
4063
4064 return ie_len + VNDR_IE_HDR_SIZE;
4065}
4066
Arend van Spriel1332e262012-11-05 16:22:18 -08004067s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
4068 const u8 *vndr_ie_buf, u32 vndr_ie_len)
Hante Meuleman1a873342012-09-27 14:17:54 +02004069{
Arend van Spriel1332e262012-11-05 16:22:18 -08004070 struct brcmf_if *ifp;
4071 struct vif_saved_ie *saved_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004072 s32 err = 0;
4073 u8 *iovar_ie_buf;
4074 u8 *curr_ie_buf;
4075 u8 *mgmt_ie_buf = NULL;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004076 int mgmt_ie_buf_len;
Dan Carpenter81118d12012-10-10 11:13:07 -07004077 u32 *mgmt_ie_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004078 u32 del_add_ie_buf_len = 0;
4079 u32 total_ie_buf_len = 0;
4080 u32 parsed_ie_buf_len = 0;
4081 struct parsed_vndr_ies old_vndr_ies;
4082 struct parsed_vndr_ies new_vndr_ies;
4083 struct parsed_vndr_ie_info *vndrie_info;
4084 s32 i;
4085 u8 *ptr;
Dan Carpenter3e4f3192012-10-10 11:13:12 -07004086 int remained_buf_len;
Hante Meuleman1a873342012-09-27 14:17:54 +02004087
Arend van Spriel1332e262012-11-05 16:22:18 -08004088 if (!vif)
4089 return -ENODEV;
4090 ifp = vif->ifp;
4091 saved_ie = &vif->saved_ie;
4092
Hante Meuleman37a869e2015-10-29 20:33:17 +01004093 brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
4094 pktflag);
Hante Meuleman1a873342012-09-27 14:17:54 +02004095 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4096 if (!iovar_ie_buf)
4097 return -ENOMEM;
4098 curr_ie_buf = iovar_ie_buf;
Hante Meuleman89286dc2013-02-08 15:53:46 +01004099 switch (pktflag) {
4100 case BRCMF_VNDR_IE_PRBREQ_FLAG:
4101 mgmt_ie_buf = saved_ie->probe_req_ie;
4102 mgmt_ie_len = &saved_ie->probe_req_ie_len;
4103 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
4104 break;
4105 case BRCMF_VNDR_IE_PRBRSP_FLAG:
4106 mgmt_ie_buf = saved_ie->probe_res_ie;
4107 mgmt_ie_len = &saved_ie->probe_res_ie_len;
4108 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
4109 break;
4110 case BRCMF_VNDR_IE_BEACON_FLAG:
4111 mgmt_ie_buf = saved_ie->beacon_ie;
4112 mgmt_ie_len = &saved_ie->beacon_ie_len;
4113 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
4114 break;
4115 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
4116 mgmt_ie_buf = saved_ie->assoc_req_ie;
4117 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
4118 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
4119 break;
4120 default:
4121 err = -EPERM;
4122 brcmf_err("not suitable type\n");
4123 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004124 }
4125
4126 if (vndr_ie_len > mgmt_ie_buf_len) {
4127 err = -ENOMEM;
Arend van Spriel57d6e912012-12-05 15:26:00 +01004128 brcmf_err("extra IE size too big\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004129 goto exit;
4130 }
4131
4132 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
4133 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
4134 ptr = curr_ie_buf;
4135 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
4136 for (i = 0; i < new_vndr_ies.count; i++) {
4137 vndrie_info = &new_vndr_ies.ie_info[i];
4138 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
4139 vndrie_info->ie_len);
4140 parsed_ie_buf_len += vndrie_info->ie_len;
4141 }
4142 }
4143
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004144 if (mgmt_ie_buf && *mgmt_ie_len) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004145 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
4146 (memcmp(mgmt_ie_buf, curr_ie_buf,
4147 parsed_ie_buf_len) == 0)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004148 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004149 goto exit;
4150 }
4151
4152 /* parse old vndr_ie */
4153 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
4154
4155 /* make a command to delete old ie */
4156 for (i = 0; i < old_vndr_ies.count; i++) {
4157 vndrie_info = &old_vndr_ies.ie_info[i];
4158
Arend van Sprield96b8012012-12-05 15:26:02 +01004159 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
4160 vndrie_info->vndrie.id,
4161 vndrie_info->vndrie.len,
4162 vndrie_info->vndrie.oui[0],
4163 vndrie_info->vndrie.oui[1],
4164 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004165
4166 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4167 vndrie_info->ie_ptr,
4168 vndrie_info->ie_len,
4169 "del");
4170 curr_ie_buf += del_add_ie_buf_len;
4171 total_ie_buf_len += del_add_ie_buf_len;
4172 }
4173 }
4174
4175 *mgmt_ie_len = 0;
4176 /* Add if there is any extra IE */
4177 if (mgmt_ie_buf && parsed_ie_buf_len) {
4178 ptr = mgmt_ie_buf;
4179
4180 remained_buf_len = mgmt_ie_buf_len;
4181
4182 /* make a command to add new ie */
4183 for (i = 0; i < new_vndr_ies.count; i++) {
4184 vndrie_info = &new_vndr_ies.ie_info[i];
4185
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004186 /* verify remained buf size before copy data */
4187 if (remained_buf_len < (vndrie_info->vndrie.len +
4188 VNDR_IE_VSIE_OFFSET)) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01004189 brcmf_err("no space in mgmt_ie_buf: len left %d",
4190 remained_buf_len);
Hante Meulemanb41fc3d2012-11-28 21:44:13 +01004191 break;
4192 }
4193 remained_buf_len -= (vndrie_info->ie_len +
4194 VNDR_IE_VSIE_OFFSET);
4195
Arend van Sprield96b8012012-12-05 15:26:02 +01004196 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
4197 vndrie_info->vndrie.id,
4198 vndrie_info->vndrie.len,
4199 vndrie_info->vndrie.oui[0],
4200 vndrie_info->vndrie.oui[1],
4201 vndrie_info->vndrie.oui[2]);
Hante Meuleman1a873342012-09-27 14:17:54 +02004202
4203 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4204 vndrie_info->ie_ptr,
4205 vndrie_info->ie_len,
4206 "add");
Hante Meuleman1a873342012-09-27 14:17:54 +02004207
4208 /* save the parsed IE in wl struct */
4209 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
4210 vndrie_info->ie_len);
4211 *mgmt_ie_len += vndrie_info->ie_len;
4212
4213 curr_ie_buf += del_add_ie_buf_len;
4214 total_ie_buf_len += del_add_ie_buf_len;
4215 }
4216 }
4217 if (total_ie_buf_len) {
Arend van Sprielc1179032012-10-22 13:55:33 -07004218 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004219 total_ie_buf_len);
Hante Meuleman1a873342012-09-27 14:17:54 +02004220 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004221 brcmf_err("vndr ie set error : %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004222 }
4223
4224exit:
4225 kfree(iovar_ie_buf);
4226 return err;
4227}
4228
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01004229s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
4230{
4231 s32 pktflags[] = {
4232 BRCMF_VNDR_IE_PRBREQ_FLAG,
4233 BRCMF_VNDR_IE_PRBRSP_FLAG,
4234 BRCMF_VNDR_IE_BEACON_FLAG
4235 };
4236 int i;
4237
4238 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
4239 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
4240
4241 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
4242 return 0;
4243}
4244
Hante Meuleman1a873342012-09-27 14:17:54 +02004245static s32
Hante Meulemana0f07952013-02-08 15:53:47 +01004246brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
4247 struct cfg80211_beacon_data *beacon)
4248{
4249 s32 err;
4250
4251 /* Set Beacon IEs to FW */
4252 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
4253 beacon->tail, beacon->tail_len);
4254 if (err) {
4255 brcmf_err("Set Beacon IE Failed\n");
4256 return err;
4257 }
4258 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
4259
4260 /* Set Probe Response IEs to FW */
4261 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
4262 beacon->proberesp_ies,
4263 beacon->proberesp_ies_len);
4264 if (err)
4265 brcmf_err("Set Probe Resp IE Failed\n");
4266 else
4267 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
4268
4269 return err;
4270}
4271
4272static s32
Hante Meuleman1a873342012-09-27 14:17:54 +02004273brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
4274 struct cfg80211_ap_settings *settings)
4275{
4276 s32 ie_offset;
Hante Meuleman1c9d30c2013-05-27 21:09:58 +02004277 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07004278 struct brcmf_if *ifp = netdev_priv(ndev);
Johannes Berg4b5800f2014-01-15 14:55:59 +01004279 const struct brcmf_tlv *ssid_ie;
Arend van Spriel98027762014-12-21 12:43:53 +01004280 const struct brcmf_tlv *country_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004281 struct brcmf_ssid_le ssid_le;
Hante Meuleman1a873342012-09-27 14:17:54 +02004282 s32 err = -EPERM;
Johannes Berg4b5800f2014-01-15 14:55:59 +01004283 const struct brcmf_tlv *rsn_ie;
4284 const struct brcmf_vs_tlv *wpa_ie;
Hante Meuleman1a873342012-09-27 14:17:54 +02004285 struct brcmf_join_params join_params;
Hante Meulemana0f07952013-02-08 15:53:47 +01004286 enum nl80211_iftype dev_role;
4287 struct brcmf_fil_bss_enable_le bss_enable;
Arend van Spriel06c01582014-05-12 10:47:37 +02004288 u16 chanspec;
Hante Meulemana44aa402014-12-03 21:05:33 +01004289 bool mbss;
Arend van Spriel98027762014-12-21 12:43:53 +01004290 int is_11d;
Hante Meuleman1a873342012-09-27 14:17:54 +02004291
Arend van Spriel06c01582014-05-12 10:47:37 +02004292 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
4293 settings->chandef.chan->hw_value,
4294 settings->chandef.center_freq1, settings->chandef.width,
Arend van Spriela9a56872014-05-12 10:47:33 +02004295 settings->beacon_interval, settings->dtim_period);
Arend van Sprield96b8012012-12-05 15:26:02 +01004296 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
4297 settings->ssid, settings->ssid_len, settings->auth_type,
4298 settings->inactivity_timeout);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004299 dev_role = ifp->vif->wdev.iftype;
Hante Meulemana44aa402014-12-03 21:05:33 +01004300 mbss = ifp->vif->mbss;
Hante Meuleman1a873342012-09-27 14:17:54 +02004301
Arend van Spriel98027762014-12-21 12:43:53 +01004302 /* store current 11d setting */
4303 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d);
4304 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4305 settings->beacon.tail_len,
4306 WLAN_EID_COUNTRY);
4307 is_11d = country_ie ? 1 : 0;
4308
Hante Meuleman1a873342012-09-27 14:17:54 +02004309 memset(&ssid_le, 0, sizeof(ssid_le));
4310 if (settings->ssid == NULL || settings->ssid_len == 0) {
4311 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
4312 ssid_ie = brcmf_parse_tlvs(
4313 (u8 *)&settings->beacon.head[ie_offset],
4314 settings->beacon.head_len - ie_offset,
4315 WLAN_EID_SSID);
4316 if (!ssid_ie)
4317 return -EINVAL;
4318
4319 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
4320 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
Arend van Sprield96b8012012-12-05 15:26:02 +01004321 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
Hante Meuleman1a873342012-09-27 14:17:54 +02004322 } else {
4323 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
4324 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
4325 }
4326
Hante Meulemana44aa402014-12-03 21:05:33 +01004327 if (!mbss) {
4328 brcmf_set_mpc(ifp, 0);
4329 brcmf_configure_arp_offload(ifp, false);
4330 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004331
4332 /* find the RSN_IE */
4333 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4334 settings->beacon.tail_len, WLAN_EID_RSN);
4335
4336 /* find the WPA_IE */
4337 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
4338 settings->beacon.tail_len);
4339
Hante Meuleman1a873342012-09-27 14:17:54 +02004340 if ((wpa_ie != NULL || rsn_ie != NULL)) {
Arend van Sprield96b8012012-12-05 15:26:02 +01004341 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004342 if (wpa_ie != NULL) {
4343 /* WPA IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004344 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
Hante Meuleman1a873342012-09-27 14:17:54 +02004345 if (err < 0)
4346 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004347 } else {
Hante Meulemana44aa402014-12-03 21:05:33 +01004348 struct brcmf_vs_tlv *tmp_ie;
4349
4350 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
4351
Hante Meuleman1a873342012-09-27 14:17:54 +02004352 /* RSN IE */
Hante Meulemana44aa402014-12-03 21:05:33 +01004353 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004354 if (err < 0)
4355 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004356 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004357 } else {
Arend van Sprield96b8012012-12-05 15:26:02 +01004358 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
Hante Meuleman1f170112013-02-06 18:40:38 +01004359 brcmf_configure_opensecurity(ifp);
Hante Meuleman1a873342012-09-27 14:17:54 +02004360 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004361
Hante Meulemana0f07952013-02-08 15:53:47 +01004362 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
Hante Meuleman1a873342012-09-27 14:17:54 +02004363
Hante Meulemana44aa402014-12-03 21:05:33 +01004364 if (!mbss) {
4365 chanspec = chandef_to_chanspec(&cfg->d11inf,
4366 &settings->chandef);
4367 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
Hante Meuleman1a873342012-09-27 14:17:54 +02004368 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004369 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4370 chanspec, err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004371 goto exit;
4372 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004373
Arend van Spriel98027762014-12-21 12:43:53 +01004374 if (is_11d != ifp->vif->is_11d) {
4375 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4376 is_11d);
4377 if (err < 0) {
4378 brcmf_err("Regulatory Set Error, %d\n", err);
4379 goto exit;
4380 }
4381 }
Hante Meulemana44aa402014-12-03 21:05:33 +01004382 if (settings->beacon_interval) {
4383 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
4384 settings->beacon_interval);
4385 if (err < 0) {
4386 brcmf_err("Beacon Interval Set Error, %d\n",
4387 err);
4388 goto exit;
4389 }
4390 }
4391 if (settings->dtim_period) {
4392 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
4393 settings->dtim_period);
4394 if (err < 0) {
4395 brcmf_err("DTIM Interval Set Error, %d\n", err);
4396 goto exit;
4397 }
4398 }
4399
Hante Meuleman8abffd82015-10-29 20:33:16 +01004400 if ((dev_role == NL80211_IFTYPE_AP) &&
4401 ((ifp->ifidx == 0) ||
4402 !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004403 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4404 if (err < 0) {
4405 brcmf_err("BRCMF_C_DOWN error %d\n", err);
4406 goto exit;
4407 }
4408 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
4409 }
4410
4411 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
Hante Meuleman1a873342012-09-27 14:17:54 +02004412 if (err < 0) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004413 brcmf_err("SET INFRA error %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004414 goto exit;
4415 }
Arend van Spriel98027762014-12-21 12:43:53 +01004416 } else if (WARN_ON(is_11d != ifp->vif->is_11d)) {
4417 /* Multiple-BSS should use same 11d configuration */
4418 err = -EINVAL;
4419 goto exit;
Hante Meuleman1a873342012-09-27 14:17:54 +02004420 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004421 if (dev_role == NL80211_IFTYPE_AP) {
Hante Meulemana44aa402014-12-03 21:05:33 +01004422 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
4423 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
4424
Hante Meulemana0f07952013-02-08 15:53:47 +01004425 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
4426 if (err < 0) {
4427 brcmf_err("setting AP mode failed %d\n", err);
4428 goto exit;
4429 }
4430 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4431 if (err < 0) {
4432 brcmf_err("BRCMF_C_UP error (%d)\n", err);
4433 goto exit;
4434 }
Hante Meuleman118eb302014-12-21 12:43:49 +01004435 /* On DOWN the firmware removes the WEP keys, reconfigure
4436 * them if they were set.
4437 */
4438 brcmf_cfg80211_reconfigure_wep(ifp);
Hante Meulemana0f07952013-02-08 15:53:47 +01004439
4440 memset(&join_params, 0, sizeof(join_params));
4441 /* join parameters starts with ssid */
4442 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
4443 /* create softap */
4444 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4445 &join_params, sizeof(join_params));
4446 if (err < 0) {
4447 brcmf_err("SET SSID error (%d)\n", err);
4448 goto exit;
4449 }
4450 brcmf_dbg(TRACE, "AP mode configuration complete\n");
4451 } else {
4452 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
4453 sizeof(ssid_le));
4454 if (err < 0) {
4455 brcmf_err("setting ssid failed %d\n", err);
4456 goto exit;
4457 }
Hante Meuleman37a869e2015-10-29 20:33:17 +01004458 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meulemana0f07952013-02-08 15:53:47 +01004459 bss_enable.enable = cpu_to_le32(1);
4460 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4461 sizeof(bss_enable));
4462 if (err < 0) {
4463 brcmf_err("bss_enable config failed %d\n", err);
4464 goto exit;
4465 }
4466
4467 brcmf_dbg(TRACE, "GO mode configuration complete\n");
4468 }
Arend van Sprielc1179032012-10-22 13:55:33 -07004469 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004470 brcmf_net_setcarrier(ifp, true);
Hante Meuleman1a873342012-09-27 14:17:54 +02004471
4472exit:
Hante Meulemana44aa402014-12-03 21:05:33 +01004473 if ((err) && (!mbss)) {
Arend van Sprielf96aa072013-04-05 10:57:48 +02004474 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004475 brcmf_configure_arp_offload(ifp, true);
4476 }
Hante Meuleman1a873342012-09-27 14:17:54 +02004477 return err;
4478}
4479
4480static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
4481{
Arend van Sprielc1179032012-10-22 13:55:33 -07004482 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004483 s32 err;
Hante Meuleman426d0a52013-02-08 15:53:53 +01004484 struct brcmf_fil_bss_enable_le bss_enable;
Hante Meuleman5c33a942013-04-02 21:06:18 +02004485 struct brcmf_join_params join_params;
Hante Meuleman1a873342012-09-27 14:17:54 +02004486
Arend van Sprield96b8012012-12-05 15:26:02 +01004487 brcmf_dbg(TRACE, "Enter\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004488
Hante Meuleman426d0a52013-02-08 15:53:53 +01004489 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
Hante Meuleman1a873342012-09-27 14:17:54 +02004490 /* Due to most likely deauths outstanding we sleep */
4491 /* first to make sure they get processed by fw. */
4492 msleep(400);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004493
Hante Meulemana44aa402014-12-03 21:05:33 +01004494 if (ifp->vif->mbss) {
4495 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
4496 return err;
4497 }
4498
Hante Meuleman5c33a942013-04-02 21:06:18 +02004499 memset(&join_params, 0, sizeof(join_params));
4500 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
4501 &join_params, sizeof(join_params));
4502 if (err < 0)
4503 brcmf_err("SET SSID error (%d)\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004504 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004505 if (err < 0)
Hante Meulemana44aa402014-12-03 21:05:33 +01004506 brcmf_err("BRCMF_C_DOWN error %d\n", err);
Hante Meuleman5c33a942013-04-02 21:06:18 +02004507 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
4508 if (err < 0)
4509 brcmf_err("setting AP mode failed %d\n", err);
4510 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
4511 if (err < 0)
4512 brcmf_err("setting INFRA mode failed %d\n", err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004513 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
4514 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
Arend van Spriel98027762014-12-21 12:43:53 +01004515 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
4516 ifp->vif->is_11d);
4517 if (err < 0)
4518 brcmf_err("restoring REGULATORY setting failed %d\n",
4519 err);
Hante Meulemana44aa402014-12-03 21:05:33 +01004520 /* Bring device back up so it can be used again */
4521 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
4522 if (err < 0)
4523 brcmf_err("BRCMF_C_UP error %d\n", err);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004524 } else {
Hante Meuleman37a869e2015-10-29 20:33:17 +01004525 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004526 bss_enable.enable = cpu_to_le32(0);
4527 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
4528 sizeof(bss_enable));
4529 if (err < 0)
4530 brcmf_err("bss_enable config failed %d\n", err);
Hante Meuleman1a873342012-09-27 14:17:54 +02004531 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02004532 brcmf_set_mpc(ifp, 1);
Hante Meulemanb3657452013-05-27 21:09:53 +02004533 brcmf_configure_arp_offload(ifp, true);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004534 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
Hante Meuleman92121e62015-10-08 20:33:21 +02004535 brcmf_net_setcarrier(ifp, false);
Hante Meuleman426d0a52013-02-08 15:53:53 +01004536
Hante Meuleman1a873342012-09-27 14:17:54 +02004537 return err;
4538}
4539
Hante Meulemana0f07952013-02-08 15:53:47 +01004540static s32
4541brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
4542 struct cfg80211_beacon_data *info)
4543{
Hante Meulemana0f07952013-02-08 15:53:47 +01004544 struct brcmf_if *ifp = netdev_priv(ndev);
4545 s32 err;
4546
4547 brcmf_dbg(TRACE, "Enter\n");
4548
Hante Meulemana0f07952013-02-08 15:53:47 +01004549 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4550
4551 return err;
4552}
4553
Hante Meuleman1a873342012-09-27 14:17:54 +02004554static int
4555brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03004556 struct station_del_parameters *params)
Hante Meuleman1a873342012-09-27 14:17:54 +02004557{
Hante Meulemana0f07952013-02-08 15:53:47 +01004558 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Hante Meuleman1a873342012-09-27 14:17:54 +02004559 struct brcmf_scb_val_le scbval;
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004560 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman1a873342012-09-27 14:17:54 +02004561 s32 err;
4562
Jouni Malinen89c771e2014-10-10 20:52:40 +03004563 if (!params->mac)
Hante Meuleman1a873342012-09-27 14:17:54 +02004564 return -EFAULT;
4565
Jouni Malinen89c771e2014-10-10 20:52:40 +03004566 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
Hante Meuleman1a873342012-09-27 14:17:54 +02004567
Hante Meulemana0f07952013-02-08 15:53:47 +01004568 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4569 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Sprielce81e312012-10-22 13:55:37 -07004570 if (!check_vif_up(ifp->vif))
Hante Meuleman1a873342012-09-27 14:17:54 +02004571 return -EIO;
4572
Jouni Malinen89c771e2014-10-10 20:52:40 +03004573 memcpy(&scbval.ea, params->mac, ETH_ALEN);
Rafał Miłeckiba8b6ae2015-02-08 11:51:47 +01004574 scbval.val = cpu_to_le32(params->reason_code);
Arend van Spriel0abb5f212012-10-22 13:55:32 -07004575 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07004576 &scbval, sizeof(scbval));
Hante Meuleman1a873342012-09-27 14:17:54 +02004577 if (err)
Arend van Spriel57d6e912012-12-05 15:26:00 +01004578 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
Hante Meuleman7ab6acd2013-02-08 15:53:58 +01004579
Arend van Sprield96b8012012-12-05 15:26:02 +01004580 brcmf_dbg(TRACE, "Exit\n");
Hante Meuleman1a873342012-09-27 14:17:54 +02004581 return err;
4582}
4583
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004584static int
4585brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
4586 const u8 *mac, struct station_parameters *params)
4587{
4588 struct brcmf_if *ifp = netdev_priv(ndev);
4589 s32 err;
4590
4591 brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
4592 params->sta_flags_mask, params->sta_flags_set);
4593
4594 /* Ignore all 00 MAC */
4595 if (is_zero_ether_addr(mac))
4596 return 0;
4597
4598 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4599 return 0;
4600
4601 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
4602 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
4603 (void *)mac, ETH_ALEN);
4604 else
4605 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
4606 (void *)mac, ETH_ALEN);
4607 if (err < 0)
4608 brcmf_err("Setting SCB (de-)authorize failed, %d\n", err);
4609
4610 return err;
4611}
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004612
4613static void
4614brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4615 struct wireless_dev *wdev,
4616 u16 frame_type, bool reg)
4617{
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004618 struct brcmf_cfg80211_vif *vif;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004619 u16 mgmt_type;
4620
4621 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4622
4623 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004624 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004625 if (reg)
4626 vif->mgmt_rx_reg |= BIT(mgmt_type);
4627 else
Hante Meuleman318a64c2013-02-08 15:53:45 +01004628 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004629}
4630
4631
4632static int
4633brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004634 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004635{
4636 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02004637 struct ieee80211_channel *chan = params->chan;
4638 const u8 *buf = params->buf;
4639 size_t len = params->len;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004640 const struct ieee80211_mgmt *mgmt;
4641 struct brcmf_cfg80211_vif *vif;
4642 s32 err = 0;
4643 s32 ie_offset;
4644 s32 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01004645 struct brcmf_fil_action_frame_le *action_frame;
4646 struct brcmf_fil_af_params_le *af_params;
4647 bool ack;
4648 s32 chan_nr;
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004649 u32 freq;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004650
4651 brcmf_dbg(TRACE, "Enter\n");
4652
4653 *cookie = 0;
4654
4655 mgmt = (const struct ieee80211_mgmt *)buf;
4656
Hante Meulemana0f07952013-02-08 15:53:47 +01004657 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4658 brcmf_err("Driver only allows MGMT packet type\n");
4659 return -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004660 }
Hante Meulemana0f07952013-02-08 15:53:47 +01004661
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004662 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4663
Hante Meulemana0f07952013-02-08 15:53:47 +01004664 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4665 /* Right now the only reason to get a probe response */
4666 /* is for p2p listen response or for p2p GO from */
4667 /* wpa_supplicant. Unfortunately the probe is send */
4668 /* on primary ndev, while dongle wants it on the p2p */
4669 /* vif. Since this is only reason for a probe */
4670 /* response to be sent, the vif is taken from cfg. */
4671 /* If ever desired to send proberesp for non p2p */
4672 /* response then data should be checked for */
4673 /* "DIRECT-". Note in future supplicant will take */
4674 /* dedicated p2p wdev to do this and then this 'hack'*/
4675 /* is not needed anymore. */
4676 ie_offset = DOT11_MGMT_HDR_LEN +
4677 DOT11_BCN_PRB_FIXED_LEN;
4678 ie_len = len - ie_offset;
Hante Meulemana0f07952013-02-08 15:53:47 +01004679 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4680 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4681 err = brcmf_vif_set_mgmt_ie(vif,
4682 BRCMF_VNDR_IE_PRBRSP_FLAG,
4683 &buf[ie_offset],
4684 ie_len);
4685 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4686 GFP_KERNEL);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004687 } else if (ieee80211_is_action(mgmt->frame_control)) {
4688 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4689 if (af_params == NULL) {
4690 brcmf_err("unable to allocate frame\n");
4691 err = -ENOMEM;
4692 goto exit;
4693 }
4694 action_frame = &af_params->action_frame;
4695 /* Add the packet Id */
4696 action_frame->packet_id = cpu_to_le32(*cookie);
4697 /* Add BSSID */
4698 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4699 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4700 /* Add the length exepted for 802.11 header */
4701 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
Antonio Quartullic2ff8ca2013-06-11 14:20:01 +02004702 /* Add the channel. Use the one specified as parameter if any or
4703 * the current one (got from the firmware) otherwise
4704 */
4705 if (chan)
4706 freq = chan->center_freq;
4707 else
4708 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4709 &freq);
4710 chan_nr = ieee80211_frequency_to_channel(freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004711 af_params->channel = cpu_to_le32(chan_nr);
4712
4713 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4714 le16_to_cpu(action_frame->len));
4715
4716 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
Antonio Quartulli86a9c4a2013-06-19 13:35:31 +02004717 *cookie, le16_to_cpu(action_frame->len), freq);
Hante Meuleman18e2f612013-02-08 15:53:49 +01004718
Arend van Spriel7fa2e352013-04-05 10:57:47 +02004719 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
Hante Meuleman18e2f612013-02-08 15:53:49 +01004720 af_params);
4721
4722 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4723 GFP_KERNEL);
4724 kfree(af_params);
Hante Meulemana0f07952013-02-08 15:53:47 +01004725 } else {
4726 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4727 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4728 }
4729
Hante Meuleman18e2f612013-02-08 15:53:49 +01004730exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004731 return err;
4732}
4733
4734
4735static int
4736brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4737 struct wireless_dev *wdev,
4738 u64 cookie)
4739{
4740 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4741 struct brcmf_cfg80211_vif *vif;
4742 int err = 0;
4743
4744 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4745
4746 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4747 if (vif == NULL) {
4748 brcmf_err("No p2p device available for probe response\n");
4749 err = -ENODEV;
4750 goto exit;
4751 }
4752 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4753exit:
4754 return err;
4755}
4756
Piotr Haber61730d42013-04-23 12:53:12 +02004757static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4758 struct wireless_dev *wdev,
4759 enum nl80211_crit_proto_id proto,
4760 u16 duration)
4761{
4762 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4763 struct brcmf_cfg80211_vif *vif;
4764
4765 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4766
4767 /* only DHCP support for now */
4768 if (proto != NL80211_CRIT_PROTO_DHCP)
4769 return -EINVAL;
4770
4771 /* suppress and abort scanning */
4772 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4773 brcmf_abort_scanning(cfg);
4774
4775 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4776}
4777
4778static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4779 struct wireless_dev *wdev)
4780{
4781 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4782 struct brcmf_cfg80211_vif *vif;
4783
4784 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4785
4786 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4787 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4788}
4789
Hante Meuleman70b7d942014-07-30 13:20:07 +02004790static s32
4791brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4792 const struct brcmf_event_msg *e, void *data)
4793{
4794 switch (e->reason) {
4795 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4796 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4797 break;
4798 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4799 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4800 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4801 break;
4802 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4803 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4804 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4805 break;
4806 }
4807
4808 return 0;
4809}
4810
Arend van Spriel89c2f382013-08-10 12:27:25 +02004811static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4812{
4813 int ret;
4814
4815 switch (oper) {
4816 case NL80211_TDLS_DISCOVERY_REQ:
4817 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4818 break;
4819 case NL80211_TDLS_SETUP:
4820 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4821 break;
4822 case NL80211_TDLS_TEARDOWN:
4823 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4824 break;
4825 default:
4826 brcmf_err("unsupported operation: %d\n", oper);
4827 ret = -EOPNOTSUPP;
4828 }
4829 return ret;
4830}
4831
4832static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02004833 struct net_device *ndev, const u8 *peer,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004834 enum nl80211_tdls_operation oper)
4835{
4836 struct brcmf_if *ifp;
4837 struct brcmf_tdls_iovar_le info;
4838 int ret = 0;
4839
4840 ret = brcmf_convert_nl80211_tdls_oper(oper);
4841 if (ret < 0)
4842 return ret;
4843
4844 ifp = netdev_priv(ndev);
4845 memset(&info, 0, sizeof(info));
4846 info.mode = (u8)ret;
4847 if (peer)
4848 memcpy(info.ea, peer, ETH_ALEN);
4849
4850 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4851 &info, sizeof(info));
4852 if (ret < 0)
4853 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4854
4855 return ret;
4856}
4857
Arend van Spriel5b435de2011-10-05 13:19:03 +02004858static struct cfg80211_ops wl_cfg80211_ops = {
Arend van Spriel9f440b72013-02-08 15:53:36 +01004859 .add_virtual_intf = brcmf_cfg80211_add_iface,
4860 .del_virtual_intf = brcmf_cfg80211_del_iface,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004861 .change_virtual_intf = brcmf_cfg80211_change_iface,
4862 .scan = brcmf_cfg80211_scan,
4863 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4864 .join_ibss = brcmf_cfg80211_join_ibss,
4865 .leave_ibss = brcmf_cfg80211_leave_ibss,
4866 .get_station = brcmf_cfg80211_get_station,
Hante Meulemanbf2a7e02015-10-08 20:33:18 +02004867 .dump_station = brcmf_cfg80211_dump_station,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004868 .set_tx_power = brcmf_cfg80211_set_tx_power,
4869 .get_tx_power = brcmf_cfg80211_get_tx_power,
4870 .add_key = brcmf_cfg80211_add_key,
4871 .del_key = brcmf_cfg80211_del_key,
4872 .get_key = brcmf_cfg80211_get_key,
4873 .set_default_key = brcmf_cfg80211_config_default_key,
4874 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4875 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004876 .connect = brcmf_cfg80211_connect,
4877 .disconnect = brcmf_cfg80211_disconnect,
4878 .suspend = brcmf_cfg80211_suspend,
4879 .resume = brcmf_cfg80211_resume,
4880 .set_pmksa = brcmf_cfg80211_set_pmksa,
4881 .del_pmksa = brcmf_cfg80211_del_pmksa,
Arend van Sprielcbaa1772012-08-30 19:43:02 +02004882 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
Hante Meuleman1a873342012-09-27 14:17:54 +02004883 .start_ap = brcmf_cfg80211_start_ap,
4884 .stop_ap = brcmf_cfg80211_stop_ap,
Hante Meulemana0f07952013-02-08 15:53:47 +01004885 .change_beacon = brcmf_cfg80211_change_beacon,
Hante Meuleman1a873342012-09-27 14:17:54 +02004886 .del_station = brcmf_cfg80211_del_station,
Hante Meuleman6b89dcb2014-12-21 12:43:52 +01004887 .change_station = brcmf_cfg80211_change_station,
Arend van Spriele5806072012-09-19 22:21:08 +02004888 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4889 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01004890 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4891 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4892 .remain_on_channel = brcmf_p2p_remain_on_channel,
4893 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
Arend van Spriel27f10e32013-04-05 10:57:50 +02004894 .start_p2p_device = brcmf_p2p_start_device,
4895 .stop_p2p_device = brcmf_p2p_stop_device,
Piotr Haber61730d42013-04-23 12:53:12 +02004896 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4897 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
Arend van Spriel89c2f382013-08-10 12:27:25 +02004898 .tdls_oper = brcmf_cfg80211_tdls_oper,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004899};
4900
Arend van Spriel3eacf862012-10-22 13:55:30 -07004901struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
Arend van Spriel9f440b72013-02-08 15:53:36 +01004902 enum nl80211_iftype type,
4903 bool pm_block)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004904{
Hante Meulemana44aa402014-12-03 21:05:33 +01004905 struct brcmf_cfg80211_vif *vif_walk;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004906 struct brcmf_cfg80211_vif *vif;
Hante Meulemana44aa402014-12-03 21:05:33 +01004907 bool mbss;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004908
Arend van Spriel33a6b152013-02-08 15:53:39 +01004909 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
Arend van Spriel9f440b72013-02-08 15:53:36 +01004910 sizeof(*vif));
Arend van Spriel3eacf862012-10-22 13:55:30 -07004911 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4912 if (!vif)
4913 return ERR_PTR(-ENOMEM);
4914
4915 vif->wdev.wiphy = cfg->wiphy;
Arend van Spriel9f440b72013-02-08 15:53:36 +01004916 vif->wdev.iftype = type;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004917
Arend van Spriel3eacf862012-10-22 13:55:30 -07004918 vif->pm_block = pm_block;
Arend van Spriel3eacf862012-10-22 13:55:30 -07004919
Arend van Spriel6ac4f4e2012-10-22 13:55:31 -07004920 brcmf_init_prof(&vif->profile);
4921
Hante Meulemana44aa402014-12-03 21:05:33 +01004922 if (type == NL80211_IFTYPE_AP) {
4923 mbss = false;
4924 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
4925 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
4926 mbss = true;
4927 break;
4928 }
4929 }
4930 vif->mbss = mbss;
4931 }
4932
Arend van Spriel3eacf862012-10-22 13:55:30 -07004933 list_add_tail(&vif->list, &cfg->vif_list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004934 return vif;
4935}
4936
Arend van Spriel427dec52014-01-06 12:40:47 +01004937void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
Arend van Spriel3eacf862012-10-22 13:55:30 -07004938{
Arend van Spriel3eacf862012-10-22 13:55:30 -07004939 list_del(&vif->list);
Arend van Spriel3eacf862012-10-22 13:55:30 -07004940 kfree(vif);
Arend van Spriel5b435de2011-10-05 13:19:03 +02004941}
4942
Arend van Spriel9df4d542014-01-06 12:40:49 +01004943void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4944{
4945 struct brcmf_cfg80211_vif *vif;
4946 struct brcmf_if *ifp;
4947
4948 ifp = netdev_priv(ndev);
4949 vif = ifp->vif;
4950
Arend van Spriel95ef1232015-08-26 22:15:04 +02004951 if (vif)
4952 brcmf_free_vif(vif);
Arend van Spriel9df4d542014-01-06 12:40:49 +01004953 free_netdev(ndev);
4954}
4955
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004956static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004957{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004958 u32 event = e->event_code;
4959 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004960
4961 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004962 brcmf_dbg(CONN, "Processing set ssid\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004963 return true;
4964 }
4965
4966 return false;
4967}
4968
Arend van Spriel903e0ee2012-11-28 21:44:11 +01004969static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
Arend van Spriel5b435de2011-10-05 13:19:03 +02004970{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004971 u32 event = e->event_code;
4972 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004973
Hante Meuleman68ca3952014-02-25 20:30:26 +01004974 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4975 (event == BRCMF_E_DISASSOC_IND) ||
4976 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
Arend van Spriel16886732012-12-05 15:26:04 +01004977 brcmf_dbg(CONN, "Processing link down\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004978 return true;
4979 }
4980 return false;
4981}
4982
Arend van Spriel27a68fe2012-09-27 14:17:55 +02004983static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02004984 const struct brcmf_event_msg *e)
4985{
Arend van Spriel5c36b992012-11-14 18:46:05 -08004986 u32 event = e->event_code;
4987 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02004988
4989 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004990 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
4991 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004992 return true;
4993 }
4994
4995 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
Arend van Spriel16886732012-12-05 15:26:04 +01004996 brcmf_dbg(CONN, "Processing connecting & no network found\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02004997 return true;
4998 }
4999
5000 return false;
5001}
5002
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005003static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005004{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005005 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005006
5007 kfree(conn_info->req_ie);
5008 conn_info->req_ie = NULL;
5009 conn_info->req_ie_len = 0;
5010 kfree(conn_info->resp_ie);
5011 conn_info->resp_ie = NULL;
5012 conn_info->resp_ie_len = 0;
5013}
5014
Hante Meuleman89286dc2013-02-08 15:53:46 +01005015static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
5016 struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005017{
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005018 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005019 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005020 u32 req_len;
5021 u32 resp_len;
5022 s32 err = 0;
5023
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005024 brcmf_clear_assoc_ies(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005025
Arend van Sprielac24be62012-10-22 10:36:23 -07005026 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
5027 cfg->extra_buf, WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005028 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005029 brcmf_err("could not get assoc info (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005030 return err;
5031 }
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005032 assoc_info =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005033 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
Arend van Sprielc4e382d2011-10-12 20:51:21 +02005034 req_len = le32_to_cpu(assoc_info->req_len);
5035 resp_len = le32_to_cpu(assoc_info->resp_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005036 if (req_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005037 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005038 cfg->extra_buf,
5039 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005040 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005041 brcmf_err("could not get assoc req (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005042 return err;
5043 }
5044 conn_info->req_ie_len = req_len;
5045 conn_info->req_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005046 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005047 GFP_KERNEL);
5048 } else {
5049 conn_info->req_ie_len = 0;
5050 conn_info->req_ie = NULL;
5051 }
5052 if (resp_len) {
Arend van Sprielac24be62012-10-22 10:36:23 -07005053 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005054 cfg->extra_buf,
5055 WL_ASSOC_INFO_MAX);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005056 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005057 brcmf_err("could not get assoc resp (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005058 return err;
5059 }
5060 conn_info->resp_ie_len = resp_len;
5061 conn_info->resp_ie =
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005062 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005063 GFP_KERNEL);
5064 } else {
5065 conn_info->resp_ie_len = 0;
5066 conn_info->resp_ie = NULL;
5067 }
Arend van Spriel16886732012-12-05 15:26:04 +01005068 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
5069 conn_info->req_ie_len, conn_info->resp_ie_len);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005070
5071 return err;
5072}
5073
5074static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005075brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005076 struct net_device *ndev,
5077 const struct brcmf_event_msg *e)
5078{
Arend van Sprielc1179032012-10-22 13:55:33 -07005079 struct brcmf_if *ifp = netdev_priv(ndev);
5080 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005081 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
5082 struct wiphy *wiphy = cfg_to_wiphy(cfg);
Franky Lina180b832012-10-10 11:13:09 -07005083 struct ieee80211_channel *notify_channel = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005084 struct ieee80211_supported_band *band;
Franky Lina180b832012-10-10 11:13:09 -07005085 struct brcmf_bss_info_le *bi;
Franky Lin83cf17a2013-04-11 13:28:50 +02005086 struct brcmu_chan ch;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005087 u32 freq;
5088 s32 err = 0;
Franky Lina180b832012-10-10 11:13:09 -07005089 u8 *buf;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005090
Arend van Sprield96b8012012-12-05 15:26:02 +01005091 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005092
Hante Meuleman89286dc2013-02-08 15:53:46 +01005093 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005094 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005095 brcmf_update_bss_info(cfg, ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005096
Franky Lina180b832012-10-10 11:13:09 -07005097 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
5098 if (buf == NULL) {
5099 err = -ENOMEM;
5100 goto done;
5101 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02005102
Franky Lina180b832012-10-10 11:13:09 -07005103 /* data sent to dongle has to be little endian */
5104 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
Arend van Sprielc1179032012-10-22 13:55:33 -07005105 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
Arend van Sprielac24be62012-10-22 10:36:23 -07005106 buf, WL_BSS_INFO_MAX);
Franky Lina180b832012-10-10 11:13:09 -07005107
5108 if (err)
5109 goto done;
5110
5111 bi = (struct brcmf_bss_info_le *)(buf + 4);
Franky Lin83cf17a2013-04-11 13:28:50 +02005112 ch.chspec = le16_to_cpu(bi->chanspec);
5113 cfg->d11inf.decchspec(&ch);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005114
Franky Lin83cf17a2013-04-11 13:28:50 +02005115 if (ch.band == BRCMU_CHAN_BAND_2G)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005116 band = wiphy->bands[IEEE80211_BAND_2GHZ];
5117 else
5118 band = wiphy->bands[IEEE80211_BAND_5GHZ];
5119
Franky Lin83cf17a2013-04-11 13:28:50 +02005120 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005121 notify_channel = ieee80211_get_channel(wiphy, freq);
5122
Franky Lina180b832012-10-10 11:13:09 -07005123done:
5124 kfree(buf);
Arend van Spriel06bb1232012-09-27 14:17:56 +02005125 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005126 conn_info->req_ie, conn_info->req_ie_len,
5127 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005128 brcmf_dbg(CONN, "Report roaming result\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005129
Arend van Sprielc1179032012-10-22 13:55:33 -07005130 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
Arend van Sprield96b8012012-12-05 15:26:02 +01005131 brcmf_dbg(TRACE, "Exit\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005132 return err;
5133}
5134
5135static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005136brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005137 struct net_device *ndev, const struct brcmf_event_msg *e,
5138 bool completed)
5139{
Arend van Sprielc1179032012-10-22 13:55:33 -07005140 struct brcmf_if *ifp = netdev_priv(ndev);
5141 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005142 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005143
Arend van Sprield96b8012012-12-05 15:26:02 +01005144 brcmf_dbg(TRACE, "Enter\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005145
Arend van Sprielc1179032012-10-22 13:55:33 -07005146 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5147 &ifp->vif->sme_state)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02005148 if (completed) {
Hante Meuleman89286dc2013-02-08 15:53:46 +01005149 brcmf_get_assoc_ies(cfg, ifp);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005150 memcpy(profile->bssid, e->addr, ETH_ALEN);
Hante Meuleman89286dc2013-02-08 15:53:46 +01005151 brcmf_update_bss_info(cfg, ifp);
5152 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5153 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005154 }
5155 cfg80211_connect_result(ndev,
Arend van Spriel06bb1232012-09-27 14:17:56 +02005156 (u8 *)profile->bssid,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005157 conn_info->req_ie,
5158 conn_info->req_ie_len,
5159 conn_info->resp_ie,
5160 conn_info->resp_ie_len,
5161 completed ? WLAN_STATUS_SUCCESS :
5162 WLAN_STATUS_AUTH_TIMEOUT,
5163 GFP_KERNEL);
Arend van Spriel16886732012-12-05 15:26:04 +01005164 brcmf_dbg(CONN, "Report connect result - connection %s\n",
5165 completed ? "succeeded" : "failed");
Arend van Spriel5b435de2011-10-05 13:19:03 +02005166 }
Arend van Sprield96b8012012-12-05 15:26:02 +01005167 brcmf_dbg(TRACE, "Exit\n");
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005168 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005169}
5170
5171static s32
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005172brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
Hante Meuleman1a873342012-09-27 14:17:54 +02005173 struct net_device *ndev,
5174 const struct brcmf_event_msg *e, void *data)
5175{
Hante Meulemana44aa402014-12-03 21:05:33 +01005176 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman7ee29602013-02-06 18:40:43 +01005177 static int generation;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005178 u32 event = e->event_code;
5179 u32 reason = e->reason;
Hante Meuleman1a873342012-09-27 14:17:54 +02005180 struct station_info sinfo;
5181
Arend van Spriel16886732012-12-05 15:26:04 +01005182 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005183 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
5184 ndev != cfg_to_ndev(cfg)) {
5185 brcmf_dbg(CONN, "AP mode link down\n");
5186 complete(&cfg->vif_disabled);
Hante Meulemana44aa402014-12-03 21:05:33 +01005187 if (ifp->vif->mbss)
Arend van Sprielee6e3a32015-08-26 22:14:55 +02005188 brcmf_remove_interface(ifp);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005189 return 0;
5190 }
Hante Meuleman1a873342012-09-27 14:17:54 +02005191
Hante Meuleman1a873342012-09-27 14:17:54 +02005192 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
Hante Meuleman7ee29602013-02-06 18:40:43 +01005193 (reason == BRCMF_E_STATUS_SUCCESS)) {
5194 memset(&sinfo, 0, sizeof(sinfo));
Hante Meuleman1a873342012-09-27 14:17:54 +02005195 if (!data) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005196 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
Hante Meuleman1a873342012-09-27 14:17:54 +02005197 return -EINVAL;
5198 }
5199 sinfo.assoc_req_ies = data;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005200 sinfo.assoc_req_ies_len = e->datalen;
Hante Meuleman1a873342012-09-27 14:17:54 +02005201 generation++;
5202 sinfo.generation = generation;
Hante Meuleman7ee29602013-02-06 18:40:43 +01005203 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005204 } else if ((event == BRCMF_E_DISASSOC_IND) ||
5205 (event == BRCMF_E_DEAUTH_IND) ||
5206 (event == BRCMF_E_DEAUTH)) {
Hante Meuleman7ee29602013-02-06 18:40:43 +01005207 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
Hante Meuleman1a873342012-09-27 14:17:54 +02005208 }
Hante Meuleman7ee29602013-02-06 18:40:43 +01005209 return 0;
Hante Meuleman1a873342012-09-27 14:17:54 +02005210}
5211
5212static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005213brcmf_notify_connect_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005214 const struct brcmf_event_msg *e, void *data)
5215{
Arend van Spriel19937322012-11-05 16:22:32 -08005216 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5217 struct net_device *ndev = ifp->ndev;
Arend van Sprielc1179032012-10-22 13:55:33 -07005218 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005219 struct ieee80211_channel *chan;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005220 s32 err = 0;
5221
Hante Meuleman8851cce2014-07-30 13:20:02 +02005222 if ((e->event_code == BRCMF_E_DEAUTH) ||
5223 (e->event_code == BRCMF_E_DEAUTH_IND) ||
5224 (e->event_code == BRCMF_E_DISASSOC_IND) ||
5225 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
5226 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5227 }
5228
Arend van Spriel967fe2c2014-03-15 17:18:21 +01005229 if (brcmf_is_apmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005230 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005231 } else if (brcmf_is_linkup(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005232 brcmf_dbg(CONN, "Linkup\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005233 if (brcmf_is_ibssmode(ifp->vif)) {
Hante Meulemanb0a79082015-12-10 13:43:07 +01005234 brcmf_inform_ibss(cfg, ndev, e->addr);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005235 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
Arend van Spriel6c8c4f72012-09-27 14:17:57 +02005236 memcpy(profile->bssid, e->addr, ETH_ALEN);
Antonio Quartullife94f3a2014-01-29 17:53:43 +01005237 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
Arend van Sprielc1179032012-10-22 13:55:33 -07005238 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5239 &ifp->vif->sme_state);
5240 set_bit(BRCMF_VIF_STATUS_CONNECTED,
5241 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005242 } else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005243 brcmf_bss_connect_done(cfg, ndev, e, true);
Hante Meuleman92121e62015-10-08 20:33:21 +02005244 brcmf_net_setcarrier(ifp, true);
Arend van Spriel903e0ee2012-11-28 21:44:11 +01005245 } else if (brcmf_is_linkdown(e)) {
Arend van Spriel16886732012-12-05 15:26:04 +01005246 brcmf_dbg(CONN, "Linkdown\n");
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005247 if (!brcmf_is_ibssmode(ifp->vif)) {
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005248 brcmf_bss_connect_done(cfg, ndev, e, false);
Hante Meuleman42e0ed02016-01-05 11:05:50 +01005249 brcmf_link_down(ifp->vif,
5250 brcmf_map_fw_linkdown_reason(e));
5251 brcmf_init_prof(ndev_to_prof(ndev));
5252 if (ndev != cfg_to_ndev(cfg))
5253 complete(&cfg->vif_disabled);
5254 brcmf_net_setcarrier(ifp, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005255 }
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005256 } else if (brcmf_is_nonetwork(cfg, e)) {
Arend van Spriel128ce3b2012-11-28 21:44:12 +01005257 if (brcmf_is_ibssmode(ifp->vif))
Arend van Sprielc1179032012-10-22 13:55:33 -07005258 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
5259 &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005260 else
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005261 brcmf_bss_connect_done(cfg, ndev, e, false);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005262 }
5263
5264 return err;
5265}
5266
5267static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005268brcmf_notify_roaming_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005269 const struct brcmf_event_msg *e, void *data)
5270{
Arend van Spriel19937322012-11-05 16:22:32 -08005271 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005272 u32 event = e->event_code;
5273 u32 status = e->status;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005274
5275 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
Arend van Sprielc1179032012-10-22 13:55:33 -07005276 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
Arend van Spriel19937322012-11-05 16:22:32 -08005277 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005278 else
Arend van Spriel19937322012-11-05 16:22:32 -08005279 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005280 }
5281
Peter Senna Tschudin12f32372014-05-31 10:14:06 -03005282 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005283}
5284
5285static s32
Arend van Spriel19937322012-11-05 16:22:32 -08005286brcmf_notify_mic_status(struct brcmf_if *ifp,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005287 const struct brcmf_event_msg *e, void *data)
5288{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005289 u16 flags = e->flags;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005290 enum nl80211_key_type key_type;
5291
5292 if (flags & BRCMF_EVENT_MSG_GROUP)
5293 key_type = NL80211_KEYTYPE_GROUP;
5294 else
5295 key_type = NL80211_KEYTYPE_PAIRWISE;
5296
Arend van Spriel19937322012-11-05 16:22:32 -08005297 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
Arend van Spriel5b435de2011-10-05 13:19:03 +02005298 NULL, GFP_KERNEL);
5299
5300 return 0;
5301}
5302
Arend van Sprield3c0b632013-02-08 15:53:37 +01005303static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
5304 const struct brcmf_event_msg *e, void *data)
5305{
5306 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5307 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
5308 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5309 struct brcmf_cfg80211_vif *vif;
5310
Hante Meuleman37a869e2015-10-29 20:33:17 +01005311 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
Arend van Sprield3c0b632013-02-08 15:53:37 +01005312 ifevent->action, ifevent->flags, ifevent->ifidx,
Hante Meuleman37a869e2015-10-29 20:33:17 +01005313 ifevent->bsscfgidx);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005314
Arend van Sprield3c0b632013-02-08 15:53:37 +01005315 mutex_lock(&event->vif_event_lock);
5316 event->action = ifevent->action;
5317 vif = event->vif;
5318
5319 switch (ifevent->action) {
5320 case BRCMF_E_IF_ADD:
5321 /* waiting process may have timed out */
Wei Yongjundc4a7872013-02-22 21:32:20 +08005322 if (!cfg->vif_event.vif) {
5323 mutex_unlock(&event->vif_event_lock);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005324 return -EBADF;
Wei Yongjundc4a7872013-02-22 21:32:20 +08005325 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005326
5327 ifp->vif = vif;
5328 vif->ifp = ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02005329 if (ifp->ndev) {
5330 vif->wdev.netdev = ifp->ndev;
5331 ifp->ndev->ieee80211_ptr = &vif->wdev;
5332 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
5333 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01005334 mutex_unlock(&event->vif_event_lock);
5335 wake_up(&event->vif_wq);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01005336 return 0;
Arend van Sprield3c0b632013-02-08 15:53:37 +01005337
5338 case BRCMF_E_IF_DEL:
Arend van Sprield3c0b632013-02-08 15:53:37 +01005339 mutex_unlock(&event->vif_event_lock);
5340 /* event may not be upon user request */
5341 if (brcmf_cfg80211_vif_event_armed(cfg))
5342 wake_up(&event->vif_wq);
5343 return 0;
5344
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01005345 case BRCMF_E_IF_CHANGE:
5346 mutex_unlock(&event->vif_event_lock);
5347 wake_up(&event->vif_wq);
5348 return 0;
5349
Arend van Sprield3c0b632013-02-08 15:53:37 +01005350 default:
5351 mutex_unlock(&event->vif_event_lock);
5352 break;
5353 }
5354 return -EINVAL;
5355}
5356
Arend van Spriel5b435de2011-10-05 13:19:03 +02005357static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
5358{
Arend van Spriel5b435de2011-10-05 13:19:03 +02005359 conf->frag_threshold = (u32)-1;
5360 conf->rts_threshold = (u32)-1;
5361 conf->retry_short = (u32)-1;
5362 conf->retry_long = (u32)-1;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005363}
5364
Arend van Spriel5c36b992012-11-14 18:46:05 -08005365static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005366{
Arend van Spriel5c36b992012-11-14 18:46:05 -08005367 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
5368 brcmf_notify_connect_status);
5369 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
5370 brcmf_notify_connect_status);
5371 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
5372 brcmf_notify_connect_status);
5373 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
5374 brcmf_notify_connect_status);
5375 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
5376 brcmf_notify_connect_status);
5377 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
5378 brcmf_notify_connect_status);
5379 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
5380 brcmf_notify_roaming_status);
5381 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
5382 brcmf_notify_mic_status);
5383 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
5384 brcmf_notify_connect_status);
5385 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
5386 brcmf_notify_sched_scan_results);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005387 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
5388 brcmf_notify_vif_event);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005389 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005390 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01005391 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
5392 brcmf_p2p_notify_listen_complete);
Hante Meulemane6da3402013-02-08 15:53:48 +01005393 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
5394 brcmf_p2p_notify_action_frame_rx);
Hante Meuleman18e2f612013-02-08 15:53:49 +01005395 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
5396 brcmf_p2p_notify_action_tx_complete);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01005397 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
5398 brcmf_p2p_notify_action_tx_complete);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005399}
5400
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005401static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005402{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005403 kfree(cfg->conf);
5404 cfg->conf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005405 kfree(cfg->escan_ioctl_buf);
5406 cfg->escan_ioctl_buf = NULL;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005407 kfree(cfg->extra_buf);
5408 cfg->extra_buf = NULL;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005409 kfree(cfg->wowl.nd);
5410 cfg->wowl.nd = NULL;
5411 kfree(cfg->wowl.nd_info);
5412 cfg->wowl.nd_info = NULL;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005413}
5414
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005415static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005416{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005417 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
5418 if (!cfg->conf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005419 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005420 cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5421 if (!cfg->escan_ioctl_buf)
Hante Meulemane756af52012-09-11 21:18:52 +02005422 goto init_priv_mem_out;
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005423 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
5424 if (!cfg->extra_buf)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005425 goto init_priv_mem_out;
Hante Meuleman3021ad92016-01-05 11:05:45 +01005426 cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL);
5427 if (!cfg->wowl.nd)
5428 goto init_priv_mem_out;
5429 cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) +
5430 sizeof(struct cfg80211_wowlan_nd_match *),
5431 GFP_KERNEL);
5432 if (!cfg->wowl.nd_info)
5433 goto init_priv_mem_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005434
5435 return 0;
5436
5437init_priv_mem_out:
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005438 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005439
5440 return -ENOMEM;
5441}
5442
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005443static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005444{
5445 s32 err = 0;
5446
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005447 cfg->scan_request = NULL;
5448 cfg->pwr_save = true;
Hante Meuleman68ca3952014-02-25 20:30:26 +01005449 cfg->active_scan = true; /* we do active scan per default */
5450 cfg->dongle_up = false; /* dongle is not up yet */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005451 err = brcmf_init_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005452 if (err)
5453 return err;
Arend van Spriel5c36b992012-11-14 18:46:05 -08005454 brcmf_register_event_handlers(cfg);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005455 mutex_init(&cfg->usr_sync);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005456 brcmf_init_escan(cfg);
5457 brcmf_init_conf(cfg->conf);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01005458 init_completion(&cfg->vif_disabled);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005459 return err;
5460}
5461
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005462static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005463{
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005464 cfg->dongle_up = false; /* dongle down */
Arend van Spriel27a68fe2012-09-27 14:17:55 +02005465 brcmf_abort_scanning(cfg);
5466 brcmf_deinit_priv_mem(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005467}
5468
Arend van Sprield3c0b632013-02-08 15:53:37 +01005469static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
5470{
5471 init_waitqueue_head(&event->vif_wq);
Arend van Sprield3c0b632013-02-08 15:53:37 +01005472 mutex_init(&event->vif_event_lock);
5473}
5474
Hante Meuleman1119e232015-11-25 11:32:42 +01005475static s32 brcmf_dongle_roam(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005476{
Hante Meuleman1119e232015-11-25 11:32:42 +01005477 s32 err;
5478 u32 bcn_timeout;
Arend van Sprielf588bc02011-10-12 20:51:22 +02005479 __le32 roamtrigger[2];
5480 __le32 roam_delta[2];
Arend van Spriel5b435de2011-10-05 13:19:03 +02005481
Hante Meuleman1119e232015-11-25 11:32:42 +01005482 /* Configure beacon timeout value based upon roaming setting */
Hante Meuleman7d34b052016-01-02 09:41:41 +01005483 if (ifp->drvr->settings->roamoff)
Hante Meuleman1119e232015-11-25 11:32:42 +01005484 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF;
5485 else
5486 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON;
5487 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
5488 if (err) {
5489 brcmf_err("bcn_timeout error (%d)\n", err);
5490 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005491 }
5492
Hante Meuleman1119e232015-11-25 11:32:42 +01005493 /* Enable/Disable built-in roaming to allow supplicant to take care of
5494 * roaming.
Arend van Spriel5b435de2011-10-05 13:19:03 +02005495 */
Hante Meuleman68ca3952014-02-25 20:30:26 +01005496 brcmf_dbg(INFO, "Internal Roaming = %s\n",
Hante Meuleman7d34b052016-01-02 09:41:41 +01005497 ifp->drvr->settings->roamoff ? "Off" : "On");
5498 err = brcmf_fil_iovar_int_set(ifp, "roam_off",
5499 ifp->drvr->settings->roamoff);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005500 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005501 brcmf_err("roam_off error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005502 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005503 }
5504
Arend van Sprielf588bc02011-10-12 20:51:22 +02005505 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
5506 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005507 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005508 (void *)roamtrigger, sizeof(roamtrigger));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005509 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005510 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005511 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005512 }
5513
Arend van Sprielf588bc02011-10-12 20:51:22 +02005514 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
5515 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
Arend van Sprielac24be62012-10-22 10:36:23 -07005516 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
Hante Meuleman81f5dcb2012-10-22 10:36:14 -07005517 (void *)roam_delta, sizeof(roam_delta));
Arend van Spriel5b435de2011-10-05 13:19:03 +02005518 if (err) {
Arend van Spriel57d6e912012-12-05 15:26:00 +01005519 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
Hante Meuleman1119e232015-11-25 11:32:42 +01005520 goto roam_setup_done;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005521 }
5522
Hante Meuleman1119e232015-11-25 11:32:42 +01005523roam_setup_done:
Arend van Spriel5b435de2011-10-05 13:19:03 +02005524 return err;
5525}
5526
5527static s32
Hante Meuleman1678ba82015-12-10 13:43:00 +01005528brcmf_dongle_scantime(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005529{
5530 s32 err = 0;
5531
Arend van Sprielac24be62012-10-22 10:36:23 -07005532 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005533 BRCMF_SCAN_CHANNEL_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005534 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005535 brcmf_err("Scan assoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005536 goto dongle_scantime_out;
5537 }
Arend van Sprielac24be62012-10-22 10:36:23 -07005538 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005539 BRCMF_SCAN_UNASSOC_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005540 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005541 brcmf_err("Scan unassoc time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005542 goto dongle_scantime_out;
5543 }
5544
Arend van Sprielac24be62012-10-22 10:36:23 -07005545 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
Hante Meuleman1678ba82015-12-10 13:43:00 +01005546 BRCMF_SCAN_PASSIVE_TIME);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005547 if (err) {
Hante Meuleman1678ba82015-12-10 13:43:00 +01005548 brcmf_err("Scan passive time error (%d)\n", err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02005549 goto dongle_scantime_out;
5550 }
5551
5552dongle_scantime_out:
5553 return err;
5554}
5555
Arend van Sprielb48d8912014-07-12 08:49:41 +02005556static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
5557 struct brcmu_chan *ch)
5558{
5559 u32 ht40_flag;
5560
5561 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
5562 if (ch->sb == BRCMU_CHAN_SB_U) {
5563 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5564 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5565 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5566 } else {
5567 /* It should be one of
5568 * IEEE80211_CHAN_NO_HT40 or
5569 * IEEE80211_CHAN_NO_HT40PLUS
5570 */
5571 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5572 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5573 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5574 }
5575}
5576
5577static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5578 u32 bw_cap[])
Hante Meulemand48200b2013-04-03 12:40:29 +02005579{
5580 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Sprielb48d8912014-07-12 08:49:41 +02005581 struct ieee80211_supported_band *band;
5582 struct ieee80211_channel *channel;
5583 struct wiphy *wiphy;
Hante Meulemand48200b2013-04-03 12:40:29 +02005584 struct brcmf_chanspec_list *list;
Franky Lin83cf17a2013-04-11 13:28:50 +02005585 struct brcmu_chan ch;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005586 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005587 u8 *pbuf;
5588 u32 i, j;
5589 u32 total;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005590 u32 chaninfo;
Hante Meulemand48200b2013-04-03 12:40:29 +02005591 u32 index;
Hante Meulemand48200b2013-04-03 12:40:29 +02005592
5593 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5594
5595 if (pbuf == NULL)
5596 return -ENOMEM;
5597
5598 list = (struct brcmf_chanspec_list *)pbuf;
5599
5600 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5601 BRCMF_DCMD_MEDLEN);
5602 if (err) {
5603 brcmf_err("get chanspecs error (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005604 goto fail_pbuf;
Hante Meulemand48200b2013-04-03 12:40:29 +02005605 }
5606
Arend van Sprielb48d8912014-07-12 08:49:41 +02005607 wiphy = cfg_to_wiphy(cfg);
Arend van Spriel58de92d2015-04-14 20:10:24 +02005608 band = wiphy->bands[IEEE80211_BAND_2GHZ];
5609 if (band)
5610 for (i = 0; i < band->n_channels; i++)
5611 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
5612 band = wiphy->bands[IEEE80211_BAND_5GHZ];
5613 if (band)
5614 for (i = 0; i < band->n_channels; i++)
5615 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
Hante Meulemand48200b2013-04-03 12:40:29 +02005616
5617 total = le32_to_cpu(list->count);
5618 for (i = 0; i < total; i++) {
Franky Lin83cf17a2013-04-11 13:28:50 +02005619 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5620 cfg->d11inf.decchspec(&ch);
Hante Meulemand48200b2013-04-03 12:40:29 +02005621
Franky Lin83cf17a2013-04-11 13:28:50 +02005622 if (ch.band == BRCMU_CHAN_BAND_2G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005623 band = wiphy->bands[IEEE80211_BAND_2GHZ];
Franky Lin83cf17a2013-04-11 13:28:50 +02005624 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005625 band = wiphy->bands[IEEE80211_BAND_5GHZ];
Hante Meulemand48200b2013-04-03 12:40:29 +02005626 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005627 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
Hante Meulemand48200b2013-04-03 12:40:29 +02005628 continue;
5629 }
Arend van Spriel58de92d2015-04-14 20:10:24 +02005630 if (!band)
5631 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005632 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
Arend van Spriel2375d972014-01-06 12:40:41 +01005633 ch.bw == BRCMU_CHAN_BW_40)
Hante Meulemand48200b2013-04-03 12:40:29 +02005634 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005635 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
Arend van Sprielee942ec2014-05-12 10:47:38 +02005636 ch.bw == BRCMU_CHAN_BW_80)
5637 continue;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005638
5639 channel = band->channels;
5640 index = band->n_channels;
5641 for (j = 0; j < band->n_channels; j++) {
5642 if (channel[j].hw_value == ch.chnum) {
5643 index = j;
Hante Meulemand48200b2013-04-03 12:40:29 +02005644 break;
5645 }
5646 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005647 channel[index].center_freq =
5648 ieee80211_channel_to_frequency(ch.chnum, band->band);
5649 channel[index].hw_value = ch.chnum;
Hante Meulemand48200b2013-04-03 12:40:29 +02005650
Arend van Sprielb48d8912014-07-12 08:49:41 +02005651 /* assuming the chanspecs order is HT20,
5652 * HT40 upper, HT40 lower, and VHT80.
5653 */
5654 if (ch.bw == BRCMU_CHAN_BW_80) {
5655 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5656 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5657 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5658 } else {
Arend van Spriel58de92d2015-04-14 20:10:24 +02005659 /* enable the channel and disable other bandwidths
5660 * for now as mentioned order assure they are enabled
5661 * for subsequent chanspecs.
Arend van Sprielee942ec2014-05-12 10:47:38 +02005662 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02005663 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5664 IEEE80211_CHAN_NO_80MHZ;
5665 ch.bw = BRCMU_CHAN_BW_20;
5666 cfg->d11inf.encchspec(&ch);
5667 chaninfo = ch.chspec;
5668 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5669 &chaninfo);
5670 if (!err) {
5671 if (chaninfo & WL_CHAN_RADAR)
5672 channel[index].flags |=
5673 (IEEE80211_CHAN_RADAR |
5674 IEEE80211_CHAN_NO_IR);
5675 if (chaninfo & WL_CHAN_PASSIVE)
5676 channel[index].flags |=
5677 IEEE80211_CHAN_NO_IR;
Hante Meulemand48200b2013-04-03 12:40:29 +02005678 }
Hante Meulemand48200b2013-04-03 12:40:29 +02005679 }
5680 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005681
Arend van Sprielb48d8912014-07-12 08:49:41 +02005682fail_pbuf:
Hante Meulemand48200b2013-04-03 12:40:29 +02005683 kfree(pbuf);
5684 return err;
5685}
5686
Arend van Sprielb48d8912014-07-12 08:49:41 +02005687static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005688{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005689 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5690 struct ieee80211_supported_band *band;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005691 struct brcmf_fil_bwcap_le band_bwcap;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005692 struct brcmf_chanspec_list *list;
5693 u8 *pbuf;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005694 u32 val;
5695 int err;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005696 struct brcmu_chan ch;
5697 u32 num_chan;
5698 int i, j;
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005699
5700 /* verify support for bw_cap command */
5701 val = WLC_BAND_5G;
5702 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5703
5704 if (!err) {
5705 /* only set 2G bandwidth using bw_cap command */
5706 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5707 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5708 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5709 sizeof(band_bwcap));
5710 } else {
5711 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5712 val = WLC_N_BW_40ALL;
5713 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5714 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02005715
5716 if (!err) {
5717 /* update channel info in 2G band */
5718 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5719
5720 if (pbuf == NULL)
5721 return -ENOMEM;
5722
5723 ch.band = BRCMU_CHAN_BAND_2G;
5724 ch.bw = BRCMU_CHAN_BW_40;
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005725 ch.sb = BRCMU_CHAN_SB_NONE;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005726 ch.chnum = 0;
5727 cfg->d11inf.encchspec(&ch);
5728
5729 /* pass encoded chanspec in query */
5730 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5731
5732 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5733 BRCMF_DCMD_MEDLEN);
5734 if (err) {
5735 brcmf_err("get chanspecs error (%d)\n", err);
5736 kfree(pbuf);
5737 return err;
5738 }
5739
5740 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5741 list = (struct brcmf_chanspec_list *)pbuf;
5742 num_chan = le32_to_cpu(list->count);
5743 for (i = 0; i < num_chan; i++) {
5744 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5745 cfg->d11inf.decchspec(&ch);
5746 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5747 continue;
5748 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5749 continue;
5750 for (j = 0; j < band->n_channels; j++) {
5751 if (band->channels[j].hw_value == ch.chnum)
5752 break;
5753 }
5754 if (WARN_ON(j == band->n_channels))
5755 continue;
5756
5757 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5758 }
Hante Meulemanfac7d2a2014-09-11 22:51:30 +02005759 kfree(pbuf);
Arend van Sprielb48d8912014-07-12 08:49:41 +02005760 }
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005761 return err;
5762}
5763
Arend van Spriel2375d972014-01-06 12:40:41 +01005764static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5765{
5766 u32 band, mimo_bwcap;
5767 int err;
5768
5769 band = WLC_BAND_2G;
5770 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5771 if (!err) {
5772 bw_cap[IEEE80211_BAND_2GHZ] = band;
5773 band = WLC_BAND_5G;
5774 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5775 if (!err) {
5776 bw_cap[IEEE80211_BAND_5GHZ] = band;
5777 return;
5778 }
5779 WARN_ON(1);
5780 return;
5781 }
5782 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5783 mimo_bwcap = 0;
5784 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5785 if (err)
5786 /* assume 20MHz if firmware does not give a clue */
5787 mimo_bwcap = WLC_N_BW_20ALL;
5788
5789 switch (mimo_bwcap) {
5790 case WLC_N_BW_40ALL:
5791 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5792 /* fall-thru */
5793 case WLC_N_BW_20IN2G_40IN5G:
5794 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5795 /* fall-thru */
5796 case WLC_N_BW_20ALL:
5797 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5798 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5799 break;
5800 default:
5801 brcmf_err("invalid mimo_bw_cap value\n");
5802 }
5803}
Hante Meulemand48200b2013-04-03 12:40:29 +02005804
Arend van Spriel18d6c532014-05-12 10:47:35 +02005805static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5806 u32 bw_cap[2], u32 nchain)
5807{
5808 band->ht_cap.ht_supported = true;
5809 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5810 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5811 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5812 }
5813 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5814 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5815 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5816 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5817 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5818 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5819}
5820
5821static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5822{
5823 u16 mcs_map;
5824 int i;
5825
5826 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5827 mcs_map = (mcs_map << 2) | supp;
5828
5829 return cpu_to_le16(mcs_map);
5830}
5831
5832static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005833 u32 bw_cap[2], u32 nchain, u32 txstreams,
5834 u32 txbf_bfe_cap, u32 txbf_bfr_cap)
Arend van Spriel18d6c532014-05-12 10:47:35 +02005835{
5836 __le16 mcs_map;
5837
5838 /* not allowed in 2.4G band */
5839 if (band->band == IEEE80211_BAND_2GHZ)
5840 return;
5841
5842 band->vht_cap.vht_supported = true;
5843 /* 80MHz is mandatory */
5844 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5845 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5846 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5847 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5848 }
5849 /* all support 256-QAM */
5850 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5851 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5852 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005853
5854 /* Beamforming support information */
5855 if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP)
5856 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
5857 if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP)
5858 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
5859 if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP)
5860 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
5861 if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP)
5862 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
5863
5864 if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) {
5865 band->vht_cap.cap |=
5866 (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
5867 band->vht_cap.cap |= ((txstreams - 1) <<
5868 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
5869 band->vht_cap.cap |=
5870 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
5871 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005872}
5873
Arend van Sprielb48d8912014-07-12 08:49:41 +02005874static int brcmf_setup_wiphybands(struct wiphy *wiphy)
Arend van Spriel5b435de2011-10-05 13:19:03 +02005875{
Arend van Sprielb48d8912014-07-12 08:49:41 +02005876 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Sprielac24be62012-10-22 10:36:23 -07005877 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
Arend van Spriel18d6c532014-05-12 10:47:35 +02005878 u32 nmode = 0;
5879 u32 vhtmode = 0;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005880 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
Daniel Kim4aca7a12014-02-25 20:30:36 +01005881 u32 rxchain;
5882 u32 nchain;
Arend van Sprielb48d8912014-07-12 08:49:41 +02005883 int err;
Hante Meulemand48200b2013-04-03 12:40:29 +02005884 s32 i;
Arend van Spriel2375d972014-01-06 12:40:41 +01005885 struct ieee80211_supported_band *band;
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005886 u32 txstreams = 0;
5887 u32 txbf_bfe_cap = 0;
5888 u32 txbf_bfr_cap = 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005889
Arend van Spriel18d6c532014-05-12 10:47:35 +02005890 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
Hante Meulemand48200b2013-04-03 12:40:29 +02005891 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5892 if (err) {
5893 brcmf_err("nmode error (%d)\n", err);
5894 } else {
Arend van Spriel2375d972014-01-06 12:40:41 +01005895 brcmf_get_bwcap(ifp, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005896 }
Arend van Spriel18d6c532014-05-12 10:47:35 +02005897 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5898 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5899 bw_cap[IEEE80211_BAND_5GHZ]);
Hante Meulemand48200b2013-04-03 12:40:29 +02005900
Daniel Kim4aca7a12014-02-25 20:30:36 +01005901 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5902 if (err) {
5903 brcmf_err("rxchain error (%d)\n", err);
5904 nchain = 1;
5905 } else {
5906 for (nchain = 0; rxchain; nchain++)
5907 rxchain = rxchain & (rxchain - 1);
5908 }
5909 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5910
Arend van Sprielb48d8912014-07-12 08:49:41 +02005911 err = brcmf_construct_chaninfo(cfg, bw_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005912 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02005913 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
Hante Meulemand48200b2013-04-03 12:40:29 +02005914 return err;
5915 }
5916
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005917 if (vhtmode) {
5918 (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams);
5919 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap",
5920 &txbf_bfe_cap);
5921 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap",
5922 &txbf_bfr_cap);
5923 }
5924
Arend van Sprielb48d8912014-07-12 08:49:41 +02005925 wiphy = cfg_to_wiphy(cfg);
5926 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5927 band = wiphy->bands[i];
5928 if (band == NULL)
Arend van Spriel2375d972014-01-06 12:40:41 +01005929 continue;
Hante Meulemand48200b2013-04-03 12:40:29 +02005930
Arend van Spriel18d6c532014-05-12 10:47:35 +02005931 if (nmode)
5932 brcmf_update_ht_cap(band, bw_cap, nchain);
5933 if (vhtmode)
Hante Meuleman7bf65aa2015-11-25 11:32:43 +01005934 brcmf_update_vht_cap(band, bw_cap, nchain, txstreams,
5935 txbf_bfe_cap, txbf_bfr_cap);
Hante Meulemand48200b2013-04-03 12:40:29 +02005936 }
5937
Arend van Sprielb48d8912014-07-12 08:49:41 +02005938 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02005939}
5940
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02005941static const struct ieee80211_txrx_stypes
5942brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5943 [NL80211_IFTYPE_STATION] = {
5944 .tx = 0xffff,
5945 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5946 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5947 },
5948 [NL80211_IFTYPE_P2P_CLIENT] = {
5949 .tx = 0xffff,
5950 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5951 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5952 },
5953 [NL80211_IFTYPE_P2P_GO] = {
5954 .tx = 0xffff,
5955 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5956 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5957 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5958 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5959 BIT(IEEE80211_STYPE_AUTH >> 4) |
5960 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5961 BIT(IEEE80211_STYPE_ACTION >> 4)
5962 },
5963 [NL80211_IFTYPE_P2P_DEVICE] = {
5964 .tx = 0xffff,
5965 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5966 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5967 }
5968};
5969
Arend van Spriel0882dda2015-08-20 22:06:03 +02005970/**
5971 * brcmf_setup_ifmodes() - determine interface modes and combinations.
5972 *
5973 * @wiphy: wiphy object.
5974 * @ifp: interface object needed for feat module api.
5975 *
5976 * The interface modes and combinations are determined dynamically here
5977 * based on firmware functionality.
5978 *
5979 * no p2p and no mbss:
5980 *
5981 * #STA <= 1, #AP <= 1, channels = 1, 2 total
5982 *
5983 * no p2p and mbss:
5984 *
5985 * #STA <= 1, #AP <= 1, channels = 1, 2 total
5986 * #AP <= 4, matching BI, channels = 1, 4 total
5987 *
5988 * p2p, no mchan, and mbss:
5989 *
5990 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
5991 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
5992 * #AP <= 4, matching BI, channels = 1, 4 total
5993 *
5994 * p2p, mchan, and mbss:
5995 *
5996 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
5997 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
5998 * #AP <= 4, matching BI, channels = 1, 4 total
5999 */
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006000static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
6001{
6002 struct ieee80211_iface_combination *combo = NULL;
Arend van Spriel0882dda2015-08-20 22:06:03 +02006003 struct ieee80211_iface_limit *c0_limits = NULL;
6004 struct ieee80211_iface_limit *p2p_limits = NULL;
6005 struct ieee80211_iface_limit *mbss_limits = NULL;
6006 bool mbss, p2p;
6007 int i, c, n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006008
Arend van Spriel0882dda2015-08-20 22:06:03 +02006009 mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
6010 p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
6011
6012 n_combos = 1 + !!p2p + !!mbss;
6013 combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006014 if (!combo)
6015 goto err;
6016
Arend van Spriel0882dda2015-08-20 22:06:03 +02006017 c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
6018 if (!c0_limits)
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006019 goto err;
6020
Arend van Spriel0882dda2015-08-20 22:06:03 +02006021 if (p2p) {
6022 p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
6023 if (!p2p_limits)
6024 goto err;
6025 }
6026
6027 if (mbss) {
6028 mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
6029 if (!mbss_limits)
6030 goto err;
6031 }
6032
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006033 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
6034 BIT(NL80211_IFTYPE_ADHOC) |
6035 BIT(NL80211_IFTYPE_AP);
6036
Arend van Spriel0882dda2015-08-20 22:06:03 +02006037 c = 0;
6038 i = 0;
6039 combo[c].num_different_channels = 1;
6040 c0_limits[i].max = 1;
6041 c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6042 if (p2p) {
6043 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
6044 combo[c].num_different_channels = 2;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006045 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
6046 BIT(NL80211_IFTYPE_P2P_GO) |
6047 BIT(NL80211_IFTYPE_P2P_DEVICE);
Arend van Spriel0882dda2015-08-20 22:06:03 +02006048 c0_limits[i].max = 1;
6049 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6050 c0_limits[i].max = 1;
6051 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
6052 BIT(NL80211_IFTYPE_P2P_GO);
6053 } else {
6054 c0_limits[i].max = 1;
6055 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006056 }
Arend van Spriel0882dda2015-08-20 22:06:03 +02006057 combo[c].max_interfaces = i;
6058 combo[c].n_limits = i;
6059 combo[c].limits = c0_limits;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006060
Arend van Spriel0882dda2015-08-20 22:06:03 +02006061 if (p2p) {
6062 c++;
6063 i = 0;
6064 combo[c].num_different_channels = 1;
6065 p2p_limits[i].max = 1;
6066 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
6067 p2p_limits[i].max = 1;
6068 p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
6069 p2p_limits[i].max = 1;
6070 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
6071 p2p_limits[i].max = 1;
6072 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
6073 combo[c].max_interfaces = i;
6074 combo[c].n_limits = i;
6075 combo[c].limits = p2p_limits;
6076 }
6077
6078 if (mbss) {
6079 c++;
6080 combo[c].beacon_int_infra_match = true;
6081 combo[c].num_different_channels = 1;
6082 mbss_limits[0].max = 4;
6083 mbss_limits[0].types = BIT(NL80211_IFTYPE_AP);
6084 combo[c].max_interfaces = 4;
6085 combo[c].n_limits = 1;
6086 combo[c].limits = mbss_limits;
6087 }
6088 wiphy->n_iface_combinations = n_combos;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006089 wiphy->iface_combinations = combo;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006090 return 0;
6091
6092err:
Arend van Spriel0882dda2015-08-20 22:06:03 +02006093 kfree(c0_limits);
6094 kfree(p2p_limits);
6095 kfree(mbss_limits);
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006096 kfree(combo);
6097 return -ENOMEM;
6098}
6099
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006100static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
6101{
6102 /* scheduled scan settings */
6103 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
6104 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
6105 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
6106 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
6107}
6108
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006109#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006110static struct wiphy_wowlan_support brcmf_wowlan_support = {
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006111 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
Hante Meulemanb9a82f82014-10-28 14:56:06 +01006112 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
6113 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
6114 .pattern_min_len = 1,
6115 .max_pkt_offset = 1500,
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006116};
6117#endif
6118
Hante Meuleman3021ad92016-01-05 11:05:45 +01006119static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp)
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006120{
6121#ifdef CONFIG_PM
Hante Meuleman3021ad92016-01-05 11:05:45 +01006122 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
6123 s32 err;
6124 u32 wowl_cap;
6125
6126 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
6127 err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap);
6128 if (!err) {
6129 if (wowl_cap & BRCMF_WOWL_PFN_FOUND) {
6130 brcmf_wowlan_support.flags |=
6131 WIPHY_WOWLAN_NET_DETECT;
6132 init_waitqueue_head(&cfg->wowl.nd_data_wait);
6133 }
6134 }
6135 }
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006136 wiphy->wowlan = &brcmf_wowlan_support;
6137#endif
6138}
6139
Arend van Sprielb48d8912014-07-12 08:49:41 +02006140static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006141{
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006142 struct brcmf_pub *drvr = ifp->drvr;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006143 const struct ieee80211_iface_combination *combo;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006144 struct ieee80211_supported_band *band;
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006145 u16 max_interfaces = 0;
Arend van Spriel58de92d2015-04-14 20:10:24 +02006146 __le32 bandlist[3];
6147 u32 n_bands;
6148 int err, i;
6149
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006150 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
6151 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
Hante Meuleman6c404f32015-12-10 13:43:03 +01006152 wiphy->max_num_pmkids = BRCMF_MAXPMKID;
Pontus Fuchs2e5f66f2015-06-11 00:12:18 +02006153
6154 err = brcmf_setup_ifmodes(wiphy, ifp);
6155 if (err)
6156 return err;
6157
Rafał Miłecki50f32e22015-08-20 00:16:42 +02006158 for (i = 0, combo = wiphy->iface_combinations;
6159 i < wiphy->n_iface_combinations; i++, combo++) {
6160 max_interfaces = max(max_interfaces, combo->max_interfaces);
6161 }
6162
6163 for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
6164 i++) {
Rafa? Mi?eckie3faa862015-07-09 17:07:08 +02006165 u8 *addr = drvr->addresses[i].addr;
6166
6167 memcpy(addr, drvr->mac, ETH_ALEN);
6168 if (i) {
6169 addr[0] |= BIT(1);
6170 addr[ETH_ALEN - 1] ^= i;
6171 }
6172 }
6173 wiphy->addresses = drvr->addresses;
6174 wiphy->n_addresses = i;
6175
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006176 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
6177 wiphy->cipher_suites = __wl_cipher_suites;
6178 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
6179 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
6180 WIPHY_FLAG_OFFCHAN_TX |
Hante Meulemana7b82d42015-12-10 13:43:04 +01006181 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6182 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS))
6183 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Hante Meuleman7d34b052016-01-02 09:41:41 +01006184 if (!ifp->drvr->settings->roamoff)
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006185 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
6186 wiphy->mgmt_stypes = brcmf_txrx_stypes;
6187 wiphy->max_remain_on_channel_duration = 5000;
Arend van Spriel7a7a87d2015-04-14 20:10:27 +02006188 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
6189 brcmf_wiphy_pno_params(wiphy);
Arend van Sprielaa70b4f2014-07-12 08:49:40 +02006190
6191 /* vendor commands/events support */
6192 wiphy->vendor_commands = brcmf_vendor_cmds;
6193 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
6194
Hante Meuleman4eb3af72014-09-30 10:23:18 +02006195 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
Hante Meuleman3021ad92016-01-05 11:05:45 +01006196 brcmf_wiphy_wowl_params(wiphy, ifp);
Arend van Spriel58de92d2015-04-14 20:10:24 +02006197 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
6198 sizeof(bandlist));
6199 if (err) {
6200 brcmf_err("could not obtain band info: err=%d\n", err);
6201 return err;
6202 }
6203 /* first entry in bandlist is number of bands */
6204 n_bands = le32_to_cpu(bandlist[0]);
6205 for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
6206 if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
6207 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
6208 GFP_KERNEL);
6209 if (!band)
6210 return -ENOMEM;
6211
6212 band->channels = kmemdup(&__wl_2ghz_channels,
6213 sizeof(__wl_2ghz_channels),
6214 GFP_KERNEL);
6215 if (!band->channels) {
6216 kfree(band);
6217 return -ENOMEM;
6218 }
6219
6220 band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
6221 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6222 }
6223 if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
6224 band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
6225 GFP_KERNEL);
6226 if (!band)
6227 return -ENOMEM;
6228
6229 band->channels = kmemdup(&__wl_5ghz_channels,
6230 sizeof(__wl_5ghz_channels),
6231 GFP_KERNEL);
6232 if (!band->channels) {
6233 kfree(band);
6234 return -ENOMEM;
6235 }
6236
6237 band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
6238 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6239 }
6240 }
6241 err = brcmf_setup_wiphybands(wiphy);
6242 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006243}
6244
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006245static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006246{
6247 struct net_device *ndev;
6248 struct wireless_dev *wdev;
Hante Meuleman40a23292013-01-02 15:22:51 +01006249 struct brcmf_if *ifp;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006250 s32 power_mode;
6251 s32 err = 0;
6252
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006253 if (cfg->dongle_up)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006254 return err;
6255
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006256 ndev = cfg_to_ndev(cfg);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006257 wdev = ndev->ieee80211_ptr;
Hante Meuleman40a23292013-01-02 15:22:51 +01006258 ifp = netdev_priv(ndev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006259
Hante Meuleman40a23292013-01-02 15:22:51 +01006260 /* make sure RF is ready for work */
6261 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
6262
Hante Meuleman1678ba82015-12-10 13:43:00 +01006263 brcmf_dongle_scantime(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006264
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006265 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
Hante Meuleman40a23292013-01-02 15:22:51 +01006266 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006267 if (err)
6268 goto default_conf_out;
Arend van Spriel647c9ae2012-12-05 15:26:01 +01006269 brcmf_dbg(INFO, "power save set to %s\n",
6270 (power_mode ? "enabled" : "disabled"));
Arend van Spriel5b435de2011-10-05 13:19:03 +02006271
Hante Meuleman1119e232015-11-25 11:32:42 +01006272 err = brcmf_dongle_roam(ifp);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006273 if (err)
6274 goto default_conf_out;
Franky Lin5dd161f2012-10-10 11:13:10 -07006275 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
6276 NULL, NULL);
Hante Meuleman40a23292013-01-02 15:22:51 +01006277 if (err)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006278 goto default_conf_out;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006279
Hante Meulemanb3657452013-05-27 21:09:53 +02006280 brcmf_configure_arp_offload(ifp, true);
6281
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006282 cfg->dongle_up = true;
Hante Meuleman40a23292013-01-02 15:22:51 +01006283default_conf_out:
Arend van Spriel5b435de2011-10-05 13:19:03 +02006284
6285 return err;
6286
6287}
6288
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006289static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006290{
Arend van Sprielc1179032012-10-22 13:55:33 -07006291 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006292
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006293 return brcmf_config_dongle(ifp->drvr->config);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006294}
6295
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006296static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006297{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006298 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Sprielc1179032012-10-22 13:55:33 -07006299
Arend van Spriel5b435de2011-10-05 13:19:03 +02006300 /*
6301 * While going down, if associated with AP disassociate
6302 * from AP to save power
6303 */
Arend van Spriel903e0ee2012-11-28 21:44:11 +01006304 if (check_vif_up(ifp->vif)) {
Arend van Spriel9b7a0dd2015-01-25 20:31:33 +01006305 brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006306
6307 /* Make sure WPA_Supplicant receives all the event
6308 generated due to DISASSOC call to the fw to keep
6309 the state fw and WPA_Supplicant state consistent
6310 */
6311 brcmf_delay(500);
6312 }
6313
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006314 brcmf_abort_scanning(cfg);
Arend van Sprielc1179032012-10-22 13:55:33 -07006315 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006316
Arend van Spriel5b435de2011-10-05 13:19:03 +02006317 return 0;
6318}
6319
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006320s32 brcmf_cfg80211_up(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006321{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006322 struct brcmf_if *ifp = netdev_priv(ndev);
6323 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006324 s32 err = 0;
6325
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006326 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006327 err = __brcmf_cfg80211_up(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006328 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006329
6330 return err;
6331}
6332
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006333s32 brcmf_cfg80211_down(struct net_device *ndev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02006334{
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006335 struct brcmf_if *ifp = netdev_priv(ndev);
6336 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
Arend van Spriel5b435de2011-10-05 13:19:03 +02006337 s32 err = 0;
6338
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006339 mutex_lock(&cfg->usr_sync);
Arend van Sprielbdf5ff52012-11-14 18:46:09 -08006340 err = __brcmf_cfg80211_down(ifp);
Arend van Spriel27a68fe2012-09-27 14:17:55 +02006341 mutex_unlock(&cfg->usr_sync);
Arend van Spriel5b435de2011-10-05 13:19:03 +02006342
6343 return err;
6344}
6345
Arend van Spriela7965fb2013-04-11 17:08:37 +02006346enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
6347{
6348 struct wireless_dev *wdev = &ifp->vif->wdev;
6349
6350 return wdev->iftype;
6351}
6352
Hante Meulemanbfe81972014-10-28 14:56:16 +01006353bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
6354 unsigned long state)
Arend van Spriel9f440b72013-02-08 15:53:36 +01006355{
6356 struct brcmf_cfg80211_vif *vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006357
6358 list_for_each_entry(vif, &cfg->vif_list, list) {
6359 if (test_bit(state, &vif->sme_state))
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006360 return true;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006361 }
Rasmus Villemoese843bb12014-06-22 20:50:40 +02006362 return false;
Arend van Spriel9f440b72013-02-08 15:53:36 +01006363}
Arend van Sprield3c0b632013-02-08 15:53:37 +01006364
6365static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
6366 u8 action)
6367{
6368 u8 evt_action;
6369
6370 mutex_lock(&event->vif_event_lock);
6371 evt_action = event->action;
6372 mutex_unlock(&event->vif_event_lock);
6373 return evt_action == action;
6374}
6375
6376void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
6377 struct brcmf_cfg80211_vif *vif)
6378{
6379 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6380
6381 mutex_lock(&event->vif_event_lock);
6382 event->vif = vif;
6383 event->action = 0;
6384 mutex_unlock(&event->vif_event_lock);
6385}
6386
6387bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
6388{
6389 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6390 bool armed;
6391
6392 mutex_lock(&event->vif_event_lock);
6393 armed = event->vif != NULL;
6394 mutex_unlock(&event->vif_event_lock);
6395
6396 return armed;
6397}
6398int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
6399 u8 action, ulong timeout)
6400{
6401 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6402
6403 return wait_event_timeout(event->vif_wq,
6404 vif_event_equals(event, action), timeout);
6405}
6406
Arend van Spriel63db1a42014-12-21 12:43:51 +01006407static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
6408 struct regulatory_request *req)
6409{
6410 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
6411 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
6412 struct brcmf_fil_country_le ccreq;
6413 int i;
6414
6415 brcmf_dbg(TRACE, "enter: initiator=%d, alpha=%c%c\n", req->initiator,
6416 req->alpha2[0], req->alpha2[1]);
6417
6418 /* ignore non-ISO3166 country codes */
6419 for (i = 0; i < sizeof(req->alpha2); i++)
6420 if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
6421 brcmf_err("not a ISO3166 code\n");
6422 return;
6423 }
6424 memset(&ccreq, 0, sizeof(ccreq));
6425 ccreq.rev = cpu_to_le32(-1);
6426 memcpy(ccreq.ccode, req->alpha2, sizeof(req->alpha2));
Arend van Spriel8afe0ec2015-04-14 20:10:25 +02006427 if (brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq))) {
6428 brcmf_err("firmware rejected country setting\n");
6429 return;
6430 }
6431 brcmf_setup_wiphybands(wiphy);
Arend van Spriel63db1a42014-12-21 12:43:51 +01006432}
6433
Arend van Sprielb48d8912014-07-12 08:49:41 +02006434static void brcmf_free_wiphy(struct wiphy *wiphy)
6435{
Arend van Spriel0882dda2015-08-20 22:06:03 +02006436 int i;
6437
Arend van Spriel58de92d2015-04-14 20:10:24 +02006438 if (!wiphy)
6439 return;
6440
Arend van Spriel0882dda2015-08-20 22:06:03 +02006441 if (wiphy->iface_combinations) {
6442 for (i = 0; i < wiphy->n_iface_combinations; i++)
6443 kfree(wiphy->iface_combinations[i].limits);
6444 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006445 kfree(wiphy->iface_combinations);
6446 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
6447 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
6448 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
6449 }
6450 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
6451 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
6452 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
6453 }
6454 wiphy_free(wiphy);
6455}
6456
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006457struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006458 struct device *busdev,
6459 bool p2pdev_forced)
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006460{
Arend van Spriel46f3b6e2015-08-26 22:14:58 +02006461 struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006462 struct brcmf_cfg80211_info *cfg;
6463 struct wiphy *wiphy;
6464 struct brcmf_cfg80211_vif *vif;
6465 struct brcmf_if *ifp;
6466 s32 err = 0;
6467 s32 io_type;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006468 u16 *cap = NULL;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006469
6470 if (!ndev) {
6471 brcmf_err("ndev is invalid\n");
6472 return NULL;
6473 }
6474
6475 ifp = netdev_priv(ndev);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006476 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
6477 if (!wiphy) {
6478 brcmf_err("Could not allocate wiphy device\n");
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006479 return NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006480 }
Rafał Miłecki6896f4f2015-05-31 02:52:26 +02006481 memcpy(wiphy->perm_addr, drvr->mac, ETH_ALEN);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006482 set_wiphy_dev(wiphy, busdev);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006483
6484 cfg = wiphy_priv(wiphy);
6485 cfg->wiphy = wiphy;
6486 cfg->pub = drvr;
6487 init_vif_event(&cfg->vif_event);
6488 INIT_LIST_HEAD(&cfg->vif_list);
6489
6490 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006491 if (IS_ERR(vif))
6492 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006493
6494 vif->ifp = ifp;
6495 vif->wdev.netdev = ndev;
6496 ndev->ieee80211_ptr = &vif->wdev;
6497 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
6498
6499 err = wl_init_priv(cfg);
6500 if (err) {
6501 brcmf_err("Failed to init iwm_priv (%d)\n", err);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006502 brcmf_free_vif(vif);
6503 goto wiphy_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006504 }
6505 ifp->vif = vif;
6506
Arend van Sprielb48d8912014-07-12 08:49:41 +02006507 /* determine d11 io type before wiphy setup */
6508 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006509 if (err) {
Arend van Sprielb48d8912014-07-12 08:49:41 +02006510 brcmf_err("Failed to get D11 version (%d)\n", err);
6511 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006512 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006513 cfg->d11inf.io_type = (u8)io_type;
6514 brcmu_d11_attach(&cfg->d11inf);
6515
6516 err = brcmf_setup_wiphy(wiphy, ifp);
6517 if (err < 0)
6518 goto priv_out;
6519
6520 brcmf_dbg(INFO, "Registering custom regulatory\n");
Arend van Spriel63db1a42014-12-21 12:43:51 +01006521 wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006522 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
6523 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
6524
6525 /* firmware defaults to 40MHz disabled in 2G band. We signal
6526 * cfg80211 here that we do and have it decide we can enable
6527 * it. But first check if device does support 2G operation.
6528 */
6529 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
6530 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
6531 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6532 }
6533 err = wiphy_register(wiphy);
6534 if (err < 0) {
6535 brcmf_err("Could not register wiphy device (%d)\n", err);
6536 goto priv_out;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006537 }
6538
6539 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
6540 * setup 40MHz in 2GHz band and enable OBSS scanning.
6541 */
Arend van Sprielb48d8912014-07-12 08:49:41 +02006542 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
6543 err = brcmf_enable_bw40_2g(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006544 if (!err)
6545 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
6546 BRCMF_OBSS_COEX_AUTO);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006547 else
6548 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006549 }
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006550 /* p2p might require that "if-events" get processed by fweh. So
6551 * activate the already registered event handlers now and activate
6552 * the rest when initialization has completed. drvr->config needs to
6553 * be assigned before activating events.
6554 */
6555 drvr->config = cfg;
6556 err = brcmf_fweh_activate_events(ifp);
6557 if (err) {
6558 brcmf_err("FWEH activation failed (%d)\n", err);
6559 goto wiphy_unreg_out;
6560 }
Arend van Sprielb48d8912014-07-12 08:49:41 +02006561
Hante Meulemanae7c03f2015-09-18 22:08:08 +02006562 err = brcmf_p2p_attach(cfg, p2pdev_forced);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006563 if (err) {
6564 brcmf_err("P2P initilisation failed (%d)\n", err);
6565 goto wiphy_unreg_out;
6566 }
6567 err = brcmf_btcoex_attach(cfg);
6568 if (err) {
6569 brcmf_err("BT-coex initialisation failed (%d)\n", err);
6570 brcmf_p2p_detach(&cfg->p2p);
6571 goto wiphy_unreg_out;
6572 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006573
Hante Meulemana7b82d42015-12-10 13:43:04 +01006574 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) {
6575 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
6576 if (err) {
6577 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
6578 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
6579 } else {
6580 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
6581 brcmf_notify_tdls_peer_event);
6582 }
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006583 }
6584
Hante Meuleman2b76acd2015-10-08 20:33:15 +02006585 /* (re-) activate FWEH event handling */
6586 err = brcmf_fweh_activate_events(ifp);
6587 if (err) {
6588 brcmf_err("FWEH activation failed (%d)\n", err);
6589 goto wiphy_unreg_out;
6590 }
6591
Hante Meuleman48ed16e2016-01-02 09:41:38 +01006592 /* Fill in some of the advertised nl80211 supported features */
6593 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) {
6594 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6595#ifdef CONFIG_PM
6596 if (wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT)
6597 wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6598#endif
6599 }
6600
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006601 return cfg;
6602
Arend van Sprielb48d8912014-07-12 08:49:41 +02006603wiphy_unreg_out:
6604 wiphy_unregister(cfg->wiphy);
6605priv_out:
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006606 wl_deinit_priv(cfg);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006607 brcmf_free_vif(vif);
Hante Meuleman2b5d3482015-09-18 22:08:04 +02006608 ifp->vif = NULL;
Arend van Sprielb48d8912014-07-12 08:49:41 +02006609wiphy_out:
6610 brcmf_free_wiphy(wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006611 return NULL;
6612}
6613
6614void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
6615{
6616 if (!cfg)
6617 return;
6618
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006619 brcmf_btcoex_detach(cfg);
Arend van Sprielf7a40872015-06-11 00:12:23 +02006620 wiphy_unregister(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006621 wl_deinit_priv(cfg);
Arend van Sprielb48d8912014-07-12 08:49:41 +02006622 brcmf_free_wiphy(cfg->wiphy);
Arend van Sprielccfd1e82014-07-12 08:49:38 +02006623}