Commit | Line | Data |
---|---|---|
5b435de0 AS |
1 | /* |
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> | |
5b435de0 | 20 | #include <linux/etherdevice.h> |
68ca395f | 21 | #include <linux/module.h> |
1bacb048 | 22 | #include <linux/vmalloc.h> |
5b435de0 | 23 | #include <net/cfg80211.h> |
cbaa177d | 24 | #include <net/netlink.h> |
5b435de0 AS |
25 | |
26 | #include <brcmu_utils.h> | |
27 | #include <defs.h> | |
28 | #include <brcmu_wifi.h> | |
29 | #include "dhd.h" | |
16886735 | 30 | #include "dhd_dbg.h" |
40c1c249 | 31 | #include "tracepoint.h" |
7a5c1f64 | 32 | #include "fwil_types.h" |
9f440b7b | 33 | #include "p2p.h" |
61730d4d | 34 | #include "btcoex.h" |
5b435de0 | 35 | #include "wl_cfg80211.h" |
c08437b4 | 36 | #include "feature.h" |
81f5dcb8 | 37 | #include "fwil.h" |
8851cce0 | 38 | #include "proto.h" |
1bacb048 | 39 | #include "vendor.h" |
4eb3af7c | 40 | #include "dhd_bus.h" |
5b435de0 | 41 | |
e5806072 AS |
42 | #define BRCMF_SCAN_IE_LEN_MAX 2048 |
43 | #define BRCMF_PNO_VERSION 2 | |
44 | #define BRCMF_PNO_TIME 30 | |
45 | #define BRCMF_PNO_REPEAT 4 | |
46 | #define BRCMF_PNO_FREQ_EXPO_MAX 3 | |
47 | #define BRCMF_PNO_MAX_PFN_COUNT 16 | |
48 | #define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6 | |
49 | #define BRCMF_PNO_HIDDEN_BIT 2 | |
50 | #define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF | |
51 | #define BRCMF_PNO_SCAN_COMPLETE 1 | |
52 | #define BRCMF_PNO_SCAN_INCOMPLETE 0 | |
53 | ||
9f440b7b | 54 | #define BRCMF_IFACE_MAX_CNT 3 |
3eacf866 | 55 | |
1a873342 HM |
56 | #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */ |
57 | #define WPA_OUI_TYPE 1 | |
58 | #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */ | |
59 | #define WME_OUI_TYPE 2 | |
89286dc9 | 60 | #define WPS_OUI_TYPE 4 |
1a873342 HM |
61 | |
62 | #define VS_IE_FIXED_HDR_LEN 6 | |
63 | #define WPA_IE_VERSION_LEN 2 | |
64 | #define WPA_IE_MIN_OUI_LEN 4 | |
65 | #define WPA_IE_SUITE_COUNT_LEN 2 | |
66 | ||
67 | #define WPA_CIPHER_NONE 0 /* None */ | |
68 | #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */ | |
69 | #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */ | |
70 | #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */ | |
71 | #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */ | |
72 | ||
73 | #define RSN_AKM_NONE 0 /* None (IBSS) */ | |
74 | #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */ | |
75 | #define RSN_AKM_PSK 2 /* Pre-shared Key */ | |
76 | #define RSN_CAP_LEN 2 /* Length of RSN capabilities */ | |
77 | #define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C | |
78 | ||
79 | #define VNDR_IE_CMD_LEN 4 /* length of the set command | |
80 | * string :"add", "del" (+ NUL) | |
81 | */ | |
82 | #define VNDR_IE_COUNT_OFFSET 4 | |
83 | #define VNDR_IE_PKTFLAG_OFFSET 8 | |
84 | #define VNDR_IE_VSIE_OFFSET 12 | |
85 | #define VNDR_IE_HDR_SIZE 12 | |
9f440b7b | 86 | #define VNDR_IE_PARSE_LIMIT 5 |
1a873342 HM |
87 | |
88 | #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */ | |
89 | #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */ | |
04012895 | 90 | |
89286dc9 HM |
91 | #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320 |
92 | #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400 | |
93 | #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20 | |
94 | ||
5b435de0 AS |
95 | #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \ |
96 | (sizeof(struct brcmf_assoc_params_le) - sizeof(u16)) | |
97 | ||
ce81e317 | 98 | static bool check_vif_up(struct brcmf_cfg80211_vif *vif) |
5b435de0 | 99 | { |
c1179033 | 100 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) { |
647c9ae0 AS |
101 | brcmf_dbg(INFO, "device is not ready : status (%lu)\n", |
102 | vif->sme_state); | |
5b435de0 AS |
103 | return false; |
104 | } | |
105 | return true; | |
106 | } | |
107 | ||
5b435de0 AS |
108 | #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2) |
109 | #define RATETAB_ENT(_rateid, _flags) \ | |
110 | { \ | |
111 | .bitrate = RATE_TO_BASE100KBPS(_rateid), \ | |
112 | .hw_value = (_rateid), \ | |
113 | .flags = (_flags), \ | |
114 | } | |
115 | ||
116 | static struct ieee80211_rate __wl_rates[] = { | |
117 | RATETAB_ENT(BRCM_RATE_1M, 0), | |
118 | RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE), | |
119 | RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE), | |
120 | RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE), | |
121 | RATETAB_ENT(BRCM_RATE_6M, 0), | |
122 | RATETAB_ENT(BRCM_RATE_9M, 0), | |
123 | RATETAB_ENT(BRCM_RATE_12M, 0), | |
124 | RATETAB_ENT(BRCM_RATE_18M, 0), | |
125 | RATETAB_ENT(BRCM_RATE_24M, 0), | |
126 | RATETAB_ENT(BRCM_RATE_36M, 0), | |
127 | RATETAB_ENT(BRCM_RATE_48M, 0), | |
128 | RATETAB_ENT(BRCM_RATE_54M, 0), | |
129 | }; | |
130 | ||
131 | #define wl_a_rates (__wl_rates + 4) | |
132 | #define wl_a_rates_size 8 | |
133 | #define wl_g_rates (__wl_rates + 0) | |
134 | #define wl_g_rates_size 12 | |
135 | ||
b48d8916 AS |
136 | /* Band templates duplicated per wiphy. The channel info |
137 | * is filled in after querying the device. | |
138 | */ | |
139 | static const struct ieee80211_supported_band __wl_band_2ghz = { | |
5b435de0 | 140 | .band = IEEE80211_BAND_2GHZ, |
5b435de0 AS |
141 | .bitrates = wl_g_rates, |
142 | .n_bitrates = wl_g_rates_size, | |
143 | }; | |
144 | ||
b48d8916 | 145 | static const struct ieee80211_supported_band __wl_band_5ghz_a = { |
5b435de0 | 146 | .band = IEEE80211_BAND_5GHZ, |
5b435de0 AS |
147 | .bitrates = wl_a_rates, |
148 | .n_bitrates = wl_a_rates_size, | |
149 | }; | |
150 | ||
d48200ba HM |
151 | /* This is to override regulatory domains defined in cfg80211 module (reg.c) |
152 | * By default world regulatory domain defined in reg.c puts the flags | |
8fe02e16 LR |
153 | * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165). |
154 | * With respect to these flags, wpa_supplicant doesn't * start p2p | |
155 | * operations on 5GHz channels. All the changes in world regulatory | |
d48200ba HM |
156 | * domain are to be done here. |
157 | */ | |
158 | static const struct ieee80211_regdomain brcmf_regdom = { | |
159 | .n_reg_rules = 4, | |
160 | .alpha2 = "99", | |
161 | .reg_rules = { | |
162 | /* IEEE 802.11b/g, channels 1..11 */ | |
163 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), | |
164 | /* If any */ | |
165 | /* IEEE 802.11 channel 14 - Only JP enables | |
166 | * this and for 802.11b only | |
167 | */ | |
168 | REG_RULE(2484-10, 2484+10, 20, 6, 20, 0), | |
169 | /* IEEE 802.11a, channel 36..64 */ | |
c555ecde | 170 | REG_RULE(5150-10, 5350+10, 80, 6, 20, 0), |
d48200ba | 171 | /* IEEE 802.11a, channel 100..165 */ |
c555ecde | 172 | REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), } |
5b435de0 AS |
173 | }; |
174 | ||
175 | static const u32 __wl_cipher_suites[] = { | |
176 | WLAN_CIPHER_SUITE_WEP40, | |
177 | WLAN_CIPHER_SUITE_WEP104, | |
178 | WLAN_CIPHER_SUITE_TKIP, | |
179 | WLAN_CIPHER_SUITE_CCMP, | |
180 | WLAN_CIPHER_SUITE_AES_CMAC, | |
181 | }; | |
182 | ||
1a873342 HM |
183 | /* Vendor specific ie. id = 221, oui and type defines exact ie */ |
184 | struct brcmf_vs_tlv { | |
185 | u8 id; | |
186 | u8 len; | |
187 | u8 oui[3]; | |
188 | u8 oui_type; | |
189 | }; | |
190 | ||
191 | struct parsed_vndr_ie_info { | |
192 | u8 *ie_ptr; | |
193 | u32 ie_len; /* total length including id & length field */ | |
194 | struct brcmf_vs_tlv vndrie; | |
195 | }; | |
196 | ||
197 | struct parsed_vndr_ies { | |
198 | u32 count; | |
9f440b7b | 199 | struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT]; |
1a873342 HM |
200 | }; |
201 | ||
68ca395f HM |
202 | static int brcmf_roamoff; |
203 | module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR); | |
204 | MODULE_PARM_DESC(roamoff, "do not use internal roaming engine"); | |
205 | ||
ef6ac17a AB |
206 | /* Quarter dBm units to mW |
207 | * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153 | |
208 | * Table is offset so the last entry is largest mW value that fits in | |
209 | * a u16. | |
210 | */ | |
211 | ||
212 | #define QDBM_OFFSET 153 /* Offset for first entry */ | |
213 | #define QDBM_TABLE_LEN 40 /* Table size */ | |
214 | ||
215 | /* Smallest mW value that will round up to the first table entry, QDBM_OFFSET. | |
216 | * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2 | |
217 | */ | |
218 | #define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */ | |
219 | ||
220 | /* Largest mW value that will round down to the last table entry, | |
221 | * QDBM_OFFSET + QDBM_TABLE_LEN-1. | |
222 | * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) + | |
223 | * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2. | |
224 | */ | |
225 | #define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */ | |
226 | ||
227 | static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = { | |
228 | /* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */ | |
229 | /* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000, | |
230 | /* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849, | |
231 | /* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119, | |
232 | /* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811, | |
233 | /* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096 | |
234 | }; | |
235 | ||
236 | static u16 brcmf_qdbm_to_mw(u8 qdbm) | |
237 | { | |
238 | uint factor = 1; | |
239 | int idx = qdbm - QDBM_OFFSET; | |
240 | ||
241 | if (idx >= QDBM_TABLE_LEN) | |
242 | /* clamp to max u16 mW value */ | |
243 | return 0xFFFF; | |
244 | ||
245 | /* scale the qdBm index up to the range of the table 0-40 | |
246 | * where an offset of 40 qdBm equals a factor of 10 mW. | |
247 | */ | |
248 | while (idx < 0) { | |
249 | idx += 40; | |
250 | factor *= 10; | |
251 | } | |
252 | ||
253 | /* return the mW value scaled down to the correct factor of 10, | |
254 | * adding in factor/2 to get proper rounding. | |
255 | */ | |
256 | return (nqdBm_to_mW_map[idx] + factor / 2) / factor; | |
257 | } | |
258 | ||
259 | static u8 brcmf_mw_to_qdbm(u16 mw) | |
260 | { | |
261 | u8 qdbm; | |
262 | int offset; | |
263 | uint mw_uint = mw; | |
264 | uint boundary; | |
265 | ||
266 | /* handle boundary case */ | |
267 | if (mw_uint <= 1) | |
268 | return 0; | |
269 | ||
270 | offset = QDBM_OFFSET; | |
271 | ||
272 | /* move mw into the range of the table */ | |
273 | while (mw_uint < QDBM_TABLE_LOW_BOUND) { | |
274 | mw_uint *= 10; | |
275 | offset -= 40; | |
276 | } | |
277 | ||
278 | for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) { | |
279 | boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] - | |
280 | nqdBm_to_mW_map[qdbm]) / 2; | |
281 | if (mw_uint < boundary) | |
282 | break; | |
283 | } | |
284 | ||
285 | qdbm += (u8) offset; | |
286 | ||
287 | return qdbm; | |
288 | } | |
289 | ||
5a394eba AS |
290 | static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, |
291 | struct cfg80211_chan_def *ch) | |
600a897d AS |
292 | { |
293 | struct brcmu_chan ch_inf; | |
294 | s32 primary_offset; | |
295 | ||
296 | brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n", | |
297 | ch->chan->center_freq, ch->center_freq1, ch->width); | |
298 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1); | |
299 | primary_offset = ch->center_freq1 - ch->chan->center_freq; | |
300 | switch (ch->width) { | |
301 | case NL80211_CHAN_WIDTH_20: | |
302 | ch_inf.bw = BRCMU_CHAN_BW_20; | |
303 | WARN_ON(primary_offset != 0); | |
304 | break; | |
305 | case NL80211_CHAN_WIDTH_40: | |
306 | ch_inf.bw = BRCMU_CHAN_BW_40; | |
307 | if (primary_offset < 0) | |
308 | ch_inf.sb = BRCMU_CHAN_SB_U; | |
309 | else | |
310 | ch_inf.sb = BRCMU_CHAN_SB_L; | |
311 | break; | |
312 | case NL80211_CHAN_WIDTH_80: | |
313 | ch_inf.bw = BRCMU_CHAN_BW_80; | |
314 | if (primary_offset < 0) { | |
315 | if (primary_offset < -CH_10MHZ_APART) | |
316 | ch_inf.sb = BRCMU_CHAN_SB_UU; | |
317 | else | |
318 | ch_inf.sb = BRCMU_CHAN_SB_UL; | |
319 | } else { | |
320 | if (primary_offset > CH_10MHZ_APART) | |
321 | ch_inf.sb = BRCMU_CHAN_SB_LL; | |
322 | else | |
323 | ch_inf.sb = BRCMU_CHAN_SB_LU; | |
324 | } | |
325 | break; | |
326 | default: | |
327 | WARN_ON_ONCE(1); | |
328 | } | |
329 | switch (ch->chan->band) { | |
330 | case IEEE80211_BAND_2GHZ: | |
331 | ch_inf.band = BRCMU_CHAN_BAND_2G; | |
332 | break; | |
333 | case IEEE80211_BAND_5GHZ: | |
334 | ch_inf.band = BRCMU_CHAN_BAND_5G; | |
335 | break; | |
336 | default: | |
337 | WARN_ON_ONCE(1); | |
338 | } | |
339 | d11inf->encchspec(&ch_inf); | |
340 | ||
341 | return ch_inf.chspec; | |
342 | } | |
343 | ||
83cf17aa FL |
344 | u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, |
345 | struct ieee80211_channel *ch) | |
6e186166 | 346 | { |
83cf17aa | 347 | struct brcmu_chan ch_inf; |
6e186166 | 348 | |
83cf17aa FL |
349 | ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq); |
350 | ch_inf.bw = BRCMU_CHAN_BW_20; | |
351 | d11inf->encchspec(&ch_inf); | |
6e186166 | 352 | |
83cf17aa | 353 | return ch_inf.chspec; |
6e186166 AS |
354 | } |
355 | ||
89286dc9 HM |
356 | /* Traverse a string of 1-byte tag/1-byte length/variable-length value |
357 | * triples, returning a pointer to the substring whose first element | |
358 | * matches tag | |
359 | */ | |
4b5800fe JB |
360 | const struct brcmf_tlv * |
361 | brcmf_parse_tlvs(const void *buf, int buflen, uint key) | |
89286dc9 | 362 | { |
4b5800fe JB |
363 | const struct brcmf_tlv *elt = buf; |
364 | int totlen = buflen; | |
89286dc9 HM |
365 | |
366 | /* find tagged parameter */ | |
367 | while (totlen >= TLV_HDR_LEN) { | |
368 | int len = elt->len; | |
369 | ||
370 | /* validate remaining totlen */ | |
371 | if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN))) | |
372 | return elt; | |
373 | ||
374 | elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN)); | |
375 | totlen -= (len + TLV_HDR_LEN); | |
376 | } | |
377 | ||
378 | return NULL; | |
379 | } | |
380 | ||
381 | /* Is any of the tlvs the expected entry? If | |
382 | * not update the tlvs buffer pointer/length. | |
383 | */ | |
384 | static bool | |
4b5800fe JB |
385 | brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len, |
386 | const u8 *oui, u32 oui_len, u8 type) | |
89286dc9 HM |
387 | { |
388 | /* If the contents match the OUI and the type */ | |
389 | if (ie[TLV_LEN_OFF] >= oui_len + 1 && | |
390 | !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) && | |
391 | type == ie[TLV_BODY_OFF + oui_len]) { | |
392 | return true; | |
393 | } | |
394 | ||
395 | if (tlvs == NULL) | |
396 | return false; | |
397 | /* point to the next ie */ | |
398 | ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN; | |
399 | /* calculate the length of the rest of the buffer */ | |
400 | *tlvs_len -= (int)(ie - *tlvs); | |
401 | /* update the pointer to the start of the buffer */ | |
402 | *tlvs = ie; | |
403 | ||
404 | return false; | |
405 | } | |
406 | ||
407 | static struct brcmf_vs_tlv * | |
4b5800fe | 408 | brcmf_find_wpaie(const u8 *parse, u32 len) |
89286dc9 | 409 | { |
4b5800fe | 410 | const struct brcmf_tlv *ie; |
89286dc9 HM |
411 | |
412 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { | |
4b5800fe | 413 | if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len, |
89286dc9 HM |
414 | WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE)) |
415 | return (struct brcmf_vs_tlv *)ie; | |
416 | } | |
417 | return NULL; | |
418 | } | |
419 | ||
420 | static struct brcmf_vs_tlv * | |
4b5800fe | 421 | brcmf_find_wpsie(const u8 *parse, u32 len) |
89286dc9 | 422 | { |
4b5800fe | 423 | const struct brcmf_tlv *ie; |
89286dc9 HM |
424 | |
425 | while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) { | |
426 | if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len, | |
427 | WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE)) | |
428 | return (struct brcmf_vs_tlv *)ie; | |
429 | } | |
430 | return NULL; | |
431 | } | |
432 | ||
433 | ||
5b435de0 AS |
434 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
435 | struct brcmf_wsec_key_le *key_le) | |
436 | { | |
437 | key_le->index = cpu_to_le32(key->index); | |
438 | key_le->len = cpu_to_le32(key->len); | |
439 | key_le->algo = cpu_to_le32(key->algo); | |
440 | key_le->flags = cpu_to_le32(key->flags); | |
441 | key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi); | |
442 | key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo); | |
443 | key_le->iv_initialized = cpu_to_le32(key->iv_initialized); | |
444 | memcpy(key_le->data, key->data, sizeof(key->data)); | |
445 | memcpy(key_le->ea, key->ea, sizeof(key->ea)); | |
446 | } | |
447 | ||
f09d0c02 | 448 | static int |
2eaba7e8 | 449 | send_key_to_dongle(struct net_device *ndev, struct brcmf_wsec_key *key) |
5b435de0 AS |
450 | { |
451 | int err; | |
452 | struct brcmf_wsec_key_le key_le; | |
453 | ||
454 | convert_key_from_CPU(key, &key_le); | |
f09d0c02 | 455 | |
81f5dcb8 HM |
456 | brcmf_netdev_wait_pend8021x(ndev); |
457 | ||
ac24be6f | 458 | err = brcmf_fil_bsscfg_data_set(netdev_priv(ndev), "wsec_key", &key_le, |
81f5dcb8 | 459 | sizeof(key_le)); |
f09d0c02 | 460 | |
5b435de0 | 461 | if (err) |
57d6e91a | 462 | brcmf_err("wsec_key error (%d)\n", err); |
5b435de0 AS |
463 | return err; |
464 | } | |
465 | ||
b3657453 HM |
466 | static s32 |
467 | brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable) | |
468 | { | |
469 | s32 err; | |
470 | u32 mode; | |
471 | ||
472 | if (enable) | |
473 | mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; | |
474 | else | |
475 | mode = 0; | |
476 | ||
477 | /* Try to set and enable ARP offload feature, this may fail, then it */ | |
478 | /* is simply not supported and err 0 will be returned */ | |
479 | err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); | |
480 | if (err) { | |
481 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", | |
482 | mode, err); | |
483 | err = 0; | |
484 | } else { | |
485 | err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); | |
486 | if (err) { | |
487 | brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", | |
488 | enable, err); | |
489 | err = 0; | |
490 | } else | |
491 | brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", | |
492 | enable, mode); | |
493 | } | |
494 | ||
495 | return err; | |
496 | } | |
497 | ||
8851cce0 HM |
498 | static void |
499 | brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev) | |
500 | { | |
8f2b4597 AS |
501 | struct brcmf_cfg80211_vif *vif; |
502 | struct brcmf_if *ifp; | |
503 | ||
504 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); | |
505 | ifp = vif->ifp; | |
8851cce0 HM |
506 | |
507 | if ((wdev->iftype == NL80211_IFTYPE_ADHOC) || | |
508 | (wdev->iftype == NL80211_IFTYPE_AP) || | |
509 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) | |
510 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, | |
511 | ADDR_DIRECT); | |
512 | else | |
513 | brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx, | |
514 | ADDR_INDIRECT); | |
515 | } | |
516 | ||
967fe2c8 AS |
517 | static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif) |
518 | { | |
519 | enum nl80211_iftype iftype; | |
520 | ||
521 | iftype = vif->wdev.iftype; | |
522 | return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO; | |
523 | } | |
524 | ||
525 | static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif) | |
526 | { | |
527 | return vif->wdev.iftype == NL80211_IFTYPE_ADHOC; | |
528 | } | |
529 | ||
9f440b7b AS |
530 | static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy, |
531 | const char *name, | |
532 | enum nl80211_iftype type, | |
533 | u32 *flags, | |
534 | struct vif_params *params) | |
535 | { | |
8851cce0 HM |
536 | struct wireless_dev *wdev; |
537 | ||
9f440b7b AS |
538 | brcmf_dbg(TRACE, "enter: %s type %d\n", name, type); |
539 | switch (type) { | |
540 | case NL80211_IFTYPE_ADHOC: | |
541 | case NL80211_IFTYPE_STATION: | |
542 | case NL80211_IFTYPE_AP: | |
543 | case NL80211_IFTYPE_AP_VLAN: | |
544 | case NL80211_IFTYPE_WDS: | |
545 | case NL80211_IFTYPE_MONITOR: | |
546 | case NL80211_IFTYPE_MESH_POINT: | |
547 | return ERR_PTR(-EOPNOTSUPP); | |
548 | case NL80211_IFTYPE_P2P_CLIENT: | |
549 | case NL80211_IFTYPE_P2P_GO: | |
27f10e38 | 550 | case NL80211_IFTYPE_P2P_DEVICE: |
8851cce0 HM |
551 | wdev = brcmf_p2p_add_vif(wiphy, name, type, flags, params); |
552 | if (!IS_ERR(wdev)) | |
553 | brcmf_cfg80211_update_proto_addr_mode(wdev); | |
554 | return wdev; | |
9f440b7b | 555 | case NL80211_IFTYPE_UNSPECIFIED: |
9f440b7b AS |
556 | default: |
557 | return ERR_PTR(-EINVAL); | |
558 | } | |
559 | } | |
560 | ||
5e787f75 DK |
561 | static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc) |
562 | { | |
c08437b4 | 563 | if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC)) |
5e787f75 DK |
564 | brcmf_set_mpc(ifp, mpc); |
565 | } | |
566 | ||
f96aa07e | 567 | void brcmf_set_mpc(struct brcmf_if *ifp, int mpc) |
5f4f9f11 | 568 | { |
5f4f9f11 AS |
569 | s32 err = 0; |
570 | ||
571 | if (check_vif_up(ifp->vif)) { | |
572 | err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc); | |
573 | if (err) { | |
574 | brcmf_err("fail to set mpc\n"); | |
575 | return; | |
576 | } | |
577 | brcmf_dbg(INFO, "MPC : %d\n", mpc); | |
578 | } | |
579 | } | |
580 | ||
a0f472ac AS |
581 | s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, |
582 | struct brcmf_if *ifp, bool aborted, | |
583 | bool fw_abort) | |
5f4f9f11 AS |
584 | { |
585 | struct brcmf_scan_params_le params_le; | |
586 | struct cfg80211_scan_request *scan_request; | |
587 | s32 err = 0; | |
588 | ||
589 | brcmf_dbg(SCAN, "Enter\n"); | |
590 | ||
591 | /* clear scan request, because the FW abort can cause a second call */ | |
592 | /* to this functon and might cause a double cfg80211_scan_done */ | |
593 | scan_request = cfg->scan_request; | |
594 | cfg->scan_request = NULL; | |
595 | ||
596 | if (timer_pending(&cfg->escan_timeout)) | |
597 | del_timer_sync(&cfg->escan_timeout); | |
598 | ||
599 | if (fw_abort) { | |
600 | /* Do a scan abort to stop the driver's scan engine */ | |
601 | brcmf_dbg(SCAN, "ABORT scan in firmware\n"); | |
602 | memset(¶ms_le, 0, sizeof(params_le)); | |
603 | memset(params_le.bssid, 0xFF, ETH_ALEN); | |
604 | params_le.bss_type = DOT11_BSSTYPE_ANY; | |
605 | params_le.scan_type = 0; | |
606 | params_le.channel_num = cpu_to_le32(1); | |
607 | params_le.nprobes = cpu_to_le32(1); | |
608 | params_le.active_time = cpu_to_le32(-1); | |
609 | params_le.passive_time = cpu_to_le32(-1); | |
610 | params_le.home_time = cpu_to_le32(-1); | |
611 | /* Scan is aborted by setting channel_list[0] to -1 */ | |
612 | params_le.channel_list[0] = cpu_to_le16(-1); | |
613 | /* E-Scan (or anyother type) can be aborted by SCAN */ | |
f96aa07e | 614 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
5f4f9f11 AS |
615 | ¶ms_le, sizeof(params_le)); |
616 | if (err) | |
617 | brcmf_err("Scan abort failed\n"); | |
618 | } | |
0f0fe990 | 619 | |
5e787f75 | 620 | brcmf_scan_config_mpc(ifp, 1); |
0f0fe990 | 621 | |
5f4f9f11 AS |
622 | /* |
623 | * e-scan can be initiated by scheduled scan | |
624 | * which takes precedence. | |
625 | */ | |
626 | if (cfg->sched_escan) { | |
627 | brcmf_dbg(SCAN, "scheduled scan completed\n"); | |
628 | cfg->sched_escan = false; | |
629 | if (!aborted) | |
630 | cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); | |
5f4f9f11 AS |
631 | } else if (scan_request) { |
632 | brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", | |
633 | aborted ? "Aborted" : "Done"); | |
634 | cfg80211_scan_done(scan_request, aborted); | |
5f4f9f11 | 635 | } |
6eda4e2c HM |
636 | if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
637 | brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); | |
5f4f9f11 AS |
638 | |
639 | return err; | |
640 | } | |
641 | ||
9f440b7b AS |
642 | static |
643 | int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) | |
644 | { | |
5f4f9f11 AS |
645 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
646 | struct net_device *ndev = wdev->netdev; | |
647 | ||
648 | /* vif event pending in firmware */ | |
649 | if (brcmf_cfg80211_vif_event_armed(cfg)) | |
650 | return -EBUSY; | |
651 | ||
652 | if (ndev) { | |
653 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) && | |
a0f472ac AS |
654 | cfg->escan_info.ifp == netdev_priv(ndev)) |
655 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), | |
656 | true, true); | |
5f4f9f11 AS |
657 | |
658 | brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1); | |
659 | } | |
660 | ||
9f440b7b AS |
661 | switch (wdev->iftype) { |
662 | case NL80211_IFTYPE_ADHOC: | |
663 | case NL80211_IFTYPE_STATION: | |
664 | case NL80211_IFTYPE_AP: | |
665 | case NL80211_IFTYPE_AP_VLAN: | |
666 | case NL80211_IFTYPE_WDS: | |
667 | case NL80211_IFTYPE_MONITOR: | |
668 | case NL80211_IFTYPE_MESH_POINT: | |
669 | return -EOPNOTSUPP; | |
670 | case NL80211_IFTYPE_P2P_CLIENT: | |
671 | case NL80211_IFTYPE_P2P_GO: | |
27f10e38 | 672 | case NL80211_IFTYPE_P2P_DEVICE: |
9f440b7b AS |
673 | return brcmf_p2p_del_vif(wiphy, wdev); |
674 | case NL80211_IFTYPE_UNSPECIFIED: | |
9f440b7b AS |
675 | default: |
676 | return -EINVAL; | |
677 | } | |
678 | return -EOPNOTSUPP; | |
679 | } | |
680 | ||
5b435de0 AS |
681 | static s32 |
682 | brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev, | |
683 | enum nl80211_iftype type, u32 *flags, | |
684 | struct vif_params *params) | |
685 | { | |
7a5c1f64 | 686 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
c1179033 | 687 | struct brcmf_if *ifp = netdev_priv(ndev); |
128ce3b6 | 688 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
5b435de0 | 689 | s32 infra = 0; |
1a873342 | 690 | s32 ap = 0; |
5b435de0 AS |
691 | s32 err = 0; |
692 | ||
d96b801f | 693 | brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type); |
5b435de0 AS |
694 | |
695 | switch (type) { | |
696 | case NL80211_IFTYPE_MONITOR: | |
697 | case NL80211_IFTYPE_WDS: | |
57d6e91a AS |
698 | brcmf_err("type (%d) : currently we do not support this type\n", |
699 | type); | |
5b435de0 AS |
700 | return -EOPNOTSUPP; |
701 | case NL80211_IFTYPE_ADHOC: | |
5b435de0 AS |
702 | infra = 0; |
703 | break; | |
704 | case NL80211_IFTYPE_STATION: | |
1bc7c654 HM |
705 | /* Ignore change for p2p IF. Unclear why supplicant does this */ |
706 | if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) || | |
707 | (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) { | |
708 | brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n"); | |
709 | /* WAR: It is unexpected to get a change of VIF for P2P | |
710 | * IF, but it happens. The request can not be handled | |
711 | * but returning EPERM causes a crash. Returning 0 | |
712 | * without setting ieee80211_ptr->iftype causes trace | |
713 | * (WARN_ON) but it works with wpa_supplicant | |
714 | */ | |
715 | return 0; | |
716 | } | |
5b435de0 AS |
717 | infra = 1; |
718 | break; | |
1a873342 | 719 | case NL80211_IFTYPE_AP: |
7a5c1f64 | 720 | case NL80211_IFTYPE_P2P_GO: |
1a873342 HM |
721 | ap = 1; |
722 | break; | |
5b435de0 AS |
723 | default: |
724 | err = -EINVAL; | |
725 | goto done; | |
726 | } | |
727 | ||
1a873342 | 728 | if (ap) { |
7a5c1f64 HM |
729 | if (type == NL80211_IFTYPE_P2P_GO) { |
730 | brcmf_dbg(INFO, "IF Type = P2P GO\n"); | |
731 | err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO); | |
732 | } | |
733 | if (!err) { | |
734 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state); | |
735 | brcmf_dbg(INFO, "IF Type = AP\n"); | |
736 | } | |
5b435de0 | 737 | } else { |
128ce3b6 | 738 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra); |
1a873342 | 739 | if (err) { |
57d6e91a | 740 | brcmf_err("WLC_SET_INFRA error (%d)\n", err); |
1a873342 HM |
741 | err = -EAGAIN; |
742 | goto done; | |
743 | } | |
967fe2c8 | 744 | brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ? |
647c9ae0 | 745 | "Adhoc" : "Infra"); |
5b435de0 | 746 | } |
1a873342 | 747 | ndev->ieee80211_ptr->iftype = type; |
5b435de0 | 748 | |
8851cce0 HM |
749 | brcmf_cfg80211_update_proto_addr_mode(&vif->wdev); |
750 | ||
5b435de0 | 751 | done: |
d96b801f | 752 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
753 | |
754 | return err; | |
755 | } | |
756 | ||
83cf17aa FL |
757 | static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg, |
758 | struct brcmf_scan_params_le *params_le, | |
e756af5b HM |
759 | struct cfg80211_scan_request *request) |
760 | { | |
761 | u32 n_ssids; | |
762 | u32 n_channels; | |
763 | s32 i; | |
764 | s32 offset; | |
029591f3 | 765 | u16 chanspec; |
e756af5b | 766 | char *ptr; |
029591f3 | 767 | struct brcmf_ssid_le ssid_le; |
e756af5b | 768 | |
ba40d166 | 769 | memset(params_le->bssid, 0xFF, ETH_ALEN); |
e756af5b HM |
770 | params_le->bss_type = DOT11_BSSTYPE_ANY; |
771 | params_le->scan_type = 0; | |
772 | params_le->channel_num = 0; | |
773 | params_le->nprobes = cpu_to_le32(-1); | |
774 | params_le->active_time = cpu_to_le32(-1); | |
775 | params_le->passive_time = cpu_to_le32(-1); | |
776 | params_le->home_time = cpu_to_le32(-1); | |
777 | memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le)); | |
778 | ||
779 | /* if request is null exit so it will be all channel broadcast scan */ | |
780 | if (!request) | |
781 | return; | |
782 | ||
783 | n_ssids = request->n_ssids; | |
784 | n_channels = request->n_channels; | |
785 | /* Copy channel array if applicable */ | |
4e8a008e AS |
786 | brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n", |
787 | n_channels); | |
e756af5b HM |
788 | if (n_channels > 0) { |
789 | for (i = 0; i < n_channels; i++) { | |
83cf17aa FL |
790 | chanspec = channel_to_chanspec(&cfg->d11inf, |
791 | request->channels[i]); | |
4e8a008e AS |
792 | brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n", |
793 | request->channels[i]->hw_value, chanspec); | |
029591f3 | 794 | params_le->channel_list[i] = cpu_to_le16(chanspec); |
e756af5b HM |
795 | } |
796 | } else { | |
4e8a008e | 797 | brcmf_dbg(SCAN, "Scanning all channels\n"); |
e756af5b HM |
798 | } |
799 | /* Copy ssid array if applicable */ | |
4e8a008e | 800 | brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids); |
e756af5b HM |
801 | if (n_ssids > 0) { |
802 | offset = offsetof(struct brcmf_scan_params_le, channel_list) + | |
803 | n_channels * sizeof(u16); | |
804 | offset = roundup(offset, sizeof(u32)); | |
805 | ptr = (char *)params_le + offset; | |
806 | for (i = 0; i < n_ssids; i++) { | |
029591f3 AS |
807 | memset(&ssid_le, 0, sizeof(ssid_le)); |
808 | ssid_le.SSID_len = | |
809 | cpu_to_le32(request->ssids[i].ssid_len); | |
810 | memcpy(ssid_le.SSID, request->ssids[i].ssid, | |
811 | request->ssids[i].ssid_len); | |
812 | if (!ssid_le.SSID_len) | |
4e8a008e | 813 | brcmf_dbg(SCAN, "%d: Broadcast scan\n", i); |
e756af5b | 814 | else |
4e8a008e AS |
815 | brcmf_dbg(SCAN, "%d: scan for %s size =%d\n", |
816 | i, ssid_le.SSID, ssid_le.SSID_len); | |
029591f3 AS |
817 | memcpy(ptr, &ssid_le, sizeof(ssid_le)); |
818 | ptr += sizeof(ssid_le); | |
e756af5b HM |
819 | } |
820 | } else { | |
4e8a008e | 821 | brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids); |
e756af5b | 822 | if ((request->ssids) && request->ssids->ssid_len) { |
4e8a008e AS |
823 | brcmf_dbg(SCAN, "SSID %s len=%d\n", |
824 | params_le->ssid_le.SSID, | |
825 | request->ssids->ssid_len); | |
e756af5b HM |
826 | params_le->ssid_le.SSID_len = |
827 | cpu_to_le32(request->ssids->ssid_len); | |
828 | memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid, | |
829 | request->ssids->ssid_len); | |
830 | } | |
831 | } | |
832 | /* Adding mask to channel numbers */ | |
833 | params_le->channel_num = | |
834 | cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) | | |
835 | (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK)); | |
836 | } | |
837 | ||
e756af5b | 838 | static s32 |
a0f472ac | 839 | brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, |
e756af5b HM |
840 | struct cfg80211_scan_request *request, u16 action) |
841 | { | |
842 | s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE + | |
843 | offsetof(struct brcmf_escan_params_le, params_le); | |
844 | struct brcmf_escan_params_le *params; | |
845 | s32 err = 0; | |
846 | ||
4e8a008e | 847 | brcmf_dbg(SCAN, "E-SCAN START\n"); |
e756af5b HM |
848 | |
849 | if (request != NULL) { | |
850 | /* Allocate space for populating ssids in struct */ | |
851 | params_size += sizeof(u32) * ((request->n_channels + 1) / 2); | |
852 | ||
853 | /* Allocate space for populating ssids in struct */ | |
854 | params_size += sizeof(struct brcmf_ssid) * request->n_ssids; | |
855 | } | |
856 | ||
857 | params = kzalloc(params_size, GFP_KERNEL); | |
858 | if (!params) { | |
859 | err = -ENOMEM; | |
860 | goto exit; | |
861 | } | |
862 | BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN); | |
83cf17aa | 863 | brcmf_escan_prep(cfg, ¶ms->params_le, request); |
e756af5b HM |
864 | params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
865 | params->action = cpu_to_le16(action); | |
866 | params->sync_id = cpu_to_le16(0x1234); | |
867 | ||
a0f472ac | 868 | err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size); |
e756af5b HM |
869 | if (err) { |
870 | if (err == -EBUSY) | |
647c9ae0 | 871 | brcmf_dbg(INFO, "system busy : escan canceled\n"); |
e756af5b | 872 | else |
57d6e91a | 873 | brcmf_err("error (%d)\n", err); |
e756af5b HM |
874 | } |
875 | ||
876 | kfree(params); | |
877 | exit: | |
878 | return err; | |
879 | } | |
880 | ||
881 | static s32 | |
27a68fe3 | 882 | brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy, |
a0f472ac | 883 | struct brcmf_if *ifp, struct cfg80211_scan_request *request) |
e756af5b HM |
884 | { |
885 | s32 err; | |
81f5dcb8 | 886 | u32 passive_scan; |
e756af5b | 887 | struct brcmf_scan_results *results; |
9f440b7b | 888 | struct escan_info *escan = &cfg->escan_info; |
e756af5b | 889 | |
4e8a008e | 890 | brcmf_dbg(SCAN, "Enter\n"); |
a0f472ac | 891 | escan->ifp = ifp; |
9f440b7b AS |
892 | escan->wiphy = wiphy; |
893 | escan->escan_state = WL_ESCAN_STATE_SCANNING; | |
81f5dcb8 | 894 | passive_scan = cfg->active_scan ? 0 : 1; |
f96aa07e | 895 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
81f5dcb8 | 896 | passive_scan); |
e756af5b | 897 | if (err) { |
57d6e91a | 898 | brcmf_err("error (%d)\n", err); |
e756af5b HM |
899 | return err; |
900 | } | |
5e787f75 | 901 | brcmf_scan_config_mpc(ifp, 0); |
27a68fe3 | 902 | results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
e756af5b HM |
903 | results->version = 0; |
904 | results->count = 0; | |
905 | results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE; | |
906 | ||
a0f472ac | 907 | err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START); |
e756af5b | 908 | if (err) |
5e787f75 | 909 | brcmf_scan_config_mpc(ifp, 1); |
e756af5b HM |
910 | return err; |
911 | } | |
912 | ||
913 | static s32 | |
a0f472ac | 914 | brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif, |
e756af5b HM |
915 | struct cfg80211_scan_request *request, |
916 | struct cfg80211_ssid *this_ssid) | |
917 | { | |
a0f472ac AS |
918 | struct brcmf_if *ifp = vif->ifp; |
919 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
e756af5b | 920 | struct cfg80211_ssid *ssids; |
f0799895 | 921 | struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int; |
81f5dcb8 | 922 | u32 passive_scan; |
e756af5b HM |
923 | bool escan_req; |
924 | bool spec_scan; | |
925 | s32 err; | |
926 | u32 SSID_len; | |
927 | ||
4e8a008e | 928 | brcmf_dbg(SCAN, "START ESCAN\n"); |
e756af5b | 929 | |
c1179033 | 930 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
57d6e91a | 931 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
e756af5b HM |
932 | return -EAGAIN; |
933 | } | |
c1179033 | 934 | if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) { |
57d6e91a AS |
935 | brcmf_err("Scanning being aborted: status (%lu)\n", |
936 | cfg->scan_status); | |
e756af5b HM |
937 | return -EAGAIN; |
938 | } | |
1687eee2 AS |
939 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
940 | brcmf_err("Scanning suppressed: status (%lu)\n", | |
941 | cfg->scan_status); | |
942 | return -EAGAIN; | |
943 | } | |
c1179033 | 944 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) { |
57d6e91a | 945 | brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state); |
e756af5b HM |
946 | return -EAGAIN; |
947 | } | |
948 | ||
0f8ffe17 | 949 | /* If scan req comes for p2p0, send it over primary I/F */ |
a0f472ac AS |
950 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
951 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; | |
0f8ffe17 | 952 | |
e756af5b | 953 | /* Arm scan timeout timer */ |
27a68fe3 | 954 | mod_timer(&cfg->escan_timeout, jiffies + |
e756af5b HM |
955 | WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000); |
956 | ||
957 | escan_req = false; | |
958 | if (request) { | |
959 | /* scan bss */ | |
960 | ssids = request->ssids; | |
961 | escan_req = true; | |
962 | } else { | |
963 | /* scan in ibss */ | |
964 | /* we don't do escan in ibss */ | |
965 | ssids = this_ssid; | |
966 | } | |
967 | ||
27a68fe3 | 968 | cfg->scan_request = request; |
c1179033 | 969 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
e756af5b | 970 | if (escan_req) { |
9f440b7b | 971 | cfg->escan_info.run = brcmf_run_escan; |
a0f472ac | 972 | err = brcmf_p2p_scan_prep(wiphy, request, vif); |
9f440b7b AS |
973 | if (err) |
974 | goto scan_out; | |
975 | ||
a0f472ac | 976 | err = brcmf_do_escan(cfg, wiphy, vif->ifp, request); |
2cb941c0 | 977 | if (err) |
e756af5b HM |
978 | goto scan_out; |
979 | } else { | |
4e8a008e AS |
980 | brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n", |
981 | ssids->ssid, ssids->ssid_len); | |
e756af5b HM |
982 | memset(&sr->ssid_le, 0, sizeof(sr->ssid_le)); |
983 | SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len); | |
984 | sr->ssid_le.SSID_len = cpu_to_le32(0); | |
985 | spec_scan = false; | |
986 | if (SSID_len) { | |
987 | memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len); | |
988 | sr->ssid_le.SSID_len = cpu_to_le32(SSID_len); | |
989 | spec_scan = true; | |
990 | } else | |
4e8a008e | 991 | brcmf_dbg(SCAN, "Broadcast scan\n"); |
e756af5b | 992 | |
81f5dcb8 | 993 | passive_scan = cfg->active_scan ? 0 : 1; |
c1179033 | 994 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN, |
81f5dcb8 | 995 | passive_scan); |
e756af5b | 996 | if (err) { |
57d6e91a | 997 | brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err); |
e756af5b HM |
998 | goto scan_out; |
999 | } | |
5e787f75 | 1000 | brcmf_scan_config_mpc(ifp, 0); |
c1179033 | 1001 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN, |
ac24be6f | 1002 | &sr->ssid_le, sizeof(sr->ssid_le)); |
e756af5b HM |
1003 | if (err) { |
1004 | if (err == -EBUSY) | |
647c9ae0 AS |
1005 | brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n", |
1006 | sr->ssid_le.SSID); | |
e756af5b | 1007 | else |
57d6e91a | 1008 | brcmf_err("WLC_SCAN error (%d)\n", err); |
e756af5b | 1009 | |
5e787f75 | 1010 | brcmf_scan_config_mpc(ifp, 1); |
e756af5b HM |
1011 | goto scan_out; |
1012 | } | |
1013 | } | |
1014 | ||
1015 | return 0; | |
1016 | ||
1017 | scan_out: | |
c1179033 | 1018 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
27a68fe3 AS |
1019 | if (timer_pending(&cfg->escan_timeout)) |
1020 | del_timer_sync(&cfg->escan_timeout); | |
1021 | cfg->scan_request = NULL; | |
e756af5b HM |
1022 | return err; |
1023 | } | |
1024 | ||
5b435de0 | 1025 | static s32 |
0abb5f21 | 1026 | brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) |
5b435de0 | 1027 | { |
a0f472ac | 1028 | struct brcmf_cfg80211_vif *vif; |
5b435de0 AS |
1029 | s32 err = 0; |
1030 | ||
d96b801f | 1031 | brcmf_dbg(TRACE, "Enter\n"); |
a0f472ac AS |
1032 | vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev); |
1033 | if (!check_vif_up(vif)) | |
5b435de0 AS |
1034 | return -EIO; |
1035 | ||
a0f472ac | 1036 | err = brcmf_cfg80211_escan(wiphy, vif, request, NULL); |
e756af5b | 1037 | |
5b435de0 | 1038 | if (err) |
57d6e91a | 1039 | brcmf_err("scan error (%d)\n", err); |
5b435de0 | 1040 | |
d96b801f | 1041 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1042 | return err; |
1043 | } | |
1044 | ||
1045 | static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold) | |
1046 | { | |
1047 | s32 err = 0; | |
1048 | ||
ac24be6f AS |
1049 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh", |
1050 | rts_threshold); | |
5b435de0 | 1051 | if (err) |
57d6e91a | 1052 | brcmf_err("Error (%d)\n", err); |
5b435de0 AS |
1053 | |
1054 | return err; | |
1055 | } | |
1056 | ||
1057 | static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold) | |
1058 | { | |
1059 | s32 err = 0; | |
1060 | ||
ac24be6f AS |
1061 | err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh", |
1062 | frag_threshold); | |
5b435de0 | 1063 | if (err) |
57d6e91a | 1064 | brcmf_err("Error (%d)\n", err); |
5b435de0 AS |
1065 | |
1066 | return err; | |
1067 | } | |
1068 | ||
1069 | static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l) | |
1070 | { | |
1071 | s32 err = 0; | |
b87e2c48 | 1072 | u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL); |
5b435de0 | 1073 | |
ac24be6f | 1074 | err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry); |
5b435de0 | 1075 | if (err) { |
57d6e91a | 1076 | brcmf_err("cmd (%d) , error (%d)\n", cmd, err); |
5b435de0 AS |
1077 | return err; |
1078 | } | |
1079 | return err; | |
1080 | } | |
1081 | ||
1082 | static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) | |
1083 | { | |
27a68fe3 AS |
1084 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
1085 | struct net_device *ndev = cfg_to_ndev(cfg); | |
0abb5f21 | 1086 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
1087 | s32 err = 0; |
1088 | ||
d96b801f | 1089 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 1090 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1091 | return -EIO; |
1092 | ||
1093 | if (changed & WIPHY_PARAM_RTS_THRESHOLD && | |
27a68fe3 AS |
1094 | (cfg->conf->rts_threshold != wiphy->rts_threshold)) { |
1095 | cfg->conf->rts_threshold = wiphy->rts_threshold; | |
1096 | err = brcmf_set_rts(ndev, cfg->conf->rts_threshold); | |
5b435de0 AS |
1097 | if (!err) |
1098 | goto done; | |
1099 | } | |
1100 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD && | |
27a68fe3 AS |
1101 | (cfg->conf->frag_threshold != wiphy->frag_threshold)) { |
1102 | cfg->conf->frag_threshold = wiphy->frag_threshold; | |
1103 | err = brcmf_set_frag(ndev, cfg->conf->frag_threshold); | |
5b435de0 AS |
1104 | if (!err) |
1105 | goto done; | |
1106 | } | |
1107 | if (changed & WIPHY_PARAM_RETRY_LONG | |
27a68fe3 AS |
1108 | && (cfg->conf->retry_long != wiphy->retry_long)) { |
1109 | cfg->conf->retry_long = wiphy->retry_long; | |
1110 | err = brcmf_set_retry(ndev, cfg->conf->retry_long, true); | |
5b435de0 AS |
1111 | if (!err) |
1112 | goto done; | |
1113 | } | |
1114 | if (changed & WIPHY_PARAM_RETRY_SHORT | |
27a68fe3 AS |
1115 | && (cfg->conf->retry_short != wiphy->retry_short)) { |
1116 | cfg->conf->retry_short = wiphy->retry_short; | |
1117 | err = brcmf_set_retry(ndev, cfg->conf->retry_short, false); | |
5b435de0 AS |
1118 | if (!err) |
1119 | goto done; | |
1120 | } | |
1121 | ||
1122 | done: | |
d96b801f | 1123 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1124 | return err; |
1125 | } | |
1126 | ||
5b435de0 AS |
1127 | static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof) |
1128 | { | |
1129 | memset(prof, 0, sizeof(*prof)); | |
1130 | } | |
1131 | ||
903e0eee | 1132 | static void brcmf_link_down(struct brcmf_cfg80211_vif *vif) |
5b435de0 | 1133 | { |
61730d4d | 1134 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy); |
5b435de0 AS |
1135 | s32 err = 0; |
1136 | ||
d96b801f | 1137 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 1138 | |
903e0eee | 1139 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) { |
647c9ae0 | 1140 | brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n "); |
903e0eee | 1141 | err = brcmf_fil_cmd_data_set(vif->ifp, |
ac24be6f | 1142 | BRCMF_C_DISASSOC, NULL, 0); |
a538ae31 | 1143 | if (err) { |
57d6e91a | 1144 | brcmf_err("WLC_DISASSOC failed (%d)\n", err); |
a538ae31 | 1145 | } |
903e0eee | 1146 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state); |
43dffbc6 AS |
1147 | cfg80211_disconnected(vif->wdev.netdev, 0, NULL, 0, GFP_KERNEL); |
1148 | ||
5b435de0 | 1149 | } |
903e0eee | 1150 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state); |
61730d4d PH |
1151 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); |
1152 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); | |
d96b801f | 1153 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1154 | } |
1155 | ||
1156 | static s32 | |
1157 | brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev, | |
1158 | struct cfg80211_ibss_params *params) | |
1159 | { | |
27a68fe3 | 1160 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 AS |
1161 | struct brcmf_if *ifp = netdev_priv(ndev); |
1162 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
5b435de0 AS |
1163 | struct brcmf_join_params join_params; |
1164 | size_t join_params_size = 0; | |
1165 | s32 err = 0; | |
1166 | s32 wsec = 0; | |
1167 | s32 bcnprd; | |
1701261d | 1168 | u16 chanspec; |
5b435de0 | 1169 | |
d96b801f | 1170 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 1171 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1172 | return -EIO; |
1173 | ||
1174 | if (params->ssid) | |
16886735 | 1175 | brcmf_dbg(CONN, "SSID: %s\n", params->ssid); |
5b435de0 | 1176 | else { |
16886735 | 1177 | brcmf_dbg(CONN, "SSID: NULL, Not supported\n"); |
5b435de0 AS |
1178 | return -EOPNOTSUPP; |
1179 | } | |
1180 | ||
c1179033 | 1181 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
5b435de0 AS |
1182 | |
1183 | if (params->bssid) | |
16886735 | 1184 | brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid); |
5b435de0 | 1185 | else |
16886735 | 1186 | brcmf_dbg(CONN, "No BSSID specified\n"); |
5b435de0 | 1187 | |
683b6d3b | 1188 | if (params->chandef.chan) |
16886735 AS |
1189 | brcmf_dbg(CONN, "channel: %d\n", |
1190 | params->chandef.chan->center_freq); | |
5b435de0 | 1191 | else |
16886735 | 1192 | brcmf_dbg(CONN, "no channel specified\n"); |
5b435de0 AS |
1193 | |
1194 | if (params->channel_fixed) | |
16886735 | 1195 | brcmf_dbg(CONN, "fixed channel required\n"); |
5b435de0 | 1196 | else |
16886735 | 1197 | brcmf_dbg(CONN, "no fixed channel required\n"); |
5b435de0 AS |
1198 | |
1199 | if (params->ie && params->ie_len) | |
16886735 | 1200 | brcmf_dbg(CONN, "ie len: %d\n", params->ie_len); |
5b435de0 | 1201 | else |
16886735 | 1202 | brcmf_dbg(CONN, "no ie specified\n"); |
5b435de0 AS |
1203 | |
1204 | if (params->beacon_interval) | |
16886735 AS |
1205 | brcmf_dbg(CONN, "beacon interval: %d\n", |
1206 | params->beacon_interval); | |
5b435de0 | 1207 | else |
16886735 | 1208 | brcmf_dbg(CONN, "no beacon interval specified\n"); |
5b435de0 AS |
1209 | |
1210 | if (params->basic_rates) | |
16886735 | 1211 | brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates); |
5b435de0 | 1212 | else |
16886735 | 1213 | brcmf_dbg(CONN, "no basic rates specified\n"); |
5b435de0 AS |
1214 | |
1215 | if (params->privacy) | |
16886735 | 1216 | brcmf_dbg(CONN, "privacy required\n"); |
5b435de0 | 1217 | else |
16886735 | 1218 | brcmf_dbg(CONN, "no privacy required\n"); |
5b435de0 AS |
1219 | |
1220 | /* Configure Privacy for starter */ | |
1221 | if (params->privacy) | |
1222 | wsec |= WEP_ENABLED; | |
1223 | ||
c1179033 | 1224 | err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec); |
5b435de0 | 1225 | if (err) { |
57d6e91a | 1226 | brcmf_err("wsec failed (%d)\n", err); |
5b435de0 AS |
1227 | goto done; |
1228 | } | |
1229 | ||
1230 | /* Configure Beacon Interval for starter */ | |
1231 | if (params->beacon_interval) | |
1232 | bcnprd = params->beacon_interval; | |
1233 | else | |
1234 | bcnprd = 100; | |
1235 | ||
b87e2c48 | 1236 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd); |
5b435de0 | 1237 | if (err) { |
57d6e91a | 1238 | brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err); |
5b435de0 AS |
1239 | goto done; |
1240 | } | |
1241 | ||
1242 | /* Configure required join parameter */ | |
1243 | memset(&join_params, 0, sizeof(struct brcmf_join_params)); | |
1244 | ||
1245 | /* SSID */ | |
6c8c4f72 AS |
1246 | profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32); |
1247 | memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len); | |
1248 | memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len); | |
1249 | join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); | |
5b435de0 | 1250 | join_params_size = sizeof(join_params.ssid_le); |
5b435de0 AS |
1251 | |
1252 | /* BSSID */ | |
1253 | if (params->bssid) { | |
1254 | memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN); | |
1255 | join_params_size = sizeof(join_params.ssid_le) + | |
1256 | BRCMF_ASSOC_PARAMS_FIXED_SIZE; | |
6c8c4f72 | 1257 | memcpy(profile->bssid, params->bssid, ETH_ALEN); |
5b435de0 | 1258 | } else { |
ba40d166 | 1259 | memset(join_params.params_le.bssid, 0xFF, ETH_ALEN); |
6c8c4f72 | 1260 | memset(profile->bssid, 0, ETH_ALEN); |
5b435de0 AS |
1261 | } |
1262 | ||
5b435de0 | 1263 | /* Channel */ |
683b6d3b | 1264 | if (params->chandef.chan) { |
5b435de0 AS |
1265 | u32 target_channel; |
1266 | ||
27a68fe3 | 1267 | cfg->channel = |
5b435de0 | 1268 | ieee80211_frequency_to_channel( |
683b6d3b | 1269 | params->chandef.chan->center_freq); |
5b435de0 AS |
1270 | if (params->channel_fixed) { |
1271 | /* adding chanspec */ | |
600a897d AS |
1272 | chanspec = chandef_to_chanspec(&cfg->d11inf, |
1273 | ¶ms->chandef); | |
1701261d HM |
1274 | join_params.params_le.chanspec_list[0] = |
1275 | cpu_to_le16(chanspec); | |
1276 | join_params.params_le.chanspec_num = cpu_to_le32(1); | |
1277 | join_params_size += sizeof(join_params.params_le); | |
5b435de0 AS |
1278 | } |
1279 | ||
1280 | /* set channel for starter */ | |
27a68fe3 | 1281 | target_channel = cfg->channel; |
b87e2c48 | 1282 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL, |
81f5dcb8 | 1283 | target_channel); |
5b435de0 | 1284 | if (err) { |
57d6e91a | 1285 | brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err); |
5b435de0 AS |
1286 | goto done; |
1287 | } | |
1288 | } else | |
27a68fe3 | 1289 | cfg->channel = 0; |
5b435de0 | 1290 | |
27a68fe3 | 1291 | cfg->ibss_starter = false; |
5b435de0 AS |
1292 | |
1293 | ||
c1179033 | 1294 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
81f5dcb8 | 1295 | &join_params, join_params_size); |
5b435de0 | 1296 | if (err) { |
57d6e91a | 1297 | brcmf_err("WLC_SET_SSID failed (%d)\n", err); |
5b435de0 AS |
1298 | goto done; |
1299 | } | |
1300 | ||
1301 | done: | |
1302 | if (err) | |
c1179033 | 1303 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
d96b801f | 1304 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1305 | return err; |
1306 | } | |
1307 | ||
1308 | static s32 | |
1309 | brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) | |
1310 | { | |
0abb5f21 | 1311 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 | 1312 | |
d96b801f | 1313 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 1314 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1315 | return -EIO; |
1316 | ||
903e0eee | 1317 | brcmf_link_down(ifp->vif); |
5b435de0 | 1318 | |
d96b801f | 1319 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 | 1320 | |
12f32370 | 1321 | return 0; |
5b435de0 AS |
1322 | } |
1323 | ||
1324 | static s32 brcmf_set_wpa_version(struct net_device *ndev, | |
1325 | struct cfg80211_connect_params *sme) | |
1326 | { | |
6ac4f4ed | 1327 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
5b435de0 AS |
1328 | struct brcmf_cfg80211_security *sec; |
1329 | s32 val = 0; | |
1330 | s32 err = 0; | |
1331 | ||
1332 | if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) | |
1333 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; | |
1334 | else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) | |
1335 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; | |
1336 | else | |
1337 | val = WPA_AUTH_DISABLED; | |
16886735 | 1338 | brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val); |
89286dc9 | 1339 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val); |
5b435de0 | 1340 | if (err) { |
57d6e91a | 1341 | brcmf_err("set wpa_auth failed (%d)\n", err); |
5b435de0 AS |
1342 | return err; |
1343 | } | |
06bb123e | 1344 | sec = &profile->sec; |
5b435de0 AS |
1345 | sec->wpa_versions = sme->crypto.wpa_versions; |
1346 | return err; | |
1347 | } | |
1348 | ||
1349 | static s32 brcmf_set_auth_type(struct net_device *ndev, | |
1350 | struct cfg80211_connect_params *sme) | |
1351 | { | |
6ac4f4ed | 1352 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
5b435de0 AS |
1353 | struct brcmf_cfg80211_security *sec; |
1354 | s32 val = 0; | |
1355 | s32 err = 0; | |
1356 | ||
1357 | switch (sme->auth_type) { | |
1358 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
1359 | val = 0; | |
16886735 | 1360 | brcmf_dbg(CONN, "open system\n"); |
5b435de0 AS |
1361 | break; |
1362 | case NL80211_AUTHTYPE_SHARED_KEY: | |
1363 | val = 1; | |
16886735 | 1364 | brcmf_dbg(CONN, "shared key\n"); |
5b435de0 AS |
1365 | break; |
1366 | case NL80211_AUTHTYPE_AUTOMATIC: | |
1367 | val = 2; | |
16886735 | 1368 | brcmf_dbg(CONN, "automatic\n"); |
5b435de0 AS |
1369 | break; |
1370 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
16886735 | 1371 | brcmf_dbg(CONN, "network eap\n"); |
5b435de0 AS |
1372 | default: |
1373 | val = 2; | |
57d6e91a | 1374 | brcmf_err("invalid auth type (%d)\n", sme->auth_type); |
5b435de0 AS |
1375 | break; |
1376 | } | |
1377 | ||
89286dc9 | 1378 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
5b435de0 | 1379 | if (err) { |
57d6e91a | 1380 | brcmf_err("set auth failed (%d)\n", err); |
5b435de0 AS |
1381 | return err; |
1382 | } | |
06bb123e | 1383 | sec = &profile->sec; |
5b435de0 AS |
1384 | sec->auth_type = sme->auth_type; |
1385 | return err; | |
1386 | } | |
1387 | ||
1388 | static s32 | |
87b7e9e2 DK |
1389 | brcmf_set_wsec_mode(struct net_device *ndev, |
1390 | struct cfg80211_connect_params *sme, bool mfp) | |
5b435de0 | 1391 | { |
6ac4f4ed | 1392 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
5b435de0 AS |
1393 | struct brcmf_cfg80211_security *sec; |
1394 | s32 pval = 0; | |
1395 | s32 gval = 0; | |
87b7e9e2 | 1396 | s32 wsec; |
5b435de0 AS |
1397 | s32 err = 0; |
1398 | ||
1399 | if (sme->crypto.n_ciphers_pairwise) { | |
1400 | switch (sme->crypto.ciphers_pairwise[0]) { | |
1401 | case WLAN_CIPHER_SUITE_WEP40: | |
1402 | case WLAN_CIPHER_SUITE_WEP104: | |
1403 | pval = WEP_ENABLED; | |
1404 | break; | |
1405 | case WLAN_CIPHER_SUITE_TKIP: | |
1406 | pval = TKIP_ENABLED; | |
1407 | break; | |
1408 | case WLAN_CIPHER_SUITE_CCMP: | |
1409 | pval = AES_ENABLED; | |
1410 | break; | |
1411 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
1412 | pval = AES_ENABLED; | |
1413 | break; | |
1414 | default: | |
57d6e91a AS |
1415 | brcmf_err("invalid cipher pairwise (%d)\n", |
1416 | sme->crypto.ciphers_pairwise[0]); | |
5b435de0 AS |
1417 | return -EINVAL; |
1418 | } | |
1419 | } | |
1420 | if (sme->crypto.cipher_group) { | |
1421 | switch (sme->crypto.cipher_group) { | |
1422 | case WLAN_CIPHER_SUITE_WEP40: | |
1423 | case WLAN_CIPHER_SUITE_WEP104: | |
1424 | gval = WEP_ENABLED; | |
1425 | break; | |
1426 | case WLAN_CIPHER_SUITE_TKIP: | |
1427 | gval = TKIP_ENABLED; | |
1428 | break; | |
1429 | case WLAN_CIPHER_SUITE_CCMP: | |
1430 | gval = AES_ENABLED; | |
1431 | break; | |
1432 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
1433 | gval = AES_ENABLED; | |
1434 | break; | |
1435 | default: | |
57d6e91a AS |
1436 | brcmf_err("invalid cipher group (%d)\n", |
1437 | sme->crypto.cipher_group); | |
5b435de0 AS |
1438 | return -EINVAL; |
1439 | } | |
1440 | } | |
1441 | ||
16886735 | 1442 | brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval); |
89286dc9 HM |
1443 | /* In case of privacy, but no security and WPS then simulate */ |
1444 | /* setting AES. WPS-2.0 allows no security */ | |
1445 | if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval && | |
1446 | sme->privacy) | |
1447 | pval = AES_ENABLED; | |
87b7e9e2 DK |
1448 | |
1449 | if (mfp) | |
1450 | wsec = pval | gval | MFP_CAPABLE; | |
1451 | else | |
1452 | wsec = pval | gval; | |
1453 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec); | |
5b435de0 | 1454 | if (err) { |
57d6e91a | 1455 | brcmf_err("error (%d)\n", err); |
5b435de0 AS |
1456 | return err; |
1457 | } | |
1458 | ||
06bb123e | 1459 | sec = &profile->sec; |
5b435de0 AS |
1460 | sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0]; |
1461 | sec->cipher_group = sme->crypto.cipher_group; | |
1462 | ||
1463 | return err; | |
1464 | } | |
1465 | ||
1466 | static s32 | |
1467 | brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme) | |
1468 | { | |
6ac4f4ed | 1469 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
5b435de0 AS |
1470 | struct brcmf_cfg80211_security *sec; |
1471 | s32 val = 0; | |
1472 | s32 err = 0; | |
1473 | ||
1474 | if (sme->crypto.n_akm_suites) { | |
89286dc9 HM |
1475 | err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), |
1476 | "wpa_auth", &val); | |
5b435de0 | 1477 | if (err) { |
57d6e91a | 1478 | brcmf_err("could not get wpa_auth (%d)\n", err); |
5b435de0 AS |
1479 | return err; |
1480 | } | |
1481 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { | |
1482 | switch (sme->crypto.akm_suites[0]) { | |
1483 | case WLAN_AKM_SUITE_8021X: | |
1484 | val = WPA_AUTH_UNSPECIFIED; | |
1485 | break; | |
1486 | case WLAN_AKM_SUITE_PSK: | |
1487 | val = WPA_AUTH_PSK; | |
1488 | break; | |
1489 | default: | |
57d6e91a AS |
1490 | brcmf_err("invalid cipher group (%d)\n", |
1491 | sme->crypto.cipher_group); | |
5b435de0 AS |
1492 | return -EINVAL; |
1493 | } | |
1494 | } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { | |
1495 | switch (sme->crypto.akm_suites[0]) { | |
1496 | case WLAN_AKM_SUITE_8021X: | |
1497 | val = WPA2_AUTH_UNSPECIFIED; | |
1498 | break; | |
1499 | case WLAN_AKM_SUITE_PSK: | |
1500 | val = WPA2_AUTH_PSK; | |
1501 | break; | |
1502 | default: | |
57d6e91a AS |
1503 | brcmf_err("invalid cipher group (%d)\n", |
1504 | sme->crypto.cipher_group); | |
5b435de0 AS |
1505 | return -EINVAL; |
1506 | } | |
1507 | } | |
1508 | ||
16886735 | 1509 | brcmf_dbg(CONN, "setting wpa_auth to %d\n", val); |
89286dc9 HM |
1510 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), |
1511 | "wpa_auth", val); | |
5b435de0 | 1512 | if (err) { |
57d6e91a | 1513 | brcmf_err("could not set wpa_auth (%d)\n", err); |
5b435de0 AS |
1514 | return err; |
1515 | } | |
1516 | } | |
06bb123e | 1517 | sec = &profile->sec; |
5b435de0 AS |
1518 | sec->wpa_auth = sme->crypto.akm_suites[0]; |
1519 | ||
1520 | return err; | |
1521 | } | |
1522 | ||
1523 | static s32 | |
f09d0c02 HM |
1524 | brcmf_set_sharedkey(struct net_device *ndev, |
1525 | struct cfg80211_connect_params *sme) | |
5b435de0 | 1526 | { |
6ac4f4ed | 1527 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev); |
5b435de0 AS |
1528 | struct brcmf_cfg80211_security *sec; |
1529 | struct brcmf_wsec_key key; | |
1530 | s32 val; | |
1531 | s32 err = 0; | |
1532 | ||
16886735 | 1533 | brcmf_dbg(CONN, "key len (%d)\n", sme->key_len); |
5b435de0 | 1534 | |
a718e2fe RV |
1535 | if (sme->key_len == 0) |
1536 | return 0; | |
1537 | ||
06bb123e | 1538 | sec = &profile->sec; |
16886735 AS |
1539 | brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n", |
1540 | sec->wpa_versions, sec->cipher_pairwise); | |
a718e2fe RV |
1541 | |
1542 | if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) | |
1543 | return 0; | |
1544 | ||
f09d0c02 HM |
1545 | if (!(sec->cipher_pairwise & |
1546 | (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104))) | |
1547 | return 0; | |
a718e2fe | 1548 | |
f09d0c02 HM |
1549 | memset(&key, 0, sizeof(key)); |
1550 | key.len = (u32) sme->key_len; | |
1551 | key.index = (u32) sme->key_idx; | |
1552 | if (key.len > sizeof(key.data)) { | |
57d6e91a | 1553 | brcmf_err("Too long key length (%u)\n", key.len); |
f09d0c02 HM |
1554 | return -EINVAL; |
1555 | } | |
1556 | memcpy(key.data, sme->key, key.len); | |
1557 | key.flags = BRCMF_PRIMARY_KEY; | |
1558 | switch (sec->cipher_pairwise) { | |
1559 | case WLAN_CIPHER_SUITE_WEP40: | |
1560 | key.algo = CRYPTO_ALGO_WEP1; | |
1561 | break; | |
1562 | case WLAN_CIPHER_SUITE_WEP104: | |
1563 | key.algo = CRYPTO_ALGO_WEP128; | |
1564 | break; | |
1565 | default: | |
57d6e91a AS |
1566 | brcmf_err("Invalid algorithm (%d)\n", |
1567 | sme->crypto.ciphers_pairwise[0]); | |
f09d0c02 HM |
1568 | return -EINVAL; |
1569 | } | |
1570 | /* Set the new key/index */ | |
16886735 AS |
1571 | brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n", |
1572 | key.len, key.index, key.algo); | |
1573 | brcmf_dbg(CONN, "key \"%s\"\n", key.data); | |
2eaba7e8 | 1574 | err = send_key_to_dongle(ndev, &key); |
f09d0c02 HM |
1575 | if (err) |
1576 | return err; | |
1577 | ||
1578 | if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) { | |
16886735 | 1579 | brcmf_dbg(CONN, "set auth_type to shared key\n"); |
f09d0c02 | 1580 | val = WL_AUTH_SHARED_KEY; /* shared key */ |
ac24be6f | 1581 | err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val); |
f09d0c02 | 1582 | if (err) |
57d6e91a | 1583 | brcmf_err("set auth failed (%d)\n", err); |
5b435de0 AS |
1584 | } |
1585 | return err; | |
1586 | } | |
1587 | ||
cbb1ec94 AS |
1588 | static |
1589 | enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp, | |
1590 | enum nl80211_auth_type type) | |
1591 | { | |
c08437b4 AS |
1592 | if (type == NL80211_AUTHTYPE_AUTOMATIC && |
1593 | brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) { | |
1594 | brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n"); | |
1595 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
cbb1ec94 AS |
1596 | } |
1597 | return type; | |
1598 | } | |
1599 | ||
5b435de0 AS |
1600 | static s32 |
1601 | brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, | |
cbb1ec94 | 1602 | struct cfg80211_connect_params *sme) |
5b435de0 | 1603 | { |
27a68fe3 | 1604 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 AS |
1605 | struct brcmf_if *ifp = netdev_priv(ndev); |
1606 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
5b435de0 AS |
1607 | struct ieee80211_channel *chan = sme->channel; |
1608 | struct brcmf_join_params join_params; | |
1609 | size_t join_params_size; | |
4b5800fe JB |
1610 | const struct brcmf_tlv *rsn_ie; |
1611 | const struct brcmf_vs_tlv *wpa_ie; | |
1612 | const void *ie; | |
89286dc9 HM |
1613 | u32 ie_len; |
1614 | struct brcmf_ext_join_params_le *ext_join_params; | |
1701261d | 1615 | u16 chanspec; |
5b435de0 AS |
1616 | s32 err = 0; |
1617 | ||
d96b801f | 1618 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 1619 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1620 | return -EIO; |
1621 | ||
1622 | if (!sme->ssid) { | |
57d6e91a | 1623 | brcmf_err("Invalid ssid\n"); |
5b435de0 AS |
1624 | return -EOPNOTSUPP; |
1625 | } | |
1626 | ||
89286dc9 HM |
1627 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) { |
1628 | /* A normal (non P2P) connection request setup. */ | |
1629 | ie = NULL; | |
1630 | ie_len = 0; | |
1631 | /* find the WPA_IE */ | |
1632 | wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len); | |
1633 | if (wpa_ie) { | |
1634 | ie = wpa_ie; | |
1635 | ie_len = wpa_ie->len + TLV_HDR_LEN; | |
1636 | } else { | |
1637 | /* find the RSN_IE */ | |
4b5800fe JB |
1638 | rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, |
1639 | sme->ie_len, | |
89286dc9 HM |
1640 | WLAN_EID_RSN); |
1641 | if (rsn_ie) { | |
1642 | ie = rsn_ie; | |
1643 | ie_len = rsn_ie->len + TLV_HDR_LEN; | |
1644 | } | |
1645 | } | |
1646 | brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len); | |
1647 | } | |
1648 | ||
1649 | err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG, | |
1650 | sme->ie, sme->ie_len); | |
1651 | if (err) | |
1652 | brcmf_err("Set Assoc REQ IE Failed\n"); | |
1653 | else | |
1654 | brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n"); | |
1655 | ||
c1179033 | 1656 | set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
5b435de0 AS |
1657 | |
1658 | if (chan) { | |
27a68fe3 | 1659 | cfg->channel = |
5b435de0 | 1660 | ieee80211_frequency_to_channel(chan->center_freq); |
83cf17aa | 1661 | chanspec = channel_to_chanspec(&cfg->d11inf, chan); |
1701261d HM |
1662 | brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n", |
1663 | cfg->channel, chan->center_freq, chanspec); | |
1664 | } else { | |
27a68fe3 | 1665 | cfg->channel = 0; |
1701261d HM |
1666 | chanspec = 0; |
1667 | } | |
5b435de0 | 1668 | |
647c9ae0 | 1669 | brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len); |
5b435de0 AS |
1670 | |
1671 | err = brcmf_set_wpa_version(ndev, sme); | |
1672 | if (err) { | |
57d6e91a | 1673 | brcmf_err("wl_set_wpa_version failed (%d)\n", err); |
5b435de0 AS |
1674 | goto done; |
1675 | } | |
1676 | ||
cbb1ec94 | 1677 | sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type); |
5b435de0 AS |
1678 | err = brcmf_set_auth_type(ndev, sme); |
1679 | if (err) { | |
57d6e91a | 1680 | brcmf_err("wl_set_auth_type failed (%d)\n", err); |
5b435de0 AS |
1681 | goto done; |
1682 | } | |
1683 | ||
87b7e9e2 | 1684 | err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED); |
5b435de0 | 1685 | if (err) { |
57d6e91a | 1686 | brcmf_err("wl_set_set_cipher failed (%d)\n", err); |
5b435de0 AS |
1687 | goto done; |
1688 | } | |
1689 | ||
1690 | err = brcmf_set_key_mgmt(ndev, sme); | |
1691 | if (err) { | |
57d6e91a | 1692 | brcmf_err("wl_set_key_mgmt failed (%d)\n", err); |
5b435de0 AS |
1693 | goto done; |
1694 | } | |
1695 | ||
f09d0c02 | 1696 | err = brcmf_set_sharedkey(ndev, sme); |
5b435de0 | 1697 | if (err) { |
57d6e91a | 1698 | brcmf_err("brcmf_set_sharedkey failed (%d)\n", err); |
5b435de0 AS |
1699 | goto done; |
1700 | } | |
1701 | ||
89286dc9 HM |
1702 | profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID), |
1703 | (u32)sme->ssid_len); | |
1704 | memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len); | |
1705 | if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) { | |
1706 | profile->ssid.SSID[profile->ssid.SSID_len] = 0; | |
1707 | brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID, | |
1708 | profile->ssid.SSID_len); | |
1709 | } | |
1710 | ||
1711 | /* Join with specific BSSID and cached SSID | |
1712 | * If SSID is zero join based on BSSID only | |
1713 | */ | |
1714 | join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) + | |
1715 | offsetof(struct brcmf_assoc_params_le, chanspec_list); | |
1716 | if (cfg->channel) | |
1717 | join_params_size += sizeof(u16); | |
1718 | ext_join_params = kzalloc(join_params_size, GFP_KERNEL); | |
1719 | if (ext_join_params == NULL) { | |
1720 | err = -ENOMEM; | |
1721 | goto done; | |
1722 | } | |
1723 | ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); | |
1724 | memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, | |
1725 | profile->ssid.SSID_len); | |
63dd99e6 | 1726 | |
89286dc9 HM |
1727 | /* Set up join scan parameters */ |
1728 | ext_join_params->scan_le.scan_type = -1; | |
89286dc9 HM |
1729 | ext_join_params->scan_le.home_time = cpu_to_le32(-1); |
1730 | ||
1731 | if (sme->bssid) | |
1732 | memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN); | |
1733 | else | |
1734 | memset(&ext_join_params->assoc_le.bssid, 0xFF, ETH_ALEN); | |
1735 | ||
1736 | if (cfg->channel) { | |
1737 | ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1); | |
1738 | ||
1739 | ext_join_params->assoc_le.chanspec_list[0] = | |
1740 | cpu_to_le16(chanspec); | |
63dd99e6 HM |
1741 | /* Increase dwell time to receive probe response or detect |
1742 | * beacon from target AP at a noisy air only during connect | |
1743 | * command. | |
1744 | */ | |
1745 | ext_join_params->scan_le.active_time = | |
1746 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); | |
1747 | ext_join_params->scan_le.passive_time = | |
1748 | cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); | |
1749 | /* To sync with presence period of VSDB GO send probe request | |
1750 | * more frequently. Probe request will be stopped when it gets | |
1751 | * probe response from target AP/GO. | |
1752 | */ | |
1753 | ext_join_params->scan_le.nprobes = | |
1754 | cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / | |
1755 | BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); | |
1756 | } else { | |
1757 | ext_join_params->scan_le.active_time = cpu_to_le32(-1); | |
1758 | ext_join_params->scan_le.passive_time = cpu_to_le32(-1); | |
1759 | ext_join_params->scan_le.nprobes = cpu_to_le32(-1); | |
89286dc9 HM |
1760 | } |
1761 | ||
1762 | err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params, | |
1763 | join_params_size); | |
1764 | kfree(ext_join_params); | |
1765 | if (!err) | |
1766 | /* This is it. join command worked, we are done */ | |
1767 | goto done; | |
1768 | ||
1769 | /* join command failed, fallback to set ssid */ | |
5b435de0 AS |
1770 | memset(&join_params, 0, sizeof(join_params)); |
1771 | join_params_size = sizeof(join_params.ssid_le); | |
1772 | ||
6c8c4f72 | 1773 | memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len); |
6c8c4f72 | 1774 | join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len); |
5b435de0 | 1775 | |
89286dc9 HM |
1776 | if (sme->bssid) |
1777 | memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN); | |
1778 | else | |
1779 | memset(join_params.params_le.bssid, 0xFF, ETH_ALEN); | |
5b435de0 | 1780 | |
1701261d HM |
1781 | if (cfg->channel) { |
1782 | join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec); | |
1783 | join_params.params_le.chanspec_num = cpu_to_le32(1); | |
1784 | join_params_size += sizeof(join_params.params_le); | |
1785 | } | |
c1179033 | 1786 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, |
81f5dcb8 | 1787 | &join_params, join_params_size); |
5b435de0 | 1788 | if (err) |
89286dc9 | 1789 | brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err); |
5b435de0 AS |
1790 | |
1791 | done: | |
1792 | if (err) | |
c1179033 | 1793 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state); |
d96b801f | 1794 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1795 | return err; |
1796 | } | |
1797 | ||
1798 | static s32 | |
1799 | brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev, | |
1800 | u16 reason_code) | |
1801 | { | |
0abb5f21 AS |
1802 | struct brcmf_if *ifp = netdev_priv(ndev); |
1803 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
5b435de0 AS |
1804 | struct brcmf_scb_val_le scbval; |
1805 | s32 err = 0; | |
1806 | ||
d96b801f | 1807 | brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code); |
ce81e317 | 1808 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1809 | return -EIO; |
1810 | ||
c1179033 | 1811 | clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
43dffbc6 | 1812 | cfg80211_disconnected(ndev, reason_code, NULL, 0, GFP_KERNEL); |
5b435de0 | 1813 | |
06bb123e | 1814 | memcpy(&scbval.ea, &profile->bssid, ETH_ALEN); |
5b435de0 | 1815 | scbval.val = cpu_to_le32(reason_code); |
c1179033 | 1816 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, |
ac24be6f | 1817 | &scbval, sizeof(scbval)); |
5b435de0 | 1818 | if (err) |
57d6e91a | 1819 | brcmf_err("error (%d)\n", err); |
5b435de0 | 1820 | |
d96b801f | 1821 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1822 | return err; |
1823 | } | |
1824 | ||
1825 | static s32 | |
c8442118 | 1826 | brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, |
d3f31134 | 1827 | enum nl80211_tx_power_setting type, s32 mbm) |
5b435de0 AS |
1828 | { |
1829 | ||
27a68fe3 | 1830 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 AS |
1831 | struct net_device *ndev = cfg_to_ndev(cfg); |
1832 | struct brcmf_if *ifp = netdev_priv(ndev); | |
5b435de0 AS |
1833 | u16 txpwrmw; |
1834 | s32 err = 0; | |
1835 | s32 disable = 0; | |
d3f31134 | 1836 | s32 dbm = MBM_TO_DBM(mbm); |
5b435de0 | 1837 | |
d96b801f | 1838 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 1839 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1840 | return -EIO; |
1841 | ||
1842 | switch (type) { | |
1843 | case NL80211_TX_POWER_AUTOMATIC: | |
1844 | break; | |
1845 | case NL80211_TX_POWER_LIMITED: | |
5b435de0 AS |
1846 | case NL80211_TX_POWER_FIXED: |
1847 | if (dbm < 0) { | |
57d6e91a | 1848 | brcmf_err("TX_POWER_FIXED - dbm is negative\n"); |
5b435de0 AS |
1849 | err = -EINVAL; |
1850 | goto done; | |
1851 | } | |
1852 | break; | |
1853 | } | |
1854 | /* Make sure radio is off or on as far as software is concerned */ | |
1855 | disable = WL_RADIO_SW_DISABLE << 16; | |
ac24be6f | 1856 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable); |
5b435de0 | 1857 | if (err) |
57d6e91a | 1858 | brcmf_err("WLC_SET_RADIO error (%d)\n", err); |
5b435de0 AS |
1859 | |
1860 | if (dbm > 0xffff) | |
1861 | txpwrmw = 0xffff; | |
1862 | else | |
1863 | txpwrmw = (u16) dbm; | |
ac24be6f AS |
1864 | err = brcmf_fil_iovar_int_set(ifp, "qtxpower", |
1865 | (s32)brcmf_mw_to_qdbm(txpwrmw)); | |
5b435de0 | 1866 | if (err) |
57d6e91a | 1867 | brcmf_err("qtxpower error (%d)\n", err); |
27a68fe3 | 1868 | cfg->conf->tx_power = dbm; |
5b435de0 AS |
1869 | |
1870 | done: | |
d96b801f | 1871 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1872 | return err; |
1873 | } | |
1874 | ||
c8442118 JB |
1875 | static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, |
1876 | struct wireless_dev *wdev, | |
1877 | s32 *dbm) | |
5b435de0 | 1878 | { |
27a68fe3 | 1879 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 1880 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
5b435de0 AS |
1881 | s32 txpwrdbm; |
1882 | u8 result; | |
1883 | s32 err = 0; | |
1884 | ||
d96b801f | 1885 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 1886 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1887 | return -EIO; |
1888 | ||
0abb5f21 | 1889 | err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &txpwrdbm); |
5b435de0 | 1890 | if (err) { |
57d6e91a | 1891 | brcmf_err("error (%d)\n", err); |
5b435de0 AS |
1892 | goto done; |
1893 | } | |
1894 | ||
1895 | result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE); | |
ef6ac17a | 1896 | *dbm = (s32) brcmf_qdbm_to_mw(result); |
5b435de0 AS |
1897 | |
1898 | done: | |
d96b801f | 1899 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1900 | return err; |
1901 | } | |
1902 | ||
1903 | static s32 | |
1904 | brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev, | |
1905 | u8 key_idx, bool unicast, bool multicast) | |
1906 | { | |
0abb5f21 | 1907 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
1908 | u32 index; |
1909 | u32 wsec; | |
1910 | s32 err = 0; | |
1911 | ||
d96b801f | 1912 | brcmf_dbg(TRACE, "Enter\n"); |
16886735 | 1913 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
ce81e317 | 1914 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
1915 | return -EIO; |
1916 | ||
0abb5f21 | 1917 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
5b435de0 | 1918 | if (err) { |
57d6e91a | 1919 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
5b435de0 AS |
1920 | goto done; |
1921 | } | |
1922 | ||
1923 | if (wsec & WEP_ENABLED) { | |
1924 | /* Just select a new current key */ | |
1925 | index = key_idx; | |
0abb5f21 | 1926 | err = brcmf_fil_cmd_int_set(ifp, |
ac24be6f | 1927 | BRCMF_C_SET_KEY_PRIMARY, index); |
5b435de0 | 1928 | if (err) |
57d6e91a | 1929 | brcmf_err("error (%d)\n", err); |
5b435de0 AS |
1930 | } |
1931 | done: | |
d96b801f | 1932 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
1933 | return err; |
1934 | } | |
1935 | ||
1936 | static s32 | |
1937 | brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev, | |
1938 | u8 key_idx, const u8 *mac_addr, struct key_params *params) | |
1939 | { | |
992f6068 | 1940 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 | 1941 | struct brcmf_wsec_key key; |
5b435de0 | 1942 | s32 err = 0; |
992f6068 | 1943 | u8 keybuf[8]; |
5b435de0 AS |
1944 | |
1945 | memset(&key, 0, sizeof(key)); | |
1946 | key.index = (u32) key_idx; | |
1947 | /* Instead of bcast for ea address for default wep keys, | |
1948 | driver needs it to be Null */ | |
1949 | if (!is_multicast_ether_addr(mac_addr)) | |
1950 | memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN); | |
1951 | key.len = (u32) params->key_len; | |
1952 | /* check for key index change */ | |
1953 | if (key.len == 0) { | |
1954 | /* key delete */ | |
2eaba7e8 | 1955 | err = send_key_to_dongle(ndev, &key); |
5b435de0 | 1956 | if (err) |
57d6e91a | 1957 | brcmf_err("key delete error (%d)\n", err); |
5b435de0 AS |
1958 | } else { |
1959 | if (key.len > sizeof(key.data)) { | |
57d6e91a | 1960 | brcmf_err("Invalid key length (%d)\n", key.len); |
5b435de0 AS |
1961 | return -EINVAL; |
1962 | } | |
1963 | ||
16886735 | 1964 | brcmf_dbg(CONN, "Setting the key index %d\n", key.index); |
5b435de0 AS |
1965 | memcpy(key.data, params->key, key.len); |
1966 | ||
967fe2c8 | 1967 | if (!brcmf_is_apmode(ifp->vif) && |
992f6068 HM |
1968 | (params->cipher == WLAN_CIPHER_SUITE_TKIP)) { |
1969 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); | |
5b435de0 AS |
1970 | memcpy(keybuf, &key.data[24], sizeof(keybuf)); |
1971 | memcpy(&key.data[24], &key.data[16], sizeof(keybuf)); | |
1972 | memcpy(&key.data[16], keybuf, sizeof(keybuf)); | |
1973 | } | |
1974 | ||
1975 | /* if IW_ENCODE_EXT_RX_SEQ_VALID set */ | |
1976 | if (params->seq && params->seq_len == 6) { | |
1977 | /* rx iv */ | |
1978 | u8 *ivptr; | |
1979 | ivptr = (u8 *) params->seq; | |
1980 | key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) | | |
1981 | (ivptr[3] << 8) | ivptr[2]; | |
1982 | key.rxiv.lo = (ivptr[1] << 8) | ivptr[0]; | |
1983 | key.iv_initialized = true; | |
1984 | } | |
1985 | ||
1986 | switch (params->cipher) { | |
1987 | case WLAN_CIPHER_SUITE_WEP40: | |
1988 | key.algo = CRYPTO_ALGO_WEP1; | |
16886735 | 1989 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
5b435de0 AS |
1990 | break; |
1991 | case WLAN_CIPHER_SUITE_WEP104: | |
1992 | key.algo = CRYPTO_ALGO_WEP128; | |
16886735 | 1993 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
5b435de0 AS |
1994 | break; |
1995 | case WLAN_CIPHER_SUITE_TKIP: | |
1996 | key.algo = CRYPTO_ALGO_TKIP; | |
16886735 | 1997 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
5b435de0 AS |
1998 | break; |
1999 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
2000 | key.algo = CRYPTO_ALGO_AES_CCM; | |
16886735 | 2001 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
5b435de0 AS |
2002 | break; |
2003 | case WLAN_CIPHER_SUITE_CCMP: | |
2004 | key.algo = CRYPTO_ALGO_AES_CCM; | |
16886735 | 2005 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
5b435de0 AS |
2006 | break; |
2007 | default: | |
57d6e91a | 2008 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
5b435de0 AS |
2009 | return -EINVAL; |
2010 | } | |
2eaba7e8 | 2011 | err = send_key_to_dongle(ndev, &key); |
f09d0c02 | 2012 | if (err) |
57d6e91a | 2013 | brcmf_err("wsec_key error (%d)\n", err); |
5b435de0 AS |
2014 | } |
2015 | return err; | |
2016 | } | |
2017 | ||
2018 | static s32 | |
2019 | brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, | |
2020 | u8 key_idx, bool pairwise, const u8 *mac_addr, | |
2021 | struct key_params *params) | |
2022 | { | |
0abb5f21 | 2023 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
2024 | struct brcmf_wsec_key key; |
2025 | s32 val; | |
2026 | s32 wsec; | |
2027 | s32 err = 0; | |
2028 | u8 keybuf[8]; | |
2029 | ||
d96b801f | 2030 | brcmf_dbg(TRACE, "Enter\n"); |
16886735 | 2031 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
ce81e317 | 2032 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2033 | return -EIO; |
2034 | ||
787eb033 DK |
2035 | if (mac_addr && |
2036 | (params->cipher != WLAN_CIPHER_SUITE_WEP40) && | |
2037 | (params->cipher != WLAN_CIPHER_SUITE_WEP104)) { | |
d96b801f | 2038 | brcmf_dbg(TRACE, "Exit"); |
5b435de0 AS |
2039 | return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params); |
2040 | } | |
2041 | memset(&key, 0, sizeof(key)); | |
2042 | ||
2043 | key.len = (u32) params->key_len; | |
2044 | key.index = (u32) key_idx; | |
2045 | ||
2046 | if (key.len > sizeof(key.data)) { | |
57d6e91a | 2047 | brcmf_err("Too long key length (%u)\n", key.len); |
5b435de0 AS |
2048 | err = -EINVAL; |
2049 | goto done; | |
2050 | } | |
2051 | memcpy(key.data, params->key, key.len); | |
2052 | ||
2053 | key.flags = BRCMF_PRIMARY_KEY; | |
2054 | switch (params->cipher) { | |
2055 | case WLAN_CIPHER_SUITE_WEP40: | |
2056 | key.algo = CRYPTO_ALGO_WEP1; | |
f09d0c02 | 2057 | val = WEP_ENABLED; |
16886735 | 2058 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
5b435de0 AS |
2059 | break; |
2060 | case WLAN_CIPHER_SUITE_WEP104: | |
2061 | key.algo = CRYPTO_ALGO_WEP128; | |
f09d0c02 | 2062 | val = WEP_ENABLED; |
16886735 | 2063 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
5b435de0 AS |
2064 | break; |
2065 | case WLAN_CIPHER_SUITE_TKIP: | |
967fe2c8 | 2066 | if (!brcmf_is_apmode(ifp->vif)) { |
992f6068 | 2067 | brcmf_dbg(CONN, "Swapping RX/TX MIC key\n"); |
1a873342 HM |
2068 | memcpy(keybuf, &key.data[24], sizeof(keybuf)); |
2069 | memcpy(&key.data[24], &key.data[16], sizeof(keybuf)); | |
2070 | memcpy(&key.data[16], keybuf, sizeof(keybuf)); | |
2071 | } | |
5b435de0 | 2072 | key.algo = CRYPTO_ALGO_TKIP; |
f09d0c02 | 2073 | val = TKIP_ENABLED; |
16886735 | 2074 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
5b435de0 AS |
2075 | break; |
2076 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
2077 | key.algo = CRYPTO_ALGO_AES_CCM; | |
f09d0c02 | 2078 | val = AES_ENABLED; |
16886735 | 2079 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
5b435de0 AS |
2080 | break; |
2081 | case WLAN_CIPHER_SUITE_CCMP: | |
2082 | key.algo = CRYPTO_ALGO_AES_CCM; | |
f09d0c02 | 2083 | val = AES_ENABLED; |
16886735 | 2084 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n"); |
5b435de0 AS |
2085 | break; |
2086 | default: | |
57d6e91a | 2087 | brcmf_err("Invalid cipher (0x%x)\n", params->cipher); |
5b435de0 AS |
2088 | err = -EINVAL; |
2089 | goto done; | |
2090 | } | |
2091 | ||
2eaba7e8 | 2092 | err = send_key_to_dongle(ndev, &key); |
5b435de0 AS |
2093 | if (err) |
2094 | goto done; | |
2095 | ||
0abb5f21 | 2096 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
5b435de0 | 2097 | if (err) { |
57d6e91a | 2098 | brcmf_err("get wsec error (%d)\n", err); |
5b435de0 AS |
2099 | goto done; |
2100 | } | |
5b435de0 | 2101 | wsec |= val; |
0abb5f21 | 2102 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
5b435de0 | 2103 | if (err) { |
57d6e91a | 2104 | brcmf_err("set wsec error (%d)\n", err); |
5b435de0 AS |
2105 | goto done; |
2106 | } | |
2107 | ||
5b435de0 | 2108 | done: |
d96b801f | 2109 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2110 | return err; |
2111 | } | |
2112 | ||
2113 | static s32 | |
2114 | brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, | |
2115 | u8 key_idx, bool pairwise, const u8 *mac_addr) | |
2116 | { | |
0abb5f21 | 2117 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
2118 | struct brcmf_wsec_key key; |
2119 | s32 err = 0; | |
5b435de0 | 2120 | |
d96b801f | 2121 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 2122 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2123 | return -EIO; |
2124 | ||
256c374f HM |
2125 | if (key_idx >= DOT11_MAX_DEFAULT_KEYS) { |
2126 | /* we ignore this key index in this case */ | |
57d6e91a | 2127 | brcmf_err("invalid key index (%d)\n", key_idx); |
256c374f HM |
2128 | return -EINVAL; |
2129 | } | |
2130 | ||
5b435de0 AS |
2131 | memset(&key, 0, sizeof(key)); |
2132 | ||
2133 | key.index = (u32) key_idx; | |
2134 | key.flags = BRCMF_PRIMARY_KEY; | |
2135 | key.algo = CRYPTO_ALGO_OFF; | |
2136 | ||
16886735 | 2137 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
5b435de0 AS |
2138 | |
2139 | /* Set the new key/index */ | |
2eaba7e8 | 2140 | err = send_key_to_dongle(ndev, &key); |
5b435de0 | 2141 | |
d96b801f | 2142 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2143 | return err; |
2144 | } | |
2145 | ||
2146 | static s32 | |
2147 | brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, | |
2148 | u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie, | |
2149 | void (*callback) (void *cookie, struct key_params * params)) | |
2150 | { | |
2151 | struct key_params params; | |
0abb5f21 AS |
2152 | struct brcmf_if *ifp = netdev_priv(ndev); |
2153 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
5b435de0 AS |
2154 | struct brcmf_cfg80211_security *sec; |
2155 | s32 wsec; | |
2156 | s32 err = 0; | |
2157 | ||
d96b801f | 2158 | brcmf_dbg(TRACE, "Enter\n"); |
16886735 | 2159 | brcmf_dbg(CONN, "key index (%d)\n", key_idx); |
ce81e317 | 2160 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2161 | return -EIO; |
2162 | ||
2163 | memset(¶ms, 0, sizeof(params)); | |
2164 | ||
0abb5f21 | 2165 | err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec); |
5b435de0 | 2166 | if (err) { |
57d6e91a | 2167 | brcmf_err("WLC_GET_WSEC error (%d)\n", err); |
5b435de0 AS |
2168 | /* Ignore this error, may happen during DISASSOC */ |
2169 | err = -EAGAIN; | |
2170 | goto done; | |
2171 | } | |
c5bf53a8 | 2172 | if (wsec & WEP_ENABLED) { |
06bb123e | 2173 | sec = &profile->sec; |
5b435de0 AS |
2174 | if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { |
2175 | params.cipher = WLAN_CIPHER_SUITE_WEP40; | |
16886735 | 2176 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n"); |
5b435de0 AS |
2177 | } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { |
2178 | params.cipher = WLAN_CIPHER_SUITE_WEP104; | |
16886735 | 2179 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n"); |
5b435de0 | 2180 | } |
c5bf53a8 | 2181 | } else if (wsec & TKIP_ENABLED) { |
5b435de0 | 2182 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
16886735 | 2183 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n"); |
c5bf53a8 | 2184 | } else if (wsec & AES_ENABLED) { |
5b435de0 | 2185 | params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
16886735 | 2186 | brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n"); |
c5bf53a8 | 2187 | } else { |
57d6e91a | 2188 | brcmf_err("Invalid algo (0x%x)\n", wsec); |
5b435de0 AS |
2189 | err = -EINVAL; |
2190 | goto done; | |
2191 | } | |
2192 | callback(cookie, ¶ms); | |
2193 | ||
2194 | done: | |
d96b801f | 2195 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2196 | return err; |
2197 | } | |
2198 | ||
2199 | static s32 | |
2200 | brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, | |
2201 | struct net_device *ndev, u8 key_idx) | |
2202 | { | |
647c9ae0 | 2203 | brcmf_dbg(INFO, "Not supported\n"); |
5b435de0 AS |
2204 | |
2205 | return -EOPNOTSUPP; | |
2206 | } | |
2207 | ||
2208 | static s32 | |
2209 | brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev, | |
3b3a0162 | 2210 | const u8 *mac, struct station_info *sinfo) |
5b435de0 | 2211 | { |
0abb5f21 AS |
2212 | struct brcmf_if *ifp = netdev_priv(ndev); |
2213 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
5b435de0 AS |
2214 | struct brcmf_scb_val_le scb_val; |
2215 | int rssi; | |
2216 | s32 rate; | |
2217 | s32 err = 0; | |
06bb123e | 2218 | u8 *bssid = profile->bssid; |
81f5dcb8 | 2219 | struct brcmf_sta_info_le sta_info_le; |
9ee66d1b HM |
2220 | u32 beacon_period; |
2221 | u32 dtim_period; | |
5b435de0 | 2222 | |
d96b801f | 2223 | brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac); |
ce81e317 | 2224 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2225 | return -EIO; |
2226 | ||
967fe2c8 | 2227 | if (brcmf_is_apmode(ifp->vif)) { |
81f5dcb8 | 2228 | memcpy(&sta_info_le, mac, ETH_ALEN); |
0abb5f21 | 2229 | err = brcmf_fil_iovar_data_get(ifp, "sta_info", |
ac24be6f | 2230 | &sta_info_le, |
81f5dcb8 | 2231 | sizeof(sta_info_le)); |
1a873342 | 2232 | if (err < 0) { |
57d6e91a | 2233 | brcmf_err("GET STA INFO failed, %d\n", err); |
1a873342 HM |
2234 | goto done; |
2235 | } | |
1a873342 | 2236 | sinfo->filled = STATION_INFO_INACTIVE_TIME; |
81f5dcb8 HM |
2237 | sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000; |
2238 | if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) { | |
1a873342 | 2239 | sinfo->filled |= STATION_INFO_CONNECTED_TIME; |
81f5dcb8 | 2240 | sinfo->connected_time = le32_to_cpu(sta_info_le.in); |
1a873342 | 2241 | } |
d96b801f AS |
2242 | brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n", |
2243 | sinfo->inactive_time, sinfo->connected_time); | |
967fe2c8 | 2244 | } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) { |
1a873342 | 2245 | if (memcmp(mac, bssid, ETH_ALEN)) { |
57d6e91a AS |
2246 | brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n", |
2247 | mac, bssid); | |
1a873342 HM |
2248 | err = -ENOENT; |
2249 | goto done; | |
2250 | } | |
2251 | /* Report the current tx rate */ | |
89286dc9 | 2252 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate); |
7f6c562d | 2253 | if (err) { |
57d6e91a | 2254 | brcmf_err("Could not get rate (%d)\n", err); |
1a873342 | 2255 | goto done; |
7f6c562d | 2256 | } else { |
1a873342 HM |
2257 | sinfo->filled |= STATION_INFO_TX_BITRATE; |
2258 | sinfo->txrate.legacy = rate * 5; | |
16886735 | 2259 | brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2); |
7f6c562d | 2260 | } |
5b435de0 | 2261 | |
c1179033 AS |
2262 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, |
2263 | &ifp->vif->sme_state)) { | |
1a873342 | 2264 | memset(&scb_val, 0, sizeof(scb_val)); |
c1179033 AS |
2265 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, |
2266 | &scb_val, sizeof(scb_val)); | |
1a873342 | 2267 | if (err) { |
57d6e91a | 2268 | brcmf_err("Could not get rssi (%d)\n", err); |
1a873342 HM |
2269 | goto done; |
2270 | } else { | |
2271 | rssi = le32_to_cpu(scb_val.val); | |
2272 | sinfo->filled |= STATION_INFO_SIGNAL; | |
2273 | sinfo->signal = rssi; | |
16886735 | 2274 | brcmf_dbg(CONN, "RSSI %d dBm\n", rssi); |
1a873342 | 2275 | } |
9ee66d1b HM |
2276 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD, |
2277 | &beacon_period); | |
2278 | if (err) { | |
2279 | brcmf_err("Could not get beacon period (%d)\n", | |
2280 | err); | |
2281 | goto done; | |
2282 | } else { | |
2283 | sinfo->bss_param.beacon_interval = | |
2284 | beacon_period; | |
2285 | brcmf_dbg(CONN, "Beacon peroid %d\n", | |
2286 | beacon_period); | |
2287 | } | |
2288 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD, | |
2289 | &dtim_period); | |
2290 | if (err) { | |
2291 | brcmf_err("Could not get DTIM period (%d)\n", | |
2292 | err); | |
2293 | goto done; | |
2294 | } else { | |
2295 | sinfo->bss_param.dtim_period = dtim_period; | |
2296 | brcmf_dbg(CONN, "DTIM peroid %d\n", | |
2297 | dtim_period); | |
2298 | } | |
2299 | sinfo->filled |= STATION_INFO_BSS_PARAM; | |
1a873342 HM |
2300 | } |
2301 | } else | |
2302 | err = -EPERM; | |
5b435de0 | 2303 | done: |
d96b801f | 2304 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2305 | return err; |
2306 | } | |
2307 | ||
2308 | static s32 | |
2309 | brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev, | |
2310 | bool enabled, s32 timeout) | |
2311 | { | |
2312 | s32 pm; | |
2313 | s32 err = 0; | |
27a68fe3 | 2314 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
c1179033 | 2315 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 | 2316 | |
d96b801f | 2317 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 AS |
2318 | |
2319 | /* | |
2320 | * Powersave enable/disable request is coming from the | |
2321 | * cfg80211 even before the interface is up. In that | |
2322 | * scenario, driver will be storing the power save | |
27a68fe3 | 2323 | * preference in cfg struct to apply this to |
5b435de0 AS |
2324 | * FW later while initializing the dongle |
2325 | */ | |
27a68fe3 | 2326 | cfg->pwr_save = enabled; |
ce81e317 | 2327 | if (!check_vif_up(ifp->vif)) { |
5b435de0 | 2328 | |
647c9ae0 | 2329 | brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n"); |
5b435de0 AS |
2330 | goto done; |
2331 | } | |
2332 | ||
2333 | pm = enabled ? PM_FAST : PM_OFF; | |
102fd0d6 HM |
2334 | /* Do not enable the power save after assoc if it is a p2p interface */ |
2335 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { | |
2336 | brcmf_dbg(INFO, "Do not enable power save for P2P clients\n"); | |
2337 | pm = PM_OFF; | |
2338 | } | |
647c9ae0 | 2339 | brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled")); |
5b435de0 | 2340 | |
c1179033 | 2341 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm); |
5b435de0 AS |
2342 | if (err) { |
2343 | if (err == -ENODEV) | |
57d6e91a | 2344 | brcmf_err("net_device is not ready yet\n"); |
5b435de0 | 2345 | else |
57d6e91a | 2346 | brcmf_err("error (%d)\n", err); |
5b435de0 AS |
2347 | } |
2348 | done: | |
d96b801f | 2349 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2350 | return err; |
2351 | } | |
2352 | ||
27a68fe3 | 2353 | static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg, |
d34bf64f | 2354 | struct brcmf_bss_info_le *bi) |
5b435de0 | 2355 | { |
27a68fe3 | 2356 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
5b435de0 AS |
2357 | struct ieee80211_channel *notify_channel; |
2358 | struct cfg80211_bss *bss; | |
2359 | struct ieee80211_supported_band *band; | |
83cf17aa | 2360 | struct brcmu_chan ch; |
5b435de0 AS |
2361 | u16 channel; |
2362 | u32 freq; | |
5b435de0 AS |
2363 | u16 notify_capability; |
2364 | u16 notify_interval; | |
2365 | u8 *notify_ie; | |
2366 | size_t notify_ielen; | |
2367 | s32 notify_signal; | |
2368 | ||
2369 | if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) { | |
57d6e91a | 2370 | brcmf_err("Bss info is larger than buffer. Discarding\n"); |
5b435de0 AS |
2371 | return 0; |
2372 | } | |
2373 | ||
83cf17aa FL |
2374 | if (!bi->ctl_ch) { |
2375 | ch.chspec = le16_to_cpu(bi->chanspec); | |
2376 | cfg->d11inf.decchspec(&ch); | |
2377 | bi->ctl_ch = ch.chnum; | |
2378 | } | |
2379 | channel = bi->ctl_ch; | |
5b435de0 AS |
2380 | |
2381 | if (channel <= CH_MAX_2G_CHANNEL) | |
2382 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; | |
2383 | else | |
2384 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | |
2385 | ||
2386 | freq = ieee80211_channel_to_frequency(channel, band->band); | |
2387 | notify_channel = ieee80211_get_channel(wiphy, freq); | |
2388 | ||
5b435de0 AS |
2389 | notify_capability = le16_to_cpu(bi->capability); |
2390 | notify_interval = le16_to_cpu(bi->beacon_period); | |
2391 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); | |
2392 | notify_ielen = le32_to_cpu(bi->ie_length); | |
2393 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; | |
2394 | ||
16886735 AS |
2395 | brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID); |
2396 | brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq); | |
2397 | brcmf_dbg(CONN, "Capability: %X\n", notify_capability); | |
2398 | brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval); | |
2399 | brcmf_dbg(CONN, "Signal: %d\n", notify_signal); | |
5b435de0 | 2400 | |
5bc8c1f2 JB |
2401 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
2402 | CFG80211_BSS_FTYPE_UNKNOWN, | |
2403 | (const u8 *)bi->BSSID, | |
2404 | 0, notify_capability, | |
2405 | notify_interval, notify_ie, | |
2406 | notify_ielen, notify_signal, | |
2407 | GFP_KERNEL); | |
5b435de0 | 2408 | |
e78946e1 FL |
2409 | if (!bss) |
2410 | return -ENOMEM; | |
2411 | ||
5b112d3d | 2412 | cfg80211_put_bss(wiphy, bss); |
5b435de0 | 2413 | |
12f32370 | 2414 | return 0; |
5b435de0 AS |
2415 | } |
2416 | ||
6f09be0a RV |
2417 | static struct brcmf_bss_info_le * |
2418 | next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss) | |
2419 | { | |
2420 | if (bss == NULL) | |
2421 | return list->bss_info_le; | |
2422 | return (struct brcmf_bss_info_le *)((unsigned long)bss + | |
2423 | le32_to_cpu(bss->length)); | |
2424 | } | |
2425 | ||
27a68fe3 | 2426 | static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) |
5b435de0 AS |
2427 | { |
2428 | struct brcmf_scan_results *bss_list; | |
d34bf64f | 2429 | struct brcmf_bss_info_le *bi = NULL; /* must be initialized */ |
5b435de0 AS |
2430 | s32 err = 0; |
2431 | int i; | |
2432 | ||
ef8596e1 | 2433 | bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; |
0ecd8164 AS |
2434 | if (bss_list->count != 0 && |
2435 | bss_list->version != BRCMF_BSS_INFO_VERSION) { | |
57d6e91a AS |
2436 | brcmf_err("Version %d != WL_BSS_INFO_VERSION\n", |
2437 | bss_list->version); | |
5b435de0 AS |
2438 | return -EOPNOTSUPP; |
2439 | } | |
4e8a008e | 2440 | brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count); |
f0799895 | 2441 | for (i = 0; i < bss_list->count; i++) { |
6f09be0a | 2442 | bi = next_bss_le(bss_list, bi); |
27a68fe3 | 2443 | err = brcmf_inform_single_bss(cfg, bi); |
5b435de0 AS |
2444 | if (err) |
2445 | break; | |
2446 | } | |
2447 | return err; | |
2448 | } | |
2449 | ||
27a68fe3 | 2450 | static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
2451 | struct net_device *ndev, const u8 *bssid) |
2452 | { | |
27a68fe3 | 2453 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
5b435de0 | 2454 | struct ieee80211_channel *notify_channel; |
d34bf64f | 2455 | struct brcmf_bss_info_le *bi = NULL; |
5b435de0 | 2456 | struct ieee80211_supported_band *band; |
e78946e1 | 2457 | struct cfg80211_bss *bss; |
83cf17aa | 2458 | struct brcmu_chan ch; |
5b435de0 AS |
2459 | u8 *buf = NULL; |
2460 | s32 err = 0; | |
5b435de0 | 2461 | u32 freq; |
5b435de0 AS |
2462 | u16 notify_capability; |
2463 | u16 notify_interval; | |
2464 | u8 *notify_ie; | |
2465 | size_t notify_ielen; | |
2466 | s32 notify_signal; | |
2467 | ||
d96b801f | 2468 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 AS |
2469 | |
2470 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); | |
2471 | if (buf == NULL) { | |
2472 | err = -ENOMEM; | |
2473 | goto CleanUp; | |
2474 | } | |
2475 | ||
2476 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); | |
2477 | ||
ac24be6f AS |
2478 | err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO, |
2479 | buf, WL_BSS_INFO_MAX); | |
5b435de0 | 2480 | if (err) { |
57d6e91a | 2481 | brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err); |
5b435de0 AS |
2482 | goto CleanUp; |
2483 | } | |
2484 | ||
d34bf64f | 2485 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
5b435de0 | 2486 | |
83cf17aa FL |
2487 | ch.chspec = le16_to_cpu(bi->chanspec); |
2488 | cfg->d11inf.decchspec(&ch); | |
5b435de0 | 2489 | |
83cf17aa | 2490 | if (ch.band == BRCMU_CHAN_BAND_2G) |
5b435de0 AS |
2491 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
2492 | else | |
2493 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | |
2494 | ||
83cf17aa | 2495 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
5b435de0 AS |
2496 | notify_channel = ieee80211_get_channel(wiphy, freq); |
2497 | ||
5b435de0 AS |
2498 | notify_capability = le16_to_cpu(bi->capability); |
2499 | notify_interval = le16_to_cpu(bi->beacon_period); | |
2500 | notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset); | |
2501 | notify_ielen = le32_to_cpu(bi->ie_length); | |
2502 | notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100; | |
2503 | ||
83cf17aa | 2504 | brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq); |
16886735 AS |
2505 | brcmf_dbg(CONN, "capability: %X\n", notify_capability); |
2506 | brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval); | |
2507 | brcmf_dbg(CONN, "signal: %d\n", notify_signal); | |
5b435de0 | 2508 | |
5bc8c1f2 JB |
2509 | bss = cfg80211_inform_bss(wiphy, notify_channel, |
2510 | CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0, | |
2511 | notify_capability, notify_interval, | |
2512 | notify_ie, notify_ielen, notify_signal, | |
2513 | GFP_KERNEL); | |
5b435de0 | 2514 | |
e78946e1 FL |
2515 | if (!bss) { |
2516 | err = -ENOMEM; | |
2517 | goto CleanUp; | |
2518 | } | |
2519 | ||
5b112d3d | 2520 | cfg80211_put_bss(wiphy, bss); |
e78946e1 | 2521 | |
5b435de0 AS |
2522 | CleanUp: |
2523 | ||
2524 | kfree(buf); | |
2525 | ||
d96b801f | 2526 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2527 | |
2528 | return err; | |
2529 | } | |
2530 | ||
89286dc9 HM |
2531 | static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg, |
2532 | struct brcmf_if *ifp) | |
1a873342 | 2533 | { |
89286dc9 | 2534 | struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev); |
d34bf64f | 2535 | struct brcmf_bss_info_le *bi; |
5b435de0 | 2536 | struct brcmf_ssid *ssid; |
4b5800fe | 2537 | const struct brcmf_tlv *tim; |
5b435de0 AS |
2538 | u16 beacon_interval; |
2539 | u8 dtim_period; | |
2540 | size_t ie_len; | |
2541 | u8 *ie; | |
2542 | s32 err = 0; | |
2543 | ||
d96b801f | 2544 | brcmf_dbg(TRACE, "Enter\n"); |
128ce3b6 | 2545 | if (brcmf_is_ibssmode(ifp->vif)) |
5b435de0 AS |
2546 | return err; |
2547 | ||
06bb123e | 2548 | ssid = &profile->ssid; |
5b435de0 | 2549 | |
27a68fe3 | 2550 | *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX); |
ac24be6f | 2551 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
81f5dcb8 | 2552 | cfg->extra_buf, WL_EXTRA_BUF_MAX); |
5b435de0 | 2553 | if (err) { |
57d6e91a | 2554 | brcmf_err("Could not get bss info %d\n", err); |
5b435de0 AS |
2555 | goto update_bss_info_out; |
2556 | } | |
2557 | ||
27a68fe3 AS |
2558 | bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4); |
2559 | err = brcmf_inform_single_bss(cfg, bi); | |
5b435de0 AS |
2560 | if (err) |
2561 | goto update_bss_info_out; | |
2562 | ||
2563 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); | |
2564 | ie_len = le32_to_cpu(bi->ie_length); | |
2565 | beacon_interval = le16_to_cpu(bi->beacon_period); | |
2566 | ||
f8e4b412 | 2567 | tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM); |
5b435de0 AS |
2568 | if (tim) |
2569 | dtim_period = tim->data[1]; | |
2570 | else { | |
2571 | /* | |
2572 | * active scan was done so we could not get dtim | |
2573 | * information out of probe response. | |
2574 | * so we speficially query dtim information to dongle. | |
2575 | */ | |
2576 | u32 var; | |
ac24be6f | 2577 | err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var); |
5b435de0 | 2578 | if (err) { |
57d6e91a | 2579 | brcmf_err("wl dtim_assoc failed (%d)\n", err); |
5b435de0 AS |
2580 | goto update_bss_info_out; |
2581 | } | |
2582 | dtim_period = (u8)var; | |
2583 | } | |
2584 | ||
5b435de0 | 2585 | update_bss_info_out: |
d96b801f | 2586 | brcmf_dbg(TRACE, "Exit"); |
5b435de0 AS |
2587 | return err; |
2588 | } | |
2589 | ||
18e2f61d | 2590 | void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 2591 | { |
27a68fe3 | 2592 | struct escan_info *escan = &cfg->escan_info; |
5b435de0 | 2593 | |
c1179033 | 2594 | set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); |
f0799895 | 2595 | if (cfg->scan_request) { |
108a4bee | 2596 | escan->escan_state = WL_ESCAN_STATE_IDLE; |
a0f472ac | 2597 | brcmf_notify_escan_complete(cfg, escan->ifp, true, true); |
5b435de0 | 2598 | } |
c1179033 AS |
2599 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
2600 | clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status); | |
5b435de0 AS |
2601 | } |
2602 | ||
e756af5b HM |
2603 | static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work) |
2604 | { | |
27a68fe3 AS |
2605 | struct brcmf_cfg80211_info *cfg = |
2606 | container_of(work, struct brcmf_cfg80211_info, | |
e756af5b HM |
2607 | escan_timeout_work); |
2608 | ||
ef8596e1 | 2609 | brcmf_inform_bss(cfg); |
a0f472ac | 2610 | brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true); |
e756af5b HM |
2611 | } |
2612 | ||
2613 | static void brcmf_escan_timeout(unsigned long data) | |
2614 | { | |
27a68fe3 AS |
2615 | struct brcmf_cfg80211_info *cfg = |
2616 | (struct brcmf_cfg80211_info *)data; | |
e756af5b | 2617 | |
27a68fe3 | 2618 | if (cfg->scan_request) { |
57d6e91a | 2619 | brcmf_err("timer expired\n"); |
f0799895 | 2620 | schedule_work(&cfg->escan_timeout_work); |
e756af5b HM |
2621 | } |
2622 | } | |
2623 | ||
2624 | static s32 | |
83cf17aa FL |
2625 | brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg, |
2626 | struct brcmf_bss_info_le *bss, | |
e756af5b HM |
2627 | struct brcmf_bss_info_le *bss_info_le) |
2628 | { | |
83cf17aa FL |
2629 | struct brcmu_chan ch_bss, ch_bss_info_le; |
2630 | ||
2631 | ch_bss.chspec = le16_to_cpu(bss->chanspec); | |
2632 | cfg->d11inf.decchspec(&ch_bss); | |
2633 | ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec); | |
2634 | cfg->d11inf.decchspec(&ch_bss_info_le); | |
2635 | ||
e756af5b | 2636 | if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) && |
83cf17aa | 2637 | ch_bss.band == ch_bss_info_le.band && |
e756af5b HM |
2638 | bss_info_le->SSID_len == bss->SSID_len && |
2639 | !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) { | |
6f5838a4 AS |
2640 | if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == |
2641 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) { | |
029591f3 AS |
2642 | s16 bss_rssi = le16_to_cpu(bss->RSSI); |
2643 | s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI); | |
2644 | ||
e756af5b HM |
2645 | /* preserve max RSSI if the measurements are |
2646 | * both on-channel or both off-channel | |
2647 | */ | |
029591f3 | 2648 | if (bss_info_rssi > bss_rssi) |
e756af5b | 2649 | bss->RSSI = bss_info_le->RSSI; |
6f5838a4 AS |
2650 | } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) && |
2651 | (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) { | |
e756af5b HM |
2652 | /* preserve the on-channel rssi measurement |
2653 | * if the new measurement is off channel | |
2654 | */ | |
2655 | bss->RSSI = bss_info_le->RSSI; | |
6f5838a4 | 2656 | bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL; |
e756af5b HM |
2657 | } |
2658 | return 1; | |
2659 | } | |
2660 | return 0; | |
2661 | } | |
2662 | ||
2663 | static s32 | |
1993732e | 2664 | brcmf_cfg80211_escan_handler(struct brcmf_if *ifp, |
e756af5b HM |
2665 | const struct brcmf_event_msg *e, void *data) |
2666 | { | |
1993732e | 2667 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
e756af5b | 2668 | s32 status; |
e756af5b HM |
2669 | struct brcmf_escan_result_le *escan_result_le; |
2670 | struct brcmf_bss_info_le *bss_info_le; | |
2671 | struct brcmf_bss_info_le *bss = NULL; | |
2672 | u32 bi_length; | |
2673 | struct brcmf_scan_results *list; | |
2674 | u32 i; | |
97ed15c7 | 2675 | bool aborted; |
e756af5b | 2676 | |
5c36b99a | 2677 | status = e->status; |
e756af5b | 2678 | |
a0f472ac AS |
2679 | if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
2680 | brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx); | |
e756af5b HM |
2681 | return -EPERM; |
2682 | } | |
2683 | ||
2684 | if (status == BRCMF_E_STATUS_PARTIAL) { | |
4e8a008e | 2685 | brcmf_dbg(SCAN, "ESCAN Partial result\n"); |
e756af5b HM |
2686 | escan_result_le = (struct brcmf_escan_result_le *) data; |
2687 | if (!escan_result_le) { | |
57d6e91a | 2688 | brcmf_err("Invalid escan result (NULL pointer)\n"); |
e756af5b HM |
2689 | goto exit; |
2690 | } | |
e756af5b | 2691 | if (le16_to_cpu(escan_result_le->bss_count) != 1) { |
57d6e91a AS |
2692 | brcmf_err("Invalid bss_count %d: ignoring\n", |
2693 | escan_result_le->bss_count); | |
e756af5b HM |
2694 | goto exit; |
2695 | } | |
2696 | bss_info_le = &escan_result_le->bss_info_le; | |
2697 | ||
6eda4e2c HM |
2698 | if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le)) |
2699 | goto exit; | |
2700 | ||
2701 | if (!cfg->scan_request) { | |
2702 | brcmf_dbg(SCAN, "result without cfg80211 request\n"); | |
2703 | goto exit; | |
2704 | } | |
2705 | ||
e756af5b HM |
2706 | bi_length = le32_to_cpu(bss_info_le->length); |
2707 | if (bi_length != (le32_to_cpu(escan_result_le->buflen) - | |
2708 | WL_ESCAN_RESULTS_FIXED_SIZE)) { | |
57d6e91a AS |
2709 | brcmf_err("Invalid bss_info length %d: ignoring\n", |
2710 | bi_length); | |
e756af5b HM |
2711 | goto exit; |
2712 | } | |
2713 | ||
27a68fe3 | 2714 | if (!(cfg_to_wiphy(cfg)->interface_modes & |
e756af5b HM |
2715 | BIT(NL80211_IFTYPE_ADHOC))) { |
2716 | if (le16_to_cpu(bss_info_le->capability) & | |
2717 | WLAN_CAPABILITY_IBSS) { | |
57d6e91a | 2718 | brcmf_err("Ignoring IBSS result\n"); |
e756af5b HM |
2719 | goto exit; |
2720 | } | |
2721 | } | |
2722 | ||
2723 | list = (struct brcmf_scan_results *) | |
27a68fe3 | 2724 | cfg->escan_info.escan_buf; |
e756af5b | 2725 | if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) { |
57d6e91a | 2726 | brcmf_err("Buffer is too small: ignoring\n"); |
e756af5b HM |
2727 | goto exit; |
2728 | } | |
2729 | ||
2730 | for (i = 0; i < list->count; i++) { | |
2731 | bss = bss ? (struct brcmf_bss_info_le *) | |
2732 | ((unsigned char *)bss + | |
2733 | le32_to_cpu(bss->length)) : list->bss_info_le; | |
83cf17aa FL |
2734 | if (brcmf_compare_update_same_bss(cfg, bss, |
2735 | bss_info_le)) | |
e756af5b HM |
2736 | goto exit; |
2737 | } | |
27a68fe3 | 2738 | memcpy(&(cfg->escan_info.escan_buf[list->buflen]), |
e756af5b HM |
2739 | bss_info_le, bi_length); |
2740 | list->version = le32_to_cpu(bss_info_le->version); | |
2741 | list->buflen += bi_length; | |
2742 | list->count++; | |
2743 | } else { | |
27a68fe3 | 2744 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
6eda4e2c HM |
2745 | if (brcmf_p2p_scan_finding_common_channel(cfg, NULL)) |
2746 | goto exit; | |
27a68fe3 | 2747 | if (cfg->scan_request) { |
27a68fe3 | 2748 | brcmf_inform_bss(cfg); |
97ed15c7 | 2749 | aborted = status != BRCMF_E_STATUS_SUCCESS; |
ef8596e1 | 2750 | brcmf_notify_escan_complete(cfg, ifp, aborted, false); |
e756af5b | 2751 | } else |
6eda4e2c HM |
2752 | brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n", |
2753 | status); | |
e756af5b HM |
2754 | } |
2755 | exit: | |
12f32370 | 2756 | return 0; |
e756af5b HM |
2757 | } |
2758 | ||
27a68fe3 | 2759 | static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg) |
e756af5b | 2760 | { |
5c36b99a AS |
2761 | brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT, |
2762 | brcmf_cfg80211_escan_handler); | |
f0799895 HM |
2763 | cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE; |
2764 | /* Init scan_timeout timer */ | |
2765 | init_timer(&cfg->escan_timeout); | |
2766 | cfg->escan_timeout.data = (unsigned long) cfg; | |
2767 | cfg->escan_timeout.function = brcmf_escan_timeout; | |
2768 | INIT_WORK(&cfg->escan_timeout_work, | |
2769 | brcmf_cfg80211_escan_timeout_worker); | |
e756af5b HM |
2770 | } |
2771 | ||
5addc0de | 2772 | static __always_inline void brcmf_delay(u32 ms) |
5b435de0 AS |
2773 | { |
2774 | if (ms < 1000 / HZ) { | |
2775 | cond_resched(); | |
2776 | mdelay(ms); | |
2777 | } else { | |
2778 | msleep(ms); | |
2779 | } | |
2780 | } | |
2781 | ||
2782 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) | |
2783 | { | |
4eb3af7c HM |
2784 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
2785 | struct net_device *ndev = cfg_to_ndev(cfg); | |
2786 | struct brcmf_if *ifp = netdev_priv(ndev); | |
2787 | ||
d96b801f | 2788 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 2789 | |
4eb3af7c HM |
2790 | if (cfg->wowl_enabled) { |
2791 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, | |
2792 | cfg->pre_wowl_pmmode); | |
2793 | brcmf_fil_iovar_data_set(ifp, "wowl_pattern", "clr", 4); | |
2794 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); | |
2795 | cfg->wowl_enabled = false; | |
2796 | } | |
5b435de0 AS |
2797 | return 0; |
2798 | } | |
2799 | ||
4eb3af7c HM |
2800 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
2801 | struct brcmf_if *ifp, | |
2802 | struct cfg80211_wowlan *wowl) | |
2803 | { | |
2804 | u32 wowl_config; | |
2805 | ||
2806 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); | |
2807 | ||
2808 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode); | |
2809 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); | |
2810 | ||
2811 | wowl_config = 0; | |
2812 | if (wowl->disconnect) | |
2813 | wowl_config |= WL_WOWL_DIS | WL_WOWL_BCN | WL_WOWL_RETR; | |
2814 | /* Note: if "wowl" target and not "wowlpf" then wowl_bcn_loss | |
2815 | * should be configured. This paramater is not supported by | |
2816 | * wowlpf. | |
2817 | */ | |
2818 | if (wowl->magic_pkt) | |
2819 | wowl_config |= WL_WOWL_MAGIC; | |
2820 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); | |
2821 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); | |
2822 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); | |
2823 | cfg->wowl_enabled = true; | |
2824 | } | |
2825 | ||
5b435de0 | 2826 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
4eb3af7c | 2827 | struct cfg80211_wowlan *wowl) |
5b435de0 | 2828 | { |
27a68fe3 AS |
2829 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
2830 | struct net_device *ndev = cfg_to_ndev(cfg); | |
4eb3af7c | 2831 | struct brcmf_if *ifp = netdev_priv(ndev); |
7d641072 | 2832 | struct brcmf_cfg80211_vif *vif; |
5b435de0 | 2833 | |
d96b801f | 2834 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 2835 | |
4eb3af7c | 2836 | /* if the primary net_device is not READY there is nothing |
7d641072 | 2837 | * we can do but pray resume goes smoothly. |
5b435de0 | 2838 | */ |
4eb3af7c | 2839 | if (!check_vif_up(ifp->vif)) |
7d641072 | 2840 | goto exit; |
5b435de0 | 2841 | |
7d641072 AS |
2842 | /* end any scanning */ |
2843 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) | |
27a68fe3 | 2844 | brcmf_abort_scanning(cfg); |
5b435de0 | 2845 | |
4eb3af7c HM |
2846 | if (wowl == NULL) { |
2847 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); | |
2848 | list_for_each_entry(vif, &cfg->vif_list, list) { | |
2849 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) | |
2850 | continue; | |
2851 | /* While going to suspend if associated with AP | |
2852 | * disassociate from AP to save power while system is | |
2853 | * in suspended state | |
2854 | */ | |
2855 | brcmf_link_down(vif); | |
2856 | /* Make sure WPA_Supplicant receives all the event | |
2857 | * generated due to DISASSOC call to the fw to keep | |
2858 | * the state fw and WPA_Supplicant state consistent | |
2859 | */ | |
2860 | brcmf_delay(500); | |
2861 | } | |
2862 | /* Configure MPC */ | |
2863 | brcmf_set_mpc(ifp, 1); | |
2864 | ||
2865 | } else { | |
2866 | /* Configure WOWL paramaters */ | |
2867 | brcmf_configure_wowl(cfg, ifp, wowl); | |
2868 | } | |
5b435de0 | 2869 | |
7d641072 | 2870 | exit: |
d96b801f | 2871 | brcmf_dbg(TRACE, "Exit\n"); |
7d641072 AS |
2872 | /* clear any scanning activity */ |
2873 | cfg->scan_status = 0; | |
5b435de0 AS |
2874 | return 0; |
2875 | } | |
2876 | ||
5b435de0 AS |
2877 | static __used s32 |
2878 | brcmf_update_pmklist(struct net_device *ndev, | |
2879 | struct brcmf_cfg80211_pmk_list *pmk_list, s32 err) | |
2880 | { | |
2881 | int i, j; | |
40c8e95a | 2882 | int pmkid_len; |
5b435de0 | 2883 | |
40c8e95a AS |
2884 | pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid); |
2885 | ||
16886735 | 2886 | brcmf_dbg(CONN, "No of elements %d\n", pmkid_len); |
40c8e95a | 2887 | for (i = 0; i < pmkid_len; i++) { |
16886735 AS |
2888 | brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i, |
2889 | &pmk_list->pmkids.pmkid[i].BSSID); | |
5b435de0 | 2890 | for (j = 0; j < WLAN_PMKID_LEN; j++) |
16886735 AS |
2891 | brcmf_dbg(CONN, "%02x\n", |
2892 | pmk_list->pmkids.pmkid[i].PMKID[j]); | |
5b435de0 AS |
2893 | } |
2894 | ||
2895 | if (!err) | |
ac24be6f AS |
2896 | brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info", |
2897 | (char *)pmk_list, sizeof(*pmk_list)); | |
5b435de0 AS |
2898 | |
2899 | return err; | |
2900 | } | |
2901 | ||
2902 | static s32 | |
2903 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, | |
2904 | struct cfg80211_pmksa *pmksa) | |
2905 | { | |
27a68fe3 | 2906 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 2907 | struct brcmf_if *ifp = netdev_priv(ndev); |
27a68fe3 | 2908 | struct pmkid_list *pmkids = &cfg->pmk_list->pmkids; |
5b435de0 AS |
2909 | s32 err = 0; |
2910 | int i; | |
40c8e95a | 2911 | int pmkid_len; |
5b435de0 | 2912 | |
d96b801f | 2913 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 2914 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2915 | return -EIO; |
2916 | ||
40c8e95a AS |
2917 | pmkid_len = le32_to_cpu(pmkids->npmkid); |
2918 | for (i = 0; i < pmkid_len; i++) | |
5b435de0 AS |
2919 | if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN)) |
2920 | break; | |
2921 | if (i < WL_NUM_PMKIDS_MAX) { | |
2922 | memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN); | |
2923 | memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); | |
40c8e95a AS |
2924 | if (i == pmkid_len) { |
2925 | pmkid_len++; | |
2926 | pmkids->npmkid = cpu_to_le32(pmkid_len); | |
2927 | } | |
5b435de0 AS |
2928 | } else |
2929 | err = -EINVAL; | |
2930 | ||
16886735 AS |
2931 | brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n", |
2932 | pmkids->pmkid[pmkid_len].BSSID); | |
5b435de0 | 2933 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
16886735 | 2934 | brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]); |
5b435de0 | 2935 | |
27a68fe3 | 2936 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
5b435de0 | 2937 | |
d96b801f | 2938 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2939 | return err; |
2940 | } | |
2941 | ||
2942 | static s32 | |
2943 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, | |
2944 | struct cfg80211_pmksa *pmksa) | |
2945 | { | |
27a68fe3 | 2946 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 2947 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
2948 | struct pmkid_list pmkid; |
2949 | s32 err = 0; | |
40c8e95a | 2950 | int i, pmkid_len; |
5b435de0 | 2951 | |
d96b801f | 2952 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 2953 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2954 | return -EIO; |
2955 | ||
2956 | memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN); | |
2957 | memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); | |
2958 | ||
16886735 AS |
2959 | brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n", |
2960 | &pmkid.pmkid[0].BSSID); | |
5b435de0 | 2961 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
16886735 | 2962 | brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]); |
5b435de0 | 2963 | |
27a68fe3 | 2964 | pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid); |
40c8e95a | 2965 | for (i = 0; i < pmkid_len; i++) |
5b435de0 | 2966 | if (!memcmp |
27a68fe3 | 2967 | (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID, |
5b435de0 AS |
2968 | ETH_ALEN)) |
2969 | break; | |
2970 | ||
40c8e95a AS |
2971 | if ((pmkid_len > 0) |
2972 | && (i < pmkid_len)) { | |
27a68fe3 | 2973 | memset(&cfg->pmk_list->pmkids.pmkid[i], 0, |
5b435de0 | 2974 | sizeof(struct pmkid)); |
40c8e95a | 2975 | for (; i < (pmkid_len - 1); i++) { |
27a68fe3 AS |
2976 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID, |
2977 | &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID, | |
5b435de0 | 2978 | ETH_ALEN); |
27a68fe3 AS |
2979 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID, |
2980 | &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID, | |
5b435de0 AS |
2981 | WLAN_PMKID_LEN); |
2982 | } | |
27a68fe3 | 2983 | cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1); |
5b435de0 AS |
2984 | } else |
2985 | err = -EINVAL; | |
2986 | ||
27a68fe3 | 2987 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
5b435de0 | 2988 | |
d96b801f | 2989 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2990 | return err; |
2991 | ||
2992 | } | |
2993 | ||
2994 | static s32 | |
2995 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) | |
2996 | { | |
27a68fe3 | 2997 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 2998 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
2999 | s32 err = 0; |
3000 | ||
d96b801f | 3001 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 3002 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
3003 | return -EIO; |
3004 | ||
27a68fe3 AS |
3005 | memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list)); |
3006 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); | |
5b435de0 | 3007 | |
d96b801f | 3008 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
3009 | return err; |
3010 | ||
3011 | } | |
3012 | ||
e5806072 AS |
3013 | /* |
3014 | * PFN result doesn't have all the info which are | |
3015 | * required by the supplicant | |
3016 | * (For e.g IEs) Do a target Escan so that sched scan results are reported | |
3017 | * via wl_inform_single_bss in the required format. Escan does require the | |
3018 | * scan request in the form of cfg80211_scan_request. For timebeing, create | |
3019 | * cfg80211_scan_request one out of the received PNO event. | |
3020 | */ | |
3021 | static s32 | |
1993732e | 3022 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
e5806072 AS |
3023 | const struct brcmf_event_msg *e, void *data) |
3024 | { | |
1993732e | 3025 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
e5806072 AS |
3026 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
3027 | struct cfg80211_scan_request *request = NULL; | |
3028 | struct cfg80211_ssid *ssid = NULL; | |
3029 | struct ieee80211_channel *channel = NULL; | |
27a68fe3 | 3030 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
e5806072 AS |
3031 | int err = 0; |
3032 | int channel_req = 0; | |
3033 | int band = 0; | |
3034 | struct brcmf_pno_scanresults_le *pfn_result; | |
3035 | u32 result_count; | |
3036 | u32 status; | |
3037 | ||
4e8a008e | 3038 | brcmf_dbg(SCAN, "Enter\n"); |
e5806072 | 3039 | |
5c36b99a | 3040 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
4e8a008e | 3041 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
e5806072 AS |
3042 | return 0; |
3043 | } | |
3044 | ||
3045 | pfn_result = (struct brcmf_pno_scanresults_le *)data; | |
3046 | result_count = le32_to_cpu(pfn_result->count); | |
3047 | status = le32_to_cpu(pfn_result->status); | |
3048 | ||
3049 | /* | |
3050 | * PFN event is limited to fit 512 bytes so we may get | |
3051 | * multiple NET_FOUND events. For now place a warning here. | |
3052 | */ | |
3053 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); | |
4e8a008e | 3054 | brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count); |
e5806072 AS |
3055 | if (result_count > 0) { |
3056 | int i; | |
3057 | ||
3058 | request = kzalloc(sizeof(*request), GFP_KERNEL); | |
58901d18 DC |
3059 | ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL); |
3060 | channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL); | |
e5806072 AS |
3061 | if (!request || !ssid || !channel) { |
3062 | err = -ENOMEM; | |
3063 | goto out_err; | |
3064 | } | |
3065 | ||
3066 | request->wiphy = wiphy; | |
3067 | data += sizeof(struct brcmf_pno_scanresults_le); | |
3068 | netinfo_start = (struct brcmf_pno_net_info_le *)data; | |
3069 | ||
3070 | for (i = 0; i < result_count; i++) { | |
3071 | netinfo = &netinfo_start[i]; | |
3072 | if (!netinfo) { | |
57d6e91a AS |
3073 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
3074 | i); | |
e5806072 AS |
3075 | err = -EINVAL; |
3076 | goto out_err; | |
3077 | } | |
3078 | ||
4e8a008e AS |
3079 | brcmf_dbg(SCAN, "SSID:%s Channel:%d\n", |
3080 | netinfo->SSID, netinfo->channel); | |
e5806072 AS |
3081 | memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len); |
3082 | ssid[i].ssid_len = netinfo->SSID_len; | |
3083 | request->n_ssids++; | |
3084 | ||
3085 | channel_req = netinfo->channel; | |
3086 | if (channel_req <= CH_MAX_2G_CHANNEL) | |
3087 | band = NL80211_BAND_2GHZ; | |
3088 | else | |
3089 | band = NL80211_BAND_5GHZ; | |
3090 | channel[i].center_freq = | |
3091 | ieee80211_channel_to_frequency(channel_req, | |
3092 | band); | |
3093 | channel[i].band = band; | |
3094 | channel[i].flags |= IEEE80211_CHAN_NO_HT40; | |
3095 | request->channels[i] = &channel[i]; | |
3096 | request->n_channels++; | |
3097 | } | |
3098 | ||
3099 | /* assign parsed ssid array */ | |
3100 | if (request->n_ssids) | |
3101 | request->ssids = &ssid[0]; | |
3102 | ||
c1179033 | 3103 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
e5806072 | 3104 | /* Abort any on-going scan */ |
27a68fe3 | 3105 | brcmf_abort_scanning(cfg); |
e5806072 AS |
3106 | } |
3107 | ||
c1179033 | 3108 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
2668b0b1 | 3109 | cfg->escan_info.run = brcmf_run_escan; |
a0f472ac | 3110 | err = brcmf_do_escan(cfg, wiphy, ifp, request); |
e5806072 | 3111 | if (err) { |
c1179033 | 3112 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
e5806072 AS |
3113 | goto out_err; |
3114 | } | |
27a68fe3 AS |
3115 | cfg->sched_escan = true; |
3116 | cfg->scan_request = request; | |
e5806072 | 3117 | } else { |
57d6e91a | 3118 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
e5806072 AS |
3119 | goto out_err; |
3120 | } | |
3121 | ||
3122 | kfree(ssid); | |
3123 | kfree(channel); | |
3124 | kfree(request); | |
3125 | return 0; | |
3126 | ||
3127 | out_err: | |
3128 | kfree(ssid); | |
3129 | kfree(channel); | |
3130 | kfree(request); | |
3131 | cfg80211_sched_scan_stopped(wiphy); | |
3132 | return err; | |
3133 | } | |
3134 | ||
e5806072 AS |
3135 | static int brcmf_dev_pno_clean(struct net_device *ndev) |
3136 | { | |
e5806072 AS |
3137 | int ret; |
3138 | ||
3139 | /* Disable pfn */ | |
ac24be6f | 3140 | ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0); |
e5806072 AS |
3141 | if (ret == 0) { |
3142 | /* clear pfn */ | |
ac24be6f AS |
3143 | ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear", |
3144 | NULL, 0); | |
e5806072 AS |
3145 | } |
3146 | if (ret < 0) | |
57d6e91a | 3147 | brcmf_err("failed code %d\n", ret); |
e5806072 AS |
3148 | |
3149 | return ret; | |
3150 | } | |
3151 | ||
3152 | static int brcmf_dev_pno_config(struct net_device *ndev) | |
3153 | { | |
3154 | struct brcmf_pno_param_le pfn_param; | |
e5806072 AS |
3155 | |
3156 | memset(&pfn_param, 0, sizeof(pfn_param)); | |
3157 | pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION); | |
3158 | ||
3159 | /* set extra pno params */ | |
3160 | pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT); | |
3161 | pfn_param.repeat = BRCMF_PNO_REPEAT; | |
3162 | pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX; | |
3163 | ||
3164 | /* set up pno scan fr */ | |
3165 | pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME); | |
3166 | ||
ac24be6f AS |
3167 | return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set", |
3168 | &pfn_param, sizeof(pfn_param)); | |
e5806072 AS |
3169 | } |
3170 | ||
3171 | static int | |
3172 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, | |
3173 | struct net_device *ndev, | |
3174 | struct cfg80211_sched_scan_request *request) | |
3175 | { | |
c1179033 | 3176 | struct brcmf_if *ifp = netdev_priv(ndev); |
27a68fe3 | 3177 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
e5806072 AS |
3178 | struct brcmf_pno_net_param_le pfn; |
3179 | int i; | |
3180 | int ret = 0; | |
3181 | ||
dc7bdbf1 | 3182 | brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n", |
4e8a008e | 3183 | request->n_match_sets, request->n_ssids); |
c1179033 | 3184 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
57d6e91a | 3185 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
e5806072 AS |
3186 | return -EAGAIN; |
3187 | } | |
1687eee2 AS |
3188 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
3189 | brcmf_err("Scanning suppressed: status (%lu)\n", | |
3190 | cfg->scan_status); | |
3191 | return -EAGAIN; | |
3192 | } | |
e5806072 | 3193 | |
dc7bdbf1 | 3194 | if (!request->n_ssids || !request->n_match_sets) { |
181f2d17 | 3195 | brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n", |
dc7bdbf1 | 3196 | request->n_ssids); |
e5806072 AS |
3197 | return -EINVAL; |
3198 | } | |
3199 | ||
3200 | if (request->n_ssids > 0) { | |
3201 | for (i = 0; i < request->n_ssids; i++) { | |
3202 | /* Active scan req for ssids */ | |
4e8a008e AS |
3203 | brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n", |
3204 | request->ssids[i].ssid); | |
e5806072 AS |
3205 | |
3206 | /* | |
3207 | * match_set ssids is a supert set of n_ssid list, | |
3208 | * so we need not add these set seperately. | |
3209 | */ | |
3210 | } | |
3211 | } | |
3212 | ||
3213 | if (request->n_match_sets > 0) { | |
3214 | /* clean up everything */ | |
3215 | ret = brcmf_dev_pno_clean(ndev); | |
3216 | if (ret < 0) { | |
57d6e91a | 3217 | brcmf_err("failed error=%d\n", ret); |
e5806072 AS |
3218 | return ret; |
3219 | } | |
3220 | ||
3221 | /* configure pno */ | |
3222 | ret = brcmf_dev_pno_config(ndev); | |
3223 | if (ret < 0) { | |
57d6e91a | 3224 | brcmf_err("PNO setup failed!! ret=%d\n", ret); |
e5806072 AS |
3225 | return -EINVAL; |
3226 | } | |
3227 | ||
3228 | /* configure each match set */ | |
3229 | for (i = 0; i < request->n_match_sets; i++) { | |
3230 | struct cfg80211_ssid *ssid; | |
3231 | u32 ssid_len; | |
3232 | ||
3233 | ssid = &request->match_sets[i].ssid; | |
3234 | ssid_len = ssid->ssid_len; | |
3235 | ||
3236 | if (!ssid_len) { | |
57d6e91a | 3237 | brcmf_err("skip broadcast ssid\n"); |
e5806072 AS |
3238 | continue; |
3239 | } | |
3240 | pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN); | |
3241 | pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY); | |
3242 | pfn.wsec = cpu_to_le32(0); | |
3243 | pfn.infra = cpu_to_le32(1); | |
3244 | pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT); | |
3245 | pfn.ssid.SSID_len = cpu_to_le32(ssid_len); | |
3246 | memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len); | |
c1179033 | 3247 | ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn, |
ac24be6f | 3248 | sizeof(pfn)); |
4e8a008e AS |
3249 | brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n", |
3250 | ret == 0 ? "set" : "failed", ssid->ssid); | |
e5806072 AS |
3251 | } |
3252 | /* Enable the PNO */ | |
c1179033 | 3253 | if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) { |
57d6e91a | 3254 | brcmf_err("PNO enable failed!! ret=%d\n", ret); |
e5806072 AS |
3255 | return -EINVAL; |
3256 | } | |
3257 | } else { | |
3258 | return -EINVAL; | |
3259 | } | |
3260 | ||
3261 | return 0; | |
3262 | } | |
3263 | ||
3264 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, | |
3265 | struct net_device *ndev) | |
3266 | { | |
27a68fe3 | 3267 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
e5806072 | 3268 | |
4e8a008e | 3269 | brcmf_dbg(SCAN, "enter\n"); |
e5806072 | 3270 | brcmf_dev_pno_clean(ndev); |
27a68fe3 | 3271 | if (cfg->sched_escan) |
a0f472ac | 3272 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true); |
e5806072 AS |
3273 | return 0; |
3274 | } | |
e5806072 | 3275 | |
1f170110 | 3276 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
1a873342 HM |
3277 | { |
3278 | s32 err; | |
3279 | ||
3280 | /* set auth */ | |
ac24be6f | 3281 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
1a873342 | 3282 | if (err < 0) { |
57d6e91a | 3283 | brcmf_err("auth error %d\n", err); |
1a873342 HM |
3284 | return err; |
3285 | } | |
3286 | /* set wsec */ | |
ac24be6f | 3287 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0); |
1a873342 | 3288 | if (err < 0) { |
57d6e91a | 3289 | brcmf_err("wsec error %d\n", err); |
1a873342 HM |
3290 | return err; |
3291 | } | |
3292 | /* set upper-layer auth */ | |
ac24be6f | 3293 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
1a873342 | 3294 | if (err < 0) { |
57d6e91a | 3295 | brcmf_err("wpa_auth error %d\n", err); |
1a873342 HM |
3296 | return err; |
3297 | } | |
3298 | ||
3299 | return 0; | |
3300 | } | |
3301 | ||
3302 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) | |
3303 | { | |
3304 | if (is_rsn_ie) | |
3305 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); | |
3306 | ||
3307 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); | |
3308 | } | |
3309 | ||
3310 | static s32 | |
4b5800fe JB |
3311 | brcmf_configure_wpaie(struct net_device *ndev, |
3312 | const struct brcmf_vs_tlv *wpa_ie, | |
3313 | bool is_rsn_ie) | |
1a873342 | 3314 | { |
ac24be6f | 3315 | struct brcmf_if *ifp = netdev_priv(ndev); |
1a873342 HM |
3316 | u32 auth = 0; /* d11 open authentication */ |
3317 | u16 count; | |
3318 | s32 err = 0; | |
3319 | s32 len = 0; | |
3320 | u32 i; | |
3321 | u32 wsec; | |
3322 | u32 pval = 0; | |
3323 | u32 gval = 0; | |
3324 | u32 wpa_auth = 0; | |
3325 | u32 offset; | |
3326 | u8 *data; | |
3327 | u16 rsn_cap; | |
3328 | u32 wme_bss_disable; | |
3329 | ||
d96b801f | 3330 | brcmf_dbg(TRACE, "Enter\n"); |
1a873342 HM |
3331 | if (wpa_ie == NULL) |
3332 | goto exit; | |
3333 | ||
3334 | len = wpa_ie->len + TLV_HDR_LEN; | |
3335 | data = (u8 *)wpa_ie; | |
619c5a9a | 3336 | offset = TLV_HDR_LEN; |
1a873342 HM |
3337 | if (!is_rsn_ie) |
3338 | offset += VS_IE_FIXED_HDR_LEN; | |
619c5a9a HM |
3339 | else |
3340 | offset += WPA_IE_VERSION_LEN; | |
1a873342 HM |
3341 | |
3342 | /* check for multicast cipher suite */ | |
3343 | if (offset + WPA_IE_MIN_OUI_LEN > len) { | |
3344 | err = -EINVAL; | |
57d6e91a | 3345 | brcmf_err("no multicast cipher suite\n"); |
1a873342 HM |
3346 | goto exit; |
3347 | } | |
3348 | ||
3349 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { | |
3350 | err = -EINVAL; | |
57d6e91a | 3351 | brcmf_err("ivalid OUI\n"); |
1a873342 HM |
3352 | goto exit; |
3353 | } | |
3354 | offset += TLV_OUI_LEN; | |
3355 | ||
3356 | /* pick up multicast cipher */ | |
3357 | switch (data[offset]) { | |
3358 | case WPA_CIPHER_NONE: | |
3359 | gval = 0; | |
3360 | break; | |
3361 | case WPA_CIPHER_WEP_40: | |
3362 | case WPA_CIPHER_WEP_104: | |
3363 | gval = WEP_ENABLED; | |
3364 | break; | |
3365 | case WPA_CIPHER_TKIP: | |
3366 | gval = TKIP_ENABLED; | |
3367 | break; | |
3368 | case WPA_CIPHER_AES_CCM: | |
3369 | gval = AES_ENABLED; | |
3370 | break; | |
3371 | default: | |
3372 | err = -EINVAL; | |
57d6e91a | 3373 | brcmf_err("Invalid multi cast cipher info\n"); |
1a873342 HM |
3374 | goto exit; |
3375 | } | |
3376 | ||
3377 | offset++; | |
3378 | /* walk thru unicast cipher list and pick up what we recognize */ | |
3379 | count = data[offset] + (data[offset + 1] << 8); | |
3380 | offset += WPA_IE_SUITE_COUNT_LEN; | |
3381 | /* Check for unicast suite(s) */ | |
3382 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { | |
3383 | err = -EINVAL; | |
57d6e91a | 3384 | brcmf_err("no unicast cipher suite\n"); |
1a873342 HM |
3385 | goto exit; |
3386 | } | |
3387 | for (i = 0; i < count; i++) { | |
3388 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { | |
3389 | err = -EINVAL; | |
57d6e91a | 3390 | brcmf_err("ivalid OUI\n"); |
1a873342 HM |
3391 | goto exit; |
3392 | } | |
3393 | offset += TLV_OUI_LEN; | |
3394 | switch (data[offset]) { | |
3395 | case WPA_CIPHER_NONE: | |
3396 | break; | |
3397 | case WPA_CIPHER_WEP_40: | |
3398 | case WPA_CIPHER_WEP_104: | |
3399 | pval |= WEP_ENABLED; | |
3400 | break; | |
3401 | case WPA_CIPHER_TKIP: | |
3402 | pval |= TKIP_ENABLED; | |
3403 | break; | |
3404 | case WPA_CIPHER_AES_CCM: | |
3405 | pval |= AES_ENABLED; | |
3406 | break; | |
3407 | default: | |
57d6e91a | 3408 | brcmf_err("Ivalid unicast security info\n"); |
1a873342 HM |
3409 | } |
3410 | offset++; | |
3411 | } | |
3412 | /* walk thru auth management suite list and pick up what we recognize */ | |
3413 | count = data[offset] + (data[offset + 1] << 8); | |
3414 | offset += WPA_IE_SUITE_COUNT_LEN; | |
3415 | /* Check for auth key management suite(s) */ | |
3416 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { | |
3417 | err = -EINVAL; | |
57d6e91a | 3418 | brcmf_err("no auth key mgmt suite\n"); |
1a873342 HM |
3419 | goto exit; |
3420 | } | |
3421 | for (i = 0; i < count; i++) { | |
3422 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { | |
3423 | err = -EINVAL; | |
57d6e91a | 3424 | brcmf_err("ivalid OUI\n"); |
1a873342 HM |
3425 | goto exit; |
3426 | } | |
3427 | offset += TLV_OUI_LEN; | |
3428 | switch (data[offset]) { | |
3429 | case RSN_AKM_NONE: | |
d96b801f | 3430 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
1a873342 HM |
3431 | wpa_auth |= WPA_AUTH_NONE; |
3432 | break; | |
3433 | case RSN_AKM_UNSPECIFIED: | |
d96b801f | 3434 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
1a873342 HM |
3435 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
3436 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); | |
3437 | break; | |
3438 | case RSN_AKM_PSK: | |
d96b801f | 3439 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
1a873342 HM |
3440 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
3441 | (wpa_auth |= WPA_AUTH_PSK); | |
3442 | break; | |
3443 | default: | |
57d6e91a | 3444 | brcmf_err("Ivalid key mgmt info\n"); |
1a873342 HM |
3445 | } |
3446 | offset++; | |
3447 | } | |
3448 | ||
3449 | if (is_rsn_ie) { | |
3450 | wme_bss_disable = 1; | |
3451 | if ((offset + RSN_CAP_LEN) <= len) { | |
3452 | rsn_cap = data[offset] + (data[offset + 1] << 8); | |
3453 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) | |
3454 | wme_bss_disable = 0; | |
3455 | } | |
3456 | /* set wme_bss_disable to sync RSN Capabilities */ | |
ac24be6f | 3457 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
81f5dcb8 | 3458 | wme_bss_disable); |
1a873342 | 3459 | if (err < 0) { |
57d6e91a | 3460 | brcmf_err("wme_bss_disable error %d\n", err); |
1a873342 HM |
3461 | goto exit; |
3462 | } | |
3463 | } | |
3464 | /* FOR WPS , set SES_OW_ENABLED */ | |
3465 | wsec = (pval | gval | SES_OW_ENABLED); | |
3466 | ||
3467 | /* set auth */ | |
ac24be6f | 3468 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
1a873342 | 3469 | if (err < 0) { |
57d6e91a | 3470 | brcmf_err("auth error %d\n", err); |
1a873342 HM |
3471 | goto exit; |
3472 | } | |
3473 | /* set wsec */ | |
ac24be6f | 3474 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
1a873342 | 3475 | if (err < 0) { |
57d6e91a | 3476 | brcmf_err("wsec error %d\n", err); |
1a873342 HM |
3477 | goto exit; |
3478 | } | |
3479 | /* set upper-layer auth */ | |
ac24be6f | 3480 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
1a873342 | 3481 | if (err < 0) { |
57d6e91a | 3482 | brcmf_err("wpa_auth error %d\n", err); |
1a873342 HM |
3483 | goto exit; |
3484 | } | |
3485 | ||
3486 | exit: | |
3487 | return err; | |
3488 | } | |
3489 | ||
3490 | static s32 | |
3082b9be | 3491 | brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len, |
1a873342 HM |
3492 | struct parsed_vndr_ies *vndr_ies) |
3493 | { | |
1a873342 HM |
3494 | struct brcmf_vs_tlv *vndrie; |
3495 | struct brcmf_tlv *ie; | |
3496 | struct parsed_vndr_ie_info *parsed_info; | |
3497 | s32 remaining_len; | |
3498 | ||
3499 | remaining_len = (s32)vndr_ie_len; | |
3500 | memset(vndr_ies, 0, sizeof(*vndr_ies)); | |
3501 | ||
3502 | ie = (struct brcmf_tlv *)vndr_ie_buf; | |
3503 | while (ie) { | |
3504 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) | |
3505 | goto next; | |
3506 | vndrie = (struct brcmf_vs_tlv *)ie; | |
3507 | /* len should be bigger than OUI length + one */ | |
3508 | if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) { | |
57d6e91a AS |
3509 | brcmf_err("invalid vndr ie. length is too small %d\n", |
3510 | vndrie->len); | |
1a873342 HM |
3511 | goto next; |
3512 | } | |
3513 | /* if wpa or wme ie, do not add ie */ | |
3514 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && | |
3515 | ((vndrie->oui_type == WPA_OUI_TYPE) || | |
3516 | (vndrie->oui_type == WME_OUI_TYPE))) { | |
d96b801f | 3517 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
1a873342 HM |
3518 | goto next; |
3519 | } | |
3520 | ||
3521 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; | |
3522 | ||
3523 | /* save vndr ie information */ | |
3524 | parsed_info->ie_ptr = (char *)vndrie; | |
3525 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; | |
3526 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); | |
3527 | ||
3528 | vndr_ies->count++; | |
3529 | ||
d96b801f AS |
3530 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
3531 | parsed_info->vndrie.oui[0], | |
3532 | parsed_info->vndrie.oui[1], | |
3533 | parsed_info->vndrie.oui[2], | |
3534 | parsed_info->vndrie.oui_type); | |
1a873342 | 3535 | |
9f440b7b | 3536 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
1a873342 HM |
3537 | break; |
3538 | next: | |
b41fc3d7 HM |
3539 | remaining_len -= (ie->len + TLV_HDR_LEN); |
3540 | if (remaining_len <= TLV_HDR_LEN) | |
1a873342 HM |
3541 | ie = NULL; |
3542 | else | |
b41fc3d7 HM |
3543 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
3544 | TLV_HDR_LEN); | |
1a873342 | 3545 | } |
12f32370 | 3546 | return 0; |
1a873342 HM |
3547 | } |
3548 | ||
3549 | static u32 | |
3550 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) | |
3551 | { | |
3552 | ||
3553 | __le32 iecount_le; | |
3554 | __le32 pktflag_le; | |
3555 | ||
3556 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); | |
3557 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; | |
3558 | ||
3559 | iecount_le = cpu_to_le32(1); | |
3560 | memcpy(&iebuf[VNDR_IE_COUNT_OFFSET], &iecount_le, sizeof(iecount_le)); | |
3561 | ||
3562 | pktflag_le = cpu_to_le32(pktflag); | |
3563 | memcpy(&iebuf[VNDR_IE_PKTFLAG_OFFSET], &pktflag_le, sizeof(pktflag_le)); | |
3564 | ||
3565 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); | |
3566 | ||
3567 | return ie_len + VNDR_IE_HDR_SIZE; | |
3568 | } | |
3569 | ||
1332e26e AS |
3570 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
3571 | const u8 *vndr_ie_buf, u32 vndr_ie_len) | |
1a873342 | 3572 | { |
1332e26e AS |
3573 | struct brcmf_if *ifp; |
3574 | struct vif_saved_ie *saved_ie; | |
1a873342 HM |
3575 | s32 err = 0; |
3576 | u8 *iovar_ie_buf; | |
3577 | u8 *curr_ie_buf; | |
3578 | u8 *mgmt_ie_buf = NULL; | |
3e4f319d | 3579 | int mgmt_ie_buf_len; |
81118d16 | 3580 | u32 *mgmt_ie_len; |
1a873342 HM |
3581 | u32 del_add_ie_buf_len = 0; |
3582 | u32 total_ie_buf_len = 0; | |
3583 | u32 parsed_ie_buf_len = 0; | |
3584 | struct parsed_vndr_ies old_vndr_ies; | |
3585 | struct parsed_vndr_ies new_vndr_ies; | |
3586 | struct parsed_vndr_ie_info *vndrie_info; | |
3587 | s32 i; | |
3588 | u8 *ptr; | |
3e4f319d | 3589 | int remained_buf_len; |
1a873342 | 3590 | |
1332e26e AS |
3591 | if (!vif) |
3592 | return -ENODEV; | |
3593 | ifp = vif->ifp; | |
3594 | saved_ie = &vif->saved_ie; | |
3595 | ||
d96b801f | 3596 | brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag); |
1a873342 HM |
3597 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
3598 | if (!iovar_ie_buf) | |
3599 | return -ENOMEM; | |
3600 | curr_ie_buf = iovar_ie_buf; | |
89286dc9 HM |
3601 | switch (pktflag) { |
3602 | case BRCMF_VNDR_IE_PRBREQ_FLAG: | |
3603 | mgmt_ie_buf = saved_ie->probe_req_ie; | |
3604 | mgmt_ie_len = &saved_ie->probe_req_ie_len; | |
3605 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); | |
3606 | break; | |
3607 | case BRCMF_VNDR_IE_PRBRSP_FLAG: | |
3608 | mgmt_ie_buf = saved_ie->probe_res_ie; | |
3609 | mgmt_ie_len = &saved_ie->probe_res_ie_len; | |
3610 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); | |
3611 | break; | |
3612 | case BRCMF_VNDR_IE_BEACON_FLAG: | |
3613 | mgmt_ie_buf = saved_ie->beacon_ie; | |
3614 | mgmt_ie_len = &saved_ie->beacon_ie_len; | |
3615 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); | |
3616 | break; | |
3617 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: | |
3618 | mgmt_ie_buf = saved_ie->assoc_req_ie; | |
3619 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; | |
3620 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); | |
3621 | break; | |
3622 | default: | |
3623 | err = -EPERM; | |
3624 | brcmf_err("not suitable type\n"); | |
3625 | goto exit; | |
1a873342 HM |
3626 | } |
3627 | ||
3628 | if (vndr_ie_len > mgmt_ie_buf_len) { | |
3629 | err = -ENOMEM; | |
57d6e91a | 3630 | brcmf_err("extra IE size too big\n"); |
1a873342 HM |
3631 | goto exit; |
3632 | } | |
3633 | ||
3634 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ | |
3635 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { | |
3636 | ptr = curr_ie_buf; | |
3637 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); | |
3638 | for (i = 0; i < new_vndr_ies.count; i++) { | |
3639 | vndrie_info = &new_vndr_ies.ie_info[i]; | |
3640 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, | |
3641 | vndrie_info->ie_len); | |
3642 | parsed_ie_buf_len += vndrie_info->ie_len; | |
3643 | } | |
3644 | } | |
3645 | ||
b41fc3d7 | 3646 | if (mgmt_ie_buf && *mgmt_ie_len) { |
1a873342 HM |
3647 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
3648 | (memcmp(mgmt_ie_buf, curr_ie_buf, | |
3649 | parsed_ie_buf_len) == 0)) { | |
d96b801f | 3650 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
1a873342 HM |
3651 | goto exit; |
3652 | } | |
3653 | ||
3654 | /* parse old vndr_ie */ | |
3655 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); | |
3656 | ||
3657 | /* make a command to delete old ie */ | |
3658 | for (i = 0; i < old_vndr_ies.count; i++) { | |
3659 | vndrie_info = &old_vndr_ies.ie_info[i]; | |
3660 | ||
d96b801f AS |
3661 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
3662 | vndrie_info->vndrie.id, | |
3663 | vndrie_info->vndrie.len, | |
3664 | vndrie_info->vndrie.oui[0], | |
3665 | vndrie_info->vndrie.oui[1], | |
3666 | vndrie_info->vndrie.oui[2]); | |
1a873342 HM |
3667 | |
3668 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, | |
3669 | vndrie_info->ie_ptr, | |
3670 | vndrie_info->ie_len, | |
3671 | "del"); | |
3672 | curr_ie_buf += del_add_ie_buf_len; | |
3673 | total_ie_buf_len += del_add_ie_buf_len; | |
3674 | } | |
3675 | } | |
3676 | ||
3677 | *mgmt_ie_len = 0; | |
3678 | /* Add if there is any extra IE */ | |
3679 | if (mgmt_ie_buf && parsed_ie_buf_len) { | |
3680 | ptr = mgmt_ie_buf; | |
3681 | ||
3682 | remained_buf_len = mgmt_ie_buf_len; | |
3683 | ||
3684 | /* make a command to add new ie */ | |
3685 | for (i = 0; i < new_vndr_ies.count; i++) { | |
3686 | vndrie_info = &new_vndr_ies.ie_info[i]; | |
3687 | ||
b41fc3d7 HM |
3688 | /* verify remained buf size before copy data */ |
3689 | if (remained_buf_len < (vndrie_info->vndrie.len + | |
3690 | VNDR_IE_VSIE_OFFSET)) { | |
57d6e91a AS |
3691 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
3692 | remained_buf_len); | |
b41fc3d7 HM |
3693 | break; |
3694 | } | |
3695 | remained_buf_len -= (vndrie_info->ie_len + | |
3696 | VNDR_IE_VSIE_OFFSET); | |
3697 | ||
d96b801f AS |
3698 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
3699 | vndrie_info->vndrie.id, | |
3700 | vndrie_info->vndrie.len, | |
3701 | vndrie_info->vndrie.oui[0], | |
3702 | vndrie_info->vndrie.oui[1], | |
3703 | vndrie_info->vndrie.oui[2]); | |
1a873342 HM |
3704 | |
3705 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, | |
3706 | vndrie_info->ie_ptr, | |
3707 | vndrie_info->ie_len, | |
3708 | "add"); | |
1a873342 HM |
3709 | |
3710 | /* save the parsed IE in wl struct */ | |
3711 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, | |
3712 | vndrie_info->ie_len); | |
3713 | *mgmt_ie_len += vndrie_info->ie_len; | |
3714 | ||
3715 | curr_ie_buf += del_add_ie_buf_len; | |
3716 | total_ie_buf_len += del_add_ie_buf_len; | |
3717 | } | |
3718 | } | |
3719 | if (total_ie_buf_len) { | |
c1179033 | 3720 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
81f5dcb8 | 3721 | total_ie_buf_len); |
1a873342 | 3722 | if (err) |
57d6e91a | 3723 | brcmf_err("vndr ie set error : %d\n", err); |
1a873342 HM |
3724 | } |
3725 | ||
3726 | exit: | |
3727 | kfree(iovar_ie_buf); | |
3728 | return err; | |
3729 | } | |
3730 | ||
5f4f9f11 AS |
3731 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
3732 | { | |
3733 | s32 pktflags[] = { | |
3734 | BRCMF_VNDR_IE_PRBREQ_FLAG, | |
3735 | BRCMF_VNDR_IE_PRBRSP_FLAG, | |
3736 | BRCMF_VNDR_IE_BEACON_FLAG | |
3737 | }; | |
3738 | int i; | |
3739 | ||
3740 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) | |
3741 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); | |
3742 | ||
3743 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); | |
3744 | return 0; | |
3745 | } | |
3746 | ||
a0f07959 HM |
3747 | static s32 |
3748 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, | |
3749 | struct cfg80211_beacon_data *beacon) | |
3750 | { | |
3751 | s32 err; | |
3752 | ||
3753 | /* Set Beacon IEs to FW */ | |
3754 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, | |
3755 | beacon->tail, beacon->tail_len); | |
3756 | if (err) { | |
3757 | brcmf_err("Set Beacon IE Failed\n"); | |
3758 | return err; | |
3759 | } | |
3760 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); | |
3761 | ||
3762 | /* Set Probe Response IEs to FW */ | |
3763 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, | |
3764 | beacon->proberesp_ies, | |
3765 | beacon->proberesp_ies_len); | |
3766 | if (err) | |
3767 | brcmf_err("Set Probe Resp IE Failed\n"); | |
3768 | else | |
3769 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); | |
3770 | ||
3771 | return err; | |
3772 | } | |
3773 | ||
1a873342 HM |
3774 | static s32 |
3775 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, | |
3776 | struct cfg80211_ap_settings *settings) | |
3777 | { | |
3778 | s32 ie_offset; | |
1c9d30cf | 3779 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
ac24be6f | 3780 | struct brcmf_if *ifp = netdev_priv(ndev); |
4b5800fe | 3781 | const struct brcmf_tlv *ssid_ie; |
1a873342 | 3782 | struct brcmf_ssid_le ssid_le; |
1a873342 | 3783 | s32 err = -EPERM; |
4b5800fe JB |
3784 | const struct brcmf_tlv *rsn_ie; |
3785 | const struct brcmf_vs_tlv *wpa_ie; | |
1a873342 | 3786 | struct brcmf_join_params join_params; |
a0f07959 HM |
3787 | enum nl80211_iftype dev_role; |
3788 | struct brcmf_fil_bss_enable_le bss_enable; | |
06c01585 | 3789 | u16 chanspec; |
1a873342 | 3790 | |
06c01585 AS |
3791 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
3792 | settings->chandef.chan->hw_value, | |
3793 | settings->chandef.center_freq1, settings->chandef.width, | |
a9a56878 | 3794 | settings->beacon_interval, settings->dtim_period); |
d96b801f AS |
3795 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
3796 | settings->ssid, settings->ssid_len, settings->auth_type, | |
3797 | settings->inactivity_timeout); | |
1a873342 | 3798 | |
426d0a56 | 3799 | dev_role = ifp->vif->wdev.iftype; |
1a873342 HM |
3800 | |
3801 | memset(&ssid_le, 0, sizeof(ssid_le)); | |
3802 | if (settings->ssid == NULL || settings->ssid_len == 0) { | |
3803 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; | |
3804 | ssid_ie = brcmf_parse_tlvs( | |
3805 | (u8 *)&settings->beacon.head[ie_offset], | |
3806 | settings->beacon.head_len - ie_offset, | |
3807 | WLAN_EID_SSID); | |
3808 | if (!ssid_ie) | |
3809 | return -EINVAL; | |
3810 | ||
3811 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); | |
3812 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); | |
d96b801f | 3813 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
1a873342 HM |
3814 | } else { |
3815 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); | |
3816 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); | |
3817 | } | |
3818 | ||
f96aa07e | 3819 | brcmf_set_mpc(ifp, 0); |
b3657453 | 3820 | brcmf_configure_arp_offload(ifp, false); |
1a873342 HM |
3821 | |
3822 | /* find the RSN_IE */ | |
3823 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, | |
3824 | settings->beacon.tail_len, WLAN_EID_RSN); | |
3825 | ||
3826 | /* find the WPA_IE */ | |
3827 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, | |
3828 | settings->beacon.tail_len); | |
3829 | ||
1a873342 | 3830 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
d96b801f | 3831 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
1a873342 HM |
3832 | if (wpa_ie != NULL) { |
3833 | /* WPA IE */ | |
34778529 | 3834 | err = brcmf_configure_wpaie(ndev, wpa_ie, false); |
1a873342 HM |
3835 | if (err < 0) |
3836 | goto exit; | |
1a873342 HM |
3837 | } else { |
3838 | /* RSN IE */ | |
3839 | err = brcmf_configure_wpaie(ndev, | |
34778529 | 3840 | (struct brcmf_vs_tlv *)rsn_ie, true); |
1a873342 HM |
3841 | if (err < 0) |
3842 | goto exit; | |
1a873342 | 3843 | } |
1a873342 | 3844 | } else { |
d96b801f | 3845 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
1f170110 | 3846 | brcmf_configure_opensecurity(ifp); |
1a873342 | 3847 | } |
1a873342 | 3848 | |
a0f07959 | 3849 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
1a873342 | 3850 | |
600a897d | 3851 | chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef); |
06c01585 | 3852 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
1c9d30cf | 3853 | if (err < 0) { |
06c01585 | 3854 | brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec, err); |
1c9d30cf HM |
3855 | goto exit; |
3856 | } | |
3857 | ||
1a873342 | 3858 | if (settings->beacon_interval) { |
ac24be6f | 3859 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
81f5dcb8 | 3860 | settings->beacon_interval); |
1a873342 | 3861 | if (err < 0) { |
57d6e91a | 3862 | brcmf_err("Beacon Interval Set Error, %d\n", err); |
1a873342 HM |
3863 | goto exit; |
3864 | } | |
3865 | } | |
3866 | if (settings->dtim_period) { | |
ac24be6f | 3867 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
81f5dcb8 | 3868 | settings->dtim_period); |
1a873342 | 3869 | if (err < 0) { |
57d6e91a | 3870 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
1a873342 HM |
3871 | goto exit; |
3872 | } | |
3873 | } | |
a0f07959 HM |
3874 | |
3875 | if (dev_role == NL80211_IFTYPE_AP) { | |
3876 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); | |
3877 | if (err < 0) { | |
3878 | brcmf_err("BRCMF_C_DOWN error %d\n", err); | |
3879 | goto exit; | |
3880 | } | |
2880b868 | 3881 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
1a873342 HM |
3882 | } |
3883 | ||
a0f07959 | 3884 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
1a873342 | 3885 | if (err < 0) { |
a0f07959 | 3886 | brcmf_err("SET INFRA error %d\n", err); |
1a873342 HM |
3887 | goto exit; |
3888 | } | |
a0f07959 HM |
3889 | if (dev_role == NL80211_IFTYPE_AP) { |
3890 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); | |
3891 | if (err < 0) { | |
3892 | brcmf_err("setting AP mode failed %d\n", err); | |
3893 | goto exit; | |
3894 | } | |
3895 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); | |
3896 | if (err < 0) { | |
3897 | brcmf_err("BRCMF_C_UP error (%d)\n", err); | |
3898 | goto exit; | |
3899 | } | |
3900 | ||
3901 | memset(&join_params, 0, sizeof(join_params)); | |
3902 | /* join parameters starts with ssid */ | |
3903 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); | |
3904 | /* create softap */ | |
3905 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, | |
3906 | &join_params, sizeof(join_params)); | |
3907 | if (err < 0) { | |
3908 | brcmf_err("SET SSID error (%d)\n", err); | |
3909 | goto exit; | |
3910 | } | |
3911 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); | |
3912 | } else { | |
3913 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, | |
3914 | sizeof(ssid_le)); | |
3915 | if (err < 0) { | |
3916 | brcmf_err("setting ssid failed %d\n", err); | |
3917 | goto exit; | |
3918 | } | |
3919 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); | |
3920 | bss_enable.enable = cpu_to_le32(1); | |
3921 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, | |
3922 | sizeof(bss_enable)); | |
3923 | if (err < 0) { | |
3924 | brcmf_err("bss_enable config failed %d\n", err); | |
3925 | goto exit; | |
3926 | } | |
3927 | ||
3928 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); | |
3929 | } | |
c1179033 AS |
3930 | clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
3931 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); | |
1a873342 HM |
3932 | |
3933 | exit: | |
b3657453 | 3934 | if (err) { |
f96aa07e | 3935 | brcmf_set_mpc(ifp, 1); |
b3657453 HM |
3936 | brcmf_configure_arp_offload(ifp, true); |
3937 | } | |
1a873342 HM |
3938 | return err; |
3939 | } | |
3940 | ||
3941 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) | |
3942 | { | |
c1179033 | 3943 | struct brcmf_if *ifp = netdev_priv(ndev); |
5c33a942 | 3944 | s32 err; |
426d0a56 | 3945 | struct brcmf_fil_bss_enable_le bss_enable; |
5c33a942 | 3946 | struct brcmf_join_params join_params; |
1a873342 | 3947 | |
d96b801f | 3948 | brcmf_dbg(TRACE, "Enter\n"); |
1a873342 | 3949 | |
426d0a56 | 3950 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
1a873342 HM |
3951 | /* Due to most likely deauths outstanding we sleep */ |
3952 | /* first to make sure they get processed by fw. */ | |
3953 | msleep(400); | |
5c33a942 HM |
3954 | |
3955 | memset(&join_params, 0, sizeof(join_params)); | |
3956 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, | |
3957 | &join_params, sizeof(join_params)); | |
3958 | if (err < 0) | |
3959 | brcmf_err("SET SSID error (%d)\n", err); | |
128ce3b6 | 3960 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
5c33a942 | 3961 | if (err < 0) |
57d6e91a | 3962 | brcmf_err("BRCMF_C_UP error %d\n", err); |
5c33a942 HM |
3963 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
3964 | if (err < 0) | |
3965 | brcmf_err("setting AP mode failed %d\n", err); | |
3966 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); | |
3967 | if (err < 0) | |
3968 | brcmf_err("setting INFRA mode failed %d\n", err); | |
426d0a56 HM |
3969 | } else { |
3970 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); | |
3971 | bss_enable.enable = cpu_to_le32(0); | |
3972 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, | |
3973 | sizeof(bss_enable)); | |
3974 | if (err < 0) | |
3975 | brcmf_err("bss_enable config failed %d\n", err); | |
1a873342 | 3976 | } |
f96aa07e | 3977 | brcmf_set_mpc(ifp, 1); |
b3657453 | 3978 | brcmf_configure_arp_offload(ifp, true); |
426d0a56 HM |
3979 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
3980 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); | |
3981 | ||
1a873342 HM |
3982 | return err; |
3983 | } | |
3984 | ||
a0f07959 HM |
3985 | static s32 |
3986 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, | |
3987 | struct cfg80211_beacon_data *info) | |
3988 | { | |
a0f07959 HM |
3989 | struct brcmf_if *ifp = netdev_priv(ndev); |
3990 | s32 err; | |
3991 | ||
3992 | brcmf_dbg(TRACE, "Enter\n"); | |
3993 | ||
a0f07959 HM |
3994 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
3995 | ||
3996 | return err; | |
3997 | } | |
3998 | ||
1a873342 HM |
3999 | static int |
4000 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, | |
89c771e5 | 4001 | struct station_del_parameters *params) |
1a873342 | 4002 | { |
a0f07959 | 4003 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
1a873342 | 4004 | struct brcmf_scb_val_le scbval; |
0abb5f21 | 4005 | struct brcmf_if *ifp = netdev_priv(ndev); |
1a873342 HM |
4006 | s32 err; |
4007 | ||
89c771e5 | 4008 | if (!params->mac) |
1a873342 HM |
4009 | return -EFAULT; |
4010 | ||
89c771e5 | 4011 | brcmf_dbg(TRACE, "Enter %pM\n", params->mac); |
1a873342 | 4012 | |
a0f07959 HM |
4013 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
4014 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; | |
ce81e317 | 4015 | if (!check_vif_up(ifp->vif)) |
1a873342 HM |
4016 | return -EIO; |
4017 | ||
89c771e5 | 4018 | memcpy(&scbval.ea, params->mac, ETH_ALEN); |
1a873342 | 4019 | scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING); |
0abb5f21 | 4020 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON, |
81f5dcb8 | 4021 | &scbval, sizeof(scbval)); |
1a873342 | 4022 | if (err) |
57d6e91a | 4023 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
7ab6acd0 | 4024 | |
d96b801f | 4025 | brcmf_dbg(TRACE, "Exit\n"); |
1a873342 HM |
4026 | return err; |
4027 | } | |
4028 | ||
0de8aace HM |
4029 | |
4030 | static void | |
4031 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, | |
4032 | struct wireless_dev *wdev, | |
4033 | u16 frame_type, bool reg) | |
4034 | { | |
7fa2e352 | 4035 | struct brcmf_cfg80211_vif *vif; |
0de8aace HM |
4036 | u16 mgmt_type; |
4037 | ||
4038 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); | |
4039 | ||
4040 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; | |
7fa2e352 | 4041 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
0de8aace HM |
4042 | if (reg) |
4043 | vif->mgmt_rx_reg |= BIT(mgmt_type); | |
4044 | else | |
318a64ce | 4045 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
0de8aace HM |
4046 | } |
4047 | ||
4048 | ||
4049 | static int | |
4050 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, | |
b176e629 | 4051 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
0de8aace HM |
4052 | { |
4053 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
b176e629 AO |
4054 | struct ieee80211_channel *chan = params->chan; |
4055 | const u8 *buf = params->buf; | |
4056 | size_t len = params->len; | |
0de8aace HM |
4057 | const struct ieee80211_mgmt *mgmt; |
4058 | struct brcmf_cfg80211_vif *vif; | |
4059 | s32 err = 0; | |
4060 | s32 ie_offset; | |
4061 | s32 ie_len; | |
18e2f61d HM |
4062 | struct brcmf_fil_action_frame_le *action_frame; |
4063 | struct brcmf_fil_af_params_le *af_params; | |
4064 | bool ack; | |
4065 | s32 chan_nr; | |
c2ff8cad | 4066 | u32 freq; |
0de8aace HM |
4067 | |
4068 | brcmf_dbg(TRACE, "Enter\n"); | |
4069 | ||
4070 | *cookie = 0; | |
4071 | ||
4072 | mgmt = (const struct ieee80211_mgmt *)buf; | |
4073 | ||
a0f07959 HM |
4074 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
4075 | brcmf_err("Driver only allows MGMT packet type\n"); | |
4076 | return -EPERM; | |
4077 | } | |
0de8aace | 4078 | |
c2ff8cad AQ |
4079 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
4080 | ||
a0f07959 HM |
4081 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
4082 | /* Right now the only reason to get a probe response */ | |
4083 | /* is for p2p listen response or for p2p GO from */ | |
4084 | /* wpa_supplicant. Unfortunately the probe is send */ | |
4085 | /* on primary ndev, while dongle wants it on the p2p */ | |
4086 | /* vif. Since this is only reason for a probe */ | |
4087 | /* response to be sent, the vif is taken from cfg. */ | |
4088 | /* If ever desired to send proberesp for non p2p */ | |
4089 | /* response then data should be checked for */ | |
4090 | /* "DIRECT-". Note in future supplicant will take */ | |
4091 | /* dedicated p2p wdev to do this and then this 'hack'*/ | |
4092 | /* is not needed anymore. */ | |
4093 | ie_offset = DOT11_MGMT_HDR_LEN + | |
4094 | DOT11_BCN_PRB_FIXED_LEN; | |
4095 | ie_len = len - ie_offset; | |
a0f07959 | 4096 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
0de8aace | 4097 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
a0f07959 HM |
4098 | err = brcmf_vif_set_mgmt_ie(vif, |
4099 | BRCMF_VNDR_IE_PRBRSP_FLAG, | |
4100 | &buf[ie_offset], | |
4101 | ie_len); | |
4102 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, | |
4103 | GFP_KERNEL); | |
18e2f61d HM |
4104 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
4105 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); | |
4106 | if (af_params == NULL) { | |
4107 | brcmf_err("unable to allocate frame\n"); | |
4108 | err = -ENOMEM; | |
4109 | goto exit; | |
4110 | } | |
4111 | action_frame = &af_params->action_frame; | |
4112 | /* Add the packet Id */ | |
4113 | action_frame->packet_id = cpu_to_le32(*cookie); | |
4114 | /* Add BSSID */ | |
4115 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); | |
4116 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); | |
4117 | /* Add the length exepted for 802.11 header */ | |
4118 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); | |
c2ff8cad AQ |
4119 | /* Add the channel. Use the one specified as parameter if any or |
4120 | * the current one (got from the firmware) otherwise | |
4121 | */ | |
4122 | if (chan) | |
4123 | freq = chan->center_freq; | |
4124 | else | |
4125 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, | |
4126 | &freq); | |
4127 | chan_nr = ieee80211_frequency_to_channel(freq); | |
18e2f61d HM |
4128 | af_params->channel = cpu_to_le32(chan_nr); |
4129 | ||
4130 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], | |
4131 | le16_to_cpu(action_frame->len)); | |
4132 | ||
4133 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", | |
86a9c4a2 | 4134 | *cookie, le16_to_cpu(action_frame->len), freq); |
18e2f61d | 4135 | |
7fa2e352 | 4136 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
18e2f61d HM |
4137 | af_params); |
4138 | ||
4139 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, | |
4140 | GFP_KERNEL); | |
4141 | kfree(af_params); | |
a0f07959 HM |
4142 | } else { |
4143 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); | |
4144 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len); | |
0de8aace | 4145 | } |
a0f07959 | 4146 | |
18e2f61d | 4147 | exit: |
0de8aace HM |
4148 | return err; |
4149 | } | |
4150 | ||
4151 | ||
4152 | static int | |
4153 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, | |
4154 | struct wireless_dev *wdev, | |
4155 | u64 cookie) | |
4156 | { | |
4157 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
4158 | struct brcmf_cfg80211_vif *vif; | |
4159 | int err = 0; | |
4160 | ||
4161 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); | |
4162 | ||
4163 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; | |
4164 | if (vif == NULL) { | |
4165 | brcmf_err("No p2p device available for probe response\n"); | |
4166 | err = -ENODEV; | |
4167 | goto exit; | |
4168 | } | |
4169 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); | |
4170 | exit: | |
4171 | return err; | |
4172 | } | |
4173 | ||
61730d4d PH |
4174 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
4175 | struct wireless_dev *wdev, | |
4176 | enum nl80211_crit_proto_id proto, | |
4177 | u16 duration) | |
4178 | { | |
4179 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
4180 | struct brcmf_cfg80211_vif *vif; | |
4181 | ||
4182 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); | |
4183 | ||
4184 | /* only DHCP support for now */ | |
4185 | if (proto != NL80211_CRIT_PROTO_DHCP) | |
4186 | return -EINVAL; | |
4187 | ||
4188 | /* suppress and abort scanning */ | |
4189 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); | |
4190 | brcmf_abort_scanning(cfg); | |
4191 | ||
4192 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); | |
4193 | } | |
4194 | ||
4195 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, | |
4196 | struct wireless_dev *wdev) | |
4197 | { | |
4198 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
4199 | struct brcmf_cfg80211_vif *vif; | |
4200 | ||
4201 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); | |
4202 | ||
4203 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); | |
4204 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); | |
4205 | } | |
4206 | ||
70b7d94b HM |
4207 | static s32 |
4208 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, | |
4209 | const struct brcmf_event_msg *e, void *data) | |
4210 | { | |
4211 | switch (e->reason) { | |
4212 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: | |
4213 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); | |
4214 | break; | |
4215 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: | |
4216 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); | |
4217 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); | |
4218 | break; | |
4219 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: | |
4220 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); | |
4221 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); | |
4222 | break; | |
4223 | } | |
4224 | ||
4225 | return 0; | |
4226 | } | |
4227 | ||
89c2f382 AS |
4228 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
4229 | { | |
4230 | int ret; | |
4231 | ||
4232 | switch (oper) { | |
4233 | case NL80211_TDLS_DISCOVERY_REQ: | |
4234 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; | |
4235 | break; | |
4236 | case NL80211_TDLS_SETUP: | |
4237 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; | |
4238 | break; | |
4239 | case NL80211_TDLS_TEARDOWN: | |
4240 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; | |
4241 | break; | |
4242 | default: | |
4243 | brcmf_err("unsupported operation: %d\n", oper); | |
4244 | ret = -EOPNOTSUPP; | |
4245 | } | |
4246 | return ret; | |
4247 | } | |
4248 | ||
4249 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, | |
3b3a0162 | 4250 | struct net_device *ndev, const u8 *peer, |
89c2f382 AS |
4251 | enum nl80211_tdls_operation oper) |
4252 | { | |
4253 | struct brcmf_if *ifp; | |
4254 | struct brcmf_tdls_iovar_le info; | |
4255 | int ret = 0; | |
4256 | ||
4257 | ret = brcmf_convert_nl80211_tdls_oper(oper); | |
4258 | if (ret < 0) | |
4259 | return ret; | |
4260 | ||
4261 | ifp = netdev_priv(ndev); | |
4262 | memset(&info, 0, sizeof(info)); | |
4263 | info.mode = (u8)ret; | |
4264 | if (peer) | |
4265 | memcpy(info.ea, peer, ETH_ALEN); | |
4266 | ||
4267 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", | |
4268 | &info, sizeof(info)); | |
4269 | if (ret < 0) | |
4270 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); | |
4271 | ||
4272 | return ret; | |
4273 | } | |
4274 | ||
5b435de0 | 4275 | static struct cfg80211_ops wl_cfg80211_ops = { |
9f440b7b AS |
4276 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
4277 | .del_virtual_intf = brcmf_cfg80211_del_iface, | |
5b435de0 AS |
4278 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
4279 | .scan = brcmf_cfg80211_scan, | |
4280 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, | |
4281 | .join_ibss = brcmf_cfg80211_join_ibss, | |
4282 | .leave_ibss = brcmf_cfg80211_leave_ibss, | |
4283 | .get_station = brcmf_cfg80211_get_station, | |
4284 | .set_tx_power = brcmf_cfg80211_set_tx_power, | |
4285 | .get_tx_power = brcmf_cfg80211_get_tx_power, | |
4286 | .add_key = brcmf_cfg80211_add_key, | |
4287 | .del_key = brcmf_cfg80211_del_key, | |
4288 | .get_key = brcmf_cfg80211_get_key, | |
4289 | .set_default_key = brcmf_cfg80211_config_default_key, | |
4290 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, | |
4291 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, | |
5b435de0 AS |
4292 | .connect = brcmf_cfg80211_connect, |
4293 | .disconnect = brcmf_cfg80211_disconnect, | |
4294 | .suspend = brcmf_cfg80211_suspend, | |
4295 | .resume = brcmf_cfg80211_resume, | |
4296 | .set_pmksa = brcmf_cfg80211_set_pmksa, | |
4297 | .del_pmksa = brcmf_cfg80211_del_pmksa, | |
cbaa177d | 4298 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
1a873342 HM |
4299 | .start_ap = brcmf_cfg80211_start_ap, |
4300 | .stop_ap = brcmf_cfg80211_stop_ap, | |
a0f07959 | 4301 | .change_beacon = brcmf_cfg80211_change_beacon, |
1a873342 | 4302 | .del_station = brcmf_cfg80211_del_station, |
e5806072 AS |
4303 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
4304 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, | |
0de8aace HM |
4305 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
4306 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, | |
4307 | .remain_on_channel = brcmf_p2p_remain_on_channel, | |
4308 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, | |
27f10e38 AS |
4309 | .start_p2p_device = brcmf_p2p_start_device, |
4310 | .stop_p2p_device = brcmf_p2p_stop_device, | |
61730d4d PH |
4311 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
4312 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, | |
89c2f382 | 4313 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
5b435de0 AS |
4314 | }; |
4315 | ||
3eacf866 | 4316 | struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg, |
9f440b7b AS |
4317 | enum nl80211_iftype type, |
4318 | bool pm_block) | |
3eacf866 AS |
4319 | { |
4320 | struct brcmf_cfg80211_vif *vif; | |
5b435de0 | 4321 | |
33a6b157 | 4322 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
9f440b7b | 4323 | sizeof(*vif)); |
3eacf866 AS |
4324 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
4325 | if (!vif) | |
4326 | return ERR_PTR(-ENOMEM); | |
4327 | ||
4328 | vif->wdev.wiphy = cfg->wiphy; | |
9f440b7b | 4329 | vif->wdev.iftype = type; |
5b435de0 | 4330 | |
3eacf866 AS |
4331 | vif->pm_block = pm_block; |
4332 | vif->roam_off = -1; | |
4333 | ||
6ac4f4ed AS |
4334 | brcmf_init_prof(&vif->profile); |
4335 | ||
3eacf866 | 4336 | list_add_tail(&vif->list, &cfg->vif_list); |
3eacf866 | 4337 | return vif; |
5b435de0 AS |
4338 | } |
4339 | ||
427dec5f | 4340 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
5b435de0 | 4341 | { |
3eacf866 | 4342 | list_del(&vif->list); |
3eacf866 | 4343 | kfree(vif); |
5b435de0 AS |
4344 | } |
4345 | ||
9df4d542 AS |
4346 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
4347 | { | |
4348 | struct brcmf_cfg80211_vif *vif; | |
4349 | struct brcmf_if *ifp; | |
4350 | ||
4351 | ifp = netdev_priv(ndev); | |
4352 | vif = ifp->vif; | |
4353 | ||
4354 | brcmf_free_vif(vif); | |
4355 | free_netdev(ndev); | |
4356 | } | |
4357 | ||
903e0eee | 4358 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
5b435de0 | 4359 | { |
5c36b99a AS |
4360 | u32 event = e->event_code; |
4361 | u32 status = e->status; | |
5b435de0 AS |
4362 | |
4363 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { | |
16886735 | 4364 | brcmf_dbg(CONN, "Processing set ssid\n"); |
5b435de0 AS |
4365 | return true; |
4366 | } | |
4367 | ||
4368 | return false; | |
4369 | } | |
4370 | ||
903e0eee | 4371 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
5b435de0 | 4372 | { |
5c36b99a AS |
4373 | u32 event = e->event_code; |
4374 | u16 flags = e->flags; | |
5b435de0 | 4375 | |
68ca395f HM |
4376 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
4377 | (event == BRCMF_E_DISASSOC_IND) || | |
4378 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { | |
16886735 | 4379 | brcmf_dbg(CONN, "Processing link down\n"); |
5b435de0 AS |
4380 | return true; |
4381 | } | |
4382 | return false; | |
4383 | } | |
4384 | ||
27a68fe3 | 4385 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
4386 | const struct brcmf_event_msg *e) |
4387 | { | |
5c36b99a AS |
4388 | u32 event = e->event_code; |
4389 | u32 status = e->status; | |
5b435de0 AS |
4390 | |
4391 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { | |
16886735 AS |
4392 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
4393 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); | |
5b435de0 AS |
4394 | return true; |
4395 | } | |
4396 | ||
4397 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { | |
16886735 | 4398 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
5b435de0 AS |
4399 | return true; |
4400 | } | |
4401 | ||
4402 | return false; | |
4403 | } | |
4404 | ||
27a68fe3 | 4405 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 4406 | { |
27a68fe3 | 4407 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
5b435de0 AS |
4408 | |
4409 | kfree(conn_info->req_ie); | |
4410 | conn_info->req_ie = NULL; | |
4411 | conn_info->req_ie_len = 0; | |
4412 | kfree(conn_info->resp_ie); | |
4413 | conn_info->resp_ie = NULL; | |
4414 | conn_info->resp_ie_len = 0; | |
4415 | } | |
4416 | ||
89286dc9 HM |
4417 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
4418 | struct brcmf_if *ifp) | |
5b435de0 | 4419 | { |
c4e382d2 | 4420 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
27a68fe3 | 4421 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
5b435de0 AS |
4422 | u32 req_len; |
4423 | u32 resp_len; | |
4424 | s32 err = 0; | |
4425 | ||
27a68fe3 | 4426 | brcmf_clear_assoc_ies(cfg); |
5b435de0 | 4427 | |
ac24be6f AS |
4428 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
4429 | cfg->extra_buf, WL_ASSOC_INFO_MAX); | |
5b435de0 | 4430 | if (err) { |
57d6e91a | 4431 | brcmf_err("could not get assoc info (%d)\n", err); |
5b435de0 AS |
4432 | return err; |
4433 | } | |
c4e382d2 | 4434 | assoc_info = |
27a68fe3 | 4435 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
c4e382d2 AS |
4436 | req_len = le32_to_cpu(assoc_info->req_len); |
4437 | resp_len = le32_to_cpu(assoc_info->resp_len); | |
5b435de0 | 4438 | if (req_len) { |
ac24be6f | 4439 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
81f5dcb8 HM |
4440 | cfg->extra_buf, |
4441 | WL_ASSOC_INFO_MAX); | |
5b435de0 | 4442 | if (err) { |
57d6e91a | 4443 | brcmf_err("could not get assoc req (%d)\n", err); |
5b435de0 AS |
4444 | return err; |
4445 | } | |
4446 | conn_info->req_ie_len = req_len; | |
4447 | conn_info->req_ie = | |
27a68fe3 | 4448 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
5b435de0 AS |
4449 | GFP_KERNEL); |
4450 | } else { | |
4451 | conn_info->req_ie_len = 0; | |
4452 | conn_info->req_ie = NULL; | |
4453 | } | |
4454 | if (resp_len) { | |
ac24be6f | 4455 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
81f5dcb8 HM |
4456 | cfg->extra_buf, |
4457 | WL_ASSOC_INFO_MAX); | |
5b435de0 | 4458 | if (err) { |
57d6e91a | 4459 | brcmf_err("could not get assoc resp (%d)\n", err); |
5b435de0 AS |
4460 | return err; |
4461 | } | |
4462 | conn_info->resp_ie_len = resp_len; | |
4463 | conn_info->resp_ie = | |
27a68fe3 | 4464 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
5b435de0 AS |
4465 | GFP_KERNEL); |
4466 | } else { | |
4467 | conn_info->resp_ie_len = 0; | |
4468 | conn_info->resp_ie = NULL; | |
4469 | } | |
16886735 AS |
4470 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
4471 | conn_info->req_ie_len, conn_info->resp_ie_len); | |
5b435de0 AS |
4472 | |
4473 | return err; | |
4474 | } | |
4475 | ||
4476 | static s32 | |
27a68fe3 | 4477 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
4478 | struct net_device *ndev, |
4479 | const struct brcmf_event_msg *e) | |
4480 | { | |
c1179033 AS |
4481 | struct brcmf_if *ifp = netdev_priv(ndev); |
4482 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
27a68fe3 AS |
4483 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
4484 | struct wiphy *wiphy = cfg_to_wiphy(cfg); | |
a180b83b | 4485 | struct ieee80211_channel *notify_channel = NULL; |
5b435de0 | 4486 | struct ieee80211_supported_band *band; |
a180b83b | 4487 | struct brcmf_bss_info_le *bi; |
83cf17aa | 4488 | struct brcmu_chan ch; |
5b435de0 AS |
4489 | u32 freq; |
4490 | s32 err = 0; | |
a180b83b | 4491 | u8 *buf; |
5b435de0 | 4492 | |
d96b801f | 4493 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 4494 | |
89286dc9 | 4495 | brcmf_get_assoc_ies(cfg, ifp); |
6c8c4f72 | 4496 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
89286dc9 | 4497 | brcmf_update_bss_info(cfg, ifp); |
5b435de0 | 4498 | |
a180b83b FL |
4499 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
4500 | if (buf == NULL) { | |
4501 | err = -ENOMEM; | |
4502 | goto done; | |
4503 | } | |
4504 | ||
4505 | /* data sent to dongle has to be little endian */ | |
4506 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); | |
c1179033 | 4507 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
ac24be6f | 4508 | buf, WL_BSS_INFO_MAX); |
a180b83b FL |
4509 | |
4510 | if (err) | |
4511 | goto done; | |
5b435de0 | 4512 | |
a180b83b | 4513 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
83cf17aa FL |
4514 | ch.chspec = le16_to_cpu(bi->chanspec); |
4515 | cfg->d11inf.decchspec(&ch); | |
5b435de0 | 4516 | |
83cf17aa | 4517 | if (ch.band == BRCMU_CHAN_BAND_2G) |
5b435de0 AS |
4518 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
4519 | else | |
4520 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | |
4521 | ||
83cf17aa | 4522 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
5b435de0 AS |
4523 | notify_channel = ieee80211_get_channel(wiphy, freq); |
4524 | ||
a180b83b FL |
4525 | done: |
4526 | kfree(buf); | |
06bb123e | 4527 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
5b435de0 AS |
4528 | conn_info->req_ie, conn_info->req_ie_len, |
4529 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); | |
16886735 | 4530 | brcmf_dbg(CONN, "Report roaming result\n"); |
5b435de0 | 4531 | |
c1179033 | 4532 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
d96b801f | 4533 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
4534 | return err; |
4535 | } | |
4536 | ||
4537 | static s32 | |
27a68fe3 | 4538 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
4539 | struct net_device *ndev, const struct brcmf_event_msg *e, |
4540 | bool completed) | |
4541 | { | |
c1179033 AS |
4542 | struct brcmf_if *ifp = netdev_priv(ndev); |
4543 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
27a68fe3 | 4544 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
5b435de0 | 4545 | |
d96b801f | 4546 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 4547 | |
c1179033 AS |
4548 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
4549 | &ifp->vif->sme_state)) { | |
5b435de0 | 4550 | if (completed) { |
89286dc9 | 4551 | brcmf_get_assoc_ies(cfg, ifp); |
6c8c4f72 | 4552 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
89286dc9 HM |
4553 | brcmf_update_bss_info(cfg, ifp); |
4554 | set_bit(BRCMF_VIF_STATUS_CONNECTED, | |
4555 | &ifp->vif->sme_state); | |
5b435de0 AS |
4556 | } |
4557 | cfg80211_connect_result(ndev, | |
06bb123e | 4558 | (u8 *)profile->bssid, |
5b435de0 AS |
4559 | conn_info->req_ie, |
4560 | conn_info->req_ie_len, | |
4561 | conn_info->resp_ie, | |
4562 | conn_info->resp_ie_len, | |
4563 | completed ? WLAN_STATUS_SUCCESS : | |
4564 | WLAN_STATUS_AUTH_TIMEOUT, | |
4565 | GFP_KERNEL); | |
16886735 AS |
4566 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
4567 | completed ? "succeeded" : "failed"); | |
5b435de0 | 4568 | } |
d96b801f | 4569 | brcmf_dbg(TRACE, "Exit\n"); |
12f32370 | 4570 | return 0; |
5b435de0 AS |
4571 | } |
4572 | ||
4573 | static s32 | |
27a68fe3 | 4574 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
1a873342 HM |
4575 | struct net_device *ndev, |
4576 | const struct brcmf_event_msg *e, void *data) | |
4577 | { | |
7ee29602 | 4578 | static int generation; |
5c36b99a AS |
4579 | u32 event = e->event_code; |
4580 | u32 reason = e->reason; | |
1a873342 HM |
4581 | struct station_info sinfo; |
4582 | ||
16886735 | 4583 | brcmf_dbg(CONN, "event %d, reason %d\n", event, reason); |
5f4f9f11 AS |
4584 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
4585 | ndev != cfg_to_ndev(cfg)) { | |
4586 | brcmf_dbg(CONN, "AP mode link down\n"); | |
4587 | complete(&cfg->vif_disabled); | |
4588 | return 0; | |
4589 | } | |
1a873342 | 4590 | |
1a873342 | 4591 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
7ee29602 HM |
4592 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
4593 | memset(&sinfo, 0, sizeof(sinfo)); | |
1a873342 HM |
4594 | sinfo.filled = STATION_INFO_ASSOC_REQ_IES; |
4595 | if (!data) { | |
57d6e91a | 4596 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
1a873342 HM |
4597 | return -EINVAL; |
4598 | } | |
4599 | sinfo.assoc_req_ies = data; | |
7ee29602 | 4600 | sinfo.assoc_req_ies_len = e->datalen; |
1a873342 HM |
4601 | generation++; |
4602 | sinfo.generation = generation; | |
7ee29602 | 4603 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
1a873342 HM |
4604 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
4605 | (event == BRCMF_E_DEAUTH_IND) || | |
4606 | (event == BRCMF_E_DEAUTH)) { | |
7ee29602 | 4607 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
1a873342 | 4608 | } |
7ee29602 | 4609 | return 0; |
1a873342 HM |
4610 | } |
4611 | ||
5b435de0 | 4612 | static s32 |
1993732e | 4613 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
5b435de0 AS |
4614 | const struct brcmf_event_msg *e, void *data) |
4615 | { | |
1993732e AS |
4616 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
4617 | struct net_device *ndev = ifp->ndev; | |
c1179033 | 4618 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
fe94f3a4 | 4619 | struct ieee80211_channel *chan; |
5b435de0 AS |
4620 | s32 err = 0; |
4621 | ||
8851cce0 HM |
4622 | if ((e->event_code == BRCMF_E_DEAUTH) || |
4623 | (e->event_code == BRCMF_E_DEAUTH_IND) || | |
4624 | (e->event_code == BRCMF_E_DISASSOC_IND) || | |
4625 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { | |
4626 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); | |
4627 | } | |
4628 | ||
967fe2c8 | 4629 | if (brcmf_is_apmode(ifp->vif)) { |
27a68fe3 | 4630 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
903e0eee | 4631 | } else if (brcmf_is_linkup(e)) { |
16886735 | 4632 | brcmf_dbg(CONN, "Linkup\n"); |
128ce3b6 | 4633 | if (brcmf_is_ibssmode(ifp->vif)) { |
fe94f3a4 | 4634 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
6c8c4f72 | 4635 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
27a68fe3 | 4636 | wl_inform_ibss(cfg, ndev, e->addr); |
fe94f3a4 | 4637 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
c1179033 AS |
4638 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
4639 | &ifp->vif->sme_state); | |
4640 | set_bit(BRCMF_VIF_STATUS_CONNECTED, | |
4641 | &ifp->vif->sme_state); | |
5b435de0 | 4642 | } else |
27a68fe3 | 4643 | brcmf_bss_connect_done(cfg, ndev, e, true); |
903e0eee | 4644 | } else if (brcmf_is_linkdown(e)) { |
16886735 | 4645 | brcmf_dbg(CONN, "Linkdown\n"); |
128ce3b6 | 4646 | if (!brcmf_is_ibssmode(ifp->vif)) { |
27a68fe3 | 4647 | brcmf_bss_connect_done(cfg, ndev, e, false); |
5b435de0 | 4648 | } |
903e0eee | 4649 | brcmf_link_down(ifp->vif); |
6ac4f4ed | 4650 | brcmf_init_prof(ndev_to_prof(ndev)); |
5f4f9f11 AS |
4651 | if (ndev != cfg_to_ndev(cfg)) |
4652 | complete(&cfg->vif_disabled); | |
27a68fe3 | 4653 | } else if (brcmf_is_nonetwork(cfg, e)) { |
128ce3b6 | 4654 | if (brcmf_is_ibssmode(ifp->vif)) |
c1179033 AS |
4655 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
4656 | &ifp->vif->sme_state); | |
5b435de0 | 4657 | else |
27a68fe3 | 4658 | brcmf_bss_connect_done(cfg, ndev, e, false); |
5b435de0 AS |
4659 | } |
4660 | ||
4661 | return err; | |
4662 | } | |
4663 | ||
4664 | static s32 | |
1993732e | 4665 | brcmf_notify_roaming_status(struct brcmf_if *ifp, |
5b435de0 AS |
4666 | const struct brcmf_event_msg *e, void *data) |
4667 | { | |
1993732e | 4668 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
5c36b99a AS |
4669 | u32 event = e->event_code; |
4670 | u32 status = e->status; | |
5b435de0 AS |
4671 | |
4672 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { | |
c1179033 | 4673 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
1993732e | 4674 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
5b435de0 | 4675 | else |
1993732e | 4676 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
5b435de0 AS |
4677 | } |
4678 | ||
12f32370 | 4679 | return 0; |
5b435de0 AS |
4680 | } |
4681 | ||
4682 | static s32 | |
1993732e | 4683 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
5b435de0 AS |
4684 | const struct brcmf_event_msg *e, void *data) |
4685 | { | |
5c36b99a | 4686 | u16 flags = e->flags; |
5b435de0 AS |
4687 | enum nl80211_key_type key_type; |
4688 | ||
4689 | if (flags & BRCMF_EVENT_MSG_GROUP) | |
4690 | key_type = NL80211_KEYTYPE_GROUP; | |
4691 | else | |
4692 | key_type = NL80211_KEYTYPE_PAIRWISE; | |
4693 | ||
1993732e | 4694 | cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1, |
5b435de0 AS |
4695 | NULL, GFP_KERNEL); |
4696 | ||
4697 | return 0; | |
4698 | } | |
4699 | ||
d3c0b633 AS |
4700 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
4701 | const struct brcmf_event_msg *e, void *data) | |
4702 | { | |
4703 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; | |
4704 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; | |
4705 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
4706 | struct brcmf_cfg80211_vif *vif; | |
4707 | ||
4708 | brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n", | |
4709 | ifevent->action, ifevent->flags, ifevent->ifidx, | |
4710 | ifevent->bssidx); | |
4711 | ||
d3c0b633 AS |
4712 | mutex_lock(&event->vif_event_lock); |
4713 | event->action = ifevent->action; | |
4714 | vif = event->vif; | |
4715 | ||
4716 | switch (ifevent->action) { | |
4717 | case BRCMF_E_IF_ADD: | |
4718 | /* waiting process may have timed out */ | |
dc4a787c WY |
4719 | if (!cfg->vif_event.vif) { |
4720 | mutex_unlock(&event->vif_event_lock); | |
d3c0b633 | 4721 | return -EBADF; |
dc4a787c | 4722 | } |
d3c0b633 AS |
4723 | |
4724 | ifp->vif = vif; | |
4725 | vif->ifp = ifp; | |
01b8e7db AS |
4726 | if (ifp->ndev) { |
4727 | vif->wdev.netdev = ifp->ndev; | |
4728 | ifp->ndev->ieee80211_ptr = &vif->wdev; | |
4729 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); | |
4730 | } | |
d3c0b633 AS |
4731 | mutex_unlock(&event->vif_event_lock); |
4732 | wake_up(&event->vif_wq); | |
4b3a89de | 4733 | return 0; |
d3c0b633 AS |
4734 | |
4735 | case BRCMF_E_IF_DEL: | |
d3c0b633 AS |
4736 | mutex_unlock(&event->vif_event_lock); |
4737 | /* event may not be upon user request */ | |
4738 | if (brcmf_cfg80211_vif_event_armed(cfg)) | |
4739 | wake_up(&event->vif_wq); | |
4740 | return 0; | |
4741 | ||
7a5c1f64 HM |
4742 | case BRCMF_E_IF_CHANGE: |
4743 | mutex_unlock(&event->vif_event_lock); | |
4744 | wake_up(&event->vif_wq); | |
4745 | return 0; | |
4746 | ||
d3c0b633 AS |
4747 | default: |
4748 | mutex_unlock(&event->vif_event_lock); | |
4749 | break; | |
4750 | } | |
4751 | return -EINVAL; | |
4752 | } | |
4753 | ||
5b435de0 AS |
4754 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
4755 | { | |
5b435de0 AS |
4756 | conf->frag_threshold = (u32)-1; |
4757 | conf->rts_threshold = (u32)-1; | |
4758 | conf->retry_short = (u32)-1; | |
4759 | conf->retry_long = (u32)-1; | |
4760 | conf->tx_power = -1; | |
4761 | } | |
4762 | ||
5c36b99a | 4763 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 4764 | { |
5c36b99a AS |
4765 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
4766 | brcmf_notify_connect_status); | |
4767 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, | |
4768 | brcmf_notify_connect_status); | |
4769 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, | |
4770 | brcmf_notify_connect_status); | |
4771 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, | |
4772 | brcmf_notify_connect_status); | |
4773 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, | |
4774 | brcmf_notify_connect_status); | |
4775 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, | |
4776 | brcmf_notify_connect_status); | |
4777 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, | |
4778 | brcmf_notify_roaming_status); | |
4779 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, | |
4780 | brcmf_notify_mic_status); | |
4781 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, | |
4782 | brcmf_notify_connect_status); | |
4783 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, | |
4784 | brcmf_notify_sched_scan_results); | |
d3c0b633 AS |
4785 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
4786 | brcmf_notify_vif_event); | |
0de8aace | 4787 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
6eda4e2c | 4788 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
0de8aace HM |
4789 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
4790 | brcmf_p2p_notify_listen_complete); | |
e6da3400 HM |
4791 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
4792 | brcmf_p2p_notify_action_frame_rx); | |
18e2f61d HM |
4793 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
4794 | brcmf_p2p_notify_action_tx_complete); | |
6eda4e2c HM |
4795 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
4796 | brcmf_p2p_notify_action_tx_complete); | |
5b435de0 AS |
4797 | } |
4798 | ||
27a68fe3 AS |
4799 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
4800 | { | |
27a68fe3 AS |
4801 | kfree(cfg->conf); |
4802 | cfg->conf = NULL; | |
27a68fe3 AS |
4803 | kfree(cfg->escan_ioctl_buf); |
4804 | cfg->escan_ioctl_buf = NULL; | |
27a68fe3 AS |
4805 | kfree(cfg->extra_buf); |
4806 | cfg->extra_buf = NULL; | |
27a68fe3 AS |
4807 | kfree(cfg->pmk_list); |
4808 | cfg->pmk_list = NULL; | |
27a68fe3 AS |
4809 | } |
4810 | ||
4811 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) | |
4812 | { | |
27a68fe3 AS |
4813 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
4814 | if (!cfg->conf) | |
5b435de0 | 4815 | goto init_priv_mem_out; |
27a68fe3 AS |
4816 | cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
4817 | if (!cfg->escan_ioctl_buf) | |
e756af5b | 4818 | goto init_priv_mem_out; |
27a68fe3 AS |
4819 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
4820 | if (!cfg->extra_buf) | |
5b435de0 | 4821 | goto init_priv_mem_out; |
27a68fe3 AS |
4822 | cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL); |
4823 | if (!cfg->pmk_list) | |
5b435de0 AS |
4824 | goto init_priv_mem_out; |
4825 | ||
4826 | return 0; | |
4827 | ||
4828 | init_priv_mem_out: | |
27a68fe3 | 4829 | brcmf_deinit_priv_mem(cfg); |
5b435de0 AS |
4830 | |
4831 | return -ENOMEM; | |
4832 | } | |
4833 | ||
27a68fe3 | 4834 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
5b435de0 AS |
4835 | { |
4836 | s32 err = 0; | |
4837 | ||
27a68fe3 AS |
4838 | cfg->scan_request = NULL; |
4839 | cfg->pwr_save = true; | |
68ca395f HM |
4840 | cfg->active_scan = true; /* we do active scan per default */ |
4841 | cfg->dongle_up = false; /* dongle is not up yet */ | |
27a68fe3 | 4842 | err = brcmf_init_priv_mem(cfg); |
5b435de0 AS |
4843 | if (err) |
4844 | return err; | |
5c36b99a | 4845 | brcmf_register_event_handlers(cfg); |
27a68fe3 | 4846 | mutex_init(&cfg->usr_sync); |
27a68fe3 AS |
4847 | brcmf_init_escan(cfg); |
4848 | brcmf_init_conf(cfg->conf); | |
5f4f9f11 | 4849 | init_completion(&cfg->vif_disabled); |
5b435de0 AS |
4850 | return err; |
4851 | } | |
4852 | ||
27a68fe3 | 4853 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 4854 | { |
27a68fe3 | 4855 | cfg->dongle_up = false; /* dongle down */ |
27a68fe3 AS |
4856 | brcmf_abort_scanning(cfg); |
4857 | brcmf_deinit_priv_mem(cfg); | |
5b435de0 AS |
4858 | } |
4859 | ||
d3c0b633 AS |
4860 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
4861 | { | |
4862 | init_waitqueue_head(&event->vif_wq); | |
d3c0b633 AS |
4863 | mutex_init(&event->vif_event_lock); |
4864 | } | |
4865 | ||
5b435de0 | 4866 | static s32 |
68ca395f | 4867 | brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout) |
5b435de0 | 4868 | { |
5b435de0 | 4869 | s32 err = 0; |
f588bc0c AS |
4870 | __le32 roamtrigger[2]; |
4871 | __le32 roam_delta[2]; | |
5b435de0 AS |
4872 | |
4873 | /* | |
4874 | * Setup timeout if Beacons are lost and roam is | |
4875 | * off to report link down | |
4876 | */ | |
68ca395f | 4877 | if (brcmf_roamoff) { |
ac24be6f | 4878 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
5b435de0 | 4879 | if (err) { |
57d6e91a | 4880 | brcmf_err("bcn_timeout error (%d)\n", err); |
5b435de0 AS |
4881 | goto dongle_rom_out; |
4882 | } | |
4883 | } | |
4884 | ||
4885 | /* | |
4886 | * Enable/Disable built-in roaming to allow supplicant | |
4887 | * to take care of roaming | |
4888 | */ | |
68ca395f HM |
4889 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
4890 | brcmf_roamoff ? "Off" : "On"); | |
4891 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff)); | |
5b435de0 | 4892 | if (err) { |
57d6e91a | 4893 | brcmf_err("roam_off error (%d)\n", err); |
5b435de0 AS |
4894 | goto dongle_rom_out; |
4895 | } | |
4896 | ||
f588bc0c AS |
4897 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
4898 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); | |
ac24be6f | 4899 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
81f5dcb8 | 4900 | (void *)roamtrigger, sizeof(roamtrigger)); |
5b435de0 | 4901 | if (err) { |
57d6e91a | 4902 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
5b435de0 AS |
4903 | goto dongle_rom_out; |
4904 | } | |
4905 | ||
f588bc0c AS |
4906 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
4907 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); | |
ac24be6f | 4908 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
81f5dcb8 | 4909 | (void *)roam_delta, sizeof(roam_delta)); |
5b435de0 | 4910 | if (err) { |
57d6e91a | 4911 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
5b435de0 AS |
4912 | goto dongle_rom_out; |
4913 | } | |
4914 | ||
4915 | dongle_rom_out: | |
4916 | return err; | |
4917 | } | |
4918 | ||
4919 | static s32 | |
40a23296 | 4920 | brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time, |
c68cdc0f | 4921 | s32 scan_unassoc_time, s32 scan_passive_time) |
5b435de0 AS |
4922 | { |
4923 | s32 err = 0; | |
4924 | ||
ac24be6f | 4925 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME, |
81f5dcb8 | 4926 | scan_assoc_time); |
5b435de0 AS |
4927 | if (err) { |
4928 | if (err == -EOPNOTSUPP) | |
647c9ae0 | 4929 | brcmf_dbg(INFO, "Scan assoc time is not supported\n"); |
5b435de0 | 4930 | else |
57d6e91a | 4931 | brcmf_err("Scan assoc time error (%d)\n", err); |
5b435de0 AS |
4932 | goto dongle_scantime_out; |
4933 | } | |
ac24be6f | 4934 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME, |
81f5dcb8 | 4935 | scan_unassoc_time); |
5b435de0 AS |
4936 | if (err) { |
4937 | if (err == -EOPNOTSUPP) | |
647c9ae0 | 4938 | brcmf_dbg(INFO, "Scan unassoc time is not supported\n"); |
5b435de0 | 4939 | else |
57d6e91a | 4940 | brcmf_err("Scan unassoc time error (%d)\n", err); |
5b435de0 AS |
4941 | goto dongle_scantime_out; |
4942 | } | |
4943 | ||
ac24be6f | 4944 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME, |
81f5dcb8 | 4945 | scan_passive_time); |
5b435de0 AS |
4946 | if (err) { |
4947 | if (err == -EOPNOTSUPP) | |
647c9ae0 | 4948 | brcmf_dbg(INFO, "Scan passive time is not supported\n"); |
5b435de0 | 4949 | else |
57d6e91a | 4950 | brcmf_err("Scan passive time error (%d)\n", err); |
5b435de0 AS |
4951 | goto dongle_scantime_out; |
4952 | } | |
4953 | ||
4954 | dongle_scantime_out: | |
4955 | return err; | |
4956 | } | |
4957 | ||
b48d8916 AS |
4958 | /* Filter the list of channels received from firmware counting only |
4959 | * the 20MHz channels. The wiphy band data only needs those which get | |
4960 | * flagged to indicate if they can take part in higher bandwidth. | |
4961 | */ | |
4962 | static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg, | |
4963 | struct brcmf_chanspec_list *chlist, | |
4964 | u32 chcnt[]) | |
4965 | { | |
4966 | u32 total = le32_to_cpu(chlist->count); | |
4967 | struct brcmu_chan ch; | |
4968 | int i; | |
4969 | ||
f8adaf0a | 4970 | for (i = 0; i < total; i++) { |
b48d8916 AS |
4971 | ch.chspec = (u16)le32_to_cpu(chlist->element[i]); |
4972 | cfg->d11inf.decchspec(&ch); | |
4973 | ||
4974 | /* Firmware gives a ordered list. We skip non-20MHz | |
4975 | * channels is 2G. For 5G we can abort upon reaching | |
4976 | * a non-20MHz channel in the list. | |
4977 | */ | |
4978 | if (ch.bw != BRCMU_CHAN_BW_20) { | |
4979 | if (ch.band == BRCMU_CHAN_BAND_5G) | |
4980 | break; | |
4981 | else | |
4982 | continue; | |
4983 | } | |
4984 | ||
4985 | if (ch.band == BRCMU_CHAN_BAND_2G) | |
4986 | chcnt[0] += 1; | |
4987 | else if (ch.band == BRCMU_CHAN_BAND_5G) | |
4988 | chcnt[1] += 1; | |
4989 | } | |
4990 | } | |
4991 | ||
4992 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, | |
4993 | struct brcmu_chan *ch) | |
4994 | { | |
4995 | u32 ht40_flag; | |
d48200ba | 4996 | |
b48d8916 AS |
4997 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
4998 | if (ch->sb == BRCMU_CHAN_SB_U) { | |
4999 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) | |
5000 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; | |
5001 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; | |
5002 | } else { | |
5003 | /* It should be one of | |
5004 | * IEEE80211_CHAN_NO_HT40 or | |
5005 | * IEEE80211_CHAN_NO_HT40PLUS | |
5006 | */ | |
5007 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; | |
5008 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) | |
5009 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; | |
5010 | } | |
5011 | } | |
5012 | ||
5013 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, | |
5014 | u32 bw_cap[]) | |
d48200ba HM |
5015 | { |
5016 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); | |
b48d8916 AS |
5017 | struct ieee80211_supported_band *band; |
5018 | struct ieee80211_channel *channel; | |
5019 | struct wiphy *wiphy; | |
d48200ba | 5020 | struct brcmf_chanspec_list *list; |
83cf17aa | 5021 | struct brcmu_chan ch; |
b48d8916 | 5022 | int err; |
d48200ba HM |
5023 | u8 *pbuf; |
5024 | u32 i, j; | |
5025 | u32 total; | |
b48d8916 AS |
5026 | u32 chaninfo; |
5027 | u32 chcnt[2] = { 0, 0 }; | |
d48200ba | 5028 | u32 index; |
d48200ba HM |
5029 | |
5030 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); | |
5031 | ||
5032 | if (pbuf == NULL) | |
5033 | return -ENOMEM; | |
5034 | ||
5035 | list = (struct brcmf_chanspec_list *)pbuf; | |
5036 | ||
5037 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, | |
5038 | BRCMF_DCMD_MEDLEN); | |
5039 | if (err) { | |
5040 | brcmf_err("get chanspecs error (%d)\n", err); | |
b48d8916 | 5041 | goto fail_pbuf; |
d48200ba HM |
5042 | } |
5043 | ||
b48d8916 AS |
5044 | brcmf_count_20mhz_channels(cfg, list, chcnt); |
5045 | wiphy = cfg_to_wiphy(cfg); | |
5046 | if (chcnt[0]) { | |
5047 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), | |
5048 | GFP_KERNEL); | |
5049 | if (band == NULL) { | |
5050 | err = -ENOMEM; | |
5051 | goto fail_pbuf; | |
5052 | } | |
5053 | band->channels = kcalloc(chcnt[0], sizeof(*channel), | |
5054 | GFP_KERNEL); | |
5055 | if (band->channels == NULL) { | |
5056 | kfree(band); | |
5057 | err = -ENOMEM; | |
5058 | goto fail_pbuf; | |
5059 | } | |
5060 | band->n_channels = 0; | |
5061 | wiphy->bands[IEEE80211_BAND_2GHZ] = band; | |
5062 | } | |
5063 | if (chcnt[1]) { | |
5064 | band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a), | |
5065 | GFP_KERNEL); | |
5066 | if (band == NULL) { | |
5067 | err = -ENOMEM; | |
5068 | goto fail_band2g; | |
5069 | } | |
5070 | band->channels = kcalloc(chcnt[1], sizeof(*channel), | |
5071 | GFP_KERNEL); | |
5072 | if (band->channels == NULL) { | |
5073 | kfree(band); | |
5074 | err = -ENOMEM; | |
5075 | goto fail_band2g; | |
5076 | } | |
5077 | band->n_channels = 0; | |
5078 | wiphy->bands[IEEE80211_BAND_5GHZ] = band; | |
5079 | } | |
d48200ba HM |
5080 | |
5081 | total = le32_to_cpu(list->count); | |
5082 | for (i = 0; i < total; i++) { | |
83cf17aa FL |
5083 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
5084 | cfg->d11inf.decchspec(&ch); | |
d48200ba | 5085 | |
83cf17aa | 5086 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
b48d8916 | 5087 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
83cf17aa | 5088 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
b48d8916 | 5089 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
d48200ba | 5090 | } else { |
2375d970 | 5091 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
d48200ba HM |
5092 | continue; |
5093 | } | |
b48d8916 | 5094 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
2375d970 | 5095 | ch.bw == BRCMU_CHAN_BW_40) |
d48200ba | 5096 | continue; |
b48d8916 | 5097 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
ee942ecc AS |
5098 | ch.bw == BRCMU_CHAN_BW_80) |
5099 | continue; | |
b48d8916 AS |
5100 | |
5101 | channel = band->channels; | |
5102 | index = band->n_channels; | |
5103 | for (j = 0; j < band->n_channels; j++) { | |
5104 | if (channel[j].hw_value == ch.chnum) { | |
5105 | index = j; | |
d48200ba HM |
5106 | break; |
5107 | } | |
5108 | } | |
b48d8916 AS |
5109 | channel[index].center_freq = |
5110 | ieee80211_channel_to_frequency(ch.chnum, band->band); | |
5111 | channel[index].hw_value = ch.chnum; | |
5112 | ||
5113 | /* assuming the chanspecs order is HT20, | |
5114 | * HT40 upper, HT40 lower, and VHT80. | |
5115 | */ | |
5116 | if (ch.bw == BRCMU_CHAN_BW_80) { | |
5117 | channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ; | |
5118 | } else if (ch.bw == BRCMU_CHAN_BW_40) { | |
5119 | brcmf_update_bw40_channel_flag(&channel[index], &ch); | |
5120 | } else { | |
5121 | /* disable other bandwidths for now as mentioned | |
5122 | * order assure they are enabled for subsequent | |
5123 | * chanspecs. | |
ee942ecc | 5124 | */ |
b48d8916 AS |
5125 | channel[index].flags = IEEE80211_CHAN_NO_HT40 | |
5126 | IEEE80211_CHAN_NO_80MHZ; | |
5127 | ch.bw = BRCMU_CHAN_BW_20; | |
5128 | cfg->d11inf.encchspec(&ch); | |
5129 | chaninfo = ch.chspec; | |
5130 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", | |
5131 | &chaninfo); | |
5132 | if (!err) { | |
5133 | if (chaninfo & WL_CHAN_RADAR) | |
5134 | channel[index].flags |= | |
5135 | (IEEE80211_CHAN_RADAR | | |
5136 | IEEE80211_CHAN_NO_IR); | |
5137 | if (chaninfo & WL_CHAN_PASSIVE) | |
5138 | channel[index].flags |= | |
5139 | IEEE80211_CHAN_NO_IR; | |
d48200ba | 5140 | } |
d48200ba | 5141 | } |
b48d8916 AS |
5142 | if (index == band->n_channels) |
5143 | band->n_channels++; | |
d48200ba | 5144 | } |
b48d8916 AS |
5145 | kfree(pbuf); |
5146 | return 0; | |
5147 | ||
5148 | fail_band2g: | |
5149 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels); | |
5150 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]); | |
5151 | wiphy->bands[IEEE80211_BAND_2GHZ] = NULL; | |
5152 | fail_pbuf: | |
d48200ba HM |
5153 | kfree(pbuf); |
5154 | return err; | |
5155 | } | |
5156 | ||
b48d8916 | 5157 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
aa70b4fa | 5158 | { |
b48d8916 AS |
5159 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
5160 | struct ieee80211_supported_band *band; | |
aa70b4fa | 5161 | struct brcmf_fil_bwcap_le band_bwcap; |
b48d8916 AS |
5162 | struct brcmf_chanspec_list *list; |
5163 | u8 *pbuf; | |
aa70b4fa AS |
5164 | u32 val; |
5165 | int err; | |
b48d8916 AS |
5166 | struct brcmu_chan ch; |
5167 | u32 num_chan; | |
5168 | int i, j; | |
aa70b4fa AS |
5169 | |
5170 | /* verify support for bw_cap command */ | |
5171 | val = WLC_BAND_5G; | |
5172 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); | |
5173 | ||
5174 | if (!err) { | |
5175 | /* only set 2G bandwidth using bw_cap command */ | |
5176 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); | |
5177 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); | |
5178 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, | |
5179 | sizeof(band_bwcap)); | |
5180 | } else { | |
5181 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); | |
5182 | val = WLC_N_BW_40ALL; | |
5183 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); | |
5184 | } | |
b48d8916 AS |
5185 | |
5186 | if (!err) { | |
5187 | /* update channel info in 2G band */ | |
5188 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); | |
5189 | ||
5190 | if (pbuf == NULL) | |
5191 | return -ENOMEM; | |
5192 | ||
5193 | ch.band = BRCMU_CHAN_BAND_2G; | |
5194 | ch.bw = BRCMU_CHAN_BW_40; | |
fac7d2a3 | 5195 | ch.sb = BRCMU_CHAN_SB_NONE; |
b48d8916 AS |
5196 | ch.chnum = 0; |
5197 | cfg->d11inf.encchspec(&ch); | |
5198 | ||
5199 | /* pass encoded chanspec in query */ | |
5200 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); | |
5201 | ||
5202 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, | |
5203 | BRCMF_DCMD_MEDLEN); | |
5204 | if (err) { | |
5205 | brcmf_err("get chanspecs error (%d)\n", err); | |
5206 | kfree(pbuf); | |
5207 | return err; | |
5208 | } | |
5209 | ||
5210 | band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ]; | |
5211 | list = (struct brcmf_chanspec_list *)pbuf; | |
5212 | num_chan = le32_to_cpu(list->count); | |
5213 | for (i = 0; i < num_chan; i++) { | |
5214 | ch.chspec = (u16)le32_to_cpu(list->element[i]); | |
5215 | cfg->d11inf.decchspec(&ch); | |
5216 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) | |
5217 | continue; | |
5218 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) | |
5219 | continue; | |
5220 | for (j = 0; j < band->n_channels; j++) { | |
5221 | if (band->channels[j].hw_value == ch.chnum) | |
5222 | break; | |
5223 | } | |
5224 | if (WARN_ON(j == band->n_channels)) | |
5225 | continue; | |
5226 | ||
5227 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); | |
5228 | } | |
fac7d2a3 | 5229 | kfree(pbuf); |
b48d8916 | 5230 | } |
aa70b4fa AS |
5231 | return err; |
5232 | } | |
5233 | ||
2375d970 AS |
5234 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
5235 | { | |
5236 | u32 band, mimo_bwcap; | |
5237 | int err; | |
5238 | ||
5239 | band = WLC_BAND_2G; | |
5240 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); | |
5241 | if (!err) { | |
5242 | bw_cap[IEEE80211_BAND_2GHZ] = band; | |
5243 | band = WLC_BAND_5G; | |
5244 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); | |
5245 | if (!err) { | |
5246 | bw_cap[IEEE80211_BAND_5GHZ] = band; | |
5247 | return; | |
5248 | } | |
5249 | WARN_ON(1); | |
5250 | return; | |
5251 | } | |
5252 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); | |
5253 | mimo_bwcap = 0; | |
5254 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); | |
5255 | if (err) | |
5256 | /* assume 20MHz if firmware does not give a clue */ | |
5257 | mimo_bwcap = WLC_N_BW_20ALL; | |
5258 | ||
5259 | switch (mimo_bwcap) { | |
5260 | case WLC_N_BW_40ALL: | |
5261 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; | |
5262 | /* fall-thru */ | |
5263 | case WLC_N_BW_20IN2G_40IN5G: | |
5264 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; | |
5265 | /* fall-thru */ | |
5266 | case WLC_N_BW_20ALL: | |
5267 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; | |
5268 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; | |
5269 | break; | |
5270 | default: | |
5271 | brcmf_err("invalid mimo_bw_cap value\n"); | |
5272 | } | |
5273 | } | |
d48200ba | 5274 | |
18d6c535 AS |
5275 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
5276 | u32 bw_cap[2], u32 nchain) | |
5277 | { | |
5278 | band->ht_cap.ht_supported = true; | |
5279 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { | |
5280 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
5281 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
5282 | } | |
5283 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
5284 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
5285 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
5286 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; | |
5287 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); | |
5288 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
5289 | } | |
5290 | ||
5291 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) | |
5292 | { | |
5293 | u16 mcs_map; | |
5294 | int i; | |
5295 | ||
5296 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) | |
5297 | mcs_map = (mcs_map << 2) | supp; | |
5298 | ||
5299 | return cpu_to_le16(mcs_map); | |
5300 | } | |
5301 | ||
5302 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, | |
5303 | u32 bw_cap[2], u32 nchain) | |
5304 | { | |
5305 | __le16 mcs_map; | |
5306 | ||
5307 | /* not allowed in 2.4G band */ | |
5308 | if (band->band == IEEE80211_BAND_2GHZ) | |
5309 | return; | |
5310 | ||
5311 | band->vht_cap.vht_supported = true; | |
5312 | /* 80MHz is mandatory */ | |
5313 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; | |
5314 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { | |
5315 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; | |
5316 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; | |
5317 | } | |
5318 | /* all support 256-QAM */ | |
5319 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); | |
5320 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; | |
5321 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; | |
5322 | } | |
5323 | ||
b48d8916 | 5324 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
5b435de0 | 5325 | { |
b48d8916 | 5326 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
ac24be6f | 5327 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
18d6c535 AS |
5328 | u32 nmode = 0; |
5329 | u32 vhtmode = 0; | |
b48d8916 | 5330 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
4aca7a18 DK |
5331 | u32 rxchain; |
5332 | u32 nchain; | |
b48d8916 | 5333 | int err; |
d48200ba | 5334 | s32 i; |
2375d970 | 5335 | struct ieee80211_supported_band *band; |
5b435de0 | 5336 | |
18d6c535 | 5337 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
d48200ba HM |
5338 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
5339 | if (err) { | |
5340 | brcmf_err("nmode error (%d)\n", err); | |
5341 | } else { | |
2375d970 | 5342 | brcmf_get_bwcap(ifp, bw_cap); |
d48200ba | 5343 | } |
18d6c535 AS |
5344 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
5345 | nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ], | |
5346 | bw_cap[IEEE80211_BAND_5GHZ]); | |
d48200ba | 5347 | |
4aca7a18 DK |
5348 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
5349 | if (err) { | |
5350 | brcmf_err("rxchain error (%d)\n", err); | |
5351 | nchain = 1; | |
5352 | } else { | |
5353 | for (nchain = 0; rxchain; nchain++) | |
5354 | rxchain = rxchain & (rxchain - 1); | |
5355 | } | |
5356 | brcmf_dbg(INFO, "nchain=%d\n", nchain); | |
5357 | ||
b48d8916 | 5358 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
d48200ba | 5359 | if (err) { |
b48d8916 | 5360 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
d48200ba HM |
5361 | return err; |
5362 | } | |
5363 | ||
b48d8916 AS |
5364 | wiphy = cfg_to_wiphy(cfg); |
5365 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { | |
5366 | band = wiphy->bands[i]; | |
5367 | if (band == NULL) | |
2375d970 | 5368 | continue; |
d48200ba | 5369 | |
18d6c535 AS |
5370 | if (nmode) |
5371 | brcmf_update_ht_cap(band, bw_cap, nchain); | |
5372 | if (vhtmode) | |
5373 | brcmf_update_vht_cap(band, bw_cap, nchain); | |
d48200ba HM |
5374 | } |
5375 | ||
b48d8916 | 5376 | return 0; |
5b435de0 AS |
5377 | } |
5378 | ||
aa70b4fa AS |
5379 | static const struct ieee80211_iface_limit brcmf_iface_limits[] = { |
5380 | { | |
5381 | .max = 2, | |
5382 | .types = BIT(NL80211_IFTYPE_STATION) | | |
5383 | BIT(NL80211_IFTYPE_ADHOC) | | |
5384 | BIT(NL80211_IFTYPE_AP) | |
5385 | }, | |
5386 | { | |
5387 | .max = 1, | |
5388 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
5389 | BIT(NL80211_IFTYPE_P2P_GO) | |
5390 | }, | |
5391 | { | |
5392 | .max = 1, | |
5393 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) | |
5394 | } | |
5395 | }; | |
5396 | static struct ieee80211_iface_combination brcmf_iface_combos[] = { | |
5397 | { | |
5398 | .max_interfaces = BRCMF_IFACE_MAX_CNT, | |
5399 | .num_different_channels = 1, | |
5400 | .n_limits = ARRAY_SIZE(brcmf_iface_limits), | |
5401 | .limits = brcmf_iface_limits | |
5402 | } | |
5403 | }; | |
5404 | ||
5405 | static const struct ieee80211_txrx_stypes | |
5406 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { | |
5407 | [NL80211_IFTYPE_STATION] = { | |
5408 | .tx = 0xffff, | |
5409 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
5410 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
5411 | }, | |
5412 | [NL80211_IFTYPE_P2P_CLIENT] = { | |
5413 | .tx = 0xffff, | |
5414 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
5415 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
5416 | }, | |
5417 | [NL80211_IFTYPE_P2P_GO] = { | |
5418 | .tx = 0xffff, | |
5419 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | | |
5420 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | | |
5421 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | | |
5422 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | | |
5423 | BIT(IEEE80211_STYPE_AUTH >> 4) | | |
5424 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | | |
5425 | BIT(IEEE80211_STYPE_ACTION >> 4) | |
5426 | }, | |
5427 | [NL80211_IFTYPE_P2P_DEVICE] = { | |
5428 | .tx = 0xffff, | |
5429 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
5430 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
5431 | } | |
5432 | }; | |
5433 | ||
5434 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) | |
5435 | { | |
5436 | /* scheduled scan settings */ | |
5437 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; | |
5438 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; | |
5439 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; | |
5440 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; | |
5441 | } | |
5442 | ||
4eb3af7c HM |
5443 | |
5444 | #ifdef CONFIG_PM | |
5445 | static const struct wiphy_wowlan_support brcmf_wowlan_support = { | |
5446 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, | |
5447 | }; | |
5448 | #endif | |
5449 | ||
5450 | static void brcmf_wiphy_wowl_params(struct wiphy *wiphy) | |
5451 | { | |
5452 | #ifdef CONFIG_PM | |
5453 | /* wowl settings */ | |
5454 | wiphy->wowlan = &brcmf_wowlan_support; | |
5455 | #endif | |
5456 | } | |
5457 | ||
b48d8916 | 5458 | static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) |
aa70b4fa | 5459 | { |
b48d8916 | 5460 | struct ieee80211_iface_combination ifc_combo; |
aa70b4fa AS |
5461 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
5462 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; | |
5463 | wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX; | |
5464 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
5465 | BIT(NL80211_IFTYPE_ADHOC) | | |
5466 | BIT(NL80211_IFTYPE_AP) | | |
5467 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
5468 | BIT(NL80211_IFTYPE_P2P_GO) | | |
5469 | BIT(NL80211_IFTYPE_P2P_DEVICE); | |
5470 | /* need VSDB firmware feature for concurrent channels */ | |
b48d8916 | 5471 | ifc_combo = brcmf_iface_combos[0]; |
aa70b4fa | 5472 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
b48d8916 AS |
5473 | ifc_combo.num_different_channels = 2; |
5474 | wiphy->iface_combinations = kmemdup(&ifc_combo, | |
5475 | sizeof(ifc_combo), | |
5476 | GFP_KERNEL); | |
aa70b4fa | 5477 | wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos); |
aa70b4fa AS |
5478 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
5479 | wiphy->cipher_suites = __wl_cipher_suites; | |
5480 | wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites); | |
5481 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | | |
5482 | WIPHY_FLAG_OFFCHAN_TX | | |
5483 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | | |
5484 | WIPHY_FLAG_SUPPORTS_TDLS; | |
5485 | if (!brcmf_roamoff) | |
5486 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; | |
5487 | wiphy->mgmt_stypes = brcmf_txrx_stypes; | |
5488 | wiphy->max_remain_on_channel_duration = 5000; | |
5489 | brcmf_wiphy_pno_params(wiphy); | |
aa70b4fa AS |
5490 | |
5491 | /* vendor commands/events support */ | |
5492 | wiphy->vendor_commands = brcmf_vendor_cmds; | |
5493 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; | |
5494 | ||
4eb3af7c HM |
5495 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
5496 | brcmf_wiphy_wowl_params(wiphy); | |
5497 | ||
b48d8916 | 5498 | return brcmf_setup_wiphybands(wiphy); |
5b435de0 AS |
5499 | } |
5500 | ||
27a68fe3 | 5501 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
5b435de0 AS |
5502 | { |
5503 | struct net_device *ndev; | |
5504 | struct wireless_dev *wdev; | |
40a23296 | 5505 | struct brcmf_if *ifp; |
5b435de0 AS |
5506 | s32 power_mode; |
5507 | s32 err = 0; | |
5508 | ||
27a68fe3 | 5509 | if (cfg->dongle_up) |
5b435de0 AS |
5510 | return err; |
5511 | ||
27a68fe3 | 5512 | ndev = cfg_to_ndev(cfg); |
5b435de0 | 5513 | wdev = ndev->ieee80211_ptr; |
40a23296 HM |
5514 | ifp = netdev_priv(ndev); |
5515 | ||
5516 | /* make sure RF is ready for work */ | |
5517 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); | |
5b435de0 | 5518 | |
40a23296 HM |
5519 | brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME, |
5520 | WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME); | |
5b435de0 | 5521 | |
27a68fe3 | 5522 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
40a23296 | 5523 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode); |
5b435de0 AS |
5524 | if (err) |
5525 | goto default_conf_out; | |
647c9ae0 AS |
5526 | brcmf_dbg(INFO, "power save set to %s\n", |
5527 | (power_mode ? "enabled" : "disabled")); | |
5b435de0 | 5528 | |
68ca395f | 5529 | err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT); |
5b435de0 AS |
5530 | if (err) |
5531 | goto default_conf_out; | |
5dd161ff FL |
5532 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
5533 | NULL, NULL); | |
40a23296 | 5534 | if (err) |
5b435de0 | 5535 | goto default_conf_out; |
5b435de0 | 5536 | |
b3657453 HM |
5537 | brcmf_configure_arp_offload(ifp, true); |
5538 | ||
27a68fe3 | 5539 | cfg->dongle_up = true; |
40a23296 | 5540 | default_conf_out: |
5b435de0 AS |
5541 | |
5542 | return err; | |
5543 | ||
5544 | } | |
5545 | ||
bdf5ff51 | 5546 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
5b435de0 | 5547 | { |
c1179033 | 5548 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
5b435de0 | 5549 | |
bdf5ff51 | 5550 | return brcmf_config_dongle(ifp->drvr->config); |
5b435de0 AS |
5551 | } |
5552 | ||
bdf5ff51 | 5553 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
5b435de0 | 5554 | { |
bdf5ff51 | 5555 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
c1179033 | 5556 | |
5b435de0 AS |
5557 | /* |
5558 | * While going down, if associated with AP disassociate | |
5559 | * from AP to save power | |
5560 | */ | |
903e0eee AS |
5561 | if (check_vif_up(ifp->vif)) { |
5562 | brcmf_link_down(ifp->vif); | |
5b435de0 AS |
5563 | |
5564 | /* Make sure WPA_Supplicant receives all the event | |
5565 | generated due to DISASSOC call to the fw to keep | |
5566 | the state fw and WPA_Supplicant state consistent | |
5567 | */ | |
5568 | brcmf_delay(500); | |
5569 | } | |
5570 | ||
27a68fe3 | 5571 | brcmf_abort_scanning(cfg); |
c1179033 | 5572 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
5b435de0 | 5573 | |
5b435de0 AS |
5574 | return 0; |
5575 | } | |
5576 | ||
bdf5ff51 | 5577 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
5b435de0 | 5578 | { |
bdf5ff51 AS |
5579 | struct brcmf_if *ifp = netdev_priv(ndev); |
5580 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; | |
5b435de0 AS |
5581 | s32 err = 0; |
5582 | ||
27a68fe3 | 5583 | mutex_lock(&cfg->usr_sync); |
bdf5ff51 | 5584 | err = __brcmf_cfg80211_up(ifp); |
27a68fe3 | 5585 | mutex_unlock(&cfg->usr_sync); |
5b435de0 AS |
5586 | |
5587 | return err; | |
5588 | } | |
5589 | ||
bdf5ff51 | 5590 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
5b435de0 | 5591 | { |
bdf5ff51 AS |
5592 | struct brcmf_if *ifp = netdev_priv(ndev); |
5593 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; | |
5b435de0 AS |
5594 | s32 err = 0; |
5595 | ||
27a68fe3 | 5596 | mutex_lock(&cfg->usr_sync); |
bdf5ff51 | 5597 | err = __brcmf_cfg80211_down(ifp); |
27a68fe3 | 5598 | mutex_unlock(&cfg->usr_sync); |
5b435de0 AS |
5599 | |
5600 | return err; | |
5601 | } | |
5602 | ||
a7965fbb AS |
5603 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
5604 | { | |
5605 | struct wireless_dev *wdev = &ifp->vif->wdev; | |
5606 | ||
5607 | return wdev->iftype; | |
5608 | } | |
5609 | ||
e843bb19 | 5610 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, unsigned long state) |
9f440b7b AS |
5611 | { |
5612 | struct brcmf_cfg80211_vif *vif; | |
9f440b7b AS |
5613 | |
5614 | list_for_each_entry(vif, &cfg->vif_list, list) { | |
5615 | if (test_bit(state, &vif->sme_state)) | |
e843bb19 | 5616 | return true; |
9f440b7b | 5617 | } |
e843bb19 | 5618 | return false; |
9f440b7b | 5619 | } |
d3c0b633 AS |
5620 | |
5621 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, | |
5622 | u8 action) | |
5623 | { | |
5624 | u8 evt_action; | |
5625 | ||
5626 | mutex_lock(&event->vif_event_lock); | |
5627 | evt_action = event->action; | |
5628 | mutex_unlock(&event->vif_event_lock); | |
5629 | return evt_action == action; | |
5630 | } | |
5631 | ||
5632 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, | |
5633 | struct brcmf_cfg80211_vif *vif) | |
5634 | { | |
5635 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
5636 | ||
5637 | mutex_lock(&event->vif_event_lock); | |
5638 | event->vif = vif; | |
5639 | event->action = 0; | |
5640 | mutex_unlock(&event->vif_event_lock); | |
5641 | } | |
5642 | ||
5643 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) | |
5644 | { | |
5645 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
5646 | bool armed; | |
5647 | ||
5648 | mutex_lock(&event->vif_event_lock); | |
5649 | armed = event->vif != NULL; | |
5650 | mutex_unlock(&event->vif_event_lock); | |
5651 | ||
5652 | return armed; | |
5653 | } | |
5654 | int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg, | |
5655 | u8 action, ulong timeout) | |
5656 | { | |
5657 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
5658 | ||
5659 | return wait_event_timeout(event->vif_wq, | |
5660 | vif_event_equals(event, action), timeout); | |
5661 | } | |
5662 | ||
b48d8916 AS |
5663 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
5664 | { | |
5665 | kfree(wiphy->iface_combinations); | |
5666 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { | |
5667 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels); | |
5668 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]); | |
5669 | } | |
5670 | if (wiphy->bands[IEEE80211_BAND_5GHZ]) { | |
5671 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels); | |
5672 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]); | |
5673 | } | |
5674 | wiphy_free(wiphy); | |
5675 | } | |
5676 | ||
ccfd1e81 AS |
5677 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
5678 | struct device *busdev) | |
5679 | { | |
5680 | struct net_device *ndev = drvr->iflist[0]->ndev; | |
5681 | struct brcmf_cfg80211_info *cfg; | |
5682 | struct wiphy *wiphy; | |
5683 | struct brcmf_cfg80211_vif *vif; | |
5684 | struct brcmf_if *ifp; | |
5685 | s32 err = 0; | |
5686 | s32 io_type; | |
b48d8916 | 5687 | u16 *cap = NULL; |
ccfd1e81 AS |
5688 | |
5689 | if (!ndev) { | |
5690 | brcmf_err("ndev is invalid\n"); | |
5691 | return NULL; | |
5692 | } | |
5693 | ||
5694 | ifp = netdev_priv(ndev); | |
b48d8916 AS |
5695 | wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info)); |
5696 | if (!wiphy) { | |
5697 | brcmf_err("Could not allocate wiphy device\n"); | |
ccfd1e81 | 5698 | return NULL; |
b48d8916 AS |
5699 | } |
5700 | set_wiphy_dev(wiphy, busdev); | |
ccfd1e81 AS |
5701 | |
5702 | cfg = wiphy_priv(wiphy); | |
5703 | cfg->wiphy = wiphy; | |
5704 | cfg->pub = drvr; | |
5705 | init_vif_event(&cfg->vif_event); | |
5706 | INIT_LIST_HEAD(&cfg->vif_list); | |
5707 | ||
5708 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false); | |
b48d8916 AS |
5709 | if (IS_ERR(vif)) |
5710 | goto wiphy_out; | |
ccfd1e81 AS |
5711 | |
5712 | vif->ifp = ifp; | |
5713 | vif->wdev.netdev = ndev; | |
5714 | ndev->ieee80211_ptr = &vif->wdev; | |
5715 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); | |
5716 | ||
5717 | err = wl_init_priv(cfg); | |
5718 | if (err) { | |
5719 | brcmf_err("Failed to init iwm_priv (%d)\n", err); | |
b48d8916 AS |
5720 | brcmf_free_vif(vif); |
5721 | goto wiphy_out; | |
ccfd1e81 AS |
5722 | } |
5723 | ifp->vif = vif; | |
5724 | ||
b48d8916 AS |
5725 | /* determine d11 io type before wiphy setup */ |
5726 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type); | |
ccfd1e81 | 5727 | if (err) { |
b48d8916 AS |
5728 | brcmf_err("Failed to get D11 version (%d)\n", err); |
5729 | goto priv_out; | |
ccfd1e81 | 5730 | } |
b48d8916 AS |
5731 | cfg->d11inf.io_type = (u8)io_type; |
5732 | brcmu_d11_attach(&cfg->d11inf); | |
5733 | ||
5734 | err = brcmf_setup_wiphy(wiphy, ifp); | |
5735 | if (err < 0) | |
5736 | goto priv_out; | |
5737 | ||
5738 | brcmf_dbg(INFO, "Registering custom regulatory\n"); | |
5739 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; | |
5740 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); | |
5741 | ||
5742 | /* firmware defaults to 40MHz disabled in 2G band. We signal | |
5743 | * cfg80211 here that we do and have it decide we can enable | |
5744 | * it. But first check if device does support 2G operation. | |
5745 | */ | |
5746 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { | |
5747 | cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap; | |
5748 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
5749 | } | |
5750 | err = wiphy_register(wiphy); | |
5751 | if (err < 0) { | |
5752 | brcmf_err("Could not register wiphy device (%d)\n", err); | |
5753 | goto priv_out; | |
ccfd1e81 AS |
5754 | } |
5755 | ||
5756 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), | |
5757 | * setup 40MHz in 2GHz band and enable OBSS scanning. | |
5758 | */ | |
b48d8916 AS |
5759 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
5760 | err = brcmf_enable_bw40_2g(cfg); | |
ccfd1e81 AS |
5761 | if (!err) |
5762 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", | |
5763 | BRCMF_OBSS_COEX_AUTO); | |
b48d8916 AS |
5764 | else |
5765 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
ccfd1e81 | 5766 | } |
ccfd1e81 | 5767 | |
b48d8916 | 5768 | err = brcmf_p2p_attach(cfg); |
ccfd1e81 | 5769 | if (err) { |
b48d8916 AS |
5770 | brcmf_err("P2P initilisation failed (%d)\n", err); |
5771 | goto wiphy_unreg_out; | |
5772 | } | |
5773 | err = brcmf_btcoex_attach(cfg); | |
5774 | if (err) { | |
5775 | brcmf_err("BT-coex initialisation failed (%d)\n", err); | |
5776 | brcmf_p2p_detach(&cfg->p2p); | |
5777 | goto wiphy_unreg_out; | |
ccfd1e81 AS |
5778 | } |
5779 | ||
b48d8916 | 5780 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
ccfd1e81 | 5781 | if (err) { |
b48d8916 AS |
5782 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
5783 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; | |
70b7d94b HM |
5784 | } else { |
5785 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, | |
5786 | brcmf_notify_tdls_peer_event); | |
ccfd1e81 | 5787 | } |
ccfd1e81 AS |
5788 | |
5789 | return cfg; | |
5790 | ||
b48d8916 AS |
5791 | wiphy_unreg_out: |
5792 | wiphy_unregister(cfg->wiphy); | |
5793 | priv_out: | |
ccfd1e81 | 5794 | wl_deinit_priv(cfg); |
ccfd1e81 | 5795 | brcmf_free_vif(vif); |
b48d8916 AS |
5796 | wiphy_out: |
5797 | brcmf_free_wiphy(wiphy); | |
ccfd1e81 AS |
5798 | return NULL; |
5799 | } | |
5800 | ||
5801 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) | |
5802 | { | |
5803 | if (!cfg) | |
5804 | return; | |
5805 | ||
5806 | WARN_ON(!list_empty(&cfg->vif_list)); | |
5807 | wiphy_unregister(cfg->wiphy); | |
5808 | brcmf_btcoex_detach(cfg); | |
c3da74bb | 5809 | brcmf_p2p_detach(&cfg->p2p); |
ccfd1e81 | 5810 | wl_deinit_priv(cfg); |
b48d8916 | 5811 | brcmf_free_wiphy(cfg->wiphy); |
ccfd1e81 | 5812 | } |