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"
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_config_wowl_pattern(struct brcmf_if
*ifp
, u8 cmd
[4],
2783 u8
*pattern
, u32 patternsize
, u8
*mask
,
2786 struct brcmf_fil_wowl_pattern_le
*filter
;
2793 masksize
= (patternsize
+ 7) / 8;
2794 patternoffset
= sizeof(*filter
) - sizeof(filter
->cmd
) + masksize
;
2796 bufsize
= sizeof(*filter
) + patternsize
+ masksize
;
2797 buf
= kzalloc(bufsize
, GFP_KERNEL
);
2800 filter
= (struct brcmf_fil_wowl_pattern_le
*)buf
;
2802 memcpy(filter
->cmd
, cmd
, 4);
2803 filter
->masksize
= cpu_to_le32(masksize
);
2804 filter
->offset
= cpu_to_le32(packet_offset
);
2805 filter
->patternoffset
= cpu_to_le32(patternoffset
);
2806 filter
->patternsize
= cpu_to_le32(patternsize
);
2807 filter
->type
= cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP
);
2809 if ((mask
) && (masksize
))
2810 memcpy(buf
+ sizeof(*filter
), mask
, masksize
);
2811 if ((pattern
) && (patternsize
))
2812 memcpy(buf
+ sizeof(*filter
) + masksize
, pattern
, patternsize
);
2814 ret
= brcmf_fil_iovar_data_set(ifp
, "wowl_pattern", buf
, bufsize
);
2820 static s32
brcmf_cfg80211_resume(struct wiphy
*wiphy
)
2822 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2823 struct net_device
*ndev
= cfg_to_ndev(cfg
);
2824 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2826 brcmf_dbg(TRACE
, "Enter\n");
2828 if (cfg
->wowl_enabled
) {
2829 brcmf_configure_arp_offload(ifp
, true);
2830 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
,
2831 cfg
->pre_wowl_pmmode
);
2832 brcmf_fil_iovar_int_set(ifp
, "wowl_clear", 0);
2833 brcmf_config_wowl_pattern(ifp
, "clr", NULL
, 0, NULL
, 0);
2834 cfg
->wowl_enabled
= false;
2839 static void brcmf_configure_wowl(struct brcmf_cfg80211_info
*cfg
,
2840 struct brcmf_if
*ifp
,
2841 struct cfg80211_wowlan
*wowl
)
2846 brcmf_dbg(TRACE
, "Suspend, wowl config.\n");
2848 brcmf_configure_arp_offload(ifp
, false);
2849 brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_PM
, &cfg
->pre_wowl_pmmode
);
2850 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, PM_MAX
);
2853 if (wowl
->disconnect
)
2854 wowl_config
= BRCMF_WOWL_DIS
| BRCMF_WOWL_BCN
| BRCMF_WOWL_RETR
;
2855 if (wowl
->magic_pkt
)
2856 wowl_config
|= BRCMF_WOWL_MAGIC
;
2857 if ((wowl
->patterns
) && (wowl
->n_patterns
)) {
2858 wowl_config
|= BRCMF_WOWL_NET
;
2859 for (i
= 0; i
< wowl
->n_patterns
; i
++) {
2860 brcmf_config_wowl_pattern(ifp
, "add",
2861 (u8
*)wowl
->patterns
[i
].pattern
,
2862 wowl
->patterns
[i
].pattern_len
,
2863 (u8
*)wowl
->patterns
[i
].mask
,
2864 wowl
->patterns
[i
].pkt_offset
);
2867 brcmf_fil_iovar_int_set(ifp
, "wowl", wowl_config
);
2868 brcmf_fil_iovar_int_set(ifp
, "wowl_activate", 1);
2869 brcmf_bus_wowl_config(cfg
->pub
->bus_if
, true);
2870 cfg
->wowl_enabled
= true;
2873 static s32
brcmf_cfg80211_suspend(struct wiphy
*wiphy
,
2874 struct cfg80211_wowlan
*wowl
)
2876 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2877 struct net_device
*ndev
= cfg_to_ndev(cfg
);
2878 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2879 struct brcmf_cfg80211_vif
*vif
;
2881 brcmf_dbg(TRACE
, "Enter\n");
2883 /* if the primary net_device is not READY there is nothing
2884 * we can do but pray resume goes smoothly.
2886 if (!check_vif_up(ifp
->vif
))
2889 /* end any scanning */
2890 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
2891 brcmf_abort_scanning(cfg
);
2894 brcmf_bus_wowl_config(cfg
->pub
->bus_if
, false);
2895 list_for_each_entry(vif
, &cfg
->vif_list
, list
) {
2896 if (!test_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
))
2898 /* While going to suspend if associated with AP
2899 * disassociate from AP to save power while system is
2900 * in suspended state
2902 brcmf_link_down(vif
);
2903 /* Make sure WPA_Supplicant receives all the event
2904 * generated due to DISASSOC call to the fw to keep
2905 * the state fw and WPA_Supplicant state consistent
2910 brcmf_set_mpc(ifp
, 1);
2913 /* Configure WOWL paramaters */
2914 brcmf_configure_wowl(cfg
, ifp
, wowl
);
2918 brcmf_dbg(TRACE
, "Exit\n");
2919 /* clear any scanning activity */
2920 cfg
->scan_status
= 0;
2925 brcmf_update_pmklist(struct net_device
*ndev
,
2926 struct brcmf_cfg80211_pmk_list
*pmk_list
, s32 err
)
2931 pmkid_len
= le32_to_cpu(pmk_list
->pmkids
.npmkid
);
2933 brcmf_dbg(CONN
, "No of elements %d\n", pmkid_len
);
2934 for (i
= 0; i
< pmkid_len
; i
++) {
2935 brcmf_dbg(CONN
, "PMKID[%d]: %pM =\n", i
,
2936 &pmk_list
->pmkids
.pmkid
[i
].BSSID
);
2937 for (j
= 0; j
< WLAN_PMKID_LEN
; j
++)
2938 brcmf_dbg(CONN
, "%02x\n",
2939 pmk_list
->pmkids
.pmkid
[i
].PMKID
[j
]);
2943 brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pmkid_info",
2944 (char *)pmk_list
, sizeof(*pmk_list
));
2950 brcmf_cfg80211_set_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
2951 struct cfg80211_pmksa
*pmksa
)
2953 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2954 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2955 struct pmkid_list
*pmkids
= &cfg
->pmk_list
->pmkids
;
2960 brcmf_dbg(TRACE
, "Enter\n");
2961 if (!check_vif_up(ifp
->vif
))
2964 pmkid_len
= le32_to_cpu(pmkids
->npmkid
);
2965 for (i
= 0; i
< pmkid_len
; i
++)
2966 if (!memcmp(pmksa
->bssid
, pmkids
->pmkid
[i
].BSSID
, ETH_ALEN
))
2968 if (i
< WL_NUM_PMKIDS_MAX
) {
2969 memcpy(pmkids
->pmkid
[i
].BSSID
, pmksa
->bssid
, ETH_ALEN
);
2970 memcpy(pmkids
->pmkid
[i
].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
2971 if (i
== pmkid_len
) {
2973 pmkids
->npmkid
= cpu_to_le32(pmkid_len
);
2978 brcmf_dbg(CONN
, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2979 pmkids
->pmkid
[pmkid_len
].BSSID
);
2980 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
2981 brcmf_dbg(CONN
, "%02x\n", pmkids
->pmkid
[pmkid_len
].PMKID
[i
]);
2983 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
2985 brcmf_dbg(TRACE
, "Exit\n");
2990 brcmf_cfg80211_del_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
2991 struct cfg80211_pmksa
*pmksa
)
2993 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2994 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2995 struct pmkid_list pmkid
;
2999 brcmf_dbg(TRACE
, "Enter\n");
3000 if (!check_vif_up(ifp
->vif
))
3003 memcpy(&pmkid
.pmkid
[0].BSSID
, pmksa
->bssid
, ETH_ALEN
);
3004 memcpy(&pmkid
.pmkid
[0].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
3006 brcmf_dbg(CONN
, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3007 &pmkid
.pmkid
[0].BSSID
);
3008 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
3009 brcmf_dbg(CONN
, "%02x\n", pmkid
.pmkid
[0].PMKID
[i
]);
3011 pmkid_len
= le32_to_cpu(cfg
->pmk_list
->pmkids
.npmkid
);
3012 for (i
= 0; i
< pmkid_len
; i
++)
3014 (pmksa
->bssid
, &cfg
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3019 && (i
< pmkid_len
)) {
3020 memset(&cfg
->pmk_list
->pmkids
.pmkid
[i
], 0,
3021 sizeof(struct pmkid
));
3022 for (; i
< (pmkid_len
- 1); i
++) {
3023 memcpy(&cfg
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3024 &cfg
->pmk_list
->pmkids
.pmkid
[i
+ 1].BSSID
,
3026 memcpy(&cfg
->pmk_list
->pmkids
.pmkid
[i
].PMKID
,
3027 &cfg
->pmk_list
->pmkids
.pmkid
[i
+ 1].PMKID
,
3030 cfg
->pmk_list
->pmkids
.npmkid
= cpu_to_le32(pmkid_len
- 1);
3034 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3036 brcmf_dbg(TRACE
, "Exit\n");
3042 brcmf_cfg80211_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
)
3044 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3045 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3048 brcmf_dbg(TRACE
, "Enter\n");
3049 if (!check_vif_up(ifp
->vif
))
3052 memset(cfg
->pmk_list
, 0, sizeof(*cfg
->pmk_list
));
3053 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3055 brcmf_dbg(TRACE
, "Exit\n");
3061 * PFN result doesn't have all the info which are
3062 * required by the supplicant
3063 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3064 * via wl_inform_single_bss in the required format. Escan does require the
3065 * scan request in the form of cfg80211_scan_request. For timebeing, create
3066 * cfg80211_scan_request one out of the received PNO event.
3069 brcmf_notify_sched_scan_results(struct brcmf_if
*ifp
,
3070 const struct brcmf_event_msg
*e
, void *data
)
3072 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
3073 struct brcmf_pno_net_info_le
*netinfo
, *netinfo_start
;
3074 struct cfg80211_scan_request
*request
= NULL
;
3075 struct cfg80211_ssid
*ssid
= NULL
;
3076 struct ieee80211_channel
*channel
= NULL
;
3077 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
3079 int channel_req
= 0;
3081 struct brcmf_pno_scanresults_le
*pfn_result
;
3085 brcmf_dbg(SCAN
, "Enter\n");
3087 if (e
->event_code
== BRCMF_E_PFN_NET_LOST
) {
3088 brcmf_dbg(SCAN
, "PFN NET LOST event. Do Nothing\n");
3092 pfn_result
= (struct brcmf_pno_scanresults_le
*)data
;
3093 result_count
= le32_to_cpu(pfn_result
->count
);
3094 status
= le32_to_cpu(pfn_result
->status
);
3097 * PFN event is limited to fit 512 bytes so we may get
3098 * multiple NET_FOUND events. For now place a warning here.
3100 WARN_ON(status
!= BRCMF_PNO_SCAN_COMPLETE
);
3101 brcmf_dbg(SCAN
, "PFN NET FOUND event. count: %d\n", result_count
);
3102 if (result_count
> 0) {
3105 request
= kzalloc(sizeof(*request
), GFP_KERNEL
);
3106 ssid
= kcalloc(result_count
, sizeof(*ssid
), GFP_KERNEL
);
3107 channel
= kcalloc(result_count
, sizeof(*channel
), GFP_KERNEL
);
3108 if (!request
|| !ssid
|| !channel
) {
3113 request
->wiphy
= wiphy
;
3114 data
+= sizeof(struct brcmf_pno_scanresults_le
);
3115 netinfo_start
= (struct brcmf_pno_net_info_le
*)data
;
3117 for (i
= 0; i
< result_count
; i
++) {
3118 netinfo
= &netinfo_start
[i
];
3120 brcmf_err("Invalid netinfo ptr. index: %d\n",
3126 brcmf_dbg(SCAN
, "SSID:%s Channel:%d\n",
3127 netinfo
->SSID
, netinfo
->channel
);
3128 memcpy(ssid
[i
].ssid
, netinfo
->SSID
, netinfo
->SSID_len
);
3129 ssid
[i
].ssid_len
= netinfo
->SSID_len
;
3132 channel_req
= netinfo
->channel
;
3133 if (channel_req
<= CH_MAX_2G_CHANNEL
)
3134 band
= NL80211_BAND_2GHZ
;
3136 band
= NL80211_BAND_5GHZ
;
3137 channel
[i
].center_freq
=
3138 ieee80211_channel_to_frequency(channel_req
,
3140 channel
[i
].band
= band
;
3141 channel
[i
].flags
|= IEEE80211_CHAN_NO_HT40
;
3142 request
->channels
[i
] = &channel
[i
];
3143 request
->n_channels
++;
3146 /* assign parsed ssid array */
3147 if (request
->n_ssids
)
3148 request
->ssids
= &ssid
[0];
3150 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
3151 /* Abort any on-going scan */
3152 brcmf_abort_scanning(cfg
);
3155 set_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
3156 cfg
->escan_info
.run
= brcmf_run_escan
;
3157 err
= brcmf_do_escan(cfg
, wiphy
, ifp
, request
);
3159 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
3162 cfg
->sched_escan
= true;
3163 cfg
->scan_request
= request
;
3165 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3178 cfg80211_sched_scan_stopped(wiphy
);
3182 static int brcmf_dev_pno_clean(struct net_device
*ndev
)
3187 ret
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "pfn", 0);
3190 ret
= brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pfnclear",
3194 brcmf_err("failed code %d\n", ret
);
3199 static int brcmf_dev_pno_config(struct net_device
*ndev
)
3201 struct brcmf_pno_param_le pfn_param
;
3203 memset(&pfn_param
, 0, sizeof(pfn_param
));
3204 pfn_param
.version
= cpu_to_le32(BRCMF_PNO_VERSION
);
3206 /* set extra pno params */
3207 pfn_param
.flags
= cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT
);
3208 pfn_param
.repeat
= BRCMF_PNO_REPEAT
;
3209 pfn_param
.exp
= BRCMF_PNO_FREQ_EXPO_MAX
;
3211 /* set up pno scan fr */
3212 pfn_param
.scan_freq
= cpu_to_le32(BRCMF_PNO_TIME
);
3214 return brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pfn_set",
3215 &pfn_param
, sizeof(pfn_param
));
3219 brcmf_cfg80211_sched_scan_start(struct wiphy
*wiphy
,
3220 struct net_device
*ndev
,
3221 struct cfg80211_sched_scan_request
*request
)
3223 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3224 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
3225 struct brcmf_pno_net_param_le pfn
;
3229 brcmf_dbg(SCAN
, "Enter n_match_sets:%d n_ssids:%d\n",
3230 request
->n_match_sets
, request
->n_ssids
);
3231 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
3232 brcmf_err("Scanning already: status (%lu)\n", cfg
->scan_status
);
3235 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
)) {
3236 brcmf_err("Scanning suppressed: status (%lu)\n",
3241 if (!request
->n_ssids
|| !request
->n_match_sets
) {
3242 brcmf_dbg(SCAN
, "Invalid sched scan req!! n_ssids:%d\n",
3247 if (request
->n_ssids
> 0) {
3248 for (i
= 0; i
< request
->n_ssids
; i
++) {
3249 /* Active scan req for ssids */
3250 brcmf_dbg(SCAN
, ">>> Active scan req for ssid (%s)\n",
3251 request
->ssids
[i
].ssid
);
3254 * match_set ssids is a supert set of n_ssid list,
3255 * so we need not add these set seperately.
3260 if (request
->n_match_sets
> 0) {
3261 /* clean up everything */
3262 ret
= brcmf_dev_pno_clean(ndev
);
3264 brcmf_err("failed error=%d\n", ret
);
3269 ret
= brcmf_dev_pno_config(ndev
);
3271 brcmf_err("PNO setup failed!! ret=%d\n", ret
);
3275 /* configure each match set */
3276 for (i
= 0; i
< request
->n_match_sets
; i
++) {
3277 struct cfg80211_ssid
*ssid
;
3280 ssid
= &request
->match_sets
[i
].ssid
;
3281 ssid_len
= ssid
->ssid_len
;
3284 brcmf_err("skip broadcast ssid\n");
3287 pfn
.auth
= cpu_to_le32(WLAN_AUTH_OPEN
);
3288 pfn
.wpa_auth
= cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY
);
3289 pfn
.wsec
= cpu_to_le32(0);
3290 pfn
.infra
= cpu_to_le32(1);
3291 pfn
.flags
= cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT
);
3292 pfn
.ssid
.SSID_len
= cpu_to_le32(ssid_len
);
3293 memcpy(pfn
.ssid
.SSID
, ssid
->ssid
, ssid_len
);
3294 ret
= brcmf_fil_iovar_data_set(ifp
, "pfn_add", &pfn
,
3296 brcmf_dbg(SCAN
, ">>> PNO filter %s for ssid (%s)\n",
3297 ret
== 0 ? "set" : "failed", ssid
->ssid
);
3299 /* Enable the PNO */
3300 if (brcmf_fil_iovar_int_set(ifp
, "pfn", 1) < 0) {
3301 brcmf_err("PNO enable failed!! ret=%d\n", ret
);
3311 static int brcmf_cfg80211_sched_scan_stop(struct wiphy
*wiphy
,
3312 struct net_device
*ndev
)
3314 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3316 brcmf_dbg(SCAN
, "enter\n");
3317 brcmf_dev_pno_clean(ndev
);
3318 if (cfg
->sched_escan
)
3319 brcmf_notify_escan_complete(cfg
, netdev_priv(ndev
), true, true);
3323 static s32
brcmf_configure_opensecurity(struct brcmf_if
*ifp
)
3328 err
= brcmf_fil_bsscfg_int_set(ifp
, "auth", 0);
3330 brcmf_err("auth error %d\n", err
);
3334 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", 0);
3336 brcmf_err("wsec error %d\n", err
);
3339 /* set upper-layer auth */
3340 err
= brcmf_fil_bsscfg_int_set(ifp
, "wpa_auth", WPA_AUTH_NONE
);
3342 brcmf_err("wpa_auth error %d\n", err
);
3349 static bool brcmf_valid_wpa_oui(u8
*oui
, bool is_rsn_ie
)
3352 return (memcmp(oui
, RSN_OUI
, TLV_OUI_LEN
) == 0);
3354 return (memcmp(oui
, WPA_OUI
, TLV_OUI_LEN
) == 0);
3358 brcmf_configure_wpaie(struct net_device
*ndev
,
3359 const struct brcmf_vs_tlv
*wpa_ie
,
3362 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3363 u32 auth
= 0; /* d11 open authentication */
3375 u32 wme_bss_disable
;
3377 brcmf_dbg(TRACE
, "Enter\n");
3381 len
= wpa_ie
->len
+ TLV_HDR_LEN
;
3382 data
= (u8
*)wpa_ie
;
3383 offset
= TLV_HDR_LEN
;
3385 offset
+= VS_IE_FIXED_HDR_LEN
;
3387 offset
+= WPA_IE_VERSION_LEN
;
3389 /* check for multicast cipher suite */
3390 if (offset
+ WPA_IE_MIN_OUI_LEN
> len
) {
3392 brcmf_err("no multicast cipher suite\n");
3396 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3398 brcmf_err("ivalid OUI\n");
3401 offset
+= TLV_OUI_LEN
;
3403 /* pick up multicast cipher */
3404 switch (data
[offset
]) {
3405 case WPA_CIPHER_NONE
:
3408 case WPA_CIPHER_WEP_40
:
3409 case WPA_CIPHER_WEP_104
:
3412 case WPA_CIPHER_TKIP
:
3413 gval
= TKIP_ENABLED
;
3415 case WPA_CIPHER_AES_CCM
:
3420 brcmf_err("Invalid multi cast cipher info\n");
3425 /* walk thru unicast cipher list and pick up what we recognize */
3426 count
= data
[offset
] + (data
[offset
+ 1] << 8);
3427 offset
+= WPA_IE_SUITE_COUNT_LEN
;
3428 /* Check for unicast suite(s) */
3429 if (offset
+ (WPA_IE_MIN_OUI_LEN
* count
) > len
) {
3431 brcmf_err("no unicast cipher suite\n");
3434 for (i
= 0; i
< count
; i
++) {
3435 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3437 brcmf_err("ivalid OUI\n");
3440 offset
+= TLV_OUI_LEN
;
3441 switch (data
[offset
]) {
3442 case WPA_CIPHER_NONE
:
3444 case WPA_CIPHER_WEP_40
:
3445 case WPA_CIPHER_WEP_104
:
3446 pval
|= WEP_ENABLED
;
3448 case WPA_CIPHER_TKIP
:
3449 pval
|= TKIP_ENABLED
;
3451 case WPA_CIPHER_AES_CCM
:
3452 pval
|= AES_ENABLED
;
3455 brcmf_err("Ivalid unicast security info\n");
3459 /* walk thru auth management suite list and pick up what we recognize */
3460 count
= data
[offset
] + (data
[offset
+ 1] << 8);
3461 offset
+= WPA_IE_SUITE_COUNT_LEN
;
3462 /* Check for auth key management suite(s) */
3463 if (offset
+ (WPA_IE_MIN_OUI_LEN
* count
) > len
) {
3465 brcmf_err("no auth key mgmt suite\n");
3468 for (i
= 0; i
< count
; i
++) {
3469 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3471 brcmf_err("ivalid OUI\n");
3474 offset
+= TLV_OUI_LEN
;
3475 switch (data
[offset
]) {
3477 brcmf_dbg(TRACE
, "RSN_AKM_NONE\n");
3478 wpa_auth
|= WPA_AUTH_NONE
;
3480 case RSN_AKM_UNSPECIFIED
:
3481 brcmf_dbg(TRACE
, "RSN_AKM_UNSPECIFIED\n");
3482 is_rsn_ie
? (wpa_auth
|= WPA2_AUTH_UNSPECIFIED
) :
3483 (wpa_auth
|= WPA_AUTH_UNSPECIFIED
);
3486 brcmf_dbg(TRACE
, "RSN_AKM_PSK\n");
3487 is_rsn_ie
? (wpa_auth
|= WPA2_AUTH_PSK
) :
3488 (wpa_auth
|= WPA_AUTH_PSK
);
3491 brcmf_err("Ivalid key mgmt info\n");
3497 wme_bss_disable
= 1;
3498 if ((offset
+ RSN_CAP_LEN
) <= len
) {
3499 rsn_cap
= data
[offset
] + (data
[offset
+ 1] << 8);
3500 if (rsn_cap
& RSN_CAP_PTK_REPLAY_CNTR_MASK
)
3501 wme_bss_disable
= 0;
3503 /* set wme_bss_disable to sync RSN Capabilities */
3504 err
= brcmf_fil_bsscfg_int_set(ifp
, "wme_bss_disable",
3507 brcmf_err("wme_bss_disable error %d\n", err
);
3511 /* FOR WPS , set SES_OW_ENABLED */
3512 wsec
= (pval
| gval
| SES_OW_ENABLED
);
3515 err
= brcmf_fil_bsscfg_int_set(ifp
, "auth", auth
);
3517 brcmf_err("auth error %d\n", err
);
3521 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", wsec
);
3523 brcmf_err("wsec error %d\n", err
);
3526 /* set upper-layer auth */
3527 err
= brcmf_fil_bsscfg_int_set(ifp
, "wpa_auth", wpa_auth
);
3529 brcmf_err("wpa_auth error %d\n", err
);
3538 brcmf_parse_vndr_ies(const u8
*vndr_ie_buf
, u32 vndr_ie_len
,
3539 struct parsed_vndr_ies
*vndr_ies
)
3541 struct brcmf_vs_tlv
*vndrie
;
3542 struct brcmf_tlv
*ie
;
3543 struct parsed_vndr_ie_info
*parsed_info
;
3546 remaining_len
= (s32
)vndr_ie_len
;
3547 memset(vndr_ies
, 0, sizeof(*vndr_ies
));
3549 ie
= (struct brcmf_tlv
*)vndr_ie_buf
;
3551 if (ie
->id
!= WLAN_EID_VENDOR_SPECIFIC
)
3553 vndrie
= (struct brcmf_vs_tlv
*)ie
;
3554 /* len should be bigger than OUI length + one */
3555 if (vndrie
->len
< (VS_IE_FIXED_HDR_LEN
- TLV_HDR_LEN
+ 1)) {
3556 brcmf_err("invalid vndr ie. length is too small %d\n",
3560 /* if wpa or wme ie, do not add ie */
3561 if (!memcmp(vndrie
->oui
, (u8
*)WPA_OUI
, TLV_OUI_LEN
) &&
3562 ((vndrie
->oui_type
== WPA_OUI_TYPE
) ||
3563 (vndrie
->oui_type
== WME_OUI_TYPE
))) {
3564 brcmf_dbg(TRACE
, "Found WPA/WME oui. Do not add it\n");
3568 parsed_info
= &vndr_ies
->ie_info
[vndr_ies
->count
];
3570 /* save vndr ie information */
3571 parsed_info
->ie_ptr
= (char *)vndrie
;
3572 parsed_info
->ie_len
= vndrie
->len
+ TLV_HDR_LEN
;
3573 memcpy(&parsed_info
->vndrie
, vndrie
, sizeof(*vndrie
));
3577 brcmf_dbg(TRACE
, "** OUI %02x %02x %02x, type 0x%02x\n",
3578 parsed_info
->vndrie
.oui
[0],
3579 parsed_info
->vndrie
.oui
[1],
3580 parsed_info
->vndrie
.oui
[2],
3581 parsed_info
->vndrie
.oui_type
);
3583 if (vndr_ies
->count
>= VNDR_IE_PARSE_LIMIT
)
3586 remaining_len
-= (ie
->len
+ TLV_HDR_LEN
);
3587 if (remaining_len
<= TLV_HDR_LEN
)
3590 ie
= (struct brcmf_tlv
*)(((u8
*)ie
) + ie
->len
+
3597 brcmf_vndr_ie(u8
*iebuf
, s32 pktflag
, u8
*ie_ptr
, u32 ie_len
, s8
*add_del_cmd
)
3603 strncpy(iebuf
, add_del_cmd
, VNDR_IE_CMD_LEN
- 1);
3604 iebuf
[VNDR_IE_CMD_LEN
- 1] = '\0';
3606 iecount_le
= cpu_to_le32(1);
3607 memcpy(&iebuf
[VNDR_IE_COUNT_OFFSET
], &iecount_le
, sizeof(iecount_le
));
3609 pktflag_le
= cpu_to_le32(pktflag
);
3610 memcpy(&iebuf
[VNDR_IE_PKTFLAG_OFFSET
], &pktflag_le
, sizeof(pktflag_le
));
3612 memcpy(&iebuf
[VNDR_IE_VSIE_OFFSET
], ie_ptr
, ie_len
);
3614 return ie_len
+ VNDR_IE_HDR_SIZE
;
3617 s32
brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif
*vif
, s32 pktflag
,
3618 const u8
*vndr_ie_buf
, u32 vndr_ie_len
)
3620 struct brcmf_if
*ifp
;
3621 struct vif_saved_ie
*saved_ie
;
3625 u8
*mgmt_ie_buf
= NULL
;
3626 int mgmt_ie_buf_len
;
3628 u32 del_add_ie_buf_len
= 0;
3629 u32 total_ie_buf_len
= 0;
3630 u32 parsed_ie_buf_len
= 0;
3631 struct parsed_vndr_ies old_vndr_ies
;
3632 struct parsed_vndr_ies new_vndr_ies
;
3633 struct parsed_vndr_ie_info
*vndrie_info
;
3636 int remained_buf_len
;
3641 saved_ie
= &vif
->saved_ie
;
3643 brcmf_dbg(TRACE
, "bssidx %d, pktflag : 0x%02X\n", ifp
->bssidx
, pktflag
);
3644 iovar_ie_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
3647 curr_ie_buf
= iovar_ie_buf
;
3649 case BRCMF_VNDR_IE_PRBREQ_FLAG
:
3650 mgmt_ie_buf
= saved_ie
->probe_req_ie
;
3651 mgmt_ie_len
= &saved_ie
->probe_req_ie_len
;
3652 mgmt_ie_buf_len
= sizeof(saved_ie
->probe_req_ie
);
3654 case BRCMF_VNDR_IE_PRBRSP_FLAG
:
3655 mgmt_ie_buf
= saved_ie
->probe_res_ie
;
3656 mgmt_ie_len
= &saved_ie
->probe_res_ie_len
;
3657 mgmt_ie_buf_len
= sizeof(saved_ie
->probe_res_ie
);
3659 case BRCMF_VNDR_IE_BEACON_FLAG
:
3660 mgmt_ie_buf
= saved_ie
->beacon_ie
;
3661 mgmt_ie_len
= &saved_ie
->beacon_ie_len
;
3662 mgmt_ie_buf_len
= sizeof(saved_ie
->beacon_ie
);
3664 case BRCMF_VNDR_IE_ASSOCREQ_FLAG
:
3665 mgmt_ie_buf
= saved_ie
->assoc_req_ie
;
3666 mgmt_ie_len
= &saved_ie
->assoc_req_ie_len
;
3667 mgmt_ie_buf_len
= sizeof(saved_ie
->assoc_req_ie
);
3671 brcmf_err("not suitable type\n");
3675 if (vndr_ie_len
> mgmt_ie_buf_len
) {
3677 brcmf_err("extra IE size too big\n");
3681 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3682 if (vndr_ie_buf
&& vndr_ie_len
&& curr_ie_buf
) {
3684 brcmf_parse_vndr_ies(vndr_ie_buf
, vndr_ie_len
, &new_vndr_ies
);
3685 for (i
= 0; i
< new_vndr_ies
.count
; i
++) {
3686 vndrie_info
= &new_vndr_ies
.ie_info
[i
];
3687 memcpy(ptr
+ parsed_ie_buf_len
, vndrie_info
->ie_ptr
,
3688 vndrie_info
->ie_len
);
3689 parsed_ie_buf_len
+= vndrie_info
->ie_len
;
3693 if (mgmt_ie_buf
&& *mgmt_ie_len
) {
3694 if (parsed_ie_buf_len
&& (parsed_ie_buf_len
== *mgmt_ie_len
) &&
3695 (memcmp(mgmt_ie_buf
, curr_ie_buf
,
3696 parsed_ie_buf_len
) == 0)) {
3697 brcmf_dbg(TRACE
, "Previous mgmt IE equals to current IE\n");
3701 /* parse old vndr_ie */
3702 brcmf_parse_vndr_ies(mgmt_ie_buf
, *mgmt_ie_len
, &old_vndr_ies
);
3704 /* make a command to delete old ie */
3705 for (i
= 0; i
< old_vndr_ies
.count
; i
++) {
3706 vndrie_info
= &old_vndr_ies
.ie_info
[i
];
3708 brcmf_dbg(TRACE
, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3709 vndrie_info
->vndrie
.id
,
3710 vndrie_info
->vndrie
.len
,
3711 vndrie_info
->vndrie
.oui
[0],
3712 vndrie_info
->vndrie
.oui
[1],
3713 vndrie_info
->vndrie
.oui
[2]);
3715 del_add_ie_buf_len
= brcmf_vndr_ie(curr_ie_buf
, pktflag
,
3716 vndrie_info
->ie_ptr
,
3717 vndrie_info
->ie_len
,
3719 curr_ie_buf
+= del_add_ie_buf_len
;
3720 total_ie_buf_len
+= del_add_ie_buf_len
;
3725 /* Add if there is any extra IE */
3726 if (mgmt_ie_buf
&& parsed_ie_buf_len
) {
3729 remained_buf_len
= mgmt_ie_buf_len
;
3731 /* make a command to add new ie */
3732 for (i
= 0; i
< new_vndr_ies
.count
; i
++) {
3733 vndrie_info
= &new_vndr_ies
.ie_info
[i
];
3735 /* verify remained buf size before copy data */
3736 if (remained_buf_len
< (vndrie_info
->vndrie
.len
+
3737 VNDR_IE_VSIE_OFFSET
)) {
3738 brcmf_err("no space in mgmt_ie_buf: len left %d",
3742 remained_buf_len
-= (vndrie_info
->ie_len
+
3743 VNDR_IE_VSIE_OFFSET
);
3745 brcmf_dbg(TRACE
, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3746 vndrie_info
->vndrie
.id
,
3747 vndrie_info
->vndrie
.len
,
3748 vndrie_info
->vndrie
.oui
[0],
3749 vndrie_info
->vndrie
.oui
[1],
3750 vndrie_info
->vndrie
.oui
[2]);
3752 del_add_ie_buf_len
= brcmf_vndr_ie(curr_ie_buf
, pktflag
,
3753 vndrie_info
->ie_ptr
,
3754 vndrie_info
->ie_len
,
3757 /* save the parsed IE in wl struct */
3758 memcpy(ptr
+ (*mgmt_ie_len
), vndrie_info
->ie_ptr
,
3759 vndrie_info
->ie_len
);
3760 *mgmt_ie_len
+= vndrie_info
->ie_len
;
3762 curr_ie_buf
+= del_add_ie_buf_len
;
3763 total_ie_buf_len
+= del_add_ie_buf_len
;
3766 if (total_ie_buf_len
) {
3767 err
= brcmf_fil_bsscfg_data_set(ifp
, "vndr_ie", iovar_ie_buf
,
3770 brcmf_err("vndr ie set error : %d\n", err
);
3774 kfree(iovar_ie_buf
);
3778 s32
brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif
*vif
)
3781 BRCMF_VNDR_IE_PRBREQ_FLAG
,
3782 BRCMF_VNDR_IE_PRBRSP_FLAG
,
3783 BRCMF_VNDR_IE_BEACON_FLAG
3787 for (i
= 0; i
< ARRAY_SIZE(pktflags
); i
++)
3788 brcmf_vif_set_mgmt_ie(vif
, pktflags
[i
], NULL
, 0);
3790 memset(&vif
->saved_ie
, 0, sizeof(vif
->saved_ie
));
3795 brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif
*vif
,
3796 struct cfg80211_beacon_data
*beacon
)
3800 /* Set Beacon IEs to FW */
3801 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_BEACON_FLAG
,
3802 beacon
->tail
, beacon
->tail_len
);
3804 brcmf_err("Set Beacon IE Failed\n");
3807 brcmf_dbg(TRACE
, "Applied Vndr IEs for Beacon\n");
3809 /* Set Probe Response IEs to FW */
3810 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_PRBRSP_FLAG
,
3811 beacon
->proberesp_ies
,
3812 beacon
->proberesp_ies_len
);
3814 brcmf_err("Set Probe Resp IE Failed\n");
3816 brcmf_dbg(TRACE
, "Applied Vndr IEs for Probe Resp\n");
3822 brcmf_cfg80211_start_ap(struct wiphy
*wiphy
, struct net_device
*ndev
,
3823 struct cfg80211_ap_settings
*settings
)
3826 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3827 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3828 const struct brcmf_tlv
*ssid_ie
;
3829 struct brcmf_ssid_le ssid_le
;
3831 const struct brcmf_tlv
*rsn_ie
;
3832 const struct brcmf_vs_tlv
*wpa_ie
;
3833 struct brcmf_join_params join_params
;
3834 enum nl80211_iftype dev_role
;
3835 struct brcmf_fil_bss_enable_le bss_enable
;
3838 brcmf_dbg(TRACE
, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3839 settings
->chandef
.chan
->hw_value
,
3840 settings
->chandef
.center_freq1
, settings
->chandef
.width
,
3841 settings
->beacon_interval
, settings
->dtim_period
);
3842 brcmf_dbg(TRACE
, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3843 settings
->ssid
, settings
->ssid_len
, settings
->auth_type
,
3844 settings
->inactivity_timeout
);
3846 dev_role
= ifp
->vif
->wdev
.iftype
;
3848 memset(&ssid_le
, 0, sizeof(ssid_le
));
3849 if (settings
->ssid
== NULL
|| settings
->ssid_len
== 0) {
3850 ie_offset
= DOT11_MGMT_HDR_LEN
+ DOT11_BCN_PRB_FIXED_LEN
;
3851 ssid_ie
= brcmf_parse_tlvs(
3852 (u8
*)&settings
->beacon
.head
[ie_offset
],
3853 settings
->beacon
.head_len
- ie_offset
,
3858 memcpy(ssid_le
.SSID
, ssid_ie
->data
, ssid_ie
->len
);
3859 ssid_le
.SSID_len
= cpu_to_le32(ssid_ie
->len
);
3860 brcmf_dbg(TRACE
, "SSID is (%s) in Head\n", ssid_le
.SSID
);
3862 memcpy(ssid_le
.SSID
, settings
->ssid
, settings
->ssid_len
);
3863 ssid_le
.SSID_len
= cpu_to_le32((u32
)settings
->ssid_len
);
3866 brcmf_set_mpc(ifp
, 0);
3867 brcmf_configure_arp_offload(ifp
, false);
3869 /* find the RSN_IE */
3870 rsn_ie
= brcmf_parse_tlvs((u8
*)settings
->beacon
.tail
,
3871 settings
->beacon
.tail_len
, WLAN_EID_RSN
);
3873 /* find the WPA_IE */
3874 wpa_ie
= brcmf_find_wpaie((u8
*)settings
->beacon
.tail
,
3875 settings
->beacon
.tail_len
);
3877 if ((wpa_ie
!= NULL
|| rsn_ie
!= NULL
)) {
3878 brcmf_dbg(TRACE
, "WPA(2) IE is found\n");
3879 if (wpa_ie
!= NULL
) {
3881 err
= brcmf_configure_wpaie(ndev
, wpa_ie
, false);
3886 err
= brcmf_configure_wpaie(ndev
,
3887 (struct brcmf_vs_tlv
*)rsn_ie
, true);
3892 brcmf_dbg(TRACE
, "No WPA(2) IEs found\n");
3893 brcmf_configure_opensecurity(ifp
);
3896 brcmf_config_ap_mgmt_ie(ifp
->vif
, &settings
->beacon
);
3898 chanspec
= chandef_to_chanspec(&cfg
->d11inf
, &settings
->chandef
);
3899 err
= brcmf_fil_iovar_int_set(ifp
, "chanspec", chanspec
);
3901 brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec
, err
);
3905 if (settings
->beacon_interval
) {
3906 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_BCNPRD
,
3907 settings
->beacon_interval
);
3909 brcmf_err("Beacon Interval Set Error, %d\n", err
);
3913 if (settings
->dtim_period
) {
3914 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_DTIMPRD
,
3915 settings
->dtim_period
);
3917 brcmf_err("DTIM Interval Set Error, %d\n", err
);
3922 if (dev_role
== NL80211_IFTYPE_AP
) {
3923 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
3925 brcmf_err("BRCMF_C_DOWN error %d\n", err
);
3928 brcmf_fil_iovar_int_set(ifp
, "apsta", 0);
3931 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, 1);
3933 brcmf_err("SET INFRA error %d\n", err
);
3936 if (dev_role
== NL80211_IFTYPE_AP
) {
3937 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_AP
, 1);
3939 brcmf_err("setting AP mode failed %d\n", err
);
3942 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 1);
3944 brcmf_err("BRCMF_C_UP error (%d)\n", err
);
3948 memset(&join_params
, 0, sizeof(join_params
));
3949 /* join parameters starts with ssid */
3950 memcpy(&join_params
.ssid_le
, &ssid_le
, sizeof(ssid_le
));
3952 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
3953 &join_params
, sizeof(join_params
));
3955 brcmf_err("SET SSID error (%d)\n", err
);
3958 brcmf_dbg(TRACE
, "AP mode configuration complete\n");
3960 err
= brcmf_fil_bsscfg_data_set(ifp
, "ssid", &ssid_le
,
3963 brcmf_err("setting ssid failed %d\n", err
);
3966 bss_enable
.bsscfg_idx
= cpu_to_le32(ifp
->bssidx
);
3967 bss_enable
.enable
= cpu_to_le32(1);
3968 err
= brcmf_fil_iovar_data_set(ifp
, "bss", &bss_enable
,
3969 sizeof(bss_enable
));
3971 brcmf_err("bss_enable config failed %d\n", err
);
3975 brcmf_dbg(TRACE
, "GO mode configuration complete\n");
3977 clear_bit(BRCMF_VIF_STATUS_AP_CREATING
, &ifp
->vif
->sme_state
);
3978 set_bit(BRCMF_VIF_STATUS_AP_CREATED
, &ifp
->vif
->sme_state
);
3982 brcmf_set_mpc(ifp
, 1);
3983 brcmf_configure_arp_offload(ifp
, true);
3988 static int brcmf_cfg80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*ndev
)
3990 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3992 struct brcmf_fil_bss_enable_le bss_enable
;
3993 struct brcmf_join_params join_params
;
3995 brcmf_dbg(TRACE
, "Enter\n");
3997 if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_AP
) {
3998 /* Due to most likely deauths outstanding we sleep */
3999 /* first to make sure they get processed by fw. */
4002 memset(&join_params
, 0, sizeof(join_params
));
4003 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
4004 &join_params
, sizeof(join_params
));
4006 brcmf_err("SET SSID error (%d)\n", err
);
4007 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
4009 brcmf_err("BRCMF_C_UP error %d\n", err
);
4010 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_AP
, 0);
4012 brcmf_err("setting AP mode failed %d\n", err
);
4013 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, 0);
4015 brcmf_err("setting INFRA mode failed %d\n", err
);
4017 bss_enable
.bsscfg_idx
= cpu_to_le32(ifp
->bssidx
);
4018 bss_enable
.enable
= cpu_to_le32(0);
4019 err
= brcmf_fil_iovar_data_set(ifp
, "bss", &bss_enable
,
4020 sizeof(bss_enable
));
4022 brcmf_err("bss_enable config failed %d\n", err
);
4024 brcmf_set_mpc(ifp
, 1);
4025 brcmf_configure_arp_offload(ifp
, true);
4026 set_bit(BRCMF_VIF_STATUS_AP_CREATING
, &ifp
->vif
->sme_state
);
4027 clear_bit(BRCMF_VIF_STATUS_AP_CREATED
, &ifp
->vif
->sme_state
);
4033 brcmf_cfg80211_change_beacon(struct wiphy
*wiphy
, struct net_device
*ndev
,
4034 struct cfg80211_beacon_data
*info
)
4036 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4039 brcmf_dbg(TRACE
, "Enter\n");
4041 err
= brcmf_config_ap_mgmt_ie(ifp
->vif
, info
);
4047 brcmf_cfg80211_del_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
4050 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4051 struct brcmf_scb_val_le scbval
;
4052 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4058 brcmf_dbg(TRACE
, "Enter %pM\n", mac
);
4060 if (ifp
->vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
4061 ifp
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
4062 if (!check_vif_up(ifp
->vif
))
4065 memcpy(&scbval
.ea
, mac
, ETH_ALEN
);
4066 scbval
.val
= cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING
);
4067 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON
,
4068 &scbval
, sizeof(scbval
));
4070 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err
);
4072 brcmf_dbg(TRACE
, "Exit\n");
4078 brcmf_cfg80211_mgmt_frame_register(struct wiphy
*wiphy
,
4079 struct wireless_dev
*wdev
,
4080 u16 frame_type
, bool reg
)
4082 struct brcmf_cfg80211_vif
*vif
;
4085 brcmf_dbg(TRACE
, "Enter, frame_type %04x, reg=%d\n", frame_type
, reg
);
4087 mgmt_type
= (frame_type
& IEEE80211_FCTL_STYPE
) >> 4;
4088 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4090 vif
->mgmt_rx_reg
|= BIT(mgmt_type
);
4092 vif
->mgmt_rx_reg
&= ~BIT(mgmt_type
);
4097 brcmf_cfg80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
4098 struct cfg80211_mgmt_tx_params
*params
, u64
*cookie
)
4100 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4101 struct ieee80211_channel
*chan
= params
->chan
;
4102 const u8
*buf
= params
->buf
;
4103 size_t len
= params
->len
;
4104 const struct ieee80211_mgmt
*mgmt
;
4105 struct brcmf_cfg80211_vif
*vif
;
4109 struct brcmf_fil_action_frame_le
*action_frame
;
4110 struct brcmf_fil_af_params_le
*af_params
;
4115 brcmf_dbg(TRACE
, "Enter\n");
4119 mgmt
= (const struct ieee80211_mgmt
*)buf
;
4121 if (!ieee80211_is_mgmt(mgmt
->frame_control
)) {
4122 brcmf_err("Driver only allows MGMT packet type\n");
4126 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4128 if (ieee80211_is_probe_resp(mgmt
->frame_control
)) {
4129 /* Right now the only reason to get a probe response */
4130 /* is for p2p listen response or for p2p GO from */
4131 /* wpa_supplicant. Unfortunately the probe is send */
4132 /* on primary ndev, while dongle wants it on the p2p */
4133 /* vif. Since this is only reason for a probe */
4134 /* response to be sent, the vif is taken from cfg. */
4135 /* If ever desired to send proberesp for non p2p */
4136 /* response then data should be checked for */
4137 /* "DIRECT-". Note in future supplicant will take */
4138 /* dedicated p2p wdev to do this and then this 'hack'*/
4139 /* is not needed anymore. */
4140 ie_offset
= DOT11_MGMT_HDR_LEN
+
4141 DOT11_BCN_PRB_FIXED_LEN
;
4142 ie_len
= len
- ie_offset
;
4143 if (vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
)
4144 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
4145 err
= brcmf_vif_set_mgmt_ie(vif
,
4146 BRCMF_VNDR_IE_PRBRSP_FLAG
,
4149 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, true,
4151 } else if (ieee80211_is_action(mgmt
->frame_control
)) {
4152 af_params
= kzalloc(sizeof(*af_params
), GFP_KERNEL
);
4153 if (af_params
== NULL
) {
4154 brcmf_err("unable to allocate frame\n");
4158 action_frame
= &af_params
->action_frame
;
4159 /* Add the packet Id */
4160 action_frame
->packet_id
= cpu_to_le32(*cookie
);
4162 memcpy(&action_frame
->da
[0], &mgmt
->da
[0], ETH_ALEN
);
4163 memcpy(&af_params
->bssid
[0], &mgmt
->bssid
[0], ETH_ALEN
);
4164 /* Add the length exepted for 802.11 header */
4165 action_frame
->len
= cpu_to_le16(len
- DOT11_MGMT_HDR_LEN
);
4166 /* Add the channel. Use the one specified as parameter if any or
4167 * the current one (got from the firmware) otherwise
4170 freq
= chan
->center_freq
;
4172 brcmf_fil_cmd_int_get(vif
->ifp
, BRCMF_C_GET_CHANNEL
,
4174 chan_nr
= ieee80211_frequency_to_channel(freq
);
4175 af_params
->channel
= cpu_to_le32(chan_nr
);
4177 memcpy(action_frame
->data
, &buf
[DOT11_MGMT_HDR_LEN
],
4178 le16_to_cpu(action_frame
->len
));
4180 brcmf_dbg(TRACE
, "Action frame, cookie=%lld, len=%d, freq=%d\n",
4181 *cookie
, le16_to_cpu(action_frame
->len
), freq
);
4183 ack
= brcmf_p2p_send_action_frame(cfg
, cfg_to_ndev(cfg
),
4186 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, ack
,
4190 brcmf_dbg(TRACE
, "Unhandled, fc=%04x!!\n", mgmt
->frame_control
);
4191 brcmf_dbg_hex_dump(true, buf
, len
, "payload, len=%Zu\n", len
);
4200 brcmf_cfg80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
4201 struct wireless_dev
*wdev
,
4204 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4205 struct brcmf_cfg80211_vif
*vif
;
4208 brcmf_dbg(TRACE
, "Enter p2p listen cancel\n");
4210 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
4212 brcmf_err("No p2p device available for probe response\n");
4216 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
4221 static int brcmf_cfg80211_crit_proto_start(struct wiphy
*wiphy
,
4222 struct wireless_dev
*wdev
,
4223 enum nl80211_crit_proto_id proto
,
4226 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4227 struct brcmf_cfg80211_vif
*vif
;
4229 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4231 /* only DHCP support for now */
4232 if (proto
!= NL80211_CRIT_PROTO_DHCP
)
4235 /* suppress and abort scanning */
4236 set_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
4237 brcmf_abort_scanning(cfg
);
4239 return brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_DISABLED
, duration
);
4242 static void brcmf_cfg80211_crit_proto_stop(struct wiphy
*wiphy
,
4243 struct wireless_dev
*wdev
)
4245 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4246 struct brcmf_cfg80211_vif
*vif
;
4248 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4250 brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_ENABLED
, 0);
4251 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
4255 brcmf_notify_tdls_peer_event(struct brcmf_if
*ifp
,
4256 const struct brcmf_event_msg
*e
, void *data
)
4258 switch (e
->reason
) {
4259 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED
:
4260 brcmf_dbg(TRACE
, "TDLS Peer Discovered\n");
4262 case BRCMF_E_REASON_TDLS_PEER_CONNECTED
:
4263 brcmf_dbg(TRACE
, "TDLS Peer Connected\n");
4264 brcmf_proto_add_tdls_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4266 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED
:
4267 brcmf_dbg(TRACE
, "TDLS Peer Disconnected\n");
4268 brcmf_proto_delete_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4275 static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper
)
4280 case NL80211_TDLS_DISCOVERY_REQ
:
4281 ret
= BRCMF_TDLS_MANUAL_EP_DISCOVERY
;
4283 case NL80211_TDLS_SETUP
:
4284 ret
= BRCMF_TDLS_MANUAL_EP_CREATE
;
4286 case NL80211_TDLS_TEARDOWN
:
4287 ret
= BRCMF_TDLS_MANUAL_EP_DELETE
;
4290 brcmf_err("unsupported operation: %d\n", oper
);
4296 static int brcmf_cfg80211_tdls_oper(struct wiphy
*wiphy
,
4297 struct net_device
*ndev
, const u8
*peer
,
4298 enum nl80211_tdls_operation oper
)
4300 struct brcmf_if
*ifp
;
4301 struct brcmf_tdls_iovar_le info
;
4304 ret
= brcmf_convert_nl80211_tdls_oper(oper
);
4308 ifp
= netdev_priv(ndev
);
4309 memset(&info
, 0, sizeof(info
));
4310 info
.mode
= (u8
)ret
;
4312 memcpy(info
.ea
, peer
, ETH_ALEN
);
4314 ret
= brcmf_fil_iovar_data_set(ifp
, "tdls_endpoint",
4315 &info
, sizeof(info
));
4317 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret
);
4322 static struct cfg80211_ops wl_cfg80211_ops
= {
4323 .add_virtual_intf
= brcmf_cfg80211_add_iface
,
4324 .del_virtual_intf
= brcmf_cfg80211_del_iface
,
4325 .change_virtual_intf
= brcmf_cfg80211_change_iface
,
4326 .scan
= brcmf_cfg80211_scan
,
4327 .set_wiphy_params
= brcmf_cfg80211_set_wiphy_params
,
4328 .join_ibss
= brcmf_cfg80211_join_ibss
,
4329 .leave_ibss
= brcmf_cfg80211_leave_ibss
,
4330 .get_station
= brcmf_cfg80211_get_station
,
4331 .set_tx_power
= brcmf_cfg80211_set_tx_power
,
4332 .get_tx_power
= brcmf_cfg80211_get_tx_power
,
4333 .add_key
= brcmf_cfg80211_add_key
,
4334 .del_key
= brcmf_cfg80211_del_key
,
4335 .get_key
= brcmf_cfg80211_get_key
,
4336 .set_default_key
= brcmf_cfg80211_config_default_key
,
4337 .set_default_mgmt_key
= brcmf_cfg80211_config_default_mgmt_key
,
4338 .set_power_mgmt
= brcmf_cfg80211_set_power_mgmt
,
4339 .connect
= brcmf_cfg80211_connect
,
4340 .disconnect
= brcmf_cfg80211_disconnect
,
4341 .suspend
= brcmf_cfg80211_suspend
,
4342 .resume
= brcmf_cfg80211_resume
,
4343 .set_pmksa
= brcmf_cfg80211_set_pmksa
,
4344 .del_pmksa
= brcmf_cfg80211_del_pmksa
,
4345 .flush_pmksa
= brcmf_cfg80211_flush_pmksa
,
4346 .start_ap
= brcmf_cfg80211_start_ap
,
4347 .stop_ap
= brcmf_cfg80211_stop_ap
,
4348 .change_beacon
= brcmf_cfg80211_change_beacon
,
4349 .del_station
= brcmf_cfg80211_del_station
,
4350 .sched_scan_start
= brcmf_cfg80211_sched_scan_start
,
4351 .sched_scan_stop
= brcmf_cfg80211_sched_scan_stop
,
4352 .mgmt_frame_register
= brcmf_cfg80211_mgmt_frame_register
,
4353 .mgmt_tx
= brcmf_cfg80211_mgmt_tx
,
4354 .remain_on_channel
= brcmf_p2p_remain_on_channel
,
4355 .cancel_remain_on_channel
= brcmf_cfg80211_cancel_remain_on_channel
,
4356 .start_p2p_device
= brcmf_p2p_start_device
,
4357 .stop_p2p_device
= brcmf_p2p_stop_device
,
4358 .crit_proto_start
= brcmf_cfg80211_crit_proto_start
,
4359 .crit_proto_stop
= brcmf_cfg80211_crit_proto_stop
,
4360 .tdls_oper
= brcmf_cfg80211_tdls_oper
,
4363 struct brcmf_cfg80211_vif
*brcmf_alloc_vif(struct brcmf_cfg80211_info
*cfg
,
4364 enum nl80211_iftype type
,
4367 struct brcmf_cfg80211_vif
*vif
;
4369 brcmf_dbg(TRACE
, "allocating virtual interface (size=%zu)\n",
4371 vif
= kzalloc(sizeof(*vif
), GFP_KERNEL
);
4373 return ERR_PTR(-ENOMEM
);
4375 vif
->wdev
.wiphy
= cfg
->wiphy
;
4376 vif
->wdev
.iftype
= type
;
4378 vif
->pm_block
= pm_block
;
4381 brcmf_init_prof(&vif
->profile
);
4383 list_add_tail(&vif
->list
, &cfg
->vif_list
);
4387 void brcmf_free_vif(struct brcmf_cfg80211_vif
*vif
)
4389 list_del(&vif
->list
);
4393 void brcmf_cfg80211_free_netdev(struct net_device
*ndev
)
4395 struct brcmf_cfg80211_vif
*vif
;
4396 struct brcmf_if
*ifp
;
4398 ifp
= netdev_priv(ndev
);
4401 brcmf_free_vif(vif
);
4405 static bool brcmf_is_linkup(const struct brcmf_event_msg
*e
)
4407 u32 event
= e
->event_code
;
4408 u32 status
= e
->status
;
4410 if (event
== BRCMF_E_SET_SSID
&& status
== BRCMF_E_STATUS_SUCCESS
) {
4411 brcmf_dbg(CONN
, "Processing set ssid\n");
4418 static bool brcmf_is_linkdown(const struct brcmf_event_msg
*e
)
4420 u32 event
= e
->event_code
;
4421 u16 flags
= e
->flags
;
4423 if ((event
== BRCMF_E_DEAUTH
) || (event
== BRCMF_E_DEAUTH_IND
) ||
4424 (event
== BRCMF_E_DISASSOC_IND
) ||
4425 ((event
== BRCMF_E_LINK
) && (!(flags
& BRCMF_EVENT_MSG_LINK
)))) {
4426 brcmf_dbg(CONN
, "Processing link down\n");
4432 static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info
*cfg
,
4433 const struct brcmf_event_msg
*e
)
4435 u32 event
= e
->event_code
;
4436 u32 status
= e
->status
;
4438 if (event
== BRCMF_E_LINK
&& status
== BRCMF_E_STATUS_NO_NETWORKS
) {
4439 brcmf_dbg(CONN
, "Processing Link %s & no network found\n",
4440 e
->flags
& BRCMF_EVENT_MSG_LINK
? "up" : "down");
4444 if (event
== BRCMF_E_SET_SSID
&& status
!= BRCMF_E_STATUS_SUCCESS
) {
4445 brcmf_dbg(CONN
, "Processing connecting & no network found\n");
4452 static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info
*cfg
)
4454 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4456 kfree(conn_info
->req_ie
);
4457 conn_info
->req_ie
= NULL
;
4458 conn_info
->req_ie_len
= 0;
4459 kfree(conn_info
->resp_ie
);
4460 conn_info
->resp_ie
= NULL
;
4461 conn_info
->resp_ie_len
= 0;
4464 static s32
brcmf_get_assoc_ies(struct brcmf_cfg80211_info
*cfg
,
4465 struct brcmf_if
*ifp
)
4467 struct brcmf_cfg80211_assoc_ielen_le
*assoc_info
;
4468 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4473 brcmf_clear_assoc_ies(cfg
);
4475 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_info",
4476 cfg
->extra_buf
, WL_ASSOC_INFO_MAX
);
4478 brcmf_err("could not get assoc info (%d)\n", err
);
4482 (struct brcmf_cfg80211_assoc_ielen_le
*)cfg
->extra_buf
;
4483 req_len
= le32_to_cpu(assoc_info
->req_len
);
4484 resp_len
= le32_to_cpu(assoc_info
->resp_len
);
4486 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_req_ies",
4490 brcmf_err("could not get assoc req (%d)\n", err
);
4493 conn_info
->req_ie_len
= req_len
;
4495 kmemdup(cfg
->extra_buf
, conn_info
->req_ie_len
,
4498 conn_info
->req_ie_len
= 0;
4499 conn_info
->req_ie
= NULL
;
4502 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_resp_ies",
4506 brcmf_err("could not get assoc resp (%d)\n", err
);
4509 conn_info
->resp_ie_len
= resp_len
;
4510 conn_info
->resp_ie
=
4511 kmemdup(cfg
->extra_buf
, conn_info
->resp_ie_len
,
4514 conn_info
->resp_ie_len
= 0;
4515 conn_info
->resp_ie
= NULL
;
4517 brcmf_dbg(CONN
, "req len (%d) resp len (%d)\n",
4518 conn_info
->req_ie_len
, conn_info
->resp_ie_len
);
4524 brcmf_bss_roaming_done(struct brcmf_cfg80211_info
*cfg
,
4525 struct net_device
*ndev
,
4526 const struct brcmf_event_msg
*e
)
4528 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4529 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4530 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4531 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
4532 struct ieee80211_channel
*notify_channel
= NULL
;
4533 struct ieee80211_supported_band
*band
;
4534 struct brcmf_bss_info_le
*bi
;
4535 struct brcmu_chan ch
;
4540 brcmf_dbg(TRACE
, "Enter\n");
4542 brcmf_get_assoc_ies(cfg
, ifp
);
4543 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4544 brcmf_update_bss_info(cfg
, ifp
);
4546 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
4552 /* data sent to dongle has to be little endian */
4553 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
4554 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
4555 buf
, WL_BSS_INFO_MAX
);
4560 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
4561 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
4562 cfg
->d11inf
.decchspec(&ch
);
4564 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
4565 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
4567 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
4569 freq
= ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
4570 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
4574 cfg80211_roamed(ndev
, notify_channel
, (u8
*)profile
->bssid
,
4575 conn_info
->req_ie
, conn_info
->req_ie_len
,
4576 conn_info
->resp_ie
, conn_info
->resp_ie_len
, GFP_KERNEL
);
4577 brcmf_dbg(CONN
, "Report roaming result\n");
4579 set_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
);
4580 brcmf_dbg(TRACE
, "Exit\n");
4585 brcmf_bss_connect_done(struct brcmf_cfg80211_info
*cfg
,
4586 struct net_device
*ndev
, const struct brcmf_event_msg
*e
,
4589 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4590 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4591 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4593 brcmf_dbg(TRACE
, "Enter\n");
4595 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4596 &ifp
->vif
->sme_state
)) {
4598 brcmf_get_assoc_ies(cfg
, ifp
);
4599 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4600 brcmf_update_bss_info(cfg
, ifp
);
4601 set_bit(BRCMF_VIF_STATUS_CONNECTED
,
4602 &ifp
->vif
->sme_state
);
4604 cfg80211_connect_result(ndev
,
4605 (u8
*)profile
->bssid
,
4607 conn_info
->req_ie_len
,
4609 conn_info
->resp_ie_len
,
4610 completed
? WLAN_STATUS_SUCCESS
:
4611 WLAN_STATUS_AUTH_TIMEOUT
,
4613 brcmf_dbg(CONN
, "Report connect result - connection %s\n",
4614 completed
? "succeeded" : "failed");
4616 brcmf_dbg(TRACE
, "Exit\n");
4621 brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info
*cfg
,
4622 struct net_device
*ndev
,
4623 const struct brcmf_event_msg
*e
, void *data
)
4625 static int generation
;
4626 u32 event
= e
->event_code
;
4627 u32 reason
= e
->reason
;
4628 struct station_info sinfo
;
4630 brcmf_dbg(CONN
, "event %d, reason %d\n", event
, reason
);
4631 if (event
== BRCMF_E_LINK
&& reason
== BRCMF_E_REASON_LINK_BSSCFG_DIS
&&
4632 ndev
!= cfg_to_ndev(cfg
)) {
4633 brcmf_dbg(CONN
, "AP mode link down\n");
4634 complete(&cfg
->vif_disabled
);
4638 if (((event
== BRCMF_E_ASSOC_IND
) || (event
== BRCMF_E_REASSOC_IND
)) &&
4639 (reason
== BRCMF_E_STATUS_SUCCESS
)) {
4640 memset(&sinfo
, 0, sizeof(sinfo
));
4641 sinfo
.filled
= STATION_INFO_ASSOC_REQ_IES
;
4643 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
4646 sinfo
.assoc_req_ies
= data
;
4647 sinfo
.assoc_req_ies_len
= e
->datalen
;
4649 sinfo
.generation
= generation
;
4650 cfg80211_new_sta(ndev
, e
->addr
, &sinfo
, GFP_KERNEL
);
4651 } else if ((event
== BRCMF_E_DISASSOC_IND
) ||
4652 (event
== BRCMF_E_DEAUTH_IND
) ||
4653 (event
== BRCMF_E_DEAUTH
)) {
4654 cfg80211_del_sta(ndev
, e
->addr
, GFP_KERNEL
);
4660 brcmf_notify_connect_status(struct brcmf_if
*ifp
,
4661 const struct brcmf_event_msg
*e
, void *data
)
4663 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4664 struct net_device
*ndev
= ifp
->ndev
;
4665 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4666 struct ieee80211_channel
*chan
;
4669 if ((e
->event_code
== BRCMF_E_DEAUTH
) ||
4670 (e
->event_code
== BRCMF_E_DEAUTH_IND
) ||
4671 (e
->event_code
== BRCMF_E_DISASSOC_IND
) ||
4672 ((e
->event_code
== BRCMF_E_LINK
) && (!e
->flags
))) {
4673 brcmf_proto_delete_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4676 if (brcmf_is_apmode(ifp
->vif
)) {
4677 err
= brcmf_notify_connect_status_ap(cfg
, ndev
, e
, data
);
4678 } else if (brcmf_is_linkup(e
)) {
4679 brcmf_dbg(CONN
, "Linkup\n");
4680 if (brcmf_is_ibssmode(ifp
->vif
)) {
4681 chan
= ieee80211_get_channel(cfg
->wiphy
, cfg
->channel
);
4682 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4683 wl_inform_ibss(cfg
, ndev
, e
->addr
);
4684 cfg80211_ibss_joined(ndev
, e
->addr
, chan
, GFP_KERNEL
);
4685 clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4686 &ifp
->vif
->sme_state
);
4687 set_bit(BRCMF_VIF_STATUS_CONNECTED
,
4688 &ifp
->vif
->sme_state
);
4690 brcmf_bss_connect_done(cfg
, ndev
, e
, true);
4691 } else if (brcmf_is_linkdown(e
)) {
4692 brcmf_dbg(CONN
, "Linkdown\n");
4693 if (!brcmf_is_ibssmode(ifp
->vif
)) {
4694 brcmf_bss_connect_done(cfg
, ndev
, e
, false);
4696 brcmf_link_down(ifp
->vif
);
4697 brcmf_init_prof(ndev_to_prof(ndev
));
4698 if (ndev
!= cfg_to_ndev(cfg
))
4699 complete(&cfg
->vif_disabled
);
4700 } else if (brcmf_is_nonetwork(cfg
, e
)) {
4701 if (brcmf_is_ibssmode(ifp
->vif
))
4702 clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4703 &ifp
->vif
->sme_state
);
4705 brcmf_bss_connect_done(cfg
, ndev
, e
, false);
4712 brcmf_notify_roaming_status(struct brcmf_if
*ifp
,
4713 const struct brcmf_event_msg
*e
, void *data
)
4715 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4716 u32 event
= e
->event_code
;
4717 u32 status
= e
->status
;
4719 if (event
== BRCMF_E_ROAM
&& status
== BRCMF_E_STATUS_SUCCESS
) {
4720 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
))
4721 brcmf_bss_roaming_done(cfg
, ifp
->ndev
, e
);
4723 brcmf_bss_connect_done(cfg
, ifp
->ndev
, e
, true);
4730 brcmf_notify_mic_status(struct brcmf_if
*ifp
,
4731 const struct brcmf_event_msg
*e
, void *data
)
4733 u16 flags
= e
->flags
;
4734 enum nl80211_key_type key_type
;
4736 if (flags
& BRCMF_EVENT_MSG_GROUP
)
4737 key_type
= NL80211_KEYTYPE_GROUP
;
4739 key_type
= NL80211_KEYTYPE_PAIRWISE
;
4741 cfg80211_michael_mic_failure(ifp
->ndev
, (u8
*)&e
->addr
, key_type
, -1,
4747 static s32
brcmf_notify_vif_event(struct brcmf_if
*ifp
,
4748 const struct brcmf_event_msg
*e
, void *data
)
4750 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4751 struct brcmf_if_event
*ifevent
= (struct brcmf_if_event
*)data
;
4752 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
4753 struct brcmf_cfg80211_vif
*vif
;
4755 brcmf_dbg(TRACE
, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4756 ifevent
->action
, ifevent
->flags
, ifevent
->ifidx
,
4759 mutex_lock(&event
->vif_event_lock
);
4760 event
->action
= ifevent
->action
;
4763 switch (ifevent
->action
) {
4764 case BRCMF_E_IF_ADD
:
4765 /* waiting process may have timed out */
4766 if (!cfg
->vif_event
.vif
) {
4767 mutex_unlock(&event
->vif_event_lock
);
4774 vif
->wdev
.netdev
= ifp
->ndev
;
4775 ifp
->ndev
->ieee80211_ptr
= &vif
->wdev
;
4776 SET_NETDEV_DEV(ifp
->ndev
, wiphy_dev(cfg
->wiphy
));
4778 mutex_unlock(&event
->vif_event_lock
);
4779 wake_up(&event
->vif_wq
);
4782 case BRCMF_E_IF_DEL
:
4783 mutex_unlock(&event
->vif_event_lock
);
4784 /* event may not be upon user request */
4785 if (brcmf_cfg80211_vif_event_armed(cfg
))
4786 wake_up(&event
->vif_wq
);
4789 case BRCMF_E_IF_CHANGE
:
4790 mutex_unlock(&event
->vif_event_lock
);
4791 wake_up(&event
->vif_wq
);
4795 mutex_unlock(&event
->vif_event_lock
);
4801 static void brcmf_init_conf(struct brcmf_cfg80211_conf
*conf
)
4803 conf
->frag_threshold
= (u32
)-1;
4804 conf
->rts_threshold
= (u32
)-1;
4805 conf
->retry_short
= (u32
)-1;
4806 conf
->retry_long
= (u32
)-1;
4807 conf
->tx_power
= -1;
4810 static void brcmf_register_event_handlers(struct brcmf_cfg80211_info
*cfg
)
4812 brcmf_fweh_register(cfg
->pub
, BRCMF_E_LINK
,
4813 brcmf_notify_connect_status
);
4814 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DEAUTH_IND
,
4815 brcmf_notify_connect_status
);
4816 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DEAUTH
,
4817 brcmf_notify_connect_status
);
4818 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DISASSOC_IND
,
4819 brcmf_notify_connect_status
);
4820 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ASSOC_IND
,
4821 brcmf_notify_connect_status
);
4822 brcmf_fweh_register(cfg
->pub
, BRCMF_E_REASSOC_IND
,
4823 brcmf_notify_connect_status
);
4824 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ROAM
,
4825 brcmf_notify_roaming_status
);
4826 brcmf_fweh_register(cfg
->pub
, BRCMF_E_MIC_ERROR
,
4827 brcmf_notify_mic_status
);
4828 brcmf_fweh_register(cfg
->pub
, BRCMF_E_SET_SSID
,
4829 brcmf_notify_connect_status
);
4830 brcmf_fweh_register(cfg
->pub
, BRCMF_E_PFN_NET_FOUND
,
4831 brcmf_notify_sched_scan_results
);
4832 brcmf_fweh_register(cfg
->pub
, BRCMF_E_IF
,
4833 brcmf_notify_vif_event
);
4834 brcmf_fweh_register(cfg
->pub
, BRCMF_E_P2P_PROBEREQ_MSG
,
4835 brcmf_p2p_notify_rx_mgmt_p2p_probereq
);
4836 brcmf_fweh_register(cfg
->pub
, BRCMF_E_P2P_DISC_LISTEN_COMPLETE
,
4837 brcmf_p2p_notify_listen_complete
);
4838 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_RX
,
4839 brcmf_p2p_notify_action_frame_rx
);
4840 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_COMPLETE
,
4841 brcmf_p2p_notify_action_tx_complete
);
4842 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE
,
4843 brcmf_p2p_notify_action_tx_complete
);
4846 static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info
*cfg
)
4850 kfree(cfg
->escan_ioctl_buf
);
4851 cfg
->escan_ioctl_buf
= NULL
;
4852 kfree(cfg
->extra_buf
);
4853 cfg
->extra_buf
= NULL
;
4854 kfree(cfg
->pmk_list
);
4855 cfg
->pmk_list
= NULL
;
4858 static s32
brcmf_init_priv_mem(struct brcmf_cfg80211_info
*cfg
)
4860 cfg
->conf
= kzalloc(sizeof(*cfg
->conf
), GFP_KERNEL
);
4862 goto init_priv_mem_out
;
4863 cfg
->escan_ioctl_buf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
4864 if (!cfg
->escan_ioctl_buf
)
4865 goto init_priv_mem_out
;
4866 cfg
->extra_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
4867 if (!cfg
->extra_buf
)
4868 goto init_priv_mem_out
;
4869 cfg
->pmk_list
= kzalloc(sizeof(*cfg
->pmk_list
), GFP_KERNEL
);
4871 goto init_priv_mem_out
;
4876 brcmf_deinit_priv_mem(cfg
);
4881 static s32
wl_init_priv(struct brcmf_cfg80211_info
*cfg
)
4885 cfg
->scan_request
= NULL
;
4886 cfg
->pwr_save
= true;
4887 cfg
->active_scan
= true; /* we do active scan per default */
4888 cfg
->dongle_up
= false; /* dongle is not up yet */
4889 err
= brcmf_init_priv_mem(cfg
);
4892 brcmf_register_event_handlers(cfg
);
4893 mutex_init(&cfg
->usr_sync
);
4894 brcmf_init_escan(cfg
);
4895 brcmf_init_conf(cfg
->conf
);
4896 init_completion(&cfg
->vif_disabled
);
4900 static void wl_deinit_priv(struct brcmf_cfg80211_info
*cfg
)
4902 cfg
->dongle_up
= false; /* dongle down */
4903 brcmf_abort_scanning(cfg
);
4904 brcmf_deinit_priv_mem(cfg
);
4907 static void init_vif_event(struct brcmf_cfg80211_vif_event
*event
)
4909 init_waitqueue_head(&event
->vif_wq
);
4910 mutex_init(&event
->vif_event_lock
);
4914 brcmf_dongle_roam(struct brcmf_if
*ifp
, u32 bcn_timeout
)
4917 __le32 roamtrigger
[2];
4918 __le32 roam_delta
[2];
4921 * Setup timeout if Beacons are lost and roam is
4922 * off to report link down
4924 if (brcmf_roamoff
) {
4925 err
= brcmf_fil_iovar_int_set(ifp
, "bcn_timeout", bcn_timeout
);
4927 brcmf_err("bcn_timeout error (%d)\n", err
);
4928 goto dongle_rom_out
;
4933 * Enable/Disable built-in roaming to allow supplicant
4934 * to take care of roaming
4936 brcmf_dbg(INFO
, "Internal Roaming = %s\n",
4937 brcmf_roamoff
? "Off" : "On");
4938 err
= brcmf_fil_iovar_int_set(ifp
, "roam_off", !!(brcmf_roamoff
));
4940 brcmf_err("roam_off error (%d)\n", err
);
4941 goto dongle_rom_out
;
4944 roamtrigger
[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL
);
4945 roamtrigger
[1] = cpu_to_le32(BRCM_BAND_ALL
);
4946 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_ROAM_TRIGGER
,
4947 (void *)roamtrigger
, sizeof(roamtrigger
));
4949 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err
);
4950 goto dongle_rom_out
;
4953 roam_delta
[0] = cpu_to_le32(WL_ROAM_DELTA
);
4954 roam_delta
[1] = cpu_to_le32(BRCM_BAND_ALL
);
4955 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_ROAM_DELTA
,
4956 (void *)roam_delta
, sizeof(roam_delta
));
4958 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err
);
4959 goto dongle_rom_out
;
4967 brcmf_dongle_scantime(struct brcmf_if
*ifp
, s32 scan_assoc_time
,
4968 s32 scan_unassoc_time
, s32 scan_passive_time
)
4972 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_CHANNEL_TIME
,
4975 if (err
== -EOPNOTSUPP
)
4976 brcmf_dbg(INFO
, "Scan assoc time is not supported\n");
4978 brcmf_err("Scan assoc time error (%d)\n", err
);
4979 goto dongle_scantime_out
;
4981 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_UNASSOC_TIME
,
4984 if (err
== -EOPNOTSUPP
)
4985 brcmf_dbg(INFO
, "Scan unassoc time is not supported\n");
4987 brcmf_err("Scan unassoc time error (%d)\n", err
);
4988 goto dongle_scantime_out
;
4991 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_PASSIVE_TIME
,
4994 if (err
== -EOPNOTSUPP
)
4995 brcmf_dbg(INFO
, "Scan passive time is not supported\n");
4997 brcmf_err("Scan passive time error (%d)\n", err
);
4998 goto dongle_scantime_out
;
5001 dongle_scantime_out
:
5005 /* Filter the list of channels received from firmware counting only
5006 * the 20MHz channels. The wiphy band data only needs those which get
5007 * flagged to indicate if they can take part in higher bandwidth.
5009 static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info
*cfg
,
5010 struct brcmf_chanspec_list
*chlist
,
5013 u32 total
= le32_to_cpu(chlist
->count
);
5014 struct brcmu_chan ch
;
5017 for (i
= 0; i
< total
; i
++) {
5018 ch
.chspec
= (u16
)le32_to_cpu(chlist
->element
[i
]);
5019 cfg
->d11inf
.decchspec(&ch
);
5021 /* Firmware gives a ordered list. We skip non-20MHz
5022 * channels is 2G. For 5G we can abort upon reaching
5023 * a non-20MHz channel in the list.
5025 if (ch
.bw
!= BRCMU_CHAN_BW_20
) {
5026 if (ch
.band
== BRCMU_CHAN_BAND_5G
)
5032 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
5034 else if (ch
.band
== BRCMU_CHAN_BAND_5G
)
5039 static void brcmf_update_bw40_channel_flag(struct ieee80211_channel
*channel
,
5040 struct brcmu_chan
*ch
)
5044 ht40_flag
= channel
->flags
& IEEE80211_CHAN_NO_HT40
;
5045 if (ch
->sb
== BRCMU_CHAN_SB_U
) {
5046 if (ht40_flag
== IEEE80211_CHAN_NO_HT40
)
5047 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40
;
5048 channel
->flags
|= IEEE80211_CHAN_NO_HT40PLUS
;
5050 /* It should be one of
5051 * IEEE80211_CHAN_NO_HT40 or
5052 * IEEE80211_CHAN_NO_HT40PLUS
5054 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40
;
5055 if (ht40_flag
== IEEE80211_CHAN_NO_HT40
)
5056 channel
->flags
|= IEEE80211_CHAN_NO_HT40MINUS
;
5060 static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info
*cfg
,
5063 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5064 struct ieee80211_supported_band
*band
;
5065 struct ieee80211_channel
*channel
;
5066 struct wiphy
*wiphy
;
5067 struct brcmf_chanspec_list
*list
;
5068 struct brcmu_chan ch
;
5074 u32 chcnt
[2] = { 0, 0 };
5077 pbuf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5082 list
= (struct brcmf_chanspec_list
*)pbuf
;
5084 err
= brcmf_fil_iovar_data_get(ifp
, "chanspecs", pbuf
,
5087 brcmf_err("get chanspecs error (%d)\n", err
);
5091 brcmf_count_20mhz_channels(cfg
, list
, chcnt
);
5092 wiphy
= cfg_to_wiphy(cfg
);
5094 band
= kmemdup(&__wl_band_2ghz
, sizeof(__wl_band_2ghz
),
5100 band
->channels
= kcalloc(chcnt
[0], sizeof(*channel
),
5102 if (band
->channels
== NULL
) {
5107 band
->n_channels
= 0;
5108 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
5111 band
= kmemdup(&__wl_band_5ghz_a
, sizeof(__wl_band_5ghz_a
),
5117 band
->channels
= kcalloc(chcnt
[1], sizeof(*channel
),
5119 if (band
->channels
== NULL
) {
5124 band
->n_channels
= 0;
5125 wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
5128 total
= le32_to_cpu(list
->count
);
5129 for (i
= 0; i
< total
; i
++) {
5130 ch
.chspec
= (u16
)le32_to_cpu(list
->element
[i
]);
5131 cfg
->d11inf
.decchspec(&ch
);
5133 if (ch
.band
== BRCMU_CHAN_BAND_2G
) {
5134 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5135 } else if (ch
.band
== BRCMU_CHAN_BAND_5G
) {
5136 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5138 brcmf_err("Invalid channel Spec. 0x%x.\n", ch
.chspec
);
5141 if (!(bw_cap
[band
->band
] & WLC_BW_40MHZ_BIT
) &&
5142 ch
.bw
== BRCMU_CHAN_BW_40
)
5144 if (!(bw_cap
[band
->band
] & WLC_BW_80MHZ_BIT
) &&
5145 ch
.bw
== BRCMU_CHAN_BW_80
)
5148 channel
= band
->channels
;
5149 index
= band
->n_channels
;
5150 for (j
= 0; j
< band
->n_channels
; j
++) {
5151 if (channel
[j
].hw_value
== ch
.chnum
) {
5156 channel
[index
].center_freq
=
5157 ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
5158 channel
[index
].hw_value
= ch
.chnum
;
5160 /* assuming the chanspecs order is HT20,
5161 * HT40 upper, HT40 lower, and VHT80.
5163 if (ch
.bw
== BRCMU_CHAN_BW_80
) {
5164 channel
[index
].flags
&= ~IEEE80211_CHAN_NO_80MHZ
;
5165 } else if (ch
.bw
== BRCMU_CHAN_BW_40
) {
5166 brcmf_update_bw40_channel_flag(&channel
[index
], &ch
);
5168 /* disable other bandwidths for now as mentioned
5169 * order assure they are enabled for subsequent
5172 channel
[index
].flags
= IEEE80211_CHAN_NO_HT40
|
5173 IEEE80211_CHAN_NO_80MHZ
;
5174 ch
.bw
= BRCMU_CHAN_BW_20
;
5175 cfg
->d11inf
.encchspec(&ch
);
5176 chaninfo
= ch
.chspec
;
5177 err
= brcmf_fil_bsscfg_int_get(ifp
, "per_chan_info",
5180 if (chaninfo
& WL_CHAN_RADAR
)
5181 channel
[index
].flags
|=
5182 (IEEE80211_CHAN_RADAR
|
5183 IEEE80211_CHAN_NO_IR
);
5184 if (chaninfo
& WL_CHAN_PASSIVE
)
5185 channel
[index
].flags
|=
5186 IEEE80211_CHAN_NO_IR
;
5189 if (index
== band
->n_channels
)
5196 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]->channels
);
5197 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]);
5198 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
5204 static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info
*cfg
)
5206 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5207 struct ieee80211_supported_band
*band
;
5208 struct brcmf_fil_bwcap_le band_bwcap
;
5209 struct brcmf_chanspec_list
*list
;
5213 struct brcmu_chan ch
;
5217 /* verify support for bw_cap command */
5219 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &val
);
5222 /* only set 2G bandwidth using bw_cap command */
5223 band_bwcap
.band
= cpu_to_le32(WLC_BAND_2G
);
5224 band_bwcap
.bw_cap
= cpu_to_le32(WLC_BW_CAP_40MHZ
);
5225 err
= brcmf_fil_iovar_data_set(ifp
, "bw_cap", &band_bwcap
,
5226 sizeof(band_bwcap
));
5228 brcmf_dbg(INFO
, "fallback to mimo_bw_cap\n");
5229 val
= WLC_N_BW_40ALL
;
5230 err
= brcmf_fil_iovar_int_set(ifp
, "mimo_bw_cap", val
);
5234 /* update channel info in 2G band */
5235 pbuf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5240 ch
.band
= BRCMU_CHAN_BAND_2G
;
5241 ch
.bw
= BRCMU_CHAN_BW_40
;
5242 ch
.sb
= BRCMU_CHAN_SB_NONE
;
5244 cfg
->d11inf
.encchspec(&ch
);
5246 /* pass encoded chanspec in query */
5247 *(__le16
*)pbuf
= cpu_to_le16(ch
.chspec
);
5249 err
= brcmf_fil_iovar_data_get(ifp
, "chanspecs", pbuf
,
5252 brcmf_err("get chanspecs error (%d)\n", err
);
5257 band
= cfg_to_wiphy(cfg
)->bands
[IEEE80211_BAND_2GHZ
];
5258 list
= (struct brcmf_chanspec_list
*)pbuf
;
5259 num_chan
= le32_to_cpu(list
->count
);
5260 for (i
= 0; i
< num_chan
; i
++) {
5261 ch
.chspec
= (u16
)le32_to_cpu(list
->element
[i
]);
5262 cfg
->d11inf
.decchspec(&ch
);
5263 if (WARN_ON(ch
.band
!= BRCMU_CHAN_BAND_2G
))
5265 if (WARN_ON(ch
.bw
!= BRCMU_CHAN_BW_40
))
5267 for (j
= 0; j
< band
->n_channels
; j
++) {
5268 if (band
->channels
[j
].hw_value
== ch
.chnum
)
5271 if (WARN_ON(j
== band
->n_channels
))
5274 brcmf_update_bw40_channel_flag(&band
->channels
[j
], &ch
);
5281 static void brcmf_get_bwcap(struct brcmf_if
*ifp
, u32 bw_cap
[])
5283 u32 band
, mimo_bwcap
;
5287 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &band
);
5289 bw_cap
[IEEE80211_BAND_2GHZ
] = band
;
5291 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &band
);
5293 bw_cap
[IEEE80211_BAND_5GHZ
] = band
;
5299 brcmf_dbg(INFO
, "fallback to mimo_bw_cap info\n");
5301 err
= brcmf_fil_iovar_int_get(ifp
, "mimo_bw_cap", &mimo_bwcap
);
5303 /* assume 20MHz if firmware does not give a clue */
5304 mimo_bwcap
= WLC_N_BW_20ALL
;
5306 switch (mimo_bwcap
) {
5307 case WLC_N_BW_40ALL
:
5308 bw_cap
[IEEE80211_BAND_2GHZ
] |= WLC_BW_40MHZ_BIT
;
5310 case WLC_N_BW_20IN2G_40IN5G
:
5311 bw_cap
[IEEE80211_BAND_5GHZ
] |= WLC_BW_40MHZ_BIT
;
5313 case WLC_N_BW_20ALL
:
5314 bw_cap
[IEEE80211_BAND_2GHZ
] |= WLC_BW_20MHZ_BIT
;
5315 bw_cap
[IEEE80211_BAND_5GHZ
] |= WLC_BW_20MHZ_BIT
;
5318 brcmf_err("invalid mimo_bw_cap value\n");
5322 static void brcmf_update_ht_cap(struct ieee80211_supported_band
*band
,
5323 u32 bw_cap
[2], u32 nchain
)
5325 band
->ht_cap
.ht_supported
= true;
5326 if (bw_cap
[band
->band
] & WLC_BW_40MHZ_BIT
) {
5327 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
5328 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5330 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
5331 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
5332 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
5333 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
5334 memset(band
->ht_cap
.mcs
.rx_mask
, 0xff, nchain
);
5335 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
5338 static __le16
brcmf_get_mcs_map(u32 nchain
, enum ieee80211_vht_mcs_support supp
)
5343 for (i
= 0, mcs_map
= 0xFFFF; i
< nchain
; i
++)
5344 mcs_map
= (mcs_map
<< 2) | supp
;
5346 return cpu_to_le16(mcs_map
);
5349 static void brcmf_update_vht_cap(struct ieee80211_supported_band
*band
,
5350 u32 bw_cap
[2], u32 nchain
)
5354 /* not allowed in 2.4G band */
5355 if (band
->band
== IEEE80211_BAND_2GHZ
)
5358 band
->vht_cap
.vht_supported
= true;
5359 /* 80MHz is mandatory */
5360 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SHORT_GI_80
;
5361 if (bw_cap
[band
->band
] & WLC_BW_160MHZ_BIT
) {
5362 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
5363 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SHORT_GI_160
;
5365 /* all support 256-QAM */
5366 mcs_map
= brcmf_get_mcs_map(nchain
, IEEE80211_VHT_MCS_SUPPORT_0_9
);
5367 band
->vht_cap
.vht_mcs
.rx_mcs_map
= mcs_map
;
5368 band
->vht_cap
.vht_mcs
.tx_mcs_map
= mcs_map
;
5371 static int brcmf_setup_wiphybands(struct wiphy
*wiphy
)
5373 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
5374 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5377 u32 bw_cap
[2] = { WLC_BW_20MHZ_BIT
, WLC_BW_20MHZ_BIT
};
5382 struct ieee80211_supported_band
*band
;
5384 (void)brcmf_fil_iovar_int_get(ifp
, "vhtmode", &vhtmode
);
5385 err
= brcmf_fil_iovar_int_get(ifp
, "nmode", &nmode
);
5387 brcmf_err("nmode error (%d)\n", err
);
5389 brcmf_get_bwcap(ifp
, bw_cap
);
5391 brcmf_dbg(INFO
, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5392 nmode
, vhtmode
, bw_cap
[IEEE80211_BAND_2GHZ
],
5393 bw_cap
[IEEE80211_BAND_5GHZ
]);
5395 err
= brcmf_fil_iovar_int_get(ifp
, "rxchain", &rxchain
);
5397 brcmf_err("rxchain error (%d)\n", err
);
5400 for (nchain
= 0; rxchain
; nchain
++)
5401 rxchain
= rxchain
& (rxchain
- 1);
5403 brcmf_dbg(INFO
, "nchain=%d\n", nchain
);
5405 err
= brcmf_construct_chaninfo(cfg
, bw_cap
);
5407 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err
);
5411 wiphy
= cfg_to_wiphy(cfg
);
5412 for (i
= 0; i
< ARRAY_SIZE(wiphy
->bands
); i
++) {
5413 band
= wiphy
->bands
[i
];
5418 brcmf_update_ht_cap(band
, bw_cap
, nchain
);
5420 brcmf_update_vht_cap(band
, bw_cap
, nchain
);
5426 static const struct ieee80211_iface_limit brcmf_iface_limits
[] = {
5429 .types
= BIT(NL80211_IFTYPE_STATION
) |
5430 BIT(NL80211_IFTYPE_ADHOC
) |
5431 BIT(NL80211_IFTYPE_AP
)
5435 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5436 BIT(NL80211_IFTYPE_P2P_GO
)
5440 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5443 static struct ieee80211_iface_combination brcmf_iface_combos
[] = {
5445 .max_interfaces
= BRCMF_IFACE_MAX_CNT
,
5446 .num_different_channels
= 1,
5447 .n_limits
= ARRAY_SIZE(brcmf_iface_limits
),
5448 .limits
= brcmf_iface_limits
5452 static const struct ieee80211_txrx_stypes
5453 brcmf_txrx_stypes
[NUM_NL80211_IFTYPES
] = {
5454 [NL80211_IFTYPE_STATION
] = {
5456 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5457 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5459 [NL80211_IFTYPE_P2P_CLIENT
] = {
5461 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5462 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5464 [NL80211_IFTYPE_P2P_GO
] = {
5466 .rx
= BIT(IEEE80211_STYPE_ASSOC_REQ
>> 4) |
5467 BIT(IEEE80211_STYPE_REASSOC_REQ
>> 4) |
5468 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4) |
5469 BIT(IEEE80211_STYPE_DISASSOC
>> 4) |
5470 BIT(IEEE80211_STYPE_AUTH
>> 4) |
5471 BIT(IEEE80211_STYPE_DEAUTH
>> 4) |
5472 BIT(IEEE80211_STYPE_ACTION
>> 4)
5474 [NL80211_IFTYPE_P2P_DEVICE
] = {
5476 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5477 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5481 static void brcmf_wiphy_pno_params(struct wiphy
*wiphy
)
5483 /* scheduled scan settings */
5484 wiphy
->max_sched_scan_ssids
= BRCMF_PNO_MAX_PFN_COUNT
;
5485 wiphy
->max_match_sets
= BRCMF_PNO_MAX_PFN_COUNT
;
5486 wiphy
->max_sched_scan_ie_len
= BRCMF_SCAN_IE_LEN_MAX
;
5487 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
5491 static const struct wiphy_wowlan_support brcmf_wowlan_support
= {
5492 .flags
= WIPHY_WOWLAN_MAGIC_PKT
| WIPHY_WOWLAN_DISCONNECT
,
5493 .n_patterns
= BRCMF_WOWL_MAXPATTERNS
,
5494 .pattern_max_len
= BRCMF_WOWL_MAXPATTERNSIZE
,
5495 .pattern_min_len
= 1,
5496 .max_pkt_offset
= 1500,
5500 static void brcmf_wiphy_wowl_params(struct wiphy
*wiphy
)
5504 wiphy
->wowlan
= &brcmf_wowlan_support
;
5508 static int brcmf_setup_wiphy(struct wiphy
*wiphy
, struct brcmf_if
*ifp
)
5510 struct ieee80211_iface_combination ifc_combo
;
5511 wiphy
->max_scan_ssids
= WL_NUM_SCAN_MAX
;
5512 wiphy
->max_scan_ie_len
= BRCMF_SCAN_IE_LEN_MAX
;
5513 wiphy
->max_num_pmkids
= WL_NUM_PMKIDS_MAX
;
5514 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5515 BIT(NL80211_IFTYPE_ADHOC
) |
5516 BIT(NL80211_IFTYPE_AP
) |
5517 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5518 BIT(NL80211_IFTYPE_P2P_GO
) |
5519 BIT(NL80211_IFTYPE_P2P_DEVICE
);
5520 /* need VSDB firmware feature for concurrent channels */
5521 ifc_combo
= brcmf_iface_combos
[0];
5522 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_MCHAN
))
5523 ifc_combo
.num_different_channels
= 2;
5524 wiphy
->iface_combinations
= kmemdup(&ifc_combo
,
5527 wiphy
->n_iface_combinations
= ARRAY_SIZE(brcmf_iface_combos
);
5528 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
5529 wiphy
->cipher_suites
= __wl_cipher_suites
;
5530 wiphy
->n_cipher_suites
= ARRAY_SIZE(__wl_cipher_suites
);
5531 wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
|
5532 WIPHY_FLAG_OFFCHAN_TX
|
5533 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
|
5534 WIPHY_FLAG_SUPPORTS_TDLS
;
5536 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_FW_ROAM
;
5537 wiphy
->mgmt_stypes
= brcmf_txrx_stypes
;
5538 wiphy
->max_remain_on_channel_duration
= 5000;
5539 brcmf_wiphy_pno_params(wiphy
);
5541 /* vendor commands/events support */
5542 wiphy
->vendor_commands
= brcmf_vendor_cmds
;
5543 wiphy
->n_vendor_commands
= BRCMF_VNDR_CMDS_LAST
- 1;
5545 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_WOWL
))
5546 brcmf_wiphy_wowl_params(wiphy
);
5548 return brcmf_setup_wiphybands(wiphy
);
5551 static s32
brcmf_config_dongle(struct brcmf_cfg80211_info
*cfg
)
5553 struct net_device
*ndev
;
5554 struct wireless_dev
*wdev
;
5555 struct brcmf_if
*ifp
;
5562 ndev
= cfg_to_ndev(cfg
);
5563 wdev
= ndev
->ieee80211_ptr
;
5564 ifp
= netdev_priv(ndev
);
5566 /* make sure RF is ready for work */
5567 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
5569 brcmf_dongle_scantime(ifp
, WL_SCAN_CHANNEL_TIME
,
5570 WL_SCAN_UNASSOC_TIME
, WL_SCAN_PASSIVE_TIME
);
5572 power_mode
= cfg
->pwr_save
? PM_FAST
: PM_OFF
;
5573 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, power_mode
);
5575 goto default_conf_out
;
5576 brcmf_dbg(INFO
, "power save set to %s\n",
5577 (power_mode
? "enabled" : "disabled"));
5579 err
= brcmf_dongle_roam(ifp
, WL_BEACON_TIMEOUT
);
5581 goto default_conf_out
;
5582 err
= brcmf_cfg80211_change_iface(wdev
->wiphy
, ndev
, wdev
->iftype
,
5585 goto default_conf_out
;
5587 brcmf_configure_arp_offload(ifp
, true);
5589 cfg
->dongle_up
= true;
5596 static s32
__brcmf_cfg80211_up(struct brcmf_if
*ifp
)
5598 set_bit(BRCMF_VIF_STATUS_READY
, &ifp
->vif
->sme_state
);
5600 return brcmf_config_dongle(ifp
->drvr
->config
);
5603 static s32
__brcmf_cfg80211_down(struct brcmf_if
*ifp
)
5605 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5608 * While going down, if associated with AP disassociate
5609 * from AP to save power
5611 if (check_vif_up(ifp
->vif
)) {
5612 brcmf_link_down(ifp
->vif
);
5614 /* Make sure WPA_Supplicant receives all the event
5615 generated due to DISASSOC call to the fw to keep
5616 the state fw and WPA_Supplicant state consistent
5621 brcmf_abort_scanning(cfg
);
5622 clear_bit(BRCMF_VIF_STATUS_READY
, &ifp
->vif
->sme_state
);
5627 s32
brcmf_cfg80211_up(struct net_device
*ndev
)
5629 struct brcmf_if
*ifp
= netdev_priv(ndev
);
5630 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5633 mutex_lock(&cfg
->usr_sync
);
5634 err
= __brcmf_cfg80211_up(ifp
);
5635 mutex_unlock(&cfg
->usr_sync
);
5640 s32
brcmf_cfg80211_down(struct net_device
*ndev
)
5642 struct brcmf_if
*ifp
= netdev_priv(ndev
);
5643 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5646 mutex_lock(&cfg
->usr_sync
);
5647 err
= __brcmf_cfg80211_down(ifp
);
5648 mutex_unlock(&cfg
->usr_sync
);
5653 enum nl80211_iftype
brcmf_cfg80211_get_iftype(struct brcmf_if
*ifp
)
5655 struct wireless_dev
*wdev
= &ifp
->vif
->wdev
;
5657 return wdev
->iftype
;
5660 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info
*cfg
,
5661 unsigned long state
)
5663 struct brcmf_cfg80211_vif
*vif
;
5665 list_for_each_entry(vif
, &cfg
->vif_list
, list
) {
5666 if (test_bit(state
, &vif
->sme_state
))
5672 static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event
*event
,
5677 mutex_lock(&event
->vif_event_lock
);
5678 evt_action
= event
->action
;
5679 mutex_unlock(&event
->vif_event_lock
);
5680 return evt_action
== action
;
5683 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info
*cfg
,
5684 struct brcmf_cfg80211_vif
*vif
)
5686 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5688 mutex_lock(&event
->vif_event_lock
);
5691 mutex_unlock(&event
->vif_event_lock
);
5694 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info
*cfg
)
5696 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5699 mutex_lock(&event
->vif_event_lock
);
5700 armed
= event
->vif
!= NULL
;
5701 mutex_unlock(&event
->vif_event_lock
);
5705 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info
*cfg
,
5706 u8 action
, ulong timeout
)
5708 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5710 return wait_event_timeout(event
->vif_wq
,
5711 vif_event_equals(event
, action
), timeout
);
5714 static void brcmf_free_wiphy(struct wiphy
*wiphy
)
5716 kfree(wiphy
->iface_combinations
);
5717 if (wiphy
->bands
[IEEE80211_BAND_2GHZ
]) {
5718 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]->channels
);
5719 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]);
5721 if (wiphy
->bands
[IEEE80211_BAND_5GHZ
]) {
5722 kfree(wiphy
->bands
[IEEE80211_BAND_5GHZ
]->channels
);
5723 kfree(wiphy
->bands
[IEEE80211_BAND_5GHZ
]);
5728 struct brcmf_cfg80211_info
*brcmf_cfg80211_attach(struct brcmf_pub
*drvr
,
5729 struct device
*busdev
)
5731 struct net_device
*ndev
= drvr
->iflist
[0]->ndev
;
5732 struct brcmf_cfg80211_info
*cfg
;
5733 struct wiphy
*wiphy
;
5734 struct brcmf_cfg80211_vif
*vif
;
5735 struct brcmf_if
*ifp
;
5741 brcmf_err("ndev is invalid\n");
5745 ifp
= netdev_priv(ndev
);
5746 wiphy
= wiphy_new(&wl_cfg80211_ops
, sizeof(struct brcmf_cfg80211_info
));
5748 brcmf_err("Could not allocate wiphy device\n");
5751 set_wiphy_dev(wiphy
, busdev
);
5753 cfg
= wiphy_priv(wiphy
);
5756 init_vif_event(&cfg
->vif_event
);
5757 INIT_LIST_HEAD(&cfg
->vif_list
);
5759 vif
= brcmf_alloc_vif(cfg
, NL80211_IFTYPE_STATION
, false);
5764 vif
->wdev
.netdev
= ndev
;
5765 ndev
->ieee80211_ptr
= &vif
->wdev
;
5766 SET_NETDEV_DEV(ndev
, wiphy_dev(cfg
->wiphy
));
5768 err
= wl_init_priv(cfg
);
5770 brcmf_err("Failed to init iwm_priv (%d)\n", err
);
5771 brcmf_free_vif(vif
);
5776 /* determine d11 io type before wiphy setup */
5777 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_VERSION
, &io_type
);
5779 brcmf_err("Failed to get D11 version (%d)\n", err
);
5782 cfg
->d11inf
.io_type
= (u8
)io_type
;
5783 brcmu_d11_attach(&cfg
->d11inf
);
5785 err
= brcmf_setup_wiphy(wiphy
, ifp
);
5789 brcmf_dbg(INFO
, "Registering custom regulatory\n");
5790 wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
;
5791 wiphy_apply_custom_regulatory(wiphy
, &brcmf_regdom
);
5793 /* firmware defaults to 40MHz disabled in 2G band. We signal
5794 * cfg80211 here that we do and have it decide we can enable
5795 * it. But first check if device does support 2G operation.
5797 if (wiphy
->bands
[IEEE80211_BAND_2GHZ
]) {
5798 cap
= &wiphy
->bands
[IEEE80211_BAND_2GHZ
]->ht_cap
.cap
;
5799 *cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5801 err
= wiphy_register(wiphy
);
5803 brcmf_err("Could not register wiphy device (%d)\n", err
);
5807 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
5808 * setup 40MHz in 2GHz band and enable OBSS scanning.
5810 if (cap
&& (*cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)) {
5811 err
= brcmf_enable_bw40_2g(cfg
);
5813 err
= brcmf_fil_iovar_int_set(ifp
, "obss_coex",
5814 BRCMF_OBSS_COEX_AUTO
);
5816 *cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5819 err
= brcmf_p2p_attach(cfg
);
5821 brcmf_err("P2P initilisation failed (%d)\n", err
);
5822 goto wiphy_unreg_out
;
5824 err
= brcmf_btcoex_attach(cfg
);
5826 brcmf_err("BT-coex initialisation failed (%d)\n", err
);
5827 brcmf_p2p_detach(&cfg
->p2p
);
5828 goto wiphy_unreg_out
;
5831 err
= brcmf_fil_iovar_int_set(ifp
, "tdls_enable", 1);
5833 brcmf_dbg(INFO
, "TDLS not enabled (%d)\n", err
);
5834 wiphy
->flags
&= ~WIPHY_FLAG_SUPPORTS_TDLS
;
5836 brcmf_fweh_register(cfg
->pub
, BRCMF_E_TDLS_PEER_EVENT
,
5837 brcmf_notify_tdls_peer_event
);
5843 wiphy_unregister(cfg
->wiphy
);
5845 wl_deinit_priv(cfg
);
5846 brcmf_free_vif(vif
);
5848 brcmf_free_wiphy(wiphy
);
5852 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info
*cfg
)
5857 WARN_ON(!list_empty(&cfg
->vif_list
));
5858 wiphy_unregister(cfg
->wiphy
);
5859 brcmf_btcoex_detach(cfg
);
5860 brcmf_p2p_detach(&cfg
->p2p
);
5861 wl_deinit_priv(cfg
);
5862 brcmf_free_wiphy(cfg
->wiphy
);