1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2010 Broadcom Corporation
6 /* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
8 #include <linux/kernel.h>
9 #include <linux/etherdevice.h>
10 #include <linux/module.h>
11 #include <linux/vmalloc.h>
12 #include <linux/ctype.h>
13 #include <net/cfg80211.h>
14 #include <net/netlink.h>
15 #include <uapi/linux/if_arp.h>
17 #include <brcmu_utils.h>
19 #include <brcmu_wifi.h>
20 #include <brcm_hw_ids.h>
23 #include "tracepoint.h"
24 #include "fwil_types.h"
37 #define BRCMF_SCAN_IE_LEN_MAX 2048
39 #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
40 #define WPA_OUI_TYPE 1
41 #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
42 #define WME_OUI_TYPE 2
43 #define WPS_OUI_TYPE 4
45 #define VS_IE_FIXED_HDR_LEN 6
46 #define WPA_IE_VERSION_LEN 2
47 #define WPA_IE_MIN_OUI_LEN 4
48 #define WPA_IE_SUITE_COUNT_LEN 2
50 #define WPA_CIPHER_NONE 0 /* None */
51 #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
52 #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
53 #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
54 #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
56 #define RSN_AKM_NONE 0 /* None (IBSS) */
57 #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
58 #define RSN_AKM_PSK 2 /* Pre-shared Key */
59 #define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */
60 #define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */
61 #define RSN_AKM_SAE 8 /* SAE */
62 #define RSN_CAP_LEN 2 /* Length of RSN capabilities */
63 #define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3))
64 #define RSN_CAP_MFPR_MASK BIT(6)
65 #define RSN_CAP_MFPC_MASK BIT(7)
66 #define RSN_PMKID_COUNT_LEN 2
68 #define VNDR_IE_CMD_LEN 4 /* length of the set command
69 * string :"add", "del" (+ NUL)
71 #define VNDR_IE_COUNT_OFFSET 4
72 #define VNDR_IE_PKTFLAG_OFFSET 8
73 #define VNDR_IE_VSIE_OFFSET 12
74 #define VNDR_IE_HDR_SIZE 12
75 #define VNDR_IE_PARSE_LIMIT 5
77 #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
78 #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
80 #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
81 #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
82 #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
84 #define BRCMF_SCAN_CHANNEL_TIME 40
85 #define BRCMF_SCAN_UNASSOC_TIME 40
86 #define BRCMF_SCAN_PASSIVE_TIME 120
88 #define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000)
90 #define BRCMF_PS_MAX_TIMEOUT_MS 2000
92 #define MGMT_AUTH_FRAME_DWELL_TIME 4000
93 #define MGMT_AUTH_FRAME_WAIT_TIME (MGMT_AUTH_FRAME_DWELL_TIME + 100)
95 /* Dump obss definitions */
96 #define ACS_MSRMNT_DELAY 80
97 #define CHAN_NOISE_DUMMY (-80)
98 #define OBSS_TOKEN_IDX 15
99 #define IBSS_TOKEN_IDX 15
100 #define TX_TOKEN_IDX 14
101 #define CTG_TOKEN_IDX 13
102 #define PKT_TOKEN_IDX 15
103 #define IDLE_TOKEN_IDX 12
105 #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
106 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
108 #define BRCMF_MAX_CHANSPEC_LIST \
109 (BRCMF_DCMD_MEDLEN / sizeof(__le32) - 1)
111 struct brcmf_dump_survey {
120 struct cca_stats_n_flags {
121 u32 msrmnt_time; /* Time for Measurement (msec) */
122 u32 msrmnt_done; /* flag set when measurement complete */
126 struct cca_msrmnt_query {
131 static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
133 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
134 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
141 #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
142 #define RATETAB_ENT(_rateid, _flags) \
144 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
145 .hw_value = (_rateid), \
149 static struct ieee80211_rate __wl_rates[] = {
150 RATETAB_ENT(BRCM_RATE_1M, 0),
151 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
152 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
153 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
154 RATETAB_ENT(BRCM_RATE_6M, 0),
155 RATETAB_ENT(BRCM_RATE_9M, 0),
156 RATETAB_ENT(BRCM_RATE_12M, 0),
157 RATETAB_ENT(BRCM_RATE_18M, 0),
158 RATETAB_ENT(BRCM_RATE_24M, 0),
159 RATETAB_ENT(BRCM_RATE_36M, 0),
160 RATETAB_ENT(BRCM_RATE_48M, 0),
161 RATETAB_ENT(BRCM_RATE_54M, 0),
164 #define wl_g_rates (__wl_rates + 0)
165 #define wl_g_rates_size ARRAY_SIZE(__wl_rates)
166 #define wl_a_rates (__wl_rates + 4)
167 #define wl_a_rates_size (wl_g_rates_size - 4)
169 #define CHAN2G(_channel, _freq) { \
170 .band = NL80211_BAND_2GHZ, \
171 .center_freq = (_freq), \
172 .hw_value = (_channel), \
173 .max_antenna_gain = 0, \
177 #define CHAN5G(_channel) { \
178 .band = NL80211_BAND_5GHZ, \
179 .center_freq = 5000 + (5 * (_channel)), \
180 .hw_value = (_channel), \
181 .max_antenna_gain = 0, \
185 static struct ieee80211_channel __wl_2ghz_channels[] = {
186 CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427),
187 CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447),
188 CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467),
189 CHAN2G(13, 2472), CHAN2G(14, 2484)
192 static struct ieee80211_channel __wl_5ghz_channels[] = {
193 CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42),
194 CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56),
195 CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108),
196 CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128),
197 CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149),
198 CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165)
201 /* Band templates duplicated per wiphy. The channel info
202 * above is added to the band during setup.
204 static const struct ieee80211_supported_band __wl_band_2ghz = {
205 .band = NL80211_BAND_2GHZ,
206 .bitrates = wl_g_rates,
207 .n_bitrates = wl_g_rates_size,
210 static const struct ieee80211_supported_band __wl_band_5ghz = {
211 .band = NL80211_BAND_5GHZ,
212 .bitrates = wl_a_rates,
213 .n_bitrates = wl_a_rates_size,
216 /* This is to override regulatory domains defined in cfg80211 module (reg.c)
217 * By default world regulatory domain defined in reg.c puts the flags
218 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
219 * With respect to these flags, wpa_supplicant doesn't * start p2p
220 * operations on 5GHz channels. All the changes in world regulatory
221 * domain are to be done here.
223 static const struct ieee80211_regdomain brcmf_regdom = {
227 /* IEEE 802.11b/g, channels 1..11 */
228 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
230 /* IEEE 802.11 channel 14 - Only JP enables
231 * this and for 802.11b only
233 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
234 /* IEEE 802.11a, channel 36..64 */
235 REG_RULE(5150-10, 5350+10, 160, 6, 20, 0),
236 /* IEEE 802.11a, channel 100..165 */
237 REG_RULE(5470-10, 5850+10, 160, 6, 20, 0), }
240 /* Note: brcmf_cipher_suites is an array of int defining which cipher suites
241 * are supported. A pointer to this array and the number of entries is passed
242 * on to upper layers. AES_CMAC defines whether or not the driver supports MFP.
243 * So the cipher suite AES_CMAC has to be the last one in the array, and when
244 * device does not support MFP then the number of suites will be decreased by 1
246 static const u32 brcmf_cipher_suites[] = {
247 WLAN_CIPHER_SUITE_WEP40,
248 WLAN_CIPHER_SUITE_WEP104,
249 WLAN_CIPHER_SUITE_TKIP,
250 WLAN_CIPHER_SUITE_CCMP,
251 /* Keep as last entry: */
252 WLAN_CIPHER_SUITE_AES_CMAC
255 /* Vendor specific ie. id = 221, oui and type defines exact ie */
256 struct brcmf_vs_tlv {
263 struct parsed_vndr_ie_info {
265 u32 ie_len; /* total length including id & length field */
266 struct brcmf_vs_tlv vndrie;
269 struct parsed_vndr_ies {
271 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
274 #define WL_INTERFACE_CREATE_VER_1 1
275 #define WL_INTERFACE_CREATE_VER_2 2
276 #define WL_INTERFACE_CREATE_VER_3 3
277 #define WL_INTERFACE_CREATE_VER_MAX WL_INTERFACE_CREATE_VER_3
279 #define WL_INTERFACE_MAC_DONT_USE 0x0
280 #define WL_INTERFACE_MAC_USE 0x2
282 #define WL_INTERFACE_CREATE_STA 0x0
283 #define WL_INTERFACE_CREATE_AP 0x1
285 struct wl_interface_create_v1 {
286 u16 ver; /* structure version */
287 u32 flags; /* flags for operation */
288 u8 mac_addr[ETH_ALEN]; /* MAC address */
289 u32 wlc_index; /* optional for wlc index */
292 struct wl_interface_create_v2 {
293 u16 ver; /* structure version */
295 u32 flags; /* flags for operation */
296 u8 mac_addr[ETH_ALEN]; /* MAC address */
297 u8 iftype; /* type of interface created */
299 u32 wlc_index; /* optional for wlc index */
302 struct wl_interface_create_v3 {
303 u16 ver; /* structure version */
304 u16 len; /* length of structure + data */
305 u16 fixed_len; /* length of structure */
306 u8 iftype; /* type of interface created */
307 u8 wlc_index; /* optional for wlc index */
308 u32 flags; /* flags for operation */
309 u8 mac_addr[ETH_ALEN]; /* MAC address */
310 u8 bssid[ETH_ALEN]; /* optional for BSSID */
311 u8 if_index; /* interface index request */
313 u8 data[]; /* Optional for specific data */
316 static u8 nl80211_band_to_fwil(enum nl80211_band band)
319 case NL80211_BAND_2GHZ:
321 case NL80211_BAND_5GHZ:
330 static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
331 struct cfg80211_chan_def *ch)
333 struct brcmu_chan ch_inf;
336 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
337 ch->chan->center_freq, ch->center_freq1, ch->width);
338 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
339 primary_offset = ch->chan->center_freq - ch->center_freq1;
341 case NL80211_CHAN_WIDTH_20:
342 case NL80211_CHAN_WIDTH_20_NOHT:
343 ch_inf.bw = BRCMU_CHAN_BW_20;
344 WARN_ON(primary_offset != 0);
346 case NL80211_CHAN_WIDTH_40:
347 ch_inf.bw = BRCMU_CHAN_BW_40;
348 if (primary_offset > 0)
349 ch_inf.sb = BRCMU_CHAN_SB_U;
351 ch_inf.sb = BRCMU_CHAN_SB_L;
353 case NL80211_CHAN_WIDTH_80:
354 ch_inf.bw = BRCMU_CHAN_BW_80;
355 if (primary_offset == -30)
356 ch_inf.sb = BRCMU_CHAN_SB_LL;
357 else if (primary_offset == -10)
358 ch_inf.sb = BRCMU_CHAN_SB_LU;
359 else if (primary_offset == 10)
360 ch_inf.sb = BRCMU_CHAN_SB_UL;
362 ch_inf.sb = BRCMU_CHAN_SB_UU;
364 case NL80211_CHAN_WIDTH_160:
365 ch_inf.bw = BRCMU_CHAN_BW_160;
366 if (primary_offset == -70)
367 ch_inf.sb = BRCMU_CHAN_SB_LLL;
368 else if (primary_offset == -50)
369 ch_inf.sb = BRCMU_CHAN_SB_LLU;
370 else if (primary_offset == -30)
371 ch_inf.sb = BRCMU_CHAN_SB_LUL;
372 else if (primary_offset == -10)
373 ch_inf.sb = BRCMU_CHAN_SB_LUU;
374 else if (primary_offset == 10)
375 ch_inf.sb = BRCMU_CHAN_SB_ULL;
376 else if (primary_offset == 30)
377 ch_inf.sb = BRCMU_CHAN_SB_ULU;
378 else if (primary_offset == 50)
379 ch_inf.sb = BRCMU_CHAN_SB_UUL;
381 ch_inf.sb = BRCMU_CHAN_SB_UUU;
383 case NL80211_CHAN_WIDTH_80P80:
384 case NL80211_CHAN_WIDTH_5:
385 case NL80211_CHAN_WIDTH_10:
389 switch (ch->chan->band) {
390 case NL80211_BAND_2GHZ:
391 ch_inf.band = BRCMU_CHAN_BAND_2G;
393 case NL80211_BAND_5GHZ:
394 ch_inf.band = BRCMU_CHAN_BAND_5G;
396 case NL80211_BAND_60GHZ:
400 d11inf->encchspec(&ch_inf);
402 brcmf_dbg(TRACE, "chanspec: 0x%x\n", ch_inf.chspec);
403 return ch_inf.chspec;
406 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
407 struct ieee80211_channel *ch)
409 struct brcmu_chan ch_inf;
411 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
412 ch_inf.bw = BRCMU_CHAN_BW_20;
413 d11inf->encchspec(&ch_inf);
415 return ch_inf.chspec;
418 /* Traverse a string of 1-byte tag/1-byte length/variable-length value
419 * triples, returning a pointer to the substring whose first element
422 static const struct brcmf_tlv *
423 brcmf_parse_tlvs(const void *buf, int buflen, uint key)
425 const struct brcmf_tlv *elt = buf;
428 /* find tagged parameter */
429 while (totlen >= TLV_HDR_LEN) {
432 /* validate remaining totlen */
433 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
436 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
437 totlen -= (len + TLV_HDR_LEN);
443 /* Is any of the tlvs the expected entry? If
444 * not update the tlvs buffer pointer/length.
447 brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
448 const u8 *oui, u32 oui_len, u8 type)
450 /* If the contents match the OUI and the type */
451 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
452 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
453 type == ie[TLV_BODY_OFF + oui_len]) {
459 /* point to the next ie */
460 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
461 /* calculate the length of the rest of the buffer */
462 *tlvs_len -= (int)(ie - *tlvs);
463 /* update the pointer to the start of the buffer */
469 static struct brcmf_vs_tlv *
470 brcmf_find_wpaie(const u8 *parse, u32 len)
472 const struct brcmf_tlv *ie;
474 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
475 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
476 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
477 return (struct brcmf_vs_tlv *)ie;
482 static struct brcmf_vs_tlv *
483 brcmf_find_wpsie(const u8 *parse, u32 len)
485 const struct brcmf_tlv *ie;
487 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
488 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
489 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
490 return (struct brcmf_vs_tlv *)ie;
495 static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
496 struct brcmf_cfg80211_vif *vif,
497 enum nl80211_iftype new_type)
499 struct brcmf_cfg80211_vif *pos;
500 bool check_combos = false;
502 struct iface_combination_params params = {
503 .num_different_channels = 1,
506 list_for_each_entry(pos, &cfg->vif_list, list)
508 params.iftype_num[new_type]++;
510 /* concurrent interfaces so need check combinations */
512 params.iftype_num[pos->wdev.iftype]++;
516 ret = cfg80211_check_combinations(cfg->wiphy, ¶ms);
521 static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
522 enum nl80211_iftype new_type)
524 struct brcmf_cfg80211_vif *pos;
525 struct iface_combination_params params = {
526 .num_different_channels = 1,
529 list_for_each_entry(pos, &cfg->vif_list, list)
530 params.iftype_num[pos->wdev.iftype]++;
532 params.iftype_num[new_type]++;
533 return cfg80211_check_combinations(cfg->wiphy, ¶ms);
536 static void convert_key_from_CPU(struct brcmf_wsec_key *key,
537 struct brcmf_wsec_key_le *key_le)
539 key_le->index = cpu_to_le32(key->index);
540 key_le->len = cpu_to_le32(key->len);
541 key_le->algo = cpu_to_le32(key->algo);
542 key_le->flags = cpu_to_le32(key->flags);
543 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
544 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
545 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
546 memcpy(key_le->data, key->data, sizeof(key->data));
547 memcpy(key_le->ea, key->ea, sizeof(key->ea));
551 send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
553 struct brcmf_pub *drvr = ifp->drvr;
555 struct brcmf_wsec_key_le key_le;
557 convert_key_from_CPU(key, &key_le);
559 brcmf_netdev_wait_pend8021x(ifp);
561 err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
565 bphy_err(drvr, "wsec_key error (%d)\n", err);
570 brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
572 struct brcmf_cfg80211_vif *vif;
573 struct brcmf_if *ifp;
575 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
578 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
579 (wdev->iftype == NL80211_IFTYPE_AP) ||
580 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
581 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
584 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
588 static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr)
592 for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) {
593 /* bsscfgidx 1 is reserved for legacy P2P */
596 if (!drvr->iflist[bsscfgidx])
603 static void brcmf_set_vif_sta_macaddr(struct brcmf_if *ifp, u8 *mac_addr)
605 u8 mac_idx = ifp->drvr->sta_mac_idx;
607 /* set difference MAC address with locally administered bit */
608 memcpy(mac_addr, ifp->mac_addr, ETH_ALEN);
610 mac_addr[3] ^= mac_idx ? 0xC0 : 0xA0;
612 mac_idx = mac_idx % 2;
613 ifp->drvr->sta_mac_idx = mac_idx;
616 static int brcmf_cfg80211_request_sta_if(struct brcmf_if *ifp, u8 *macaddr)
618 struct wl_interface_create_v1 iface_v1;
619 struct wl_interface_create_v2 iface_v2;
620 struct wl_interface_create_v3 iface_v3;
621 u32 iface_create_ver;
624 /* interface_create version 1 */
625 memset(&iface_v1, 0, sizeof(iface_v1));
626 iface_v1.ver = WL_INTERFACE_CREATE_VER_1;
627 iface_v1.flags = WL_INTERFACE_CREATE_STA |
628 WL_INTERFACE_MAC_USE;
629 if (!is_zero_ether_addr(macaddr))
630 memcpy(iface_v1.mac_addr, macaddr, ETH_ALEN);
632 brcmf_set_vif_sta_macaddr(ifp, iface_v1.mac_addr);
634 err = brcmf_fil_iovar_data_get(ifp, "interface_create",
638 brcmf_info("failed to create interface(v1), err=%d\n",
641 brcmf_dbg(INFO, "interface created(v1)\n");
645 /* interface_create version 2 */
646 memset(&iface_v2, 0, sizeof(iface_v2));
647 iface_v2.ver = WL_INTERFACE_CREATE_VER_2;
648 iface_v2.flags = WL_INTERFACE_MAC_USE;
649 iface_v2.iftype = WL_INTERFACE_CREATE_STA;
650 if (!is_zero_ether_addr(macaddr))
651 memcpy(iface_v2.mac_addr, macaddr, ETH_ALEN);
653 brcmf_set_vif_sta_macaddr(ifp, iface_v2.mac_addr);
655 err = brcmf_fil_iovar_data_get(ifp, "interface_create",
659 brcmf_info("failed to create interface(v2), err=%d\n",
662 brcmf_dbg(INFO, "interface created(v2)\n");
666 /* interface_create version 3+ */
667 /* get supported version from firmware side */
668 iface_create_ver = 0;
669 err = brcmf_fil_bsscfg_int_get(ifp, "interface_create",
672 brcmf_err("fail to get supported version, err=%d\n", err);
676 switch (iface_create_ver) {
677 case WL_INTERFACE_CREATE_VER_3:
678 memset(&iface_v3, 0, sizeof(iface_v3));
679 iface_v3.ver = WL_INTERFACE_CREATE_VER_3;
680 iface_v3.flags = WL_INTERFACE_MAC_USE;
681 iface_v3.iftype = WL_INTERFACE_CREATE_STA;
682 if (!is_zero_ether_addr(macaddr))
683 memcpy(iface_v3.mac_addr, macaddr, ETH_ALEN);
685 brcmf_set_vif_sta_macaddr(ifp, iface_v3.mac_addr);
687 err = brcmf_fil_iovar_data_get(ifp, "interface_create",
692 brcmf_dbg(INFO, "interface created(v3)\n");
695 brcmf_err("not support interface create(v%d)\n",
702 brcmf_info("station interface creation failed (%d)\n",
710 static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
712 struct wl_interface_create_v1 iface_v1;
713 struct wl_interface_create_v2 iface_v2;
714 struct wl_interface_create_v3 iface_v3;
715 u32 iface_create_ver;
716 struct brcmf_pub *drvr = ifp->drvr;
717 struct brcmf_mbss_ssid_le mbss_ssid_le;
721 /* interface_create version 1 */
722 memset(&iface_v1, 0, sizeof(iface_v1));
723 iface_v1.ver = WL_INTERFACE_CREATE_VER_1;
724 iface_v1.flags = WL_INTERFACE_CREATE_AP |
725 WL_INTERFACE_MAC_USE;
727 brcmf_set_vif_sta_macaddr(ifp, iface_v1.mac_addr);
729 err = brcmf_fil_iovar_data_get(ifp, "interface_create",
733 brcmf_info("failed to create interface(v1), err=%d\n",
736 brcmf_dbg(INFO, "interface created(v1)\n");
740 /* interface_create version 2 */
741 memset(&iface_v2, 0, sizeof(iface_v2));
742 iface_v2.ver = WL_INTERFACE_CREATE_VER_2;
743 iface_v2.flags = WL_INTERFACE_MAC_USE;
744 iface_v2.iftype = WL_INTERFACE_CREATE_AP;
746 brcmf_set_vif_sta_macaddr(ifp, iface_v2.mac_addr);
748 err = brcmf_fil_iovar_data_get(ifp, "interface_create",
752 brcmf_info("failed to create interface(v2), err=%d\n",
755 brcmf_dbg(INFO, "interface created(v2)\n");
759 /* interface_create version 3+ */
760 /* get supported version from firmware side */
761 iface_create_ver = 0;
762 err = brcmf_fil_bsscfg_int_get(ifp, "interface_create",
765 brcmf_err("fail to get supported version, err=%d\n", err);
769 switch (iface_create_ver) {
770 case WL_INTERFACE_CREATE_VER_3:
771 memset(&iface_v3, 0, sizeof(iface_v3));
772 iface_v3.ver = WL_INTERFACE_CREATE_VER_3;
773 iface_v3.flags = WL_INTERFACE_MAC_USE;
774 iface_v3.iftype = WL_INTERFACE_CREATE_AP;
775 brcmf_set_vif_sta_macaddr(ifp, iface_v3.mac_addr);
777 err = brcmf_fil_iovar_data_get(ifp, "interface_create",
782 brcmf_dbg(INFO, "interface created(v3)\n");
785 brcmf_err("not support interface create(v%d)\n",
792 brcmf_info("Does not support interface_create (%d)\n",
794 memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
795 bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr);
799 mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
800 mbss_ssid_le.SSID_len = cpu_to_le32(5);
801 sprintf(mbss_ssid_le.SSID, "ssid%d", bsscfgidx);
803 err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
804 sizeof(mbss_ssid_le));
807 bphy_err(drvr, "setting ssid failed %d\n", err);
814 * brcmf_apsta_add_vif() - create a new AP or STA virtual interface
816 * @wiphy: wiphy device of new interface.
817 * @name: name of the new interface.
818 * @params: contains mac address for AP or STA device.
819 * @type: interface type.
822 struct wireless_dev *brcmf_apsta_add_vif(struct wiphy *wiphy, const char *name,
823 struct vif_params *params,
824 enum nl80211_iftype type)
826 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
827 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
828 struct brcmf_pub *drvr = cfg->pub;
829 struct brcmf_cfg80211_vif *vif;
832 if (type != NL80211_IFTYPE_STATION && type != NL80211_IFTYPE_AP)
833 return ERR_PTR(-EINVAL);
835 if (brcmf_cfg80211_vif_event_armed(cfg))
836 return ERR_PTR(-EBUSY);
838 brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
840 vif = brcmf_alloc_vif(cfg, type);
842 return (struct wireless_dev *)vif;
844 brcmf_cfg80211_arm_vif_event(cfg, vif);
846 if (type == NL80211_IFTYPE_STATION)
847 err = brcmf_cfg80211_request_sta_if(ifp, params->macaddr);
849 err = brcmf_cfg80211_request_ap_if(ifp);
851 brcmf_cfg80211_arm_vif_event(cfg, NULL);
855 /* wait for firmware event */
856 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD,
857 BRCMF_VIF_EVENT_TIMEOUT);
858 brcmf_cfg80211_arm_vif_event(cfg, NULL);
860 bphy_err(drvr, "timeout occurred\n");
865 /* interface created in firmware */
868 bphy_err(drvr, "no if pointer provided\n");
873 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
874 err = brcmf_net_attach(ifp, true);
876 bphy_err(drvr, "Registering netdevice failed\n");
877 free_netdev(ifp->ndev);
881 return &ifp->vif->wdev;
888 static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
890 enum nl80211_iftype iftype;
892 iftype = vif->wdev.iftype;
893 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
896 static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
898 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
902 * brcmf_mon_add_vif() - create monitor mode virtual interface
904 * @wiphy: wiphy device of new interface.
905 * @name: name of the new interface.
907 static struct wireless_dev *brcmf_mon_add_vif(struct wiphy *wiphy,
910 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
911 struct brcmf_cfg80211_vif *vif;
912 struct net_device *ndev;
913 struct brcmf_if *ifp;
916 if (cfg->pub->mon_if) {
921 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_MONITOR);
927 ndev = alloc_netdev(sizeof(*ifp), name, NET_NAME_UNKNOWN, ether_setup);
932 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
933 ndev->ieee80211_ptr = &vif->wdev;
934 ndev->needs_free_netdev = true;
935 ndev->priv_destructor = brcmf_cfg80211_free_netdev;
936 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
938 ifp = netdev_priv(ndev);
941 ifp->drvr = cfg->pub;
944 vif->wdev.netdev = ndev;
946 err = brcmf_net_mon_attach(ifp);
948 brcmf_err("Failed to attach %s device\n", ndev->name);
953 cfg->pub->mon_if = ifp;
963 static int brcmf_mon_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
965 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
966 struct net_device *ndev = wdev->netdev;
968 ndev->netdev_ops->ndo_stop(ndev);
970 brcmf_net_detach(ndev, true);
972 cfg->pub->mon_if = NULL;
977 static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
979 unsigned char name_assign_type,
980 enum nl80211_iftype type,
981 struct vif_params *params)
983 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
984 struct brcmf_pub *drvr = cfg->pub;
985 struct wireless_dev *wdev;
988 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
989 err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
991 bphy_err(drvr, "iface validation failed: err=%d\n", err);
995 case NL80211_IFTYPE_ADHOC:
996 case NL80211_IFTYPE_AP_VLAN:
997 case NL80211_IFTYPE_WDS:
998 case NL80211_IFTYPE_MESH_POINT:
999 return ERR_PTR(-EOPNOTSUPP);
1000 case NL80211_IFTYPE_MONITOR:
1001 return brcmf_mon_add_vif(wiphy, name);
1002 case NL80211_IFTYPE_STATION:
1003 case NL80211_IFTYPE_AP:
1004 wdev = brcmf_apsta_add_vif(wiphy, name, params, type);
1006 case NL80211_IFTYPE_P2P_CLIENT:
1007 case NL80211_IFTYPE_P2P_GO:
1008 case NL80211_IFTYPE_P2P_DEVICE:
1009 wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, params);
1011 case NL80211_IFTYPE_UNSPECIFIED:
1013 return ERR_PTR(-EINVAL);
1017 bphy_err(drvr, "add iface %s type %d failed: err=%d\n", name,
1018 type, (int)PTR_ERR(wdev));
1020 brcmf_cfg80211_update_proto_addr_mode(wdev);
1025 static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
1027 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
1028 brcmf_set_mpc(ifp, mpc);
1031 void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
1033 struct brcmf_pub *drvr = ifp->drvr;
1036 if (check_vif_up(ifp->vif)) {
1037 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
1039 bphy_err(drvr, "fail to set mpc\n");
1042 brcmf_dbg(INFO, "MPC : %d\n", mpc);
1046 static void brcmf_scan_params_v2_to_v1(struct brcmf_scan_params_v2_le *params_v2_le,
1047 struct brcmf_scan_params_le *params_le)
1051 int n_channels, n_ssids;
1053 memcpy(¶ms_le->ssid_le, ¶ms_v2_le->ssid_le,
1054 sizeof(params_le->ssid_le));
1055 memcpy(¶ms_le->bssid, ¶ms_v2_le->bssid,
1056 sizeof(params_le->bssid));
1058 params_le->bss_type = params_v2_le->bss_type;
1059 params_le->scan_type = le32_to_cpu(params_v2_le->scan_type);
1060 params_le->nprobes = params_v2_le->nprobes;
1061 params_le->active_time = params_v2_le->active_time;
1062 params_le->passive_time = params_v2_le->passive_time;
1063 params_le->home_time = params_v2_le->home_time;
1064 params_le->channel_num = params_v2_le->channel_num;
1066 ch = le32_to_cpu(params_v2_le->channel_num);
1067 n_channels = ch & BRCMF_SCAN_PARAMS_COUNT_MASK;
1068 n_ssids = ch >> BRCMF_SCAN_PARAMS_NSSID_SHIFT;
1070 params_size = sizeof(u16) * n_channels;
1072 params_size = roundup(params_size, sizeof(u32));
1073 params_size += sizeof(struct brcmf_ssid_le) * n_ssids;
1076 memcpy(¶ms_le->channel_list[0],
1077 ¶ms_v2_le->channel_list[0], params_size);
1080 static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
1081 struct brcmf_scan_params_v2_le *params_le,
1082 struct cfg80211_scan_request *request)
1091 struct brcmf_ssid_le ssid_le;
1093 eth_broadcast_addr(params_le->bssid);
1095 length = BRCMF_SCAN_PARAMS_V2_FIXED_SIZE;
1097 params_le->version = cpu_to_le16(BRCMF_SCAN_PARAMS_VERSION_V2);
1098 params_le->bss_type = DOT11_BSSTYPE_ANY;
1099 params_le->scan_type = cpu_to_le32(BRCMF_SCANTYPE_ACTIVE);
1100 params_le->channel_num = 0;
1101 params_le->nprobes = cpu_to_le32(-1);
1102 params_le->active_time = cpu_to_le32(-1);
1103 params_le->passive_time = cpu_to_le32(-1);
1104 params_le->home_time = cpu_to_le32(-1);
1105 memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le));
1109 length += sizeof(u16);
1110 params_le->channel_num = cpu_to_le32(1);
1111 params_le->channel_list[0] = cpu_to_le16(-1);
1112 params_le->length = cpu_to_le16(length);
1116 n_ssids = request->n_ssids;
1117 n_channels = request->n_channels;
1119 /* Copy channel array if applicable */
1120 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
1122 if (n_channels > 0) {
1123 length += roundup(sizeof(u16) * n_channels, sizeof(u32));
1124 for (i = 0; i < n_channels; i++) {
1125 chanspec = channel_to_chanspec(&cfg->d11inf,
1126 request->channels[i]);
1127 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
1128 request->channels[i]->hw_value, chanspec);
1129 params_le->channel_list[i] = cpu_to_le16(chanspec);
1132 brcmf_dbg(SCAN, "Scanning all channels\n");
1135 /* Copy ssid array if applicable */
1136 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
1138 offset = offsetof(struct brcmf_scan_params_v2_le, channel_list) +
1139 n_channels * sizeof(u16);
1140 offset = roundup(offset, sizeof(u32));
1141 length += sizeof(ssid_le) * n_ssids,
1142 ptr = (char *)params_le + offset;
1143 for (i = 0; i < n_ssids; i++) {
1144 memset(&ssid_le, 0, sizeof(ssid_le));
1146 cpu_to_le32(request->ssids[i].ssid_len);
1147 memcpy(ssid_le.SSID, request->ssids[i].ssid,
1148 request->ssids[i].ssid_len);
1149 if (!ssid_le.SSID_len)
1150 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
1152 brcmf_dbg(SCAN, "%d: scan for %.32s size=%d\n",
1153 i, ssid_le.SSID, ssid_le.SSID_len);
1154 memcpy(ptr, &ssid_le, sizeof(ssid_le));
1155 ptr += sizeof(ssid_le);
1158 brcmf_dbg(SCAN, "Performing passive scan\n");
1159 params_le->scan_type = cpu_to_le32(BRCMF_SCANTYPE_PASSIVE);
1161 params_le->length = cpu_to_le16(length);
1162 /* Adding mask to channel numbers */
1163 params_le->channel_num =
1164 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
1165 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
1168 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
1169 struct brcmf_if *ifp, bool aborted,
1172 struct brcmf_pub *drvr = cfg->pub;
1173 struct brcmf_scan_params_v2_le params_v2_le;
1174 struct cfg80211_scan_request *scan_request;
1179 brcmf_dbg(SCAN, "Enter\n");
1181 /* clear scan request, because the FW abort can cause a second call */
1182 /* to this functon and might cause a double cfg80211_scan_done */
1183 scan_request = cfg->scan_request;
1184 cfg->scan_request = NULL;
1186 if (timer_pending(&cfg->escan_timeout))
1187 del_timer_sync(&cfg->escan_timeout);
1190 /* Do a scan abort to stop the driver's scan engine */
1191 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
1193 brcmf_escan_prep(cfg, ¶ms_v2_le, NULL);
1195 /* E-Scan (or anyother type) can be aborted by SCAN */
1196 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V2)) {
1197 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
1199 sizeof(params_v2_le));
1201 struct brcmf_scan_params_le params_le;
1203 brcmf_scan_params_v2_to_v1(¶ms_v2_le, ¶ms_le);
1204 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
1210 bphy_err(drvr, "Scan abort failed\n");
1213 brcmf_scan_config_mpc(ifp, 1);
1216 * e-scan can be initiated internally
1217 * which takes precedence.
1219 if (cfg->int_escan_map) {
1220 brcmf_dbg(SCAN, "scheduled scan completed (%x)\n",
1221 cfg->int_escan_map);
1222 while (cfg->int_escan_map) {
1223 bucket = __ffs(cfg->int_escan_map);
1224 cfg->int_escan_map &= ~BIT(bucket);
1225 reqid = brcmf_pno_find_reqid_by_bucket(cfg->pno,
1228 brcmf_dbg(SCAN, "report results: reqid=%llu\n",
1230 cfg80211_sched_scan_results(cfg_to_wiphy(cfg),
1234 } else if (scan_request) {
1235 struct cfg80211_scan_info info = {
1239 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
1240 aborted ? "Aborted" : "Done");
1241 cfg80211_scan_done(scan_request, &info);
1243 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1244 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
1249 static int brcmf_cfg80211_del_apsta_iface(struct wiphy *wiphy,
1250 struct wireless_dev *wdev)
1252 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1253 struct net_device *ndev = wdev->netdev;
1254 struct brcmf_if *ifp = netdev_priv(ndev);
1255 struct brcmf_pub *drvr = cfg->pub;
1259 brcmf_cfg80211_arm_vif_event(cfg, ifp->vif);
1261 err = brcmf_fil_bsscfg_data_set(ifp, "interface_remove", NULL, 0);
1263 bphy_err(drvr, "interface_remove failed %d\n", err);
1267 /* wait for firmware event */
1268 ret = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_DEL,
1269 BRCMF_VIF_EVENT_TIMEOUT);
1271 bphy_err(drvr, "timeout occurred\n");
1276 brcmf_remove_interface(ifp, true);
1279 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1284 int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
1286 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1287 struct net_device *ndev = wdev->netdev;
1289 if (ndev && ndev == cfg_to_ndev(cfg))
1292 /* vif event pending in firmware */
1293 if (brcmf_cfg80211_vif_event_armed(cfg))
1297 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
1298 cfg->escan_info.ifp == netdev_priv(ndev))
1299 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
1302 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
1305 switch (wdev->iftype) {
1306 case NL80211_IFTYPE_ADHOC:
1307 case NL80211_IFTYPE_AP_VLAN:
1308 case NL80211_IFTYPE_WDS:
1309 case NL80211_IFTYPE_MESH_POINT:
1311 case NL80211_IFTYPE_MONITOR:
1312 return brcmf_mon_del_vif(wiphy, wdev);
1313 case NL80211_IFTYPE_STATION:
1314 case NL80211_IFTYPE_AP:
1315 return brcmf_cfg80211_del_apsta_iface(wiphy, wdev);
1316 case NL80211_IFTYPE_P2P_CLIENT:
1317 case NL80211_IFTYPE_P2P_GO:
1318 case NL80211_IFTYPE_P2P_DEVICE:
1319 return brcmf_p2p_del_vif(wiphy, wdev);
1320 case NL80211_IFTYPE_UNSPECIFIED:
1328 brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
1329 enum nl80211_iftype type,
1330 struct vif_params *params)
1332 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1333 struct brcmf_if *ifp = netdev_priv(ndev);
1334 struct brcmf_cfg80211_vif *vif = ifp->vif;
1335 struct brcmf_pub *drvr = cfg->pub;
1340 brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx,
1343 /* WAR: There are a number of p2p interface related problems which
1344 * need to be handled initially (before doing the validate).
1345 * wpa_supplicant tends to do iface changes on p2p device/client/go
1346 * which are not always possible/allowed. However we need to return
1347 * OK otherwise the wpa_supplicant wont start. The situation differs
1348 * on configuration and setup (p2pon=1 module param). The first check
1349 * is to see if the request is a change to station for p2p iface.
1351 if ((type == NL80211_IFTYPE_STATION) &&
1352 ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
1353 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) ||
1354 (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) {
1355 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
1356 /* Now depending on whether module param p2pon=1 was used the
1357 * response needs to be either 0 or EOPNOTSUPP. The reason is
1358 * that if p2pon=1 is used, but a newer supplicant is used then
1359 * we should return an error, as this combination wont work.
1360 * In other situations 0 is returned and supplicant will start
1361 * normally. It will give a trace in cfg80211, but it is the
1362 * only way to get it working. Unfortunately this will result
1363 * in situation where we wont support new supplicant in
1364 * combination with module param p2pon=1, but that is the way
1365 * it is. If the user tries this then unloading of driver might
1368 if (cfg->p2p.p2pdev_dynamically)
1373 err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
1375 bphy_err(drvr, "iface validation failed: err=%d\n", err);
1379 case NL80211_IFTYPE_MONITOR:
1380 case NL80211_IFTYPE_WDS:
1381 bphy_err(drvr, "type (%d) : currently we do not support this type\n",
1384 case NL80211_IFTYPE_ADHOC:
1387 case NL80211_IFTYPE_STATION:
1390 case NL80211_IFTYPE_AP:
1391 case NL80211_IFTYPE_P2P_GO:
1400 if (type == NL80211_IFTYPE_P2P_GO) {
1401 brcmf_dbg(INFO, "IF Type = P2P GO\n");
1402 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
1405 brcmf_dbg(INFO, "IF Type = AP\n");
1408 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
1410 bphy_err(drvr, "WLC_SET_INFRA error (%d)\n", err);
1414 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
1417 ndev->ieee80211_ptr->iftype = type;
1419 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
1422 brcmf_dbg(TRACE, "Exit\n");
1428 brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
1429 struct cfg80211_scan_request *request)
1431 struct brcmf_pub *drvr = cfg->pub;
1432 s32 params_size = BRCMF_SCAN_PARAMS_V2_FIXED_SIZE +
1433 offsetof(struct brcmf_escan_params_le, params_v2_le);
1434 struct brcmf_escan_params_le *params;
1437 brcmf_dbg(SCAN, "E-SCAN START\n");
1439 if (request != NULL) {
1440 /* Allocate space for populating ssids in struct */
1441 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
1443 /* Allocate space for populating ssids in struct */
1444 params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids;
1447 params = kzalloc(params_size, GFP_KERNEL);
1452 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
1453 brcmf_escan_prep(cfg, ¶ms->params_v2_le, request);
1455 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION_V2);
1457 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V2)) {
1458 struct brcmf_escan_params_le *params_v1;
1460 params_size -= BRCMF_SCAN_PARAMS_V2_FIXED_SIZE;
1461 params_size += BRCMF_SCAN_PARAMS_FIXED_SIZE;
1462 params_v1 = kzalloc(params_size, GFP_KERNEL);
1467 params_v1->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
1468 brcmf_scan_params_v2_to_v1(¶ms->params_v2_le, ¶ms_v1->params_le);
1473 params->action = cpu_to_le16(WL_ESCAN_ACTION_START);
1474 params->sync_id = cpu_to_le16(0x1234);
1476 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
1479 brcmf_dbg(INFO, "system busy : escan canceled\n");
1481 bphy_err(drvr, "error (%d)\n", err);
1491 brcmf_do_escan(struct brcmf_if *ifp, struct cfg80211_scan_request *request)
1493 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1495 struct brcmf_scan_results *results;
1496 struct escan_info *escan = &cfg->escan_info;
1498 brcmf_dbg(SCAN, "Enter\n");
1500 escan->wiphy = cfg->wiphy;
1501 escan->escan_state = WL_ESCAN_STATE_SCANNING;
1503 brcmf_scan_config_mpc(ifp, 0);
1504 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
1505 results->version = 0;
1507 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
1509 err = escan->run(cfg, ifp, request);
1511 brcmf_scan_config_mpc(ifp, 1);
1516 brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
1518 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1519 struct brcmf_pub *drvr = cfg->pub;
1520 struct brcmf_cfg80211_vif *vif;
1523 brcmf_dbg(TRACE, "Enter\n");
1524 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1525 if (!check_vif_up(vif))
1528 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
1529 bphy_err(drvr, "Scanning already: status (%lu)\n",
1533 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
1534 bphy_err(drvr, "Scanning being aborted: status (%lu)\n",
1538 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
1539 bphy_err(drvr, "Scanning suppressed: status (%lu)\n",
1543 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state)) {
1544 bphy_err(drvr, "Connecting: status (%lu)\n", vif->sme_state);
1548 /* If scan req comes for p2p0, send it over primary I/F */
1549 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
1550 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1552 brcmf_dbg(SCAN, "START ESCAN\n");
1554 cfg->scan_request = request;
1555 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
1557 cfg->escan_info.run = brcmf_run_escan;
1558 err = brcmf_p2p_scan_prep(wiphy, request, vif);
1562 err = brcmf_do_escan(vif->ifp, request);
1566 /* Arm scan timeout timer */
1567 mod_timer(&cfg->escan_timeout,
1568 jiffies + msecs_to_jiffies(BRCMF_ESCAN_TIMER_INTERVAL_MS));
1573 bphy_err(drvr, "scan error (%d)\n", err);
1574 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
1575 cfg->scan_request = NULL;
1579 static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1581 struct brcmf_if *ifp = netdev_priv(ndev);
1582 struct brcmf_pub *drvr = ifp->drvr;
1585 err = brcmf_fil_iovar_int_set(ifp, "rtsthresh", rts_threshold);
1587 bphy_err(drvr, "Error (%d)\n", err);
1592 static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1594 struct brcmf_if *ifp = netdev_priv(ndev);
1595 struct brcmf_pub *drvr = ifp->drvr;
1598 err = brcmf_fil_iovar_int_set(ifp, "fragthresh",
1601 bphy_err(drvr, "Error (%d)\n", err);
1606 static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1608 struct brcmf_if *ifp = netdev_priv(ndev);
1609 struct brcmf_pub *drvr = ifp->drvr;
1611 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
1613 err = brcmf_fil_cmd_int_set(ifp, cmd, retry);
1615 bphy_err(drvr, "cmd (%d) , error (%d)\n", cmd, err);
1621 static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1623 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1624 struct net_device *ndev = cfg_to_ndev(cfg);
1625 struct brcmf_if *ifp = netdev_priv(ndev);
1628 brcmf_dbg(TRACE, "Enter\n");
1629 if (!check_vif_up(ifp->vif))
1632 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
1633 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1634 cfg->conf->rts_threshold = wiphy->rts_threshold;
1635 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
1639 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
1640 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1641 cfg->conf->frag_threshold = wiphy->frag_threshold;
1642 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
1646 if (changed & WIPHY_PARAM_RETRY_LONG
1647 && (cfg->conf->retry_long != wiphy->retry_long)) {
1648 cfg->conf->retry_long = wiphy->retry_long;
1649 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
1653 if (changed & WIPHY_PARAM_RETRY_SHORT
1654 && (cfg->conf->retry_short != wiphy->retry_short)) {
1655 cfg->conf->retry_short = wiphy->retry_short;
1656 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
1662 brcmf_dbg(TRACE, "Exit\n");
1666 static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1668 memset(prof, 0, sizeof(*prof));
1671 static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
1675 switch (e->event_code) {
1676 case BRCMF_E_DEAUTH:
1677 case BRCMF_E_DEAUTH_IND:
1678 case BRCMF_E_DISASSOC_IND:
1689 static int brcmf_set_pmk(struct brcmf_if *ifp, const u8 *pmk_data, u16 pmk_len)
1691 struct brcmf_pub *drvr = ifp->drvr;
1692 struct brcmf_wsec_pmk_le pmk;
1695 memset(&pmk, 0, sizeof(pmk));
1697 /* pass pmk directly */
1698 pmk.key_len = cpu_to_le16(pmk_len);
1699 pmk.flags = cpu_to_le16(0);
1700 memcpy(pmk.key, pmk_data, pmk_len);
1702 /* store psk in firmware */
1703 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_WSEC_PMK,
1706 bphy_err(drvr, "failed to change PSK in firmware (len=%u)\n",
1712 static int brcmf_set_sae_password(struct brcmf_if *ifp, const u8 *pwd_data,
1715 struct brcmf_pub *drvr = ifp->drvr;
1716 struct brcmf_wsec_sae_pwd_le sae_pwd;
1719 if (pwd_len > BRCMF_WSEC_MAX_SAE_PASSWORD_LEN) {
1720 bphy_err(drvr, "sae_password must be less than %d\n",
1721 BRCMF_WSEC_MAX_SAE_PASSWORD_LEN);
1725 sae_pwd.key_len = cpu_to_le16(pwd_len);
1726 memcpy(sae_pwd.key, pwd_data, pwd_len);
1728 err = brcmf_fil_iovar_data_set(ifp, "sae_password", &sae_pwd,
1731 bphy_err(drvr, "failed to set SAE password in firmware (len=%u)\n",
1737 static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason,
1738 bool locally_generated)
1740 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
1741 struct brcmf_pub *drvr = cfg->pub;
1742 bool bus_up = drvr->bus_if->state == BRCMF_BUS_UP;
1745 brcmf_dbg(TRACE, "Enter\n");
1747 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
1749 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n");
1750 err = brcmf_fil_cmd_data_set(vif->ifp,
1751 BRCMF_C_DISASSOC, NULL, 0);
1753 bphy_err(drvr, "WLC_DISASSOC failed (%d)\n",
1757 if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) ||
1758 (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT))
1759 cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
1760 locally_generated, GFP_KERNEL);
1762 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
1763 clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
1764 clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
1765 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1766 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
1767 if (vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_NONE) {
1769 brcmf_set_pmk(vif->ifp, NULL, 0);
1770 vif->profile.use_fwsup = BRCMF_PROFILE_FWSUP_NONE;
1772 brcmf_dbg(TRACE, "Exit\n");
1776 brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1777 struct cfg80211_ibss_params *params)
1779 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1780 struct brcmf_if *ifp = netdev_priv(ndev);
1781 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
1782 struct brcmf_pub *drvr = cfg->pub;
1783 struct brcmf_join_params join_params;
1784 size_t join_params_size = 0;
1791 brcmf_dbg(TRACE, "Enter\n");
1792 if (!check_vif_up(ifp->vif))
1796 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
1798 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
1802 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
1805 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
1807 brcmf_dbg(CONN, "No BSSID specified\n");
1809 if (params->chandef.chan)
1810 brcmf_dbg(CONN, "channel: %d\n",
1811 params->chandef.chan->center_freq);
1813 brcmf_dbg(CONN, "no channel specified\n");
1815 if (params->channel_fixed)
1816 brcmf_dbg(CONN, "fixed channel required\n");
1818 brcmf_dbg(CONN, "no fixed channel required\n");
1820 if (params->ie && params->ie_len)
1821 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
1823 brcmf_dbg(CONN, "no ie specified\n");
1825 if (params->beacon_interval)
1826 brcmf_dbg(CONN, "beacon interval: %d\n",
1827 params->beacon_interval);
1829 brcmf_dbg(CONN, "no beacon interval specified\n");
1831 if (params->basic_rates)
1832 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
1834 brcmf_dbg(CONN, "no basic rates specified\n");
1836 if (params->privacy)
1837 brcmf_dbg(CONN, "privacy required\n");
1839 brcmf_dbg(CONN, "no privacy required\n");
1841 /* Configure Privacy for starter */
1842 if (params->privacy)
1843 wsec |= WEP_ENABLED;
1845 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
1847 bphy_err(drvr, "wsec failed (%d)\n", err);
1851 /* Configure Beacon Interval for starter */
1852 if (params->beacon_interval)
1853 bcnprd = params->beacon_interval;
1857 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
1859 bphy_err(drvr, "WLC_SET_BCNPRD failed (%d)\n", err);
1863 /* Configure required join parameter */
1864 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1867 ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN);
1868 memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len);
1869 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
1870 join_params_size = sizeof(join_params.ssid_le);
1873 if (params->bssid) {
1874 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
1875 join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE;
1876 memcpy(profile->bssid, params->bssid, ETH_ALEN);
1878 eth_broadcast_addr(join_params.params_le.bssid);
1879 eth_zero_addr(profile->bssid);
1883 if (params->chandef.chan) {
1887 ieee80211_frequency_to_channel(
1888 params->chandef.chan->center_freq);
1889 if (params->channel_fixed) {
1890 /* adding chanspec */
1891 chanspec = chandef_to_chanspec(&cfg->d11inf,
1893 join_params.params_le.chanspec_list[0] =
1894 cpu_to_le16(chanspec);
1895 join_params.params_le.chanspec_num = cpu_to_le32(1);
1896 join_params_size += sizeof(join_params.params_le);
1899 /* set channel for starter */
1900 target_channel = cfg->channel;
1901 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
1904 bphy_err(drvr, "WLC_SET_CHANNEL failed (%d)\n", err);
1910 cfg->ibss_starter = false;
1913 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
1914 &join_params, join_params_size);
1916 bphy_err(drvr, "WLC_SET_SSID failed (%d)\n", err);
1922 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
1923 brcmf_dbg(TRACE, "Exit\n");
1928 brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1930 struct brcmf_if *ifp = netdev_priv(ndev);
1932 brcmf_dbg(TRACE, "Enter\n");
1933 if (!check_vif_up(ifp->vif)) {
1934 /* When driver is being unloaded, it can end up here. If an
1935 * error is returned then later on a debug trace in the wireless
1936 * core module will be printed. To avoid this 0 is returned.
1941 brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING, true);
1942 brcmf_net_setcarrier(ifp, false);
1944 brcmf_dbg(TRACE, "Exit\n");
1949 static s32 brcmf_set_wpa_version(struct net_device *ndev,
1950 struct cfg80211_connect_params *sme)
1952 struct brcmf_if *ifp = netdev_priv(ndev);
1953 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1954 struct brcmf_pub *drvr = ifp->drvr;
1955 struct brcmf_cfg80211_security *sec;
1959 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) {
1960 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1961 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2) {
1962 if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_SAE)
1963 val = WPA3_AUTH_SAE_PSK;
1965 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1966 } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_3) {
1967 val = WPA3_AUTH_SAE_PSK;
1969 val = WPA_AUTH_DISABLED;
1971 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
1972 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", val);
1974 bphy_err(drvr, "set wpa_auth failed (%d)\n", err);
1977 sec = &profile->sec;
1978 sec->wpa_versions = sme->crypto.wpa_versions;
1982 static s32 brcmf_set_auth_type(struct net_device *ndev,
1983 struct cfg80211_connect_params *sme)
1985 struct brcmf_if *ifp = netdev_priv(ndev);
1986 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1987 struct brcmf_pub *drvr = ifp->drvr;
1988 struct brcmf_cfg80211_security *sec;
1992 switch (sme->auth_type) {
1993 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1995 brcmf_dbg(CONN, "open system\n");
1997 case NL80211_AUTHTYPE_SHARED_KEY:
1999 brcmf_dbg(CONN, "shared key\n");
2001 case NL80211_AUTHTYPE_SAE:
2003 brcmf_dbg(CONN, "SAE authentication\n");
2007 brcmf_dbg(CONN, "automatic, auth type (%d)\n", sme->auth_type);
2011 err = brcmf_fil_bsscfg_int_set(ifp, "auth", val);
2013 bphy_err(drvr, "set auth failed (%d)\n", err);
2016 sec = &profile->sec;
2017 sec->auth_type = sme->auth_type;
2022 brcmf_set_wsec_mode(struct net_device *ndev,
2023 struct cfg80211_connect_params *sme)
2025 struct brcmf_if *ifp = netdev_priv(ndev);
2026 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
2027 struct brcmf_pub *drvr = ifp->drvr;
2028 struct brcmf_cfg80211_security *sec;
2034 if (sme->crypto.n_ciphers_pairwise) {
2035 switch (sme->crypto.ciphers_pairwise[0]) {
2036 case WLAN_CIPHER_SUITE_WEP40:
2037 case WLAN_CIPHER_SUITE_WEP104:
2040 case WLAN_CIPHER_SUITE_TKIP:
2041 pval = TKIP_ENABLED;
2043 case WLAN_CIPHER_SUITE_CCMP:
2046 case WLAN_CIPHER_SUITE_AES_CMAC:
2050 bphy_err(drvr, "invalid cipher pairwise (%d)\n",
2051 sme->crypto.ciphers_pairwise[0]);
2055 if (sme->crypto.cipher_group) {
2056 switch (sme->crypto.cipher_group) {
2057 case WLAN_CIPHER_SUITE_WEP40:
2058 case WLAN_CIPHER_SUITE_WEP104:
2061 case WLAN_CIPHER_SUITE_TKIP:
2062 gval = TKIP_ENABLED;
2064 case WLAN_CIPHER_SUITE_CCMP:
2067 case WLAN_CIPHER_SUITE_AES_CMAC:
2071 bphy_err(drvr, "invalid cipher group (%d)\n",
2072 sme->crypto.cipher_group);
2077 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
2078 /* In case of privacy, but no security and WPS then simulate */
2079 /* setting AES. WPS-2.0 allows no security */
2080 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
2085 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2087 bphy_err(drvr, "error (%d)\n", err);
2091 sec = &profile->sec;
2092 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
2093 sec->cipher_group = sme->crypto.cipher_group;
2099 brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
2101 struct brcmf_if *ifp = netdev_priv(ndev);
2102 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2103 struct brcmf_pub *drvr = ifp->drvr;
2106 const struct brcmf_tlv *rsn_ie;
2114 profile->use_fwsup = BRCMF_PROFILE_FWSUP_NONE;
2115 profile->is_ft = false;
2117 if (!sme->crypto.n_akm_suites)
2120 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val);
2122 bphy_err(drvr, "could not get wpa_auth (%d)\n", err);
2125 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
2126 switch (sme->crypto.akm_suites[0]) {
2127 case WLAN_AKM_SUITE_8021X:
2128 val = WPA_AUTH_UNSPECIFIED;
2130 profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
2132 case WLAN_AKM_SUITE_PSK:
2136 bphy_err(drvr, "invalid akm suite (%d)\n",
2137 sme->crypto.akm_suites[0]);
2140 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
2141 switch (sme->crypto.akm_suites[0]) {
2142 case WLAN_AKM_SUITE_8021X:
2143 val = WPA2_AUTH_UNSPECIFIED;
2145 profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
2147 case WLAN_AKM_SUITE_8021X_SHA256:
2148 val = WPA2_AUTH_1X_SHA256;
2150 profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
2152 case WLAN_AKM_SUITE_PSK_SHA256:
2153 val = WPA2_AUTH_PSK_SHA256;
2155 case WLAN_AKM_SUITE_PSK:
2156 val = WPA2_AUTH_PSK;
2158 case WLAN_AKM_SUITE_FT_8021X:
2159 val = WPA2_AUTH_UNSPECIFIED | WPA2_AUTH_FT;
2160 profile->is_ft = true;
2162 profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
2164 case WLAN_AKM_SUITE_FT_PSK:
2165 val = WPA2_AUTH_PSK | WPA2_AUTH_FT;
2166 profile->is_ft = true;
2169 bphy_err(drvr, "invalid akm suite (%d)\n",
2170 sme->crypto.akm_suites[0]);
2173 } else if (val & WPA3_AUTH_SAE_PSK) {
2174 switch (sme->crypto.akm_suites[0]) {
2175 case WLAN_AKM_SUITE_SAE:
2176 val = WPA3_AUTH_SAE_PSK;
2177 if (sme->crypto.sae_pwd) {
2178 brcmf_dbg(INFO, "using SAE offload\n");
2179 profile->use_fwsup = BRCMF_PROFILE_FWSUP_SAE;
2182 case WLAN_AKM_SUITE_FT_OVER_SAE:
2183 val = WPA3_AUTH_SAE_PSK | WPA2_AUTH_FT;
2184 profile->is_ft = true;
2185 if (sme->crypto.sae_pwd) {
2186 brcmf_dbg(INFO, "using SAE offload\n");
2187 profile->use_fwsup = BRCMF_PROFILE_FWSUP_SAE;
2191 bphy_err(drvr, "invalid akm suite (%d)\n",
2192 sme->crypto.akm_suites[0]);
2197 if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X)
2198 brcmf_dbg(INFO, "using 1X offload\n");
2200 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
2201 goto skip_mfp_config;
2202 /* The MFP mode (1 or 2) needs to be determined, parse IEs. The
2203 * IE will not be verified, just a quick search for MFP config
2205 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len,
2208 goto skip_mfp_config;
2209 ie = (const u8 *)rsn_ie;
2210 ie_len = rsn_ie->len + TLV_HDR_LEN;
2211 /* Skip unicast suite */
2212 offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN;
2213 if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
2214 goto skip_mfp_config;
2215 /* Skip multicast suite */
2216 count = ie[offset] + (ie[offset + 1] << 8);
2217 offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
2218 if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
2219 goto skip_mfp_config;
2220 /* Skip auth key management suite(s) */
2221 count = ie[offset] + (ie[offset + 1] << 8);
2222 offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
2223 if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len)
2224 goto skip_mfp_config;
2225 /* Ready to read capabilities */
2226 mfp = BRCMF_MFP_NONE;
2227 rsn_cap = ie[offset] + (ie[offset + 1] << 8);
2228 if (rsn_cap & RSN_CAP_MFPR_MASK)
2229 mfp = BRCMF_MFP_REQUIRED;
2230 else if (rsn_cap & RSN_CAP_MFPC_MASK)
2231 mfp = BRCMF_MFP_CAPABLE;
2232 brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp);
2235 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
2236 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
2238 bphy_err(drvr, "could not set wpa_auth (%d)\n", err);
2246 brcmf_set_sharedkey(struct net_device *ndev,
2247 struct cfg80211_connect_params *sme)
2249 struct brcmf_if *ifp = netdev_priv(ndev);
2250 struct brcmf_pub *drvr = ifp->drvr;
2251 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
2252 struct brcmf_cfg80211_security *sec;
2253 struct brcmf_wsec_key key;
2257 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
2259 if (sme->key_len == 0)
2262 sec = &profile->sec;
2263 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
2264 sec->wpa_versions, sec->cipher_pairwise);
2266 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2 |
2267 NL80211_WPA_VERSION_3))
2270 if (!(sec->cipher_pairwise &
2271 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
2274 memset(&key, 0, sizeof(key));
2275 key.len = (u32) sme->key_len;
2276 key.index = (u32) sme->key_idx;
2277 if (key.len > sizeof(key.data)) {
2278 bphy_err(drvr, "Too long key length (%u)\n", key.len);
2281 memcpy(key.data, sme->key, key.len);
2282 key.flags = BRCMF_PRIMARY_KEY;
2283 switch (sec->cipher_pairwise) {
2284 case WLAN_CIPHER_SUITE_WEP40:
2285 key.algo = CRYPTO_ALGO_WEP1;
2287 case WLAN_CIPHER_SUITE_WEP104:
2288 key.algo = CRYPTO_ALGO_WEP128;
2291 bphy_err(drvr, "Invalid algorithm (%d)\n",
2292 sme->crypto.ciphers_pairwise[0]);
2295 /* Set the new key/index */
2296 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
2297 key.len, key.index, key.algo);
2298 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
2299 err = send_key_to_dongle(ifp, &key);
2303 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
2304 brcmf_dbg(CONN, "set auth_type to shared key\n");
2305 val = WL_AUTH_SHARED_KEY; /* shared key */
2306 err = brcmf_fil_bsscfg_int_set(ifp, "auth", val);
2308 bphy_err(drvr, "set auth failed (%d)\n", err);
2314 enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
2315 enum nl80211_auth_type type)
2317 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
2318 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
2319 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
2320 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2325 static void brcmf_set_join_pref(struct brcmf_if *ifp,
2326 struct cfg80211_bss_selection *bss_select)
2328 struct brcmf_pub *drvr = ifp->drvr;
2329 struct brcmf_join_pref_params join_pref_params[2];
2330 enum nl80211_band band;
2333 join_pref_params[i].len = 2;
2334 join_pref_params[i].rssi_gain = 0;
2336 if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF)
2337 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO);
2339 switch (bss_select->behaviour) {
2340 case __NL80211_BSS_SELECT_ATTR_INVALID:
2341 brcmf_c_set_joinpref_default(ifp);
2343 case NL80211_BSS_SELECT_ATTR_BAND_PREF:
2344 join_pref_params[i].type = BRCMF_JOIN_PREF_BAND;
2345 band = bss_select->param.band_pref;
2346 join_pref_params[i].band = nl80211_band_to_fwil(band);
2349 case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST:
2350 join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA;
2351 band = bss_select->param.adjust.band;
2352 join_pref_params[i].band = nl80211_band_to_fwil(band);
2353 join_pref_params[i].rssi_gain = bss_select->param.adjust.delta;
2356 case NL80211_BSS_SELECT_ATTR_RSSI:
2360 join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI;
2361 join_pref_params[i].len = 2;
2362 join_pref_params[i].rssi_gain = 0;
2363 join_pref_params[i].band = 0;
2364 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
2365 sizeof(join_pref_params));
2367 bphy_err(drvr, "Set join_pref error (%d)\n", err);
2371 brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
2372 struct cfg80211_connect_params *sme)
2374 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2375 struct brcmf_if *ifp = netdev_priv(ndev);
2376 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2377 struct ieee80211_channel *chan = sme->channel;
2378 struct brcmf_pub *drvr = ifp->drvr;
2379 struct brcmf_join_params join_params;
2380 size_t join_params_size;
2381 const struct brcmf_tlv *rsn_ie;
2382 const struct brcmf_vs_tlv *wpa_ie;
2385 struct brcmf_ext_join_params_le *ext_join_params;
2390 brcmf_dbg(TRACE, "Enter\n");
2391 if (!check_vif_up(ifp->vif))
2395 bphy_err(drvr, "Invalid ssid\n");
2399 if (sme->channel_hint)
2400 chan = sme->channel_hint;
2402 if (sme->bssid_hint)
2403 sme->bssid = sme->bssid_hint;
2405 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
2406 /* A normal (non P2P) connection request setup. */
2409 /* find the WPA_IE */
2410 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
2413 ie_len = wpa_ie->len + TLV_HDR_LEN;
2415 /* find the RSN_IE */
2416 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
2421 ie_len = rsn_ie->len + TLV_HDR_LEN;
2424 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
2427 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
2428 sme->ie, sme->ie_len);
2430 bphy_err(drvr, "Set Assoc REQ IE Failed\n");
2432 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
2434 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
2438 ieee80211_frequency_to_channel(chan->center_freq);
2439 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
2440 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
2441 cfg->channel, chan->center_freq, chanspec);
2447 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
2449 err = brcmf_set_wpa_version(ndev, sme);
2451 bphy_err(drvr, "wl_set_wpa_version failed (%d)\n", err);
2455 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
2456 err = brcmf_set_auth_type(ndev, sme);
2458 bphy_err(drvr, "wl_set_auth_type failed (%d)\n", err);
2462 err = brcmf_set_wsec_mode(ndev, sme);
2464 bphy_err(drvr, "wl_set_set_cipher failed (%d)\n", err);
2468 err = brcmf_set_key_mgmt(ndev, sme);
2470 bphy_err(drvr, "wl_set_key_mgmt failed (%d)\n", err);
2474 err = brcmf_set_sharedkey(ndev, sme);
2476 bphy_err(drvr, "brcmf_set_sharedkey failed (%d)\n", err);
2480 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FWSUP)) {
2481 if (sme->crypto.psk) {
2482 if (profile->use_fwsup != BRCMF_PROFILE_FWSUP_SAE) {
2483 if (WARN_ON(profile->use_fwsup !=
2484 BRCMF_PROFILE_FWSUP_NONE)) {
2488 brcmf_dbg(INFO, "using PSK offload\n");
2489 profile->use_fwsup = BRCMF_PROFILE_FWSUP_PSK;
2492 profile->use_fwsup = BRCMF_PROFILE_FWSUP_NONE;
2495 if (profile->use_fwsup != BRCMF_PROFILE_FWSUP_NONE) {
2496 /* enable firmware supplicant for this interface */
2497 err = brcmf_fil_iovar_int_set(ifp, "sup_wpa", 1);
2499 bphy_err(drvr, "failed to enable fw supplicant\n");
2503 err = brcmf_fil_iovar_int_set(ifp, "sup_wpa", 0);
2506 if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_PSK)
2507 err = brcmf_set_pmk(ifp, sme->crypto.psk,
2508 BRCMF_WSEC_MAX_PSK_LEN);
2509 else if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_SAE) {
2510 /* clean up user-space RSNE */
2511 if (brcmf_fil_iovar_data_set(ifp, "wpaie", NULL, 0)) {
2512 bphy_err(drvr, "failed to clean up user-space RSNE\n");
2515 err = brcmf_set_sae_password(ifp, sme->crypto.sae_pwd,
2516 sme->crypto.sae_pwd_len);
2517 if (!err && sme->crypto.psk)
2518 err = brcmf_set_pmk(ifp, sme->crypto.psk,
2519 BRCMF_WSEC_MAX_PSK_LEN);
2524 /* Join with specific BSSID and cached SSID
2525 * If SSID is zero join based on BSSID only
2527 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
2528 offsetof(struct brcmf_assoc_params_le, chanspec_list);
2530 join_params_size += sizeof(u16);
2531 ext_join_params = kzalloc(sizeof(*ext_join_params), GFP_KERNEL);
2532 if (ext_join_params == NULL) {
2536 ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN);
2537 ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len);
2538 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len);
2539 if (ssid_len < IEEE80211_MAX_SSID_LEN)
2540 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n",
2541 ext_join_params->ssid_le.SSID, ssid_len);
2543 /* Set up join scan parameters */
2544 ext_join_params->scan_le.scan_type = -1;
2545 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
2548 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
2550 eth_broadcast_addr(ext_join_params->assoc_le.bssid);
2553 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
2555 ext_join_params->assoc_le.chanspec_list[0] =
2556 cpu_to_le16(chanspec);
2557 /* Increase dwell time to receive probe response or detect
2558 * beacon from target AP at a noisy air only during connect
2561 ext_join_params->scan_le.active_time =
2562 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
2563 ext_join_params->scan_le.passive_time =
2564 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
2565 /* To sync with presence period of VSDB GO send probe request
2566 * more frequently. Probe request will be stopped when it gets
2567 * probe response from target AP/GO.
2569 ext_join_params->scan_le.nprobes =
2570 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
2571 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
2573 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
2574 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
2575 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
2578 brcmf_set_join_pref(ifp, &sme->bss_select);
2580 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
2582 kfree(ext_join_params);
2584 /* This is it. join command worked, we are done */
2587 /* join command failed, fallback to set ssid */
2588 memset(&join_params, 0, sizeof(join_params));
2589 join_params_size = sizeof(join_params.ssid_le);
2591 memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len);
2592 join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
2595 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
2597 eth_broadcast_addr(join_params.params_le.bssid);
2600 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
2601 join_params.params_le.chanspec_num = cpu_to_le32(1);
2602 join_params_size += sizeof(join_params.params_le);
2604 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
2605 &join_params, join_params_size);
2607 bphy_err(drvr, "BRCMF_C_SET_SSID failed (%d)\n", err);
2611 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
2612 brcmf_dbg(TRACE, "Exit\n");
2617 brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2620 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2621 struct brcmf_if *ifp = netdev_priv(ndev);
2622 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2623 struct brcmf_pub *drvr = cfg->pub;
2624 struct brcmf_scb_val_le scbval;
2627 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
2628 if (!check_vif_up(ifp->vif))
2631 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
2632 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
2633 clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &ifp->vif->sme_state);
2634 clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &ifp->vif->sme_state);
2635 cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL);
2637 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
2638 scbval.val = cpu_to_le32(reason_code);
2639 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
2640 &scbval, sizeof(scbval));
2642 bphy_err(drvr, "error (%d)\n", err);
2644 brcmf_dbg(TRACE, "Exit\n");
2649 brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2650 enum nl80211_tx_power_setting type, s32 mbm)
2652 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2653 struct net_device *ndev = cfg_to_ndev(cfg);
2654 struct brcmf_if *ifp = netdev_priv(ndev);
2655 struct brcmf_pub *drvr = cfg->pub;
2660 brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm);
2661 if (!check_vif_up(ifp->vif))
2665 case NL80211_TX_POWER_AUTOMATIC:
2667 case NL80211_TX_POWER_LIMITED:
2668 case NL80211_TX_POWER_FIXED:
2670 bphy_err(drvr, "TX_POWER_FIXED - dbm is negative\n");
2674 qdbm = MBM_TO_DBM(4 * mbm);
2677 qdbm |= WL_TXPWR_OVERRIDE;
2680 bphy_err(drvr, "Unsupported type %d\n", type);
2684 /* Make sure radio is off or on as far as software is concerned */
2685 disable = WL_RADIO_SW_DISABLE << 16;
2686 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
2688 bphy_err(drvr, "WLC_SET_RADIO error (%d)\n", err);
2690 err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm);
2692 bphy_err(drvr, "qtxpower error (%d)\n", err);
2695 brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE);
2700 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
2703 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2704 struct brcmf_cfg80211_vif *vif = wdev_to_vif(wdev);
2705 struct brcmf_pub *drvr = cfg->pub;
2709 brcmf_dbg(TRACE, "Enter\n");
2710 if (!check_vif_up(vif))
2713 err = brcmf_fil_iovar_int_get(vif->ifp, "qtxpower", &qdbm);
2715 bphy_err(drvr, "error (%d)\n", err);
2718 *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4;
2721 brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm);
2726 brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
2727 int link_id, u8 key_idx, bool unicast,
2730 struct brcmf_if *ifp = netdev_priv(ndev);
2731 struct brcmf_pub *drvr = ifp->drvr;
2736 brcmf_dbg(TRACE, "Enter\n");
2737 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2738 if (!check_vif_up(ifp->vif))
2741 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2743 bphy_err(drvr, "WLC_GET_WSEC error (%d)\n", err);
2747 if (wsec & WEP_ENABLED) {
2748 /* Just select a new current key */
2750 err = brcmf_fil_cmd_int_set(ifp,
2751 BRCMF_C_SET_KEY_PRIMARY, index);
2753 bphy_err(drvr, "error (%d)\n", err);
2756 brcmf_dbg(TRACE, "Exit\n");
2761 brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2762 int link_id, u8 key_idx, bool pairwise,
2765 struct brcmf_if *ifp = netdev_priv(ndev);
2766 struct brcmf_wsec_key *key;
2769 brcmf_dbg(TRACE, "Enter\n");
2770 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2772 if (!check_vif_up(ifp->vif))
2775 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2776 /* we ignore this key index in this case */
2780 key = &ifp->vif->profile.key[key_idx];
2782 if (key->algo == CRYPTO_ALGO_OFF) {
2783 brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n");
2787 memset(key, 0, sizeof(*key));
2788 key->index = (u32)key_idx;
2789 key->flags = BRCMF_PRIMARY_KEY;
2791 /* Clear the key/index */
2792 err = send_key_to_dongle(ifp, key);
2794 brcmf_dbg(TRACE, "Exit\n");
2799 brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2800 int link_id, u8 key_idx, bool pairwise,
2801 const u8 *mac_addr, struct key_params *params)
2803 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2804 struct brcmf_if *ifp = netdev_priv(ndev);
2805 struct brcmf_pub *drvr = cfg->pub;
2806 struct brcmf_wsec_key *key;
2813 brcmf_dbg(TRACE, "Enter\n");
2814 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2815 if (!check_vif_up(ifp->vif))
2818 if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
2819 /* we ignore this key index in this case */
2820 bphy_err(drvr, "invalid key index (%d)\n", key_idx);
2824 if (params->key_len == 0)
2825 return brcmf_cfg80211_del_key(wiphy, ndev, -1, key_idx,
2826 pairwise, mac_addr);
2828 if (params->key_len > sizeof(key->data)) {
2829 bphy_err(drvr, "Too long key length (%u)\n", params->key_len);
2834 if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2835 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
2836 brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr);
2840 key = &ifp->vif->profile.key[key_idx];
2841 memset(key, 0, sizeof(*key));
2842 if ((ext_key) && (!is_multicast_ether_addr(mac_addr)))
2843 memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN);
2844 key->len = params->key_len;
2845 key->index = key_idx;
2846 memcpy(key->data, params->key, key->len);
2848 key->flags = BRCMF_PRIMARY_KEY;
2850 if (params->seq && params->seq_len == 6) {
2854 ivptr = (u8 *)params->seq;
2855 key->rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2856 (ivptr[3] << 8) | ivptr[2];
2857 key->rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2858 key->iv_initialized = true;
2861 switch (params->cipher) {
2862 case WLAN_CIPHER_SUITE_WEP40:
2863 key->algo = CRYPTO_ALGO_WEP1;
2865 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
2867 case WLAN_CIPHER_SUITE_WEP104:
2868 key->algo = CRYPTO_ALGO_WEP128;
2870 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
2872 case WLAN_CIPHER_SUITE_TKIP:
2873 if (!brcmf_is_apmode(ifp->vif)) {
2874 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
2875 memcpy(keybuf, &key->data[24], sizeof(keybuf));
2876 memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
2877 memcpy(&key->data[16], keybuf, sizeof(keybuf));
2879 key->algo = CRYPTO_ALGO_TKIP;
2881 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
2883 case WLAN_CIPHER_SUITE_AES_CMAC:
2884 key->algo = CRYPTO_ALGO_AES_CCM;
2886 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2888 case WLAN_CIPHER_SUITE_CCMP:
2889 key->algo = CRYPTO_ALGO_AES_CCM;
2891 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
2894 bphy_err(drvr, "Invalid cipher (0x%x)\n", params->cipher);
2899 err = send_key_to_dongle(ifp, key);
2903 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2905 bphy_err(drvr, "get wsec error (%d)\n", err);
2909 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2911 bphy_err(drvr, "set wsec error (%d)\n", err);
2916 brcmf_dbg(TRACE, "Exit\n");
2921 brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2922 int link_id, u8 key_idx, bool pairwise,
2923 const u8 *mac_addr, void *cookie,
2924 void (*callback)(void *cookie,
2925 struct key_params *params))
2927 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2928 struct key_params params;
2929 struct brcmf_if *ifp = netdev_priv(ndev);
2930 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2931 struct brcmf_pub *drvr = cfg->pub;
2932 struct brcmf_cfg80211_security *sec;
2936 brcmf_dbg(TRACE, "Enter\n");
2937 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2938 if (!check_vif_up(ifp->vif))
2941 memset(¶ms, 0, sizeof(params));
2943 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2945 bphy_err(drvr, "WLC_GET_WSEC error (%d)\n", err);
2946 /* Ignore this error, may happen during DISASSOC */
2950 if (wsec & WEP_ENABLED) {
2951 sec = &profile->sec;
2952 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2953 params.cipher = WLAN_CIPHER_SUITE_WEP40;
2954 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
2955 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2956 params.cipher = WLAN_CIPHER_SUITE_WEP104;
2957 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
2959 } else if (wsec & TKIP_ENABLED) {
2960 params.cipher = WLAN_CIPHER_SUITE_TKIP;
2961 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
2962 } else if (wsec & AES_ENABLED) {
2963 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
2964 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2966 bphy_err(drvr, "Invalid algo (0x%x)\n", wsec);
2970 callback(cookie, ¶ms);
2973 brcmf_dbg(TRACE, "Exit\n");
2978 brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2979 struct net_device *ndev, int link_id,
2982 struct brcmf_if *ifp = netdev_priv(ndev);
2984 brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx);
2986 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
2989 brcmf_dbg(INFO, "Not supported\n");
2995 brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
2997 struct brcmf_pub *drvr = ifp->drvr;
3000 struct brcmf_wsec_key *key;
3003 for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
3004 key = &ifp->vif->profile.key[key_idx];
3005 if ((key->algo == CRYPTO_ALGO_WEP1) ||
3006 (key->algo == CRYPTO_ALGO_WEP128))
3009 if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
3012 err = send_key_to_dongle(ifp, key);
3014 bphy_err(drvr, "Setting WEP key failed (%d)\n", err);
3017 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
3019 bphy_err(drvr, "get wsec error (%d)\n", err);
3022 wsec |= WEP_ENABLED;
3023 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
3025 bphy_err(drvr, "set wsec error (%d)\n", err);
3028 static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si)
3030 struct nl80211_sta_flag_update *sfu;
3032 brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags);
3033 si->filled |= BIT_ULL(NL80211_STA_INFO_STA_FLAGS);
3034 sfu = &si->sta_flags;
3035 sfu->mask = BIT(NL80211_STA_FLAG_WME) |
3036 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3037 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3038 BIT(NL80211_STA_FLAG_AUTHORIZED);
3039 if (fw_sta_flags & BRCMF_STA_WME)
3040 sfu->set |= BIT(NL80211_STA_FLAG_WME);
3041 if (fw_sta_flags & BRCMF_STA_AUTHE)
3042 sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
3043 if (fw_sta_flags & BRCMF_STA_ASSOC)
3044 sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
3045 if (fw_sta_flags & BRCMF_STA_AUTHO)
3046 sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3049 static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si)
3051 struct brcmf_pub *drvr = ifp->drvr;
3054 struct brcmf_bss_info_le bss_le;
3059 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
3063 buf->len = cpu_to_le32(WL_BSS_INFO_MAX);
3064 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf,
3067 bphy_err(drvr, "Failed to get bss info (%d)\n", err);
3070 si->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
3071 si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period);
3072 si->bss_param.dtim_period = buf->bss_le.dtim_period;
3073 capability = le16_to_cpu(buf->bss_le.capability);
3074 if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT)
3075 si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
3076 if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3077 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
3078 if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
3079 si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
3086 brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp,
3087 struct station_info *sinfo)
3089 struct brcmf_pub *drvr = ifp->drvr;
3090 struct brcmf_scb_val_le scbval;
3091 struct brcmf_pktcnt_le pktcnt;
3096 /* Get the current tx rate */
3097 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
3099 bphy_err(drvr, "BRCMF_C_GET_RATE error (%d)\n", err);
3102 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
3103 sinfo->txrate.legacy = rate * 5;
3105 memset(&scbval, 0, sizeof(scbval));
3106 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval,
3109 bphy_err(drvr, "BRCMF_C_GET_RSSI error (%d)\n", err);
3112 rssi = le32_to_cpu(scbval.val);
3113 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
3114 sinfo->signal = rssi;
3116 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt,
3119 bphy_err(drvr, "BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err);
3122 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
3123 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC) |
3124 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
3125 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
3126 sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt);
3127 sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt);
3128 sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt);
3129 sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt);
3135 brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
3136 const u8 *mac, struct station_info *sinfo)
3138 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3139 struct brcmf_if *ifp = netdev_priv(ndev);
3140 struct brcmf_pub *drvr = cfg->pub;
3141 struct brcmf_scb_val_le scb_val;
3143 struct brcmf_sta_info_le sta_info_le;
3146 s32 total_rssi_avg = 0;
3152 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
3153 if (!check_vif_up(ifp->vif))
3156 if (brcmf_is_ibssmode(ifp->vif))
3157 return brcmf_cfg80211_get_station_ibss(ifp, sinfo);
3159 memset(&sta_info_le, 0, sizeof(sta_info_le));
3160 memcpy(&sta_info_le, mac, ETH_ALEN);
3161 err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info",
3163 sizeof(sta_info_le));
3164 is_tdls_peer = !err;
3166 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
3168 sizeof(sta_info_le));
3170 bphy_err(drvr, "GET STA INFO failed, %d\n", err);
3174 brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver));
3175 sinfo->filled = BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME);
3176 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
3177 sta_flags = le32_to_cpu(sta_info_le.flags);
3178 brcmf_convert_sta_flags(sta_flags, sinfo);
3179 sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
3181 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
3183 sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3184 if (sta_flags & BRCMF_STA_ASSOC) {
3185 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME);
3186 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
3187 brcmf_fill_bss_param(ifp, sinfo);
3189 if (sta_flags & BRCMF_STA_SCBSTATS) {
3190 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
3191 sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures);
3192 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
3193 sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts);
3194 sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts);
3195 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
3196 sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts);
3197 sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts);
3198 if (sinfo->tx_packets) {
3199 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
3200 sinfo->txrate.legacy =
3201 le32_to_cpu(sta_info_le.tx_rate) / 100;
3203 if (sinfo->rx_packets) {
3204 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
3205 sinfo->rxrate.legacy =
3206 le32_to_cpu(sta_info_le.rx_rate) / 100;
3208 if (le16_to_cpu(sta_info_le.ver) >= 4) {
3209 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES);
3210 sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes);
3211 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES);
3212 sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes);
3214 for (i = 0; i < BRCMF_ANT_MAX; i++) {
3215 if (sta_info_le.rssi[i] == 0 ||
3216 sta_info_le.rx_lastpkt_rssi[i] == 0)
3218 sinfo->chains |= BIT(count_rssi);
3219 sinfo->chain_signal[count_rssi] =
3220 sta_info_le.rx_lastpkt_rssi[i];
3221 sinfo->chain_signal_avg[count_rssi] =
3222 sta_info_le.rssi[i];
3223 total_rssi += sta_info_le.rx_lastpkt_rssi[i];
3224 total_rssi_avg += sta_info_le.rssi[i];
3228 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
3229 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
3230 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
3232 BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
3233 sinfo->signal = total_rssi / count_rssi;
3234 sinfo->signal_avg = total_rssi_avg / count_rssi;
3235 } else if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
3236 &ifp->vif->sme_state)) {
3237 memset(&scb_val, 0, sizeof(scb_val));
3238 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
3239 &scb_val, sizeof(scb_val));
3241 bphy_err(drvr, "Could not get rssi (%d)\n",
3245 rssi = le32_to_cpu(scb_val.val);
3246 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
3247 sinfo->signal = rssi;
3248 brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
3253 brcmf_dbg(TRACE, "Exit\n");
3258 brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
3259 int idx, u8 *mac, struct station_info *sinfo)
3261 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3262 struct brcmf_if *ifp = netdev_priv(ndev);
3263 struct brcmf_pub *drvr = cfg->pub;
3266 brcmf_dbg(TRACE, "Enter, idx %d\n", idx);
3269 cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST);
3270 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST,
3272 sizeof(cfg->assoclist));
3274 /* GET_ASSOCLIST unsupported by firmware of older chips */
3276 bphy_info_once(drvr, "BRCMF_C_GET_ASSOCLIST unsupported\n");
3278 bphy_err(drvr, "BRCMF_C_GET_ASSOCLIST failed, err=%d\n",
3281 cfg->assoclist.count = 0;
3285 if (idx < le32_to_cpu(cfg->assoclist.count)) {
3286 memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN);
3287 return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo);
3293 brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
3294 bool enabled, s32 timeout)
3298 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3299 struct brcmf_if *ifp = netdev_priv(ndev);
3300 struct brcmf_pub *drvr = cfg->pub;
3302 brcmf_dbg(TRACE, "Enter\n");
3305 * Powersave enable/disable request is coming from the
3306 * cfg80211 even before the interface is up. In that
3307 * scenario, driver will be storing the power save
3308 * preference in cfg struct to apply this to
3309 * FW later while initializing the dongle
3311 cfg->pwr_save = enabled;
3312 if (!check_vif_up(ifp->vif)) {
3314 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
3318 pm = enabled ? PM_FAST : PM_OFF;
3319 /* Do not enable the power save after assoc if it is a p2p interface */
3320 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
3321 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
3324 brcmf_info("power save %s\n", (pm ? "enabled" : "disabled"));
3326 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
3329 bphy_err(drvr, "net_device is not ready yet\n");
3331 bphy_err(drvr, "error (%d)\n", err);
3334 timeout = 2000; /* 2000ms - the maximum */
3335 err = brcmf_fil_iovar_int_set(ifp, "pm2_sleep_ret",
3336 min_t(u32, timeout, BRCMF_PS_MAX_TIMEOUT_MS));
3338 bphy_err(drvr, "Unable to set pm timeout, (%d)\n", err);
3341 brcmf_dbg(TRACE, "Exit\n");
3345 static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
3346 struct brcmf_bss_info_le *bi)
3348 struct wiphy *wiphy = cfg_to_wiphy(cfg);
3349 struct brcmf_pub *drvr = cfg->pub;
3350 struct cfg80211_bss *bss;
3351 enum nl80211_band band;
3352 struct brcmu_chan ch;
3355 u16 notify_capability;
3356 u16 notify_interval;
3358 size_t notify_ielen;
3359 struct cfg80211_inform_bss bss_data = {};
3361 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
3362 bphy_err(drvr, "Bss info is larger than buffer. Discarding\n");
3367 ch.chspec = le16_to_cpu(bi->chanspec);
3368 cfg->d11inf.decchspec(&ch);
3369 bi->ctl_ch = ch.control_ch_num;
3371 channel = bi->ctl_ch;
3373 if (channel <= CH_MAX_2G_CHANNEL)
3374 band = NL80211_BAND_2GHZ;
3376 band = NL80211_BAND_5GHZ;
3378 freq = ieee80211_channel_to_frequency(channel, band);
3379 bss_data.chan = ieee80211_get_channel(wiphy, freq);
3380 bss_data.scan_width = NL80211_BSS_CHAN_WIDTH_20;
3381 bss_data.boottime_ns = ktime_to_ns(ktime_get_boottime());
3383 notify_capability = le16_to_cpu(bi->capability);
3384 notify_interval = le16_to_cpu(bi->beacon_period);
3385 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
3386 notify_ielen = le32_to_cpu(bi->ie_length);
3387 bss_data.signal = (s16)le16_to_cpu(bi->RSSI) * 100;
3389 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
3390 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
3391 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
3392 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
3393 brcmf_dbg(CONN, "Signal: %d\n", bss_data.signal);
3395 bss = cfg80211_inform_bss_data(wiphy, &bss_data,
3396 CFG80211_BSS_FTYPE_UNKNOWN,
3397 (const u8 *)bi->BSSID,
3398 0, notify_capability,
3399 notify_interval, notify_ie,
3400 notify_ielen, GFP_KERNEL);
3405 cfg80211_put_bss(wiphy, bss);
3410 static struct brcmf_bss_info_le *
3411 next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
3414 return list->bss_info_le;
3415 return (struct brcmf_bss_info_le *)((unsigned long)bss +
3416 le32_to_cpu(bss->length));
3419 static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
3421 struct brcmf_pub *drvr = cfg->pub;
3422 struct brcmf_scan_results *bss_list;
3423 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
3427 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
3428 if (bss_list->count != 0 &&
3429 bss_list->version != BRCMF_BSS_INFO_VERSION) {
3430 bphy_err(drvr, "Version %d != WL_BSS_INFO_VERSION\n",
3434 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
3435 for (i = 0; i < bss_list->count; i++) {
3436 bi = next_bss_le(bss_list, bi);
3437 err = brcmf_inform_single_bss(cfg, bi);
3444 static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg,
3445 struct net_device *ndev, const u8 *bssid)
3447 struct wiphy *wiphy = cfg_to_wiphy(cfg);
3448 struct brcmf_pub *drvr = cfg->pub;
3449 struct ieee80211_channel *notify_channel;
3450 struct brcmf_bss_info_le *bi = NULL;
3451 struct ieee80211_supported_band *band;
3452 struct cfg80211_bss *bss;
3453 struct brcmu_chan ch;
3457 u16 notify_capability;
3458 u16 notify_interval;
3460 size_t notify_ielen;
3463 brcmf_dbg(TRACE, "Enter\n");
3465 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
3471 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
3473 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
3474 buf, WL_BSS_INFO_MAX);
3476 bphy_err(drvr, "WLC_GET_BSS_INFO failed: %d\n", err);
3480 bi = (struct brcmf_bss_info_le *)(buf + 4);
3482 ch.chspec = le16_to_cpu(bi->chanspec);
3483 cfg->d11inf.decchspec(&ch);
3485 if (ch.band == BRCMU_CHAN_BAND_2G)
3486 band = wiphy->bands[NL80211_BAND_2GHZ];
3488 band = wiphy->bands[NL80211_BAND_5GHZ];
3490 freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band);
3491 cfg->channel = freq;
3492 notify_channel = ieee80211_get_channel(wiphy, freq);
3494 notify_capability = le16_to_cpu(bi->capability);
3495 notify_interval = le16_to_cpu(bi->beacon_period);
3496 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
3497 notify_ielen = le32_to_cpu(bi->ie_length);
3498 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
3500 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.control_ch_num, freq);
3501 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
3502 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
3503 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
3505 bss = cfg80211_inform_bss(wiphy, notify_channel,
3506 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
3507 notify_capability, notify_interval,
3508 notify_ie, notify_ielen, notify_signal,
3516 cfg80211_put_bss(wiphy, bss);
3522 brcmf_dbg(TRACE, "Exit\n");
3527 static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
3528 struct brcmf_if *ifp)
3530 struct brcmf_pub *drvr = cfg->pub;
3531 struct brcmf_bss_info_le *bi = NULL;
3534 brcmf_dbg(TRACE, "Enter\n");
3535 if (brcmf_is_ibssmode(ifp->vif))
3538 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
3539 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
3540 cfg->extra_buf, WL_EXTRA_BUF_MAX);
3542 bphy_err(drvr, "Could not get bss info %d\n", err);
3543 goto update_bss_info_out;
3545 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
3546 err = brcmf_inform_single_bss(cfg, bi);
3548 update_bss_info_out:
3549 brcmf_dbg(TRACE, "Exit");
3553 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
3555 struct escan_info *escan = &cfg->escan_info;
3557 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
3558 if (cfg->int_escan_map || cfg->scan_request) {
3559 escan->escan_state = WL_ESCAN_STATE_IDLE;
3560 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
3562 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3563 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
3566 static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
3568 struct brcmf_cfg80211_info *cfg =
3569 container_of(work, struct brcmf_cfg80211_info,
3570 escan_timeout_work);
3572 brcmf_inform_bss(cfg);
3573 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
3576 static void brcmf_escan_timeout(struct timer_list *t)
3578 struct brcmf_cfg80211_info *cfg =
3579 from_timer(cfg, t, escan_timeout);
3580 struct brcmf_pub *drvr = cfg->pub;
3582 if (cfg->int_escan_map || cfg->scan_request) {
3583 bphy_err(drvr, "timer expired\n");
3584 schedule_work(&cfg->escan_timeout_work);
3589 brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
3590 struct brcmf_bss_info_le *bss,
3591 struct brcmf_bss_info_le *bss_info_le)
3593 struct brcmu_chan ch_bss, ch_bss_info_le;
3595 ch_bss.chspec = le16_to_cpu(bss->chanspec);
3596 cfg->d11inf.decchspec(&ch_bss);
3597 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
3598 cfg->d11inf.decchspec(&ch_bss_info_le);
3600 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
3601 ch_bss.band == ch_bss_info_le.band &&
3602 bss_info_le->SSID_len == bss->SSID_len &&
3603 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
3604 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
3605 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
3606 s16 bss_rssi = le16_to_cpu(bss->RSSI);
3607 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
3609 /* preserve max RSSI if the measurements are
3610 * both on-channel or both off-channel
3612 if (bss_info_rssi > bss_rssi)
3613 bss->RSSI = bss_info_le->RSSI;
3614 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
3615 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
3616 /* preserve the on-channel rssi measurement
3617 * if the new measurement is off channel
3619 bss->RSSI = bss_info_le->RSSI;
3620 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
3628 brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
3629 const struct brcmf_event_msg *e, void *data)
3631 struct brcmf_pub *drvr = ifp->drvr;
3632 struct brcmf_cfg80211_info *cfg = drvr->config;
3634 struct brcmf_escan_result_le *escan_result_le;
3636 struct brcmf_bss_info_le *bss_info_le;
3637 struct brcmf_bss_info_le *bss = NULL;
3639 struct brcmf_scan_results *list;
3645 if (status == BRCMF_E_STATUS_ABORT)
3648 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3649 bphy_err(drvr, "scan not ready, bsscfgidx=%d\n",
3654 if (status == BRCMF_E_STATUS_PARTIAL) {
3655 brcmf_dbg(SCAN, "ESCAN Partial result\n");
3656 if (e->datalen < sizeof(*escan_result_le)) {
3657 bphy_err(drvr, "invalid event data length\n");
3660 escan_result_le = (struct brcmf_escan_result_le *) data;
3661 if (!escan_result_le) {
3662 bphy_err(drvr, "Invalid escan result (NULL pointer)\n");
3665 escan_buflen = le32_to_cpu(escan_result_le->buflen);
3666 if (escan_buflen > BRCMF_ESCAN_BUF_SIZE ||
3667 escan_buflen > e->datalen ||
3668 escan_buflen < sizeof(*escan_result_le)) {
3669 bphy_err(drvr, "Invalid escan buffer length: %d\n",
3673 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
3674 bphy_err(drvr, "Invalid bss_count %d: ignoring\n",
3675 escan_result_le->bss_count);
3678 bss_info_le = &escan_result_le->bss_info_le;
3680 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
3683 if (!cfg->int_escan_map && !cfg->scan_request) {
3684 brcmf_dbg(SCAN, "result without cfg80211 request\n");
3688 bi_length = le32_to_cpu(bss_info_le->length);
3689 if (bi_length != escan_buflen - WL_ESCAN_RESULTS_FIXED_SIZE) {
3690 bphy_err(drvr, "Ignoring invalid bss_info length: %d\n",
3695 if (!(cfg_to_wiphy(cfg)->interface_modes &
3696 BIT(NL80211_IFTYPE_ADHOC))) {
3697 if (le16_to_cpu(bss_info_le->capability) &
3698 WLAN_CAPABILITY_IBSS) {
3699 bphy_err(drvr, "Ignoring IBSS result\n");
3704 list = (struct brcmf_scan_results *)
3705 cfg->escan_info.escan_buf;
3706 if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
3707 bphy_err(drvr, "Buffer is too small: ignoring\n");
3711 for (i = 0; i < list->count; i++) {
3712 bss = bss ? (struct brcmf_bss_info_le *)
3713 ((unsigned char *)bss +
3714 le32_to_cpu(bss->length)) : list->bss_info_le;
3715 if (brcmf_compare_update_same_bss(cfg, bss,
3719 memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le,
3721 list->version = le32_to_cpu(bss_info_le->version);
3722 list->buflen += bi_length;
3725 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
3726 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
3728 if (cfg->int_escan_map || cfg->scan_request) {
3729 brcmf_inform_bss(cfg);
3730 aborted = status != BRCMF_E_STATUS_SUCCESS;
3731 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
3733 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
3740 static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
3742 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
3743 brcmf_cfg80211_escan_handler);
3744 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
3745 /* Init scan_timeout timer */
3746 timer_setup(&cfg->escan_timeout, brcmf_escan_timeout, 0);
3747 INIT_WORK(&cfg->escan_timeout_work,
3748 brcmf_cfg80211_escan_timeout_worker);
3751 static struct cfg80211_scan_request *
3752 brcmf_alloc_internal_escan_request(struct wiphy *wiphy, u32 n_netinfo) {
3753 struct cfg80211_scan_request *req;
3756 req_size = sizeof(*req) +
3757 n_netinfo * sizeof(req->channels[0]) +
3758 n_netinfo * sizeof(*req->ssids);
3760 req = kzalloc(req_size, GFP_KERNEL);
3763 req->ssids = (void *)(&req->channels[0]) +
3764 n_netinfo * sizeof(req->channels[0]);
3769 static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req,
3770 u8 *ssid, u8 ssid_len, u8 channel)
3772 struct ieee80211_channel *chan;
3773 enum nl80211_band band;
3776 if (channel <= CH_MAX_2G_CHANNEL)
3777 band = NL80211_BAND_2GHZ;
3779 band = NL80211_BAND_5GHZ;
3781 freq = ieee80211_channel_to_frequency(channel, band);
3785 chan = ieee80211_get_channel(req->wiphy, freq);
3789 for (i = 0; i < req->n_channels; i++) {
3790 if (req->channels[i] == chan)
3793 if (i == req->n_channels) {
3795 req->channels[i] = chan;
3798 for (i = 0; i < req->n_ssids; i++) {
3799 if (req->ssids[i].ssid_len == ssid_len &&
3800 !memcmp(req->ssids[i].ssid, ssid, ssid_len))
3803 if (i == req->n_ssids) {
3804 memcpy(req->ssids[req->n_ssids].ssid, ssid, ssid_len);
3805 req->ssids[req->n_ssids++].ssid_len = ssid_len;
3810 static int brcmf_start_internal_escan(struct brcmf_if *ifp, u32 fwmap,
3811 struct cfg80211_scan_request *request)
3813 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3816 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3817 if (cfg->int_escan_map)
3818 brcmf_dbg(SCAN, "aborting internal scan: map=%u\n",
3819 cfg->int_escan_map);
3820 /* Abort any on-going scan */
3821 brcmf_abort_scanning(cfg);
3824 brcmf_dbg(SCAN, "start internal scan: map=%u\n", fwmap);
3825 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3826 cfg->escan_info.run = brcmf_run_escan;
3827 err = brcmf_do_escan(ifp, request);
3829 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3832 cfg->int_escan_map = fwmap;
3836 static struct brcmf_pno_net_info_le *
3837 brcmf_get_netinfo_array(struct brcmf_pno_scanresults_le *pfn_v1)
3839 struct brcmf_pno_scanresults_v2_le *pfn_v2;
3840 struct brcmf_pno_net_info_le *netinfo;
3842 switch (pfn_v1->version) {
3846 case cpu_to_le32(1):
3847 netinfo = (struct brcmf_pno_net_info_le *)(pfn_v1 + 1);
3849 case cpu_to_le32(2):
3850 pfn_v2 = (struct brcmf_pno_scanresults_v2_le *)pfn_v1;
3851 netinfo = (struct brcmf_pno_net_info_le *)(pfn_v2 + 1);
3858 /* PFN result doesn't have all the info which are required by the supplicant
3859 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3860 * via wl_inform_single_bss in the required format. Escan does require the
3861 * scan request in the form of cfg80211_scan_request. For timebeing, create
3862 * cfg80211_scan_request one out of the received PNO event.
3865 brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
3866 const struct brcmf_event_msg *e, void *data)
3868 struct brcmf_pub *drvr = ifp->drvr;
3869 struct brcmf_cfg80211_info *cfg = drvr->config;
3870 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3871 struct cfg80211_scan_request *request = NULL;
3872 struct wiphy *wiphy = cfg_to_wiphy(cfg);
3874 struct brcmf_pno_scanresults_le *pfn_result;
3880 brcmf_dbg(SCAN, "Enter\n");
3882 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
3883 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
3887 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3888 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
3892 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3893 result_count = le32_to_cpu(pfn_result->count);
3894 status = le32_to_cpu(pfn_result->status);
3896 /* PFN event is limited to fit 512 bytes so we may get
3897 * multiple NET_FOUND events. For now place a warning here.
3899 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
3900 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
3901 if (!result_count) {
3902 bphy_err(drvr, "FALSE PNO Event. (pfn_count == 0)\n");
3906 netinfo_start = brcmf_get_netinfo_array(pfn_result);
3907 datalen = e->datalen - ((void *)netinfo_start - (void *)pfn_result);
3908 if (datalen < result_count * sizeof(*netinfo)) {
3909 bphy_err(drvr, "insufficient event data\n");
3913 request = brcmf_alloc_internal_escan_request(wiphy,
3921 for (i = 0; i < result_count; i++) {
3922 netinfo = &netinfo_start[i];
3924 if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
3925 netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
3926 brcmf_dbg(SCAN, "SSID:%.32s Channel:%d\n",
3927 netinfo->SSID, netinfo->channel);
3928 bucket_map |= brcmf_pno_get_bucket_map(cfg->pno, netinfo);
3929 err = brcmf_internal_escan_add_info(request,
3940 err = brcmf_start_internal_escan(ifp, bucket_map, request);
3945 cfg80211_sched_scan_stopped(wiphy, 0);
3952 brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3953 struct net_device *ndev,
3954 struct cfg80211_sched_scan_request *req)
3956 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3957 struct brcmf_if *ifp = netdev_priv(ndev);
3958 struct brcmf_pub *drvr = cfg->pub;
3960 brcmf_dbg(SCAN, "Enter: n_match_sets=%d n_ssids=%d\n",
3961 req->n_match_sets, req->n_ssids);
3963 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3964 bphy_err(drvr, "Scanning suppressed: status=%lu\n",
3969 if (req->n_match_sets <= 0) {
3970 brcmf_dbg(SCAN, "invalid number of matchsets specified: %d\n",
3975 return brcmf_pno_start_sched_scan(ifp, req);
3978 static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3979 struct net_device *ndev, u64 reqid)
3981 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3982 struct brcmf_if *ifp = netdev_priv(ndev);
3984 brcmf_dbg(SCAN, "enter\n");
3985 brcmf_pno_stop_sched_scan(ifp, reqid);
3986 if (cfg->int_escan_map)
3987 brcmf_notify_escan_complete(cfg, ifp, true, true);
3991 static __always_inline void brcmf_delay(u32 ms)
3993 if (ms < 1000 / HZ) {
4001 static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
4002 u8 *pattern, u32 patternsize, u8 *mask,
4005 struct brcmf_fil_wowl_pattern_le *filter;
4012 masksize = (patternsize + 7) / 8;
4013 patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
4015 bufsize = sizeof(*filter) + patternsize + masksize;
4016 buf = kzalloc(bufsize, GFP_KERNEL);
4019 filter = (struct brcmf_fil_wowl_pattern_le *)buf;
4021 memcpy(filter->cmd, cmd, 4);
4022 filter->masksize = cpu_to_le32(masksize);
4023 filter->offset = cpu_to_le32(packet_offset);
4024 filter->patternoffset = cpu_to_le32(patternoffset);
4025 filter->patternsize = cpu_to_le32(patternsize);
4026 filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
4028 if ((mask) && (masksize))
4029 memcpy(buf + sizeof(*filter), mask, masksize);
4030 if ((pattern) && (patternsize))
4031 memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
4033 ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
4040 brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
4043 struct brcmf_pub *drvr = ifp->drvr;
4044 struct brcmf_cfg80211_info *cfg = drvr->config;
4045 struct brcmf_pno_scanresults_le *pfn_result;
4046 struct brcmf_pno_net_info_le *netinfo;
4048 brcmf_dbg(SCAN, "Enter\n");
4050 if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
4051 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
4055 pfn_result = (struct brcmf_pno_scanresults_le *)data;
4057 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
4058 brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n");
4062 if (le32_to_cpu(pfn_result->count) < 1) {
4063 bphy_err(drvr, "Invalid result count, expected 1 (%d)\n",
4064 le32_to_cpu(pfn_result->count));
4068 netinfo = brcmf_get_netinfo_array(pfn_result);
4069 if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
4070 netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
4071 memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
4072 cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
4073 cfg->wowl.nd->n_channels = 1;
4074 cfg->wowl.nd->channels[0] =
4075 ieee80211_channel_to_frequency(netinfo->channel,
4076 netinfo->channel <= CH_MAX_2G_CHANNEL ?
4077 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
4078 cfg->wowl.nd_info->n_matches = 1;
4079 cfg->wowl.nd_info->matches[0] = cfg->wowl.nd;
4081 /* Inform (the resume task) that the net detect information was recvd */
4082 cfg->wowl.nd_data_completed = true;
4083 wake_up(&cfg->wowl.nd_data_wait);
4090 static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
4092 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4093 struct brcmf_pub *drvr = cfg->pub;
4094 struct brcmf_wowl_wakeind_le wake_ind_le;
4095 struct cfg80211_wowlan_wakeup wakeup_data;
4096 struct cfg80211_wowlan_wakeup *wakeup;
4101 err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
4102 sizeof(wake_ind_le));
4104 bphy_err(drvr, "Get wowl_wakeind failed, err = %d\n", err);
4108 wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
4109 if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
4110 BRCMF_WOWL_RETR | BRCMF_WOWL_NET |
4111 BRCMF_WOWL_PFN_FOUND)) {
4112 wakeup = &wakeup_data;
4113 memset(&wakeup_data, 0, sizeof(wakeup_data));
4114 wakeup_data.pattern_idx = -1;
4116 if (wakeind & BRCMF_WOWL_MAGIC) {
4117 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
4118 wakeup_data.magic_pkt = true;
4120 if (wakeind & BRCMF_WOWL_DIS) {
4121 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
4122 wakeup_data.disconnect = true;
4124 if (wakeind & BRCMF_WOWL_BCN) {
4125 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
4126 wakeup_data.disconnect = true;
4128 if (wakeind & BRCMF_WOWL_RETR) {
4129 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
4130 wakeup_data.disconnect = true;
4132 if (wakeind & BRCMF_WOWL_NET) {
4133 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
4134 /* For now always map to pattern 0, no API to get
4135 * correct information available at the moment.
4137 wakeup_data.pattern_idx = 0;
4139 if (wakeind & BRCMF_WOWL_PFN_FOUND) {
4140 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n");
4141 timeout = wait_event_timeout(cfg->wowl.nd_data_wait,
4142 cfg->wowl.nd_data_completed,
4143 BRCMF_ND_INFO_TIMEOUT);
4145 bphy_err(drvr, "No result for wowl net detect\n");
4147 wakeup_data.net_detect = cfg->wowl.nd_info;
4149 if (wakeind & BRCMF_WOWL_GTK_FAILURE) {
4150 brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n");
4151 wakeup_data.gtk_rekey_failure = true;
4156 cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
4161 static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
4165 #endif /* CONFIG_PM */
4167 static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
4169 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4170 struct net_device *ndev = cfg_to_ndev(cfg);
4171 struct brcmf_if *ifp = netdev_priv(ndev);
4173 brcmf_dbg(TRACE, "Enter\n");
4175 if (cfg->wowl.active) {
4176 brcmf_report_wowl_wakeind(wiphy, ifp);
4177 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
4178 brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
4179 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
4180 brcmf_configure_arp_nd_offload(ifp, true);
4181 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
4182 cfg->wowl.pre_pmmode);
4183 cfg->wowl.active = false;
4184 if (cfg->wowl.nd_enabled) {
4185 brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev, 0);
4186 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
4187 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
4188 brcmf_notify_sched_scan_results);
4189 cfg->wowl.nd_enabled = false;
4195 static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
4196 struct brcmf_if *ifp,
4197 struct cfg80211_wowlan *wowl)
4200 struct brcmf_wowl_wakeind_le wowl_wakeind;
4203 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
4205 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
4206 brcmf_configure_arp_nd_offload(ifp, false);
4207 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode);
4208 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
4211 if (wowl->disconnect)
4212 wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
4213 if (wowl->magic_pkt)
4214 wowl_config |= BRCMF_WOWL_MAGIC;
4215 if ((wowl->patterns) && (wowl->n_patterns)) {
4216 wowl_config |= BRCMF_WOWL_NET;
4217 for (i = 0; i < wowl->n_patterns; i++) {
4218 brcmf_config_wowl_pattern(ifp, "add",
4219 (u8 *)wowl->patterns[i].pattern,
4220 wowl->patterns[i].pattern_len,
4221 (u8 *)wowl->patterns[i].mask,
4222 wowl->patterns[i].pkt_offset);
4225 if (wowl->nd_config) {
4226 brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev,
4228 wowl_config |= BRCMF_WOWL_PFN_FOUND;
4230 cfg->wowl.nd_data_completed = false;
4231 cfg->wowl.nd_enabled = true;
4232 /* Now reroute the event for PFN to the wowl function. */
4233 brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
4234 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
4235 brcmf_wowl_nd_results);
4237 if (wowl->gtk_rekey_failure)
4238 wowl_config |= BRCMF_WOWL_GTK_FAILURE;
4239 if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
4240 wowl_config |= BRCMF_WOWL_UNASSOC;
4242 memcpy(&wowl_wakeind, "clear", 6);
4243 brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", &wowl_wakeind,
4244 sizeof(wowl_wakeind));
4245 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
4246 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
4247 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
4248 cfg->wowl.active = true;
4251 static int brcmf_keepalive_start(struct brcmf_if *ifp, unsigned int interval)
4253 struct brcmf_mkeep_alive_pkt_le kalive = {0};
4256 /* Configure Null function/data keepalive */
4257 kalive.version = cpu_to_le16(1);
4258 kalive.period_msec = cpu_to_le32(interval * MSEC_PER_SEC);
4259 kalive.len_bytes = cpu_to_le16(0);
4260 kalive.keep_alive_id = 0;
4262 ret = brcmf_fil_iovar_data_set(ifp, "mkeep_alive", &kalive, sizeof(kalive));
4264 brcmf_err("keep-alive packet config failed, ret=%d\n", ret);
4269 static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
4270 struct cfg80211_wowlan *wowl)
4272 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4273 struct net_device *ndev = cfg_to_ndev(cfg);
4274 struct brcmf_if *ifp = netdev_priv(ndev);
4275 struct brcmf_cfg80211_vif *vif;
4277 brcmf_dbg(TRACE, "Enter\n");
4279 /* if the primary net_device is not READY there is nothing
4280 * we can do but pray resume goes smoothly.
4282 if (!check_vif_up(ifp->vif))
4285 /* Stop scheduled scan */
4286 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
4287 brcmf_cfg80211_sched_scan_stop(wiphy, ndev, 0);
4289 /* end any scanning */
4290 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
4291 brcmf_abort_scanning(cfg);
4294 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
4295 list_for_each_entry(vif, &cfg->vif_list, list) {
4296 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
4298 /* While going to suspend if associated with AP
4299 * disassociate from AP to save power while system is
4300 * in suspended state
4302 brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED, true);
4303 /* Make sure WPA_Supplicant receives all the event
4304 * generated due to DISASSOC call to the fw to keep
4305 * the state fw and WPA_Supplicant state consistent
4310 brcmf_set_mpc(ifp, 1);
4313 /* Configure WOWL paramaters */
4314 brcmf_configure_wowl(cfg, ifp, wowl);
4316 /* Prevent disassociation due to inactivity with keep-alive */
4317 brcmf_keepalive_start(ifp, 30);
4321 brcmf_dbg(TRACE, "Exit\n");
4322 /* clear any scanning activity */
4323 cfg->scan_status = 0;
4328 brcmf_pmksa_v3_op(struct brcmf_if *ifp, struct cfg80211_pmksa *pmksa,
4331 struct brcmf_pmk_op_v3_le *pmk_op;
4332 int length = offsetof(struct brcmf_pmk_op_v3_le, pmk);
4335 pmk_op = kzalloc(sizeof(*pmk_op), GFP_KERNEL);
4336 pmk_op->version = cpu_to_le16(BRCMF_PMKSA_VER_3);
4339 /* Flush operation, operate on entire list */
4340 pmk_op->count = cpu_to_le16(0);
4342 /* Single PMK operation */
4343 pmk_op->count = cpu_to_le16(1);
4344 length += sizeof(struct brcmf_pmksa_v3);
4345 memcpy(pmk_op->pmk[0].bssid, pmksa->bssid, ETH_ALEN);
4346 memcpy(pmk_op->pmk[0].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
4347 pmk_op->pmk[0].pmkid_len = WLAN_PMKID_LEN;
4348 pmk_op->pmk[0].time_left = cpu_to_le32(alive ? BRCMF_PMKSA_NO_EXPIRY : 0);
4351 pmk_op->length = cpu_to_le16(length);
4353 ret = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_op, sizeof(*pmk_op));
4359 brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp)
4361 struct brcmf_pmk_list_le *pmk_list;
4365 pmk_list = &cfg->pmk_list;
4366 npmk = le32_to_cpu(pmk_list->npmk);
4368 brcmf_dbg(CONN, "No of elements %d\n", npmk);
4369 for (i = 0; i < npmk; i++)
4370 brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid);
4372 return brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list,
4377 brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
4378 struct cfg80211_pmksa *pmksa)
4380 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4381 struct brcmf_if *ifp = netdev_priv(ndev);
4382 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
4383 struct brcmf_pub *drvr = cfg->pub;
4387 brcmf_dbg(TRACE, "Enter\n");
4388 if (!check_vif_up(ifp->vif))
4391 brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmksa->bssid);
4392 brcmf_dbg(CONN, "%*ph\n", WLAN_PMKID_LEN, pmksa->pmkid);
4394 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PMKID_V3))
4395 return brcmf_pmksa_v3_op(ifp, pmksa, true);
4397 /* TODO: implement PMKID_V2 */
4399 npmk = le32_to_cpu(cfg->pmk_list.npmk);
4400 for (i = 0; i < npmk; i++)
4401 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
4403 if (i < BRCMF_MAXPMKID) {
4404 memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN);
4405 memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
4408 cfg->pmk_list.npmk = cpu_to_le32(npmk);
4411 bphy_err(drvr, "Too many PMKSA entries cached %d\n", npmk);
4415 err = brcmf_update_pmklist(cfg, ifp);
4417 brcmf_dbg(TRACE, "Exit\n");
4422 brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
4423 struct cfg80211_pmksa *pmksa)
4425 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4426 struct brcmf_if *ifp = netdev_priv(ndev);
4427 struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
4428 struct brcmf_pub *drvr = cfg->pub;
4432 brcmf_dbg(TRACE, "Enter\n");
4433 if (!check_vif_up(ifp->vif))
4436 brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", pmksa->bssid);
4438 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PMKID_V3))
4439 return brcmf_pmksa_v3_op(ifp, pmksa, false);
4441 /* TODO: implement PMKID_V2 */
4443 npmk = le32_to_cpu(cfg->pmk_list.npmk);
4444 for (i = 0; i < npmk; i++)
4445 if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
4448 if ((npmk > 0) && (i < npmk)) {
4449 for (; i < (npmk - 1); i++) {
4450 memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN);
4451 memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid,
4454 memset(&pmk[i], 0, sizeof(*pmk));
4455 cfg->pmk_list.npmk = cpu_to_le32(npmk - 1);
4457 bphy_err(drvr, "Cache entry not found\n");
4461 err = brcmf_update_pmklist(cfg, ifp);
4463 brcmf_dbg(TRACE, "Exit\n");
4469 brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
4471 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4472 struct brcmf_if *ifp = netdev_priv(ndev);
4475 brcmf_dbg(TRACE, "Enter\n");
4476 if (!check_vif_up(ifp->vif))
4479 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PMKID_V3))
4480 return brcmf_pmksa_v3_op(ifp, NULL, false);
4482 /* TODO: implement PMKID_V2 */
4484 memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list));
4485 err = brcmf_update_pmklist(cfg, ifp);
4487 brcmf_dbg(TRACE, "Exit\n");
4492 static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
4494 struct brcmf_pub *drvr = ifp->drvr;
4499 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
4501 bphy_err(drvr, "auth error %d\n", err);
4505 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
4507 bphy_err(drvr, "wsec error %d\n", err);
4510 /* set upper-layer auth */
4511 if (brcmf_is_ibssmode(ifp->vif))
4512 wpa_val = WPA_AUTH_NONE;
4514 wpa_val = WPA_AUTH_DISABLED;
4515 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_val);
4517 bphy_err(drvr, "wpa_auth error %d\n", err);
4524 static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
4527 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
4529 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
4533 brcmf_configure_wpaie(struct brcmf_if *ifp,
4534 const struct brcmf_vs_tlv *wpa_ie,
4537 struct brcmf_pub *drvr = ifp->drvr;
4538 u32 auth = 0; /* d11 open authentication */
4550 u32 wme_bss_disable;
4553 brcmf_dbg(TRACE, "Enter\n");
4557 len = wpa_ie->len + TLV_HDR_LEN;
4558 data = (u8 *)wpa_ie;
4559 offset = TLV_HDR_LEN;
4561 offset += VS_IE_FIXED_HDR_LEN;
4563 offset += WPA_IE_VERSION_LEN;
4565 /* check for multicast cipher suite */
4566 if (offset + WPA_IE_MIN_OUI_LEN > len) {
4568 bphy_err(drvr, "no multicast cipher suite\n");
4572 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
4574 bphy_err(drvr, "ivalid OUI\n");
4577 offset += TLV_OUI_LEN;
4579 /* pick up multicast cipher */
4580 switch (data[offset]) {
4581 case WPA_CIPHER_NONE:
4584 case WPA_CIPHER_WEP_40:
4585 case WPA_CIPHER_WEP_104:
4588 case WPA_CIPHER_TKIP:
4589 gval = TKIP_ENABLED;
4591 case WPA_CIPHER_AES_CCM:
4596 bphy_err(drvr, "Invalid multi cast cipher info\n");
4601 /* walk thru unicast cipher list and pick up what we recognize */
4602 count = data[offset] + (data[offset + 1] << 8);
4603 offset += WPA_IE_SUITE_COUNT_LEN;
4604 /* Check for unicast suite(s) */
4605 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
4607 bphy_err(drvr, "no unicast cipher suite\n");
4610 for (i = 0; i < count; i++) {
4611 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
4613 bphy_err(drvr, "ivalid OUI\n");
4616 offset += TLV_OUI_LEN;
4617 switch (data[offset]) {
4618 case WPA_CIPHER_NONE:
4620 case WPA_CIPHER_WEP_40:
4621 case WPA_CIPHER_WEP_104:
4622 pval |= WEP_ENABLED;
4624 case WPA_CIPHER_TKIP:
4625 pval |= TKIP_ENABLED;
4627 case WPA_CIPHER_AES_CCM:
4628 pval |= AES_ENABLED;
4631 bphy_err(drvr, "Invalid unicast security info\n");
4635 /* walk thru auth management suite list and pick up what we recognize */
4636 count = data[offset] + (data[offset + 1] << 8);
4637 offset += WPA_IE_SUITE_COUNT_LEN;
4638 /* Check for auth key management suite(s) */
4639 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
4641 bphy_err(drvr, "no auth key mgmt suite\n");
4644 for (i = 0; i < count; i++) {
4645 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
4647 bphy_err(drvr, "ivalid OUI\n");
4650 offset += TLV_OUI_LEN;
4651 switch (data[offset]) {
4653 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
4654 wpa_auth |= WPA_AUTH_NONE;
4656 case RSN_AKM_UNSPECIFIED:
4657 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
4658 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
4659 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
4662 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
4663 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
4664 (wpa_auth |= WPA_AUTH_PSK);
4666 case RSN_AKM_SHA256_PSK:
4667 brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n");
4668 wpa_auth |= WPA2_AUTH_PSK_SHA256;
4670 case RSN_AKM_SHA256_1X:
4671 brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n");
4672 wpa_auth |= WPA2_AUTH_1X_SHA256;
4675 brcmf_dbg(TRACE, "RSN_AKM_SAE\n");
4676 wpa_auth |= WPA3_AUTH_SAE_PSK;
4679 bphy_err(drvr, "Invalid key mgmt info\n");
4684 mfp = BRCMF_MFP_NONE;
4686 wme_bss_disable = 1;
4687 if ((offset + RSN_CAP_LEN) <= len) {
4688 rsn_cap = data[offset] + (data[offset + 1] << 8);
4689 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
4690 wme_bss_disable = 0;
4691 if (rsn_cap & RSN_CAP_MFPR_MASK) {
4692 brcmf_dbg(TRACE, "MFP Required\n");
4693 mfp = BRCMF_MFP_REQUIRED;
4694 /* Firmware only supports mfp required in
4695 * combination with WPA2_AUTH_PSK_SHA256,
4696 * WPA2_AUTH_1X_SHA256, or WPA3_AUTH_SAE_PSK.
4698 if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 |
4699 WPA2_AUTH_1X_SHA256 |
4700 WPA3_AUTH_SAE_PSK))) {
4704 /* Firmware has requirement that WPA2_AUTH_PSK/
4705 * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI
4706 * is to be included in the rsn ie.
4708 if (wpa_auth & WPA2_AUTH_PSK_SHA256)
4709 wpa_auth |= WPA2_AUTH_PSK;
4710 else if (wpa_auth & WPA2_AUTH_1X_SHA256)
4711 wpa_auth |= WPA2_AUTH_UNSPECIFIED;
4712 } else if (rsn_cap & RSN_CAP_MFPC_MASK) {
4713 brcmf_dbg(TRACE, "MFP Capable\n");
4714 mfp = BRCMF_MFP_CAPABLE;
4717 offset += RSN_CAP_LEN;
4718 /* set wme_bss_disable to sync RSN Capabilities */
4719 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
4722 bphy_err(drvr, "wme_bss_disable error %d\n", err);
4726 /* Skip PMKID cnt as it is know to be 0 for AP. */
4727 offset += RSN_PMKID_COUNT_LEN;
4729 /* See if there is BIP wpa suite left for MFP */
4730 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) &&
4731 ((offset + WPA_IE_MIN_OUI_LEN) <= len)) {
4732 err = brcmf_fil_bsscfg_data_set(ifp, "bip",
4734 WPA_IE_MIN_OUI_LEN);
4736 bphy_err(drvr, "bip error %d\n", err);
4741 /* FOR WPS , set SES_OW_ENABLED */
4742 wsec = (pval | gval | SES_OW_ENABLED);
4745 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
4747 bphy_err(drvr, "auth error %d\n", err);
4751 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
4753 bphy_err(drvr, "wsec error %d\n", err);
4756 /* Configure MFP, this needs to go after wsec otherwise the wsec command
4757 * will overwrite the values set by MFP
4759 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) {
4760 err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp);
4762 bphy_err(drvr, "mfp error %d\n", err);
4766 /* set upper-layer auth */
4767 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
4769 bphy_err(drvr, "wpa_auth error %d\n", err);
4778 brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
4779 struct parsed_vndr_ies *vndr_ies)
4781 struct brcmf_vs_tlv *vndrie;
4782 struct brcmf_tlv *ie;
4783 struct parsed_vndr_ie_info *parsed_info;
4786 remaining_len = (s32)vndr_ie_len;
4787 memset(vndr_ies, 0, sizeof(*vndr_ies));
4789 ie = (struct brcmf_tlv *)vndr_ie_buf;
4791 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
4793 vndrie = (struct brcmf_vs_tlv *)ie;
4794 /* len should be bigger than OUI length + one */
4795 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
4796 brcmf_err("invalid vndr ie. length is too small %d\n",
4800 /* if wpa or wme ie, do not add ie */
4801 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
4802 ((vndrie->oui_type == WPA_OUI_TYPE) ||
4803 (vndrie->oui_type == WME_OUI_TYPE))) {
4804 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
4808 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
4810 /* save vndr ie information */
4811 parsed_info->ie_ptr = (char *)vndrie;
4812 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
4813 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
4817 brcmf_dbg(TRACE, "** OUI %3ph, type 0x%02x\n",
4818 parsed_info->vndrie.oui,
4819 parsed_info->vndrie.oui_type);
4821 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
4824 remaining_len -= (ie->len + TLV_HDR_LEN);
4825 if (remaining_len <= TLV_HDR_LEN)
4828 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
4835 brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
4837 strscpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN);
4839 put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
4841 put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
4843 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
4845 return ie_len + VNDR_IE_HDR_SIZE;
4848 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
4849 const u8 *vndr_ie_buf, u32 vndr_ie_len)
4851 struct brcmf_pub *drvr;
4852 struct brcmf_if *ifp;
4853 struct vif_saved_ie *saved_ie;
4857 u8 *mgmt_ie_buf = NULL;
4858 int mgmt_ie_buf_len;
4860 u32 del_add_ie_buf_len = 0;
4861 u32 total_ie_buf_len = 0;
4862 u32 parsed_ie_buf_len = 0;
4863 struct parsed_vndr_ies old_vndr_ies;
4864 struct parsed_vndr_ies new_vndr_ies;
4865 struct parsed_vndr_ie_info *vndrie_info;
4868 int remained_buf_len;
4874 saved_ie = &vif->saved_ie;
4876 brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
4878 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4881 curr_ie_buf = iovar_ie_buf;
4883 case BRCMF_VNDR_IE_PRBREQ_FLAG:
4884 mgmt_ie_buf = saved_ie->probe_req_ie;
4885 mgmt_ie_len = &saved_ie->probe_req_ie_len;
4886 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
4888 case BRCMF_VNDR_IE_PRBRSP_FLAG:
4889 mgmt_ie_buf = saved_ie->probe_res_ie;
4890 mgmt_ie_len = &saved_ie->probe_res_ie_len;
4891 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
4893 case BRCMF_VNDR_IE_BEACON_FLAG:
4894 mgmt_ie_buf = saved_ie->beacon_ie;
4895 mgmt_ie_len = &saved_ie->beacon_ie_len;
4896 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
4898 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
4899 mgmt_ie_buf = saved_ie->assoc_req_ie;
4900 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
4901 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
4903 case BRCMF_VNDR_IE_ASSOCRSP_FLAG:
4904 mgmt_ie_buf = saved_ie->assoc_res_ie;
4905 mgmt_ie_len = &saved_ie->assoc_res_ie_len;
4906 mgmt_ie_buf_len = sizeof(saved_ie->assoc_res_ie);
4910 bphy_err(drvr, "not suitable type\n");
4914 if (vndr_ie_len > mgmt_ie_buf_len) {
4916 bphy_err(drvr, "extra IE size too big\n");
4920 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
4921 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
4923 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
4924 for (i = 0; i < new_vndr_ies.count; i++) {
4925 vndrie_info = &new_vndr_ies.ie_info[i];
4926 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
4927 vndrie_info->ie_len);
4928 parsed_ie_buf_len += vndrie_info->ie_len;
4932 if (mgmt_ie_buf && *mgmt_ie_len) {
4933 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
4934 (memcmp(mgmt_ie_buf, curr_ie_buf,
4935 parsed_ie_buf_len) == 0)) {
4936 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
4940 /* parse old vndr_ie */
4941 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
4943 /* make a command to delete old ie */
4944 for (i = 0; i < old_vndr_ies.count; i++) {
4945 vndrie_info = &old_vndr_ies.ie_info[i];
4947 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%3ph\n",
4948 vndrie_info->vndrie.id,
4949 vndrie_info->vndrie.len,
4950 vndrie_info->vndrie.oui);
4952 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4953 vndrie_info->ie_ptr,
4954 vndrie_info->ie_len,
4956 curr_ie_buf += del_add_ie_buf_len;
4957 total_ie_buf_len += del_add_ie_buf_len;
4962 /* Add if there is any extra IE */
4963 if (mgmt_ie_buf && parsed_ie_buf_len) {
4966 remained_buf_len = mgmt_ie_buf_len;
4968 /* make a command to add new ie */
4969 for (i = 0; i < new_vndr_ies.count; i++) {
4970 vndrie_info = &new_vndr_ies.ie_info[i];
4972 /* verify remained buf size before copy data */
4973 if (remained_buf_len < (vndrie_info->vndrie.len +
4974 VNDR_IE_VSIE_OFFSET)) {
4975 bphy_err(drvr, "no space in mgmt_ie_buf: len left %d",
4979 remained_buf_len -= (vndrie_info->ie_len +
4980 VNDR_IE_VSIE_OFFSET);
4982 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%3ph\n",
4983 vndrie_info->vndrie.id,
4984 vndrie_info->vndrie.len,
4985 vndrie_info->vndrie.oui);
4987 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
4988 vndrie_info->ie_ptr,
4989 vndrie_info->ie_len,
4992 /* save the parsed IE in wl struct */
4993 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
4994 vndrie_info->ie_len);
4995 *mgmt_ie_len += vndrie_info->ie_len;
4997 curr_ie_buf += del_add_ie_buf_len;
4998 total_ie_buf_len += del_add_ie_buf_len;
5001 if (total_ie_buf_len) {
5002 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
5005 bphy_err(drvr, "vndr ie set error : %d\n", err);
5009 kfree(iovar_ie_buf);
5013 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
5015 static const s32 pktflags[] = {
5016 BRCMF_VNDR_IE_PRBREQ_FLAG,
5017 BRCMF_VNDR_IE_PRBRSP_FLAG,
5018 BRCMF_VNDR_IE_BEACON_FLAG
5022 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
5023 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
5025 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
5030 brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
5031 struct cfg80211_beacon_data *beacon)
5033 struct brcmf_pub *drvr = vif->ifp->drvr;
5036 /* Set Beacon IEs to FW */
5037 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
5038 beacon->tail, beacon->tail_len);
5040 bphy_err(drvr, "Set Beacon IE Failed\n");
5043 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
5045 /* Set Probe Response IEs to FW */
5046 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
5047 beacon->proberesp_ies,
5048 beacon->proberesp_ies_len);
5050 bphy_err(drvr, "Set Probe Resp IE Failed\n");
5052 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
5054 /* Set Assoc Response IEs to FW */
5055 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_ASSOCRSP_FLAG,
5056 beacon->assocresp_ies,
5057 beacon->assocresp_ies_len);
5059 brcmf_err("Set Assoc Resp IE Failed\n");
5061 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc Resp\n");
5067 brcmf_parse_configure_security(struct brcmf_if *ifp,
5068 struct cfg80211_ap_settings *settings,
5069 enum nl80211_iftype dev_role)
5071 const struct brcmf_tlv *rsn_ie;
5072 const struct brcmf_vs_tlv *wpa_ie;
5075 /* find the RSN_IE */
5076 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
5077 settings->beacon.tail_len, WLAN_EID_RSN);
5079 /* find the WPA_IE */
5080 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
5081 settings->beacon.tail_len);
5083 if (wpa_ie || rsn_ie) {
5084 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
5087 err = brcmf_configure_wpaie(ifp, wpa_ie, false);
5091 struct brcmf_vs_tlv *tmp_ie;
5093 tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
5096 err = brcmf_configure_wpaie(ifp, tmp_ie, true);
5101 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
5102 brcmf_configure_opensecurity(ifp);
5109 brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
5110 struct cfg80211_ap_settings *settings)
5113 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5114 struct brcmf_if *ifp = netdev_priv(ndev);
5115 struct brcmf_pub *drvr = cfg->pub;
5116 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
5117 struct cfg80211_crypto_settings *crypto = &settings->crypto;
5118 const struct brcmf_tlv *ssid_ie;
5119 const struct brcmf_tlv *country_ie;
5120 struct brcmf_ssid_le ssid_le;
5122 struct brcmf_join_params join_params;
5123 enum nl80211_iftype dev_role;
5124 struct brcmf_fil_bss_enable_le bss_enable;
5125 u16 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef);
5130 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
5131 settings->chandef.chan->hw_value,
5132 settings->chandef.center_freq1, settings->chandef.width,
5133 settings->beacon_interval, settings->dtim_period);
5134 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
5135 settings->ssid, settings->ssid_len, settings->auth_type,
5136 settings->inactivity_timeout);
5137 dev_role = ifp->vif->wdev.iftype;
5138 mbss = ifp->vif->mbss;
5140 /* store current 11d setting */
5141 if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY,
5142 &ifp->vif->is_11d)) {
5143 is_11d = supports_11d = false;
5145 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
5146 settings->beacon.tail_len,
5148 is_11d = country_ie ? 1 : 0;
5149 supports_11d = true;
5152 memset(&ssid_le, 0, sizeof(ssid_le));
5153 if (settings->ssid == NULL || settings->ssid_len == 0) {
5154 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
5155 ssid_ie = brcmf_parse_tlvs(
5156 (u8 *)&settings->beacon.head[ie_offset],
5157 settings->beacon.head_len - ie_offset,
5159 if (!ssid_ie || ssid_ie->len > IEEE80211_MAX_SSID_LEN)
5162 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
5163 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
5164 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
5166 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
5167 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
5171 brcmf_set_mpc(ifp, 0);
5172 brcmf_configure_arp_nd_offload(ifp, false);
5175 /* Parameters shared by all radio interfaces */
5177 if ((supports_11d) && (is_11d != ifp->vif->is_11d)) {
5178 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
5181 bphy_err(drvr, "Regulatory Set Error, %d\n",
5186 if (settings->beacon_interval) {
5187 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
5188 settings->beacon_interval);
5190 bphy_err(drvr, "Beacon Interval Set Error, %d\n",
5195 if (settings->dtim_period) {
5196 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
5197 settings->dtim_period);
5199 bphy_err(drvr, "DTIM Interval Set Error, %d\n",
5205 if ((dev_role == NL80211_IFTYPE_AP) &&
5206 ((ifp->ifidx == 0) ||
5207 (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB) &&
5208 !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN)))) {
5209 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
5211 bphy_err(drvr, "BRCMF_C_DOWN error %d\n",
5215 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
5218 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
5220 bphy_err(drvr, "SET INFRA error %d\n", err);
5223 } else if (WARN_ON(supports_11d && (is_11d != ifp->vif->is_11d))) {
5224 /* Multiple-BSS should use same 11d configuration */
5229 /* Interface specific setup */
5230 if (dev_role == NL80211_IFTYPE_AP) {
5231 if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
5232 brcmf_fil_iovar_int_set(ifp, "mbss", 1);
5234 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
5236 bphy_err(drvr, "setting AP mode failed %d\n",
5241 /* Firmware 10.x requires setting channel after enabling
5242 * AP and before bringing interface up.
5244 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
5246 bphy_err(drvr, "Set Channel failed: chspec=%d, %d\n",
5251 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
5253 bphy_err(drvr, "BRCMF_C_UP error (%d)\n", err);
5258 brcmf_dbg(INFO, "using PSK offload\n");
5259 profile->use_fwauth |= BIT(BRCMF_PROFILE_FWAUTH_PSK);
5260 err = brcmf_set_pmk(ifp, crypto->psk,
5261 BRCMF_WSEC_MAX_PSK_LEN);
5265 if (crypto->sae_pwd) {
5266 brcmf_dbg(INFO, "using SAE offload\n");
5267 profile->use_fwauth |= BIT(BRCMF_PROFILE_FWAUTH_SAE);
5268 err = brcmf_set_sae_password(ifp, crypto->sae_pwd,
5269 crypto->sae_pwd_len);
5273 if (profile->use_fwauth == 0)
5274 profile->use_fwauth = BIT(BRCMF_PROFILE_FWAUTH_NONE);
5276 err = brcmf_parse_configure_security(ifp, settings,
5279 bphy_err(drvr, "brcmf_parse_configure_security error\n");
5283 /* On DOWN the firmware removes the WEP keys, reconfigure
5284 * them if they were set.
5286 brcmf_cfg80211_reconfigure_wep(ifp);
5288 memset(&join_params, 0, sizeof(join_params));
5289 /* join parameters starts with ssid */
5290 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
5292 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
5293 &join_params, sizeof(join_params));
5295 bphy_err(drvr, "SET SSID error (%d)\n", err);
5299 err = brcmf_fil_iovar_int_set(ifp, "closednet",
5300 settings->hidden_ssid);
5302 bphy_err(drvr, "%s closednet error (%d)\n",
5303 settings->hidden_ssid ?
5304 "enabled" : "disabled",
5309 brcmf_dbg(TRACE, "AP mode configuration complete\n");
5310 } else if (dev_role == NL80211_IFTYPE_P2P_GO) {
5311 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
5313 bphy_err(drvr, "Set Channel failed: chspec=%d, %d\n",
5318 err = brcmf_parse_configure_security(ifp, settings,
5319 NL80211_IFTYPE_P2P_GO);
5321 brcmf_err("brcmf_parse_configure_security error\n");
5325 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
5328 bphy_err(drvr, "setting ssid failed %d\n", err);
5331 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
5332 bss_enable.enable = cpu_to_le32(1);
5333 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
5334 sizeof(bss_enable));
5336 bphy_err(drvr, "bss_enable config failed %d\n", err);
5340 brcmf_dbg(TRACE, "GO mode configuration complete\n");
5345 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
5346 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
5347 brcmf_net_setcarrier(ifp, true);
5350 if ((err) && (!mbss)) {
5351 brcmf_set_mpc(ifp, 1);
5352 brcmf_configure_arp_nd_offload(ifp, true);
5357 static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev,
5358 unsigned int link_id)
5360 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5361 struct brcmf_if *ifp = netdev_priv(ndev);
5362 struct brcmf_pub *drvr = cfg->pub;
5363 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
5365 struct brcmf_fil_bss_enable_le bss_enable;
5366 struct brcmf_join_params join_params;
5368 brcmf_dbg(TRACE, "Enter\n");
5370 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
5371 /* Due to most likely deauths outstanding we sleep */
5372 /* first to make sure they get processed by fw. */
5375 if (profile->use_fwauth != BIT(BRCMF_PROFILE_FWAUTH_NONE)) {
5376 if (profile->use_fwauth & BIT(BRCMF_PROFILE_FWAUTH_PSK))
5377 brcmf_set_pmk(ifp, NULL, 0);
5378 if (profile->use_fwauth & BIT(BRCMF_PROFILE_FWAUTH_SAE))
5379 brcmf_set_sae_password(ifp, NULL, 0);
5380 profile->use_fwauth = BIT(BRCMF_PROFILE_FWAUTH_NONE);
5383 if (ifp->vif->mbss) {
5384 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
5388 /* First BSS doesn't get a full reset */
5389 if (ifp->bsscfgidx == 0)
5390 brcmf_fil_iovar_int_set(ifp, "closednet", 0);
5392 memset(&join_params, 0, sizeof(join_params));
5393 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
5394 &join_params, sizeof(join_params));
5396 bphy_err(drvr, "SET SSID error (%d)\n", err);
5397 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
5399 bphy_err(drvr, "BRCMF_C_DOWN error %d\n", err);
5400 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
5402 bphy_err(drvr, "setting AP mode failed %d\n", err);
5403 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
5404 brcmf_fil_iovar_int_set(ifp, "mbss", 0);
5405 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
5407 /* Bring device back up so it can be used again */
5408 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
5410 bphy_err(drvr, "BRCMF_C_UP error %d\n", err);
5412 brcmf_vif_clear_mgmt_ies(ifp->vif);
5414 bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
5415 bss_enable.enable = cpu_to_le32(0);
5416 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
5417 sizeof(bss_enable));
5419 bphy_err(drvr, "bss_enable config failed %d\n", err);
5421 brcmf_set_mpc(ifp, 1);
5422 brcmf_configure_arp_nd_offload(ifp, true);
5423 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
5424 brcmf_net_setcarrier(ifp, false);
5430 brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
5431 struct cfg80211_beacon_data *info)
5433 struct brcmf_if *ifp = netdev_priv(ndev);
5435 brcmf_dbg(TRACE, "Enter\n");
5437 return brcmf_config_ap_mgmt_ie(ifp->vif, info);
5441 brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
5442 struct station_del_parameters *params)
5444 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5445 struct brcmf_pub *drvr = cfg->pub;
5446 struct brcmf_scb_val_le scbval;
5447 struct brcmf_if *ifp = netdev_priv(ndev);
5453 brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
5455 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
5456 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
5457 if (!check_vif_up(ifp->vif))
5460 memcpy(&scbval.ea, params->mac, ETH_ALEN);
5461 scbval.val = cpu_to_le32(params->reason_code);
5462 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
5463 &scbval, sizeof(scbval));
5465 bphy_err(drvr, "SCB_DEAUTHENTICATE_FOR_REASON failed %d\n",
5468 brcmf_dbg(TRACE, "Exit\n");
5473 brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
5474 const u8 *mac, struct station_parameters *params)
5476 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5477 struct brcmf_pub *drvr = cfg->pub;
5478 struct brcmf_if *ifp = netdev_priv(ndev);
5481 brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
5482 params->sta_flags_mask, params->sta_flags_set);
5484 /* Ignore all 00 MAC */
5485 if (is_zero_ether_addr(mac))
5488 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5491 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
5492 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
5493 (void *)mac, ETH_ALEN);
5495 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
5496 (void *)mac, ETH_ALEN);
5498 bphy_err(drvr, "Setting SCB (de-)authorize failed, %d\n", err);
5504 brcmf_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
5505 struct wireless_dev *wdev,
5506 struct mgmt_frame_regs *upd)
5508 struct brcmf_cfg80211_vif *vif;
5510 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
5512 vif->mgmt_rx_reg = upd->interface_stypes;
5517 brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
5518 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
5520 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5521 struct ieee80211_channel *chan = params->chan;
5522 struct brcmf_pub *drvr = cfg->pub;
5523 const u8 *buf = params->buf;
5524 size_t len = params->len;
5525 const struct ieee80211_mgmt *mgmt;
5526 struct brcmf_cfg80211_vif *vif;
5530 struct brcmf_fil_action_frame_le *action_frame;
5531 struct brcmf_fil_af_params_le *af_params;
5535 struct brcmf_mf_params_le *mf_params;
5539 brcmf_dbg(TRACE, "Enter\n");
5543 mgmt = (const struct ieee80211_mgmt *)buf;
5545 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
5546 bphy_err(drvr, "Driver only allows MGMT packet type\n");
5550 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
5552 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
5553 /* Right now the only reason to get a probe response */
5554 /* is for p2p listen response or for p2p GO from */
5555 /* wpa_supplicant. Unfortunately the probe is send */
5556 /* on primary ndev, while dongle wants it on the p2p */
5557 /* vif. Since this is only reason for a probe */
5558 /* response to be sent, the vif is taken from cfg. */
5559 /* If ever desired to send proberesp for non p2p */
5560 /* response then data should be checked for */
5561 /* "DIRECT-". Note in future supplicant will take */
5562 /* dedicated p2p wdev to do this and then this 'hack'*/
5563 /* is not needed anymore. */
5564 ie_offset = DOT11_MGMT_HDR_LEN +
5565 DOT11_BCN_PRB_FIXED_LEN;
5566 ie_len = len - ie_offset;
5567 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
5568 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
5569 err = brcmf_vif_set_mgmt_ie(vif,
5570 BRCMF_VNDR_IE_PRBRSP_FLAG,
5573 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
5575 } else if (ieee80211_is_action(mgmt->frame_control)) {
5576 if (len > BRCMF_FIL_ACTION_FRAME_SIZE + DOT11_MGMT_HDR_LEN) {
5577 bphy_err(drvr, "invalid action frame length\n");
5581 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
5582 if (af_params == NULL) {
5583 bphy_err(drvr, "unable to allocate frame\n");
5587 action_frame = &af_params->action_frame;
5588 /* Add the packet Id */
5589 action_frame->packet_id = cpu_to_le32(*cookie);
5591 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
5592 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
5593 /* Add the length exepted for 802.11 header */
5594 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
5595 /* Add the channel. Use the one specified as parameter if any or
5596 * the current one (got from the firmware) otherwise
5599 freq = chan->center_freq;
5601 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
5603 chan_nr = ieee80211_frequency_to_channel(freq);
5604 af_params->channel = cpu_to_le32(chan_nr);
5605 af_params->dwell_time = cpu_to_le32(params->wait);
5606 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
5607 le16_to_cpu(action_frame->len));
5609 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
5610 *cookie, le16_to_cpu(action_frame->len), freq);
5612 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
5615 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
5618 } else if (ieee80211_is_auth(mgmt->frame_control)) {
5619 reinit_completion(&vif->mgmt_tx);
5620 clear_bit(BRCMF_MGMT_TX_ACK, &vif->mgmt_tx_status);
5621 clear_bit(BRCMF_MGMT_TX_NOACK, &vif->mgmt_tx_status);
5622 clear_bit(BRCMF_MGMT_TX_OFF_CHAN_COMPLETED,
5623 &vif->mgmt_tx_status);
5625 mf_params_len = offsetof(struct brcmf_mf_params_le, data) +
5626 (len - DOT11_MGMT_HDR_LEN);
5627 mf_params = kzalloc(mf_params_len, GFP_KERNEL);
5633 mf_params->dwell_time = cpu_to_le32(MGMT_AUTH_FRAME_DWELL_TIME);
5634 mf_params->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
5635 mf_params->frame_control = mgmt->frame_control;
5638 freq = chan->center_freq;
5640 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
5642 chan_nr = ieee80211_frequency_to_channel(freq);
5643 mf_params->channel = cpu_to_le32(chan_nr);
5644 memcpy(&mf_params->da[0], &mgmt->da[0], ETH_ALEN);
5645 memcpy(&mf_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
5646 mf_params->packet_id = cpu_to_le32(*cookie);
5647 memcpy(mf_params->data, &buf[DOT11_MGMT_HDR_LEN],
5648 le16_to_cpu(mf_params->len));
5650 brcmf_dbg(TRACE, "Auth frame, cookie=%d, fc=%04x, len=%d, channel=%d\n",
5651 le32_to_cpu(mf_params->packet_id),
5652 le16_to_cpu(mf_params->frame_control),
5653 le16_to_cpu(mf_params->len),
5654 le32_to_cpu(mf_params->channel));
5656 vif->mgmt_tx_id = le32_to_cpu(mf_params->packet_id);
5657 set_bit(BRCMF_MGMT_TX_SEND_FRAME, &vif->mgmt_tx_status);
5659 err = brcmf_fil_bsscfg_data_set(vif->ifp, "mgmt_frame",
5660 mf_params, mf_params_len);
5662 bphy_err(drvr, "Failed to send Auth frame: err=%d\n",
5668 wait_for_completion_timeout(&vif->mgmt_tx,
5669 MGMT_AUTH_FRAME_WAIT_TIME);
5670 if (test_bit(BRCMF_MGMT_TX_ACK, &vif->mgmt_tx_status)) {
5671 brcmf_dbg(TRACE, "TX Auth frame operation is success\n");
5674 bphy_err(drvr, "TX Auth frame operation is failed: status=%ld)\n",
5675 vif->mgmt_tx_status);
5679 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
5684 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
5685 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%zu\n", len);
5692 static int brcmf_cfg80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
5693 struct net_device *ndev,
5694 s32 rssi_low, s32 rssi_high)
5696 struct brcmf_cfg80211_vif *vif;
5697 struct brcmf_if *ifp;
5700 brcmf_dbg(TRACE, "low=%d high=%d", rssi_low, rssi_high);
5702 ifp = netdev_priv(ndev);
5705 if (rssi_low != vif->cqm_rssi_low || rssi_high != vif->cqm_rssi_high) {
5706 /* The firmware will send an event when the RSSI is less than or
5707 * equal to a configured level and the previous RSSI event was
5708 * less than or equal to a different level. Set a third level
5709 * so that we also detect the transition from rssi <= rssi_high
5710 * to rssi > rssi_high.
5712 struct brcmf_rssi_event_le config = {
5713 .rate_limit_msec = cpu_to_le32(0),
5714 .rssi_level_num = 3,
5716 clamp_val(rssi_low, S8_MIN, S8_MAX - 2),
5717 clamp_val(rssi_high, S8_MIN + 1, S8_MAX - 1),
5722 err = brcmf_fil_iovar_data_set(ifp, "rssi_event", &config,
5727 vif->cqm_rssi_low = rssi_low;
5728 vif->cqm_rssi_high = rssi_high;
5736 brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
5737 struct wireless_dev *wdev,
5740 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5741 struct brcmf_pub *drvr = cfg->pub;
5742 struct brcmf_cfg80211_vif *vif;
5745 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
5747 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
5749 bphy_err(drvr, "No p2p device available for probe response\n");
5753 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
5758 static int brcmf_cfg80211_get_channel(struct wiphy *wiphy,
5759 struct wireless_dev *wdev,
5760 unsigned int link_id,
5761 struct cfg80211_chan_def *chandef)
5763 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5764 struct net_device *ndev = wdev->netdev;
5765 struct brcmf_pub *drvr = cfg->pub;
5766 struct brcmu_chan ch;
5767 enum nl80211_band band = 0;
5768 enum nl80211_chan_width width = 0;
5772 if (!ndev || drvr->bus_if->state != BRCMF_BUS_UP)
5775 err = brcmf_fil_iovar_int_get(netdev_priv(ndev), "chanspec", &chanspec);
5777 bphy_err(drvr, "chanspec failed (%d)\n", err);
5781 ch.chspec = chanspec;
5782 cfg->d11inf.decchspec(&ch);
5785 case BRCMU_CHAN_BAND_2G:
5786 band = NL80211_BAND_2GHZ;
5788 case BRCMU_CHAN_BAND_5G:
5789 band = NL80211_BAND_5GHZ;
5794 case BRCMU_CHAN_BW_80:
5795 width = NL80211_CHAN_WIDTH_80;
5797 case BRCMU_CHAN_BW_40:
5798 width = NL80211_CHAN_WIDTH_40;
5800 case BRCMU_CHAN_BW_20:
5801 width = NL80211_CHAN_WIDTH_20;
5803 case BRCMU_CHAN_BW_80P80:
5804 width = NL80211_CHAN_WIDTH_80P80;
5806 case BRCMU_CHAN_BW_160:
5807 width = NL80211_CHAN_WIDTH_160;
5811 freq = ieee80211_channel_to_frequency(ch.control_ch_num, band);
5812 chandef->chan = ieee80211_get_channel(wiphy, freq);
5813 chandef->width = width;
5814 chandef->center_freq1 = ieee80211_channel_to_frequency(ch.chnum, band);
5815 chandef->center_freq2 = 0;
5820 static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
5821 struct wireless_dev *wdev,
5822 enum nl80211_crit_proto_id proto,
5825 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5826 struct brcmf_cfg80211_vif *vif;
5828 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
5830 /* only DHCP support for now */
5831 if (proto != NL80211_CRIT_PROTO_DHCP)
5834 /* suppress and abort scanning */
5835 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
5836 brcmf_abort_scanning(cfg);
5838 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
5841 static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
5842 struct wireless_dev *wdev)
5844 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5845 struct brcmf_cfg80211_vif *vif;
5847 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
5849 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
5850 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
5854 brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
5855 const struct brcmf_event_msg *e, void *data)
5857 switch (e->reason) {
5858 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
5859 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
5861 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
5862 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
5863 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5865 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
5866 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
5867 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
5874 static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
5879 case NL80211_TDLS_DISCOVERY_REQ:
5880 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
5882 case NL80211_TDLS_SETUP:
5883 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
5885 case NL80211_TDLS_TEARDOWN:
5886 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
5889 brcmf_err("unsupported operation: %d\n", oper);
5895 static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
5896 struct net_device *ndev, const u8 *peer,
5897 enum nl80211_tdls_operation oper)
5899 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5900 struct brcmf_pub *drvr = cfg->pub;
5901 struct brcmf_if *ifp;
5902 struct brcmf_tdls_iovar_le info;
5905 ret = brcmf_convert_nl80211_tdls_oper(oper);
5909 ifp = netdev_priv(ndev);
5910 memset(&info, 0, sizeof(info));
5911 info.mode = (u8)ret;
5913 memcpy(info.ea, peer, ETH_ALEN);
5915 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
5916 &info, sizeof(info));
5918 bphy_err(drvr, "tdls_endpoint iovar failed: ret=%d\n", ret);
5924 brcmf_cfg80211_update_conn_params(struct wiphy *wiphy,
5925 struct net_device *ndev,
5926 struct cfg80211_connect_params *sme,
5929 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5930 struct brcmf_pub *drvr = cfg->pub;
5931 struct brcmf_if *ifp;
5934 if (!(changed & UPDATE_ASSOC_IES))
5937 ifp = netdev_priv(ndev);
5938 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
5939 sme->ie, sme->ie_len);
5941 bphy_err(drvr, "Set Assoc REQ IE Failed\n");
5943 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
5950 brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev,
5951 struct cfg80211_gtk_rekey_data *gtk)
5953 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
5954 struct brcmf_pub *drvr = cfg->pub;
5955 struct brcmf_if *ifp = netdev_priv(ndev);
5956 struct brcmf_gtk_keyinfo_le gtk_le;
5959 brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx);
5961 memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck));
5962 memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek));
5963 memcpy(gtk_le.replay_counter, gtk->replay_ctr,
5964 sizeof(gtk_le.replay_counter));
5966 ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", >k_le,
5969 bphy_err(drvr, "gtk_key_info iovar failed: ret=%d\n", ret);
5975 static int brcmf_cfg80211_set_pmk(struct wiphy *wiphy, struct net_device *dev,
5976 const struct cfg80211_pmk_conf *conf)
5978 struct brcmf_if *ifp;
5980 brcmf_dbg(TRACE, "enter\n");
5982 /* expect using firmware supplicant for 1X */
5983 ifp = netdev_priv(dev);
5984 if (WARN_ON(ifp->vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_1X))
5987 if (conf->pmk_len > BRCMF_WSEC_MAX_PSK_LEN)
5990 return brcmf_set_pmk(ifp, conf->pmk, conf->pmk_len);
5993 static int brcmf_cfg80211_del_pmk(struct wiphy *wiphy, struct net_device *dev,
5996 struct brcmf_if *ifp;
5998 brcmf_dbg(TRACE, "enter\n");
5999 ifp = netdev_priv(dev);
6000 if (WARN_ON(ifp->vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_1X))
6003 return brcmf_set_pmk(ifp, NULL, 0);
6007 brcmf_cfg80211_external_auth(struct wiphy *wiphy, struct net_device *dev,
6008 struct cfg80211_external_auth_params *params)
6010 struct brcmf_if *ifp;
6011 struct brcmf_pub *drvr;
6012 struct brcmf_auth_req_status_le auth_status;
6015 brcmf_dbg(TRACE, "Enter\n");
6017 ifp = netdev_priv(dev);
6019 if (params->status == WLAN_STATUS_SUCCESS) {
6020 auth_status.flags = cpu_to_le16(BRCMF_EXTAUTH_SUCCESS);
6022 bphy_err(drvr, "External authentication failed: status=%d\n",
6024 auth_status.flags = cpu_to_le16(BRCMF_EXTAUTH_FAIL);
6027 memcpy(auth_status.peer_mac, params->bssid, ETH_ALEN);
6028 auth_status.ssid_len = cpu_to_le32(min_t(u8, params->ssid.ssid_len,
6029 IEEE80211_MAX_SSID_LEN));
6030 memcpy(auth_status.ssid, params->ssid.ssid, auth_status.ssid_len);
6032 ret = brcmf_fil_iovar_data_set(ifp, "auth_status", &auth_status,
6033 sizeof(auth_status));
6035 bphy_err(drvr, "auth_status iovar failed: ret=%d\n", ret);
6040 static struct cfg80211_ops brcmf_cfg80211_ops = {
6041 .add_virtual_intf = brcmf_cfg80211_add_iface,
6042 .del_virtual_intf = brcmf_cfg80211_del_iface,
6043 .change_virtual_intf = brcmf_cfg80211_change_iface,
6044 .scan = brcmf_cfg80211_scan,
6045 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
6046 .join_ibss = brcmf_cfg80211_join_ibss,
6047 .leave_ibss = brcmf_cfg80211_leave_ibss,
6048 .get_station = brcmf_cfg80211_get_station,
6049 .dump_station = brcmf_cfg80211_dump_station,
6050 .set_tx_power = brcmf_cfg80211_set_tx_power,
6051 .get_tx_power = brcmf_cfg80211_get_tx_power,
6052 .add_key = brcmf_cfg80211_add_key,
6053 .del_key = brcmf_cfg80211_del_key,
6054 .get_key = brcmf_cfg80211_get_key,
6055 .set_default_key = brcmf_cfg80211_config_default_key,
6056 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
6057 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
6058 .connect = brcmf_cfg80211_connect,
6059 .disconnect = brcmf_cfg80211_disconnect,
6060 .suspend = brcmf_cfg80211_suspend,
6061 .resume = brcmf_cfg80211_resume,
6062 .set_pmksa = brcmf_cfg80211_set_pmksa,
6063 .del_pmksa = brcmf_cfg80211_del_pmksa,
6064 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
6065 .start_ap = brcmf_cfg80211_start_ap,
6066 .stop_ap = brcmf_cfg80211_stop_ap,
6067 .change_beacon = brcmf_cfg80211_change_beacon,
6068 .del_station = brcmf_cfg80211_del_station,
6069 .change_station = brcmf_cfg80211_change_station,
6070 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
6071 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
6072 .update_mgmt_frame_registrations =
6073 brcmf_cfg80211_update_mgmt_frame_registrations,
6074 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
6075 .set_cqm_rssi_range_config = brcmf_cfg80211_set_cqm_rssi_range_config,
6076 .remain_on_channel = brcmf_p2p_remain_on_channel,
6077 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
6078 .get_channel = brcmf_cfg80211_get_channel,
6079 .start_p2p_device = brcmf_p2p_start_device,
6080 .stop_p2p_device = brcmf_p2p_stop_device,
6081 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
6082 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
6083 .tdls_oper = brcmf_cfg80211_tdls_oper,
6084 .update_connect_params = brcmf_cfg80211_update_conn_params,
6085 .set_pmk = brcmf_cfg80211_set_pmk,
6086 .del_pmk = brcmf_cfg80211_del_pmk,
6087 .external_auth = brcmf_cfg80211_external_auth,
6090 struct cfg80211_ops *brcmf_cfg80211_get_ops(struct brcmf_mp_device *settings)
6092 struct cfg80211_ops *ops;
6094 ops = kmemdup(&brcmf_cfg80211_ops, sizeof(brcmf_cfg80211_ops),
6097 if (ops && settings->roamoff)
6098 ops->update_connect_params = NULL;
6103 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
6104 enum nl80211_iftype type)
6106 struct brcmf_cfg80211_vif *vif_walk;
6107 struct brcmf_cfg80211_vif *vif;
6109 struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
6111 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
6113 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
6115 return ERR_PTR(-ENOMEM);
6117 vif->wdev.wiphy = cfg->wiphy;
6118 vif->wdev.iftype = type;
6120 brcmf_init_prof(&vif->profile);
6122 if (type == NL80211_IFTYPE_AP &&
6123 brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) {
6125 list_for_each_entry(vif_walk, &cfg->vif_list, list) {
6126 if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
6134 init_completion(&vif->mgmt_tx);
6135 list_add_tail(&vif->list, &cfg->vif_list);
6139 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
6141 list_del(&vif->list);
6145 void brcmf_cfg80211_free_netdev(struct net_device *ndev)
6147 struct brcmf_cfg80211_vif *vif;
6148 struct brcmf_if *ifp;
6150 ifp = netdev_priv(ndev);
6154 brcmf_free_vif(vif);
6157 static bool brcmf_is_linkup(struct brcmf_cfg80211_vif *vif,
6158 const struct brcmf_event_msg *e)
6160 u32 event = e->event_code;
6161 u32 status = e->status;
6163 if ((vif->profile.use_fwsup == BRCMF_PROFILE_FWSUP_PSK ||
6164 vif->profile.use_fwsup == BRCMF_PROFILE_FWSUP_SAE) &&
6165 event == BRCMF_E_PSK_SUP &&
6166 status == BRCMF_E_STATUS_FWSUP_COMPLETED)
6167 set_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
6168 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
6169 brcmf_dbg(CONN, "Processing set ssid\n");
6170 memcpy(vif->profile.bssid, e->addr, ETH_ALEN);
6171 if (vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_PSK &&
6172 vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_SAE)
6175 set_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
6178 if (test_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state) &&
6179 test_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state)) {
6180 clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
6181 clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
6187 static bool brcmf_is_linkdown(struct brcmf_cfg80211_vif *vif,
6188 const struct brcmf_event_msg *e)
6190 u32 event = e->event_code;
6191 u16 flags = e->flags;
6193 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
6194 (event == BRCMF_E_DISASSOC_IND) ||
6195 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
6196 brcmf_dbg(CONN, "Processing link down\n");
6197 clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
6198 clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
6204 static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
6205 const struct brcmf_event_msg *e)
6207 u32 event = e->event_code;
6208 u32 status = e->status;
6210 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
6211 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
6212 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
6216 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
6217 brcmf_dbg(CONN, "Processing connecting & no network found\n");
6221 if (event == BRCMF_E_PSK_SUP &&
6222 status != BRCMF_E_STATUS_FWSUP_COMPLETED) {
6223 brcmf_dbg(CONN, "Processing failed supplicant state: %u\n",
6231 static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
6233 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
6235 kfree(conn_info->req_ie);
6236 conn_info->req_ie = NULL;
6237 conn_info->req_ie_len = 0;
6238 kfree(conn_info->resp_ie);
6239 conn_info->resp_ie = NULL;
6240 conn_info->resp_ie_len = 0;
6243 u8 brcmf_map_prio_to_prec(void *config, u8 prio)
6245 struct brcmf_cfg80211_info *cfg = (struct brcmf_cfg80211_info *)config;
6248 return (prio == PRIO_8021D_NONE || prio == PRIO_8021D_BE) ?
6251 /* For those AC(s) with ACM flag set to 1, convert its 4-level priority
6252 * to an 8-level precedence which is the same as BE's
6254 if (prio > PRIO_8021D_EE &&
6255 cfg->ac_priority[prio] == cfg->ac_priority[PRIO_8021D_BE])
6256 return cfg->ac_priority[prio] * 2;
6258 /* Conversion of 4-level priority to 8-level precedence */
6259 if (prio == PRIO_8021D_BE || prio == PRIO_8021D_BK ||
6260 prio == PRIO_8021D_CL || prio == PRIO_8021D_VO)
6261 return cfg->ac_priority[prio] * 2;
6263 return cfg->ac_priority[prio] * 2 + 1;
6266 u8 brcmf_map_prio_to_aci(void *config, u8 prio)
6268 /* Prio here refers to the 802.1d priority in range of 0 to 7.
6269 * ACI here refers to the WLAN AC Index in range of 0 to 3.
6270 * This function will return ACI corresponding to input prio.
6272 struct brcmf_cfg80211_info *cfg = (struct brcmf_cfg80211_info *)config;
6275 return cfg->ac_priority[prio];
6280 static void brcmf_init_wmm_prio(u8 *priority)
6282 /* Initialize AC priority array to default
6283 * 802.1d priority as per following table:
6284 * 802.1d prio 0,3 maps to BE
6285 * 802.1d prio 1,2 maps to BK
6286 * 802.1d prio 4,5 maps to VI
6287 * 802.1d prio 6,7 maps to VO
6289 priority[0] = BRCMF_FWS_FIFO_AC_BE;
6290 priority[3] = BRCMF_FWS_FIFO_AC_BE;
6291 priority[1] = BRCMF_FWS_FIFO_AC_BK;
6292 priority[2] = BRCMF_FWS_FIFO_AC_BK;
6293 priority[4] = BRCMF_FWS_FIFO_AC_VI;
6294 priority[5] = BRCMF_FWS_FIFO_AC_VI;
6295 priority[6] = BRCMF_FWS_FIFO_AC_VO;
6296 priority[7] = BRCMF_FWS_FIFO_AC_VO;
6299 static void brcmf_wifi_prioritize_acparams(const
6300 struct brcmf_cfg80211_edcf_acparam *acp, u8 *priority)
6307 u8 ranking_basis[EDCF_AC_COUNT];
6308 u8 aci_prio[EDCF_AC_COUNT]; /* AC_BE, AC_BK, AC_VI, AC_VO */
6311 for (aci = 0; aci < EDCF_AC_COUNT; aci++, acp++) {
6312 aifsn = acp->ACI & EDCF_AIFSN_MASK;
6313 acm = (acp->ACI & EDCF_ACM_MASK) ? 1 : 0;
6314 ecwmin = acp->ECW & EDCF_ECWMIN_MASK;
6315 ecwmax = (acp->ECW & EDCF_ECWMAX_MASK) >> EDCF_ECWMAX_SHIFT;
6316 brcmf_dbg(CONN, "ACI %d aifsn %d acm %d ecwmin %d ecwmax %d\n",
6317 aci, aifsn, acm, ecwmin, ecwmax);
6318 /* Default AC_VO will be the lowest ranking value */
6319 ranking_basis[aci] = aifsn + ecwmin + ecwmax;
6320 /* Initialise priority starting at 0 (AC_BE) */
6323 /* If ACM is set, STA can't use this AC as per 802.11.
6324 * Change the ranking to BE
6326 if (aci != AC_BE && aci != AC_BK && acm == 1)
6327 ranking_basis[aci] = ranking_basis[AC_BE];
6330 /* Ranking method which works for AC priority
6331 * swapping when values for cwmin, cwmax and aifsn are varied
6332 * Compare each aci_prio against each other aci_prio
6334 for (aci = 0; aci < EDCF_AC_COUNT; aci++) {
6335 for (index = 0; index < EDCF_AC_COUNT; index++) {
6337 /* Smaller ranking value has higher priority,
6338 * so increment priority for each ACI which has
6339 * a higher ranking value
6341 if (ranking_basis[aci] < ranking_basis[index])
6347 /* By now, aci_prio[] will be in range of 0 to 3.
6348 * Use ACI prio to get the new priority value for
6349 * each 802.1d traffic type, in this range.
6351 if (!(aci_prio[AC_BE] == aci_prio[AC_BK] &&
6352 aci_prio[AC_BK] == aci_prio[AC_VI] &&
6353 aci_prio[AC_VI] == aci_prio[AC_VO])) {
6354 /* 802.1d 0,3 maps to BE */
6355 priority[0] = aci_prio[AC_BE];
6356 priority[3] = aci_prio[AC_BE];
6358 /* 802.1d 1,2 maps to BK */
6359 priority[1] = aci_prio[AC_BK];
6360 priority[2] = aci_prio[AC_BK];
6362 /* 802.1d 4,5 maps to VO */
6363 priority[4] = aci_prio[AC_VI];
6364 priority[5] = aci_prio[AC_VI];
6366 /* 802.1d 6,7 maps to VO */
6367 priority[6] = aci_prio[AC_VO];
6368 priority[7] = aci_prio[AC_VO];
6370 /* Initialize to default priority */
6371 brcmf_init_wmm_prio(priority);
6374 brcmf_dbg(CONN, "Adj prio BE 0->%d, BK 1->%d, BK 2->%d, BE 3->%d\n",
6375 priority[0], priority[1], priority[2], priority[3]);
6377 brcmf_dbg(CONN, "Adj prio VI 4->%d, VI 5->%d, VO 6->%d, VO 7->%d\n",
6378 priority[4], priority[5], priority[6], priority[7]);
6381 static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
6382 struct brcmf_if *ifp)
6384 struct brcmf_pub *drvr = cfg->pub;
6385 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
6386 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
6387 struct brcmf_cfg80211_edcf_acparam edcf_acparam_info[EDCF_AC_COUNT];
6392 brcmf_clear_assoc_ies(cfg);
6394 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
6395 cfg->extra_buf, WL_ASSOC_INFO_MAX);
6397 bphy_err(drvr, "could not get assoc info (%d)\n", err);
6401 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
6402 req_len = le32_to_cpu(assoc_info->req_len);
6403 resp_len = le32_to_cpu(assoc_info->resp_len);
6404 if (req_len > WL_EXTRA_BUF_MAX || resp_len > WL_EXTRA_BUF_MAX) {
6405 bphy_err(drvr, "invalid lengths in assoc info: req %u resp %u\n",
6410 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
6414 bphy_err(drvr, "could not get assoc req (%d)\n", err);
6417 conn_info->req_ie_len = req_len;
6419 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
6421 if (!conn_info->req_ie)
6422 conn_info->req_ie_len = 0;
6424 conn_info->req_ie_len = 0;
6425 conn_info->req_ie = NULL;
6428 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
6432 bphy_err(drvr, "could not get assoc resp (%d)\n", err);
6435 conn_info->resp_ie_len = resp_len;
6436 conn_info->resp_ie =
6437 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
6439 if (!conn_info->resp_ie)
6440 conn_info->resp_ie_len = 0;
6442 err = brcmf_fil_iovar_data_get(ifp, "wme_ac_sta",
6444 sizeof(edcf_acparam_info));
6446 brcmf_err("could not get wme_ac_sta (%d)\n", err);
6450 brcmf_wifi_prioritize_acparams(edcf_acparam_info,
6453 conn_info->resp_ie_len = 0;
6454 conn_info->resp_ie = NULL;
6456 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
6457 conn_info->req_ie_len, conn_info->resp_ie_len);
6463 brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
6464 struct net_device *ndev,
6465 const struct brcmf_event_msg *e)
6467 struct brcmf_if *ifp = netdev_priv(ndev);
6468 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
6469 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
6470 struct wiphy *wiphy = cfg_to_wiphy(cfg);
6471 struct ieee80211_channel *notify_channel = NULL;
6472 struct ieee80211_supported_band *band;
6473 struct brcmf_bss_info_le *bi;
6474 struct brcmu_chan ch;
6475 struct cfg80211_roam_info roam_info = {};
6480 brcmf_dbg(TRACE, "Enter\n");
6482 brcmf_get_assoc_ies(cfg, ifp);
6483 memcpy(profile->bssid, e->addr, ETH_ALEN);
6484 brcmf_update_bss_info(cfg, ifp);
6486 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
6492 /* data sent to dongle has to be little endian */
6493 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
6494 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
6495 buf, WL_BSS_INFO_MAX);
6500 bi = (struct brcmf_bss_info_le *)(buf + 4);
6501 ch.chspec = le16_to_cpu(bi->chanspec);
6502 cfg->d11inf.decchspec(&ch);
6504 if (ch.band == BRCMU_CHAN_BAND_2G)
6505 band = wiphy->bands[NL80211_BAND_2GHZ];
6507 band = wiphy->bands[NL80211_BAND_5GHZ];
6509 freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band);
6510 notify_channel = ieee80211_get_channel(wiphy, freq);
6515 roam_info.links[0].channel = notify_channel;
6516 roam_info.links[0].bssid = profile->bssid;
6517 roam_info.req_ie = conn_info->req_ie;
6518 roam_info.req_ie_len = conn_info->req_ie_len;
6519 roam_info.resp_ie = conn_info->resp_ie;
6520 roam_info.resp_ie_len = conn_info->resp_ie_len;
6522 cfg80211_roamed(ndev, &roam_info, GFP_KERNEL);
6523 brcmf_dbg(CONN, "Report roaming result\n");
6525 if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X && profile->is_ft) {
6526 cfg80211_port_authorized(ndev, profile->bssid, NULL, 0, GFP_KERNEL);
6527 brcmf_dbg(CONN, "Report port authorized\n");
6530 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
6531 brcmf_dbg(TRACE, "Exit\n");
6536 brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
6537 struct net_device *ndev, const struct brcmf_event_msg *e,
6540 struct brcmf_if *ifp = netdev_priv(ndev);
6541 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
6542 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
6543 struct cfg80211_connect_resp_params conn_params;
6545 brcmf_dbg(TRACE, "Enter\n");
6547 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
6548 &ifp->vif->sme_state)) {
6549 memset(&conn_params, 0, sizeof(conn_params));
6551 brcmf_get_assoc_ies(cfg, ifp);
6552 brcmf_update_bss_info(cfg, ifp);
6553 set_bit(BRCMF_VIF_STATUS_CONNECTED,
6554 &ifp->vif->sme_state);
6555 conn_params.status = WLAN_STATUS_SUCCESS;
6557 clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS,
6558 &ifp->vif->sme_state);
6559 clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS,
6560 &ifp->vif->sme_state);
6561 conn_params.status = WLAN_STATUS_AUTH_TIMEOUT;
6563 conn_params.links[0].bssid = profile->bssid;
6564 conn_params.req_ie = conn_info->req_ie;
6565 conn_params.req_ie_len = conn_info->req_ie_len;
6566 conn_params.resp_ie = conn_info->resp_ie;
6567 conn_params.resp_ie_len = conn_info->resp_ie_len;
6568 cfg80211_connect_done(ndev, &conn_params, GFP_KERNEL);
6569 brcmf_dbg(CONN, "Report connect result - connection %s\n",
6570 completed ? "succeeded" : "failed");
6572 brcmf_dbg(TRACE, "Exit\n");
6577 brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
6578 struct net_device *ndev,
6579 const struct brcmf_event_msg *e, void *data)
6581 struct brcmf_pub *drvr = cfg->pub;
6582 static int generation;
6583 u32 event = e->event_code;
6584 u32 reason = e->reason;
6585 struct station_info *sinfo;
6587 brcmf_dbg(CONN, "event %s (%u), reason %d\n",
6588 brcmf_fweh_event_name(event), event, reason);
6589 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
6590 ndev != cfg_to_ndev(cfg)) {
6591 brcmf_dbg(CONN, "AP mode link down\n");
6592 complete(&cfg->vif_disabled);
6596 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
6597 (reason == BRCMF_E_STATUS_SUCCESS)) {
6599 bphy_err(drvr, "No IEs present in ASSOC/REASSOC_IND\n");
6603 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
6607 sinfo->assoc_req_ies = data;
6608 sinfo->assoc_req_ies_len = e->datalen;
6610 sinfo->generation = generation;
6611 cfg80211_new_sta(ndev, e->addr, sinfo, GFP_KERNEL);
6614 } else if ((event == BRCMF_E_DISASSOC_IND) ||
6615 (event == BRCMF_E_DEAUTH_IND) ||
6616 (event == BRCMF_E_DEAUTH)) {
6617 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
6623 brcmf_notify_connect_status(struct brcmf_if *ifp,
6624 const struct brcmf_event_msg *e, void *data)
6626 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
6627 struct net_device *ndev = ifp->ndev;
6628 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
6629 struct ieee80211_channel *chan;
6632 if ((e->event_code == BRCMF_E_DEAUTH) ||
6633 (e->event_code == BRCMF_E_DEAUTH_IND) ||
6634 (e->event_code == BRCMF_E_DISASSOC_IND) ||
6635 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
6636 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
6639 if (brcmf_is_apmode(ifp->vif)) {
6640 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
6641 } else if (brcmf_is_linkup(ifp->vif, e)) {
6642 brcmf_dbg(CONN, "Linkup\n");
6643 if (brcmf_is_ibssmode(ifp->vif)) {
6644 brcmf_inform_ibss(cfg, ndev, e->addr);
6645 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
6646 memcpy(profile->bssid, e->addr, ETH_ALEN);
6647 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
6648 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
6649 &ifp->vif->sme_state);
6650 set_bit(BRCMF_VIF_STATUS_CONNECTED,
6651 &ifp->vif->sme_state);
6653 brcmf_bss_connect_done(cfg, ndev, e, true);
6654 brcmf_net_setcarrier(ifp, true);
6655 } else if (brcmf_is_linkdown(ifp->vif, e)) {
6656 brcmf_dbg(CONN, "Linkdown\n");
6657 if (!brcmf_is_ibssmode(ifp->vif) &&
6658 (test_bit(BRCMF_VIF_STATUS_CONNECTED,
6659 &ifp->vif->sme_state) ||
6660 test_bit(BRCMF_VIF_STATUS_CONNECTING,
6661 &ifp->vif->sme_state))) {
6662 if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
6663 &ifp->vif->sme_state) &&
6664 memcmp(profile->bssid, e->addr, ETH_ALEN))
6667 brcmf_bss_connect_done(cfg, ndev, e, false);
6668 brcmf_link_down(ifp->vif,
6669 brcmf_map_fw_linkdown_reason(e),
6671 (BRCMF_E_DEAUTH_IND |
6672 BRCMF_E_DISASSOC_IND)
6674 brcmf_init_prof(ndev_to_prof(ndev));
6675 if (ndev != cfg_to_ndev(cfg))
6676 complete(&cfg->vif_disabled);
6677 brcmf_net_setcarrier(ifp, false);
6679 } else if (brcmf_is_nonetwork(cfg, e)) {
6680 if (brcmf_is_ibssmode(ifp->vif))
6681 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
6682 &ifp->vif->sme_state);
6684 brcmf_bss_connect_done(cfg, ndev, e, false);
6691 brcmf_notify_roaming_status(struct brcmf_if *ifp,
6692 const struct brcmf_event_msg *e, void *data)
6694 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
6695 u32 event = e->event_code;
6696 u32 status = e->status;
6698 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
6699 if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
6700 &ifp->vif->sme_state)) {
6701 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
6703 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
6704 brcmf_net_setcarrier(ifp, true);
6712 brcmf_notify_mic_status(struct brcmf_if *ifp,
6713 const struct brcmf_event_msg *e, void *data)
6715 u16 flags = e->flags;
6716 enum nl80211_key_type key_type;
6718 if (flags & BRCMF_EVENT_MSG_GROUP)
6719 key_type = NL80211_KEYTYPE_GROUP;
6721 key_type = NL80211_KEYTYPE_PAIRWISE;
6723 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
6729 static s32 brcmf_notify_rssi(struct brcmf_if *ifp,
6730 const struct brcmf_event_msg *e, void *data)
6732 struct brcmf_cfg80211_vif *vif = ifp->vif;
6733 struct brcmf_rssi_be *info = data;
6734 s32 rssi, snr = 0, noise = 0;
6735 s32 low, high, last;
6737 if (e->datalen >= sizeof(*info)) {
6738 rssi = be32_to_cpu(info->rssi);
6739 snr = be32_to_cpu(info->snr);
6740 noise = be32_to_cpu(info->noise);
6741 } else if (e->datalen >= sizeof(rssi)) {
6742 rssi = be32_to_cpu(*(__be32 *)data);
6744 brcmf_err("insufficient RSSI event data\n");
6748 low = vif->cqm_rssi_low;
6749 high = vif->cqm_rssi_high;
6750 last = vif->cqm_rssi_last;
6752 brcmf_dbg(TRACE, "rssi=%d snr=%d noise=%d low=%d high=%d last=%d\n",
6753 rssi, snr, noise, low, high, last);
6755 vif->cqm_rssi_last = rssi;
6757 if (rssi <= low || rssi == 0) {
6758 brcmf_dbg(INFO, "LOW rssi=%d\n", rssi);
6759 cfg80211_cqm_rssi_notify(ifp->ndev,
6760 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
6762 } else if (rssi > high) {
6763 brcmf_dbg(INFO, "HIGH rssi=%d\n", rssi);
6764 cfg80211_cqm_rssi_notify(ifp->ndev,
6765 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
6772 static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
6773 const struct brcmf_event_msg *e, void *data)
6775 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
6776 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
6777 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
6778 struct brcmf_cfg80211_vif *vif;
6780 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
6781 ifevent->action, ifevent->flags, ifevent->ifidx,
6782 ifevent->bsscfgidx);
6784 spin_lock(&event->vif_event_lock);
6785 event->action = ifevent->action;
6788 switch (ifevent->action) {
6789 case BRCMF_E_IF_ADD:
6790 /* waiting process may have timed out */
6791 if (!cfg->vif_event.vif) {
6792 spin_unlock(&event->vif_event_lock);
6799 vif->wdev.netdev = ifp->ndev;
6800 ifp->ndev->ieee80211_ptr = &vif->wdev;
6801 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
6803 spin_unlock(&event->vif_event_lock);
6804 wake_up(&event->vif_wq);
6807 case BRCMF_E_IF_DEL:
6808 spin_unlock(&event->vif_event_lock);
6809 /* event may not be upon user request */
6810 if (brcmf_cfg80211_vif_event_armed(cfg))
6811 wake_up(&event->vif_wq);
6814 case BRCMF_E_IF_CHANGE:
6815 spin_unlock(&event->vif_event_lock);
6816 wake_up(&event->vif_wq);
6820 spin_unlock(&event->vif_event_lock);
6827 brcmf_notify_ext_auth_request(struct brcmf_if *ifp,
6828 const struct brcmf_event_msg *e, void *data)
6830 struct brcmf_pub *drvr = ifp->drvr;
6831 struct cfg80211_external_auth_params params;
6832 struct brcmf_auth_req_status_le *auth_req =
6833 (struct brcmf_auth_req_status_le *)data;
6836 brcmf_dbg(INFO, "Enter: event %s (%d) received\n",
6837 brcmf_fweh_event_name(e->event_code), e->event_code);
6839 if (e->datalen < sizeof(*auth_req)) {
6840 bphy_err(drvr, "Event %s (%d) data too small. Ignore\n",
6841 brcmf_fweh_event_name(e->event_code), e->event_code);
6845 memset(¶ms, 0, sizeof(params));
6846 params.action = NL80211_EXTERNAL_AUTH_START;
6847 params.key_mgmt_suite = ntohl(WLAN_AKM_SUITE_SAE);
6848 params.status = WLAN_STATUS_SUCCESS;
6849 params.ssid.ssid_len = min_t(u32, 32, le32_to_cpu(auth_req->ssid_len));
6850 memcpy(params.ssid.ssid, auth_req->ssid, params.ssid.ssid_len);
6851 memcpy(params.bssid, auth_req->peer_mac, ETH_ALEN);
6853 err = cfg80211_external_auth_request(ifp->ndev, ¶ms, GFP_ATOMIC);
6855 bphy_err(drvr, "Ext Auth request to supplicant failed (%d)\n",
6862 brcmf_notify_auth_frame_rx(struct brcmf_if *ifp,
6863 const struct brcmf_event_msg *e, void *data)
6865 struct brcmf_pub *drvr = ifp->drvr;
6866 struct brcmf_cfg80211_info *cfg = drvr->config;
6867 struct wireless_dev *wdev;
6868 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
6869 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
6870 u8 *frame = (u8 *)(rxframe + 1);
6871 struct brcmu_chan ch;
6872 struct ieee80211_mgmt *mgmt_frame;
6875 brcmf_dbg(INFO, "Enter: event %s (%d) received\n",
6876 brcmf_fweh_event_name(e->event_code), e->event_code);
6878 if (e->datalen < sizeof(*rxframe)) {
6879 bphy_err(drvr, "Event %s (%d) data too small. Ignore\n",
6880 brcmf_fweh_event_name(e->event_code), e->event_code);
6884 wdev = &ifp->vif->wdev;
6887 ch.chspec = be16_to_cpu(rxframe->chanspec);
6888 cfg->d11inf.decchspec(&ch);
6890 mgmt_frame = kzalloc(mgmt_frame_len, GFP_KERNEL);
6894 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_AUTH);
6895 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
6896 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
6897 brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
6899 frame += offsetof(struct ieee80211_mgmt, u);
6900 memcpy(&mgmt_frame->u, frame,
6901 mgmt_frame_len - offsetof(struct ieee80211_mgmt, u));
6903 freq = ieee80211_channel_to_frequency(ch.control_ch_num,
6904 ch.band == BRCMU_CHAN_BAND_2G ?
6908 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
6909 NL80211_RXMGMT_FLAG_EXTERNAL_AUTH);
6915 brcmf_notify_mgmt_tx_status(struct brcmf_if *ifp,
6916 const struct brcmf_event_msg *e, void *data)
6918 struct brcmf_cfg80211_vif *vif = ifp->vif;
6919 u32 *packet_id = (u32 *)data;
6921 brcmf_dbg(INFO, "Enter: event %s (%d), status=%d\n",
6922 brcmf_fweh_event_name(e->event_code), e->event_code,
6925 if (!test_bit(BRCMF_MGMT_TX_SEND_FRAME, &vif->mgmt_tx_status) ||
6926 (*packet_id != vif->mgmt_tx_id))
6929 if (e->event_code == BRCMF_E_MGMT_FRAME_TXSTATUS) {
6930 if (e->status == BRCMF_E_STATUS_SUCCESS)
6931 set_bit(BRCMF_MGMT_TX_ACK, &vif->mgmt_tx_status);
6933 set_bit(BRCMF_MGMT_TX_NOACK, &vif->mgmt_tx_status);
6935 set_bit(BRCMF_MGMT_TX_OFF_CHAN_COMPLETED, &vif->mgmt_tx_status);
6938 complete(&vif->mgmt_tx);
6942 static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
6944 conf->frag_threshold = (u32)-1;
6945 conf->rts_threshold = (u32)-1;
6946 conf->retry_short = (u32)-1;
6947 conf->retry_long = (u32)-1;
6950 static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
6952 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
6953 brcmf_notify_connect_status);
6954 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
6955 brcmf_notify_connect_status);
6956 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
6957 brcmf_notify_connect_status);
6958 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
6959 brcmf_notify_connect_status);
6960 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
6961 brcmf_notify_connect_status);
6962 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
6963 brcmf_notify_connect_status);
6964 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
6965 brcmf_notify_roaming_status);
6966 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
6967 brcmf_notify_mic_status);
6968 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
6969 brcmf_notify_connect_status);
6970 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
6971 brcmf_notify_sched_scan_results);
6972 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
6973 brcmf_notify_vif_event);
6974 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
6975 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
6976 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
6977 brcmf_p2p_notify_listen_complete);
6978 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
6979 brcmf_p2p_notify_action_frame_rx);
6980 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
6981 brcmf_p2p_notify_action_tx_complete);
6982 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
6983 brcmf_p2p_notify_action_tx_complete);
6984 brcmf_fweh_register(cfg->pub, BRCMF_E_PSK_SUP,
6985 brcmf_notify_connect_status);
6986 brcmf_fweh_register(cfg->pub, BRCMF_E_RSSI,
6988 brcmf_fweh_register(cfg->pub, BRCMF_E_EXT_AUTH_REQ,
6989 brcmf_notify_ext_auth_request);
6990 brcmf_fweh_register(cfg->pub, BRCMF_E_EXT_AUTH_FRAME_RX,
6991 brcmf_notify_auth_frame_rx);
6992 brcmf_fweh_register(cfg->pub, BRCMF_E_MGMT_FRAME_TXSTATUS,
6993 brcmf_notify_mgmt_tx_status);
6994 brcmf_fweh_register(cfg->pub, BRCMF_E_MGMT_FRAME_OFF_CHAN_COMPLETE,
6995 brcmf_notify_mgmt_tx_status);
6998 static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
7002 kfree(cfg->extra_buf);
7003 cfg->extra_buf = NULL;
7004 kfree(cfg->wowl.nd);
7005 cfg->wowl.nd = NULL;
7006 kfree(cfg->wowl.nd_info);
7007 cfg->wowl.nd_info = NULL;
7008 kfree(cfg->escan_info.escan_buf);
7009 cfg->escan_info.escan_buf = NULL;
7012 static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
7014 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
7016 goto init_priv_mem_out;
7017 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
7018 if (!cfg->extra_buf)
7019 goto init_priv_mem_out;
7020 cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL);
7022 goto init_priv_mem_out;
7023 cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) +
7024 sizeof(struct cfg80211_wowlan_nd_match *),
7026 if (!cfg->wowl.nd_info)
7027 goto init_priv_mem_out;
7028 cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL);
7029 if (!cfg->escan_info.escan_buf)
7030 goto init_priv_mem_out;
7035 brcmf_deinit_priv_mem(cfg);
7040 static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
7044 cfg->scan_request = NULL;
7045 cfg->pwr_save = true;
7046 cfg->dongle_up = false; /* dongle is not up yet */
7047 err = brcmf_init_priv_mem(cfg);
7050 brcmf_register_event_handlers(cfg);
7051 mutex_init(&cfg->usr_sync);
7052 brcmf_init_escan(cfg);
7053 brcmf_init_conf(cfg->conf);
7054 brcmf_init_wmm_prio(cfg->ac_priority);
7055 init_completion(&cfg->vif_disabled);
7059 static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
7061 cfg->dongle_up = false; /* dongle down */
7062 brcmf_abort_scanning(cfg);
7063 brcmf_deinit_priv_mem(cfg);
7064 brcmf_clear_assoc_ies(cfg);
7067 static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
7069 init_waitqueue_head(&event->vif_wq);
7070 spin_lock_init(&event->vif_event_lock);
7073 static s32 brcmf_dongle_roam(struct brcmf_if *ifp)
7075 struct brcmf_pub *drvr = ifp->drvr;
7078 __le32 roamtrigger[2];
7079 __le32 roam_delta[2];
7081 /* Configure beacon timeout value based upon roaming setting */
7082 if (ifp->drvr->settings->roamoff)
7083 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF;
7085 bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON;
7086 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
7088 bphy_err(drvr, "bcn_timeout error (%d)\n", err);
7089 goto roam_setup_done;
7092 /* Enable/Disable built-in roaming to allow supplicant to take care of
7095 brcmf_dbg(INFO, "Internal Roaming = %s\n",
7096 ifp->drvr->settings->roamoff ? "Off" : "On");
7097 err = brcmf_fil_iovar_int_set(ifp, "roam_off",
7098 ifp->drvr->settings->roamoff);
7100 bphy_err(drvr, "roam_off error (%d)\n", err);
7101 goto roam_setup_done;
7104 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
7105 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
7106 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
7107 (void *)roamtrigger, sizeof(roamtrigger));
7109 bphy_err(drvr, "WLC_SET_ROAM_TRIGGER error (%d)\n", err);
7111 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
7112 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
7113 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
7114 (void *)roam_delta, sizeof(roam_delta));
7116 bphy_err(drvr, "WLC_SET_ROAM_DELTA error (%d)\n", err);
7125 brcmf_dongle_scantime(struct brcmf_if *ifp)
7127 struct brcmf_pub *drvr = ifp->drvr;
7130 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
7131 BRCMF_SCAN_CHANNEL_TIME);
7133 bphy_err(drvr, "Scan assoc time error (%d)\n", err);
7134 goto dongle_scantime_out;
7136 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
7137 BRCMF_SCAN_UNASSOC_TIME);
7139 bphy_err(drvr, "Scan unassoc time error (%d)\n", err);
7140 goto dongle_scantime_out;
7143 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
7144 BRCMF_SCAN_PASSIVE_TIME);
7146 bphy_err(drvr, "Scan passive time error (%d)\n", err);
7147 goto dongle_scantime_out;
7150 dongle_scantime_out:
7154 static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
7155 struct brcmu_chan *ch)
7159 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
7160 if (ch->sb == BRCMU_CHAN_SB_U) {
7161 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
7162 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
7163 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
7165 /* It should be one of
7166 * IEEE80211_CHAN_NO_HT40 or
7167 * IEEE80211_CHAN_NO_HT40PLUS
7169 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
7170 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
7171 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
7175 static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
7178 struct wiphy *wiphy = cfg_to_wiphy(cfg);
7179 struct brcmf_pub *drvr = cfg->pub;
7180 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
7181 struct ieee80211_supported_band *band;
7182 struct ieee80211_channel *channel;
7183 struct brcmf_chanspec_list *list;
7184 struct brcmu_chan ch;
7191 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
7196 list = (struct brcmf_chanspec_list *)pbuf;
7198 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
7201 bphy_err(drvr, "get chanspecs error (%d)\n", err);
7205 band = wiphy->bands[NL80211_BAND_2GHZ];
7207 for (i = 0; i < band->n_channels; i++)
7208 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7209 band = wiphy->bands[NL80211_BAND_5GHZ];
7211 for (i = 0; i < band->n_channels; i++)
7212 band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7214 total = le32_to_cpu(list->count);
7215 if (total > BRCMF_MAX_CHANSPEC_LIST) {
7216 bphy_err(drvr, "Invalid count of channel Spec. (%u)\n",
7222 for (i = 0; i < total; i++) {
7223 ch.chspec = (u16)le32_to_cpu(list->element[i]);
7224 cfg->d11inf.decchspec(&ch);
7226 if (ch.band == BRCMU_CHAN_BAND_2G) {
7227 band = wiphy->bands[NL80211_BAND_2GHZ];
7228 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
7229 band = wiphy->bands[NL80211_BAND_5GHZ];
7231 bphy_err(drvr, "Invalid channel Spec. 0x%x.\n",
7237 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
7238 ch.bw == BRCMU_CHAN_BW_40)
7240 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
7241 ch.bw == BRCMU_CHAN_BW_80)
7245 for (j = 0; j < band->n_channels; j++) {
7246 if (band->channels[j].hw_value == ch.control_ch_num) {
7247 channel = &band->channels[j];
7252 /* It seems firmware supports some channel we never
7253 * considered. Something new in IEEE standard?
7255 bphy_err(drvr, "Ignoring unexpected firmware channel %d\n",
7260 if (channel->orig_flags & IEEE80211_CHAN_DISABLED)
7263 /* assuming the chanspecs order is HT20,
7264 * HT40 upper, HT40 lower, and VHT80.
7267 case BRCMU_CHAN_BW_160:
7268 channel->flags &= ~IEEE80211_CHAN_NO_160MHZ;
7270 case BRCMU_CHAN_BW_80:
7271 channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
7273 case BRCMU_CHAN_BW_40:
7274 brcmf_update_bw40_channel_flag(channel, &ch);
7277 wiphy_warn(wiphy, "Firmware reported unsupported bandwidth %d\n",
7280 case BRCMU_CHAN_BW_20:
7281 /* enable the channel and disable other bandwidths
7282 * for now as mentioned order assure they are enabled
7283 * for subsequent chanspecs.
7285 channel->flags = IEEE80211_CHAN_NO_HT40 |
7286 IEEE80211_CHAN_NO_80MHZ |
7287 IEEE80211_CHAN_NO_160MHZ;
7288 ch.bw = BRCMU_CHAN_BW_20;
7289 cfg->d11inf.encchspec(&ch);
7290 chaninfo = ch.chspec;
7291 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
7294 if (chaninfo & WL_CHAN_RADAR)
7296 (IEEE80211_CHAN_RADAR |
7297 IEEE80211_CHAN_NO_IR);
7298 if (chaninfo & WL_CHAN_PASSIVE)
7300 IEEE80211_CHAN_NO_IR;
7310 static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
7312 struct brcmf_pub *drvr = cfg->pub;
7313 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
7314 struct ieee80211_supported_band *band;
7315 struct brcmf_fil_bwcap_le band_bwcap;
7316 struct brcmf_chanspec_list *list;
7320 struct brcmu_chan ch;
7324 /* verify support for bw_cap command */
7326 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
7329 /* only set 2G bandwidth using bw_cap command */
7330 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
7331 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
7332 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
7333 sizeof(band_bwcap));
7335 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
7336 val = WLC_N_BW_40ALL;
7337 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
7341 /* update channel info in 2G band */
7342 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
7347 ch.band = BRCMU_CHAN_BAND_2G;
7348 ch.bw = BRCMU_CHAN_BW_40;
7349 ch.sb = BRCMU_CHAN_SB_NONE;
7351 cfg->d11inf.encchspec(&ch);
7353 /* pass encoded chanspec in query */
7354 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
7356 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
7359 bphy_err(drvr, "get chanspecs error (%d)\n", err);
7364 band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ];
7365 list = (struct brcmf_chanspec_list *)pbuf;
7366 num_chan = le32_to_cpu(list->count);
7367 if (num_chan > BRCMF_MAX_CHANSPEC_LIST) {
7368 bphy_err(drvr, "Invalid count of channel Spec. (%u)\n",
7374 for (i = 0; i < num_chan; i++) {
7375 ch.chspec = (u16)le32_to_cpu(list->element[i]);
7376 cfg->d11inf.decchspec(&ch);
7377 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
7379 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
7381 for (j = 0; j < band->n_channels; j++) {
7382 if (band->channels[j].hw_value == ch.control_ch_num)
7385 if (WARN_ON(j == band->n_channels))
7388 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
7395 static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
7397 struct brcmf_pub *drvr = ifp->drvr;
7398 u32 band, mimo_bwcap;
7402 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
7404 bw_cap[NL80211_BAND_2GHZ] = band;
7406 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
7408 bw_cap[NL80211_BAND_5GHZ] = band;
7414 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
7416 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
7418 /* assume 20MHz if firmware does not give a clue */
7419 mimo_bwcap = WLC_N_BW_20ALL;
7421 switch (mimo_bwcap) {
7422 case WLC_N_BW_40ALL:
7423 bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
7425 case WLC_N_BW_20IN2G_40IN5G:
7426 bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
7428 case WLC_N_BW_20ALL:
7429 bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
7430 bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
7433 bphy_err(drvr, "invalid mimo_bw_cap value\n");
7437 static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
7438 u32 bw_cap[2], u32 nchain)
7440 band->ht_cap.ht_supported = true;
7441 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
7442 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
7443 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
7445 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
7446 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
7447 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
7448 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
7449 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
7450 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
7453 static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
7458 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
7459 mcs_map = (mcs_map << 2) | supp;
7461 return cpu_to_le16(mcs_map);
7464 static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
7465 u32 bw_cap[2], u32 nchain, u32 txstreams,
7466 u32 txbf_bfe_cap, u32 txbf_bfr_cap)
7470 /* not allowed in 2.4G band */
7471 if (band->band == NL80211_BAND_2GHZ)
7474 band->vht_cap.vht_supported = true;
7475 /* 80MHz is mandatory */
7476 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
7477 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
7478 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
7479 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
7481 /* all support 256-QAM */
7482 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
7483 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
7484 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
7486 /* Beamforming support information */
7487 if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP)
7488 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
7489 if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP)
7490 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
7491 if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP)
7492 band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
7493 if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP)
7494 band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
7496 if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) {
7497 band->vht_cap.cap |=
7498 (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
7499 band->vht_cap.cap |= ((txstreams - 1) <<
7500 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
7501 band->vht_cap.cap |=
7502 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
7506 static int brcmf_setup_wiphybands(struct brcmf_cfg80211_info *cfg)
7508 struct brcmf_pub *drvr = cfg->pub;
7509 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
7510 struct wiphy *wiphy = cfg_to_wiphy(cfg);
7513 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
7518 struct ieee80211_supported_band *band;
7520 u32 txbf_bfe_cap = 0;
7521 u32 txbf_bfr_cap = 0;
7523 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
7524 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
7526 bphy_err(drvr, "nmode error (%d)\n", err);
7528 brcmf_get_bwcap(ifp, bw_cap);
7530 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
7531 nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ],
7532 bw_cap[NL80211_BAND_5GHZ]);
7534 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
7536 /* rxchain unsupported by firmware of older chips */
7538 bphy_info_once(drvr, "rxchain unsupported\n");
7540 bphy_err(drvr, "rxchain error (%d)\n", err);
7544 for (nchain = 0; rxchain; nchain++)
7545 rxchain = rxchain & (rxchain - 1);
7547 brcmf_dbg(INFO, "nchain=%d\n", nchain);
7549 err = brcmf_construct_chaninfo(cfg, bw_cap);
7551 bphy_err(drvr, "brcmf_construct_chaninfo failed (%d)\n", err);
7556 (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams);
7557 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap",
7559 (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap",
7563 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
7564 band = wiphy->bands[i];
7569 brcmf_update_ht_cap(band, bw_cap, nchain);
7571 brcmf_update_vht_cap(band, bw_cap, nchain, txstreams,
7572 txbf_bfe_cap, txbf_bfr_cap);
7578 static const struct ieee80211_txrx_stypes
7579 brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
7580 [NL80211_IFTYPE_STATION] = {
7582 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
7583 BIT(IEEE80211_STYPE_AUTH >> 4) |
7584 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
7586 [NL80211_IFTYPE_P2P_CLIENT] = {
7588 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
7589 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
7591 [NL80211_IFTYPE_P2P_GO] = {
7593 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
7594 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
7595 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
7596 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
7597 BIT(IEEE80211_STYPE_AUTH >> 4) |
7598 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
7599 BIT(IEEE80211_STYPE_ACTION >> 4)
7601 [NL80211_IFTYPE_P2P_DEVICE] = {
7603 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
7604 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
7606 [NL80211_IFTYPE_AP] = {
7608 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
7609 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
7610 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
7611 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
7612 BIT(IEEE80211_STYPE_AUTH >> 4) |
7613 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
7614 BIT(IEEE80211_STYPE_ACTION >> 4)
7619 * brcmf_setup_ifmodes() - determine interface modes and combinations.
7621 * @wiphy: wiphy object.
7622 * @ifp: interface object needed for feat module api.
7624 * The interface modes and combinations are determined dynamically here
7625 * based on firmware functionality.
7627 * no p2p and no mbss:
7629 * #STA <= 1, #AP <= 1, channels = 1, 2 total
7633 * #STA <= 1, #AP <= 1, channels = 1, 2 total
7634 * #AP <= 4, matching BI, channels = 1, 4 total
7637 * #STA <= 1, #AP <= 2, channels = 2, 4 total
7639 * p2p, no mchan, and mbss:
7641 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
7642 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
7643 * #AP <= 4, matching BI, channels = 1, 4 total
7645 * p2p, mchan, and mbss:
7647 * #STA <= 2, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
7648 * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
7649 * #AP <= 4, matching BI, channels = 1, 4 total
7651 * p2p, rsdb, and no mbss:
7652 * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 2, AP <= 2,
7653 * channels = 2, 4 total
7655 static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
7657 struct ieee80211_iface_combination *combo = NULL;
7658 struct ieee80211_iface_limit *c0_limits = NULL;
7659 struct ieee80211_iface_limit *p2p_limits = NULL;
7660 struct ieee80211_iface_limit *mbss_limits = NULL;
7661 bool mon_flag, mbss, p2p, rsdb, mchan;
7662 int i, c, n_combos, n_limits;
7664 mon_flag = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FLAG);
7665 mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
7666 p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
7667 rsdb = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB);
7668 mchan = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN);
7670 n_combos = 1 + !!(p2p && !rsdb) + !!mbss;
7671 combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
7675 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
7676 BIT(NL80211_IFTYPE_ADHOC) |
7677 BIT(NL80211_IFTYPE_AP);
7679 wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
7681 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
7682 BIT(NL80211_IFTYPE_P2P_GO) |
7683 BIT(NL80211_IFTYPE_P2P_DEVICE);
7687 n_limits = 1 + mon_flag + (p2p ? 2 : 0) + (rsdb || !p2p);
7688 c0_limits = kcalloc(n_limits, sizeof(*c0_limits), GFP_KERNEL);
7692 combo[c].num_different_channels = 1 + (rsdb || (p2p && mchan));
7693 c0_limits[i].max = 1 + (p2p && mchan);
7694 c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
7696 c0_limits[i].max = 1;
7697 c0_limits[i++].types = BIT(NL80211_IFTYPE_MONITOR);
7700 c0_limits[i].max = 1;
7701 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
7702 c0_limits[i].max = 1 + rsdb;
7703 c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
7704 BIT(NL80211_IFTYPE_P2P_GO);
7707 c0_limits[i].max = 2;
7708 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
7709 combo[c].max_interfaces = 4;
7711 combo[c].max_interfaces = i;
7713 c0_limits[i].max = 2;
7714 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
7715 combo[c].max_interfaces = 3;
7717 c0_limits[i].max = 1;
7718 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
7719 combo[c].max_interfaces = i;
7721 combo[c].n_limits = i;
7722 combo[c].limits = c0_limits;
7727 p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
7730 p2p_limits[i].max = 1;
7731 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
7732 p2p_limits[i].max = 1;
7733 p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
7734 p2p_limits[i].max = 1;
7735 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
7736 p2p_limits[i].max = 1;
7737 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
7738 combo[c].num_different_channels = 1;
7739 combo[c].max_interfaces = i;
7740 combo[c].n_limits = i;
7741 combo[c].limits = p2p_limits;
7747 n_limits = 1 + mon_flag;
7748 mbss_limits = kcalloc(n_limits, sizeof(*mbss_limits),
7752 mbss_limits[i].max = 4;
7753 mbss_limits[i++].types = BIT(NL80211_IFTYPE_AP);
7755 mbss_limits[i].max = 1;
7756 mbss_limits[i++].types = BIT(NL80211_IFTYPE_MONITOR);
7758 combo[c].beacon_int_infra_match = true;
7759 combo[c].num_different_channels = 1;
7760 combo[c].max_interfaces = 4 + mon_flag;
7761 combo[c].n_limits = i;
7762 combo[c].limits = mbss_limits;
7765 wiphy->n_iface_combinations = n_combos;
7766 wiphy->iface_combinations = combo;
7778 static const struct wiphy_wowlan_support brcmf_wowlan_support = {
7779 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
7780 .n_patterns = BRCMF_WOWL_MAXPATTERNS,
7781 .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
7782 .pattern_min_len = 1,
7783 .max_pkt_offset = 1500,
7787 static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp)
7790 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
7791 struct brcmf_pub *drvr = cfg->pub;
7792 struct wiphy_wowlan_support *wowl;
7794 wowl = kmemdup(&brcmf_wowlan_support, sizeof(brcmf_wowlan_support),
7797 bphy_err(drvr, "only support basic wowlan features\n");
7798 wiphy->wowlan = &brcmf_wowlan_support;
7802 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
7803 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) {
7804 wowl->flags |= WIPHY_WOWLAN_NET_DETECT;
7805 wowl->max_nd_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
7806 init_waitqueue_head(&cfg->wowl.nd_data_wait);
7809 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) {
7810 wowl->flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY;
7811 wowl->flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE;
7814 wiphy->wowlan = wowl;
7818 static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
7820 struct brcmf_pub *drvr = ifp->drvr;
7821 const struct ieee80211_iface_combination *combo;
7822 struct ieee80211_supported_band *band;
7823 u16 max_interfaces = 0;
7829 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
7830 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
7831 wiphy->max_num_pmkids = BRCMF_MAXPMKID;
7833 err = brcmf_setup_ifmodes(wiphy, ifp);
7837 for (i = 0, combo = wiphy->iface_combinations;
7838 i < wiphy->n_iface_combinations; i++, combo++) {
7839 max_interfaces = max(max_interfaces, combo->max_interfaces);
7842 for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
7844 u8 *addr = drvr->addresses[i].addr;
7846 memcpy(addr, drvr->mac, ETH_ALEN);
7849 addr[ETH_ALEN - 1] ^= i;
7852 wiphy->addresses = drvr->addresses;
7853 wiphy->n_addresses = i;
7855 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
7856 wiphy->cipher_suites = brcmf_cipher_suites;
7857 wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites);
7858 if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
7859 wiphy->n_cipher_suites--;
7860 wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) |
7861 BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) |
7862 BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST);
7864 wiphy->flags |= WIPHY_FLAG_NETNS_OK |
7865 WIPHY_FLAG_PS_ON_BY_DEFAULT |
7866 WIPHY_FLAG_HAVE_AP_SME |
7867 WIPHY_FLAG_OFFCHAN_TX |
7868 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
7869 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS))
7870 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7871 if (!ifp->drvr->settings->roamoff)
7872 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
7873 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FWSUP)) {
7874 wiphy_ext_feature_set(wiphy,
7875 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK);
7876 wiphy_ext_feature_set(wiphy,
7877 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X);
7878 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SAE))
7879 wiphy_ext_feature_set(wiphy,
7880 NL80211_EXT_FEATURE_SAE_OFFLOAD);
7882 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FWAUTH)) {
7883 wiphy_ext_feature_set(wiphy,
7884 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK);
7885 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SAE))
7886 wiphy_ext_feature_set(wiphy,
7887 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP);
7889 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SAE_EXT))
7890 wiphy->features |= NL80211_FEATURE_SAE;
7891 wiphy->mgmt_stypes = brcmf_txrx_stypes;
7892 wiphy->max_remain_on_channel_duration = 5000;
7893 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
7894 gscan = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_GSCAN);
7895 brcmf_pno_wiphy_params(wiphy, gscan);
7897 /* vendor commands/events support */
7898 wiphy->vendor_commands = brcmf_vendor_cmds;
7899 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
7901 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
7902 brcmf_wiphy_wowl_params(wiphy, ifp);
7903 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
7906 bphy_err(drvr, "could not obtain band info: err=%d\n", err);
7909 /* first entry in bandlist is number of bands */
7910 n_bands = le32_to_cpu(bandlist[0]);
7911 for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
7912 if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
7913 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
7918 band->channels = kmemdup(&__wl_2ghz_channels,
7919 sizeof(__wl_2ghz_channels),
7921 if (!band->channels) {
7926 band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
7927 wiphy->bands[NL80211_BAND_2GHZ] = band;
7929 if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
7930 band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
7935 band->channels = kmemdup(&__wl_5ghz_channels,
7936 sizeof(__wl_5ghz_channels),
7938 if (!band->channels) {
7943 band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
7944 wiphy->bands[NL80211_BAND_5GHZ] = band;
7948 if (wiphy->bands[NL80211_BAND_5GHZ] &&
7949 brcmf_feat_is_enabled(ifp, BRCMF_FEAT_DOT11H))
7950 wiphy_ext_feature_set(wiphy,
7951 NL80211_EXT_FEATURE_DFS_OFFLOAD);
7953 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
7955 wiphy_read_of_freq_limits(wiphy);
7960 static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
7962 struct brcmf_pub *drvr = cfg->pub;
7963 struct net_device *ndev;
7964 struct wireless_dev *wdev;
7965 struct brcmf_if *ifp;
7972 ndev = cfg_to_ndev(cfg);
7973 wdev = ndev->ieee80211_ptr;
7974 ifp = netdev_priv(ndev);
7976 /* make sure RF is ready for work */
7977 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
7979 brcmf_dongle_scantime(ifp);
7981 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
7982 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
7984 goto default_conf_out;
7985 brcmf_dbg(INFO, "power save set to %s\n",
7986 (power_mode ? "enabled" : "disabled"));
7988 err = brcmf_dongle_roam(ifp);
7990 goto default_conf_out;
7991 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
7994 goto default_conf_out;
7996 brcmf_configure_arp_nd_offload(ifp, true);
7998 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_FAKEFRAG, 1);
8000 bphy_err(drvr, "failed to set frameburst mode\n");
8001 goto default_conf_out;
8004 cfg->dongle_up = true;
8011 static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
8013 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
8015 return brcmf_config_dongle(ifp->drvr->config);
8018 static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
8020 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
8023 * While going down, if associated with AP disassociate
8024 * from AP to save power
8026 if (check_vif_up(ifp->vif)) {
8027 brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED, true);
8029 /* Make sure WPA_Supplicant receives all the event
8030 generated due to DISASSOC call to the fw to keep
8031 the state fw and WPA_Supplicant state consistent
8036 brcmf_abort_scanning(cfg);
8037 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
8042 s32 brcmf_cfg80211_up(struct net_device *ndev)
8044 struct brcmf_if *ifp = netdev_priv(ndev);
8045 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
8048 mutex_lock(&cfg->usr_sync);
8049 err = __brcmf_cfg80211_up(ifp);
8050 mutex_unlock(&cfg->usr_sync);
8055 s32 brcmf_cfg80211_down(struct net_device *ndev)
8057 struct brcmf_if *ifp = netdev_priv(ndev);
8058 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
8061 mutex_lock(&cfg->usr_sync);
8062 err = __brcmf_cfg80211_down(ifp);
8063 mutex_unlock(&cfg->usr_sync);
8068 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
8070 struct wireless_dev *wdev = &ifp->vif->wdev;
8072 return wdev->iftype;
8075 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
8076 unsigned long state)
8078 struct brcmf_cfg80211_vif *vif;
8080 list_for_each_entry(vif, &cfg->vif_list, list) {
8081 if (test_bit(state, &vif->sme_state))
8087 static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
8092 spin_lock(&event->vif_event_lock);
8093 evt_action = event->action;
8094 spin_unlock(&event->vif_event_lock);
8095 return evt_action == action;
8098 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
8099 struct brcmf_cfg80211_vif *vif)
8101 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
8103 spin_lock(&event->vif_event_lock);
8106 spin_unlock(&event->vif_event_lock);
8109 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
8111 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
8114 spin_lock(&event->vif_event_lock);
8115 armed = event->vif != NULL;
8116 spin_unlock(&event->vif_event_lock);
8121 int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
8122 u8 action, ulong timeout)
8124 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
8126 return wait_event_timeout(event->vif_wq,
8127 vif_event_equals(event, action), timeout);
8130 static bool brmcf_use_iso3166_ccode_fallback(struct brcmf_pub *drvr)
8132 if (drvr->settings->trivial_ccode_map)
8135 switch (drvr->bus_if->chip) {
8136 case BRCM_CC_43430_CHIP_ID:
8137 case BRCM_CC_4345_CHIP_ID:
8138 case BRCM_CC_4356_CHIP_ID:
8139 case BRCM_CC_43602_CHIP_ID:
8146 static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2],
8147 struct brcmf_fil_country_le *ccreq)
8149 struct brcmfmac_pd_cc *country_codes;
8150 struct brcmfmac_pd_cc_entry *cc;
8154 if ((alpha2[0] == ccreq->country_abbrev[0]) &&
8155 (alpha2[1] == ccreq->country_abbrev[1])) {
8156 brcmf_dbg(TRACE, "Country code already set\n");
8160 country_codes = drvr->settings->country_codes;
8161 if (!country_codes) {
8162 if (brmcf_use_iso3166_ccode_fallback(drvr)) {
8163 brcmf_dbg(TRACE, "No country codes configured for device, using ISO3166 code and 0 rev\n");
8164 memset(ccreq, 0, sizeof(*ccreq));
8165 ccreq->country_abbrev[0] = alpha2[0];
8166 ccreq->country_abbrev[1] = alpha2[1];
8167 ccreq->ccode[0] = alpha2[0];
8168 ccreq->ccode[1] = alpha2[1];
8172 brcmf_dbg(TRACE, "No country codes configured for device\n");
8177 for (i = 0; i < country_codes->table_size; i++) {
8178 cc = &country_codes->table[i];
8179 if ((cc->iso3166[0] == '\0') && (found_index == -1))
8181 if ((cc->iso3166[0] == alpha2[0]) &&
8182 (cc->iso3166[1] == alpha2[1])) {
8187 if (found_index == -1) {
8188 brcmf_dbg(TRACE, "No country code match found\n");
8191 memset(ccreq, 0, sizeof(*ccreq));
8192 ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev);
8193 memcpy(ccreq->ccode, country_codes->table[found_index].cc,
8194 BRCMF_COUNTRY_BUF_SZ);
8195 ccreq->country_abbrev[0] = alpha2[0];
8196 ccreq->country_abbrev[1] = alpha2[1];
8197 ccreq->country_abbrev[2] = 0;
8203 brcmf_parse_dump_obss(char *buf, struct brcmf_dump_survey *survey)
8207 char delim[] = "\n ";
8211 token = strsep(&buf, delim);
8213 if (!strcmp(token, "OBSS")) {
8214 for (i = 0; i < OBSS_TOKEN_IDX; i++)
8215 token = strsep(&buf, delim);
8216 err = kstrtoul(token, 10, &val);
8222 if (!strcmp(token, "IBSS")) {
8223 for (i = 0; i < IBSS_TOKEN_IDX; i++)
8224 token = strsep(&buf, delim);
8225 err = kstrtoul(token, 10, &val);
8231 if (!strcmp(token, "TXDur")) {
8232 for (i = 0; i < TX_TOKEN_IDX; i++)
8233 token = strsep(&buf, delim);
8234 err = kstrtoul(token, 10, &val);
8240 if (!strcmp(token, "Category")) {
8241 for (i = 0; i < CTG_TOKEN_IDX; i++)
8242 token = strsep(&buf, delim);
8243 err = kstrtoul(token, 10, &val);
8246 survey->no_ctg = val;
8249 if (!strcmp(token, "Packet")) {
8250 for (i = 0; i < PKT_TOKEN_IDX; i++)
8251 token = strsep(&buf, delim);
8252 err = kstrtoul(token, 10, &val);
8255 survey->no_pckt = val;
8258 if (!strcmp(token, "Opp(time):")) {
8259 for (i = 0; i < IDLE_TOKEN_IDX; i++)
8260 token = strsep(&buf, delim);
8261 err = kstrtoul(token, 10, &val);
8267 token = strsep(&buf, delim);
8274 brcmf_dump_obss(struct brcmf_if *ifp, struct cca_msrmnt_query req,
8275 struct brcmf_dump_survey *survey)
8277 struct cca_stats_n_flags *results;
8281 buf = kzalloc(sizeof(char) * BRCMF_DCMD_MEDLEN, GFP_KERNEL);
8285 memcpy(buf, &req, sizeof(struct cca_msrmnt_query));
8286 err = brcmf_fil_iovar_data_get(ifp, "dump_obss",
8287 buf, BRCMF_DCMD_MEDLEN);
8289 brcmf_err("dump_obss error (%d)\n", err);
8293 results = (struct cca_stats_n_flags *)(buf);
8295 if (req.msrmnt_query)
8296 brcmf_parse_dump_obss(results->buf, survey);
8304 brcmf_set_channel(struct brcmf_cfg80211_info *cfg, struct ieee80211_channel *chan)
8308 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
8310 if (chan->flags & IEEE80211_CHAN_DISABLED)
8314 chspec = channel_to_chanspec(&cfg->d11inf, chan);
8315 if (chspec != INVCHANSPEC) {
8316 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chspec);
8318 brcmf_err("set chanspec 0x%04x fail, reason %d\n", chspec, err);
8322 brcmf_err("failed to convert host chanspec to fw chanspec\n");
8330 brcmf_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *ndev,
8331 int idx, struct survey_info *info)
8333 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
8334 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
8335 struct brcmf_dump_survey survey = {};
8336 struct ieee80211_supported_band *band;
8337 enum nl80211_band band_id;
8338 struct cca_msrmnt_query req;
8342 brcmf_dbg(TRACE, "Enter: channel idx=%d\n", idx);
8344 /* Do not run survey when VIF in CONNECTING / CONNECTED states */
8345 if ((test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) ||
8346 (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))) {
8350 for (band_id = 0; band_id < NUM_NL80211_BANDS; band_id++) {
8351 band = wiphy->bands[band_id];
8354 if (idx >= band->n_channels) {
8355 idx -= band->n_channels;
8359 info->channel = &band->channels[idx];
8362 if (band_id == NUM_NL80211_BANDS)
8365 /* Setting current channel to the requested channel */
8367 if (brcmf_set_channel(cfg, info->channel))
8371 brcmf_set_mpc(ifp, 0);
8373 /* Set interface up, explicitly. */
8374 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
8376 brcmf_err("set interface up failed, err = %d\n", err);
8380 /* Get noise value */
8381 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PHY_NOISE, &noise);
8383 brcmf_err("Get Phy Noise failed, use dummy value\n");
8384 noise = CHAN_NOISE_DUMMY;
8387 /* Start Measurement for obss stats on current channel */
8388 req.msrmnt_query = 0;
8389 req.time_req = ACS_MSRMNT_DELAY;
8390 err = brcmf_dump_obss(ifp, req, &survey);
8394 /* Add 10 ms for IOVAR completion */
8395 msleep(ACS_MSRMNT_DELAY + 10);
8397 /* Issue IOVAR to collect measurement results */
8398 req.msrmnt_query = 1;
8399 err = brcmf_dump_obss(ifp, req, &survey);
8403 info->noise = noise;
8404 info->time = ACS_MSRMNT_DELAY;
8405 info->time_busy = ACS_MSRMNT_DELAY - survey.idle;
8406 info->time_rx = survey.obss + survey.ibss + survey.no_ctg +
8408 info->time_tx = survey.tx;
8409 info->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
8410 SURVEY_INFO_TIME_BUSY | SURVEY_INFO_TIME_RX |
8411 SURVEY_INFO_TIME_TX;
8413 brcmf_dbg(INFO, "OBSS dump: channel %d: survey duration %d\n",
8414 ieee80211_frequency_to_channel(info->channel->center_freq),
8416 brcmf_dbg(INFO, "noise(%d) busy(%llu) rx(%llu) tx(%llu)\n",
8417 info->noise, info->time_busy, info->time_rx, info->time_tx);
8420 if (!brcmf_is_apmode(ifp->vif))
8421 brcmf_set_mpc(ifp, 1);
8425 static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
8426 struct regulatory_request *req)
8428 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
8429 struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
8430 struct brcmf_pub *drvr = cfg->pub;
8431 struct brcmf_fil_country_le ccreq;
8436 err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq));
8438 bphy_err(drvr, "Country code iovar returned err = %d\n", err);
8442 /* The country code gets set to "00" by default at boot - substitute
8443 * any saved ccode from the nvram file unless there is a valid code
8446 alpha2 = req->alpha2;
8447 if (alpha2[0] == '0' && alpha2[1] == '0') {
8448 extern char saved_ccode[2];
8450 if ((isupper(ccreq.country_abbrev[0]) &&
8451 isupper(ccreq.country_abbrev[1])) ||
8454 alpha2 = saved_ccode;
8455 pr_debug("brcmfmac: substituting saved ccode %c%c\n",
8456 alpha2[0], alpha2[1]);
8459 /* ignore non-ISO3166 country codes */
8460 for (i = 0; i < 2; i++)
8461 if (alpha2[i] < 'A' || alpha2[i] > 'Z') {
8462 bphy_err(drvr, "not an ISO3166 code (0x%02x 0x%02x)\n",
8463 alpha2[0], alpha2[1]);
8467 brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator,
8468 alpha2[0], alpha2[1]);
8470 err = brcmf_translate_country_code(ifp->drvr, alpha2, &ccreq);
8474 err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
8476 bphy_err(drvr, "Firmware rejected country setting\n");
8479 brcmf_setup_wiphybands(cfg);
8482 static void brcmf_free_wiphy(struct wiphy *wiphy)
8489 if (wiphy->iface_combinations) {
8490 for (i = 0; i < wiphy->n_iface_combinations; i++)
8491 kfree(wiphy->iface_combinations[i].limits);
8493 kfree(wiphy->iface_combinations);
8494 if (wiphy->bands[NL80211_BAND_2GHZ]) {
8495 kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels);
8496 kfree(wiphy->bands[NL80211_BAND_2GHZ]);
8498 if (wiphy->bands[NL80211_BAND_5GHZ]) {
8499 kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels);
8500 kfree(wiphy->bands[NL80211_BAND_5GHZ]);
8502 #if IS_ENABLED(CONFIG_PM)
8503 if (wiphy->wowlan != &brcmf_wowlan_support)
8504 kfree(wiphy->wowlan);
8508 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
8509 struct cfg80211_ops *ops,
8512 struct wiphy *wiphy = drvr->wiphy;
8513 struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
8514 struct brcmf_cfg80211_info *cfg;
8515 struct brcmf_cfg80211_vif *vif;
8516 struct brcmf_if *ifp;
8522 bphy_err(drvr, "ndev is invalid\n");
8526 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
8528 bphy_err(drvr, "Could not allocate wiphy device\n");
8534 init_vif_event(&cfg->vif_event);
8535 INIT_LIST_HEAD(&cfg->vif_list);
8537 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION);
8541 ifp = netdev_priv(ndev);
8543 vif->wdev.netdev = ndev;
8544 ndev->ieee80211_ptr = &vif->wdev;
8545 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
8547 err = wl_init_priv(cfg);
8549 bphy_err(drvr, "Failed to init iwm_priv (%d)\n", err);
8550 brcmf_free_vif(vif);
8555 /* determine d11 io type before wiphy setup */
8556 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
8558 bphy_err(drvr, "Failed to get D11 version (%d)\n", err);
8561 cfg->d11inf.io_type = (u8)io_type;
8562 brcmu_d11_attach(&cfg->d11inf);
8564 /* regulatory notifer below needs access to cfg so
8569 err = brcmf_setup_wiphy(wiphy, ifp);
8573 brcmf_dbg(INFO, "Registering custom regulatory\n");
8574 wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
8575 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
8576 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
8578 /* firmware defaults to 40MHz disabled in 2G band. We signal
8579 * cfg80211 here that we do and have it decide we can enable
8580 * it. But first check if device does support 2G operation.
8582 if (wiphy->bands[NL80211_BAND_2GHZ]) {
8583 cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap;
8584 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
8587 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK))
8588 ops->set_rekey_data = brcmf_cfg80211_set_rekey_data;
8590 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_DUMP_OBSS))
8591 ops->dump_survey = brcmf_cfg80211_dump_survey;
8593 err = wiphy_register(wiphy);
8595 bphy_err(drvr, "Could not register wiphy device (%d)\n", err);
8599 err = brcmf_setup_wiphybands(cfg);
8601 bphy_err(drvr, "Setting wiphy bands failed (%d)\n", err);
8602 goto wiphy_unreg_out;
8605 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
8606 * setup 40MHz in 2GHz band and enable OBSS scanning.
8608 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
8609 err = brcmf_enable_bw40_2g(cfg);
8611 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
8612 BRCMF_OBSS_COEX_AUTO);
8614 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
8617 err = brcmf_fweh_activate_events(ifp);
8619 bphy_err(drvr, "FWEH activation failed (%d)\n", err);
8620 goto wiphy_unreg_out;
8623 err = brcmf_p2p_attach(cfg, p2pdev_forced);
8625 bphy_err(drvr, "P2P initialisation failed (%d)\n", err);
8626 goto wiphy_unreg_out;
8628 err = brcmf_btcoex_attach(cfg);
8630 bphy_err(drvr, "BT-coex initialisation failed (%d)\n", err);
8631 brcmf_p2p_detach(&cfg->p2p);
8632 goto wiphy_unreg_out;
8634 err = brcmf_pno_attach(cfg);
8636 bphy_err(drvr, "PNO initialisation failed (%d)\n", err);
8637 brcmf_btcoex_detach(cfg);
8638 brcmf_p2p_detach(&cfg->p2p);
8639 goto wiphy_unreg_out;
8642 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) {
8643 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
8645 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
8646 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
8648 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
8649 brcmf_notify_tdls_peer_event);
8653 /* (re-) activate FWEH event handling */
8654 err = brcmf_fweh_activate_events(ifp);
8656 bphy_err(drvr, "FWEH activation failed (%d)\n", err);
8660 /* Fill in some of the advertised nl80211 supported features */
8661 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) {
8662 wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
8664 if (wiphy->wowlan &&
8665 wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT)
8666 wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
8673 brcmf_pno_detach(cfg);
8674 brcmf_btcoex_detach(cfg);
8675 brcmf_p2p_detach(&cfg->p2p);
8677 wiphy_unregister(cfg->wiphy);
8679 wl_deinit_priv(cfg);
8680 brcmf_free_vif(vif);
8683 brcmf_free_wiphy(wiphy);
8688 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
8693 brcmf_pno_detach(cfg);
8694 brcmf_btcoex_detach(cfg);
8695 wiphy_unregister(cfg->wiphy);
8696 wl_deinit_priv(cfg);
8697 brcmf_free_wiphy(cfg->wiphy);