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" | |
a8e8ed34 | 30 | #include "debug.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" |
d14f78b9 | 40 | #include "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 | ||
b9a82f89 HM |
2782 | static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4], |
2783 | u8 *pattern, u32 patternsize, u8 *mask, | |
2784 | u32 packet_offset) | |
2785 | { | |
2786 | struct brcmf_fil_wowl_pattern_le *filter; | |
2787 | u32 masksize; | |
2788 | u32 patternoffset; | |
2789 | u8 *buf; | |
2790 | u32 bufsize; | |
2791 | s32 ret; | |
2792 | ||
2793 | masksize = (patternsize + 7) / 8; | |
2794 | patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize; | |
2795 | ||
2796 | bufsize = sizeof(*filter) + patternsize + masksize; | |
2797 | buf = kzalloc(bufsize, GFP_KERNEL); | |
2798 | if (!buf) | |
2799 | return -ENOMEM; | |
2800 | filter = (struct brcmf_fil_wowl_pattern_le *)buf; | |
2801 | ||
2802 | memcpy(filter->cmd, cmd, 4); | |
2803 | filter->masksize = cpu_to_le32(masksize); | |
2804 | filter->offset = cpu_to_le32(packet_offset); | |
2805 | filter->patternoffset = cpu_to_le32(patternoffset); | |
2806 | filter->patternsize = cpu_to_le32(patternsize); | |
2807 | filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP); | |
2808 | ||
2809 | if ((mask) && (masksize)) | |
2810 | memcpy(buf + sizeof(*filter), mask, masksize); | |
2811 | if ((pattern) && (patternsize)) | |
2812 | memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize); | |
2813 | ||
2814 | ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize); | |
2815 | ||
2816 | kfree(buf); | |
2817 | return ret; | |
2818 | } | |
2819 | ||
5b435de0 AS |
2820 | static s32 brcmf_cfg80211_resume(struct wiphy *wiphy) |
2821 | { | |
4eb3af7c HM |
2822 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
2823 | struct net_device *ndev = cfg_to_ndev(cfg); | |
2824 | struct brcmf_if *ifp = netdev_priv(ndev); | |
2825 | ||
d96b801f | 2826 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 2827 | |
4eb3af7c | 2828 | if (cfg->wowl_enabled) { |
b9a82f89 | 2829 | brcmf_configure_arp_offload(ifp, true); |
4eb3af7c HM |
2830 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, |
2831 | cfg->pre_wowl_pmmode); | |
4eb3af7c | 2832 | brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0); |
b9a82f89 | 2833 | brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0); |
4eb3af7c HM |
2834 | cfg->wowl_enabled = false; |
2835 | } | |
5b435de0 AS |
2836 | return 0; |
2837 | } | |
2838 | ||
4eb3af7c HM |
2839 | static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg, |
2840 | struct brcmf_if *ifp, | |
2841 | struct cfg80211_wowlan *wowl) | |
2842 | { | |
2843 | u32 wowl_config; | |
b9a82f89 | 2844 | u32 i; |
4eb3af7c HM |
2845 | |
2846 | brcmf_dbg(TRACE, "Suspend, wowl config.\n"); | |
2847 | ||
b9a82f89 | 2848 | brcmf_configure_arp_offload(ifp, false); |
4eb3af7c HM |
2849 | brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode); |
2850 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX); | |
2851 | ||
2852 | wowl_config = 0; | |
2853 | if (wowl->disconnect) | |
b9a82f89 | 2854 | wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR; |
4eb3af7c | 2855 | if (wowl->magic_pkt) |
b9a82f89 HM |
2856 | wowl_config |= BRCMF_WOWL_MAGIC; |
2857 | if ((wowl->patterns) && (wowl->n_patterns)) { | |
2858 | wowl_config |= BRCMF_WOWL_NET; | |
2859 | for (i = 0; i < wowl->n_patterns; i++) { | |
2860 | brcmf_config_wowl_pattern(ifp, "add", | |
2861 | (u8 *)wowl->patterns[i].pattern, | |
2862 | wowl->patterns[i].pattern_len, | |
2863 | (u8 *)wowl->patterns[i].mask, | |
2864 | wowl->patterns[i].pkt_offset); | |
2865 | } | |
2866 | } | |
4eb3af7c HM |
2867 | brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config); |
2868 | brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1); | |
2869 | brcmf_bus_wowl_config(cfg->pub->bus_if, true); | |
2870 | cfg->wowl_enabled = true; | |
2871 | } | |
2872 | ||
5b435de0 | 2873 | static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy, |
4eb3af7c | 2874 | struct cfg80211_wowlan *wowl) |
5b435de0 | 2875 | { |
27a68fe3 AS |
2876 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
2877 | struct net_device *ndev = cfg_to_ndev(cfg); | |
4eb3af7c | 2878 | struct brcmf_if *ifp = netdev_priv(ndev); |
7d641072 | 2879 | struct brcmf_cfg80211_vif *vif; |
5b435de0 | 2880 | |
d96b801f | 2881 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 2882 | |
4eb3af7c | 2883 | /* if the primary net_device is not READY there is nothing |
7d641072 | 2884 | * we can do but pray resume goes smoothly. |
5b435de0 | 2885 | */ |
4eb3af7c | 2886 | if (!check_vif_up(ifp->vif)) |
7d641072 | 2887 | goto exit; |
5b435de0 | 2888 | |
7d641072 AS |
2889 | /* end any scanning */ |
2890 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) | |
27a68fe3 | 2891 | brcmf_abort_scanning(cfg); |
5b435de0 | 2892 | |
4eb3af7c HM |
2893 | if (wowl == NULL) { |
2894 | brcmf_bus_wowl_config(cfg->pub->bus_if, false); | |
2895 | list_for_each_entry(vif, &cfg->vif_list, list) { | |
2896 | if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) | |
2897 | continue; | |
2898 | /* While going to suspend if associated with AP | |
2899 | * disassociate from AP to save power while system is | |
2900 | * in suspended state | |
2901 | */ | |
2902 | brcmf_link_down(vif); | |
2903 | /* Make sure WPA_Supplicant receives all the event | |
2904 | * generated due to DISASSOC call to the fw to keep | |
2905 | * the state fw and WPA_Supplicant state consistent | |
2906 | */ | |
2907 | brcmf_delay(500); | |
2908 | } | |
2909 | /* Configure MPC */ | |
2910 | brcmf_set_mpc(ifp, 1); | |
2911 | ||
2912 | } else { | |
2913 | /* Configure WOWL paramaters */ | |
2914 | brcmf_configure_wowl(cfg, ifp, wowl); | |
2915 | } | |
5b435de0 | 2916 | |
7d641072 | 2917 | exit: |
d96b801f | 2918 | brcmf_dbg(TRACE, "Exit\n"); |
7d641072 AS |
2919 | /* clear any scanning activity */ |
2920 | cfg->scan_status = 0; | |
5b435de0 AS |
2921 | return 0; |
2922 | } | |
2923 | ||
5b435de0 AS |
2924 | static __used s32 |
2925 | brcmf_update_pmklist(struct net_device *ndev, | |
2926 | struct brcmf_cfg80211_pmk_list *pmk_list, s32 err) | |
2927 | { | |
2928 | int i, j; | |
40c8e95a | 2929 | int pmkid_len; |
5b435de0 | 2930 | |
40c8e95a AS |
2931 | pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid); |
2932 | ||
16886735 | 2933 | brcmf_dbg(CONN, "No of elements %d\n", pmkid_len); |
40c8e95a | 2934 | for (i = 0; i < pmkid_len; i++) { |
16886735 AS |
2935 | brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i, |
2936 | &pmk_list->pmkids.pmkid[i].BSSID); | |
5b435de0 | 2937 | for (j = 0; j < WLAN_PMKID_LEN; j++) |
16886735 AS |
2938 | brcmf_dbg(CONN, "%02x\n", |
2939 | pmk_list->pmkids.pmkid[i].PMKID[j]); | |
5b435de0 AS |
2940 | } |
2941 | ||
2942 | if (!err) | |
ac24be6f AS |
2943 | brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info", |
2944 | (char *)pmk_list, sizeof(*pmk_list)); | |
5b435de0 AS |
2945 | |
2946 | return err; | |
2947 | } | |
2948 | ||
2949 | static s32 | |
2950 | brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev, | |
2951 | struct cfg80211_pmksa *pmksa) | |
2952 | { | |
27a68fe3 | 2953 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 2954 | struct brcmf_if *ifp = netdev_priv(ndev); |
27a68fe3 | 2955 | struct pmkid_list *pmkids = &cfg->pmk_list->pmkids; |
5b435de0 AS |
2956 | s32 err = 0; |
2957 | int i; | |
40c8e95a | 2958 | int pmkid_len; |
5b435de0 | 2959 | |
d96b801f | 2960 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 2961 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
2962 | return -EIO; |
2963 | ||
40c8e95a AS |
2964 | pmkid_len = le32_to_cpu(pmkids->npmkid); |
2965 | for (i = 0; i < pmkid_len; i++) | |
5b435de0 AS |
2966 | if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN)) |
2967 | break; | |
2968 | if (i < WL_NUM_PMKIDS_MAX) { | |
2969 | memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN); | |
2970 | memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); | |
40c8e95a AS |
2971 | if (i == pmkid_len) { |
2972 | pmkid_len++; | |
2973 | pmkids->npmkid = cpu_to_le32(pmkid_len); | |
2974 | } | |
5b435de0 AS |
2975 | } else |
2976 | err = -EINVAL; | |
2977 | ||
16886735 AS |
2978 | brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n", |
2979 | pmkids->pmkid[pmkid_len].BSSID); | |
5b435de0 | 2980 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
16886735 | 2981 | brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]); |
5b435de0 | 2982 | |
27a68fe3 | 2983 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
5b435de0 | 2984 | |
d96b801f | 2985 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
2986 | return err; |
2987 | } | |
2988 | ||
2989 | static s32 | |
2990 | brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev, | |
2991 | struct cfg80211_pmksa *pmksa) | |
2992 | { | |
27a68fe3 | 2993 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 2994 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
2995 | struct pmkid_list pmkid; |
2996 | s32 err = 0; | |
40c8e95a | 2997 | int i, pmkid_len; |
5b435de0 | 2998 | |
d96b801f | 2999 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 3000 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
3001 | return -EIO; |
3002 | ||
3003 | memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN); | |
3004 | memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN); | |
3005 | ||
16886735 AS |
3006 | brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n", |
3007 | &pmkid.pmkid[0].BSSID); | |
5b435de0 | 3008 | for (i = 0; i < WLAN_PMKID_LEN; i++) |
16886735 | 3009 | brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]); |
5b435de0 | 3010 | |
27a68fe3 | 3011 | pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid); |
40c8e95a | 3012 | for (i = 0; i < pmkid_len; i++) |
5b435de0 | 3013 | if (!memcmp |
27a68fe3 | 3014 | (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID, |
5b435de0 AS |
3015 | ETH_ALEN)) |
3016 | break; | |
3017 | ||
40c8e95a AS |
3018 | if ((pmkid_len > 0) |
3019 | && (i < pmkid_len)) { | |
27a68fe3 | 3020 | memset(&cfg->pmk_list->pmkids.pmkid[i], 0, |
5b435de0 | 3021 | sizeof(struct pmkid)); |
40c8e95a | 3022 | for (; i < (pmkid_len - 1); i++) { |
27a68fe3 AS |
3023 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID, |
3024 | &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID, | |
5b435de0 | 3025 | ETH_ALEN); |
27a68fe3 AS |
3026 | memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID, |
3027 | &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID, | |
5b435de0 AS |
3028 | WLAN_PMKID_LEN); |
3029 | } | |
27a68fe3 | 3030 | cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1); |
5b435de0 AS |
3031 | } else |
3032 | err = -EINVAL; | |
3033 | ||
27a68fe3 | 3034 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); |
5b435de0 | 3035 | |
d96b801f | 3036 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
3037 | return err; |
3038 | ||
3039 | } | |
3040 | ||
3041 | static s32 | |
3042 | brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev) | |
3043 | { | |
27a68fe3 | 3044 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
0abb5f21 | 3045 | struct brcmf_if *ifp = netdev_priv(ndev); |
5b435de0 AS |
3046 | s32 err = 0; |
3047 | ||
d96b801f | 3048 | brcmf_dbg(TRACE, "Enter\n"); |
ce81e317 | 3049 | if (!check_vif_up(ifp->vif)) |
5b435de0 AS |
3050 | return -EIO; |
3051 | ||
27a68fe3 AS |
3052 | memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list)); |
3053 | err = brcmf_update_pmklist(ndev, cfg->pmk_list, err); | |
5b435de0 | 3054 | |
d96b801f | 3055 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
3056 | return err; |
3057 | ||
3058 | } | |
3059 | ||
e5806072 AS |
3060 | /* |
3061 | * PFN result doesn't have all the info which are | |
3062 | * required by the supplicant | |
3063 | * (For e.g IEs) Do a target Escan so that sched scan results are reported | |
3064 | * via wl_inform_single_bss in the required format. Escan does require the | |
3065 | * scan request in the form of cfg80211_scan_request. For timebeing, create | |
3066 | * cfg80211_scan_request one out of the received PNO event. | |
3067 | */ | |
3068 | static s32 | |
1993732e | 3069 | brcmf_notify_sched_scan_results(struct brcmf_if *ifp, |
e5806072 AS |
3070 | const struct brcmf_event_msg *e, void *data) |
3071 | { | |
1993732e | 3072 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
e5806072 AS |
3073 | struct brcmf_pno_net_info_le *netinfo, *netinfo_start; |
3074 | struct cfg80211_scan_request *request = NULL; | |
3075 | struct cfg80211_ssid *ssid = NULL; | |
3076 | struct ieee80211_channel *channel = NULL; | |
27a68fe3 | 3077 | struct wiphy *wiphy = cfg_to_wiphy(cfg); |
e5806072 AS |
3078 | int err = 0; |
3079 | int channel_req = 0; | |
3080 | int band = 0; | |
3081 | struct brcmf_pno_scanresults_le *pfn_result; | |
3082 | u32 result_count; | |
3083 | u32 status; | |
3084 | ||
4e8a008e | 3085 | brcmf_dbg(SCAN, "Enter\n"); |
e5806072 | 3086 | |
5c36b99a | 3087 | if (e->event_code == BRCMF_E_PFN_NET_LOST) { |
4e8a008e | 3088 | brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n"); |
e5806072 AS |
3089 | return 0; |
3090 | } | |
3091 | ||
3092 | pfn_result = (struct brcmf_pno_scanresults_le *)data; | |
3093 | result_count = le32_to_cpu(pfn_result->count); | |
3094 | status = le32_to_cpu(pfn_result->status); | |
3095 | ||
3096 | /* | |
3097 | * PFN event is limited to fit 512 bytes so we may get | |
3098 | * multiple NET_FOUND events. For now place a warning here. | |
3099 | */ | |
3100 | WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE); | |
4e8a008e | 3101 | brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count); |
e5806072 AS |
3102 | if (result_count > 0) { |
3103 | int i; | |
3104 | ||
3105 | request = kzalloc(sizeof(*request), GFP_KERNEL); | |
58901d18 DC |
3106 | ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL); |
3107 | channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL); | |
e5806072 AS |
3108 | if (!request || !ssid || !channel) { |
3109 | err = -ENOMEM; | |
3110 | goto out_err; | |
3111 | } | |
3112 | ||
3113 | request->wiphy = wiphy; | |
3114 | data += sizeof(struct brcmf_pno_scanresults_le); | |
3115 | netinfo_start = (struct brcmf_pno_net_info_le *)data; | |
3116 | ||
3117 | for (i = 0; i < result_count; i++) { | |
3118 | netinfo = &netinfo_start[i]; | |
3119 | if (!netinfo) { | |
57d6e91a AS |
3120 | brcmf_err("Invalid netinfo ptr. index: %d\n", |
3121 | i); | |
e5806072 AS |
3122 | err = -EINVAL; |
3123 | goto out_err; | |
3124 | } | |
3125 | ||
4e8a008e AS |
3126 | brcmf_dbg(SCAN, "SSID:%s Channel:%d\n", |
3127 | netinfo->SSID, netinfo->channel); | |
e5806072 AS |
3128 | memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len); |
3129 | ssid[i].ssid_len = netinfo->SSID_len; | |
3130 | request->n_ssids++; | |
3131 | ||
3132 | channel_req = netinfo->channel; | |
3133 | if (channel_req <= CH_MAX_2G_CHANNEL) | |
3134 | band = NL80211_BAND_2GHZ; | |
3135 | else | |
3136 | band = NL80211_BAND_5GHZ; | |
3137 | channel[i].center_freq = | |
3138 | ieee80211_channel_to_frequency(channel_req, | |
3139 | band); | |
3140 | channel[i].band = band; | |
3141 | channel[i].flags |= IEEE80211_CHAN_NO_HT40; | |
3142 | request->channels[i] = &channel[i]; | |
3143 | request->n_channels++; | |
3144 | } | |
3145 | ||
3146 | /* assign parsed ssid array */ | |
3147 | if (request->n_ssids) | |
3148 | request->ssids = &ssid[0]; | |
3149 | ||
c1179033 | 3150 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
e5806072 | 3151 | /* Abort any on-going scan */ |
27a68fe3 | 3152 | brcmf_abort_scanning(cfg); |
e5806072 AS |
3153 | } |
3154 | ||
c1179033 | 3155 | set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
2668b0b1 | 3156 | cfg->escan_info.run = brcmf_run_escan; |
a0f472ac | 3157 | err = brcmf_do_escan(cfg, wiphy, ifp, request); |
e5806072 | 3158 | if (err) { |
c1179033 | 3159 | clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status); |
e5806072 AS |
3160 | goto out_err; |
3161 | } | |
27a68fe3 AS |
3162 | cfg->sched_escan = true; |
3163 | cfg->scan_request = request; | |
e5806072 | 3164 | } else { |
57d6e91a | 3165 | brcmf_err("FALSE PNO Event. (pfn_count == 0)\n"); |
e5806072 AS |
3166 | goto out_err; |
3167 | } | |
3168 | ||
3169 | kfree(ssid); | |
3170 | kfree(channel); | |
3171 | kfree(request); | |
3172 | return 0; | |
3173 | ||
3174 | out_err: | |
3175 | kfree(ssid); | |
3176 | kfree(channel); | |
3177 | kfree(request); | |
3178 | cfg80211_sched_scan_stopped(wiphy); | |
3179 | return err; | |
3180 | } | |
3181 | ||
e5806072 AS |
3182 | static int brcmf_dev_pno_clean(struct net_device *ndev) |
3183 | { | |
e5806072 AS |
3184 | int ret; |
3185 | ||
3186 | /* Disable pfn */ | |
ac24be6f | 3187 | ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0); |
e5806072 AS |
3188 | if (ret == 0) { |
3189 | /* clear pfn */ | |
ac24be6f AS |
3190 | ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear", |
3191 | NULL, 0); | |
e5806072 AS |
3192 | } |
3193 | if (ret < 0) | |
57d6e91a | 3194 | brcmf_err("failed code %d\n", ret); |
e5806072 AS |
3195 | |
3196 | return ret; | |
3197 | } | |
3198 | ||
3199 | static int brcmf_dev_pno_config(struct net_device *ndev) | |
3200 | { | |
3201 | struct brcmf_pno_param_le pfn_param; | |
e5806072 AS |
3202 | |
3203 | memset(&pfn_param, 0, sizeof(pfn_param)); | |
3204 | pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION); | |
3205 | ||
3206 | /* set extra pno params */ | |
3207 | pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT); | |
3208 | pfn_param.repeat = BRCMF_PNO_REPEAT; | |
3209 | pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX; | |
3210 | ||
3211 | /* set up pno scan fr */ | |
3212 | pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME); | |
3213 | ||
ac24be6f AS |
3214 | return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set", |
3215 | &pfn_param, sizeof(pfn_param)); | |
e5806072 AS |
3216 | } |
3217 | ||
3218 | static int | |
3219 | brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy, | |
3220 | struct net_device *ndev, | |
3221 | struct cfg80211_sched_scan_request *request) | |
3222 | { | |
c1179033 | 3223 | struct brcmf_if *ifp = netdev_priv(ndev); |
27a68fe3 | 3224 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
e5806072 AS |
3225 | struct brcmf_pno_net_param_le pfn; |
3226 | int i; | |
3227 | int ret = 0; | |
3228 | ||
dc7bdbf1 | 3229 | brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n", |
4e8a008e | 3230 | request->n_match_sets, request->n_ssids); |
c1179033 | 3231 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) { |
57d6e91a | 3232 | brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status); |
e5806072 AS |
3233 | return -EAGAIN; |
3234 | } | |
1687eee2 AS |
3235 | if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) { |
3236 | brcmf_err("Scanning suppressed: status (%lu)\n", | |
3237 | cfg->scan_status); | |
3238 | return -EAGAIN; | |
3239 | } | |
e5806072 | 3240 | |
dc7bdbf1 | 3241 | if (!request->n_ssids || !request->n_match_sets) { |
181f2d17 | 3242 | brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n", |
dc7bdbf1 | 3243 | request->n_ssids); |
e5806072 AS |
3244 | return -EINVAL; |
3245 | } | |
3246 | ||
3247 | if (request->n_ssids > 0) { | |
3248 | for (i = 0; i < request->n_ssids; i++) { | |
3249 | /* Active scan req for ssids */ | |
4e8a008e AS |
3250 | brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n", |
3251 | request->ssids[i].ssid); | |
e5806072 AS |
3252 | |
3253 | /* | |
3254 | * match_set ssids is a supert set of n_ssid list, | |
3255 | * so we need not add these set seperately. | |
3256 | */ | |
3257 | } | |
3258 | } | |
3259 | ||
3260 | if (request->n_match_sets > 0) { | |
3261 | /* clean up everything */ | |
3262 | ret = brcmf_dev_pno_clean(ndev); | |
3263 | if (ret < 0) { | |
57d6e91a | 3264 | brcmf_err("failed error=%d\n", ret); |
e5806072 AS |
3265 | return ret; |
3266 | } | |
3267 | ||
3268 | /* configure pno */ | |
3269 | ret = brcmf_dev_pno_config(ndev); | |
3270 | if (ret < 0) { | |
57d6e91a | 3271 | brcmf_err("PNO setup failed!! ret=%d\n", ret); |
e5806072 AS |
3272 | return -EINVAL; |
3273 | } | |
3274 | ||
3275 | /* configure each match set */ | |
3276 | for (i = 0; i < request->n_match_sets; i++) { | |
3277 | struct cfg80211_ssid *ssid; | |
3278 | u32 ssid_len; | |
3279 | ||
3280 | ssid = &request->match_sets[i].ssid; | |
3281 | ssid_len = ssid->ssid_len; | |
3282 | ||
3283 | if (!ssid_len) { | |
57d6e91a | 3284 | brcmf_err("skip broadcast ssid\n"); |
e5806072 AS |
3285 | continue; |
3286 | } | |
3287 | pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN); | |
3288 | pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY); | |
3289 | pfn.wsec = cpu_to_le32(0); | |
3290 | pfn.infra = cpu_to_le32(1); | |
3291 | pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT); | |
3292 | pfn.ssid.SSID_len = cpu_to_le32(ssid_len); | |
3293 | memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len); | |
c1179033 | 3294 | ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn, |
ac24be6f | 3295 | sizeof(pfn)); |
4e8a008e AS |
3296 | brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n", |
3297 | ret == 0 ? "set" : "failed", ssid->ssid); | |
e5806072 AS |
3298 | } |
3299 | /* Enable the PNO */ | |
c1179033 | 3300 | if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) { |
57d6e91a | 3301 | brcmf_err("PNO enable failed!! ret=%d\n", ret); |
e5806072 AS |
3302 | return -EINVAL; |
3303 | } | |
3304 | } else { | |
3305 | return -EINVAL; | |
3306 | } | |
3307 | ||
3308 | return 0; | |
3309 | } | |
3310 | ||
3311 | static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy, | |
3312 | struct net_device *ndev) | |
3313 | { | |
27a68fe3 | 3314 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
e5806072 | 3315 | |
4e8a008e | 3316 | brcmf_dbg(SCAN, "enter\n"); |
e5806072 | 3317 | brcmf_dev_pno_clean(ndev); |
27a68fe3 | 3318 | if (cfg->sched_escan) |
a0f472ac | 3319 | brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true); |
e5806072 AS |
3320 | return 0; |
3321 | } | |
e5806072 | 3322 | |
1f170110 | 3323 | static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp) |
1a873342 HM |
3324 | { |
3325 | s32 err; | |
3326 | ||
3327 | /* set auth */ | |
ac24be6f | 3328 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0); |
1a873342 | 3329 | if (err < 0) { |
57d6e91a | 3330 | brcmf_err("auth error %d\n", err); |
1a873342 HM |
3331 | return err; |
3332 | } | |
3333 | /* set wsec */ | |
ac24be6f | 3334 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0); |
1a873342 | 3335 | if (err < 0) { |
57d6e91a | 3336 | brcmf_err("wsec error %d\n", err); |
1a873342 HM |
3337 | return err; |
3338 | } | |
3339 | /* set upper-layer auth */ | |
ac24be6f | 3340 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE); |
1a873342 | 3341 | if (err < 0) { |
57d6e91a | 3342 | brcmf_err("wpa_auth error %d\n", err); |
1a873342 HM |
3343 | return err; |
3344 | } | |
3345 | ||
3346 | return 0; | |
3347 | } | |
3348 | ||
3349 | static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie) | |
3350 | { | |
3351 | if (is_rsn_ie) | |
3352 | return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0); | |
3353 | ||
3354 | return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0); | |
3355 | } | |
3356 | ||
3357 | static s32 | |
4b5800fe JB |
3358 | brcmf_configure_wpaie(struct net_device *ndev, |
3359 | const struct brcmf_vs_tlv *wpa_ie, | |
3360 | bool is_rsn_ie) | |
1a873342 | 3361 | { |
ac24be6f | 3362 | struct brcmf_if *ifp = netdev_priv(ndev); |
1a873342 HM |
3363 | u32 auth = 0; /* d11 open authentication */ |
3364 | u16 count; | |
3365 | s32 err = 0; | |
3366 | s32 len = 0; | |
3367 | u32 i; | |
3368 | u32 wsec; | |
3369 | u32 pval = 0; | |
3370 | u32 gval = 0; | |
3371 | u32 wpa_auth = 0; | |
3372 | u32 offset; | |
3373 | u8 *data; | |
3374 | u16 rsn_cap; | |
3375 | u32 wme_bss_disable; | |
3376 | ||
d96b801f | 3377 | brcmf_dbg(TRACE, "Enter\n"); |
1a873342 HM |
3378 | if (wpa_ie == NULL) |
3379 | goto exit; | |
3380 | ||
3381 | len = wpa_ie->len + TLV_HDR_LEN; | |
3382 | data = (u8 *)wpa_ie; | |
619c5a9a | 3383 | offset = TLV_HDR_LEN; |
1a873342 HM |
3384 | if (!is_rsn_ie) |
3385 | offset += VS_IE_FIXED_HDR_LEN; | |
619c5a9a HM |
3386 | else |
3387 | offset += WPA_IE_VERSION_LEN; | |
1a873342 HM |
3388 | |
3389 | /* check for multicast cipher suite */ | |
3390 | if (offset + WPA_IE_MIN_OUI_LEN > len) { | |
3391 | err = -EINVAL; | |
57d6e91a | 3392 | brcmf_err("no multicast cipher suite\n"); |
1a873342 HM |
3393 | goto exit; |
3394 | } | |
3395 | ||
3396 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { | |
3397 | err = -EINVAL; | |
57d6e91a | 3398 | brcmf_err("ivalid OUI\n"); |
1a873342 HM |
3399 | goto exit; |
3400 | } | |
3401 | offset += TLV_OUI_LEN; | |
3402 | ||
3403 | /* pick up multicast cipher */ | |
3404 | switch (data[offset]) { | |
3405 | case WPA_CIPHER_NONE: | |
3406 | gval = 0; | |
3407 | break; | |
3408 | case WPA_CIPHER_WEP_40: | |
3409 | case WPA_CIPHER_WEP_104: | |
3410 | gval = WEP_ENABLED; | |
3411 | break; | |
3412 | case WPA_CIPHER_TKIP: | |
3413 | gval = TKIP_ENABLED; | |
3414 | break; | |
3415 | case WPA_CIPHER_AES_CCM: | |
3416 | gval = AES_ENABLED; | |
3417 | break; | |
3418 | default: | |
3419 | err = -EINVAL; | |
57d6e91a | 3420 | brcmf_err("Invalid multi cast cipher info\n"); |
1a873342 HM |
3421 | goto exit; |
3422 | } | |
3423 | ||
3424 | offset++; | |
3425 | /* walk thru unicast cipher list and pick up what we recognize */ | |
3426 | count = data[offset] + (data[offset + 1] << 8); | |
3427 | offset += WPA_IE_SUITE_COUNT_LEN; | |
3428 | /* Check for unicast suite(s) */ | |
3429 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { | |
3430 | err = -EINVAL; | |
57d6e91a | 3431 | brcmf_err("no unicast cipher suite\n"); |
1a873342 HM |
3432 | goto exit; |
3433 | } | |
3434 | for (i = 0; i < count; i++) { | |
3435 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { | |
3436 | err = -EINVAL; | |
57d6e91a | 3437 | brcmf_err("ivalid OUI\n"); |
1a873342 HM |
3438 | goto exit; |
3439 | } | |
3440 | offset += TLV_OUI_LEN; | |
3441 | switch (data[offset]) { | |
3442 | case WPA_CIPHER_NONE: | |
3443 | break; | |
3444 | case WPA_CIPHER_WEP_40: | |
3445 | case WPA_CIPHER_WEP_104: | |
3446 | pval |= WEP_ENABLED; | |
3447 | break; | |
3448 | case WPA_CIPHER_TKIP: | |
3449 | pval |= TKIP_ENABLED; | |
3450 | break; | |
3451 | case WPA_CIPHER_AES_CCM: | |
3452 | pval |= AES_ENABLED; | |
3453 | break; | |
3454 | default: | |
57d6e91a | 3455 | brcmf_err("Ivalid unicast security info\n"); |
1a873342 HM |
3456 | } |
3457 | offset++; | |
3458 | } | |
3459 | /* walk thru auth management suite list and pick up what we recognize */ | |
3460 | count = data[offset] + (data[offset + 1] << 8); | |
3461 | offset += WPA_IE_SUITE_COUNT_LEN; | |
3462 | /* Check for auth key management suite(s) */ | |
3463 | if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) { | |
3464 | err = -EINVAL; | |
57d6e91a | 3465 | brcmf_err("no auth key mgmt suite\n"); |
1a873342 HM |
3466 | goto exit; |
3467 | } | |
3468 | for (i = 0; i < count; i++) { | |
3469 | if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) { | |
3470 | err = -EINVAL; | |
57d6e91a | 3471 | brcmf_err("ivalid OUI\n"); |
1a873342 HM |
3472 | goto exit; |
3473 | } | |
3474 | offset += TLV_OUI_LEN; | |
3475 | switch (data[offset]) { | |
3476 | case RSN_AKM_NONE: | |
d96b801f | 3477 | brcmf_dbg(TRACE, "RSN_AKM_NONE\n"); |
1a873342 HM |
3478 | wpa_auth |= WPA_AUTH_NONE; |
3479 | break; | |
3480 | case RSN_AKM_UNSPECIFIED: | |
d96b801f | 3481 | brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n"); |
1a873342 HM |
3482 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) : |
3483 | (wpa_auth |= WPA_AUTH_UNSPECIFIED); | |
3484 | break; | |
3485 | case RSN_AKM_PSK: | |
d96b801f | 3486 | brcmf_dbg(TRACE, "RSN_AKM_PSK\n"); |
1a873342 HM |
3487 | is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) : |
3488 | (wpa_auth |= WPA_AUTH_PSK); | |
3489 | break; | |
3490 | default: | |
57d6e91a | 3491 | brcmf_err("Ivalid key mgmt info\n"); |
1a873342 HM |
3492 | } |
3493 | offset++; | |
3494 | } | |
3495 | ||
3496 | if (is_rsn_ie) { | |
3497 | wme_bss_disable = 1; | |
3498 | if ((offset + RSN_CAP_LEN) <= len) { | |
3499 | rsn_cap = data[offset] + (data[offset + 1] << 8); | |
3500 | if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK) | |
3501 | wme_bss_disable = 0; | |
3502 | } | |
3503 | /* set wme_bss_disable to sync RSN Capabilities */ | |
ac24be6f | 3504 | err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable", |
81f5dcb8 | 3505 | wme_bss_disable); |
1a873342 | 3506 | if (err < 0) { |
57d6e91a | 3507 | brcmf_err("wme_bss_disable error %d\n", err); |
1a873342 HM |
3508 | goto exit; |
3509 | } | |
3510 | } | |
3511 | /* FOR WPS , set SES_OW_ENABLED */ | |
3512 | wsec = (pval | gval | SES_OW_ENABLED); | |
3513 | ||
3514 | /* set auth */ | |
ac24be6f | 3515 | err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth); |
1a873342 | 3516 | if (err < 0) { |
57d6e91a | 3517 | brcmf_err("auth error %d\n", err); |
1a873342 HM |
3518 | goto exit; |
3519 | } | |
3520 | /* set wsec */ | |
ac24be6f | 3521 | err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec); |
1a873342 | 3522 | if (err < 0) { |
57d6e91a | 3523 | brcmf_err("wsec error %d\n", err); |
1a873342 HM |
3524 | goto exit; |
3525 | } | |
3526 | /* set upper-layer auth */ | |
ac24be6f | 3527 | err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth); |
1a873342 | 3528 | if (err < 0) { |
57d6e91a | 3529 | brcmf_err("wpa_auth error %d\n", err); |
1a873342 HM |
3530 | goto exit; |
3531 | } | |
3532 | ||
3533 | exit: | |
3534 | return err; | |
3535 | } | |
3536 | ||
3537 | static s32 | |
3082b9be | 3538 | brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len, |
1a873342 HM |
3539 | struct parsed_vndr_ies *vndr_ies) |
3540 | { | |
1a873342 HM |
3541 | struct brcmf_vs_tlv *vndrie; |
3542 | struct brcmf_tlv *ie; | |
3543 | struct parsed_vndr_ie_info *parsed_info; | |
3544 | s32 remaining_len; | |
3545 | ||
3546 | remaining_len = (s32)vndr_ie_len; | |
3547 | memset(vndr_ies, 0, sizeof(*vndr_ies)); | |
3548 | ||
3549 | ie = (struct brcmf_tlv *)vndr_ie_buf; | |
3550 | while (ie) { | |
3551 | if (ie->id != WLAN_EID_VENDOR_SPECIFIC) | |
3552 | goto next; | |
3553 | vndrie = (struct brcmf_vs_tlv *)ie; | |
3554 | /* len should be bigger than OUI length + one */ | |
3555 | if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) { | |
57d6e91a AS |
3556 | brcmf_err("invalid vndr ie. length is too small %d\n", |
3557 | vndrie->len); | |
1a873342 HM |
3558 | goto next; |
3559 | } | |
3560 | /* if wpa or wme ie, do not add ie */ | |
3561 | if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) && | |
3562 | ((vndrie->oui_type == WPA_OUI_TYPE) || | |
3563 | (vndrie->oui_type == WME_OUI_TYPE))) { | |
d96b801f | 3564 | brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n"); |
1a873342 HM |
3565 | goto next; |
3566 | } | |
3567 | ||
3568 | parsed_info = &vndr_ies->ie_info[vndr_ies->count]; | |
3569 | ||
3570 | /* save vndr ie information */ | |
3571 | parsed_info->ie_ptr = (char *)vndrie; | |
3572 | parsed_info->ie_len = vndrie->len + TLV_HDR_LEN; | |
3573 | memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie)); | |
3574 | ||
3575 | vndr_ies->count++; | |
3576 | ||
d96b801f AS |
3577 | brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n", |
3578 | parsed_info->vndrie.oui[0], | |
3579 | parsed_info->vndrie.oui[1], | |
3580 | parsed_info->vndrie.oui[2], | |
3581 | parsed_info->vndrie.oui_type); | |
1a873342 | 3582 | |
9f440b7b | 3583 | if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT) |
1a873342 HM |
3584 | break; |
3585 | next: | |
b41fc3d7 HM |
3586 | remaining_len -= (ie->len + TLV_HDR_LEN); |
3587 | if (remaining_len <= TLV_HDR_LEN) | |
1a873342 HM |
3588 | ie = NULL; |
3589 | else | |
b41fc3d7 HM |
3590 | ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len + |
3591 | TLV_HDR_LEN); | |
1a873342 | 3592 | } |
12f32370 | 3593 | return 0; |
1a873342 HM |
3594 | } |
3595 | ||
3596 | static u32 | |
3597 | brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd) | |
3598 | { | |
3599 | ||
3600 | __le32 iecount_le; | |
3601 | __le32 pktflag_le; | |
3602 | ||
3603 | strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1); | |
3604 | iebuf[VNDR_IE_CMD_LEN - 1] = '\0'; | |
3605 | ||
3606 | iecount_le = cpu_to_le32(1); | |
3607 | memcpy(&iebuf[VNDR_IE_COUNT_OFFSET], &iecount_le, sizeof(iecount_le)); | |
3608 | ||
3609 | pktflag_le = cpu_to_le32(pktflag); | |
3610 | memcpy(&iebuf[VNDR_IE_PKTFLAG_OFFSET], &pktflag_le, sizeof(pktflag_le)); | |
3611 | ||
3612 | memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len); | |
3613 | ||
3614 | return ie_len + VNDR_IE_HDR_SIZE; | |
3615 | } | |
3616 | ||
1332e26e AS |
3617 | s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, |
3618 | const u8 *vndr_ie_buf, u32 vndr_ie_len) | |
1a873342 | 3619 | { |
1332e26e AS |
3620 | struct brcmf_if *ifp; |
3621 | struct vif_saved_ie *saved_ie; | |
1a873342 HM |
3622 | s32 err = 0; |
3623 | u8 *iovar_ie_buf; | |
3624 | u8 *curr_ie_buf; | |
3625 | u8 *mgmt_ie_buf = NULL; | |
3e4f319d | 3626 | int mgmt_ie_buf_len; |
81118d16 | 3627 | u32 *mgmt_ie_len; |
1a873342 HM |
3628 | u32 del_add_ie_buf_len = 0; |
3629 | u32 total_ie_buf_len = 0; | |
3630 | u32 parsed_ie_buf_len = 0; | |
3631 | struct parsed_vndr_ies old_vndr_ies; | |
3632 | struct parsed_vndr_ies new_vndr_ies; | |
3633 | struct parsed_vndr_ie_info *vndrie_info; | |
3634 | s32 i; | |
3635 | u8 *ptr; | |
3e4f319d | 3636 | int remained_buf_len; |
1a873342 | 3637 | |
1332e26e AS |
3638 | if (!vif) |
3639 | return -ENODEV; | |
3640 | ifp = vif->ifp; | |
3641 | saved_ie = &vif->saved_ie; | |
3642 | ||
d96b801f | 3643 | brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag); |
1a873342 HM |
3644 | iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
3645 | if (!iovar_ie_buf) | |
3646 | return -ENOMEM; | |
3647 | curr_ie_buf = iovar_ie_buf; | |
89286dc9 HM |
3648 | switch (pktflag) { |
3649 | case BRCMF_VNDR_IE_PRBREQ_FLAG: | |
3650 | mgmt_ie_buf = saved_ie->probe_req_ie; | |
3651 | mgmt_ie_len = &saved_ie->probe_req_ie_len; | |
3652 | mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie); | |
3653 | break; | |
3654 | case BRCMF_VNDR_IE_PRBRSP_FLAG: | |
3655 | mgmt_ie_buf = saved_ie->probe_res_ie; | |
3656 | mgmt_ie_len = &saved_ie->probe_res_ie_len; | |
3657 | mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie); | |
3658 | break; | |
3659 | case BRCMF_VNDR_IE_BEACON_FLAG: | |
3660 | mgmt_ie_buf = saved_ie->beacon_ie; | |
3661 | mgmt_ie_len = &saved_ie->beacon_ie_len; | |
3662 | mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie); | |
3663 | break; | |
3664 | case BRCMF_VNDR_IE_ASSOCREQ_FLAG: | |
3665 | mgmt_ie_buf = saved_ie->assoc_req_ie; | |
3666 | mgmt_ie_len = &saved_ie->assoc_req_ie_len; | |
3667 | mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie); | |
3668 | break; | |
3669 | default: | |
3670 | err = -EPERM; | |
3671 | brcmf_err("not suitable type\n"); | |
3672 | goto exit; | |
1a873342 HM |
3673 | } |
3674 | ||
3675 | if (vndr_ie_len > mgmt_ie_buf_len) { | |
3676 | err = -ENOMEM; | |
57d6e91a | 3677 | brcmf_err("extra IE size too big\n"); |
1a873342 HM |
3678 | goto exit; |
3679 | } | |
3680 | ||
3681 | /* parse and save new vndr_ie in curr_ie_buff before comparing it */ | |
3682 | if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) { | |
3683 | ptr = curr_ie_buf; | |
3684 | brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies); | |
3685 | for (i = 0; i < new_vndr_ies.count; i++) { | |
3686 | vndrie_info = &new_vndr_ies.ie_info[i]; | |
3687 | memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr, | |
3688 | vndrie_info->ie_len); | |
3689 | parsed_ie_buf_len += vndrie_info->ie_len; | |
3690 | } | |
3691 | } | |
3692 | ||
b41fc3d7 | 3693 | if (mgmt_ie_buf && *mgmt_ie_len) { |
1a873342 HM |
3694 | if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) && |
3695 | (memcmp(mgmt_ie_buf, curr_ie_buf, | |
3696 | parsed_ie_buf_len) == 0)) { | |
d96b801f | 3697 | brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n"); |
1a873342 HM |
3698 | goto exit; |
3699 | } | |
3700 | ||
3701 | /* parse old vndr_ie */ | |
3702 | brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies); | |
3703 | ||
3704 | /* make a command to delete old ie */ | |
3705 | for (i = 0; i < old_vndr_ies.count; i++) { | |
3706 | vndrie_info = &old_vndr_ies.ie_info[i]; | |
3707 | ||
d96b801f AS |
3708 | brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n", |
3709 | vndrie_info->vndrie.id, | |
3710 | vndrie_info->vndrie.len, | |
3711 | vndrie_info->vndrie.oui[0], | |
3712 | vndrie_info->vndrie.oui[1], | |
3713 | vndrie_info->vndrie.oui[2]); | |
1a873342 HM |
3714 | |
3715 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, | |
3716 | vndrie_info->ie_ptr, | |
3717 | vndrie_info->ie_len, | |
3718 | "del"); | |
3719 | curr_ie_buf += del_add_ie_buf_len; | |
3720 | total_ie_buf_len += del_add_ie_buf_len; | |
3721 | } | |
3722 | } | |
3723 | ||
3724 | *mgmt_ie_len = 0; | |
3725 | /* Add if there is any extra IE */ | |
3726 | if (mgmt_ie_buf && parsed_ie_buf_len) { | |
3727 | ptr = mgmt_ie_buf; | |
3728 | ||
3729 | remained_buf_len = mgmt_ie_buf_len; | |
3730 | ||
3731 | /* make a command to add new ie */ | |
3732 | for (i = 0; i < new_vndr_ies.count; i++) { | |
3733 | vndrie_info = &new_vndr_ies.ie_info[i]; | |
3734 | ||
b41fc3d7 HM |
3735 | /* verify remained buf size before copy data */ |
3736 | if (remained_buf_len < (vndrie_info->vndrie.len + | |
3737 | VNDR_IE_VSIE_OFFSET)) { | |
57d6e91a AS |
3738 | brcmf_err("no space in mgmt_ie_buf: len left %d", |
3739 | remained_buf_len); | |
b41fc3d7 HM |
3740 | break; |
3741 | } | |
3742 | remained_buf_len -= (vndrie_info->ie_len + | |
3743 | VNDR_IE_VSIE_OFFSET); | |
3744 | ||
d96b801f AS |
3745 | brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n", |
3746 | vndrie_info->vndrie.id, | |
3747 | vndrie_info->vndrie.len, | |
3748 | vndrie_info->vndrie.oui[0], | |
3749 | vndrie_info->vndrie.oui[1], | |
3750 | vndrie_info->vndrie.oui[2]); | |
1a873342 HM |
3751 | |
3752 | del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag, | |
3753 | vndrie_info->ie_ptr, | |
3754 | vndrie_info->ie_len, | |
3755 | "add"); | |
1a873342 HM |
3756 | |
3757 | /* save the parsed IE in wl struct */ | |
3758 | memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr, | |
3759 | vndrie_info->ie_len); | |
3760 | *mgmt_ie_len += vndrie_info->ie_len; | |
3761 | ||
3762 | curr_ie_buf += del_add_ie_buf_len; | |
3763 | total_ie_buf_len += del_add_ie_buf_len; | |
3764 | } | |
3765 | } | |
3766 | if (total_ie_buf_len) { | |
c1179033 | 3767 | err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf, |
81f5dcb8 | 3768 | total_ie_buf_len); |
1a873342 | 3769 | if (err) |
57d6e91a | 3770 | brcmf_err("vndr ie set error : %d\n", err); |
1a873342 HM |
3771 | } |
3772 | ||
3773 | exit: | |
3774 | kfree(iovar_ie_buf); | |
3775 | return err; | |
3776 | } | |
3777 | ||
5f4f9f11 AS |
3778 | s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif) |
3779 | { | |
3780 | s32 pktflags[] = { | |
3781 | BRCMF_VNDR_IE_PRBREQ_FLAG, | |
3782 | BRCMF_VNDR_IE_PRBRSP_FLAG, | |
3783 | BRCMF_VNDR_IE_BEACON_FLAG | |
3784 | }; | |
3785 | int i; | |
3786 | ||
3787 | for (i = 0; i < ARRAY_SIZE(pktflags); i++) | |
3788 | brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0); | |
3789 | ||
3790 | memset(&vif->saved_ie, 0, sizeof(vif->saved_ie)); | |
3791 | return 0; | |
3792 | } | |
3793 | ||
a0f07959 HM |
3794 | static s32 |
3795 | brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif, | |
3796 | struct cfg80211_beacon_data *beacon) | |
3797 | { | |
3798 | s32 err; | |
3799 | ||
3800 | /* Set Beacon IEs to FW */ | |
3801 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG, | |
3802 | beacon->tail, beacon->tail_len); | |
3803 | if (err) { | |
3804 | brcmf_err("Set Beacon IE Failed\n"); | |
3805 | return err; | |
3806 | } | |
3807 | brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n"); | |
3808 | ||
3809 | /* Set Probe Response IEs to FW */ | |
3810 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG, | |
3811 | beacon->proberesp_ies, | |
3812 | beacon->proberesp_ies_len); | |
3813 | if (err) | |
3814 | brcmf_err("Set Probe Resp IE Failed\n"); | |
3815 | else | |
3816 | brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n"); | |
3817 | ||
3818 | return err; | |
3819 | } | |
3820 | ||
1a873342 HM |
3821 | static s32 |
3822 | brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev, | |
3823 | struct cfg80211_ap_settings *settings) | |
3824 | { | |
3825 | s32 ie_offset; | |
1c9d30cf | 3826 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
ac24be6f | 3827 | struct brcmf_if *ifp = netdev_priv(ndev); |
4b5800fe | 3828 | const struct brcmf_tlv *ssid_ie; |
1a873342 | 3829 | struct brcmf_ssid_le ssid_le; |
1a873342 | 3830 | s32 err = -EPERM; |
4b5800fe JB |
3831 | const struct brcmf_tlv *rsn_ie; |
3832 | const struct brcmf_vs_tlv *wpa_ie; | |
1a873342 | 3833 | struct brcmf_join_params join_params; |
a0f07959 HM |
3834 | enum nl80211_iftype dev_role; |
3835 | struct brcmf_fil_bss_enable_le bss_enable; | |
06c01585 | 3836 | u16 chanspec; |
1a873342 | 3837 | |
06c01585 AS |
3838 | brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n", |
3839 | settings->chandef.chan->hw_value, | |
3840 | settings->chandef.center_freq1, settings->chandef.width, | |
a9a56878 | 3841 | settings->beacon_interval, settings->dtim_period); |
d96b801f AS |
3842 | brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n", |
3843 | settings->ssid, settings->ssid_len, settings->auth_type, | |
3844 | settings->inactivity_timeout); | |
1a873342 | 3845 | |
426d0a56 | 3846 | dev_role = ifp->vif->wdev.iftype; |
1a873342 HM |
3847 | |
3848 | memset(&ssid_le, 0, sizeof(ssid_le)); | |
3849 | if (settings->ssid == NULL || settings->ssid_len == 0) { | |
3850 | ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN; | |
3851 | ssid_ie = brcmf_parse_tlvs( | |
3852 | (u8 *)&settings->beacon.head[ie_offset], | |
3853 | settings->beacon.head_len - ie_offset, | |
3854 | WLAN_EID_SSID); | |
3855 | if (!ssid_ie) | |
3856 | return -EINVAL; | |
3857 | ||
3858 | memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len); | |
3859 | ssid_le.SSID_len = cpu_to_le32(ssid_ie->len); | |
d96b801f | 3860 | brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID); |
1a873342 HM |
3861 | } else { |
3862 | memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len); | |
3863 | ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len); | |
3864 | } | |
3865 | ||
f96aa07e | 3866 | brcmf_set_mpc(ifp, 0); |
b3657453 | 3867 | brcmf_configure_arp_offload(ifp, false); |
1a873342 HM |
3868 | |
3869 | /* find the RSN_IE */ | |
3870 | rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, | |
3871 | settings->beacon.tail_len, WLAN_EID_RSN); | |
3872 | ||
3873 | /* find the WPA_IE */ | |
3874 | wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail, | |
3875 | settings->beacon.tail_len); | |
3876 | ||
1a873342 | 3877 | if ((wpa_ie != NULL || rsn_ie != NULL)) { |
d96b801f | 3878 | brcmf_dbg(TRACE, "WPA(2) IE is found\n"); |
1a873342 HM |
3879 | if (wpa_ie != NULL) { |
3880 | /* WPA IE */ | |
34778529 | 3881 | err = brcmf_configure_wpaie(ndev, wpa_ie, false); |
1a873342 HM |
3882 | if (err < 0) |
3883 | goto exit; | |
1a873342 HM |
3884 | } else { |
3885 | /* RSN IE */ | |
3886 | err = brcmf_configure_wpaie(ndev, | |
34778529 | 3887 | (struct brcmf_vs_tlv *)rsn_ie, true); |
1a873342 HM |
3888 | if (err < 0) |
3889 | goto exit; | |
1a873342 | 3890 | } |
1a873342 | 3891 | } else { |
d96b801f | 3892 | brcmf_dbg(TRACE, "No WPA(2) IEs found\n"); |
1f170110 | 3893 | brcmf_configure_opensecurity(ifp); |
1a873342 | 3894 | } |
1a873342 | 3895 | |
a0f07959 | 3896 | brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon); |
1a873342 | 3897 | |
600a897d | 3898 | chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef); |
06c01585 | 3899 | err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec); |
1c9d30cf | 3900 | if (err < 0) { |
06c01585 | 3901 | brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec, err); |
1c9d30cf HM |
3902 | goto exit; |
3903 | } | |
3904 | ||
1a873342 | 3905 | if (settings->beacon_interval) { |
ac24be6f | 3906 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, |
81f5dcb8 | 3907 | settings->beacon_interval); |
1a873342 | 3908 | if (err < 0) { |
57d6e91a | 3909 | brcmf_err("Beacon Interval Set Error, %d\n", err); |
1a873342 HM |
3910 | goto exit; |
3911 | } | |
3912 | } | |
3913 | if (settings->dtim_period) { | |
ac24be6f | 3914 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD, |
81f5dcb8 | 3915 | settings->dtim_period); |
1a873342 | 3916 | if (err < 0) { |
57d6e91a | 3917 | brcmf_err("DTIM Interval Set Error, %d\n", err); |
1a873342 HM |
3918 | goto exit; |
3919 | } | |
3920 | } | |
a0f07959 HM |
3921 | |
3922 | if (dev_role == NL80211_IFTYPE_AP) { | |
3923 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); | |
3924 | if (err < 0) { | |
3925 | brcmf_err("BRCMF_C_DOWN error %d\n", err); | |
3926 | goto exit; | |
3927 | } | |
2880b868 | 3928 | brcmf_fil_iovar_int_set(ifp, "apsta", 0); |
1a873342 HM |
3929 | } |
3930 | ||
a0f07959 | 3931 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1); |
1a873342 | 3932 | if (err < 0) { |
a0f07959 | 3933 | brcmf_err("SET INFRA error %d\n", err); |
1a873342 HM |
3934 | goto exit; |
3935 | } | |
a0f07959 HM |
3936 | if (dev_role == NL80211_IFTYPE_AP) { |
3937 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1); | |
3938 | if (err < 0) { | |
3939 | brcmf_err("setting AP mode failed %d\n", err); | |
3940 | goto exit; | |
3941 | } | |
3942 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); | |
3943 | if (err < 0) { | |
3944 | brcmf_err("BRCMF_C_UP error (%d)\n", err); | |
3945 | goto exit; | |
3946 | } | |
3947 | ||
3948 | memset(&join_params, 0, sizeof(join_params)); | |
3949 | /* join parameters starts with ssid */ | |
3950 | memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le)); | |
3951 | /* create softap */ | |
3952 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, | |
3953 | &join_params, sizeof(join_params)); | |
3954 | if (err < 0) { | |
3955 | brcmf_err("SET SSID error (%d)\n", err); | |
3956 | goto exit; | |
3957 | } | |
3958 | brcmf_dbg(TRACE, "AP mode configuration complete\n"); | |
3959 | } else { | |
3960 | err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le, | |
3961 | sizeof(ssid_le)); | |
3962 | if (err < 0) { | |
3963 | brcmf_err("setting ssid failed %d\n", err); | |
3964 | goto exit; | |
3965 | } | |
3966 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); | |
3967 | bss_enable.enable = cpu_to_le32(1); | |
3968 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, | |
3969 | sizeof(bss_enable)); | |
3970 | if (err < 0) { | |
3971 | brcmf_err("bss_enable config failed %d\n", err); | |
3972 | goto exit; | |
3973 | } | |
3974 | ||
3975 | brcmf_dbg(TRACE, "GO mode configuration complete\n"); | |
3976 | } | |
c1179033 AS |
3977 | clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
3978 | set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); | |
1a873342 HM |
3979 | |
3980 | exit: | |
b3657453 | 3981 | if (err) { |
f96aa07e | 3982 | brcmf_set_mpc(ifp, 1); |
b3657453 HM |
3983 | brcmf_configure_arp_offload(ifp, true); |
3984 | } | |
1a873342 HM |
3985 | return err; |
3986 | } | |
3987 | ||
3988 | static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev) | |
3989 | { | |
c1179033 | 3990 | struct brcmf_if *ifp = netdev_priv(ndev); |
5c33a942 | 3991 | s32 err; |
426d0a56 | 3992 | struct brcmf_fil_bss_enable_le bss_enable; |
5c33a942 | 3993 | struct brcmf_join_params join_params; |
1a873342 | 3994 | |
d96b801f | 3995 | brcmf_dbg(TRACE, "Enter\n"); |
1a873342 | 3996 | |
426d0a56 | 3997 | if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) { |
1a873342 HM |
3998 | /* Due to most likely deauths outstanding we sleep */ |
3999 | /* first to make sure they get processed by fw. */ | |
4000 | msleep(400); | |
5c33a942 HM |
4001 | |
4002 | memset(&join_params, 0, sizeof(join_params)); | |
4003 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID, | |
4004 | &join_params, sizeof(join_params)); | |
4005 | if (err < 0) | |
4006 | brcmf_err("SET SSID error (%d)\n", err); | |
128ce3b6 | 4007 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); |
5c33a942 | 4008 | if (err < 0) |
57d6e91a | 4009 | brcmf_err("BRCMF_C_UP error %d\n", err); |
5c33a942 HM |
4010 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0); |
4011 | if (err < 0) | |
4012 | brcmf_err("setting AP mode failed %d\n", err); | |
4013 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0); | |
4014 | if (err < 0) | |
4015 | brcmf_err("setting INFRA mode failed %d\n", err); | |
426d0a56 HM |
4016 | } else { |
4017 | bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx); | |
4018 | bss_enable.enable = cpu_to_le32(0); | |
4019 | err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable, | |
4020 | sizeof(bss_enable)); | |
4021 | if (err < 0) | |
4022 | brcmf_err("bss_enable config failed %d\n", err); | |
1a873342 | 4023 | } |
f96aa07e | 4024 | brcmf_set_mpc(ifp, 1); |
b3657453 | 4025 | brcmf_configure_arp_offload(ifp, true); |
426d0a56 HM |
4026 | set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state); |
4027 | clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state); | |
4028 | ||
1a873342 HM |
4029 | return err; |
4030 | } | |
4031 | ||
a0f07959 HM |
4032 | static s32 |
4033 | brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev, | |
4034 | struct cfg80211_beacon_data *info) | |
4035 | { | |
a0f07959 HM |
4036 | struct brcmf_if *ifp = netdev_priv(ndev); |
4037 | s32 err; | |
4038 | ||
4039 | brcmf_dbg(TRACE, "Enter\n"); | |
4040 | ||
a0f07959 HM |
4041 | err = brcmf_config_ap_mgmt_ie(ifp->vif, info); |
4042 | ||
4043 | return err; | |
4044 | } | |
4045 | ||
1a873342 HM |
4046 | static int |
4047 | brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev, | |
3b3a0162 | 4048 | const u8 *mac) |
1a873342 | 4049 | { |
a0f07959 | 4050 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
1a873342 | 4051 | struct brcmf_scb_val_le scbval; |
0abb5f21 | 4052 | struct brcmf_if *ifp = netdev_priv(ndev); |
1a873342 HM |
4053 | s32 err; |
4054 | ||
4055 | if (!mac) | |
4056 | return -EFAULT; | |
4057 | ||
d96b801f | 4058 | brcmf_dbg(TRACE, "Enter %pM\n", mac); |
1a873342 | 4059 | |
a0f07959 HM |
4060 | if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
4061 | ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; | |
ce81e317 | 4062 | if (!check_vif_up(ifp->vif)) |
1a873342 HM |
4063 | return -EIO; |
4064 | ||
4065 | memcpy(&scbval.ea, mac, ETH_ALEN); | |
4066 | scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING); | |
0abb5f21 | 4067 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON, |
81f5dcb8 | 4068 | &scbval, sizeof(scbval)); |
1a873342 | 4069 | if (err) |
57d6e91a | 4070 | brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err); |
7ab6acd0 | 4071 | |
d96b801f | 4072 | brcmf_dbg(TRACE, "Exit\n"); |
1a873342 HM |
4073 | return err; |
4074 | } | |
4075 | ||
0de8aace HM |
4076 | |
4077 | static void | |
4078 | brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy, | |
4079 | struct wireless_dev *wdev, | |
4080 | u16 frame_type, bool reg) | |
4081 | { | |
7fa2e352 | 4082 | struct brcmf_cfg80211_vif *vif; |
0de8aace HM |
4083 | u16 mgmt_type; |
4084 | ||
4085 | brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg); | |
4086 | ||
4087 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; | |
7fa2e352 | 4088 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
0de8aace HM |
4089 | if (reg) |
4090 | vif->mgmt_rx_reg |= BIT(mgmt_type); | |
4091 | else | |
318a64ce | 4092 | vif->mgmt_rx_reg &= ~BIT(mgmt_type); |
0de8aace HM |
4093 | } |
4094 | ||
4095 | ||
4096 | static int | |
4097 | brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, | |
b176e629 | 4098 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
0de8aace HM |
4099 | { |
4100 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
b176e629 AO |
4101 | struct ieee80211_channel *chan = params->chan; |
4102 | const u8 *buf = params->buf; | |
4103 | size_t len = params->len; | |
0de8aace HM |
4104 | const struct ieee80211_mgmt *mgmt; |
4105 | struct brcmf_cfg80211_vif *vif; | |
4106 | s32 err = 0; | |
4107 | s32 ie_offset; | |
4108 | s32 ie_len; | |
18e2f61d HM |
4109 | struct brcmf_fil_action_frame_le *action_frame; |
4110 | struct brcmf_fil_af_params_le *af_params; | |
4111 | bool ack; | |
4112 | s32 chan_nr; | |
c2ff8cad | 4113 | u32 freq; |
0de8aace HM |
4114 | |
4115 | brcmf_dbg(TRACE, "Enter\n"); | |
4116 | ||
4117 | *cookie = 0; | |
4118 | ||
4119 | mgmt = (const struct ieee80211_mgmt *)buf; | |
4120 | ||
a0f07959 HM |
4121 | if (!ieee80211_is_mgmt(mgmt->frame_control)) { |
4122 | brcmf_err("Driver only allows MGMT packet type\n"); | |
4123 | return -EPERM; | |
4124 | } | |
0de8aace | 4125 | |
c2ff8cad AQ |
4126 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
4127 | ||
a0f07959 HM |
4128 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
4129 | /* Right now the only reason to get a probe response */ | |
4130 | /* is for p2p listen response or for p2p GO from */ | |
4131 | /* wpa_supplicant. Unfortunately the probe is send */ | |
4132 | /* on primary ndev, while dongle wants it on the p2p */ | |
4133 | /* vif. Since this is only reason for a probe */ | |
4134 | /* response to be sent, the vif is taken from cfg. */ | |
4135 | /* If ever desired to send proberesp for non p2p */ | |
4136 | /* response then data should be checked for */ | |
4137 | /* "DIRECT-". Note in future supplicant will take */ | |
4138 | /* dedicated p2p wdev to do this and then this 'hack'*/ | |
4139 | /* is not needed anymore. */ | |
4140 | ie_offset = DOT11_MGMT_HDR_LEN + | |
4141 | DOT11_BCN_PRB_FIXED_LEN; | |
4142 | ie_len = len - ie_offset; | |
a0f07959 | 4143 | if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) |
0de8aace | 4144 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
a0f07959 HM |
4145 | err = brcmf_vif_set_mgmt_ie(vif, |
4146 | BRCMF_VNDR_IE_PRBRSP_FLAG, | |
4147 | &buf[ie_offset], | |
4148 | ie_len); | |
4149 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, | |
4150 | GFP_KERNEL); | |
18e2f61d HM |
4151 | } else if (ieee80211_is_action(mgmt->frame_control)) { |
4152 | af_params = kzalloc(sizeof(*af_params), GFP_KERNEL); | |
4153 | if (af_params == NULL) { | |
4154 | brcmf_err("unable to allocate frame\n"); | |
4155 | err = -ENOMEM; | |
4156 | goto exit; | |
4157 | } | |
4158 | action_frame = &af_params->action_frame; | |
4159 | /* Add the packet Id */ | |
4160 | action_frame->packet_id = cpu_to_le32(*cookie); | |
4161 | /* Add BSSID */ | |
4162 | memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN); | |
4163 | memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN); | |
4164 | /* Add the length exepted for 802.11 header */ | |
4165 | action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN); | |
c2ff8cad AQ |
4166 | /* Add the channel. Use the one specified as parameter if any or |
4167 | * the current one (got from the firmware) otherwise | |
4168 | */ | |
4169 | if (chan) | |
4170 | freq = chan->center_freq; | |
4171 | else | |
4172 | brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL, | |
4173 | &freq); | |
4174 | chan_nr = ieee80211_frequency_to_channel(freq); | |
18e2f61d HM |
4175 | af_params->channel = cpu_to_le32(chan_nr); |
4176 | ||
4177 | memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN], | |
4178 | le16_to_cpu(action_frame->len)); | |
4179 | ||
4180 | brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n", | |
86a9c4a2 | 4181 | *cookie, le16_to_cpu(action_frame->len), freq); |
18e2f61d | 4182 | |
7fa2e352 | 4183 | ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg), |
18e2f61d HM |
4184 | af_params); |
4185 | ||
4186 | cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, | |
4187 | GFP_KERNEL); | |
4188 | kfree(af_params); | |
a0f07959 HM |
4189 | } else { |
4190 | brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control); | |
4191 | brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len); | |
0de8aace | 4192 | } |
a0f07959 | 4193 | |
18e2f61d | 4194 | exit: |
0de8aace HM |
4195 | return err; |
4196 | } | |
4197 | ||
4198 | ||
4199 | static int | |
4200 | brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, | |
4201 | struct wireless_dev *wdev, | |
4202 | u64 cookie) | |
4203 | { | |
4204 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
4205 | struct brcmf_cfg80211_vif *vif; | |
4206 | int err = 0; | |
4207 | ||
4208 | brcmf_dbg(TRACE, "Enter p2p listen cancel\n"); | |
4209 | ||
4210 | vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif; | |
4211 | if (vif == NULL) { | |
4212 | brcmf_err("No p2p device available for probe response\n"); | |
4213 | err = -ENODEV; | |
4214 | goto exit; | |
4215 | } | |
4216 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); | |
4217 | exit: | |
4218 | return err; | |
4219 | } | |
4220 | ||
61730d4d PH |
4221 | static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy, |
4222 | struct wireless_dev *wdev, | |
4223 | enum nl80211_crit_proto_id proto, | |
4224 | u16 duration) | |
4225 | { | |
4226 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
4227 | struct brcmf_cfg80211_vif *vif; | |
4228 | ||
4229 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); | |
4230 | ||
4231 | /* only DHCP support for now */ | |
4232 | if (proto != NL80211_CRIT_PROTO_DHCP) | |
4233 | return -EINVAL; | |
4234 | ||
4235 | /* suppress and abort scanning */ | |
4236 | set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); | |
4237 | brcmf_abort_scanning(cfg); | |
4238 | ||
4239 | return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration); | |
4240 | } | |
4241 | ||
4242 | static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy, | |
4243 | struct wireless_dev *wdev) | |
4244 | { | |
4245 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); | |
4246 | struct brcmf_cfg80211_vif *vif; | |
4247 | ||
4248 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); | |
4249 | ||
4250 | brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0); | |
4251 | clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status); | |
4252 | } | |
4253 | ||
70b7d94b HM |
4254 | static s32 |
4255 | brcmf_notify_tdls_peer_event(struct brcmf_if *ifp, | |
4256 | const struct brcmf_event_msg *e, void *data) | |
4257 | { | |
4258 | switch (e->reason) { | |
4259 | case BRCMF_E_REASON_TDLS_PEER_DISCOVERED: | |
4260 | brcmf_dbg(TRACE, "TDLS Peer Discovered\n"); | |
4261 | break; | |
4262 | case BRCMF_E_REASON_TDLS_PEER_CONNECTED: | |
4263 | brcmf_dbg(TRACE, "TDLS Peer Connected\n"); | |
4264 | brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); | |
4265 | break; | |
4266 | case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED: | |
4267 | brcmf_dbg(TRACE, "TDLS Peer Disconnected\n"); | |
4268 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); | |
4269 | break; | |
4270 | } | |
4271 | ||
4272 | return 0; | |
4273 | } | |
4274 | ||
89c2f382 AS |
4275 | static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper) |
4276 | { | |
4277 | int ret; | |
4278 | ||
4279 | switch (oper) { | |
4280 | case NL80211_TDLS_DISCOVERY_REQ: | |
4281 | ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY; | |
4282 | break; | |
4283 | case NL80211_TDLS_SETUP: | |
4284 | ret = BRCMF_TDLS_MANUAL_EP_CREATE; | |
4285 | break; | |
4286 | case NL80211_TDLS_TEARDOWN: | |
4287 | ret = BRCMF_TDLS_MANUAL_EP_DELETE; | |
4288 | break; | |
4289 | default: | |
4290 | brcmf_err("unsupported operation: %d\n", oper); | |
4291 | ret = -EOPNOTSUPP; | |
4292 | } | |
4293 | return ret; | |
4294 | } | |
4295 | ||
4296 | static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy, | |
3b3a0162 | 4297 | struct net_device *ndev, const u8 *peer, |
89c2f382 AS |
4298 | enum nl80211_tdls_operation oper) |
4299 | { | |
4300 | struct brcmf_if *ifp; | |
4301 | struct brcmf_tdls_iovar_le info; | |
4302 | int ret = 0; | |
4303 | ||
4304 | ret = brcmf_convert_nl80211_tdls_oper(oper); | |
4305 | if (ret < 0) | |
4306 | return ret; | |
4307 | ||
4308 | ifp = netdev_priv(ndev); | |
4309 | memset(&info, 0, sizeof(info)); | |
4310 | info.mode = (u8)ret; | |
4311 | if (peer) | |
4312 | memcpy(info.ea, peer, ETH_ALEN); | |
4313 | ||
4314 | ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint", | |
4315 | &info, sizeof(info)); | |
4316 | if (ret < 0) | |
4317 | brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret); | |
4318 | ||
4319 | return ret; | |
4320 | } | |
4321 | ||
5b435de0 | 4322 | static struct cfg80211_ops wl_cfg80211_ops = { |
9f440b7b AS |
4323 | .add_virtual_intf = brcmf_cfg80211_add_iface, |
4324 | .del_virtual_intf = brcmf_cfg80211_del_iface, | |
5b435de0 AS |
4325 | .change_virtual_intf = brcmf_cfg80211_change_iface, |
4326 | .scan = brcmf_cfg80211_scan, | |
4327 | .set_wiphy_params = brcmf_cfg80211_set_wiphy_params, | |
4328 | .join_ibss = brcmf_cfg80211_join_ibss, | |
4329 | .leave_ibss = brcmf_cfg80211_leave_ibss, | |
4330 | .get_station = brcmf_cfg80211_get_station, | |
4331 | .set_tx_power = brcmf_cfg80211_set_tx_power, | |
4332 | .get_tx_power = brcmf_cfg80211_get_tx_power, | |
4333 | .add_key = brcmf_cfg80211_add_key, | |
4334 | .del_key = brcmf_cfg80211_del_key, | |
4335 | .get_key = brcmf_cfg80211_get_key, | |
4336 | .set_default_key = brcmf_cfg80211_config_default_key, | |
4337 | .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key, | |
4338 | .set_power_mgmt = brcmf_cfg80211_set_power_mgmt, | |
5b435de0 AS |
4339 | .connect = brcmf_cfg80211_connect, |
4340 | .disconnect = brcmf_cfg80211_disconnect, | |
4341 | .suspend = brcmf_cfg80211_suspend, | |
4342 | .resume = brcmf_cfg80211_resume, | |
4343 | .set_pmksa = brcmf_cfg80211_set_pmksa, | |
4344 | .del_pmksa = brcmf_cfg80211_del_pmksa, | |
cbaa177d | 4345 | .flush_pmksa = brcmf_cfg80211_flush_pmksa, |
1a873342 HM |
4346 | .start_ap = brcmf_cfg80211_start_ap, |
4347 | .stop_ap = brcmf_cfg80211_stop_ap, | |
a0f07959 | 4348 | .change_beacon = brcmf_cfg80211_change_beacon, |
1a873342 | 4349 | .del_station = brcmf_cfg80211_del_station, |
e5806072 AS |
4350 | .sched_scan_start = brcmf_cfg80211_sched_scan_start, |
4351 | .sched_scan_stop = brcmf_cfg80211_sched_scan_stop, | |
0de8aace HM |
4352 | .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register, |
4353 | .mgmt_tx = brcmf_cfg80211_mgmt_tx, | |
4354 | .remain_on_channel = brcmf_p2p_remain_on_channel, | |
4355 | .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, | |
27f10e38 AS |
4356 | .start_p2p_device = brcmf_p2p_start_device, |
4357 | .stop_p2p_device = brcmf_p2p_stop_device, | |
61730d4d PH |
4358 | .crit_proto_start = brcmf_cfg80211_crit_proto_start, |
4359 | .crit_proto_stop = brcmf_cfg80211_crit_proto_stop, | |
89c2f382 | 4360 | .tdls_oper = brcmf_cfg80211_tdls_oper, |
5b435de0 AS |
4361 | }; |
4362 | ||
3eacf866 | 4363 | struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg, |
9f440b7b AS |
4364 | enum nl80211_iftype type, |
4365 | bool pm_block) | |
3eacf866 AS |
4366 | { |
4367 | struct brcmf_cfg80211_vif *vif; | |
5b435de0 | 4368 | |
33a6b157 | 4369 | brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n", |
9f440b7b | 4370 | sizeof(*vif)); |
3eacf866 AS |
4371 | vif = kzalloc(sizeof(*vif), GFP_KERNEL); |
4372 | if (!vif) | |
4373 | return ERR_PTR(-ENOMEM); | |
4374 | ||
4375 | vif->wdev.wiphy = cfg->wiphy; | |
9f440b7b | 4376 | vif->wdev.iftype = type; |
5b435de0 | 4377 | |
3eacf866 AS |
4378 | vif->pm_block = pm_block; |
4379 | vif->roam_off = -1; | |
4380 | ||
6ac4f4ed AS |
4381 | brcmf_init_prof(&vif->profile); |
4382 | ||
3eacf866 | 4383 | list_add_tail(&vif->list, &cfg->vif_list); |
3eacf866 | 4384 | return vif; |
5b435de0 AS |
4385 | } |
4386 | ||
427dec5f | 4387 | void brcmf_free_vif(struct brcmf_cfg80211_vif *vif) |
5b435de0 | 4388 | { |
3eacf866 | 4389 | list_del(&vif->list); |
3eacf866 | 4390 | kfree(vif); |
5b435de0 AS |
4391 | } |
4392 | ||
9df4d542 AS |
4393 | void brcmf_cfg80211_free_netdev(struct net_device *ndev) |
4394 | { | |
4395 | struct brcmf_cfg80211_vif *vif; | |
4396 | struct brcmf_if *ifp; | |
4397 | ||
4398 | ifp = netdev_priv(ndev); | |
4399 | vif = ifp->vif; | |
4400 | ||
4401 | brcmf_free_vif(vif); | |
4402 | free_netdev(ndev); | |
4403 | } | |
4404 | ||
903e0eee | 4405 | static bool brcmf_is_linkup(const struct brcmf_event_msg *e) |
5b435de0 | 4406 | { |
5c36b99a AS |
4407 | u32 event = e->event_code; |
4408 | u32 status = e->status; | |
5b435de0 AS |
4409 | |
4410 | if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) { | |
16886735 | 4411 | brcmf_dbg(CONN, "Processing set ssid\n"); |
5b435de0 AS |
4412 | return true; |
4413 | } | |
4414 | ||
4415 | return false; | |
4416 | } | |
4417 | ||
903e0eee | 4418 | static bool brcmf_is_linkdown(const struct brcmf_event_msg *e) |
5b435de0 | 4419 | { |
5c36b99a AS |
4420 | u32 event = e->event_code; |
4421 | u16 flags = e->flags; | |
5b435de0 | 4422 | |
68ca395f HM |
4423 | if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) || |
4424 | (event == BRCMF_E_DISASSOC_IND) || | |
4425 | ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) { | |
16886735 | 4426 | brcmf_dbg(CONN, "Processing link down\n"); |
5b435de0 AS |
4427 | return true; |
4428 | } | |
4429 | return false; | |
4430 | } | |
4431 | ||
27a68fe3 | 4432 | static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
4433 | const struct brcmf_event_msg *e) |
4434 | { | |
5c36b99a AS |
4435 | u32 event = e->event_code; |
4436 | u32 status = e->status; | |
5b435de0 AS |
4437 | |
4438 | if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) { | |
16886735 AS |
4439 | brcmf_dbg(CONN, "Processing Link %s & no network found\n", |
4440 | e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down"); | |
5b435de0 AS |
4441 | return true; |
4442 | } | |
4443 | ||
4444 | if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) { | |
16886735 | 4445 | brcmf_dbg(CONN, "Processing connecting & no network found\n"); |
5b435de0 AS |
4446 | return true; |
4447 | } | |
4448 | ||
4449 | return false; | |
4450 | } | |
4451 | ||
27a68fe3 | 4452 | static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 4453 | { |
27a68fe3 | 4454 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
5b435de0 AS |
4455 | |
4456 | kfree(conn_info->req_ie); | |
4457 | conn_info->req_ie = NULL; | |
4458 | conn_info->req_ie_len = 0; | |
4459 | kfree(conn_info->resp_ie); | |
4460 | conn_info->resp_ie = NULL; | |
4461 | conn_info->resp_ie_len = 0; | |
4462 | } | |
4463 | ||
89286dc9 HM |
4464 | static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg, |
4465 | struct brcmf_if *ifp) | |
5b435de0 | 4466 | { |
c4e382d2 | 4467 | struct brcmf_cfg80211_assoc_ielen_le *assoc_info; |
27a68fe3 | 4468 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
5b435de0 AS |
4469 | u32 req_len; |
4470 | u32 resp_len; | |
4471 | s32 err = 0; | |
4472 | ||
27a68fe3 | 4473 | brcmf_clear_assoc_ies(cfg); |
5b435de0 | 4474 | |
ac24be6f AS |
4475 | err = brcmf_fil_iovar_data_get(ifp, "assoc_info", |
4476 | cfg->extra_buf, WL_ASSOC_INFO_MAX); | |
5b435de0 | 4477 | if (err) { |
57d6e91a | 4478 | brcmf_err("could not get assoc info (%d)\n", err); |
5b435de0 AS |
4479 | return err; |
4480 | } | |
c4e382d2 | 4481 | assoc_info = |
27a68fe3 | 4482 | (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf; |
c4e382d2 AS |
4483 | req_len = le32_to_cpu(assoc_info->req_len); |
4484 | resp_len = le32_to_cpu(assoc_info->resp_len); | |
5b435de0 | 4485 | if (req_len) { |
ac24be6f | 4486 | err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies", |
81f5dcb8 HM |
4487 | cfg->extra_buf, |
4488 | WL_ASSOC_INFO_MAX); | |
5b435de0 | 4489 | if (err) { |
57d6e91a | 4490 | brcmf_err("could not get assoc req (%d)\n", err); |
5b435de0 AS |
4491 | return err; |
4492 | } | |
4493 | conn_info->req_ie_len = req_len; | |
4494 | conn_info->req_ie = | |
27a68fe3 | 4495 | kmemdup(cfg->extra_buf, conn_info->req_ie_len, |
5b435de0 AS |
4496 | GFP_KERNEL); |
4497 | } else { | |
4498 | conn_info->req_ie_len = 0; | |
4499 | conn_info->req_ie = NULL; | |
4500 | } | |
4501 | if (resp_len) { | |
ac24be6f | 4502 | err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies", |
81f5dcb8 HM |
4503 | cfg->extra_buf, |
4504 | WL_ASSOC_INFO_MAX); | |
5b435de0 | 4505 | if (err) { |
57d6e91a | 4506 | brcmf_err("could not get assoc resp (%d)\n", err); |
5b435de0 AS |
4507 | return err; |
4508 | } | |
4509 | conn_info->resp_ie_len = resp_len; | |
4510 | conn_info->resp_ie = | |
27a68fe3 | 4511 | kmemdup(cfg->extra_buf, conn_info->resp_ie_len, |
5b435de0 AS |
4512 | GFP_KERNEL); |
4513 | } else { | |
4514 | conn_info->resp_ie_len = 0; | |
4515 | conn_info->resp_ie = NULL; | |
4516 | } | |
16886735 AS |
4517 | brcmf_dbg(CONN, "req len (%d) resp len (%d)\n", |
4518 | conn_info->req_ie_len, conn_info->resp_ie_len); | |
5b435de0 AS |
4519 | |
4520 | return err; | |
4521 | } | |
4522 | ||
4523 | static s32 | |
27a68fe3 | 4524 | brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
4525 | struct net_device *ndev, |
4526 | const struct brcmf_event_msg *e) | |
4527 | { | |
c1179033 AS |
4528 | struct brcmf_if *ifp = netdev_priv(ndev); |
4529 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
27a68fe3 AS |
4530 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
4531 | struct wiphy *wiphy = cfg_to_wiphy(cfg); | |
a180b83b | 4532 | struct ieee80211_channel *notify_channel = NULL; |
5b435de0 | 4533 | struct ieee80211_supported_band *band; |
a180b83b | 4534 | struct brcmf_bss_info_le *bi; |
83cf17aa | 4535 | struct brcmu_chan ch; |
5b435de0 AS |
4536 | u32 freq; |
4537 | s32 err = 0; | |
a180b83b | 4538 | u8 *buf; |
5b435de0 | 4539 | |
d96b801f | 4540 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 4541 | |
89286dc9 | 4542 | brcmf_get_assoc_ies(cfg, ifp); |
6c8c4f72 | 4543 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
89286dc9 | 4544 | brcmf_update_bss_info(cfg, ifp); |
5b435de0 | 4545 | |
a180b83b FL |
4546 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
4547 | if (buf == NULL) { | |
4548 | err = -ENOMEM; | |
4549 | goto done; | |
4550 | } | |
4551 | ||
4552 | /* data sent to dongle has to be little endian */ | |
4553 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); | |
c1179033 | 4554 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
ac24be6f | 4555 | buf, WL_BSS_INFO_MAX); |
a180b83b FL |
4556 | |
4557 | if (err) | |
4558 | goto done; | |
5b435de0 | 4559 | |
a180b83b | 4560 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
83cf17aa FL |
4561 | ch.chspec = le16_to_cpu(bi->chanspec); |
4562 | cfg->d11inf.decchspec(&ch); | |
5b435de0 | 4563 | |
83cf17aa | 4564 | if (ch.band == BRCMU_CHAN_BAND_2G) |
5b435de0 AS |
4565 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
4566 | else | |
4567 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | |
4568 | ||
83cf17aa | 4569 | freq = ieee80211_channel_to_frequency(ch.chnum, band->band); |
5b435de0 AS |
4570 | notify_channel = ieee80211_get_channel(wiphy, freq); |
4571 | ||
a180b83b FL |
4572 | done: |
4573 | kfree(buf); | |
06bb123e | 4574 | cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, |
5b435de0 AS |
4575 | conn_info->req_ie, conn_info->req_ie_len, |
4576 | conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); | |
16886735 | 4577 | brcmf_dbg(CONN, "Report roaming result\n"); |
5b435de0 | 4578 | |
c1179033 | 4579 | set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); |
d96b801f | 4580 | brcmf_dbg(TRACE, "Exit\n"); |
5b435de0 AS |
4581 | return err; |
4582 | } | |
4583 | ||
4584 | static s32 | |
27a68fe3 | 4585 | brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, |
5b435de0 AS |
4586 | struct net_device *ndev, const struct brcmf_event_msg *e, |
4587 | bool completed) | |
4588 | { | |
c1179033 AS |
4589 | struct brcmf_if *ifp = netdev_priv(ndev); |
4590 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; | |
27a68fe3 | 4591 | struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg); |
5b435de0 | 4592 | |
d96b801f | 4593 | brcmf_dbg(TRACE, "Enter\n"); |
5b435de0 | 4594 | |
c1179033 AS |
4595 | if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
4596 | &ifp->vif->sme_state)) { | |
5b435de0 | 4597 | if (completed) { |
89286dc9 | 4598 | brcmf_get_assoc_ies(cfg, ifp); |
6c8c4f72 | 4599 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
89286dc9 HM |
4600 | brcmf_update_bss_info(cfg, ifp); |
4601 | set_bit(BRCMF_VIF_STATUS_CONNECTED, | |
4602 | &ifp->vif->sme_state); | |
5b435de0 AS |
4603 | } |
4604 | cfg80211_connect_result(ndev, | |
06bb123e | 4605 | (u8 *)profile->bssid, |
5b435de0 AS |
4606 | conn_info->req_ie, |
4607 | conn_info->req_ie_len, | |
4608 | conn_info->resp_ie, | |
4609 | conn_info->resp_ie_len, | |
4610 | completed ? WLAN_STATUS_SUCCESS : | |
4611 | WLAN_STATUS_AUTH_TIMEOUT, | |
4612 | GFP_KERNEL); | |
16886735 AS |
4613 | brcmf_dbg(CONN, "Report connect result - connection %s\n", |
4614 | completed ? "succeeded" : "failed"); | |
5b435de0 | 4615 | } |
d96b801f | 4616 | brcmf_dbg(TRACE, "Exit\n"); |
12f32370 | 4617 | return 0; |
5b435de0 AS |
4618 | } |
4619 | ||
4620 | static s32 | |
27a68fe3 | 4621 | brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg, |
1a873342 HM |
4622 | struct net_device *ndev, |
4623 | const struct brcmf_event_msg *e, void *data) | |
4624 | { | |
7ee29602 | 4625 | static int generation; |
5c36b99a AS |
4626 | u32 event = e->event_code; |
4627 | u32 reason = e->reason; | |
1a873342 HM |
4628 | struct station_info sinfo; |
4629 | ||
16886735 | 4630 | brcmf_dbg(CONN, "event %d, reason %d\n", event, reason); |
5f4f9f11 AS |
4631 | if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS && |
4632 | ndev != cfg_to_ndev(cfg)) { | |
4633 | brcmf_dbg(CONN, "AP mode link down\n"); | |
4634 | complete(&cfg->vif_disabled); | |
4635 | return 0; | |
4636 | } | |
1a873342 | 4637 | |
1a873342 | 4638 | if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) && |
7ee29602 HM |
4639 | (reason == BRCMF_E_STATUS_SUCCESS)) { |
4640 | memset(&sinfo, 0, sizeof(sinfo)); | |
1a873342 HM |
4641 | sinfo.filled = STATION_INFO_ASSOC_REQ_IES; |
4642 | if (!data) { | |
57d6e91a | 4643 | brcmf_err("No IEs present in ASSOC/REASSOC_IND"); |
1a873342 HM |
4644 | return -EINVAL; |
4645 | } | |
4646 | sinfo.assoc_req_ies = data; | |
7ee29602 | 4647 | sinfo.assoc_req_ies_len = e->datalen; |
1a873342 HM |
4648 | generation++; |
4649 | sinfo.generation = generation; | |
7ee29602 | 4650 | cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL); |
1a873342 HM |
4651 | } else if ((event == BRCMF_E_DISASSOC_IND) || |
4652 | (event == BRCMF_E_DEAUTH_IND) || | |
4653 | (event == BRCMF_E_DEAUTH)) { | |
7ee29602 | 4654 | cfg80211_del_sta(ndev, e->addr, GFP_KERNEL); |
1a873342 | 4655 | } |
7ee29602 | 4656 | return 0; |
1a873342 HM |
4657 | } |
4658 | ||
5b435de0 | 4659 | static s32 |
1993732e | 4660 | brcmf_notify_connect_status(struct brcmf_if *ifp, |
5b435de0 AS |
4661 | const struct brcmf_event_msg *e, void *data) |
4662 | { | |
1993732e AS |
4663 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
4664 | struct net_device *ndev = ifp->ndev; | |
c1179033 | 4665 | struct brcmf_cfg80211_profile *profile = &ifp->vif->profile; |
fe94f3a4 | 4666 | struct ieee80211_channel *chan; |
5b435de0 AS |
4667 | s32 err = 0; |
4668 | ||
8851cce0 HM |
4669 | if ((e->event_code == BRCMF_E_DEAUTH) || |
4670 | (e->event_code == BRCMF_E_DEAUTH_IND) || | |
4671 | (e->event_code == BRCMF_E_DISASSOC_IND) || | |
4672 | ((e->event_code == BRCMF_E_LINK) && (!e->flags))) { | |
4673 | brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr); | |
4674 | } | |
4675 | ||
967fe2c8 | 4676 | if (brcmf_is_apmode(ifp->vif)) { |
27a68fe3 | 4677 | err = brcmf_notify_connect_status_ap(cfg, ndev, e, data); |
903e0eee | 4678 | } else if (brcmf_is_linkup(e)) { |
16886735 | 4679 | brcmf_dbg(CONN, "Linkup\n"); |
128ce3b6 | 4680 | if (brcmf_is_ibssmode(ifp->vif)) { |
fe94f3a4 | 4681 | chan = ieee80211_get_channel(cfg->wiphy, cfg->channel); |
6c8c4f72 | 4682 | memcpy(profile->bssid, e->addr, ETH_ALEN); |
27a68fe3 | 4683 | wl_inform_ibss(cfg, ndev, e->addr); |
fe94f3a4 | 4684 | cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL); |
c1179033 AS |
4685 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
4686 | &ifp->vif->sme_state); | |
4687 | set_bit(BRCMF_VIF_STATUS_CONNECTED, | |
4688 | &ifp->vif->sme_state); | |
5b435de0 | 4689 | } else |
27a68fe3 | 4690 | brcmf_bss_connect_done(cfg, ndev, e, true); |
903e0eee | 4691 | } else if (brcmf_is_linkdown(e)) { |
16886735 | 4692 | brcmf_dbg(CONN, "Linkdown\n"); |
128ce3b6 | 4693 | if (!brcmf_is_ibssmode(ifp->vif)) { |
27a68fe3 | 4694 | brcmf_bss_connect_done(cfg, ndev, e, false); |
5b435de0 | 4695 | } |
903e0eee | 4696 | brcmf_link_down(ifp->vif); |
6ac4f4ed | 4697 | brcmf_init_prof(ndev_to_prof(ndev)); |
5f4f9f11 AS |
4698 | if (ndev != cfg_to_ndev(cfg)) |
4699 | complete(&cfg->vif_disabled); | |
27a68fe3 | 4700 | } else if (brcmf_is_nonetwork(cfg, e)) { |
128ce3b6 | 4701 | if (brcmf_is_ibssmode(ifp->vif)) |
c1179033 AS |
4702 | clear_bit(BRCMF_VIF_STATUS_CONNECTING, |
4703 | &ifp->vif->sme_state); | |
5b435de0 | 4704 | else |
27a68fe3 | 4705 | brcmf_bss_connect_done(cfg, ndev, e, false); |
5b435de0 AS |
4706 | } |
4707 | ||
4708 | return err; | |
4709 | } | |
4710 | ||
4711 | static s32 | |
1993732e | 4712 | brcmf_notify_roaming_status(struct brcmf_if *ifp, |
5b435de0 AS |
4713 | const struct brcmf_event_msg *e, void *data) |
4714 | { | |
1993732e | 4715 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
5c36b99a AS |
4716 | u32 event = e->event_code; |
4717 | u32 status = e->status; | |
5b435de0 AS |
4718 | |
4719 | if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) { | |
c1179033 | 4720 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state)) |
1993732e | 4721 | brcmf_bss_roaming_done(cfg, ifp->ndev, e); |
5b435de0 | 4722 | else |
1993732e | 4723 | brcmf_bss_connect_done(cfg, ifp->ndev, e, true); |
5b435de0 AS |
4724 | } |
4725 | ||
12f32370 | 4726 | return 0; |
5b435de0 AS |
4727 | } |
4728 | ||
4729 | static s32 | |
1993732e | 4730 | brcmf_notify_mic_status(struct brcmf_if *ifp, |
5b435de0 AS |
4731 | const struct brcmf_event_msg *e, void *data) |
4732 | { | |
5c36b99a | 4733 | u16 flags = e->flags; |
5b435de0 AS |
4734 | enum nl80211_key_type key_type; |
4735 | ||
4736 | if (flags & BRCMF_EVENT_MSG_GROUP) | |
4737 | key_type = NL80211_KEYTYPE_GROUP; | |
4738 | else | |
4739 | key_type = NL80211_KEYTYPE_PAIRWISE; | |
4740 | ||
1993732e | 4741 | cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1, |
5b435de0 AS |
4742 | NULL, GFP_KERNEL); |
4743 | ||
4744 | return 0; | |
4745 | } | |
4746 | ||
d3c0b633 AS |
4747 | static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, |
4748 | const struct brcmf_event_msg *e, void *data) | |
4749 | { | |
4750 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; | |
4751 | struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data; | |
4752 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
4753 | struct brcmf_cfg80211_vif *vif; | |
4754 | ||
4755 | brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n", | |
4756 | ifevent->action, ifevent->flags, ifevent->ifidx, | |
4757 | ifevent->bssidx); | |
4758 | ||
d3c0b633 AS |
4759 | mutex_lock(&event->vif_event_lock); |
4760 | event->action = ifevent->action; | |
4761 | vif = event->vif; | |
4762 | ||
4763 | switch (ifevent->action) { | |
4764 | case BRCMF_E_IF_ADD: | |
4765 | /* waiting process may have timed out */ | |
dc4a787c WY |
4766 | if (!cfg->vif_event.vif) { |
4767 | mutex_unlock(&event->vif_event_lock); | |
d3c0b633 | 4768 | return -EBADF; |
dc4a787c | 4769 | } |
d3c0b633 AS |
4770 | |
4771 | ifp->vif = vif; | |
4772 | vif->ifp = ifp; | |
01b8e7db AS |
4773 | if (ifp->ndev) { |
4774 | vif->wdev.netdev = ifp->ndev; | |
4775 | ifp->ndev->ieee80211_ptr = &vif->wdev; | |
4776 | SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy)); | |
4777 | } | |
d3c0b633 AS |
4778 | mutex_unlock(&event->vif_event_lock); |
4779 | wake_up(&event->vif_wq); | |
4b3a89de | 4780 | return 0; |
d3c0b633 AS |
4781 | |
4782 | case BRCMF_E_IF_DEL: | |
d3c0b633 AS |
4783 | mutex_unlock(&event->vif_event_lock); |
4784 | /* event may not be upon user request */ | |
4785 | if (brcmf_cfg80211_vif_event_armed(cfg)) | |
4786 | wake_up(&event->vif_wq); | |
4787 | return 0; | |
4788 | ||
7a5c1f64 HM |
4789 | case BRCMF_E_IF_CHANGE: |
4790 | mutex_unlock(&event->vif_event_lock); | |
4791 | wake_up(&event->vif_wq); | |
4792 | return 0; | |
4793 | ||
d3c0b633 AS |
4794 | default: |
4795 | mutex_unlock(&event->vif_event_lock); | |
4796 | break; | |
4797 | } | |
4798 | return -EINVAL; | |
4799 | } | |
4800 | ||
5b435de0 AS |
4801 | static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf) |
4802 | { | |
5b435de0 AS |
4803 | conf->frag_threshold = (u32)-1; |
4804 | conf->rts_threshold = (u32)-1; | |
4805 | conf->retry_short = (u32)-1; | |
4806 | conf->retry_long = (u32)-1; | |
4807 | conf->tx_power = -1; | |
4808 | } | |
4809 | ||
5c36b99a | 4810 | static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 4811 | { |
5c36b99a AS |
4812 | brcmf_fweh_register(cfg->pub, BRCMF_E_LINK, |
4813 | brcmf_notify_connect_status); | |
4814 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND, | |
4815 | brcmf_notify_connect_status); | |
4816 | brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH, | |
4817 | brcmf_notify_connect_status); | |
4818 | brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND, | |
4819 | brcmf_notify_connect_status); | |
4820 | brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND, | |
4821 | brcmf_notify_connect_status); | |
4822 | brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND, | |
4823 | brcmf_notify_connect_status); | |
4824 | brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM, | |
4825 | brcmf_notify_roaming_status); | |
4826 | brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR, | |
4827 | brcmf_notify_mic_status); | |
4828 | brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID, | |
4829 | brcmf_notify_connect_status); | |
4830 | brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND, | |
4831 | brcmf_notify_sched_scan_results); | |
d3c0b633 AS |
4832 | brcmf_fweh_register(cfg->pub, BRCMF_E_IF, |
4833 | brcmf_notify_vif_event); | |
0de8aace | 4834 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG, |
6eda4e2c | 4835 | brcmf_p2p_notify_rx_mgmt_p2p_probereq); |
0de8aace HM |
4836 | brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE, |
4837 | brcmf_p2p_notify_listen_complete); | |
e6da3400 HM |
4838 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX, |
4839 | brcmf_p2p_notify_action_frame_rx); | |
18e2f61d HM |
4840 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE, |
4841 | brcmf_p2p_notify_action_tx_complete); | |
6eda4e2c HM |
4842 | brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE, |
4843 | brcmf_p2p_notify_action_tx_complete); | |
5b435de0 AS |
4844 | } |
4845 | ||
27a68fe3 AS |
4846 | static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) |
4847 | { | |
27a68fe3 AS |
4848 | kfree(cfg->conf); |
4849 | cfg->conf = NULL; | |
27a68fe3 AS |
4850 | kfree(cfg->escan_ioctl_buf); |
4851 | cfg->escan_ioctl_buf = NULL; | |
27a68fe3 AS |
4852 | kfree(cfg->extra_buf); |
4853 | cfg->extra_buf = NULL; | |
27a68fe3 AS |
4854 | kfree(cfg->pmk_list); |
4855 | cfg->pmk_list = NULL; | |
27a68fe3 AS |
4856 | } |
4857 | ||
4858 | static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg) | |
4859 | { | |
27a68fe3 AS |
4860 | cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL); |
4861 | if (!cfg->conf) | |
5b435de0 | 4862 | goto init_priv_mem_out; |
27a68fe3 AS |
4863 | cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); |
4864 | if (!cfg->escan_ioctl_buf) | |
e756af5b | 4865 | goto init_priv_mem_out; |
27a68fe3 AS |
4866 | cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); |
4867 | if (!cfg->extra_buf) | |
5b435de0 | 4868 | goto init_priv_mem_out; |
27a68fe3 AS |
4869 | cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL); |
4870 | if (!cfg->pmk_list) | |
5b435de0 AS |
4871 | goto init_priv_mem_out; |
4872 | ||
4873 | return 0; | |
4874 | ||
4875 | init_priv_mem_out: | |
27a68fe3 | 4876 | brcmf_deinit_priv_mem(cfg); |
5b435de0 AS |
4877 | |
4878 | return -ENOMEM; | |
4879 | } | |
4880 | ||
27a68fe3 | 4881 | static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg) |
5b435de0 AS |
4882 | { |
4883 | s32 err = 0; | |
4884 | ||
27a68fe3 AS |
4885 | cfg->scan_request = NULL; |
4886 | cfg->pwr_save = true; | |
68ca395f HM |
4887 | cfg->active_scan = true; /* we do active scan per default */ |
4888 | cfg->dongle_up = false; /* dongle is not up yet */ | |
27a68fe3 | 4889 | err = brcmf_init_priv_mem(cfg); |
5b435de0 AS |
4890 | if (err) |
4891 | return err; | |
5c36b99a | 4892 | brcmf_register_event_handlers(cfg); |
27a68fe3 | 4893 | mutex_init(&cfg->usr_sync); |
27a68fe3 AS |
4894 | brcmf_init_escan(cfg); |
4895 | brcmf_init_conf(cfg->conf); | |
5f4f9f11 | 4896 | init_completion(&cfg->vif_disabled); |
5b435de0 AS |
4897 | return err; |
4898 | } | |
4899 | ||
27a68fe3 | 4900 | static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg) |
5b435de0 | 4901 | { |
27a68fe3 | 4902 | cfg->dongle_up = false; /* dongle down */ |
27a68fe3 AS |
4903 | brcmf_abort_scanning(cfg); |
4904 | brcmf_deinit_priv_mem(cfg); | |
5b435de0 AS |
4905 | } |
4906 | ||
d3c0b633 AS |
4907 | static void init_vif_event(struct brcmf_cfg80211_vif_event *event) |
4908 | { | |
4909 | init_waitqueue_head(&event->vif_wq); | |
d3c0b633 AS |
4910 | mutex_init(&event->vif_event_lock); |
4911 | } | |
4912 | ||
5b435de0 | 4913 | static s32 |
68ca395f | 4914 | brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout) |
5b435de0 | 4915 | { |
5b435de0 | 4916 | s32 err = 0; |
f588bc0c AS |
4917 | __le32 roamtrigger[2]; |
4918 | __le32 roam_delta[2]; | |
5b435de0 AS |
4919 | |
4920 | /* | |
4921 | * Setup timeout if Beacons are lost and roam is | |
4922 | * off to report link down | |
4923 | */ | |
68ca395f | 4924 | if (brcmf_roamoff) { |
ac24be6f | 4925 | err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout); |
5b435de0 | 4926 | if (err) { |
57d6e91a | 4927 | brcmf_err("bcn_timeout error (%d)\n", err); |
5b435de0 AS |
4928 | goto dongle_rom_out; |
4929 | } | |
4930 | } | |
4931 | ||
4932 | /* | |
4933 | * Enable/Disable built-in roaming to allow supplicant | |
4934 | * to take care of roaming | |
4935 | */ | |
68ca395f HM |
4936 | brcmf_dbg(INFO, "Internal Roaming = %s\n", |
4937 | brcmf_roamoff ? "Off" : "On"); | |
4938 | err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff)); | |
5b435de0 | 4939 | if (err) { |
57d6e91a | 4940 | brcmf_err("roam_off error (%d)\n", err); |
5b435de0 AS |
4941 | goto dongle_rom_out; |
4942 | } | |
4943 | ||
f588bc0c AS |
4944 | roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL); |
4945 | roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL); | |
ac24be6f | 4946 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER, |
81f5dcb8 | 4947 | (void *)roamtrigger, sizeof(roamtrigger)); |
5b435de0 | 4948 | if (err) { |
57d6e91a | 4949 | brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err); |
5b435de0 AS |
4950 | goto dongle_rom_out; |
4951 | } | |
4952 | ||
f588bc0c AS |
4953 | roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA); |
4954 | roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL); | |
ac24be6f | 4955 | err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA, |
81f5dcb8 | 4956 | (void *)roam_delta, sizeof(roam_delta)); |
5b435de0 | 4957 | if (err) { |
57d6e91a | 4958 | brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err); |
5b435de0 AS |
4959 | goto dongle_rom_out; |
4960 | } | |
4961 | ||
4962 | dongle_rom_out: | |
4963 | return err; | |
4964 | } | |
4965 | ||
4966 | static s32 | |
40a23296 | 4967 | brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time, |
c68cdc0f | 4968 | s32 scan_unassoc_time, s32 scan_passive_time) |
5b435de0 AS |
4969 | { |
4970 | s32 err = 0; | |
4971 | ||
ac24be6f | 4972 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME, |
81f5dcb8 | 4973 | scan_assoc_time); |
5b435de0 AS |
4974 | if (err) { |
4975 | if (err == -EOPNOTSUPP) | |
647c9ae0 | 4976 | brcmf_dbg(INFO, "Scan assoc time is not supported\n"); |
5b435de0 | 4977 | else |
57d6e91a | 4978 | brcmf_err("Scan assoc time error (%d)\n", err); |
5b435de0 AS |
4979 | goto dongle_scantime_out; |
4980 | } | |
ac24be6f | 4981 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME, |
81f5dcb8 | 4982 | scan_unassoc_time); |
5b435de0 AS |
4983 | if (err) { |
4984 | if (err == -EOPNOTSUPP) | |
647c9ae0 | 4985 | brcmf_dbg(INFO, "Scan unassoc time is not supported\n"); |
5b435de0 | 4986 | else |
57d6e91a | 4987 | brcmf_err("Scan unassoc time error (%d)\n", err); |
5b435de0 AS |
4988 | goto dongle_scantime_out; |
4989 | } | |
4990 | ||
ac24be6f | 4991 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME, |
81f5dcb8 | 4992 | scan_passive_time); |
5b435de0 AS |
4993 | if (err) { |
4994 | if (err == -EOPNOTSUPP) | |
647c9ae0 | 4995 | brcmf_dbg(INFO, "Scan passive time is not supported\n"); |
5b435de0 | 4996 | else |
57d6e91a | 4997 | brcmf_err("Scan passive time error (%d)\n", err); |
5b435de0 AS |
4998 | goto dongle_scantime_out; |
4999 | } | |
5000 | ||
5001 | dongle_scantime_out: | |
5002 | return err; | |
5003 | } | |
5004 | ||
b48d8916 AS |
5005 | /* Filter the list of channels received from firmware counting only |
5006 | * the 20MHz channels. The wiphy band data only needs those which get | |
5007 | * flagged to indicate if they can take part in higher bandwidth. | |
5008 | */ | |
5009 | static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg, | |
5010 | struct brcmf_chanspec_list *chlist, | |
5011 | u32 chcnt[]) | |
5012 | { | |
5013 | u32 total = le32_to_cpu(chlist->count); | |
5014 | struct brcmu_chan ch; | |
5015 | int i; | |
5016 | ||
f8adaf0a | 5017 | for (i = 0; i < total; i++) { |
b48d8916 AS |
5018 | ch.chspec = (u16)le32_to_cpu(chlist->element[i]); |
5019 | cfg->d11inf.decchspec(&ch); | |
5020 | ||
5021 | /* Firmware gives a ordered list. We skip non-20MHz | |
5022 | * channels is 2G. For 5G we can abort upon reaching | |
5023 | * a non-20MHz channel in the list. | |
5024 | */ | |
5025 | if (ch.bw != BRCMU_CHAN_BW_20) { | |
5026 | if (ch.band == BRCMU_CHAN_BAND_5G) | |
5027 | break; | |
5028 | else | |
5029 | continue; | |
5030 | } | |
5031 | ||
5032 | if (ch.band == BRCMU_CHAN_BAND_2G) | |
5033 | chcnt[0] += 1; | |
5034 | else if (ch.band == BRCMU_CHAN_BAND_5G) | |
5035 | chcnt[1] += 1; | |
5036 | } | |
5037 | } | |
5038 | ||
5039 | static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel, | |
5040 | struct brcmu_chan *ch) | |
5041 | { | |
5042 | u32 ht40_flag; | |
d48200ba | 5043 | |
b48d8916 AS |
5044 | ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40; |
5045 | if (ch->sb == BRCMU_CHAN_SB_U) { | |
5046 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) | |
5047 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; | |
5048 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; | |
5049 | } else { | |
5050 | /* It should be one of | |
5051 | * IEEE80211_CHAN_NO_HT40 or | |
5052 | * IEEE80211_CHAN_NO_HT40PLUS | |
5053 | */ | |
5054 | channel->flags &= ~IEEE80211_CHAN_NO_HT40; | |
5055 | if (ht40_flag == IEEE80211_CHAN_NO_HT40) | |
5056 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; | |
5057 | } | |
5058 | } | |
5059 | ||
5060 | static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, | |
5061 | u32 bw_cap[]) | |
d48200ba HM |
5062 | { |
5063 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); | |
b48d8916 AS |
5064 | struct ieee80211_supported_band *band; |
5065 | struct ieee80211_channel *channel; | |
5066 | struct wiphy *wiphy; | |
d48200ba | 5067 | struct brcmf_chanspec_list *list; |
83cf17aa | 5068 | struct brcmu_chan ch; |
b48d8916 | 5069 | int err; |
d48200ba HM |
5070 | u8 *pbuf; |
5071 | u32 i, j; | |
5072 | u32 total; | |
b48d8916 AS |
5073 | u32 chaninfo; |
5074 | u32 chcnt[2] = { 0, 0 }; | |
d48200ba | 5075 | u32 index; |
d48200ba HM |
5076 | |
5077 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); | |
5078 | ||
5079 | if (pbuf == NULL) | |
5080 | return -ENOMEM; | |
5081 | ||
5082 | list = (struct brcmf_chanspec_list *)pbuf; | |
5083 | ||
5084 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, | |
5085 | BRCMF_DCMD_MEDLEN); | |
5086 | if (err) { | |
5087 | brcmf_err("get chanspecs error (%d)\n", err); | |
b48d8916 | 5088 | goto fail_pbuf; |
d48200ba HM |
5089 | } |
5090 | ||
b48d8916 AS |
5091 | brcmf_count_20mhz_channels(cfg, list, chcnt); |
5092 | wiphy = cfg_to_wiphy(cfg); | |
5093 | if (chcnt[0]) { | |
5094 | band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz), | |
5095 | GFP_KERNEL); | |
5096 | if (band == NULL) { | |
5097 | err = -ENOMEM; | |
5098 | goto fail_pbuf; | |
5099 | } | |
5100 | band->channels = kcalloc(chcnt[0], sizeof(*channel), | |
5101 | GFP_KERNEL); | |
5102 | if (band->channels == NULL) { | |
5103 | kfree(band); | |
5104 | err = -ENOMEM; | |
5105 | goto fail_pbuf; | |
5106 | } | |
5107 | band->n_channels = 0; | |
5108 | wiphy->bands[IEEE80211_BAND_2GHZ] = band; | |
5109 | } | |
5110 | if (chcnt[1]) { | |
5111 | band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a), | |
5112 | GFP_KERNEL); | |
5113 | if (band == NULL) { | |
5114 | err = -ENOMEM; | |
5115 | goto fail_band2g; | |
5116 | } | |
5117 | band->channels = kcalloc(chcnt[1], sizeof(*channel), | |
5118 | GFP_KERNEL); | |
5119 | if (band->channels == NULL) { | |
5120 | kfree(band); | |
5121 | err = -ENOMEM; | |
5122 | goto fail_band2g; | |
5123 | } | |
5124 | band->n_channels = 0; | |
5125 | wiphy->bands[IEEE80211_BAND_5GHZ] = band; | |
5126 | } | |
d48200ba HM |
5127 | |
5128 | total = le32_to_cpu(list->count); | |
5129 | for (i = 0; i < total; i++) { | |
83cf17aa FL |
5130 | ch.chspec = (u16)le32_to_cpu(list->element[i]); |
5131 | cfg->d11inf.decchspec(&ch); | |
d48200ba | 5132 | |
83cf17aa | 5133 | if (ch.band == BRCMU_CHAN_BAND_2G) { |
b48d8916 | 5134 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; |
83cf17aa | 5135 | } else if (ch.band == BRCMU_CHAN_BAND_5G) { |
b48d8916 | 5136 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
d48200ba | 5137 | } else { |
2375d970 | 5138 | brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec); |
d48200ba HM |
5139 | continue; |
5140 | } | |
b48d8916 | 5141 | if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) && |
2375d970 | 5142 | ch.bw == BRCMU_CHAN_BW_40) |
d48200ba | 5143 | continue; |
b48d8916 | 5144 | if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) && |
ee942ecc AS |
5145 | ch.bw == BRCMU_CHAN_BW_80) |
5146 | continue; | |
b48d8916 AS |
5147 | |
5148 | channel = band->channels; | |
5149 | index = band->n_channels; | |
5150 | for (j = 0; j < band->n_channels; j++) { | |
5151 | if (channel[j].hw_value == ch.chnum) { | |
5152 | index = j; | |
d48200ba HM |
5153 | break; |
5154 | } | |
5155 | } | |
b48d8916 AS |
5156 | channel[index].center_freq = |
5157 | ieee80211_channel_to_frequency(ch.chnum, band->band); | |
5158 | channel[index].hw_value = ch.chnum; | |
5159 | ||
5160 | /* assuming the chanspecs order is HT20, | |
5161 | * HT40 upper, HT40 lower, and VHT80. | |
5162 | */ | |
5163 | if (ch.bw == BRCMU_CHAN_BW_80) { | |
5164 | channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ; | |
5165 | } else if (ch.bw == BRCMU_CHAN_BW_40) { | |
5166 | brcmf_update_bw40_channel_flag(&channel[index], &ch); | |
5167 | } else { | |
5168 | /* disable other bandwidths for now as mentioned | |
5169 | * order assure they are enabled for subsequent | |
5170 | * chanspecs. | |
ee942ecc | 5171 | */ |
b48d8916 AS |
5172 | channel[index].flags = IEEE80211_CHAN_NO_HT40 | |
5173 | IEEE80211_CHAN_NO_80MHZ; | |
5174 | ch.bw = BRCMU_CHAN_BW_20; | |
5175 | cfg->d11inf.encchspec(&ch); | |
5176 | chaninfo = ch.chspec; | |
5177 | err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info", | |
5178 | &chaninfo); | |
5179 | if (!err) { | |
5180 | if (chaninfo & WL_CHAN_RADAR) | |
5181 | channel[index].flags |= | |
5182 | (IEEE80211_CHAN_RADAR | | |
5183 | IEEE80211_CHAN_NO_IR); | |
5184 | if (chaninfo & WL_CHAN_PASSIVE) | |
5185 | channel[index].flags |= | |
5186 | IEEE80211_CHAN_NO_IR; | |
d48200ba | 5187 | } |
d48200ba | 5188 | } |
b48d8916 AS |
5189 | if (index == band->n_channels) |
5190 | band->n_channels++; | |
d48200ba | 5191 | } |
b48d8916 AS |
5192 | kfree(pbuf); |
5193 | return 0; | |
5194 | ||
5195 | fail_band2g: | |
5196 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels); | |
5197 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]); | |
5198 | wiphy->bands[IEEE80211_BAND_2GHZ] = NULL; | |
5199 | fail_pbuf: | |
d48200ba HM |
5200 | kfree(pbuf); |
5201 | return err; | |
5202 | } | |
5203 | ||
b48d8916 | 5204 | static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg) |
aa70b4fa | 5205 | { |
b48d8916 AS |
5206 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
5207 | struct ieee80211_supported_band *band; | |
aa70b4fa | 5208 | struct brcmf_fil_bwcap_le band_bwcap; |
b48d8916 AS |
5209 | struct brcmf_chanspec_list *list; |
5210 | u8 *pbuf; | |
aa70b4fa AS |
5211 | u32 val; |
5212 | int err; | |
b48d8916 AS |
5213 | struct brcmu_chan ch; |
5214 | u32 num_chan; | |
5215 | int i, j; | |
aa70b4fa AS |
5216 | |
5217 | /* verify support for bw_cap command */ | |
5218 | val = WLC_BAND_5G; | |
5219 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val); | |
5220 | ||
5221 | if (!err) { | |
5222 | /* only set 2G bandwidth using bw_cap command */ | |
5223 | band_bwcap.band = cpu_to_le32(WLC_BAND_2G); | |
5224 | band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ); | |
5225 | err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap, | |
5226 | sizeof(band_bwcap)); | |
5227 | } else { | |
5228 | brcmf_dbg(INFO, "fallback to mimo_bw_cap\n"); | |
5229 | val = WLC_N_BW_40ALL; | |
5230 | err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val); | |
5231 | } | |
b48d8916 AS |
5232 | |
5233 | if (!err) { | |
5234 | /* update channel info in 2G band */ | |
5235 | pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL); | |
5236 | ||
5237 | if (pbuf == NULL) | |
5238 | return -ENOMEM; | |
5239 | ||
5240 | ch.band = BRCMU_CHAN_BAND_2G; | |
5241 | ch.bw = BRCMU_CHAN_BW_40; | |
fac7d2a3 | 5242 | ch.sb = BRCMU_CHAN_SB_NONE; |
b48d8916 AS |
5243 | ch.chnum = 0; |
5244 | cfg->d11inf.encchspec(&ch); | |
5245 | ||
5246 | /* pass encoded chanspec in query */ | |
5247 | *(__le16 *)pbuf = cpu_to_le16(ch.chspec); | |
5248 | ||
5249 | err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf, | |
5250 | BRCMF_DCMD_MEDLEN); | |
5251 | if (err) { | |
5252 | brcmf_err("get chanspecs error (%d)\n", err); | |
5253 | kfree(pbuf); | |
5254 | return err; | |
5255 | } | |
5256 | ||
5257 | band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ]; | |
5258 | list = (struct brcmf_chanspec_list *)pbuf; | |
5259 | num_chan = le32_to_cpu(list->count); | |
5260 | for (i = 0; i < num_chan; i++) { | |
5261 | ch.chspec = (u16)le32_to_cpu(list->element[i]); | |
5262 | cfg->d11inf.decchspec(&ch); | |
5263 | if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G)) | |
5264 | continue; | |
5265 | if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40)) | |
5266 | continue; | |
5267 | for (j = 0; j < band->n_channels; j++) { | |
5268 | if (band->channels[j].hw_value == ch.chnum) | |
5269 | break; | |
5270 | } | |
5271 | if (WARN_ON(j == band->n_channels)) | |
5272 | continue; | |
5273 | ||
5274 | brcmf_update_bw40_channel_flag(&band->channels[j], &ch); | |
5275 | } | |
fac7d2a3 | 5276 | kfree(pbuf); |
b48d8916 | 5277 | } |
aa70b4fa AS |
5278 | return err; |
5279 | } | |
5280 | ||
2375d970 AS |
5281 | static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[]) |
5282 | { | |
5283 | u32 band, mimo_bwcap; | |
5284 | int err; | |
5285 | ||
5286 | band = WLC_BAND_2G; | |
5287 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); | |
5288 | if (!err) { | |
5289 | bw_cap[IEEE80211_BAND_2GHZ] = band; | |
5290 | band = WLC_BAND_5G; | |
5291 | err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band); | |
5292 | if (!err) { | |
5293 | bw_cap[IEEE80211_BAND_5GHZ] = band; | |
5294 | return; | |
5295 | } | |
5296 | WARN_ON(1); | |
5297 | return; | |
5298 | } | |
5299 | brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n"); | |
5300 | mimo_bwcap = 0; | |
5301 | err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap); | |
5302 | if (err) | |
5303 | /* assume 20MHz if firmware does not give a clue */ | |
5304 | mimo_bwcap = WLC_N_BW_20ALL; | |
5305 | ||
5306 | switch (mimo_bwcap) { | |
5307 | case WLC_N_BW_40ALL: | |
5308 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT; | |
5309 | /* fall-thru */ | |
5310 | case WLC_N_BW_20IN2G_40IN5G: | |
5311 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT; | |
5312 | /* fall-thru */ | |
5313 | case WLC_N_BW_20ALL: | |
5314 | bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT; | |
5315 | bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT; | |
5316 | break; | |
5317 | default: | |
5318 | brcmf_err("invalid mimo_bw_cap value\n"); | |
5319 | } | |
5320 | } | |
d48200ba | 5321 | |
18d6c535 AS |
5322 | static void brcmf_update_ht_cap(struct ieee80211_supported_band *band, |
5323 | u32 bw_cap[2], u32 nchain) | |
5324 | { | |
5325 | band->ht_cap.ht_supported = true; | |
5326 | if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) { | |
5327 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
5328 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
5329 | } | |
5330 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
5331 | band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
5332 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
5333 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; | |
5334 | memset(band->ht_cap.mcs.rx_mask, 0xff, nchain); | |
5335 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
5336 | } | |
5337 | ||
5338 | static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp) | |
5339 | { | |
5340 | u16 mcs_map; | |
5341 | int i; | |
5342 | ||
5343 | for (i = 0, mcs_map = 0xFFFF; i < nchain; i++) | |
5344 | mcs_map = (mcs_map << 2) | supp; | |
5345 | ||
5346 | return cpu_to_le16(mcs_map); | |
5347 | } | |
5348 | ||
5349 | static void brcmf_update_vht_cap(struct ieee80211_supported_band *band, | |
5350 | u32 bw_cap[2], u32 nchain) | |
5351 | { | |
5352 | __le16 mcs_map; | |
5353 | ||
5354 | /* not allowed in 2.4G band */ | |
5355 | if (band->band == IEEE80211_BAND_2GHZ) | |
5356 | return; | |
5357 | ||
5358 | band->vht_cap.vht_supported = true; | |
5359 | /* 80MHz is mandatory */ | |
5360 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80; | |
5361 | if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) { | |
5362 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; | |
5363 | band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160; | |
5364 | } | |
5365 | /* all support 256-QAM */ | |
5366 | mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9); | |
5367 | band->vht_cap.vht_mcs.rx_mcs_map = mcs_map; | |
5368 | band->vht_cap.vht_mcs.tx_mcs_map = mcs_map; | |
5369 | } | |
5370 | ||
b48d8916 | 5371 | static int brcmf_setup_wiphybands(struct wiphy *wiphy) |
5b435de0 | 5372 | { |
b48d8916 | 5373 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
ac24be6f | 5374 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
18d6c535 AS |
5375 | u32 nmode = 0; |
5376 | u32 vhtmode = 0; | |
b48d8916 | 5377 | u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT }; |
4aca7a18 DK |
5378 | u32 rxchain; |
5379 | u32 nchain; | |
b48d8916 | 5380 | int err; |
d48200ba | 5381 | s32 i; |
2375d970 | 5382 | struct ieee80211_supported_band *band; |
5b435de0 | 5383 | |
18d6c535 | 5384 | (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode); |
d48200ba HM |
5385 | err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode); |
5386 | if (err) { | |
5387 | brcmf_err("nmode error (%d)\n", err); | |
5388 | } else { | |
2375d970 | 5389 | brcmf_get_bwcap(ifp, bw_cap); |
d48200ba | 5390 | } |
18d6c535 AS |
5391 | brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n", |
5392 | nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ], | |
5393 | bw_cap[IEEE80211_BAND_5GHZ]); | |
d48200ba | 5394 | |
4aca7a18 DK |
5395 | err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain); |
5396 | if (err) { | |
5397 | brcmf_err("rxchain error (%d)\n", err); | |
5398 | nchain = 1; | |
5399 | } else { | |
5400 | for (nchain = 0; rxchain; nchain++) | |
5401 | rxchain = rxchain & (rxchain - 1); | |
5402 | } | |
5403 | brcmf_dbg(INFO, "nchain=%d\n", nchain); | |
5404 | ||
b48d8916 | 5405 | err = brcmf_construct_chaninfo(cfg, bw_cap); |
d48200ba | 5406 | if (err) { |
b48d8916 | 5407 | brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err); |
d48200ba HM |
5408 | return err; |
5409 | } | |
5410 | ||
b48d8916 AS |
5411 | wiphy = cfg_to_wiphy(cfg); |
5412 | for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) { | |
5413 | band = wiphy->bands[i]; | |
5414 | if (band == NULL) | |
2375d970 | 5415 | continue; |
d48200ba | 5416 | |
18d6c535 AS |
5417 | if (nmode) |
5418 | brcmf_update_ht_cap(band, bw_cap, nchain); | |
5419 | if (vhtmode) | |
5420 | brcmf_update_vht_cap(band, bw_cap, nchain); | |
d48200ba HM |
5421 | } |
5422 | ||
b48d8916 | 5423 | return 0; |
5b435de0 AS |
5424 | } |
5425 | ||
aa70b4fa AS |
5426 | static const struct ieee80211_iface_limit brcmf_iface_limits[] = { |
5427 | { | |
5428 | .max = 2, | |
5429 | .types = BIT(NL80211_IFTYPE_STATION) | | |
5430 | BIT(NL80211_IFTYPE_ADHOC) | | |
5431 | BIT(NL80211_IFTYPE_AP) | |
5432 | }, | |
5433 | { | |
5434 | .max = 1, | |
5435 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
5436 | BIT(NL80211_IFTYPE_P2P_GO) | |
5437 | }, | |
5438 | { | |
5439 | .max = 1, | |
5440 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) | |
5441 | } | |
5442 | }; | |
5443 | static struct ieee80211_iface_combination brcmf_iface_combos[] = { | |
5444 | { | |
5445 | .max_interfaces = BRCMF_IFACE_MAX_CNT, | |
5446 | .num_different_channels = 1, | |
5447 | .n_limits = ARRAY_SIZE(brcmf_iface_limits), | |
5448 | .limits = brcmf_iface_limits | |
5449 | } | |
5450 | }; | |
5451 | ||
5452 | static const struct ieee80211_txrx_stypes | |
5453 | brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = { | |
5454 | [NL80211_IFTYPE_STATION] = { | |
5455 | .tx = 0xffff, | |
5456 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
5457 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
5458 | }, | |
5459 | [NL80211_IFTYPE_P2P_CLIENT] = { | |
5460 | .tx = 0xffff, | |
5461 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
5462 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
5463 | }, | |
5464 | [NL80211_IFTYPE_P2P_GO] = { | |
5465 | .tx = 0xffff, | |
5466 | .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | | |
5467 | BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | | |
5468 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | | |
5469 | BIT(IEEE80211_STYPE_DISASSOC >> 4) | | |
5470 | BIT(IEEE80211_STYPE_AUTH >> 4) | | |
5471 | BIT(IEEE80211_STYPE_DEAUTH >> 4) | | |
5472 | BIT(IEEE80211_STYPE_ACTION >> 4) | |
5473 | }, | |
5474 | [NL80211_IFTYPE_P2P_DEVICE] = { | |
5475 | .tx = 0xffff, | |
5476 | .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | | |
5477 | BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | |
5478 | } | |
5479 | }; | |
5480 | ||
5481 | static void brcmf_wiphy_pno_params(struct wiphy *wiphy) | |
5482 | { | |
5483 | /* scheduled scan settings */ | |
5484 | wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT; | |
5485 | wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT; | |
5486 | wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; | |
5487 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; | |
5488 | } | |
5489 | ||
4eb3af7c HM |
5490 | #ifdef CONFIG_PM |
5491 | static const struct wiphy_wowlan_support brcmf_wowlan_support = { | |
5492 | .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT, | |
b9a82f89 HM |
5493 | .n_patterns = BRCMF_WOWL_MAXPATTERNS, |
5494 | .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE, | |
5495 | .pattern_min_len = 1, | |
5496 | .max_pkt_offset = 1500, | |
4eb3af7c HM |
5497 | }; |
5498 | #endif | |
5499 | ||
5500 | static void brcmf_wiphy_wowl_params(struct wiphy *wiphy) | |
5501 | { | |
5502 | #ifdef CONFIG_PM | |
5503 | /* wowl settings */ | |
5504 | wiphy->wowlan = &brcmf_wowlan_support; | |
5505 | #endif | |
5506 | } | |
5507 | ||
b48d8916 | 5508 | static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) |
aa70b4fa | 5509 | { |
b48d8916 | 5510 | struct ieee80211_iface_combination ifc_combo; |
aa70b4fa AS |
5511 | wiphy->max_scan_ssids = WL_NUM_SCAN_MAX; |
5512 | wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX; | |
5513 | wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX; | |
5514 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
5515 | BIT(NL80211_IFTYPE_ADHOC) | | |
5516 | BIT(NL80211_IFTYPE_AP) | | |
5517 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
5518 | BIT(NL80211_IFTYPE_P2P_GO) | | |
5519 | BIT(NL80211_IFTYPE_P2P_DEVICE); | |
5520 | /* need VSDB firmware feature for concurrent channels */ | |
b48d8916 | 5521 | ifc_combo = brcmf_iface_combos[0]; |
aa70b4fa | 5522 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)) |
b48d8916 AS |
5523 | ifc_combo.num_different_channels = 2; |
5524 | wiphy->iface_combinations = kmemdup(&ifc_combo, | |
5525 | sizeof(ifc_combo), | |
5526 | GFP_KERNEL); | |
aa70b4fa | 5527 | wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos); |
aa70b4fa AS |
5528 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
5529 | wiphy->cipher_suites = __wl_cipher_suites; | |
5530 | wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites); | |
5531 | wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT | | |
5532 | WIPHY_FLAG_OFFCHAN_TX | | |
5533 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | | |
5534 | WIPHY_FLAG_SUPPORTS_TDLS; | |
5535 | if (!brcmf_roamoff) | |
5536 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; | |
5537 | wiphy->mgmt_stypes = brcmf_txrx_stypes; | |
5538 | wiphy->max_remain_on_channel_duration = 5000; | |
5539 | brcmf_wiphy_pno_params(wiphy); | |
aa70b4fa AS |
5540 | |
5541 | /* vendor commands/events support */ | |
5542 | wiphy->vendor_commands = brcmf_vendor_cmds; | |
5543 | wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1; | |
5544 | ||
4eb3af7c HM |
5545 | if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) |
5546 | brcmf_wiphy_wowl_params(wiphy); | |
5547 | ||
b48d8916 | 5548 | return brcmf_setup_wiphybands(wiphy); |
5b435de0 AS |
5549 | } |
5550 | ||
27a68fe3 | 5551 | static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg) |
5b435de0 AS |
5552 | { |
5553 | struct net_device *ndev; | |
5554 | struct wireless_dev *wdev; | |
40a23296 | 5555 | struct brcmf_if *ifp; |
5b435de0 AS |
5556 | s32 power_mode; |
5557 | s32 err = 0; | |
5558 | ||
27a68fe3 | 5559 | if (cfg->dongle_up) |
5b435de0 AS |
5560 | return err; |
5561 | ||
27a68fe3 | 5562 | ndev = cfg_to_ndev(cfg); |
5b435de0 | 5563 | wdev = ndev->ieee80211_ptr; |
40a23296 HM |
5564 | ifp = netdev_priv(ndev); |
5565 | ||
5566 | /* make sure RF is ready for work */ | |
5567 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0); | |
5b435de0 | 5568 | |
40a23296 HM |
5569 | brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME, |
5570 | WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME); | |
5b435de0 | 5571 | |
27a68fe3 | 5572 | power_mode = cfg->pwr_save ? PM_FAST : PM_OFF; |
40a23296 | 5573 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode); |
5b435de0 AS |
5574 | if (err) |
5575 | goto default_conf_out; | |
647c9ae0 AS |
5576 | brcmf_dbg(INFO, "power save set to %s\n", |
5577 | (power_mode ? "enabled" : "disabled")); | |
5b435de0 | 5578 | |
68ca395f | 5579 | err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT); |
5b435de0 AS |
5580 | if (err) |
5581 | goto default_conf_out; | |
5dd161ff FL |
5582 | err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype, |
5583 | NULL, NULL); | |
40a23296 | 5584 | if (err) |
5b435de0 | 5585 | goto default_conf_out; |
5b435de0 | 5586 | |
b3657453 HM |
5587 | brcmf_configure_arp_offload(ifp, true); |
5588 | ||
27a68fe3 | 5589 | cfg->dongle_up = true; |
40a23296 | 5590 | default_conf_out: |
5b435de0 AS |
5591 | |
5592 | return err; | |
5593 | ||
5594 | } | |
5595 | ||
bdf5ff51 | 5596 | static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp) |
5b435de0 | 5597 | { |
c1179033 | 5598 | set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
5b435de0 | 5599 | |
bdf5ff51 | 5600 | return brcmf_config_dongle(ifp->drvr->config); |
5b435de0 AS |
5601 | } |
5602 | ||
bdf5ff51 | 5603 | static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp) |
5b435de0 | 5604 | { |
bdf5ff51 | 5605 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
c1179033 | 5606 | |
5b435de0 AS |
5607 | /* |
5608 | * While going down, if associated with AP disassociate | |
5609 | * from AP to save power | |
5610 | */ | |
903e0eee AS |
5611 | if (check_vif_up(ifp->vif)) { |
5612 | brcmf_link_down(ifp->vif); | |
5b435de0 AS |
5613 | |
5614 | /* Make sure WPA_Supplicant receives all the event | |
5615 | generated due to DISASSOC call to the fw to keep | |
5616 | the state fw and WPA_Supplicant state consistent | |
5617 | */ | |
5618 | brcmf_delay(500); | |
5619 | } | |
5620 | ||
27a68fe3 | 5621 | brcmf_abort_scanning(cfg); |
c1179033 | 5622 | clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state); |
5b435de0 | 5623 | |
5b435de0 AS |
5624 | return 0; |
5625 | } | |
5626 | ||
bdf5ff51 | 5627 | s32 brcmf_cfg80211_up(struct net_device *ndev) |
5b435de0 | 5628 | { |
bdf5ff51 AS |
5629 | struct brcmf_if *ifp = netdev_priv(ndev); |
5630 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; | |
5b435de0 AS |
5631 | s32 err = 0; |
5632 | ||
27a68fe3 | 5633 | mutex_lock(&cfg->usr_sync); |
bdf5ff51 | 5634 | err = __brcmf_cfg80211_up(ifp); |
27a68fe3 | 5635 | mutex_unlock(&cfg->usr_sync); |
5b435de0 AS |
5636 | |
5637 | return err; | |
5638 | } | |
5639 | ||
bdf5ff51 | 5640 | s32 brcmf_cfg80211_down(struct net_device *ndev) |
5b435de0 | 5641 | { |
bdf5ff51 AS |
5642 | struct brcmf_if *ifp = netdev_priv(ndev); |
5643 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; | |
5b435de0 AS |
5644 | s32 err = 0; |
5645 | ||
27a68fe3 | 5646 | mutex_lock(&cfg->usr_sync); |
bdf5ff51 | 5647 | err = __brcmf_cfg80211_down(ifp); |
27a68fe3 | 5648 | mutex_unlock(&cfg->usr_sync); |
5b435de0 AS |
5649 | |
5650 | return err; | |
5651 | } | |
5652 | ||
a7965fbb AS |
5653 | enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp) |
5654 | { | |
5655 | struct wireless_dev *wdev = &ifp->vif->wdev; | |
5656 | ||
5657 | return wdev->iftype; | |
5658 | } | |
5659 | ||
e843bb19 | 5660 | bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, unsigned long state) |
9f440b7b AS |
5661 | { |
5662 | struct brcmf_cfg80211_vif *vif; | |
9f440b7b AS |
5663 | |
5664 | list_for_each_entry(vif, &cfg->vif_list, list) { | |
5665 | if (test_bit(state, &vif->sme_state)) | |
e843bb19 | 5666 | return true; |
9f440b7b | 5667 | } |
e843bb19 | 5668 | return false; |
9f440b7b | 5669 | } |
d3c0b633 AS |
5670 | |
5671 | static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event, | |
5672 | u8 action) | |
5673 | { | |
5674 | u8 evt_action; | |
5675 | ||
5676 | mutex_lock(&event->vif_event_lock); | |
5677 | evt_action = event->action; | |
5678 | mutex_unlock(&event->vif_event_lock); | |
5679 | return evt_action == action; | |
5680 | } | |
5681 | ||
5682 | void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, | |
5683 | struct brcmf_cfg80211_vif *vif) | |
5684 | { | |
5685 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
5686 | ||
5687 | mutex_lock(&event->vif_event_lock); | |
5688 | event->vif = vif; | |
5689 | event->action = 0; | |
5690 | mutex_unlock(&event->vif_event_lock); | |
5691 | } | |
5692 | ||
5693 | bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg) | |
5694 | { | |
5695 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
5696 | bool armed; | |
5697 | ||
5698 | mutex_lock(&event->vif_event_lock); | |
5699 | armed = event->vif != NULL; | |
5700 | mutex_unlock(&event->vif_event_lock); | |
5701 | ||
5702 | return armed; | |
5703 | } | |
5704 | int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg, | |
5705 | u8 action, ulong timeout) | |
5706 | { | |
5707 | struct brcmf_cfg80211_vif_event *event = &cfg->vif_event; | |
5708 | ||
5709 | return wait_event_timeout(event->vif_wq, | |
5710 | vif_event_equals(event, action), timeout); | |
5711 | } | |
5712 | ||
b48d8916 AS |
5713 | static void brcmf_free_wiphy(struct wiphy *wiphy) |
5714 | { | |
5715 | kfree(wiphy->iface_combinations); | |
5716 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { | |
5717 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels); | |
5718 | kfree(wiphy->bands[IEEE80211_BAND_2GHZ]); | |
5719 | } | |
5720 | if (wiphy->bands[IEEE80211_BAND_5GHZ]) { | |
5721 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels); | |
5722 | kfree(wiphy->bands[IEEE80211_BAND_5GHZ]); | |
5723 | } | |
5724 | wiphy_free(wiphy); | |
5725 | } | |
5726 | ||
ccfd1e81 AS |
5727 | struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, |
5728 | struct device *busdev) | |
5729 | { | |
5730 | struct net_device *ndev = drvr->iflist[0]->ndev; | |
5731 | struct brcmf_cfg80211_info *cfg; | |
5732 | struct wiphy *wiphy; | |
5733 | struct brcmf_cfg80211_vif *vif; | |
5734 | struct brcmf_if *ifp; | |
5735 | s32 err = 0; | |
5736 | s32 io_type; | |
b48d8916 | 5737 | u16 *cap = NULL; |
ccfd1e81 AS |
5738 | |
5739 | if (!ndev) { | |
5740 | brcmf_err("ndev is invalid\n"); | |
5741 | return NULL; | |
5742 | } | |
5743 | ||
5744 | ifp = netdev_priv(ndev); | |
b48d8916 AS |
5745 | wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info)); |
5746 | if (!wiphy) { | |
5747 | brcmf_err("Could not allocate wiphy device\n"); | |
ccfd1e81 | 5748 | return NULL; |
b48d8916 AS |
5749 | } |
5750 | set_wiphy_dev(wiphy, busdev); | |
ccfd1e81 AS |
5751 | |
5752 | cfg = wiphy_priv(wiphy); | |
5753 | cfg->wiphy = wiphy; | |
5754 | cfg->pub = drvr; | |
5755 | init_vif_event(&cfg->vif_event); | |
5756 | INIT_LIST_HEAD(&cfg->vif_list); | |
5757 | ||
5758 | vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false); | |
b48d8916 AS |
5759 | if (IS_ERR(vif)) |
5760 | goto wiphy_out; | |
ccfd1e81 AS |
5761 | |
5762 | vif->ifp = ifp; | |
5763 | vif->wdev.netdev = ndev; | |
5764 | ndev->ieee80211_ptr = &vif->wdev; | |
5765 | SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy)); | |
5766 | ||
5767 | err = wl_init_priv(cfg); | |
5768 | if (err) { | |
5769 | brcmf_err("Failed to init iwm_priv (%d)\n", err); | |
b48d8916 AS |
5770 | brcmf_free_vif(vif); |
5771 | goto wiphy_out; | |
ccfd1e81 AS |
5772 | } |
5773 | ifp->vif = vif; | |
5774 | ||
b48d8916 AS |
5775 | /* determine d11 io type before wiphy setup */ |
5776 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type); | |
ccfd1e81 | 5777 | if (err) { |
b48d8916 AS |
5778 | brcmf_err("Failed to get D11 version (%d)\n", err); |
5779 | goto priv_out; | |
ccfd1e81 | 5780 | } |
b48d8916 AS |
5781 | cfg->d11inf.io_type = (u8)io_type; |
5782 | brcmu_d11_attach(&cfg->d11inf); | |
5783 | ||
5784 | err = brcmf_setup_wiphy(wiphy, ifp); | |
5785 | if (err < 0) | |
5786 | goto priv_out; | |
5787 | ||
5788 | brcmf_dbg(INFO, "Registering custom regulatory\n"); | |
5789 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; | |
5790 | wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom); | |
5791 | ||
5792 | /* firmware defaults to 40MHz disabled in 2G band. We signal | |
5793 | * cfg80211 here that we do and have it decide we can enable | |
5794 | * it. But first check if device does support 2G operation. | |
5795 | */ | |
5796 | if (wiphy->bands[IEEE80211_BAND_2GHZ]) { | |
5797 | cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap; | |
5798 | *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
5799 | } | |
5800 | err = wiphy_register(wiphy); | |
5801 | if (err < 0) { | |
5802 | brcmf_err("Could not register wiphy device (%d)\n", err); | |
5803 | goto priv_out; | |
ccfd1e81 AS |
5804 | } |
5805 | ||
5806 | /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(), | |
5807 | * setup 40MHz in 2GHz band and enable OBSS scanning. | |
5808 | */ | |
b48d8916 AS |
5809 | if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) { |
5810 | err = brcmf_enable_bw40_2g(cfg); | |
ccfd1e81 AS |
5811 | if (!err) |
5812 | err = brcmf_fil_iovar_int_set(ifp, "obss_coex", | |
5813 | BRCMF_OBSS_COEX_AUTO); | |
b48d8916 AS |
5814 | else |
5815 | *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
ccfd1e81 | 5816 | } |
ccfd1e81 | 5817 | |
b48d8916 | 5818 | err = brcmf_p2p_attach(cfg); |
ccfd1e81 | 5819 | if (err) { |
b48d8916 AS |
5820 | brcmf_err("P2P initilisation failed (%d)\n", err); |
5821 | goto wiphy_unreg_out; | |
5822 | } | |
5823 | err = brcmf_btcoex_attach(cfg); | |
5824 | if (err) { | |
5825 | brcmf_err("BT-coex initialisation failed (%d)\n", err); | |
5826 | brcmf_p2p_detach(&cfg->p2p); | |
5827 | goto wiphy_unreg_out; | |
ccfd1e81 AS |
5828 | } |
5829 | ||
b48d8916 | 5830 | err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1); |
ccfd1e81 | 5831 | if (err) { |
b48d8916 AS |
5832 | brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err); |
5833 | wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS; | |
70b7d94b HM |
5834 | } else { |
5835 | brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT, | |
5836 | brcmf_notify_tdls_peer_event); | |
ccfd1e81 | 5837 | } |
ccfd1e81 AS |
5838 | |
5839 | return cfg; | |
5840 | ||
b48d8916 AS |
5841 | wiphy_unreg_out: |
5842 | wiphy_unregister(cfg->wiphy); | |
5843 | priv_out: | |
ccfd1e81 | 5844 | wl_deinit_priv(cfg); |
ccfd1e81 | 5845 | brcmf_free_vif(vif); |
b48d8916 AS |
5846 | wiphy_out: |
5847 | brcmf_free_wiphy(wiphy); | |
ccfd1e81 AS |
5848 | return NULL; |
5849 | } | |
5850 | ||
5851 | void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg) | |
5852 | { | |
5853 | if (!cfg) | |
5854 | return; | |
5855 | ||
5856 | WARN_ON(!list_empty(&cfg->vif_list)); | |
5857 | wiphy_unregister(cfg->wiphy); | |
5858 | brcmf_btcoex_detach(cfg); | |
c3da74bb | 5859 | brcmf_p2p_detach(&cfg->p2p); |
ccfd1e81 | 5860 | wl_deinit_priv(cfg); |
b48d8916 | 5861 | brcmf_free_wiphy(cfg->wiphy); |
ccfd1e81 | 5862 | } |