2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
19 #include <linux/kernel.h>
20 #include <linux/etherdevice.h>
21 #include <linux/module.h>
22 #include <linux/vmalloc.h>
23 #include <net/cfg80211.h>
24 #include <net/netlink.h>
26 #include <brcmu_utils.h>
28 #include <brcmu_wifi.h>
31 #include "tracepoint.h"
32 #include "fwil_types.h"
35 #include "wl_cfg80211.h"
42 #define BRCMF_SCAN_IE_LEN_MAX 2048
43 #define BRCMF_PNO_VERSION 2
44 #define BRCMF_PNO_TIME 30
45 #define BRCMF_PNO_REPEAT 4
46 #define BRCMF_PNO_FREQ_EXPO_MAX 3
47 #define BRCMF_PNO_MAX_PFN_COUNT 16
48 #define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
49 #define BRCMF_PNO_HIDDEN_BIT 2
50 #define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
51 #define BRCMF_PNO_SCAN_COMPLETE 1
52 #define BRCMF_PNO_SCAN_INCOMPLETE 0
54 #define BRCMF_IFACE_MAX_CNT 3
56 #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
57 #define WPA_OUI_TYPE 1
58 #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
59 #define WME_OUI_TYPE 2
60 #define WPS_OUI_TYPE 4
62 #define VS_IE_FIXED_HDR_LEN 6
63 #define WPA_IE_VERSION_LEN 2
64 #define WPA_IE_MIN_OUI_LEN 4
65 #define WPA_IE_SUITE_COUNT_LEN 2
67 #define WPA_CIPHER_NONE 0 /* None */
68 #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
69 #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
70 #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
71 #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
73 #define RSN_AKM_NONE 0 /* None (IBSS) */
74 #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
75 #define RSN_AKM_PSK 2 /* Pre-shared Key */
76 #define RSN_CAP_LEN 2 /* Length of RSN capabilities */
77 #define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
79 #define VNDR_IE_CMD_LEN 4 /* length of the set command
80 * string :"add", "del" (+ NUL)
82 #define VNDR_IE_COUNT_OFFSET 4
83 #define VNDR_IE_PKTFLAG_OFFSET 8
84 #define VNDR_IE_VSIE_OFFSET 12
85 #define VNDR_IE_HDR_SIZE 12
86 #define VNDR_IE_PARSE_LIMIT 5
88 #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
89 #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
91 #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
92 #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
93 #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
95 #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
96 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
98 static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
100 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
101 brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
108 #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
109 #define RATETAB_ENT(_rateid, _flags) \
111 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
112 .hw_value = (_rateid), \
116 static struct ieee80211_rate __wl_rates[] = {
117 RATETAB_ENT(BRCM_RATE_1M, 0),
118 RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
119 RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
120 RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
121 RATETAB_ENT(BRCM_RATE_6M, 0),
122 RATETAB_ENT(BRCM_RATE_9M, 0),
123 RATETAB_ENT(BRCM_RATE_12M, 0),
124 RATETAB_ENT(BRCM_RATE_18M, 0),
125 RATETAB_ENT(BRCM_RATE_24M, 0),
126 RATETAB_ENT(BRCM_RATE_36M, 0),
127 RATETAB_ENT(BRCM_RATE_48M, 0),
128 RATETAB_ENT(BRCM_RATE_54M, 0),
131 #define wl_a_rates (__wl_rates + 4)
132 #define wl_a_rates_size 8
133 #define wl_g_rates (__wl_rates + 0)
134 #define wl_g_rates_size 12
136 /* Band templates duplicated per wiphy. The channel info
137 * is filled in after querying the device.
139 static const struct ieee80211_supported_band __wl_band_2ghz = {
140 .band = IEEE80211_BAND_2GHZ,
141 .bitrates = wl_g_rates,
142 .n_bitrates = wl_g_rates_size,
145 static const struct ieee80211_supported_band __wl_band_5ghz_a = {
146 .band = IEEE80211_BAND_5GHZ,
147 .bitrates = wl_a_rates,
148 .n_bitrates = wl_a_rates_size,
151 /* This is to override regulatory domains defined in cfg80211 module (reg.c)
152 * By default world regulatory domain defined in reg.c puts the flags
153 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
154 * With respect to these flags, wpa_supplicant doesn't * start p2p
155 * operations on 5GHz channels. All the changes in world regulatory
156 * domain are to be done here.
158 static const struct ieee80211_regdomain brcmf_regdom = {
162 /* IEEE 802.11b/g, channels 1..11 */
163 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
165 /* IEEE 802.11 channel 14 - Only JP enables
166 * this and for 802.11b only
168 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
169 /* IEEE 802.11a, channel 36..64 */
170 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
171 /* IEEE 802.11a, channel 100..165 */
172 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
175 static const u32 __wl_cipher_suites[] = {
176 WLAN_CIPHER_SUITE_WEP40,
177 WLAN_CIPHER_SUITE_WEP104,
178 WLAN_CIPHER_SUITE_TKIP,
179 WLAN_CIPHER_SUITE_CCMP,
180 WLAN_CIPHER_SUITE_AES_CMAC,
183 /* Vendor specific ie. id = 221, oui and type defines exact ie */
184 struct brcmf_vs_tlv {
191 struct parsed_vndr_ie_info {
193 u32 ie_len; /* total length including id & length field */
194 struct brcmf_vs_tlv vndrie;
197 struct parsed_vndr_ies {
199 struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
202 static int brcmf_roamoff;
203 module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
204 MODULE_PARM_DESC(roamoff, "do not use internal roaming engine");
206 /* Quarter dBm units to mW
207 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
208 * Table is offset so the last entry is largest mW value that fits in
212 #define QDBM_OFFSET 153 /* Offset for first entry */
213 #define QDBM_TABLE_LEN 40 /* Table size */
215 /* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
216 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
218 #define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
220 /* Largest mW value that will round down to the last table entry,
221 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
222 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
223 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
225 #define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
227 static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
228 /* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
229 /* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
230 /* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
231 /* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
232 /* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
233 /* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
236 static u16 brcmf_qdbm_to_mw(u8 qdbm)
239 int idx = qdbm - QDBM_OFFSET;
241 if (idx >= QDBM_TABLE_LEN)
242 /* clamp to max u16 mW value */
245 /* scale the qdBm index up to the range of the table 0-40
246 * where an offset of 40 qdBm equals a factor of 10 mW.
253 /* return the mW value scaled down to the correct factor of 10,
254 * adding in factor/2 to get proper rounding.
256 return (nqdBm_to_mW_map[idx] + factor / 2) / factor;
259 static u8 brcmf_mw_to_qdbm(u16 mw)
266 /* handle boundary case */
270 offset = QDBM_OFFSET;
272 /* move mw into the range of the table */
273 while (mw_uint < QDBM_TABLE_LOW_BOUND) {
278 for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) {
279 boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] -
280 nqdBm_to_mW_map[qdbm]) / 2;
281 if (mw_uint < boundary)
290 static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
291 struct cfg80211_chan_def *ch)
293 struct brcmu_chan ch_inf;
296 brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
297 ch->chan->center_freq, ch->center_freq1, ch->width);
298 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
299 primary_offset = ch->center_freq1 - ch->chan->center_freq;
301 case NL80211_CHAN_WIDTH_20:
302 ch_inf.bw = BRCMU_CHAN_BW_20;
303 WARN_ON(primary_offset != 0);
305 case NL80211_CHAN_WIDTH_40:
306 ch_inf.bw = BRCMU_CHAN_BW_40;
307 if (primary_offset < 0)
308 ch_inf.sb = BRCMU_CHAN_SB_U;
310 ch_inf.sb = BRCMU_CHAN_SB_L;
312 case NL80211_CHAN_WIDTH_80:
313 ch_inf.bw = BRCMU_CHAN_BW_80;
314 if (primary_offset < 0) {
315 if (primary_offset < -CH_10MHZ_APART)
316 ch_inf.sb = BRCMU_CHAN_SB_UU;
318 ch_inf.sb = BRCMU_CHAN_SB_UL;
320 if (primary_offset > CH_10MHZ_APART)
321 ch_inf.sb = BRCMU_CHAN_SB_LL;
323 ch_inf.sb = BRCMU_CHAN_SB_LU;
329 switch (ch->chan->band) {
330 case IEEE80211_BAND_2GHZ:
331 ch_inf.band = BRCMU_CHAN_BAND_2G;
333 case IEEE80211_BAND_5GHZ:
334 ch_inf.band = BRCMU_CHAN_BAND_5G;
339 d11inf->encchspec(&ch_inf);
341 return ch_inf.chspec;
344 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
345 struct ieee80211_channel *ch)
347 struct brcmu_chan ch_inf;
349 ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
350 ch_inf.bw = BRCMU_CHAN_BW_20;
351 d11inf->encchspec(&ch_inf);
353 return ch_inf.chspec;
356 /* Traverse a string of 1-byte tag/1-byte length/variable-length value
357 * triples, returning a pointer to the substring whose first element
360 const struct brcmf_tlv *
361 brcmf_parse_tlvs(const void *buf, int buflen, uint key)
363 const struct brcmf_tlv *elt = buf;
366 /* find tagged parameter */
367 while (totlen >= TLV_HDR_LEN) {
370 /* validate remaining totlen */
371 if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
374 elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
375 totlen -= (len + TLV_HDR_LEN);
381 /* Is any of the tlvs the expected entry? If
382 * not update the tlvs buffer pointer/length.
385 brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
386 const u8 *oui, u32 oui_len, u8 type)
388 /* If the contents match the OUI and the type */
389 if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
390 !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
391 type == ie[TLV_BODY_OFF + oui_len]) {
397 /* point to the next ie */
398 ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
399 /* calculate the length of the rest of the buffer */
400 *tlvs_len -= (int)(ie - *tlvs);
401 /* update the pointer to the start of the buffer */
407 static struct brcmf_vs_tlv *
408 brcmf_find_wpaie(const u8 *parse, u32 len)
410 const struct brcmf_tlv *ie;
412 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
413 if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
414 WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
415 return (struct brcmf_vs_tlv *)ie;
420 static struct brcmf_vs_tlv *
421 brcmf_find_wpsie(const u8 *parse, u32 len)
423 const struct brcmf_tlv *ie;
425 while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
426 if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
427 WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
428 return (struct brcmf_vs_tlv *)ie;
434 static void convert_key_from_CPU(struct brcmf_wsec_key *key,
435 struct brcmf_wsec_key_le *key_le)
437 key_le->index = cpu_to_le32(key->index);
438 key_le->len = cpu_to_le32(key->len);
439 key_le->algo = cpu_to_le32(key->algo);
440 key_le->flags = cpu_to_le32(key->flags);
441 key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
442 key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
443 key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
444 memcpy(key_le->data, key->data, sizeof(key->data));
445 memcpy(key_le->ea, key->ea, sizeof(key->ea));
449 send_key_to_dongle(struct net_device *ndev, struct brcmf_wsec_key *key)
452 struct brcmf_wsec_key_le key_le;
454 convert_key_from_CPU(key, &key_le);
456 brcmf_netdev_wait_pend8021x(ndev);
458 err = brcmf_fil_bsscfg_data_set(netdev_priv(ndev), "wsec_key", &key_le,
462 brcmf_err("wsec_key error (%d)\n", err);
467 brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable)
473 mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
477 /* Try to set and enable ARP offload feature, this may fail, then it */
478 /* is simply not supported and err 0 will be returned */
479 err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
481 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
485 err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
487 brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
491 brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
499 brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
501 struct brcmf_cfg80211_vif *vif;
502 struct brcmf_if *ifp;
504 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
507 if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
508 (wdev->iftype == NL80211_IFTYPE_AP) ||
509 (wdev->iftype == NL80211_IFTYPE_P2P_GO))
510 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
513 brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
517 static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
519 enum nl80211_iftype iftype;
521 iftype = vif->wdev.iftype;
522 return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
525 static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
527 return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
530 static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
532 enum nl80211_iftype type,
534 struct vif_params *params)
536 struct wireless_dev *wdev;
538 brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
540 case NL80211_IFTYPE_ADHOC:
541 case NL80211_IFTYPE_STATION:
542 case NL80211_IFTYPE_AP:
543 case NL80211_IFTYPE_AP_VLAN:
544 case NL80211_IFTYPE_WDS:
545 case NL80211_IFTYPE_MONITOR:
546 case NL80211_IFTYPE_MESH_POINT:
547 return ERR_PTR(-EOPNOTSUPP);
548 case NL80211_IFTYPE_P2P_CLIENT:
549 case NL80211_IFTYPE_P2P_GO:
550 case NL80211_IFTYPE_P2P_DEVICE:
551 wdev = brcmf_p2p_add_vif(wiphy, name, type, flags, params);
553 brcmf_cfg80211_update_proto_addr_mode(wdev);
555 case NL80211_IFTYPE_UNSPECIFIED:
557 return ERR_PTR(-EINVAL);
561 static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
563 if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
564 brcmf_set_mpc(ifp, mpc);
567 void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
571 if (check_vif_up(ifp->vif)) {
572 err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
574 brcmf_err("fail to set mpc\n");
577 brcmf_dbg(INFO, "MPC : %d\n", mpc);
581 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
582 struct brcmf_if *ifp, bool aborted,
585 struct brcmf_scan_params_le params_le;
586 struct cfg80211_scan_request *scan_request;
589 brcmf_dbg(SCAN, "Enter\n");
591 /* clear scan request, because the FW abort can cause a second call */
592 /* to this functon and might cause a double cfg80211_scan_done */
593 scan_request = cfg->scan_request;
594 cfg->scan_request = NULL;
596 if (timer_pending(&cfg->escan_timeout))
597 del_timer_sync(&cfg->escan_timeout);
600 /* Do a scan abort to stop the driver's scan engine */
601 brcmf_dbg(SCAN, "ABORT scan in firmware\n");
602 memset(¶ms_le, 0, sizeof(params_le));
603 memset(params_le.bssid, 0xFF, ETH_ALEN);
604 params_le.bss_type = DOT11_BSSTYPE_ANY;
605 params_le.scan_type = 0;
606 params_le.channel_num = cpu_to_le32(1);
607 params_le.nprobes = cpu_to_le32(1);
608 params_le.active_time = cpu_to_le32(-1);
609 params_le.passive_time = cpu_to_le32(-1);
610 params_le.home_time = cpu_to_le32(-1);
611 /* Scan is aborted by setting channel_list[0] to -1 */
612 params_le.channel_list[0] = cpu_to_le16(-1);
613 /* E-Scan (or anyother type) can be aborted by SCAN */
614 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
615 ¶ms_le, sizeof(params_le));
617 brcmf_err("Scan abort failed\n");
620 brcmf_scan_config_mpc(ifp, 1);
623 * e-scan can be initiated by scheduled scan
624 * which takes precedence.
626 if (cfg->sched_escan) {
627 brcmf_dbg(SCAN, "scheduled scan completed\n");
628 cfg->sched_escan = false;
630 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
631 } else if (scan_request) {
632 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
633 aborted ? "Aborted" : "Done");
634 cfg80211_scan_done(scan_request, aborted);
636 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
637 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
643 int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
645 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
646 struct net_device *ndev = wdev->netdev;
648 /* vif event pending in firmware */
649 if (brcmf_cfg80211_vif_event_armed(cfg))
653 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
654 cfg->escan_info.ifp == netdev_priv(ndev))
655 brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
658 brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
661 switch (wdev->iftype) {
662 case NL80211_IFTYPE_ADHOC:
663 case NL80211_IFTYPE_STATION:
664 case NL80211_IFTYPE_AP:
665 case NL80211_IFTYPE_AP_VLAN:
666 case NL80211_IFTYPE_WDS:
667 case NL80211_IFTYPE_MONITOR:
668 case NL80211_IFTYPE_MESH_POINT:
670 case NL80211_IFTYPE_P2P_CLIENT:
671 case NL80211_IFTYPE_P2P_GO:
672 case NL80211_IFTYPE_P2P_DEVICE:
673 return brcmf_p2p_del_vif(wiphy, wdev);
674 case NL80211_IFTYPE_UNSPECIFIED:
682 brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
683 enum nl80211_iftype type, u32 *flags,
684 struct vif_params *params)
686 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
687 struct brcmf_if *ifp = netdev_priv(ndev);
688 struct brcmf_cfg80211_vif *vif = ifp->vif;
693 brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type);
696 case NL80211_IFTYPE_MONITOR:
697 case NL80211_IFTYPE_WDS:
698 brcmf_err("type (%d) : currently we do not support this type\n",
701 case NL80211_IFTYPE_ADHOC:
704 case NL80211_IFTYPE_STATION:
705 /* Ignore change for p2p IF. Unclear why supplicant does this */
706 if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
707 (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) {
708 brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
709 /* WAR: It is unexpected to get a change of VIF for P2P
710 * IF, but it happens. The request can not be handled
711 * but returning EPERM causes a crash. Returning 0
712 * without setting ieee80211_ptr->iftype causes trace
713 * (WARN_ON) but it works with wpa_supplicant
719 case NL80211_IFTYPE_AP:
720 case NL80211_IFTYPE_P2P_GO:
729 if (type == NL80211_IFTYPE_P2P_GO) {
730 brcmf_dbg(INFO, "IF Type = P2P GO\n");
731 err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
734 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state);
735 brcmf_dbg(INFO, "IF Type = AP\n");
738 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
740 brcmf_err("WLC_SET_INFRA error (%d)\n", err);
744 brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
747 ndev->ieee80211_ptr->iftype = type;
749 brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
752 brcmf_dbg(TRACE, "Exit\n");
757 static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
758 struct brcmf_scan_params_le *params_le,
759 struct cfg80211_scan_request *request)
767 struct brcmf_ssid_le ssid_le;
769 memset(params_le->bssid, 0xFF, ETH_ALEN);
770 params_le->bss_type = DOT11_BSSTYPE_ANY;
771 params_le->scan_type = 0;
772 params_le->channel_num = 0;
773 params_le->nprobes = cpu_to_le32(-1);
774 params_le->active_time = cpu_to_le32(-1);
775 params_le->passive_time = cpu_to_le32(-1);
776 params_le->home_time = cpu_to_le32(-1);
777 memset(¶ms_le->ssid_le, 0, sizeof(params_le->ssid_le));
779 /* if request is null exit so it will be all channel broadcast scan */
783 n_ssids = request->n_ssids;
784 n_channels = request->n_channels;
785 /* Copy channel array if applicable */
786 brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
788 if (n_channels > 0) {
789 for (i = 0; i < n_channels; i++) {
790 chanspec = channel_to_chanspec(&cfg->d11inf,
791 request->channels[i]);
792 brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
793 request->channels[i]->hw_value, chanspec);
794 params_le->channel_list[i] = cpu_to_le16(chanspec);
797 brcmf_dbg(SCAN, "Scanning all channels\n");
799 /* Copy ssid array if applicable */
800 brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
802 offset = offsetof(struct brcmf_scan_params_le, channel_list) +
803 n_channels * sizeof(u16);
804 offset = roundup(offset, sizeof(u32));
805 ptr = (char *)params_le + offset;
806 for (i = 0; i < n_ssids; i++) {
807 memset(&ssid_le, 0, sizeof(ssid_le));
809 cpu_to_le32(request->ssids[i].ssid_len);
810 memcpy(ssid_le.SSID, request->ssids[i].ssid,
811 request->ssids[i].ssid_len);
812 if (!ssid_le.SSID_len)
813 brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
815 brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
816 i, ssid_le.SSID, ssid_le.SSID_len);
817 memcpy(ptr, &ssid_le, sizeof(ssid_le));
818 ptr += sizeof(ssid_le);
821 brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
822 if ((request->ssids) && request->ssids->ssid_len) {
823 brcmf_dbg(SCAN, "SSID %s len=%d\n",
824 params_le->ssid_le.SSID,
825 request->ssids->ssid_len);
826 params_le->ssid_le.SSID_len =
827 cpu_to_le32(request->ssids->ssid_len);
828 memcpy(¶ms_le->ssid_le.SSID, request->ssids->ssid,
829 request->ssids->ssid_len);
832 /* Adding mask to channel numbers */
833 params_le->channel_num =
834 cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
835 (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
839 brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
840 struct cfg80211_scan_request *request, u16 action)
842 s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
843 offsetof(struct brcmf_escan_params_le, params_le);
844 struct brcmf_escan_params_le *params;
847 brcmf_dbg(SCAN, "E-SCAN START\n");
849 if (request != NULL) {
850 /* Allocate space for populating ssids in struct */
851 params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
853 /* Allocate space for populating ssids in struct */
854 params_size += sizeof(struct brcmf_ssid) * request->n_ssids;
857 params = kzalloc(params_size, GFP_KERNEL);
862 BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
863 brcmf_escan_prep(cfg, ¶ms->params_le, request);
864 params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
865 params->action = cpu_to_le16(action);
866 params->sync_id = cpu_to_le16(0x1234);
868 err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
871 brcmf_dbg(INFO, "system busy : escan canceled\n");
873 brcmf_err("error (%d)\n", err);
882 brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
883 struct brcmf_if *ifp, struct cfg80211_scan_request *request)
887 struct brcmf_scan_results *results;
888 struct escan_info *escan = &cfg->escan_info;
890 brcmf_dbg(SCAN, "Enter\n");
892 escan->wiphy = wiphy;
893 escan->escan_state = WL_ESCAN_STATE_SCANNING;
894 passive_scan = cfg->active_scan ? 0 : 1;
895 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
898 brcmf_err("error (%d)\n", err);
901 brcmf_scan_config_mpc(ifp, 0);
902 results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
903 results->version = 0;
905 results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
907 err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START);
909 brcmf_scan_config_mpc(ifp, 1);
914 brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
915 struct cfg80211_scan_request *request,
916 struct cfg80211_ssid *this_ssid)
918 struct brcmf_if *ifp = vif->ifp;
919 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
920 struct cfg80211_ssid *ssids;
921 struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int;
928 brcmf_dbg(SCAN, "START ESCAN\n");
930 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
931 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
934 if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
935 brcmf_err("Scanning being aborted: status (%lu)\n",
939 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
940 brcmf_err("Scanning suppressed: status (%lu)\n",
944 if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
945 brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
949 /* If scan req comes for p2p0, send it over primary I/F */
950 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
951 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
953 /* Arm scan timeout timer */
954 mod_timer(&cfg->escan_timeout, jiffies +
955 WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
960 ssids = request->ssids;
964 /* we don't do escan in ibss */
968 cfg->scan_request = request;
969 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
971 cfg->escan_info.run = brcmf_run_escan;
972 err = brcmf_p2p_scan_prep(wiphy, request, vif);
976 err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
980 brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
981 ssids->ssid, ssids->ssid_len);
982 memset(&sr->ssid_le, 0, sizeof(sr->ssid_le));
983 SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len);
984 sr->ssid_le.SSID_len = cpu_to_le32(0);
987 memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len);
988 sr->ssid_le.SSID_len = cpu_to_le32(SSID_len);
991 brcmf_dbg(SCAN, "Broadcast scan\n");
993 passive_scan = cfg->active_scan ? 0 : 1;
994 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
997 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
1000 brcmf_scan_config_mpc(ifp, 0);
1001 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
1002 &sr->ssid_le, sizeof(sr->ssid_le));
1005 brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
1008 brcmf_err("WLC_SCAN error (%d)\n", err);
1010 brcmf_scan_config_mpc(ifp, 1);
1018 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
1019 if (timer_pending(&cfg->escan_timeout))
1020 del_timer_sync(&cfg->escan_timeout);
1021 cfg->scan_request = NULL;
1026 brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
1028 struct brcmf_cfg80211_vif *vif;
1031 brcmf_dbg(TRACE, "Enter\n");
1032 vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
1033 if (!check_vif_up(vif))
1036 err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
1039 brcmf_err("scan error (%d)\n", err);
1041 brcmf_dbg(TRACE, "Exit\n");
1045 static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
1049 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
1052 brcmf_err("Error (%d)\n", err);
1057 static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
1061 err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
1064 brcmf_err("Error (%d)\n", err);
1069 static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
1072 u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
1074 err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
1076 brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
1082 static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1084 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1085 struct net_device *ndev = cfg_to_ndev(cfg);
1086 struct brcmf_if *ifp = netdev_priv(ndev);
1089 brcmf_dbg(TRACE, "Enter\n");
1090 if (!check_vif_up(ifp->vif))
1093 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
1094 (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
1095 cfg->conf->rts_threshold = wiphy->rts_threshold;
1096 err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
1100 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
1101 (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
1102 cfg->conf->frag_threshold = wiphy->frag_threshold;
1103 err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
1107 if (changed & WIPHY_PARAM_RETRY_LONG
1108 && (cfg->conf->retry_long != wiphy->retry_long)) {
1109 cfg->conf->retry_long = wiphy->retry_long;
1110 err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
1114 if (changed & WIPHY_PARAM_RETRY_SHORT
1115 && (cfg->conf->retry_short != wiphy->retry_short)) {
1116 cfg->conf->retry_short = wiphy->retry_short;
1117 err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
1123 brcmf_dbg(TRACE, "Exit\n");
1127 static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
1129 memset(prof, 0, sizeof(*prof));
1132 static void brcmf_link_down(struct brcmf_cfg80211_vif *vif)
1134 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
1137 brcmf_dbg(TRACE, "Enter\n");
1139 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
1140 brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
1141 err = brcmf_fil_cmd_data_set(vif->ifp,
1142 BRCMF_C_DISASSOC, NULL, 0);
1144 brcmf_err("WLC_DISASSOC failed (%d)\n", err);
1146 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
1147 cfg80211_disconnected(vif->wdev.netdev, 0, NULL, 0, GFP_KERNEL);
1150 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
1151 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
1152 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
1153 brcmf_dbg(TRACE, "Exit\n");
1157 brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
1158 struct cfg80211_ibss_params *params)
1160 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1161 struct brcmf_if *ifp = netdev_priv(ndev);
1162 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
1163 struct brcmf_join_params join_params;
1164 size_t join_params_size = 0;
1170 brcmf_dbg(TRACE, "Enter\n");
1171 if (!check_vif_up(ifp->vif))
1175 brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
1177 brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
1181 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
1184 brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
1186 brcmf_dbg(CONN, "No BSSID specified\n");
1188 if (params->chandef.chan)
1189 brcmf_dbg(CONN, "channel: %d\n",
1190 params->chandef.chan->center_freq);
1192 brcmf_dbg(CONN, "no channel specified\n");
1194 if (params->channel_fixed)
1195 brcmf_dbg(CONN, "fixed channel required\n");
1197 brcmf_dbg(CONN, "no fixed channel required\n");
1199 if (params->ie && params->ie_len)
1200 brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
1202 brcmf_dbg(CONN, "no ie specified\n");
1204 if (params->beacon_interval)
1205 brcmf_dbg(CONN, "beacon interval: %d\n",
1206 params->beacon_interval);
1208 brcmf_dbg(CONN, "no beacon interval specified\n");
1210 if (params->basic_rates)
1211 brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
1213 brcmf_dbg(CONN, "no basic rates specified\n");
1215 if (params->privacy)
1216 brcmf_dbg(CONN, "privacy required\n");
1218 brcmf_dbg(CONN, "no privacy required\n");
1220 /* Configure Privacy for starter */
1221 if (params->privacy)
1222 wsec |= WEP_ENABLED;
1224 err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
1226 brcmf_err("wsec failed (%d)\n", err);
1230 /* Configure Beacon Interval for starter */
1231 if (params->beacon_interval)
1232 bcnprd = params->beacon_interval;
1236 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
1238 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
1242 /* Configure required join parameter */
1243 memset(&join_params, 0, sizeof(struct brcmf_join_params));
1246 profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32);
1247 memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len);
1248 memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len);
1249 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
1250 join_params_size = sizeof(join_params.ssid_le);
1253 if (params->bssid) {
1254 memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
1255 join_params_size = sizeof(join_params.ssid_le) +
1256 BRCMF_ASSOC_PARAMS_FIXED_SIZE;
1257 memcpy(profile->bssid, params->bssid, ETH_ALEN);
1259 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
1260 memset(profile->bssid, 0, ETH_ALEN);
1264 if (params->chandef.chan) {
1268 ieee80211_frequency_to_channel(
1269 params->chandef.chan->center_freq);
1270 if (params->channel_fixed) {
1271 /* adding chanspec */
1272 chanspec = chandef_to_chanspec(&cfg->d11inf,
1274 join_params.params_le.chanspec_list[0] =
1275 cpu_to_le16(chanspec);
1276 join_params.params_le.chanspec_num = cpu_to_le32(1);
1277 join_params_size += sizeof(join_params.params_le);
1280 /* set channel for starter */
1281 target_channel = cfg->channel;
1282 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
1285 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
1291 cfg->ibss_starter = false;
1294 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
1295 &join_params, join_params_size);
1297 brcmf_err("WLC_SET_SSID failed (%d)\n", err);
1303 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
1304 brcmf_dbg(TRACE, "Exit\n");
1309 brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
1311 struct brcmf_if *ifp = netdev_priv(ndev);
1313 brcmf_dbg(TRACE, "Enter\n");
1314 if (!check_vif_up(ifp->vif))
1317 brcmf_link_down(ifp->vif);
1319 brcmf_dbg(TRACE, "Exit\n");
1324 static s32 brcmf_set_wpa_version(struct net_device *ndev,
1325 struct cfg80211_connect_params *sme)
1327 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1328 struct brcmf_cfg80211_security *sec;
1332 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1333 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1334 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1335 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1337 val = WPA_AUTH_DISABLED;
1338 brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
1339 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
1341 brcmf_err("set wpa_auth failed (%d)\n", err);
1344 sec = &profile->sec;
1345 sec->wpa_versions = sme->crypto.wpa_versions;
1349 static s32 brcmf_set_auth_type(struct net_device *ndev,
1350 struct cfg80211_connect_params *sme)
1352 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1353 struct brcmf_cfg80211_security *sec;
1357 switch (sme->auth_type) {
1358 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1360 brcmf_dbg(CONN, "open system\n");
1362 case NL80211_AUTHTYPE_SHARED_KEY:
1364 brcmf_dbg(CONN, "shared key\n");
1366 case NL80211_AUTHTYPE_AUTOMATIC:
1368 brcmf_dbg(CONN, "automatic\n");
1370 case NL80211_AUTHTYPE_NETWORK_EAP:
1371 brcmf_dbg(CONN, "network eap\n");
1374 brcmf_err("invalid auth type (%d)\n", sme->auth_type);
1378 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
1380 brcmf_err("set auth failed (%d)\n", err);
1383 sec = &profile->sec;
1384 sec->auth_type = sme->auth_type;
1389 brcmf_set_wsec_mode(struct net_device *ndev,
1390 struct cfg80211_connect_params *sme, bool mfp)
1392 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1393 struct brcmf_cfg80211_security *sec;
1399 if (sme->crypto.n_ciphers_pairwise) {
1400 switch (sme->crypto.ciphers_pairwise[0]) {
1401 case WLAN_CIPHER_SUITE_WEP40:
1402 case WLAN_CIPHER_SUITE_WEP104:
1405 case WLAN_CIPHER_SUITE_TKIP:
1406 pval = TKIP_ENABLED;
1408 case WLAN_CIPHER_SUITE_CCMP:
1411 case WLAN_CIPHER_SUITE_AES_CMAC:
1415 brcmf_err("invalid cipher pairwise (%d)\n",
1416 sme->crypto.ciphers_pairwise[0]);
1420 if (sme->crypto.cipher_group) {
1421 switch (sme->crypto.cipher_group) {
1422 case WLAN_CIPHER_SUITE_WEP40:
1423 case WLAN_CIPHER_SUITE_WEP104:
1426 case WLAN_CIPHER_SUITE_TKIP:
1427 gval = TKIP_ENABLED;
1429 case WLAN_CIPHER_SUITE_CCMP:
1432 case WLAN_CIPHER_SUITE_AES_CMAC:
1436 brcmf_err("invalid cipher group (%d)\n",
1437 sme->crypto.cipher_group);
1442 brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
1443 /* In case of privacy, but no security and WPS then simulate */
1444 /* setting AES. WPS-2.0 allows no security */
1445 if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
1450 wsec = pval | gval | MFP_CAPABLE;
1453 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
1455 brcmf_err("error (%d)\n", err);
1459 sec = &profile->sec;
1460 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1461 sec->cipher_group = sme->crypto.cipher_group;
1467 brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
1469 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1470 struct brcmf_cfg80211_security *sec;
1474 if (sme->crypto.n_akm_suites) {
1475 err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
1478 brcmf_err("could not get wpa_auth (%d)\n", err);
1481 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1482 switch (sme->crypto.akm_suites[0]) {
1483 case WLAN_AKM_SUITE_8021X:
1484 val = WPA_AUTH_UNSPECIFIED;
1486 case WLAN_AKM_SUITE_PSK:
1490 brcmf_err("invalid cipher group (%d)\n",
1491 sme->crypto.cipher_group);
1494 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1495 switch (sme->crypto.akm_suites[0]) {
1496 case WLAN_AKM_SUITE_8021X:
1497 val = WPA2_AUTH_UNSPECIFIED;
1499 case WLAN_AKM_SUITE_PSK:
1500 val = WPA2_AUTH_PSK;
1503 brcmf_err("invalid cipher group (%d)\n",
1504 sme->crypto.cipher_group);
1509 brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
1510 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
1513 brcmf_err("could not set wpa_auth (%d)\n", err);
1517 sec = &profile->sec;
1518 sec->wpa_auth = sme->crypto.akm_suites[0];
1524 brcmf_set_sharedkey(struct net_device *ndev,
1525 struct cfg80211_connect_params *sme)
1527 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
1528 struct brcmf_cfg80211_security *sec;
1529 struct brcmf_wsec_key key;
1533 brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
1535 if (sme->key_len == 0)
1538 sec = &profile->sec;
1539 brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1540 sec->wpa_versions, sec->cipher_pairwise);
1542 if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
1545 if (!(sec->cipher_pairwise &
1546 (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
1549 memset(&key, 0, sizeof(key));
1550 key.len = (u32) sme->key_len;
1551 key.index = (u32) sme->key_idx;
1552 if (key.len > sizeof(key.data)) {
1553 brcmf_err("Too long key length (%u)\n", key.len);
1556 memcpy(key.data, sme->key, key.len);
1557 key.flags = BRCMF_PRIMARY_KEY;
1558 switch (sec->cipher_pairwise) {
1559 case WLAN_CIPHER_SUITE_WEP40:
1560 key.algo = CRYPTO_ALGO_WEP1;
1562 case WLAN_CIPHER_SUITE_WEP104:
1563 key.algo = CRYPTO_ALGO_WEP128;
1566 brcmf_err("Invalid algorithm (%d)\n",
1567 sme->crypto.ciphers_pairwise[0]);
1570 /* Set the new key/index */
1571 brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
1572 key.len, key.index, key.algo);
1573 brcmf_dbg(CONN, "key \"%s\"\n", key.data);
1574 err = send_key_to_dongle(ndev, &key);
1578 if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
1579 brcmf_dbg(CONN, "set auth_type to shared key\n");
1580 val = WL_AUTH_SHARED_KEY; /* shared key */
1581 err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
1583 brcmf_err("set auth failed (%d)\n", err);
1589 enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
1590 enum nl80211_auth_type type)
1592 if (type == NL80211_AUTHTYPE_AUTOMATIC &&
1593 brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
1594 brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
1595 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1601 brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
1602 struct cfg80211_connect_params *sme)
1604 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1605 struct brcmf_if *ifp = netdev_priv(ndev);
1606 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
1607 struct ieee80211_channel *chan = sme->channel;
1608 struct brcmf_join_params join_params;
1609 size_t join_params_size;
1610 const struct brcmf_tlv *rsn_ie;
1611 const struct brcmf_vs_tlv *wpa_ie;
1614 struct brcmf_ext_join_params_le *ext_join_params;
1618 brcmf_dbg(TRACE, "Enter\n");
1619 if (!check_vif_up(ifp->vif))
1623 brcmf_err("Invalid ssid\n");
1627 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
1628 /* A normal (non P2P) connection request setup. */
1631 /* find the WPA_IE */
1632 wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
1635 ie_len = wpa_ie->len + TLV_HDR_LEN;
1637 /* find the RSN_IE */
1638 rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
1643 ie_len = rsn_ie->len + TLV_HDR_LEN;
1646 brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
1649 err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
1650 sme->ie, sme->ie_len);
1652 brcmf_err("Set Assoc REQ IE Failed\n");
1654 brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
1656 set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
1660 ieee80211_frequency_to_channel(chan->center_freq);
1661 chanspec = channel_to_chanspec(&cfg->d11inf, chan);
1662 brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1663 cfg->channel, chan->center_freq, chanspec);
1669 brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
1671 err = brcmf_set_wpa_version(ndev, sme);
1673 brcmf_err("wl_set_wpa_version failed (%d)\n", err);
1677 sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
1678 err = brcmf_set_auth_type(ndev, sme);
1680 brcmf_err("wl_set_auth_type failed (%d)\n", err);
1684 err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
1686 brcmf_err("wl_set_set_cipher failed (%d)\n", err);
1690 err = brcmf_set_key_mgmt(ndev, sme);
1692 brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
1696 err = brcmf_set_sharedkey(ndev, sme);
1698 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
1702 profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID),
1703 (u32)sme->ssid_len);
1704 memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len);
1705 if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1706 profile->ssid.SSID[profile->ssid.SSID_len] = 0;
1707 brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID,
1708 profile->ssid.SSID_len);
1711 /* Join with specific BSSID and cached SSID
1712 * If SSID is zero join based on BSSID only
1714 join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
1715 offsetof(struct brcmf_assoc_params_le, chanspec_list);
1717 join_params_size += sizeof(u16);
1718 ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
1719 if (ext_join_params == NULL) {
1723 ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
1724 memcpy(&ext_join_params->ssid_le.SSID, sme->ssid,
1725 profile->ssid.SSID_len);
1727 /* Set up join scan parameters */
1728 ext_join_params->scan_le.scan_type = -1;
1729 ext_join_params->scan_le.home_time = cpu_to_le32(-1);
1732 memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
1734 memset(&ext_join_params->assoc_le.bssid, 0xFF, ETH_ALEN);
1737 ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
1739 ext_join_params->assoc_le.chanspec_list[0] =
1740 cpu_to_le16(chanspec);
1741 /* Increase dwell time to receive probe response or detect
1742 * beacon from target AP at a noisy air only during connect
1745 ext_join_params->scan_le.active_time =
1746 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
1747 ext_join_params->scan_le.passive_time =
1748 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
1749 /* To sync with presence period of VSDB GO send probe request
1750 * more frequently. Probe request will be stopped when it gets
1751 * probe response from target AP/GO.
1753 ext_join_params->scan_le.nprobes =
1754 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
1755 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
1757 ext_join_params->scan_le.active_time = cpu_to_le32(-1);
1758 ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
1759 ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
1762 err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
1764 kfree(ext_join_params);
1766 /* This is it. join command worked, we are done */
1769 /* join command failed, fallback to set ssid */
1770 memset(&join_params, 0, sizeof(join_params));
1771 join_params_size = sizeof(join_params.ssid_le);
1773 memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len);
1774 join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
1777 memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
1779 memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
1782 join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
1783 join_params.params_le.chanspec_num = cpu_to_le32(1);
1784 join_params_size += sizeof(join_params.params_le);
1786 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
1787 &join_params, join_params_size);
1789 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
1793 clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
1794 brcmf_dbg(TRACE, "Exit\n");
1799 brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
1802 struct brcmf_if *ifp = netdev_priv(ndev);
1803 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
1804 struct brcmf_scb_val_le scbval;
1807 brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
1808 if (!check_vif_up(ifp->vif))
1811 clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
1812 cfg80211_disconnected(ndev, reason_code, NULL, 0, GFP_KERNEL);
1814 memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
1815 scbval.val = cpu_to_le32(reason_code);
1816 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
1817 &scbval, sizeof(scbval));
1819 brcmf_err("error (%d)\n", err);
1821 brcmf_dbg(TRACE, "Exit\n");
1826 brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
1827 enum nl80211_tx_power_setting type, s32 mbm)
1830 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1831 struct net_device *ndev = cfg_to_ndev(cfg);
1832 struct brcmf_if *ifp = netdev_priv(ndev);
1836 s32 dbm = MBM_TO_DBM(mbm);
1838 brcmf_dbg(TRACE, "Enter\n");
1839 if (!check_vif_up(ifp->vif))
1843 case NL80211_TX_POWER_AUTOMATIC:
1845 case NL80211_TX_POWER_LIMITED:
1846 case NL80211_TX_POWER_FIXED:
1848 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
1854 /* Make sure radio is off or on as far as software is concerned */
1855 disable = WL_RADIO_SW_DISABLE << 16;
1856 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
1858 brcmf_err("WLC_SET_RADIO error (%d)\n", err);
1863 txpwrmw = (u16) dbm;
1864 err = brcmf_fil_iovar_int_set(ifp, "qtxpower",
1865 (s32)brcmf_mw_to_qdbm(txpwrmw));
1867 brcmf_err("qtxpower error (%d)\n", err);
1868 cfg->conf->tx_power = dbm;
1871 brcmf_dbg(TRACE, "Exit\n");
1875 static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy,
1876 struct wireless_dev *wdev,
1879 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1880 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
1885 brcmf_dbg(TRACE, "Enter\n");
1886 if (!check_vif_up(ifp->vif))
1889 err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &txpwrdbm);
1891 brcmf_err("error (%d)\n", err);
1895 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
1896 *dbm = (s32) brcmf_qdbm_to_mw(result);
1899 brcmf_dbg(TRACE, "Exit\n");
1904 brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
1905 u8 key_idx, bool unicast, bool multicast)
1907 struct brcmf_if *ifp = netdev_priv(ndev);
1912 brcmf_dbg(TRACE, "Enter\n");
1913 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
1914 if (!check_vif_up(ifp->vif))
1917 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
1919 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
1923 if (wsec & WEP_ENABLED) {
1924 /* Just select a new current key */
1926 err = brcmf_fil_cmd_int_set(ifp,
1927 BRCMF_C_SET_KEY_PRIMARY, index);
1929 brcmf_err("error (%d)\n", err);
1932 brcmf_dbg(TRACE, "Exit\n");
1937 brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
1938 u8 key_idx, const u8 *mac_addr, struct key_params *params)
1940 struct brcmf_if *ifp = netdev_priv(ndev);
1941 struct brcmf_wsec_key key;
1945 memset(&key, 0, sizeof(key));
1946 key.index = (u32) key_idx;
1947 /* Instead of bcast for ea address for default wep keys,
1948 driver needs it to be Null */
1949 if (!is_multicast_ether_addr(mac_addr))
1950 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
1951 key.len = (u32) params->key_len;
1952 /* check for key index change */
1955 err = send_key_to_dongle(ndev, &key);
1957 brcmf_err("key delete error (%d)\n", err);
1959 if (key.len > sizeof(key.data)) {
1960 brcmf_err("Invalid key length (%d)\n", key.len);
1964 brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
1965 memcpy(key.data, params->key, key.len);
1967 if (!brcmf_is_apmode(ifp->vif) &&
1968 (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
1969 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
1970 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1971 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1972 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1975 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1976 if (params->seq && params->seq_len == 6) {
1979 ivptr = (u8 *) params->seq;
1980 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
1981 (ivptr[3] << 8) | ivptr[2];
1982 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
1983 key.iv_initialized = true;
1986 switch (params->cipher) {
1987 case WLAN_CIPHER_SUITE_WEP40:
1988 key.algo = CRYPTO_ALGO_WEP1;
1989 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
1991 case WLAN_CIPHER_SUITE_WEP104:
1992 key.algo = CRYPTO_ALGO_WEP128;
1993 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
1995 case WLAN_CIPHER_SUITE_TKIP:
1996 key.algo = CRYPTO_ALGO_TKIP;
1997 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
1999 case WLAN_CIPHER_SUITE_AES_CMAC:
2000 key.algo = CRYPTO_ALGO_AES_CCM;
2001 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2003 case WLAN_CIPHER_SUITE_CCMP:
2004 key.algo = CRYPTO_ALGO_AES_CCM;
2005 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
2008 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
2011 err = send_key_to_dongle(ndev, &key);
2013 brcmf_err("wsec_key error (%d)\n", err);
2019 brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
2020 u8 key_idx, bool pairwise, const u8 *mac_addr,
2021 struct key_params *params)
2023 struct brcmf_if *ifp = netdev_priv(ndev);
2024 struct brcmf_wsec_key key;
2030 brcmf_dbg(TRACE, "Enter\n");
2031 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2032 if (!check_vif_up(ifp->vif))
2036 (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
2037 (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
2038 brcmf_dbg(TRACE, "Exit");
2039 return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
2041 memset(&key, 0, sizeof(key));
2043 key.len = (u32) params->key_len;
2044 key.index = (u32) key_idx;
2046 if (key.len > sizeof(key.data)) {
2047 brcmf_err("Too long key length (%u)\n", key.len);
2051 memcpy(key.data, params->key, key.len);
2053 key.flags = BRCMF_PRIMARY_KEY;
2054 switch (params->cipher) {
2055 case WLAN_CIPHER_SUITE_WEP40:
2056 key.algo = CRYPTO_ALGO_WEP1;
2058 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
2060 case WLAN_CIPHER_SUITE_WEP104:
2061 key.algo = CRYPTO_ALGO_WEP128;
2063 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
2065 case WLAN_CIPHER_SUITE_TKIP:
2066 if (!brcmf_is_apmode(ifp->vif)) {
2067 brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
2068 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2069 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2070 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2072 key.algo = CRYPTO_ALGO_TKIP;
2074 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
2076 case WLAN_CIPHER_SUITE_AES_CMAC:
2077 key.algo = CRYPTO_ALGO_AES_CCM;
2079 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2081 case WLAN_CIPHER_SUITE_CCMP:
2082 key.algo = CRYPTO_ALGO_AES_CCM;
2084 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
2087 brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
2092 err = send_key_to_dongle(ndev, &key);
2096 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2098 brcmf_err("get wsec error (%d)\n", err);
2102 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
2104 brcmf_err("set wsec error (%d)\n", err);
2109 brcmf_dbg(TRACE, "Exit\n");
2114 brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
2115 u8 key_idx, bool pairwise, const u8 *mac_addr)
2117 struct brcmf_if *ifp = netdev_priv(ndev);
2118 struct brcmf_wsec_key key;
2121 brcmf_dbg(TRACE, "Enter\n");
2122 if (!check_vif_up(ifp->vif))
2125 if (key_idx >= DOT11_MAX_DEFAULT_KEYS) {
2126 /* we ignore this key index in this case */
2127 brcmf_err("invalid key index (%d)\n", key_idx);
2131 memset(&key, 0, sizeof(key));
2133 key.index = (u32) key_idx;
2134 key.flags = BRCMF_PRIMARY_KEY;
2135 key.algo = CRYPTO_ALGO_OFF;
2137 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2139 /* Set the new key/index */
2140 err = send_key_to_dongle(ndev, &key);
2142 brcmf_dbg(TRACE, "Exit\n");
2147 brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
2148 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
2149 void (*callback) (void *cookie, struct key_params * params))
2151 struct key_params params;
2152 struct brcmf_if *ifp = netdev_priv(ndev);
2153 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2154 struct brcmf_cfg80211_security *sec;
2158 brcmf_dbg(TRACE, "Enter\n");
2159 brcmf_dbg(CONN, "key index (%d)\n", key_idx);
2160 if (!check_vif_up(ifp->vif))
2163 memset(¶ms, 0, sizeof(params));
2165 err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
2167 brcmf_err("WLC_GET_WSEC error (%d)\n", err);
2168 /* Ignore this error, may happen during DISASSOC */
2172 if (wsec & WEP_ENABLED) {
2173 sec = &profile->sec;
2174 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
2175 params.cipher = WLAN_CIPHER_SUITE_WEP40;
2176 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
2177 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
2178 params.cipher = WLAN_CIPHER_SUITE_WEP104;
2179 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
2181 } else if (wsec & TKIP_ENABLED) {
2182 params.cipher = WLAN_CIPHER_SUITE_TKIP;
2183 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
2184 } else if (wsec & AES_ENABLED) {
2185 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
2186 brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2188 brcmf_err("Invalid algo (0x%x)\n", wsec);
2192 callback(cookie, ¶ms);
2195 brcmf_dbg(TRACE, "Exit\n");
2200 brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
2201 struct net_device *ndev, u8 key_idx)
2203 brcmf_dbg(INFO, "Not supported\n");
2209 brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
2210 const u8 *mac, struct station_info *sinfo)
2212 struct brcmf_if *ifp = netdev_priv(ndev);
2213 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2214 struct brcmf_scb_val_le scb_val;
2218 u8 *bssid = profile->bssid;
2219 struct brcmf_sta_info_le sta_info_le;
2223 brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
2224 if (!check_vif_up(ifp->vif))
2227 if (brcmf_is_apmode(ifp->vif)) {
2228 memcpy(&sta_info_le, mac, ETH_ALEN);
2229 err = brcmf_fil_iovar_data_get(ifp, "sta_info",
2231 sizeof(sta_info_le));
2233 brcmf_err("GET STA INFO failed, %d\n", err);
2236 sinfo->filled = STATION_INFO_INACTIVE_TIME;
2237 sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
2238 if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) {
2239 sinfo->filled |= STATION_INFO_CONNECTED_TIME;
2240 sinfo->connected_time = le32_to_cpu(sta_info_le.in);
2242 brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n",
2243 sinfo->inactive_time, sinfo->connected_time);
2244 } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) {
2245 if (memcmp(mac, bssid, ETH_ALEN)) {
2246 brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
2251 /* Report the current tx rate */
2252 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
2254 brcmf_err("Could not get rate (%d)\n", err);
2257 sinfo->filled |= STATION_INFO_TX_BITRATE;
2258 sinfo->txrate.legacy = rate * 5;
2259 brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2);
2262 if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
2263 &ifp->vif->sme_state)) {
2264 memset(&scb_val, 0, sizeof(scb_val));
2265 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
2266 &scb_val, sizeof(scb_val));
2268 brcmf_err("Could not get rssi (%d)\n", err);
2271 rssi = le32_to_cpu(scb_val.val);
2272 sinfo->filled |= STATION_INFO_SIGNAL;
2273 sinfo->signal = rssi;
2274 brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
2276 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD,
2279 brcmf_err("Could not get beacon period (%d)\n",
2283 sinfo->bss_param.beacon_interval =
2285 brcmf_dbg(CONN, "Beacon peroid %d\n",
2288 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD,
2291 brcmf_err("Could not get DTIM period (%d)\n",
2295 sinfo->bss_param.dtim_period = dtim_period;
2296 brcmf_dbg(CONN, "DTIM peroid %d\n",
2299 sinfo->filled |= STATION_INFO_BSS_PARAM;
2304 brcmf_dbg(TRACE, "Exit\n");
2309 brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
2310 bool enabled, s32 timeout)
2314 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2315 struct brcmf_if *ifp = netdev_priv(ndev);
2317 brcmf_dbg(TRACE, "Enter\n");
2320 * Powersave enable/disable request is coming from the
2321 * cfg80211 even before the interface is up. In that
2322 * scenario, driver will be storing the power save
2323 * preference in cfg struct to apply this to
2324 * FW later while initializing the dongle
2326 cfg->pwr_save = enabled;
2327 if (!check_vif_up(ifp->vif)) {
2329 brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
2333 pm = enabled ? PM_FAST : PM_OFF;
2334 /* Do not enable the power save after assoc if it is a p2p interface */
2335 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
2336 brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
2339 brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
2341 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
2344 brcmf_err("net_device is not ready yet\n");
2346 brcmf_err("error (%d)\n", err);
2349 brcmf_dbg(TRACE, "Exit\n");
2353 static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
2354 struct brcmf_bss_info_le *bi)
2356 struct wiphy *wiphy = cfg_to_wiphy(cfg);
2357 struct ieee80211_channel *notify_channel;
2358 struct cfg80211_bss *bss;
2359 struct ieee80211_supported_band *band;
2360 struct brcmu_chan ch;
2363 u16 notify_capability;
2364 u16 notify_interval;
2366 size_t notify_ielen;
2369 if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
2370 brcmf_err("Bss info is larger than buffer. Discarding\n");
2375 ch.chspec = le16_to_cpu(bi->chanspec);
2376 cfg->d11inf.decchspec(&ch);
2377 bi->ctl_ch = ch.chnum;
2379 channel = bi->ctl_ch;
2381 if (channel <= CH_MAX_2G_CHANNEL)
2382 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2384 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2386 freq = ieee80211_channel_to_frequency(channel, band->band);
2387 notify_channel = ieee80211_get_channel(wiphy, freq);
2389 notify_capability = le16_to_cpu(bi->capability);
2390 notify_interval = le16_to_cpu(bi->beacon_period);
2391 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2392 notify_ielen = le32_to_cpu(bi->ie_length);
2393 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2395 brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
2396 brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
2397 brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
2398 brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
2399 brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
2401 bss = cfg80211_inform_bss(wiphy, notify_channel,
2402 CFG80211_BSS_FTYPE_UNKNOWN,
2403 (const u8 *)bi->BSSID,
2404 0, notify_capability,
2405 notify_interval, notify_ie,
2406 notify_ielen, notify_signal,
2412 cfg80211_put_bss(wiphy, bss);
2417 static struct brcmf_bss_info_le *
2418 next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
2421 return list->bss_info_le;
2422 return (struct brcmf_bss_info_le *)((unsigned long)bss +
2423 le32_to_cpu(bss->length));
2426 static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
2428 struct brcmf_scan_results *bss_list;
2429 struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
2433 bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
2434 if (bss_list->count != 0 &&
2435 bss_list->version != BRCMF_BSS_INFO_VERSION) {
2436 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2440 brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
2441 for (i = 0; i < bss_list->count; i++) {
2442 bi = next_bss_le(bss_list, bi);
2443 err = brcmf_inform_single_bss(cfg, bi);
2450 static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg,
2451 struct net_device *ndev, const u8 *bssid)
2453 struct wiphy *wiphy = cfg_to_wiphy(cfg);
2454 struct ieee80211_channel *notify_channel;
2455 struct brcmf_bss_info_le *bi = NULL;
2456 struct ieee80211_supported_band *band;
2457 struct cfg80211_bss *bss;
2458 struct brcmu_chan ch;
2462 u16 notify_capability;
2463 u16 notify_interval;
2465 size_t notify_ielen;
2468 brcmf_dbg(TRACE, "Enter\n");
2470 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2476 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2478 err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
2479 buf, WL_BSS_INFO_MAX);
2481 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
2485 bi = (struct brcmf_bss_info_le *)(buf + 4);
2487 ch.chspec = le16_to_cpu(bi->chanspec);
2488 cfg->d11inf.decchspec(&ch);
2490 if (ch.band == BRCMU_CHAN_BAND_2G)
2491 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2493 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2495 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
2496 notify_channel = ieee80211_get_channel(wiphy, freq);
2498 notify_capability = le16_to_cpu(bi->capability);
2499 notify_interval = le16_to_cpu(bi->beacon_period);
2500 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2501 notify_ielen = le32_to_cpu(bi->ie_length);
2502 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2504 brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
2505 brcmf_dbg(CONN, "capability: %X\n", notify_capability);
2506 brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
2507 brcmf_dbg(CONN, "signal: %d\n", notify_signal);
2509 bss = cfg80211_inform_bss(wiphy, notify_channel,
2510 CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
2511 notify_capability, notify_interval,
2512 notify_ie, notify_ielen, notify_signal,
2520 cfg80211_put_bss(wiphy, bss);
2526 brcmf_dbg(TRACE, "Exit\n");
2531 static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
2532 struct brcmf_if *ifp)
2534 struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev);
2535 struct brcmf_bss_info_le *bi;
2536 struct brcmf_ssid *ssid;
2537 const struct brcmf_tlv *tim;
2538 u16 beacon_interval;
2544 brcmf_dbg(TRACE, "Enter\n");
2545 if (brcmf_is_ibssmode(ifp->vif))
2548 ssid = &profile->ssid;
2550 *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
2551 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
2552 cfg->extra_buf, WL_EXTRA_BUF_MAX);
2554 brcmf_err("Could not get bss info %d\n", err);
2555 goto update_bss_info_out;
2558 bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
2559 err = brcmf_inform_single_bss(cfg, bi);
2561 goto update_bss_info_out;
2563 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
2564 ie_len = le32_to_cpu(bi->ie_length);
2565 beacon_interval = le16_to_cpu(bi->beacon_period);
2567 tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
2569 dtim_period = tim->data[1];
2572 * active scan was done so we could not get dtim
2573 * information out of probe response.
2574 * so we speficially query dtim information to dongle.
2577 err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
2579 brcmf_err("wl dtim_assoc failed (%d)\n", err);
2580 goto update_bss_info_out;
2582 dtim_period = (u8)var;
2585 update_bss_info_out:
2586 brcmf_dbg(TRACE, "Exit");
2590 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
2592 struct escan_info *escan = &cfg->escan_info;
2594 set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
2595 if (cfg->scan_request) {
2596 escan->escan_state = WL_ESCAN_STATE_IDLE;
2597 brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
2599 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
2600 clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
2603 static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
2605 struct brcmf_cfg80211_info *cfg =
2606 container_of(work, struct brcmf_cfg80211_info,
2607 escan_timeout_work);
2609 brcmf_inform_bss(cfg);
2610 brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
2613 static void brcmf_escan_timeout(unsigned long data)
2615 struct brcmf_cfg80211_info *cfg =
2616 (struct brcmf_cfg80211_info *)data;
2618 if (cfg->scan_request) {
2619 brcmf_err("timer expired\n");
2620 schedule_work(&cfg->escan_timeout_work);
2625 brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
2626 struct brcmf_bss_info_le *bss,
2627 struct brcmf_bss_info_le *bss_info_le)
2629 struct brcmu_chan ch_bss, ch_bss_info_le;
2631 ch_bss.chspec = le16_to_cpu(bss->chanspec);
2632 cfg->d11inf.decchspec(&ch_bss);
2633 ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
2634 cfg->d11inf.decchspec(&ch_bss_info_le);
2636 if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
2637 ch_bss.band == ch_bss_info_le.band &&
2638 bss_info_le->SSID_len == bss->SSID_len &&
2639 !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
2640 if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
2641 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
2642 s16 bss_rssi = le16_to_cpu(bss->RSSI);
2643 s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
2645 /* preserve max RSSI if the measurements are
2646 * both on-channel or both off-channel
2648 if (bss_info_rssi > bss_rssi)
2649 bss->RSSI = bss_info_le->RSSI;
2650 } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
2651 (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
2652 /* preserve the on-channel rssi measurement
2653 * if the new measurement is off channel
2655 bss->RSSI = bss_info_le->RSSI;
2656 bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
2664 brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
2665 const struct brcmf_event_msg *e, void *data)
2667 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
2669 struct brcmf_escan_result_le *escan_result_le;
2670 struct brcmf_bss_info_le *bss_info_le;
2671 struct brcmf_bss_info_le *bss = NULL;
2673 struct brcmf_scan_results *list;
2679 if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
2680 brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx);
2684 if (status == BRCMF_E_STATUS_PARTIAL) {
2685 brcmf_dbg(SCAN, "ESCAN Partial result\n");
2686 escan_result_le = (struct brcmf_escan_result_le *) data;
2687 if (!escan_result_le) {
2688 brcmf_err("Invalid escan result (NULL pointer)\n");
2691 if (le16_to_cpu(escan_result_le->bss_count) != 1) {
2692 brcmf_err("Invalid bss_count %d: ignoring\n",
2693 escan_result_le->bss_count);
2696 bss_info_le = &escan_result_le->bss_info_le;
2698 if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
2701 if (!cfg->scan_request) {
2702 brcmf_dbg(SCAN, "result without cfg80211 request\n");
2706 bi_length = le32_to_cpu(bss_info_le->length);
2707 if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
2708 WL_ESCAN_RESULTS_FIXED_SIZE)) {
2709 brcmf_err("Invalid bss_info length %d: ignoring\n",
2714 if (!(cfg_to_wiphy(cfg)->interface_modes &
2715 BIT(NL80211_IFTYPE_ADHOC))) {
2716 if (le16_to_cpu(bss_info_le->capability) &
2717 WLAN_CAPABILITY_IBSS) {
2718 brcmf_err("Ignoring IBSS result\n");
2723 list = (struct brcmf_scan_results *)
2724 cfg->escan_info.escan_buf;
2725 if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
2726 brcmf_err("Buffer is too small: ignoring\n");
2730 for (i = 0; i < list->count; i++) {
2731 bss = bss ? (struct brcmf_bss_info_le *)
2732 ((unsigned char *)bss +
2733 le32_to_cpu(bss->length)) : list->bss_info_le;
2734 if (brcmf_compare_update_same_bss(cfg, bss,
2738 memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
2739 bss_info_le, bi_length);
2740 list->version = le32_to_cpu(bss_info_le->version);
2741 list->buflen += bi_length;
2744 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
2745 if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
2747 if (cfg->scan_request) {
2748 brcmf_inform_bss(cfg);
2749 aborted = status != BRCMF_E_STATUS_SUCCESS;
2750 brcmf_notify_escan_complete(cfg, ifp, aborted, false);
2752 brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
2759 static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
2761 brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
2762 brcmf_cfg80211_escan_handler);
2763 cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
2764 /* Init scan_timeout timer */
2765 init_timer(&cfg->escan_timeout);
2766 cfg->escan_timeout.data = (unsigned long) cfg;
2767 cfg->escan_timeout.function = brcmf_escan_timeout;
2768 INIT_WORK(&cfg->escan_timeout_work,
2769 brcmf_cfg80211_escan_timeout_worker);
2772 static __always_inline void brcmf_delay(u32 ms)
2774 if (ms < 1000 / HZ) {
2782 static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
2784 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2785 struct net_device *ndev = cfg_to_ndev(cfg);
2786 struct brcmf_if *ifp = netdev_priv(ndev);
2788 brcmf_dbg(TRACE, "Enter\n");
2790 if (cfg->wowl_enabled) {
2791 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
2792 cfg->pre_wowl_pmmode);
2793 brcmf_fil_iovar_data_set(ifp, "wowl_pattern", "clr", 4);
2794 brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
2795 cfg->wowl_enabled = false;
2800 static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
2801 struct brcmf_if *ifp,
2802 struct cfg80211_wowlan *wowl)
2806 brcmf_dbg(TRACE, "Suspend, wowl config.\n");
2808 brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode);
2809 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
2812 if (wowl->disconnect)
2813 wowl_config |= WL_WOWL_DIS | WL_WOWL_BCN | WL_WOWL_RETR;
2814 /* Note: if "wowl" target and not "wowlpf" then wowl_bcn_loss
2815 * should be configured. This paramater is not supported by
2818 if (wowl->magic_pkt)
2819 wowl_config |= WL_WOWL_MAGIC;
2820 brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
2821 brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
2822 brcmf_bus_wowl_config(cfg->pub->bus_if, true);
2823 cfg->wowl_enabled = true;
2826 static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
2827 struct cfg80211_wowlan *wowl)
2829 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2830 struct net_device *ndev = cfg_to_ndev(cfg);
2831 struct brcmf_if *ifp = netdev_priv(ndev);
2832 struct brcmf_cfg80211_vif *vif;
2834 brcmf_dbg(TRACE, "Enter\n");
2836 /* if the primary net_device is not READY there is nothing
2837 * we can do but pray resume goes smoothly.
2839 if (!check_vif_up(ifp->vif))
2842 /* end any scanning */
2843 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
2844 brcmf_abort_scanning(cfg);
2847 brcmf_bus_wowl_config(cfg->pub->bus_if, false);
2848 list_for_each_entry(vif, &cfg->vif_list, list) {
2849 if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
2851 /* While going to suspend if associated with AP
2852 * disassociate from AP to save power while system is
2853 * in suspended state
2855 brcmf_link_down(vif);
2856 /* Make sure WPA_Supplicant receives all the event
2857 * generated due to DISASSOC call to the fw to keep
2858 * the state fw and WPA_Supplicant state consistent
2863 brcmf_set_mpc(ifp, 1);
2866 /* Configure WOWL paramaters */
2867 brcmf_configure_wowl(cfg, ifp, wowl);
2871 brcmf_dbg(TRACE, "Exit\n");
2872 /* clear any scanning activity */
2873 cfg->scan_status = 0;
2878 brcmf_update_pmklist(struct net_device *ndev,
2879 struct brcmf_cfg80211_pmk_list *pmk_list, s32 err)
2884 pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid);
2886 brcmf_dbg(CONN, "No of elements %d\n", pmkid_len);
2887 for (i = 0; i < pmkid_len; i++) {
2888 brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i,
2889 &pmk_list->pmkids.pmkid[i].BSSID);
2890 for (j = 0; j < WLAN_PMKID_LEN; j++)
2891 brcmf_dbg(CONN, "%02x\n",
2892 pmk_list->pmkids.pmkid[i].PMKID[j]);
2896 brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info",
2897 (char *)pmk_list, sizeof(*pmk_list));
2903 brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
2904 struct cfg80211_pmksa *pmksa)
2906 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2907 struct brcmf_if *ifp = netdev_priv(ndev);
2908 struct pmkid_list *pmkids = &cfg->pmk_list->pmkids;
2913 brcmf_dbg(TRACE, "Enter\n");
2914 if (!check_vif_up(ifp->vif))
2917 pmkid_len = le32_to_cpu(pmkids->npmkid);
2918 for (i = 0; i < pmkid_len; i++)
2919 if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN))
2921 if (i < WL_NUM_PMKIDS_MAX) {
2922 memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN);
2923 memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2924 if (i == pmkid_len) {
2926 pmkids->npmkid = cpu_to_le32(pmkid_len);
2931 brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2932 pmkids->pmkid[pmkid_len].BSSID);
2933 for (i = 0; i < WLAN_PMKID_LEN; i++)
2934 brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]);
2936 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
2938 brcmf_dbg(TRACE, "Exit\n");
2943 brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
2944 struct cfg80211_pmksa *pmksa)
2946 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2947 struct brcmf_if *ifp = netdev_priv(ndev);
2948 struct pmkid_list pmkid;
2952 brcmf_dbg(TRACE, "Enter\n");
2953 if (!check_vif_up(ifp->vif))
2956 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
2957 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2959 brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
2960 &pmkid.pmkid[0].BSSID);
2961 for (i = 0; i < WLAN_PMKID_LEN; i++)
2962 brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]);
2964 pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid);
2965 for (i = 0; i < pmkid_len; i++)
2967 (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID,
2972 && (i < pmkid_len)) {
2973 memset(&cfg->pmk_list->pmkids.pmkid[i], 0,
2974 sizeof(struct pmkid));
2975 for (; i < (pmkid_len - 1); i++) {
2976 memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID,
2977 &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID,
2979 memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID,
2980 &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID,
2983 cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1);
2987 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
2989 brcmf_dbg(TRACE, "Exit\n");
2995 brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
2997 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2998 struct brcmf_if *ifp = netdev_priv(ndev);
3001 brcmf_dbg(TRACE, "Enter\n");
3002 if (!check_vif_up(ifp->vif))
3005 memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list));
3006 err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
3008 brcmf_dbg(TRACE, "Exit\n");
3014 * PFN result doesn't have all the info which are
3015 * required by the supplicant
3016 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3017 * via wl_inform_single_bss in the required format. Escan does require the
3018 * scan request in the form of cfg80211_scan_request. For timebeing, create
3019 * cfg80211_scan_request one out of the received PNO event.
3022 brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
3023 const struct brcmf_event_msg *e, void *data)
3025 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
3026 struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
3027 struct cfg80211_scan_request *request = NULL;
3028 struct cfg80211_ssid *ssid = NULL;
3029 struct ieee80211_channel *channel = NULL;
3030 struct wiphy *wiphy = cfg_to_wiphy(cfg);
3032 int channel_req = 0;
3034 struct brcmf_pno_scanresults_le *pfn_result;
3038 brcmf_dbg(SCAN, "Enter\n");
3040 if (e->event_code == BRCMF_E_PFN_NET_LOST) {
3041 brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
3045 pfn_result = (struct brcmf_pno_scanresults_le *)data;
3046 result_count = le32_to_cpu(pfn_result->count);
3047 status = le32_to_cpu(pfn_result->status);
3050 * PFN event is limited to fit 512 bytes so we may get
3051 * multiple NET_FOUND events. For now place a warning here.
3053 WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
3054 brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
3055 if (result_count > 0) {
3058 request = kzalloc(sizeof(*request), GFP_KERNEL);
3059 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
3060 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
3061 if (!request || !ssid || !channel) {
3066 request->wiphy = wiphy;
3067 data += sizeof(struct brcmf_pno_scanresults_le);
3068 netinfo_start = (struct brcmf_pno_net_info_le *)data;
3070 for (i = 0; i < result_count; i++) {
3071 netinfo = &netinfo_start[i];
3073 brcmf_err("Invalid netinfo ptr. index: %d\n",
3079 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
3080 netinfo->SSID, netinfo->channel);
3081 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
3082 ssid[i].ssid_len = netinfo->SSID_len;
3085 channel_req = netinfo->channel;
3086 if (channel_req <= CH_MAX_2G_CHANNEL)
3087 band = NL80211_BAND_2GHZ;
3089 band = NL80211_BAND_5GHZ;
3090 channel[i].center_freq =
3091 ieee80211_channel_to_frequency(channel_req,
3093 channel[i].band = band;
3094 channel[i].flags |= IEEE80211_CHAN_NO_HT40;
3095 request->channels[i] = &channel[i];
3096 request->n_channels++;
3099 /* assign parsed ssid array */
3100 if (request->n_ssids)
3101 request->ssids = &ssid[0];
3103 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3104 /* Abort any on-going scan */
3105 brcmf_abort_scanning(cfg);
3108 set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3109 cfg->escan_info.run = brcmf_run_escan;
3110 err = brcmf_do_escan(cfg, wiphy, ifp, request);
3112 clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
3115 cfg->sched_escan = true;
3116 cfg->scan_request = request;
3118 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3131 cfg80211_sched_scan_stopped(wiphy);
3135 static int brcmf_dev_pno_clean(struct net_device *ndev)
3140 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
3143 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
3147 brcmf_err("failed code %d\n", ret);
3152 static int brcmf_dev_pno_config(struct net_device *ndev)
3154 struct brcmf_pno_param_le pfn_param;
3156 memset(&pfn_param, 0, sizeof(pfn_param));
3157 pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
3159 /* set extra pno params */
3160 pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
3161 pfn_param.repeat = BRCMF_PNO_REPEAT;
3162 pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
3164 /* set up pno scan fr */
3165 pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
3167 return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set",
3168 &pfn_param, sizeof(pfn_param));
3172 brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3173 struct net_device *ndev,
3174 struct cfg80211_sched_scan_request *request)
3176 struct brcmf_if *ifp = netdev_priv(ndev);
3177 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
3178 struct brcmf_pno_net_param_le pfn;
3182 brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
3183 request->n_match_sets, request->n_ssids);
3184 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
3185 brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
3188 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
3189 brcmf_err("Scanning suppressed: status (%lu)\n",
3194 if (!request->n_ssids || !request->n_match_sets) {
3195 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
3200 if (request->n_ssids > 0) {
3201 for (i = 0; i < request->n_ssids; i++) {
3202 /* Active scan req for ssids */
3203 brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
3204 request->ssids[i].ssid);
3207 * match_set ssids is a supert set of n_ssid list,
3208 * so we need not add these set seperately.
3213 if (request->n_match_sets > 0) {
3214 /* clean up everything */
3215 ret = brcmf_dev_pno_clean(ndev);
3217 brcmf_err("failed error=%d\n", ret);
3222 ret = brcmf_dev_pno_config(ndev);
3224 brcmf_err("PNO setup failed!! ret=%d\n", ret);
3228 /* configure each match set */
3229 for (i = 0; i < request->n_match_sets; i++) {
3230 struct cfg80211_ssid *ssid;
3233 ssid = &request->match_sets[i].ssid;
3234 ssid_len = ssid->ssid_len;
3237 brcmf_err("skip broadcast ssid\n");
3240 pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
3241 pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
3242 pfn.wsec = cpu_to_le32(0);
3243 pfn.infra = cpu_to_le32(1);
3244 pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
3245 pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
3246 memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
3247 ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
3249 brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
3250 ret == 0 ? "set" : "failed", ssid->ssid);
3252 /* Enable the PNO */
3253 if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
3254 brcmf_err("PNO enable failed!! ret=%d\n", ret);
3264 static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3265 struct net_device *ndev)
3267 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3269 brcmf_dbg(SCAN, "enter\n");
3270 brcmf_dev_pno_clean(ndev);
3271 if (cfg->sched_escan)
3272 brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
3276 static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
3281 err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
3283 brcmf_err("auth error %d\n", err);
3287 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
3289 brcmf_err("wsec error %d\n", err);
3292 /* set upper-layer auth */
3293 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
3295 brcmf_err("wpa_auth error %d\n", err);
3302 static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
3305 return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
3307 return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
3311 brcmf_configure_wpaie(struct net_device *ndev,
3312 const struct brcmf_vs_tlv *wpa_ie,
3315 struct brcmf_if *ifp = netdev_priv(ndev);
3316 u32 auth = 0; /* d11 open authentication */
3328 u32 wme_bss_disable;
3330 brcmf_dbg(TRACE, "Enter\n");
3334 len = wpa_ie->len + TLV_HDR_LEN;
3335 data = (u8 *)wpa_ie;
3336 offset = TLV_HDR_LEN;
3338 offset += VS_IE_FIXED_HDR_LEN;
3340 offset += WPA_IE_VERSION_LEN;
3342 /* check for multicast cipher suite */
3343 if (offset + WPA_IE_MIN_OUI_LEN > len) {
3345 brcmf_err("no multicast cipher suite\n");
3349 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3351 brcmf_err("ivalid OUI\n");
3354 offset += TLV_OUI_LEN;
3356 /* pick up multicast cipher */
3357 switch (data[offset]) {
3358 case WPA_CIPHER_NONE:
3361 case WPA_CIPHER_WEP_40:
3362 case WPA_CIPHER_WEP_104:
3365 case WPA_CIPHER_TKIP:
3366 gval = TKIP_ENABLED;
3368 case WPA_CIPHER_AES_CCM:
3373 brcmf_err("Invalid multi cast cipher info\n");
3378 /* walk thru unicast cipher list and pick up what we recognize */
3379 count = data[offset] + (data[offset + 1] << 8);
3380 offset += WPA_IE_SUITE_COUNT_LEN;
3381 /* Check for unicast suite(s) */
3382 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3384 brcmf_err("no unicast cipher suite\n");
3387 for (i = 0; i < count; i++) {
3388 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3390 brcmf_err("ivalid OUI\n");
3393 offset += TLV_OUI_LEN;
3394 switch (data[offset]) {
3395 case WPA_CIPHER_NONE:
3397 case WPA_CIPHER_WEP_40:
3398 case WPA_CIPHER_WEP_104:
3399 pval |= WEP_ENABLED;
3401 case WPA_CIPHER_TKIP:
3402 pval |= TKIP_ENABLED;
3404 case WPA_CIPHER_AES_CCM:
3405 pval |= AES_ENABLED;
3408 brcmf_err("Ivalid unicast security info\n");
3412 /* walk thru auth management suite list and pick up what we recognize */
3413 count = data[offset] + (data[offset + 1] << 8);
3414 offset += WPA_IE_SUITE_COUNT_LEN;
3415 /* Check for auth key management suite(s) */
3416 if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
3418 brcmf_err("no auth key mgmt suite\n");
3421 for (i = 0; i < count; i++) {
3422 if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
3424 brcmf_err("ivalid OUI\n");
3427 offset += TLV_OUI_LEN;
3428 switch (data[offset]) {
3430 brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
3431 wpa_auth |= WPA_AUTH_NONE;
3433 case RSN_AKM_UNSPECIFIED:
3434 brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
3435 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
3436 (wpa_auth |= WPA_AUTH_UNSPECIFIED);
3439 brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
3440 is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
3441 (wpa_auth |= WPA_AUTH_PSK);
3444 brcmf_err("Ivalid key mgmt info\n");
3450 wme_bss_disable = 1;
3451 if ((offset + RSN_CAP_LEN) <= len) {
3452 rsn_cap = data[offset] + (data[offset + 1] << 8);
3453 if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
3454 wme_bss_disable = 0;
3456 /* set wme_bss_disable to sync RSN Capabilities */
3457 err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
3460 brcmf_err("wme_bss_disable error %d\n", err);
3464 /* FOR WPS , set SES_OW_ENABLED */
3465 wsec = (pval | gval | SES_OW_ENABLED);
3468 err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
3470 brcmf_err("auth error %d\n", err);
3474 err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
3476 brcmf_err("wsec error %d\n", err);
3479 /* set upper-layer auth */
3480 err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
3482 brcmf_err("wpa_auth error %d\n", err);
3491 brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
3492 struct parsed_vndr_ies *vndr_ies)
3494 struct brcmf_vs_tlv *vndrie;
3495 struct brcmf_tlv *ie;
3496 struct parsed_vndr_ie_info *parsed_info;
3499 remaining_len = (s32)vndr_ie_len;
3500 memset(vndr_ies, 0, sizeof(*vndr_ies));
3502 ie = (struct brcmf_tlv *)vndr_ie_buf;
3504 if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
3506 vndrie = (struct brcmf_vs_tlv *)ie;
3507 /* len should be bigger than OUI length + one */
3508 if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
3509 brcmf_err("invalid vndr ie. length is too small %d\n",
3513 /* if wpa or wme ie, do not add ie */
3514 if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
3515 ((vndrie->oui_type == WPA_OUI_TYPE) ||
3516 (vndrie->oui_type == WME_OUI_TYPE))) {
3517 brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
3521 parsed_info = &vndr_ies->ie_info[vndr_ies->count];
3523 /* save vndr ie information */
3524 parsed_info->ie_ptr = (char *)vndrie;
3525 parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
3526 memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
3530 brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
3531 parsed_info->vndrie.oui[0],
3532 parsed_info->vndrie.oui[1],
3533 parsed_info->vndrie.oui[2],
3534 parsed_info->vndrie.oui_type);
3536 if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
3539 remaining_len -= (ie->len + TLV_HDR_LEN);
3540 if (remaining_len <= TLV_HDR_LEN)
3543 ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
3550 brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
3556 strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
3557 iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
3559 iecount_le = cpu_to_le32(1);
3560 memcpy(&iebuf[VNDR_IE_COUNT_OFFSET], &iecount_le, sizeof(iecount_le));
3562 pktflag_le = cpu_to_le32(pktflag);
3563 memcpy(&iebuf[VNDR_IE_PKTFLAG_OFFSET], &pktflag_le, sizeof(pktflag_le));
3565 memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
3567 return ie_len + VNDR_IE_HDR_SIZE;
3570 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
3571 const u8 *vndr_ie_buf, u32 vndr_ie_len)
3573 struct brcmf_if *ifp;
3574 struct vif_saved_ie *saved_ie;
3578 u8 *mgmt_ie_buf = NULL;
3579 int mgmt_ie_buf_len;
3581 u32 del_add_ie_buf_len = 0;
3582 u32 total_ie_buf_len = 0;
3583 u32 parsed_ie_buf_len = 0;
3584 struct parsed_vndr_ies old_vndr_ies;
3585 struct parsed_vndr_ies new_vndr_ies;
3586 struct parsed_vndr_ie_info *vndrie_info;
3589 int remained_buf_len;
3594 saved_ie = &vif->saved_ie;
3596 brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag);
3597 iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
3600 curr_ie_buf = iovar_ie_buf;
3602 case BRCMF_VNDR_IE_PRBREQ_FLAG:
3603 mgmt_ie_buf = saved_ie->probe_req_ie;
3604 mgmt_ie_len = &saved_ie->probe_req_ie_len;
3605 mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
3607 case BRCMF_VNDR_IE_PRBRSP_FLAG:
3608 mgmt_ie_buf = saved_ie->probe_res_ie;
3609 mgmt_ie_len = &saved_ie->probe_res_ie_len;
3610 mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
3612 case BRCMF_VNDR_IE_BEACON_FLAG:
3613 mgmt_ie_buf = saved_ie->beacon_ie;
3614 mgmt_ie_len = &saved_ie->beacon_ie_len;
3615 mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
3617 case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
3618 mgmt_ie_buf = saved_ie->assoc_req_ie;
3619 mgmt_ie_len = &saved_ie->assoc_req_ie_len;
3620 mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
3624 brcmf_err("not suitable type\n");
3628 if (vndr_ie_len > mgmt_ie_buf_len) {
3630 brcmf_err("extra IE size too big\n");
3634 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3635 if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
3637 brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
3638 for (i = 0; i < new_vndr_ies.count; i++) {
3639 vndrie_info = &new_vndr_ies.ie_info[i];
3640 memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
3641 vndrie_info->ie_len);
3642 parsed_ie_buf_len += vndrie_info->ie_len;
3646 if (mgmt_ie_buf && *mgmt_ie_len) {
3647 if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
3648 (memcmp(mgmt_ie_buf, curr_ie_buf,
3649 parsed_ie_buf_len) == 0)) {
3650 brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
3654 /* parse old vndr_ie */
3655 brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
3657 /* make a command to delete old ie */
3658 for (i = 0; i < old_vndr_ies.count; i++) {
3659 vndrie_info = &old_vndr_ies.ie_info[i];
3661 brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3662 vndrie_info->vndrie.id,
3663 vndrie_info->vndrie.len,
3664 vndrie_info->vndrie.oui[0],
3665 vndrie_info->vndrie.oui[1],
3666 vndrie_info->vndrie.oui[2]);
3668 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3669 vndrie_info->ie_ptr,
3670 vndrie_info->ie_len,
3672 curr_ie_buf += del_add_ie_buf_len;
3673 total_ie_buf_len += del_add_ie_buf_len;
3678 /* Add if there is any extra IE */
3679 if (mgmt_ie_buf && parsed_ie_buf_len) {
3682 remained_buf_len = mgmt_ie_buf_len;
3684 /* make a command to add new ie */
3685 for (i = 0; i < new_vndr_ies.count; i++) {
3686 vndrie_info = &new_vndr_ies.ie_info[i];
3688 /* verify remained buf size before copy data */
3689 if (remained_buf_len < (vndrie_info->vndrie.len +
3690 VNDR_IE_VSIE_OFFSET)) {
3691 brcmf_err("no space in mgmt_ie_buf: len left %d",
3695 remained_buf_len -= (vndrie_info->ie_len +
3696 VNDR_IE_VSIE_OFFSET);
3698 brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3699 vndrie_info->vndrie.id,
3700 vndrie_info->vndrie.len,
3701 vndrie_info->vndrie.oui[0],
3702 vndrie_info->vndrie.oui[1],
3703 vndrie_info->vndrie.oui[2]);
3705 del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
3706 vndrie_info->ie_ptr,
3707 vndrie_info->ie_len,
3710 /* save the parsed IE in wl struct */
3711 memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
3712 vndrie_info->ie_len);
3713 *mgmt_ie_len += vndrie_info->ie_len;
3715 curr_ie_buf += del_add_ie_buf_len;
3716 total_ie_buf_len += del_add_ie_buf_len;
3719 if (total_ie_buf_len) {
3720 err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
3723 brcmf_err("vndr ie set error : %d\n", err);
3727 kfree(iovar_ie_buf);
3731 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
3734 BRCMF_VNDR_IE_PRBREQ_FLAG,
3735 BRCMF_VNDR_IE_PRBRSP_FLAG,
3736 BRCMF_VNDR_IE_BEACON_FLAG
3740 for (i = 0; i < ARRAY_SIZE(pktflags); i++)
3741 brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
3743 memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
3748 brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
3749 struct cfg80211_beacon_data *beacon)
3753 /* Set Beacon IEs to FW */
3754 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
3755 beacon->tail, beacon->tail_len);
3757 brcmf_err("Set Beacon IE Failed\n");
3760 brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
3762 /* Set Probe Response IEs to FW */
3763 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
3764 beacon->proberesp_ies,
3765 beacon->proberesp_ies_len);
3767 brcmf_err("Set Probe Resp IE Failed\n");
3769 brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
3775 brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
3776 struct cfg80211_ap_settings *settings)
3779 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
3780 struct brcmf_if *ifp = netdev_priv(ndev);
3781 const struct brcmf_tlv *ssid_ie;
3782 struct brcmf_ssid_le ssid_le;
3784 const struct brcmf_tlv *rsn_ie;
3785 const struct brcmf_vs_tlv *wpa_ie;
3786 struct brcmf_join_params join_params;
3787 enum nl80211_iftype dev_role;
3788 struct brcmf_fil_bss_enable_le bss_enable;
3791 brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3792 settings->chandef.chan->hw_value,
3793 settings->chandef.center_freq1, settings->chandef.width,
3794 settings->beacon_interval, settings->dtim_period);
3795 brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3796 settings->ssid, settings->ssid_len, settings->auth_type,
3797 settings->inactivity_timeout);
3799 dev_role = ifp->vif->wdev.iftype;
3801 memset(&ssid_le, 0, sizeof(ssid_le));
3802 if (settings->ssid == NULL || settings->ssid_len == 0) {
3803 ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
3804 ssid_ie = brcmf_parse_tlvs(
3805 (u8 *)&settings->beacon.head[ie_offset],
3806 settings->beacon.head_len - ie_offset,
3811 memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
3812 ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
3813 brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
3815 memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
3816 ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
3819 brcmf_set_mpc(ifp, 0);
3820 brcmf_configure_arp_offload(ifp, false);
3822 /* find the RSN_IE */
3823 rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
3824 settings->beacon.tail_len, WLAN_EID_RSN);
3826 /* find the WPA_IE */
3827 wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
3828 settings->beacon.tail_len);
3830 if ((wpa_ie != NULL || rsn_ie != NULL)) {
3831 brcmf_dbg(TRACE, "WPA(2) IE is found\n");
3832 if (wpa_ie != NULL) {
3834 err = brcmf_configure_wpaie(ndev, wpa_ie, false);
3839 err = brcmf_configure_wpaie(ndev,
3840 (struct brcmf_vs_tlv *)rsn_ie, true);
3845 brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
3846 brcmf_configure_opensecurity(ifp);
3849 brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
3851 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef);
3852 err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
3854 brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec, err);
3858 if (settings->beacon_interval) {
3859 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
3860 settings->beacon_interval);
3862 brcmf_err("Beacon Interval Set Error, %d\n", err);
3866 if (settings->dtim_period) {
3867 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
3868 settings->dtim_period);
3870 brcmf_err("DTIM Interval Set Error, %d\n", err);
3875 if (dev_role == NL80211_IFTYPE_AP) {
3876 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
3878 brcmf_err("BRCMF_C_DOWN error %d\n", err);
3881 brcmf_fil_iovar_int_set(ifp, "apsta", 0);
3884 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
3886 brcmf_err("SET INFRA error %d\n", err);
3889 if (dev_role == NL80211_IFTYPE_AP) {
3890 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
3892 brcmf_err("setting AP mode failed %d\n", err);
3895 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
3897 brcmf_err("BRCMF_C_UP error (%d)\n", err);
3901 memset(&join_params, 0, sizeof(join_params));
3902 /* join parameters starts with ssid */
3903 memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
3905 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
3906 &join_params, sizeof(join_params));
3908 brcmf_err("SET SSID error (%d)\n", err);
3911 brcmf_dbg(TRACE, "AP mode configuration complete\n");
3913 err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
3916 brcmf_err("setting ssid failed %d\n", err);
3919 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
3920 bss_enable.enable = cpu_to_le32(1);
3921 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
3922 sizeof(bss_enable));
3924 brcmf_err("bss_enable config failed %d\n", err);
3928 brcmf_dbg(TRACE, "GO mode configuration complete\n");
3930 clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
3931 set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
3935 brcmf_set_mpc(ifp, 1);
3936 brcmf_configure_arp_offload(ifp, true);
3941 static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
3943 struct brcmf_if *ifp = netdev_priv(ndev);
3945 struct brcmf_fil_bss_enable_le bss_enable;
3946 struct brcmf_join_params join_params;
3948 brcmf_dbg(TRACE, "Enter\n");
3950 if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
3951 /* Due to most likely deauths outstanding we sleep */
3952 /* first to make sure they get processed by fw. */
3955 memset(&join_params, 0, sizeof(join_params));
3956 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
3957 &join_params, sizeof(join_params));
3959 brcmf_err("SET SSID error (%d)\n", err);
3960 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
3962 brcmf_err("BRCMF_C_UP error %d\n", err);
3963 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
3965 brcmf_err("setting AP mode failed %d\n", err);
3966 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
3968 brcmf_err("setting INFRA mode failed %d\n", err);
3970 bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
3971 bss_enable.enable = cpu_to_le32(0);
3972 err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
3973 sizeof(bss_enable));
3975 brcmf_err("bss_enable config failed %d\n", err);
3977 brcmf_set_mpc(ifp, 1);
3978 brcmf_configure_arp_offload(ifp, true);
3979 set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
3980 clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
3986 brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
3987 struct cfg80211_beacon_data *info)
3989 struct brcmf_if *ifp = netdev_priv(ndev);
3992 brcmf_dbg(TRACE, "Enter\n");
3994 err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
4000 brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
4003 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4004 struct brcmf_scb_val_le scbval;
4005 struct brcmf_if *ifp = netdev_priv(ndev);
4011 brcmf_dbg(TRACE, "Enter %pM\n", mac);
4013 if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
4014 ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
4015 if (!check_vif_up(ifp->vif))
4018 memcpy(&scbval.ea, mac, ETH_ALEN);
4019 scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING);
4020 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
4021 &scbval, sizeof(scbval));
4023 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
4025 brcmf_dbg(TRACE, "Exit\n");
4031 brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
4032 struct wireless_dev *wdev,
4033 u16 frame_type, bool reg)
4035 struct brcmf_cfg80211_vif *vif;
4038 brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
4040 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
4041 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4043 vif->mgmt_rx_reg |= BIT(mgmt_type);
4045 vif->mgmt_rx_reg &= ~BIT(mgmt_type);
4050 brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
4051 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
4053 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4054 struct ieee80211_channel *chan = params->chan;
4055 const u8 *buf = params->buf;
4056 size_t len = params->len;
4057 const struct ieee80211_mgmt *mgmt;
4058 struct brcmf_cfg80211_vif *vif;
4062 struct brcmf_fil_action_frame_le *action_frame;
4063 struct brcmf_fil_af_params_le *af_params;
4068 brcmf_dbg(TRACE, "Enter\n");
4072 mgmt = (const struct ieee80211_mgmt *)buf;
4074 if (!ieee80211_is_mgmt(mgmt->frame_control)) {
4075 brcmf_err("Driver only allows MGMT packet type\n");
4079 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4081 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
4082 /* Right now the only reason to get a probe response */
4083 /* is for p2p listen response or for p2p GO from */
4084 /* wpa_supplicant. Unfortunately the probe is send */
4085 /* on primary ndev, while dongle wants it on the p2p */
4086 /* vif. Since this is only reason for a probe */
4087 /* response to be sent, the vif is taken from cfg. */
4088 /* If ever desired to send proberesp for non p2p */
4089 /* response then data should be checked for */
4090 /* "DIRECT-". Note in future supplicant will take */
4091 /* dedicated p2p wdev to do this and then this 'hack'*/
4092 /* is not needed anymore. */
4093 ie_offset = DOT11_MGMT_HDR_LEN +
4094 DOT11_BCN_PRB_FIXED_LEN;
4095 ie_len = len - ie_offset;
4096 if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
4097 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4098 err = brcmf_vif_set_mgmt_ie(vif,
4099 BRCMF_VNDR_IE_PRBRSP_FLAG,
4102 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
4104 } else if (ieee80211_is_action(mgmt->frame_control)) {
4105 af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
4106 if (af_params == NULL) {
4107 brcmf_err("unable to allocate frame\n");
4111 action_frame = &af_params->action_frame;
4112 /* Add the packet Id */
4113 action_frame->packet_id = cpu_to_le32(*cookie);
4115 memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
4116 memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
4117 /* Add the length exepted for 802.11 header */
4118 action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
4119 /* Add the channel. Use the one specified as parameter if any or
4120 * the current one (got from the firmware) otherwise
4123 freq = chan->center_freq;
4125 brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
4127 chan_nr = ieee80211_frequency_to_channel(freq);
4128 af_params->channel = cpu_to_le32(chan_nr);
4130 memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
4131 le16_to_cpu(action_frame->len));
4133 brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
4134 *cookie, le16_to_cpu(action_frame->len), freq);
4136 ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
4139 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
4143 brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
4144 brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
4153 brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
4154 struct wireless_dev *wdev,
4157 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4158 struct brcmf_cfg80211_vif *vif;
4161 brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
4163 vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
4165 brcmf_err("No p2p device available for probe response\n");
4169 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
4174 static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
4175 struct wireless_dev *wdev,
4176 enum nl80211_crit_proto_id proto,
4179 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4180 struct brcmf_cfg80211_vif *vif;
4182 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4184 /* only DHCP support for now */
4185 if (proto != NL80211_CRIT_PROTO_DHCP)
4188 /* suppress and abort scanning */
4189 set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4190 brcmf_abort_scanning(cfg);
4192 return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
4195 static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
4196 struct wireless_dev *wdev)
4198 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
4199 struct brcmf_cfg80211_vif *vif;
4201 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
4203 brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
4204 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
4208 brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
4209 const struct brcmf_event_msg *e, void *data)
4211 switch (e->reason) {
4212 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
4213 brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
4215 case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
4216 brcmf_dbg(TRACE, "TDLS Peer Connected\n");
4217 brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4219 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
4220 brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
4221 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4228 static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
4233 case NL80211_TDLS_DISCOVERY_REQ:
4234 ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
4236 case NL80211_TDLS_SETUP:
4237 ret = BRCMF_TDLS_MANUAL_EP_CREATE;
4239 case NL80211_TDLS_TEARDOWN:
4240 ret = BRCMF_TDLS_MANUAL_EP_DELETE;
4243 brcmf_err("unsupported operation: %d\n", oper);
4249 static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
4250 struct net_device *ndev, const u8 *peer,
4251 enum nl80211_tdls_operation oper)
4253 struct brcmf_if *ifp;
4254 struct brcmf_tdls_iovar_le info;
4257 ret = brcmf_convert_nl80211_tdls_oper(oper);
4261 ifp = netdev_priv(ndev);
4262 memset(&info, 0, sizeof(info));
4263 info.mode = (u8)ret;
4265 memcpy(info.ea, peer, ETH_ALEN);
4267 ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
4268 &info, sizeof(info));
4270 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
4275 static struct cfg80211_ops wl_cfg80211_ops = {
4276 .add_virtual_intf = brcmf_cfg80211_add_iface,
4277 .del_virtual_intf = brcmf_cfg80211_del_iface,
4278 .change_virtual_intf = brcmf_cfg80211_change_iface,
4279 .scan = brcmf_cfg80211_scan,
4280 .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
4281 .join_ibss = brcmf_cfg80211_join_ibss,
4282 .leave_ibss = brcmf_cfg80211_leave_ibss,
4283 .get_station = brcmf_cfg80211_get_station,
4284 .set_tx_power = brcmf_cfg80211_set_tx_power,
4285 .get_tx_power = brcmf_cfg80211_get_tx_power,
4286 .add_key = brcmf_cfg80211_add_key,
4287 .del_key = brcmf_cfg80211_del_key,
4288 .get_key = brcmf_cfg80211_get_key,
4289 .set_default_key = brcmf_cfg80211_config_default_key,
4290 .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
4291 .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
4292 .connect = brcmf_cfg80211_connect,
4293 .disconnect = brcmf_cfg80211_disconnect,
4294 .suspend = brcmf_cfg80211_suspend,
4295 .resume = brcmf_cfg80211_resume,
4296 .set_pmksa = brcmf_cfg80211_set_pmksa,
4297 .del_pmksa = brcmf_cfg80211_del_pmksa,
4298 .flush_pmksa = brcmf_cfg80211_flush_pmksa,
4299 .start_ap = brcmf_cfg80211_start_ap,
4300 .stop_ap = brcmf_cfg80211_stop_ap,
4301 .change_beacon = brcmf_cfg80211_change_beacon,
4302 .del_station = brcmf_cfg80211_del_station,
4303 .sched_scan_start = brcmf_cfg80211_sched_scan_start,
4304 .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
4305 .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
4306 .mgmt_tx = brcmf_cfg80211_mgmt_tx,
4307 .remain_on_channel = brcmf_p2p_remain_on_channel,
4308 .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
4309 .start_p2p_device = brcmf_p2p_start_device,
4310 .stop_p2p_device = brcmf_p2p_stop_device,
4311 .crit_proto_start = brcmf_cfg80211_crit_proto_start,
4312 .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
4313 .tdls_oper = brcmf_cfg80211_tdls_oper,
4316 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
4317 enum nl80211_iftype type,
4320 struct brcmf_cfg80211_vif *vif;
4322 brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
4324 vif = kzalloc(sizeof(*vif), GFP_KERNEL);
4326 return ERR_PTR(-ENOMEM);
4328 vif->wdev.wiphy = cfg->wiphy;
4329 vif->wdev.iftype = type;
4331 vif->pm_block = pm_block;
4334 brcmf_init_prof(&vif->profile);
4336 list_add_tail(&vif->list, &cfg->vif_list);
4340 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
4342 list_del(&vif->list);
4346 void brcmf_cfg80211_free_netdev(struct net_device *ndev)
4348 struct brcmf_cfg80211_vif *vif;
4349 struct brcmf_if *ifp;
4351 ifp = netdev_priv(ndev);
4354 brcmf_free_vif(vif);
4358 static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
4360 u32 event = e->event_code;
4361 u32 status = e->status;
4363 if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
4364 brcmf_dbg(CONN, "Processing set ssid\n");
4371 static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
4373 u32 event = e->event_code;
4374 u16 flags = e->flags;
4376 if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
4377 (event == BRCMF_E_DISASSOC_IND) ||
4378 ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
4379 brcmf_dbg(CONN, "Processing link down\n");
4385 static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
4386 const struct brcmf_event_msg *e)
4388 u32 event = e->event_code;
4389 u32 status = e->status;
4391 if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
4392 brcmf_dbg(CONN, "Processing Link %s & no network found\n",
4393 e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
4397 if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
4398 brcmf_dbg(CONN, "Processing connecting & no network found\n");
4405 static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
4407 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4409 kfree(conn_info->req_ie);
4410 conn_info->req_ie = NULL;
4411 conn_info->req_ie_len = 0;
4412 kfree(conn_info->resp_ie);
4413 conn_info->resp_ie = NULL;
4414 conn_info->resp_ie_len = 0;
4417 static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
4418 struct brcmf_if *ifp)
4420 struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
4421 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4426 brcmf_clear_assoc_ies(cfg);
4428 err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
4429 cfg->extra_buf, WL_ASSOC_INFO_MAX);
4431 brcmf_err("could not get assoc info (%d)\n", err);
4435 (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
4436 req_len = le32_to_cpu(assoc_info->req_len);
4437 resp_len = le32_to_cpu(assoc_info->resp_len);
4439 err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
4443 brcmf_err("could not get assoc req (%d)\n", err);
4446 conn_info->req_ie_len = req_len;
4448 kmemdup(cfg->extra_buf, conn_info->req_ie_len,
4451 conn_info->req_ie_len = 0;
4452 conn_info->req_ie = NULL;
4455 err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
4459 brcmf_err("could not get assoc resp (%d)\n", err);
4462 conn_info->resp_ie_len = resp_len;
4463 conn_info->resp_ie =
4464 kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
4467 conn_info->resp_ie_len = 0;
4468 conn_info->resp_ie = NULL;
4470 brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
4471 conn_info->req_ie_len, conn_info->resp_ie_len);
4477 brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
4478 struct net_device *ndev,
4479 const struct brcmf_event_msg *e)
4481 struct brcmf_if *ifp = netdev_priv(ndev);
4482 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
4483 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4484 struct wiphy *wiphy = cfg_to_wiphy(cfg);
4485 struct ieee80211_channel *notify_channel = NULL;
4486 struct ieee80211_supported_band *band;
4487 struct brcmf_bss_info_le *bi;
4488 struct brcmu_chan ch;
4493 brcmf_dbg(TRACE, "Enter\n");
4495 brcmf_get_assoc_ies(cfg, ifp);
4496 memcpy(profile->bssid, e->addr, ETH_ALEN);
4497 brcmf_update_bss_info(cfg, ifp);
4499 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
4505 /* data sent to dongle has to be little endian */
4506 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
4507 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
4508 buf, WL_BSS_INFO_MAX);
4513 bi = (struct brcmf_bss_info_le *)(buf + 4);
4514 ch.chspec = le16_to_cpu(bi->chanspec);
4515 cfg->d11inf.decchspec(&ch);
4517 if (ch.band == BRCMU_CHAN_BAND_2G)
4518 band = wiphy->bands[IEEE80211_BAND_2GHZ];
4520 band = wiphy->bands[IEEE80211_BAND_5GHZ];
4522 freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
4523 notify_channel = ieee80211_get_channel(wiphy, freq);
4527 cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
4528 conn_info->req_ie, conn_info->req_ie_len,
4529 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
4530 brcmf_dbg(CONN, "Report roaming result\n");
4532 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
4533 brcmf_dbg(TRACE, "Exit\n");
4538 brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
4539 struct net_device *ndev, const struct brcmf_event_msg *e,
4542 struct brcmf_if *ifp = netdev_priv(ndev);
4543 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
4544 struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
4546 brcmf_dbg(TRACE, "Enter\n");
4548 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4549 &ifp->vif->sme_state)) {
4551 brcmf_get_assoc_ies(cfg, ifp);
4552 memcpy(profile->bssid, e->addr, ETH_ALEN);
4553 brcmf_update_bss_info(cfg, ifp);
4554 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4555 &ifp->vif->sme_state);
4557 cfg80211_connect_result(ndev,
4558 (u8 *)profile->bssid,
4560 conn_info->req_ie_len,
4562 conn_info->resp_ie_len,
4563 completed ? WLAN_STATUS_SUCCESS :
4564 WLAN_STATUS_AUTH_TIMEOUT,
4566 brcmf_dbg(CONN, "Report connect result - connection %s\n",
4567 completed ? "succeeded" : "failed");
4569 brcmf_dbg(TRACE, "Exit\n");
4574 brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
4575 struct net_device *ndev,
4576 const struct brcmf_event_msg *e, void *data)
4578 static int generation;
4579 u32 event = e->event_code;
4580 u32 reason = e->reason;
4581 struct station_info sinfo;
4583 brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
4584 if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
4585 ndev != cfg_to_ndev(cfg)) {
4586 brcmf_dbg(CONN, "AP mode link down\n");
4587 complete(&cfg->vif_disabled);
4591 if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
4592 (reason == BRCMF_E_STATUS_SUCCESS)) {
4593 memset(&sinfo, 0, sizeof(sinfo));
4594 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
4596 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
4599 sinfo.assoc_req_ies = data;
4600 sinfo.assoc_req_ies_len = e->datalen;
4602 sinfo.generation = generation;
4603 cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
4604 } else if ((event == BRCMF_E_DISASSOC_IND) ||
4605 (event == BRCMF_E_DEAUTH_IND) ||
4606 (event == BRCMF_E_DEAUTH)) {
4607 cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
4613 brcmf_notify_connect_status(struct brcmf_if *ifp,
4614 const struct brcmf_event_msg *e, void *data)
4616 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4617 struct net_device *ndev = ifp->ndev;
4618 struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
4619 struct ieee80211_channel *chan;
4622 if ((e->event_code == BRCMF_E_DEAUTH) ||
4623 (e->event_code == BRCMF_E_DEAUTH_IND) ||
4624 (e->event_code == BRCMF_E_DISASSOC_IND) ||
4625 ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
4626 brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
4629 if (brcmf_is_apmode(ifp->vif)) {
4630 err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
4631 } else if (brcmf_is_linkup(e)) {
4632 brcmf_dbg(CONN, "Linkup\n");
4633 if (brcmf_is_ibssmode(ifp->vif)) {
4634 chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
4635 memcpy(profile->bssid, e->addr, ETH_ALEN);
4636 wl_inform_ibss(cfg, ndev, e->addr);
4637 cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
4638 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4639 &ifp->vif->sme_state);
4640 set_bit(BRCMF_VIF_STATUS_CONNECTED,
4641 &ifp->vif->sme_state);
4643 brcmf_bss_connect_done(cfg, ndev, e, true);
4644 } else if (brcmf_is_linkdown(e)) {
4645 brcmf_dbg(CONN, "Linkdown\n");
4646 if (!brcmf_is_ibssmode(ifp->vif)) {
4647 brcmf_bss_connect_done(cfg, ndev, e, false);
4649 brcmf_link_down(ifp->vif);
4650 brcmf_init_prof(ndev_to_prof(ndev));
4651 if (ndev != cfg_to_ndev(cfg))
4652 complete(&cfg->vif_disabled);
4653 } else if (brcmf_is_nonetwork(cfg, e)) {
4654 if (brcmf_is_ibssmode(ifp->vif))
4655 clear_bit(BRCMF_VIF_STATUS_CONNECTING,
4656 &ifp->vif->sme_state);
4658 brcmf_bss_connect_done(cfg, ndev, e, false);
4665 brcmf_notify_roaming_status(struct brcmf_if *ifp,
4666 const struct brcmf_event_msg *e, void *data)
4668 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4669 u32 event = e->event_code;
4670 u32 status = e->status;
4672 if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
4673 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
4674 brcmf_bss_roaming_done(cfg, ifp->ndev, e);
4676 brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
4683 brcmf_notify_mic_status(struct brcmf_if *ifp,
4684 const struct brcmf_event_msg *e, void *data)
4686 u16 flags = e->flags;
4687 enum nl80211_key_type key_type;
4689 if (flags & BRCMF_EVENT_MSG_GROUP)
4690 key_type = NL80211_KEYTYPE_GROUP;
4692 key_type = NL80211_KEYTYPE_PAIRWISE;
4694 cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
4700 static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
4701 const struct brcmf_event_msg *e, void *data)
4703 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
4704 struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
4705 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
4706 struct brcmf_cfg80211_vif *vif;
4708 brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4709 ifevent->action, ifevent->flags, ifevent->ifidx,
4712 mutex_lock(&event->vif_event_lock);
4713 event->action = ifevent->action;
4716 switch (ifevent->action) {
4717 case BRCMF_E_IF_ADD:
4718 /* waiting process may have timed out */
4719 if (!cfg->vif_event.vif) {
4720 mutex_unlock(&event->vif_event_lock);
4727 vif->wdev.netdev = ifp->ndev;
4728 ifp->ndev->ieee80211_ptr = &vif->wdev;
4729 SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
4731 mutex_unlock(&event->vif_event_lock);
4732 wake_up(&event->vif_wq);
4735 case BRCMF_E_IF_DEL:
4736 mutex_unlock(&event->vif_event_lock);
4737 /* event may not be upon user request */
4738 if (brcmf_cfg80211_vif_event_armed(cfg))
4739 wake_up(&event->vif_wq);
4742 case BRCMF_E_IF_CHANGE:
4743 mutex_unlock(&event->vif_event_lock);
4744 wake_up(&event->vif_wq);
4748 mutex_unlock(&event->vif_event_lock);
4754 static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
4756 conf->frag_threshold = (u32)-1;
4757 conf->rts_threshold = (u32)-1;
4758 conf->retry_short = (u32)-1;
4759 conf->retry_long = (u32)-1;
4760 conf->tx_power = -1;
4763 static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
4765 brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
4766 brcmf_notify_connect_status);
4767 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
4768 brcmf_notify_connect_status);
4769 brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
4770 brcmf_notify_connect_status);
4771 brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
4772 brcmf_notify_connect_status);
4773 brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
4774 brcmf_notify_connect_status);
4775 brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
4776 brcmf_notify_connect_status);
4777 brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
4778 brcmf_notify_roaming_status);
4779 brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
4780 brcmf_notify_mic_status);
4781 brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
4782 brcmf_notify_connect_status);
4783 brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
4784 brcmf_notify_sched_scan_results);
4785 brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
4786 brcmf_notify_vif_event);
4787 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
4788 brcmf_p2p_notify_rx_mgmt_p2p_probereq);
4789 brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
4790 brcmf_p2p_notify_listen_complete);
4791 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
4792 brcmf_p2p_notify_action_frame_rx);
4793 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
4794 brcmf_p2p_notify_action_tx_complete);
4795 brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
4796 brcmf_p2p_notify_action_tx_complete);
4799 static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
4803 kfree(cfg->escan_ioctl_buf);
4804 cfg->escan_ioctl_buf = NULL;
4805 kfree(cfg->extra_buf);
4806 cfg->extra_buf = NULL;
4807 kfree(cfg->pmk_list);
4808 cfg->pmk_list = NULL;
4811 static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
4813 cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
4815 goto init_priv_mem_out;
4816 cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
4817 if (!cfg->escan_ioctl_buf)
4818 goto init_priv_mem_out;
4819 cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
4820 if (!cfg->extra_buf)
4821 goto init_priv_mem_out;
4822 cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL);
4824 goto init_priv_mem_out;
4829 brcmf_deinit_priv_mem(cfg);
4834 static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
4838 cfg->scan_request = NULL;
4839 cfg->pwr_save = true;
4840 cfg->active_scan = true; /* we do active scan per default */
4841 cfg->dongle_up = false; /* dongle is not up yet */
4842 err = brcmf_init_priv_mem(cfg);
4845 brcmf_register_event_handlers(cfg);
4846 mutex_init(&cfg->usr_sync);
4847 brcmf_init_escan(cfg);
4848 brcmf_init_conf(cfg->conf);
4849 init_completion(&cfg->vif_disabled);
4853 static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
4855 cfg->dongle_up = false; /* dongle down */
4856 brcmf_abort_scanning(cfg);
4857 brcmf_deinit_priv_mem(cfg);
4860 static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
4862 init_waitqueue_head(&event->vif_wq);
4863 mutex_init(&event->vif_event_lock);
4867 brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout)
4870 __le32 roamtrigger[2];
4871 __le32 roam_delta[2];
4874 * Setup timeout if Beacons are lost and roam is
4875 * off to report link down
4877 if (brcmf_roamoff) {
4878 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
4880 brcmf_err("bcn_timeout error (%d)\n", err);
4881 goto dongle_rom_out;
4886 * Enable/Disable built-in roaming to allow supplicant
4887 * to take care of roaming
4889 brcmf_dbg(INFO, "Internal Roaming = %s\n",
4890 brcmf_roamoff ? "Off" : "On");
4891 err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff));
4893 brcmf_err("roam_off error (%d)\n", err);
4894 goto dongle_rom_out;
4897 roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
4898 roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
4899 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
4900 (void *)roamtrigger, sizeof(roamtrigger));
4902 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
4903 goto dongle_rom_out;
4906 roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
4907 roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
4908 err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
4909 (void *)roam_delta, sizeof(roam_delta));
4911 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
4912 goto dongle_rom_out;
4920 brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time,
4921 s32 scan_unassoc_time, s32 scan_passive_time)
4925 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
4928 if (err == -EOPNOTSUPP)
4929 brcmf_dbg(INFO, "Scan assoc time is not supported\n");
4931 brcmf_err("Scan assoc time error (%d)\n", err);
4932 goto dongle_scantime_out;
4934 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
4937 if (err == -EOPNOTSUPP)
4938 brcmf_dbg(INFO, "Scan unassoc time is not supported\n");
4940 brcmf_err("Scan unassoc time error (%d)\n", err);
4941 goto dongle_scantime_out;
4944 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
4947 if (err == -EOPNOTSUPP)
4948 brcmf_dbg(INFO, "Scan passive time is not supported\n");
4950 brcmf_err("Scan passive time error (%d)\n", err);
4951 goto dongle_scantime_out;
4954 dongle_scantime_out:
4958 /* Filter the list of channels received from firmware counting only
4959 * the 20MHz channels. The wiphy band data only needs those which get
4960 * flagged to indicate if they can take part in higher bandwidth.
4962 static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
4963 struct brcmf_chanspec_list *chlist,
4966 u32 total = le32_to_cpu(chlist->count);
4967 struct brcmu_chan ch;
4970 for (i = 0; i < total; i++) {
4971 ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
4972 cfg->d11inf.decchspec(&ch);
4974 /* Firmware gives a ordered list. We skip non-20MHz
4975 * channels is 2G. For 5G we can abort upon reaching
4976 * a non-20MHz channel in the list.
4978 if (ch.bw != BRCMU_CHAN_BW_20) {
4979 if (ch.band == BRCMU_CHAN_BAND_5G)
4985 if (ch.band == BRCMU_CHAN_BAND_2G)
4987 else if (ch.band == BRCMU_CHAN_BAND_5G)
4992 static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
4993 struct brcmu_chan *ch)
4997 ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
4998 if (ch->sb == BRCMU_CHAN_SB_U) {
4999 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5000 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5001 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
5003 /* It should be one of
5004 * IEEE80211_CHAN_NO_HT40 or
5005 * IEEE80211_CHAN_NO_HT40PLUS
5007 channel->flags &= ~IEEE80211_CHAN_NO_HT40;
5008 if (ht40_flag == IEEE80211_CHAN_NO_HT40)
5009 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
5013 static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
5016 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5017 struct ieee80211_supported_band *band;
5018 struct ieee80211_channel *channel;
5019 struct wiphy *wiphy;
5020 struct brcmf_chanspec_list *list;
5021 struct brcmu_chan ch;
5027 u32 chcnt[2] = { 0, 0 };
5030 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5035 list = (struct brcmf_chanspec_list *)pbuf;
5037 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5040 brcmf_err("get chanspecs error (%d)\n", err);
5044 brcmf_count_20mhz_channels(cfg, list, chcnt);
5045 wiphy = cfg_to_wiphy(cfg);
5047 band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
5053 band->channels = kcalloc(chcnt[0], sizeof(*channel),
5055 if (band->channels == NULL) {
5060 band->n_channels = 0;
5061 wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5064 band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a),
5070 band->channels = kcalloc(chcnt[1], sizeof(*channel),
5072 if (band->channels == NULL) {
5077 band->n_channels = 0;
5078 wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5081 total = le32_to_cpu(list->count);
5082 for (i = 0; i < total; i++) {
5083 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5084 cfg->d11inf.decchspec(&ch);
5086 if (ch.band == BRCMU_CHAN_BAND_2G) {
5087 band = wiphy->bands[IEEE80211_BAND_2GHZ];
5088 } else if (ch.band == BRCMU_CHAN_BAND_5G) {
5089 band = wiphy->bands[IEEE80211_BAND_5GHZ];
5091 brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
5094 if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
5095 ch.bw == BRCMU_CHAN_BW_40)
5097 if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
5098 ch.bw == BRCMU_CHAN_BW_80)
5101 channel = band->channels;
5102 index = band->n_channels;
5103 for (j = 0; j < band->n_channels; j++) {
5104 if (channel[j].hw_value == ch.chnum) {
5109 channel[index].center_freq =
5110 ieee80211_channel_to_frequency(ch.chnum, band->band);
5111 channel[index].hw_value = ch.chnum;
5113 /* assuming the chanspecs order is HT20,
5114 * HT40 upper, HT40 lower, and VHT80.
5116 if (ch.bw == BRCMU_CHAN_BW_80) {
5117 channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
5118 } else if (ch.bw == BRCMU_CHAN_BW_40) {
5119 brcmf_update_bw40_channel_flag(&channel[index], &ch);
5121 /* disable other bandwidths for now as mentioned
5122 * order assure they are enabled for subsequent
5125 channel[index].flags = IEEE80211_CHAN_NO_HT40 |
5126 IEEE80211_CHAN_NO_80MHZ;
5127 ch.bw = BRCMU_CHAN_BW_20;
5128 cfg->d11inf.encchspec(&ch);
5129 chaninfo = ch.chspec;
5130 err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
5133 if (chaninfo & WL_CHAN_RADAR)
5134 channel[index].flags |=
5135 (IEEE80211_CHAN_RADAR |
5136 IEEE80211_CHAN_NO_IR);
5137 if (chaninfo & WL_CHAN_PASSIVE)
5138 channel[index].flags |=
5139 IEEE80211_CHAN_NO_IR;
5142 if (index == band->n_channels)
5149 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5150 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5151 wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
5157 static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
5159 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5160 struct ieee80211_supported_band *band;
5161 struct brcmf_fil_bwcap_le band_bwcap;
5162 struct brcmf_chanspec_list *list;
5166 struct brcmu_chan ch;
5170 /* verify support for bw_cap command */
5172 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
5175 /* only set 2G bandwidth using bw_cap command */
5176 band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
5177 band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
5178 err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
5179 sizeof(band_bwcap));
5181 brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
5182 val = WLC_N_BW_40ALL;
5183 err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
5187 /* update channel info in 2G band */
5188 pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
5193 ch.band = BRCMU_CHAN_BAND_2G;
5194 ch.bw = BRCMU_CHAN_BW_40;
5195 ch.sb = BRCMU_CHAN_SB_NONE;
5197 cfg->d11inf.encchspec(&ch);
5199 /* pass encoded chanspec in query */
5200 *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
5202 err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
5205 brcmf_err("get chanspecs error (%d)\n", err);
5210 band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
5211 list = (struct brcmf_chanspec_list *)pbuf;
5212 num_chan = le32_to_cpu(list->count);
5213 for (i = 0; i < num_chan; i++) {
5214 ch.chspec = (u16)le32_to_cpu(list->element[i]);
5215 cfg->d11inf.decchspec(&ch);
5216 if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
5218 if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
5220 for (j = 0; j < band->n_channels; j++) {
5221 if (band->channels[j].hw_value == ch.chnum)
5224 if (WARN_ON(j == band->n_channels))
5227 brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
5234 static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
5236 u32 band, mimo_bwcap;
5240 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5242 bw_cap[IEEE80211_BAND_2GHZ] = band;
5244 err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
5246 bw_cap[IEEE80211_BAND_5GHZ] = band;
5252 brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
5254 err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
5256 /* assume 20MHz if firmware does not give a clue */
5257 mimo_bwcap = WLC_N_BW_20ALL;
5259 switch (mimo_bwcap) {
5260 case WLC_N_BW_40ALL:
5261 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
5263 case WLC_N_BW_20IN2G_40IN5G:
5264 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
5266 case WLC_N_BW_20ALL:
5267 bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
5268 bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
5271 brcmf_err("invalid mimo_bw_cap value\n");
5275 static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
5276 u32 bw_cap[2], u32 nchain)
5278 band->ht_cap.ht_supported = true;
5279 if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
5280 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5281 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5283 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5284 band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5285 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5286 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
5287 memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
5288 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5291 static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
5296 for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
5297 mcs_map = (mcs_map << 2) | supp;
5299 return cpu_to_le16(mcs_map);
5302 static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
5303 u32 bw_cap[2], u32 nchain)
5307 /* not allowed in 2.4G band */
5308 if (band->band == IEEE80211_BAND_2GHZ)
5311 band->vht_cap.vht_supported = true;
5312 /* 80MHz is mandatory */
5313 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
5314 if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
5315 band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
5316 band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
5318 /* all support 256-QAM */
5319 mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
5320 band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
5321 band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
5324 static int brcmf_setup_wiphybands(struct wiphy *wiphy)
5326 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
5327 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
5330 u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
5335 struct ieee80211_supported_band *band;
5337 (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
5338 err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
5340 brcmf_err("nmode error (%d)\n", err);
5342 brcmf_get_bwcap(ifp, bw_cap);
5344 brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5345 nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
5346 bw_cap[IEEE80211_BAND_5GHZ]);
5348 err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
5350 brcmf_err("rxchain error (%d)\n", err);
5353 for (nchain = 0; rxchain; nchain++)
5354 rxchain = rxchain & (rxchain - 1);
5356 brcmf_dbg(INFO, "nchain=%d\n", nchain);
5358 err = brcmf_construct_chaninfo(cfg, bw_cap);
5360 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
5364 wiphy = cfg_to_wiphy(cfg);
5365 for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
5366 band = wiphy->bands[i];
5371 brcmf_update_ht_cap(band, bw_cap, nchain);
5373 brcmf_update_vht_cap(band, bw_cap, nchain);
5379 static const struct ieee80211_iface_limit brcmf_iface_limits[] = {
5382 .types = BIT(NL80211_IFTYPE_STATION) |
5383 BIT(NL80211_IFTYPE_ADHOC) |
5384 BIT(NL80211_IFTYPE_AP)
5388 .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
5389 BIT(NL80211_IFTYPE_P2P_GO)
5393 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5396 static struct ieee80211_iface_combination brcmf_iface_combos[] = {
5398 .max_interfaces = BRCMF_IFACE_MAX_CNT,
5399 .num_different_channels = 1,
5400 .n_limits = ARRAY_SIZE(brcmf_iface_limits),
5401 .limits = brcmf_iface_limits
5405 static const struct ieee80211_txrx_stypes
5406 brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
5407 [NL80211_IFTYPE_STATION] = {
5409 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5410 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5412 [NL80211_IFTYPE_P2P_CLIENT] = {
5414 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5415 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5417 [NL80211_IFTYPE_P2P_GO] = {
5419 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5420 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5421 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5422 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5423 BIT(IEEE80211_STYPE_AUTH >> 4) |
5424 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5425 BIT(IEEE80211_STYPE_ACTION >> 4)
5427 [NL80211_IFTYPE_P2P_DEVICE] = {
5429 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5430 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
5434 static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
5436 /* scheduled scan settings */
5437 wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
5438 wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
5439 wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5440 wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
5445 static const struct wiphy_wowlan_support brcmf_wowlan_support = {
5446 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
5450 static void brcmf_wiphy_wowl_params(struct wiphy *wiphy)
5454 wiphy->wowlan = &brcmf_wowlan_support;
5458 static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
5460 struct ieee80211_iface_combination ifc_combo;
5461 wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
5462 wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
5463 wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
5464 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
5465 BIT(NL80211_IFTYPE_ADHOC) |
5466 BIT(NL80211_IFTYPE_AP) |
5467 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5468 BIT(NL80211_IFTYPE_P2P_GO) |
5469 BIT(NL80211_IFTYPE_P2P_DEVICE);
5470 /* need VSDB firmware feature for concurrent channels */
5471 ifc_combo = brcmf_iface_combos[0];
5472 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
5473 ifc_combo.num_different_channels = 2;
5474 wiphy->iface_combinations = kmemdup(&ifc_combo,
5477 wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos);
5478 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
5479 wiphy->cipher_suites = __wl_cipher_suites;
5480 wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
5481 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
5482 WIPHY_FLAG_OFFCHAN_TX |
5483 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5484 WIPHY_FLAG_SUPPORTS_TDLS;
5486 wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
5487 wiphy->mgmt_stypes = brcmf_txrx_stypes;
5488 wiphy->max_remain_on_channel_duration = 5000;
5489 brcmf_wiphy_pno_params(wiphy);
5491 /* vendor commands/events support */
5492 wiphy->vendor_commands = brcmf_vendor_cmds;
5493 wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
5495 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
5496 brcmf_wiphy_wowl_params(wiphy);
5498 return brcmf_setup_wiphybands(wiphy);
5501 static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
5503 struct net_device *ndev;
5504 struct wireless_dev *wdev;
5505 struct brcmf_if *ifp;
5512 ndev = cfg_to_ndev(cfg);
5513 wdev = ndev->ieee80211_ptr;
5514 ifp = netdev_priv(ndev);
5516 /* make sure RF is ready for work */
5517 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
5519 brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME,
5520 WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
5522 power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
5523 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
5525 goto default_conf_out;
5526 brcmf_dbg(INFO, "power save set to %s\n",
5527 (power_mode ? "enabled" : "disabled"));
5529 err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT);
5531 goto default_conf_out;
5532 err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
5535 goto default_conf_out;
5537 brcmf_configure_arp_offload(ifp, true);
5539 cfg->dongle_up = true;
5546 static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
5548 set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
5550 return brcmf_config_dongle(ifp->drvr->config);
5553 static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
5555 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5558 * While going down, if associated with AP disassociate
5559 * from AP to save power
5561 if (check_vif_up(ifp->vif)) {
5562 brcmf_link_down(ifp->vif);
5564 /* Make sure WPA_Supplicant receives all the event
5565 generated due to DISASSOC call to the fw to keep
5566 the state fw and WPA_Supplicant state consistent
5571 brcmf_abort_scanning(cfg);
5572 clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
5577 s32 brcmf_cfg80211_up(struct net_device *ndev)
5579 struct brcmf_if *ifp = netdev_priv(ndev);
5580 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5583 mutex_lock(&cfg->usr_sync);
5584 err = __brcmf_cfg80211_up(ifp);
5585 mutex_unlock(&cfg->usr_sync);
5590 s32 brcmf_cfg80211_down(struct net_device *ndev)
5592 struct brcmf_if *ifp = netdev_priv(ndev);
5593 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
5596 mutex_lock(&cfg->usr_sync);
5597 err = __brcmf_cfg80211_down(ifp);
5598 mutex_unlock(&cfg->usr_sync);
5603 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
5605 struct wireless_dev *wdev = &ifp->vif->wdev;
5607 return wdev->iftype;
5610 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, unsigned long state)
5612 struct brcmf_cfg80211_vif *vif;
5614 list_for_each_entry(vif, &cfg->vif_list, list) {
5615 if (test_bit(state, &vif->sme_state))
5621 static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
5626 mutex_lock(&event->vif_event_lock);
5627 evt_action = event->action;
5628 mutex_unlock(&event->vif_event_lock);
5629 return evt_action == action;
5632 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
5633 struct brcmf_cfg80211_vif *vif)
5635 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5637 mutex_lock(&event->vif_event_lock);
5640 mutex_unlock(&event->vif_event_lock);
5643 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
5645 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5648 mutex_lock(&event->vif_event_lock);
5649 armed = event->vif != NULL;
5650 mutex_unlock(&event->vif_event_lock);
5654 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
5655 u8 action, ulong timeout)
5657 struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
5659 return wait_event_timeout(event->vif_wq,
5660 vif_event_equals(event, action), timeout);
5663 static void brcmf_free_wiphy(struct wiphy *wiphy)
5665 kfree(wiphy->iface_combinations);
5666 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5667 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
5668 kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
5670 if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
5671 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
5672 kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
5677 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
5678 struct device *busdev)
5680 struct net_device *ndev = drvr->iflist[0]->ndev;
5681 struct brcmf_cfg80211_info *cfg;
5682 struct wiphy *wiphy;
5683 struct brcmf_cfg80211_vif *vif;
5684 struct brcmf_if *ifp;
5690 brcmf_err("ndev is invalid\n");
5694 ifp = netdev_priv(ndev);
5695 wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
5697 brcmf_err("Could not allocate wiphy device\n");
5700 set_wiphy_dev(wiphy, busdev);
5702 cfg = wiphy_priv(wiphy);
5705 init_vif_event(&cfg->vif_event);
5706 INIT_LIST_HEAD(&cfg->vif_list);
5708 vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
5713 vif->wdev.netdev = ndev;
5714 ndev->ieee80211_ptr = &vif->wdev;
5715 SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
5717 err = wl_init_priv(cfg);
5719 brcmf_err("Failed to init iwm_priv (%d)\n", err);
5720 brcmf_free_vif(vif);
5725 /* determine d11 io type before wiphy setup */
5726 err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
5728 brcmf_err("Failed to get D11 version (%d)\n", err);
5731 cfg->d11inf.io_type = (u8)io_type;
5732 brcmu_d11_attach(&cfg->d11inf);
5734 err = brcmf_setup_wiphy(wiphy, ifp);
5738 brcmf_dbg(INFO, "Registering custom regulatory\n");
5739 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
5740 wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
5742 /* firmware defaults to 40MHz disabled in 2G band. We signal
5743 * cfg80211 here that we do and have it decide we can enable
5744 * it. But first check if device does support 2G operation.
5746 if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
5747 cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
5748 *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5750 err = wiphy_register(wiphy);
5752 brcmf_err("Could not register wiphy device (%d)\n", err);
5756 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
5757 * setup 40MHz in 2GHz band and enable OBSS scanning.
5759 if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
5760 err = brcmf_enable_bw40_2g(cfg);
5762 err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
5763 BRCMF_OBSS_COEX_AUTO);
5765 *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5768 err = brcmf_p2p_attach(cfg);
5770 brcmf_err("P2P initilisation failed (%d)\n", err);
5771 goto wiphy_unreg_out;
5773 err = brcmf_btcoex_attach(cfg);
5775 brcmf_err("BT-coex initialisation failed (%d)\n", err);
5776 brcmf_p2p_detach(&cfg->p2p);
5777 goto wiphy_unreg_out;
5780 err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
5782 brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
5783 wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
5785 brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
5786 brcmf_notify_tdls_peer_event);
5792 wiphy_unregister(cfg->wiphy);
5794 wl_deinit_priv(cfg);
5795 brcmf_free_vif(vif);
5797 brcmf_free_wiphy(wiphy);
5801 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
5806 WARN_ON(!list_empty(&cfg->vif_list));
5807 wiphy_unregister(cfg->wiphy);
5808 brcmf_btcoex_detach(cfg);
5809 brcmf_p2p_detach(&cfg->p2p);
5810 wl_deinit_priv(cfg);
5811 brcmf_free_wiphy(cfg->wiphy);