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