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 case NL80211_CHAN_WIDTH_20_NOHT
:
303 ch_inf
.bw
= BRCMU_CHAN_BW_20
;
304 WARN_ON(primary_offset
!= 0);
306 case NL80211_CHAN_WIDTH_40
:
307 ch_inf
.bw
= BRCMU_CHAN_BW_40
;
308 if (primary_offset
< 0)
309 ch_inf
.sb
= BRCMU_CHAN_SB_U
;
311 ch_inf
.sb
= BRCMU_CHAN_SB_L
;
313 case NL80211_CHAN_WIDTH_80
:
314 ch_inf
.bw
= BRCMU_CHAN_BW_80
;
315 if (primary_offset
< 0) {
316 if (primary_offset
< -CH_10MHZ_APART
)
317 ch_inf
.sb
= BRCMU_CHAN_SB_UU
;
319 ch_inf
.sb
= BRCMU_CHAN_SB_UL
;
321 if (primary_offset
> CH_10MHZ_APART
)
322 ch_inf
.sb
= BRCMU_CHAN_SB_LL
;
324 ch_inf
.sb
= BRCMU_CHAN_SB_LU
;
327 case NL80211_CHAN_WIDTH_80P80
:
328 case NL80211_CHAN_WIDTH_160
:
329 case NL80211_CHAN_WIDTH_5
:
330 case NL80211_CHAN_WIDTH_10
:
334 switch (ch
->chan
->band
) {
335 case IEEE80211_BAND_2GHZ
:
336 ch_inf
.band
= BRCMU_CHAN_BAND_2G
;
338 case IEEE80211_BAND_5GHZ
:
339 ch_inf
.band
= BRCMU_CHAN_BAND_5G
;
341 case IEEE80211_BAND_60GHZ
:
345 d11inf
->encchspec(&ch_inf
);
347 return ch_inf
.chspec
;
350 u16
channel_to_chanspec(struct brcmu_d11inf
*d11inf
,
351 struct ieee80211_channel
*ch
)
353 struct brcmu_chan ch_inf
;
355 ch_inf
.chnum
= ieee80211_frequency_to_channel(ch
->center_freq
);
356 ch_inf
.bw
= BRCMU_CHAN_BW_20
;
357 d11inf
->encchspec(&ch_inf
);
359 return ch_inf
.chspec
;
362 /* Traverse a string of 1-byte tag/1-byte length/variable-length value
363 * triples, returning a pointer to the substring whose first element
366 const struct brcmf_tlv
*
367 brcmf_parse_tlvs(const void *buf
, int buflen
, uint key
)
369 const struct brcmf_tlv
*elt
= buf
;
372 /* find tagged parameter */
373 while (totlen
>= TLV_HDR_LEN
) {
376 /* validate remaining totlen */
377 if ((elt
->id
== key
) && (totlen
>= (len
+ TLV_HDR_LEN
)))
380 elt
= (struct brcmf_tlv
*)((u8
*)elt
+ (len
+ TLV_HDR_LEN
));
381 totlen
-= (len
+ TLV_HDR_LEN
);
387 /* Is any of the tlvs the expected entry? If
388 * not update the tlvs buffer pointer/length.
391 brcmf_tlv_has_ie(const u8
*ie
, const u8
**tlvs
, u32
*tlvs_len
,
392 const u8
*oui
, u32 oui_len
, u8 type
)
394 /* If the contents match the OUI and the type */
395 if (ie
[TLV_LEN_OFF
] >= oui_len
+ 1 &&
396 !memcmp(&ie
[TLV_BODY_OFF
], oui
, oui_len
) &&
397 type
== ie
[TLV_BODY_OFF
+ oui_len
]) {
403 /* point to the next ie */
404 ie
+= ie
[TLV_LEN_OFF
] + TLV_HDR_LEN
;
405 /* calculate the length of the rest of the buffer */
406 *tlvs_len
-= (int)(ie
- *tlvs
);
407 /* update the pointer to the start of the buffer */
413 static struct brcmf_vs_tlv
*
414 brcmf_find_wpaie(const u8
*parse
, u32 len
)
416 const struct brcmf_tlv
*ie
;
418 while ((ie
= brcmf_parse_tlvs(parse
, len
, WLAN_EID_VENDOR_SPECIFIC
))) {
419 if (brcmf_tlv_has_ie((const u8
*)ie
, &parse
, &len
,
420 WPA_OUI
, TLV_OUI_LEN
, WPA_OUI_TYPE
))
421 return (struct brcmf_vs_tlv
*)ie
;
426 static struct brcmf_vs_tlv
*
427 brcmf_find_wpsie(const u8
*parse
, u32 len
)
429 const struct brcmf_tlv
*ie
;
431 while ((ie
= brcmf_parse_tlvs(parse
, len
, WLAN_EID_VENDOR_SPECIFIC
))) {
432 if (brcmf_tlv_has_ie((u8
*)ie
, &parse
, &len
,
433 WPA_OUI
, TLV_OUI_LEN
, WPS_OUI_TYPE
))
434 return (struct brcmf_vs_tlv
*)ie
;
440 static void convert_key_from_CPU(struct brcmf_wsec_key
*key
,
441 struct brcmf_wsec_key_le
*key_le
)
443 key_le
->index
= cpu_to_le32(key
->index
);
444 key_le
->len
= cpu_to_le32(key
->len
);
445 key_le
->algo
= cpu_to_le32(key
->algo
);
446 key_le
->flags
= cpu_to_le32(key
->flags
);
447 key_le
->rxiv
.hi
= cpu_to_le32(key
->rxiv
.hi
);
448 key_le
->rxiv
.lo
= cpu_to_le16(key
->rxiv
.lo
);
449 key_le
->iv_initialized
= cpu_to_le32(key
->iv_initialized
);
450 memcpy(key_le
->data
, key
->data
, sizeof(key
->data
));
451 memcpy(key_le
->ea
, key
->ea
, sizeof(key
->ea
));
455 send_key_to_dongle(struct net_device
*ndev
, struct brcmf_wsec_key
*key
)
458 struct brcmf_wsec_key_le key_le
;
460 convert_key_from_CPU(key
, &key_le
);
462 brcmf_netdev_wait_pend8021x(ndev
);
464 err
= brcmf_fil_bsscfg_data_set(netdev_priv(ndev
), "wsec_key", &key_le
,
468 brcmf_err("wsec_key error (%d)\n", err
);
473 brcmf_configure_arp_offload(struct brcmf_if
*ifp
, bool enable
)
479 mode
= BRCMF_ARP_OL_AGENT
| BRCMF_ARP_OL_PEER_AUTO_REPLY
;
483 /* Try to set and enable ARP offload feature, this may fail, then it */
484 /* is simply not supported and err 0 will be returned */
485 err
= brcmf_fil_iovar_int_set(ifp
, "arp_ol", mode
);
487 brcmf_dbg(TRACE
, "failed to set ARP offload mode to 0x%x, err = %d\n",
491 err
= brcmf_fil_iovar_int_set(ifp
, "arpoe", enable
);
493 brcmf_dbg(TRACE
, "failed to configure (%d) ARP offload err = %d\n",
497 brcmf_dbg(TRACE
, "successfully configured (%d) ARP offload to 0x%x\n",
505 brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev
*wdev
)
507 struct brcmf_cfg80211_vif
*vif
;
508 struct brcmf_if
*ifp
;
510 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
513 if ((wdev
->iftype
== NL80211_IFTYPE_ADHOC
) ||
514 (wdev
->iftype
== NL80211_IFTYPE_AP
) ||
515 (wdev
->iftype
== NL80211_IFTYPE_P2P_GO
))
516 brcmf_proto_configure_addr_mode(ifp
->drvr
, ifp
->ifidx
,
519 brcmf_proto_configure_addr_mode(ifp
->drvr
, ifp
->ifidx
,
523 static bool brcmf_is_apmode(struct brcmf_cfg80211_vif
*vif
)
525 enum nl80211_iftype iftype
;
527 iftype
= vif
->wdev
.iftype
;
528 return iftype
== NL80211_IFTYPE_AP
|| iftype
== NL80211_IFTYPE_P2P_GO
;
531 static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif
*vif
)
533 return vif
->wdev
.iftype
== NL80211_IFTYPE_ADHOC
;
536 static struct wireless_dev
*brcmf_cfg80211_add_iface(struct wiphy
*wiphy
,
538 enum nl80211_iftype type
,
540 struct vif_params
*params
)
542 struct wireless_dev
*wdev
;
544 brcmf_dbg(TRACE
, "enter: %s type %d\n", name
, type
);
546 case NL80211_IFTYPE_ADHOC
:
547 case NL80211_IFTYPE_STATION
:
548 case NL80211_IFTYPE_AP
:
549 case NL80211_IFTYPE_AP_VLAN
:
550 case NL80211_IFTYPE_WDS
:
551 case NL80211_IFTYPE_MONITOR
:
552 case NL80211_IFTYPE_MESH_POINT
:
553 return ERR_PTR(-EOPNOTSUPP
);
554 case NL80211_IFTYPE_P2P_CLIENT
:
555 case NL80211_IFTYPE_P2P_GO
:
556 case NL80211_IFTYPE_P2P_DEVICE
:
557 wdev
= brcmf_p2p_add_vif(wiphy
, name
, type
, flags
, params
);
559 brcmf_cfg80211_update_proto_addr_mode(wdev
);
561 case NL80211_IFTYPE_UNSPECIFIED
:
563 return ERR_PTR(-EINVAL
);
567 static void brcmf_scan_config_mpc(struct brcmf_if
*ifp
, int mpc
)
569 if (brcmf_feat_is_quirk_enabled(ifp
, BRCMF_FEAT_QUIRK_NEED_MPC
))
570 brcmf_set_mpc(ifp
, mpc
);
573 void brcmf_set_mpc(struct brcmf_if
*ifp
, int mpc
)
577 if (check_vif_up(ifp
->vif
)) {
578 err
= brcmf_fil_iovar_int_set(ifp
, "mpc", mpc
);
580 brcmf_err("fail to set mpc\n");
583 brcmf_dbg(INFO
, "MPC : %d\n", mpc
);
587 s32
brcmf_notify_escan_complete(struct brcmf_cfg80211_info
*cfg
,
588 struct brcmf_if
*ifp
, bool aborted
,
591 struct brcmf_scan_params_le params_le
;
592 struct cfg80211_scan_request
*scan_request
;
595 brcmf_dbg(SCAN
, "Enter\n");
597 /* clear scan request, because the FW abort can cause a second call */
598 /* to this functon and might cause a double cfg80211_scan_done */
599 scan_request
= cfg
->scan_request
;
600 cfg
->scan_request
= NULL
;
602 if (timer_pending(&cfg
->escan_timeout
))
603 del_timer_sync(&cfg
->escan_timeout
);
606 /* Do a scan abort to stop the driver's scan engine */
607 brcmf_dbg(SCAN
, "ABORT scan in firmware\n");
608 memset(¶ms_le
, 0, sizeof(params_le
));
609 memset(params_le
.bssid
, 0xFF, ETH_ALEN
);
610 params_le
.bss_type
= DOT11_BSSTYPE_ANY
;
611 params_le
.scan_type
= 0;
612 params_le
.channel_num
= cpu_to_le32(1);
613 params_le
.nprobes
= cpu_to_le32(1);
614 params_le
.active_time
= cpu_to_le32(-1);
615 params_le
.passive_time
= cpu_to_le32(-1);
616 params_le
.home_time
= cpu_to_le32(-1);
617 /* Scan is aborted by setting channel_list[0] to -1 */
618 params_le
.channel_list
[0] = cpu_to_le16(-1);
619 /* E-Scan (or anyother type) can be aborted by SCAN */
620 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCAN
,
621 ¶ms_le
, sizeof(params_le
));
623 brcmf_err("Scan abort failed\n");
626 brcmf_scan_config_mpc(ifp
, 1);
629 * e-scan can be initiated by scheduled scan
630 * which takes precedence.
632 if (cfg
->sched_escan
) {
633 brcmf_dbg(SCAN
, "scheduled scan completed\n");
634 cfg
->sched_escan
= false;
636 cfg80211_sched_scan_results(cfg_to_wiphy(cfg
));
637 } else if (scan_request
) {
638 brcmf_dbg(SCAN
, "ESCAN Completed scan: %s\n",
639 aborted
? "Aborted" : "Done");
640 cfg80211_scan_done(scan_request
, aborted
);
642 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
643 brcmf_dbg(SCAN
, "Scan complete, probably P2P scan\n");
649 int brcmf_cfg80211_del_iface(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
651 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
652 struct net_device
*ndev
= wdev
->netdev
;
654 /* vif event pending in firmware */
655 if (brcmf_cfg80211_vif_event_armed(cfg
))
659 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
) &&
660 cfg
->escan_info
.ifp
== netdev_priv(ndev
))
661 brcmf_notify_escan_complete(cfg
, netdev_priv(ndev
),
664 brcmf_fil_iovar_int_set(netdev_priv(ndev
), "mpc", 1);
667 switch (wdev
->iftype
) {
668 case NL80211_IFTYPE_ADHOC
:
669 case NL80211_IFTYPE_STATION
:
670 case NL80211_IFTYPE_AP
:
671 case NL80211_IFTYPE_AP_VLAN
:
672 case NL80211_IFTYPE_WDS
:
673 case NL80211_IFTYPE_MONITOR
:
674 case NL80211_IFTYPE_MESH_POINT
:
676 case NL80211_IFTYPE_P2P_CLIENT
:
677 case NL80211_IFTYPE_P2P_GO
:
678 case NL80211_IFTYPE_P2P_DEVICE
:
679 return brcmf_p2p_del_vif(wiphy
, wdev
);
680 case NL80211_IFTYPE_UNSPECIFIED
:
688 brcmf_cfg80211_change_iface(struct wiphy
*wiphy
, struct net_device
*ndev
,
689 enum nl80211_iftype type
, u32
*flags
,
690 struct vif_params
*params
)
692 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
693 struct brcmf_if
*ifp
= netdev_priv(ndev
);
694 struct brcmf_cfg80211_vif
*vif
= ifp
->vif
;
699 brcmf_dbg(TRACE
, "Enter, ndev=%p, type=%d\n", ndev
, type
);
702 case NL80211_IFTYPE_MONITOR
:
703 case NL80211_IFTYPE_WDS
:
704 brcmf_err("type (%d) : currently we do not support this type\n",
707 case NL80211_IFTYPE_ADHOC
:
710 case NL80211_IFTYPE_STATION
:
711 /* Ignore change for p2p IF. Unclear why supplicant does this */
712 if ((vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_CLIENT
) ||
713 (vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_GO
)) {
714 brcmf_dbg(TRACE
, "Ignoring cmd for p2p if\n");
715 /* WAR: It is unexpected to get a change of VIF for P2P
716 * IF, but it happens. The request can not be handled
717 * but returning EPERM causes a crash. Returning 0
718 * without setting ieee80211_ptr->iftype causes trace
719 * (WARN_ON) but it works with wpa_supplicant
725 case NL80211_IFTYPE_AP
:
726 case NL80211_IFTYPE_P2P_GO
:
735 if (type
== NL80211_IFTYPE_P2P_GO
) {
736 brcmf_dbg(INFO
, "IF Type = P2P GO\n");
737 err
= brcmf_p2p_ifchange(cfg
, BRCMF_FIL_P2P_IF_GO
);
740 set_bit(BRCMF_VIF_STATUS_AP_CREATING
, &vif
->sme_state
);
741 brcmf_dbg(INFO
, "IF Type = AP\n");
744 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, infra
);
746 brcmf_err("WLC_SET_INFRA error (%d)\n", err
);
750 brcmf_dbg(INFO
, "IF Type = %s\n", brcmf_is_ibssmode(vif
) ?
753 ndev
->ieee80211_ptr
->iftype
= type
;
755 brcmf_cfg80211_update_proto_addr_mode(&vif
->wdev
);
758 brcmf_dbg(TRACE
, "Exit\n");
763 static void brcmf_escan_prep(struct brcmf_cfg80211_info
*cfg
,
764 struct brcmf_scan_params_le
*params_le
,
765 struct cfg80211_scan_request
*request
)
773 struct brcmf_ssid_le ssid_le
;
775 memset(params_le
->bssid
, 0xFF, ETH_ALEN
);
776 params_le
->bss_type
= DOT11_BSSTYPE_ANY
;
777 params_le
->scan_type
= 0;
778 params_le
->channel_num
= 0;
779 params_le
->nprobes
= cpu_to_le32(-1);
780 params_le
->active_time
= cpu_to_le32(-1);
781 params_le
->passive_time
= cpu_to_le32(-1);
782 params_le
->home_time
= cpu_to_le32(-1);
783 memset(¶ms_le
->ssid_le
, 0, sizeof(params_le
->ssid_le
));
785 /* if request is null exit so it will be all channel broadcast scan */
789 n_ssids
= request
->n_ssids
;
790 n_channels
= request
->n_channels
;
791 /* Copy channel array if applicable */
792 brcmf_dbg(SCAN
, "### List of channelspecs to scan ### %d\n",
794 if (n_channels
> 0) {
795 for (i
= 0; i
< n_channels
; i
++) {
796 chanspec
= channel_to_chanspec(&cfg
->d11inf
,
797 request
->channels
[i
]);
798 brcmf_dbg(SCAN
, "Chan : %d, Channel spec: %x\n",
799 request
->channels
[i
]->hw_value
, chanspec
);
800 params_le
->channel_list
[i
] = cpu_to_le16(chanspec
);
803 brcmf_dbg(SCAN
, "Scanning all channels\n");
805 /* Copy ssid array if applicable */
806 brcmf_dbg(SCAN
, "### List of SSIDs to scan ### %d\n", n_ssids
);
808 offset
= offsetof(struct brcmf_scan_params_le
, channel_list
) +
809 n_channels
* sizeof(u16
);
810 offset
= roundup(offset
, sizeof(u32
));
811 ptr
= (char *)params_le
+ offset
;
812 for (i
= 0; i
< n_ssids
; i
++) {
813 memset(&ssid_le
, 0, sizeof(ssid_le
));
815 cpu_to_le32(request
->ssids
[i
].ssid_len
);
816 memcpy(ssid_le
.SSID
, request
->ssids
[i
].ssid
,
817 request
->ssids
[i
].ssid_len
);
818 if (!ssid_le
.SSID_len
)
819 brcmf_dbg(SCAN
, "%d: Broadcast scan\n", i
);
821 brcmf_dbg(SCAN
, "%d: scan for %s size =%d\n",
822 i
, ssid_le
.SSID
, ssid_le
.SSID_len
);
823 memcpy(ptr
, &ssid_le
, sizeof(ssid_le
));
824 ptr
+= sizeof(ssid_le
);
827 brcmf_dbg(SCAN
, "Broadcast scan %p\n", request
->ssids
);
828 if ((request
->ssids
) && request
->ssids
->ssid_len
) {
829 brcmf_dbg(SCAN
, "SSID %s len=%d\n",
830 params_le
->ssid_le
.SSID
,
831 request
->ssids
->ssid_len
);
832 params_le
->ssid_le
.SSID_len
=
833 cpu_to_le32(request
->ssids
->ssid_len
);
834 memcpy(¶ms_le
->ssid_le
.SSID
, request
->ssids
->ssid
,
835 request
->ssids
->ssid_len
);
838 /* Adding mask to channel numbers */
839 params_le
->channel_num
=
840 cpu_to_le32((n_ssids
<< BRCMF_SCAN_PARAMS_NSSID_SHIFT
) |
841 (n_channels
& BRCMF_SCAN_PARAMS_COUNT_MASK
));
845 brcmf_run_escan(struct brcmf_cfg80211_info
*cfg
, struct brcmf_if
*ifp
,
846 struct cfg80211_scan_request
*request
, u16 action
)
848 s32 params_size
= BRCMF_SCAN_PARAMS_FIXED_SIZE
+
849 offsetof(struct brcmf_escan_params_le
, params_le
);
850 struct brcmf_escan_params_le
*params
;
853 brcmf_dbg(SCAN
, "E-SCAN START\n");
855 if (request
!= NULL
) {
856 /* Allocate space for populating ssids in struct */
857 params_size
+= sizeof(u32
) * ((request
->n_channels
+ 1) / 2);
859 /* Allocate space for populating ssids in struct */
860 params_size
+= sizeof(struct brcmf_ssid
) * request
->n_ssids
;
863 params
= kzalloc(params_size
, GFP_KERNEL
);
868 BUG_ON(params_size
+ sizeof("escan") >= BRCMF_DCMD_MEDLEN
);
869 brcmf_escan_prep(cfg
, ¶ms
->params_le
, request
);
870 params
->version
= cpu_to_le32(BRCMF_ESCAN_REQ_VERSION
);
871 params
->action
= cpu_to_le16(action
);
872 params
->sync_id
= cpu_to_le16(0x1234);
874 err
= brcmf_fil_iovar_data_set(ifp
, "escan", params
, params_size
);
877 brcmf_dbg(INFO
, "system busy : escan canceled\n");
879 brcmf_err("error (%d)\n", err
);
888 brcmf_do_escan(struct brcmf_cfg80211_info
*cfg
, struct wiphy
*wiphy
,
889 struct brcmf_if
*ifp
, struct cfg80211_scan_request
*request
)
893 struct brcmf_scan_results
*results
;
894 struct escan_info
*escan
= &cfg
->escan_info
;
896 brcmf_dbg(SCAN
, "Enter\n");
898 escan
->wiphy
= wiphy
;
899 escan
->escan_state
= WL_ESCAN_STATE_SCANNING
;
900 passive_scan
= cfg
->active_scan
? 0 : 1;
901 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PASSIVE_SCAN
,
904 brcmf_err("error (%d)\n", err
);
907 brcmf_scan_config_mpc(ifp
, 0);
908 results
= (struct brcmf_scan_results
*)cfg
->escan_info
.escan_buf
;
909 results
->version
= 0;
911 results
->buflen
= WL_ESCAN_RESULTS_FIXED_SIZE
;
913 err
= escan
->run(cfg
, ifp
, request
, WL_ESCAN_ACTION_START
);
915 brcmf_scan_config_mpc(ifp
, 1);
920 brcmf_cfg80211_escan(struct wiphy
*wiphy
, struct brcmf_cfg80211_vif
*vif
,
921 struct cfg80211_scan_request
*request
,
922 struct cfg80211_ssid
*this_ssid
)
924 struct brcmf_if
*ifp
= vif
->ifp
;
925 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
926 struct cfg80211_ssid
*ssids
;
927 struct brcmf_cfg80211_scan_req
*sr
= &cfg
->scan_req_int
;
934 brcmf_dbg(SCAN
, "START ESCAN\n");
936 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
937 brcmf_err("Scanning already: status (%lu)\n", cfg
->scan_status
);
940 if (test_bit(BRCMF_SCAN_STATUS_ABORT
, &cfg
->scan_status
)) {
941 brcmf_err("Scanning being aborted: status (%lu)\n",
945 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
)) {
946 brcmf_err("Scanning suppressed: status (%lu)\n",
950 if (test_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
)) {
951 brcmf_err("Connecting: status (%lu)\n", ifp
->vif
->sme_state
);
955 /* If scan req comes for p2p0, send it over primary I/F */
956 if (vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
957 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
959 /* Arm scan timeout timer */
960 mod_timer(&cfg
->escan_timeout
, jiffies
+
961 WL_ESCAN_TIMER_INTERVAL_MS
* HZ
/ 1000);
966 ssids
= request
->ssids
;
970 /* we don't do escan in ibss */
974 cfg
->scan_request
= request
;
975 set_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
977 cfg
->escan_info
.run
= brcmf_run_escan
;
978 err
= brcmf_p2p_scan_prep(wiphy
, request
, vif
);
982 err
= brcmf_do_escan(cfg
, wiphy
, vif
->ifp
, request
);
986 brcmf_dbg(SCAN
, "ssid \"%s\", ssid_len (%d)\n",
987 ssids
->ssid
, ssids
->ssid_len
);
988 memset(&sr
->ssid_le
, 0, sizeof(sr
->ssid_le
));
989 SSID_len
= min_t(u8
, sizeof(sr
->ssid_le
.SSID
), ssids
->ssid_len
);
990 sr
->ssid_le
.SSID_len
= cpu_to_le32(0);
993 memcpy(sr
->ssid_le
.SSID
, ssids
->ssid
, SSID_len
);
994 sr
->ssid_le
.SSID_len
= cpu_to_le32(SSID_len
);
997 brcmf_dbg(SCAN
, "Broadcast scan\n");
999 passive_scan
= cfg
->active_scan
? 0 : 1;
1000 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PASSIVE_SCAN
,
1003 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err
);
1006 brcmf_scan_config_mpc(ifp
, 0);
1007 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCAN
,
1008 &sr
->ssid_le
, sizeof(sr
->ssid_le
));
1011 brcmf_dbg(INFO
, "BUSY: scan for \"%s\" canceled\n",
1014 brcmf_err("WLC_SCAN error (%d)\n", err
);
1016 brcmf_scan_config_mpc(ifp
, 1);
1024 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
1025 if (timer_pending(&cfg
->escan_timeout
))
1026 del_timer_sync(&cfg
->escan_timeout
);
1027 cfg
->scan_request
= NULL
;
1032 brcmf_cfg80211_scan(struct wiphy
*wiphy
, struct cfg80211_scan_request
*request
)
1034 struct brcmf_cfg80211_vif
*vif
;
1037 brcmf_dbg(TRACE
, "Enter\n");
1038 vif
= container_of(request
->wdev
, struct brcmf_cfg80211_vif
, wdev
);
1039 if (!check_vif_up(vif
))
1042 err
= brcmf_cfg80211_escan(wiphy
, vif
, request
, NULL
);
1045 brcmf_err("scan error (%d)\n", err
);
1047 brcmf_dbg(TRACE
, "Exit\n");
1051 static s32
brcmf_set_rts(struct net_device
*ndev
, u32 rts_threshold
)
1055 err
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "rtsthresh",
1058 brcmf_err("Error (%d)\n", err
);
1063 static s32
brcmf_set_frag(struct net_device
*ndev
, u32 frag_threshold
)
1067 err
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "fragthresh",
1070 brcmf_err("Error (%d)\n", err
);
1075 static s32
brcmf_set_retry(struct net_device
*ndev
, u32 retry
, bool l
)
1078 u32 cmd
= (l
? BRCMF_C_SET_LRL
: BRCMF_C_SET_SRL
);
1080 err
= brcmf_fil_cmd_int_set(netdev_priv(ndev
), cmd
, retry
);
1082 brcmf_err("cmd (%d) , error (%d)\n", cmd
, err
);
1088 static s32
brcmf_cfg80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1090 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1091 struct net_device
*ndev
= cfg_to_ndev(cfg
);
1092 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1095 brcmf_dbg(TRACE
, "Enter\n");
1096 if (!check_vif_up(ifp
->vif
))
1099 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
&&
1100 (cfg
->conf
->rts_threshold
!= wiphy
->rts_threshold
)) {
1101 cfg
->conf
->rts_threshold
= wiphy
->rts_threshold
;
1102 err
= brcmf_set_rts(ndev
, cfg
->conf
->rts_threshold
);
1106 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
&&
1107 (cfg
->conf
->frag_threshold
!= wiphy
->frag_threshold
)) {
1108 cfg
->conf
->frag_threshold
= wiphy
->frag_threshold
;
1109 err
= brcmf_set_frag(ndev
, cfg
->conf
->frag_threshold
);
1113 if (changed
& WIPHY_PARAM_RETRY_LONG
1114 && (cfg
->conf
->retry_long
!= wiphy
->retry_long
)) {
1115 cfg
->conf
->retry_long
= wiphy
->retry_long
;
1116 err
= brcmf_set_retry(ndev
, cfg
->conf
->retry_long
, true);
1120 if (changed
& WIPHY_PARAM_RETRY_SHORT
1121 && (cfg
->conf
->retry_short
!= wiphy
->retry_short
)) {
1122 cfg
->conf
->retry_short
= wiphy
->retry_short
;
1123 err
= brcmf_set_retry(ndev
, cfg
->conf
->retry_short
, false);
1129 brcmf_dbg(TRACE
, "Exit\n");
1133 static void brcmf_init_prof(struct brcmf_cfg80211_profile
*prof
)
1135 memset(prof
, 0, sizeof(*prof
));
1138 static void brcmf_link_down(struct brcmf_cfg80211_vif
*vif
)
1140 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(vif
->wdev
.wiphy
);
1143 brcmf_dbg(TRACE
, "Enter\n");
1145 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &vif
->sme_state
)) {
1146 brcmf_dbg(INFO
, "Call WLC_DISASSOC to stop excess roaming\n ");
1147 err
= brcmf_fil_cmd_data_set(vif
->ifp
,
1148 BRCMF_C_DISASSOC
, NULL
, 0);
1150 brcmf_err("WLC_DISASSOC failed (%d)\n", err
);
1152 clear_bit(BRCMF_VIF_STATUS_CONNECTED
, &vif
->sme_state
);
1153 cfg80211_disconnected(vif
->wdev
.netdev
, 0, NULL
, 0, GFP_KERNEL
);
1156 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &vif
->sme_state
);
1157 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
1158 brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_ENABLED
, 0);
1159 brcmf_dbg(TRACE
, "Exit\n");
1163 brcmf_cfg80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*ndev
,
1164 struct cfg80211_ibss_params
*params
)
1166 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1167 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1168 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
1169 struct brcmf_join_params join_params
;
1170 size_t join_params_size
= 0;
1176 brcmf_dbg(TRACE
, "Enter\n");
1177 if (!check_vif_up(ifp
->vif
))
1181 brcmf_dbg(CONN
, "SSID: %s\n", params
->ssid
);
1183 brcmf_dbg(CONN
, "SSID: NULL, Not supported\n");
1187 set_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1190 brcmf_dbg(CONN
, "BSSID: %pM\n", params
->bssid
);
1192 brcmf_dbg(CONN
, "No BSSID specified\n");
1194 if (params
->chandef
.chan
)
1195 brcmf_dbg(CONN
, "channel: %d\n",
1196 params
->chandef
.chan
->center_freq
);
1198 brcmf_dbg(CONN
, "no channel specified\n");
1200 if (params
->channel_fixed
)
1201 brcmf_dbg(CONN
, "fixed channel required\n");
1203 brcmf_dbg(CONN
, "no fixed channel required\n");
1205 if (params
->ie
&& params
->ie_len
)
1206 brcmf_dbg(CONN
, "ie len: %d\n", params
->ie_len
);
1208 brcmf_dbg(CONN
, "no ie specified\n");
1210 if (params
->beacon_interval
)
1211 brcmf_dbg(CONN
, "beacon interval: %d\n",
1212 params
->beacon_interval
);
1214 brcmf_dbg(CONN
, "no beacon interval specified\n");
1216 if (params
->basic_rates
)
1217 brcmf_dbg(CONN
, "basic rates: %08X\n", params
->basic_rates
);
1219 brcmf_dbg(CONN
, "no basic rates specified\n");
1221 if (params
->privacy
)
1222 brcmf_dbg(CONN
, "privacy required\n");
1224 brcmf_dbg(CONN
, "no privacy required\n");
1226 /* Configure Privacy for starter */
1227 if (params
->privacy
)
1228 wsec
|= WEP_ENABLED
;
1230 err
= brcmf_fil_iovar_int_set(ifp
, "wsec", wsec
);
1232 brcmf_err("wsec failed (%d)\n", err
);
1236 /* Configure Beacon Interval for starter */
1237 if (params
->beacon_interval
)
1238 bcnprd
= params
->beacon_interval
;
1242 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_BCNPRD
, bcnprd
);
1244 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err
);
1248 /* Configure required join parameter */
1249 memset(&join_params
, 0, sizeof(struct brcmf_join_params
));
1252 profile
->ssid
.SSID_len
= min_t(u32
, params
->ssid_len
, 32);
1253 memcpy(profile
->ssid
.SSID
, params
->ssid
, profile
->ssid
.SSID_len
);
1254 memcpy(join_params
.ssid_le
.SSID
, params
->ssid
, profile
->ssid
.SSID_len
);
1255 join_params
.ssid_le
.SSID_len
= cpu_to_le32(profile
->ssid
.SSID_len
);
1256 join_params_size
= sizeof(join_params
.ssid_le
);
1259 if (params
->bssid
) {
1260 memcpy(join_params
.params_le
.bssid
, params
->bssid
, ETH_ALEN
);
1261 join_params_size
= sizeof(join_params
.ssid_le
) +
1262 BRCMF_ASSOC_PARAMS_FIXED_SIZE
;
1263 memcpy(profile
->bssid
, params
->bssid
, ETH_ALEN
);
1265 memset(join_params
.params_le
.bssid
, 0xFF, ETH_ALEN
);
1266 memset(profile
->bssid
, 0, ETH_ALEN
);
1270 if (params
->chandef
.chan
) {
1274 ieee80211_frequency_to_channel(
1275 params
->chandef
.chan
->center_freq
);
1276 if (params
->channel_fixed
) {
1277 /* adding chanspec */
1278 chanspec
= chandef_to_chanspec(&cfg
->d11inf
,
1280 join_params
.params_le
.chanspec_list
[0] =
1281 cpu_to_le16(chanspec
);
1282 join_params
.params_le
.chanspec_num
= cpu_to_le32(1);
1283 join_params_size
+= sizeof(join_params
.params_le
);
1286 /* set channel for starter */
1287 target_channel
= cfg
->channel
;
1288 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_CHANNEL
,
1291 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err
);
1297 cfg
->ibss_starter
= false;
1300 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
1301 &join_params
, join_params_size
);
1303 brcmf_err("WLC_SET_SSID failed (%d)\n", err
);
1309 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1310 brcmf_dbg(TRACE
, "Exit\n");
1315 brcmf_cfg80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*ndev
)
1317 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1319 brcmf_dbg(TRACE
, "Enter\n");
1320 if (!check_vif_up(ifp
->vif
))
1323 brcmf_link_down(ifp
->vif
);
1325 brcmf_dbg(TRACE
, "Exit\n");
1330 static s32
brcmf_set_wpa_version(struct net_device
*ndev
,
1331 struct cfg80211_connect_params
*sme
)
1333 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1334 struct brcmf_cfg80211_security
*sec
;
1338 if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_1
)
1339 val
= WPA_AUTH_PSK
| WPA_AUTH_UNSPECIFIED
;
1340 else if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_2
)
1341 val
= WPA2_AUTH_PSK
| WPA2_AUTH_UNSPECIFIED
;
1343 val
= WPA_AUTH_DISABLED
;
1344 brcmf_dbg(CONN
, "setting wpa_auth to 0x%0x\n", val
);
1345 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "wpa_auth", val
);
1347 brcmf_err("set wpa_auth failed (%d)\n", err
);
1350 sec
= &profile
->sec
;
1351 sec
->wpa_versions
= sme
->crypto
.wpa_versions
;
1355 static s32
brcmf_set_auth_type(struct net_device
*ndev
,
1356 struct cfg80211_connect_params
*sme
)
1358 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1359 struct brcmf_cfg80211_security
*sec
;
1363 switch (sme
->auth_type
) {
1364 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
1366 brcmf_dbg(CONN
, "open system\n");
1368 case NL80211_AUTHTYPE_SHARED_KEY
:
1370 brcmf_dbg(CONN
, "shared key\n");
1372 case NL80211_AUTHTYPE_AUTOMATIC
:
1374 brcmf_dbg(CONN
, "automatic\n");
1376 case NL80211_AUTHTYPE_NETWORK_EAP
:
1377 brcmf_dbg(CONN
, "network eap\n");
1380 brcmf_err("invalid auth type (%d)\n", sme
->auth_type
);
1384 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "auth", val
);
1386 brcmf_err("set auth failed (%d)\n", err
);
1389 sec
= &profile
->sec
;
1390 sec
->auth_type
= sme
->auth_type
;
1395 brcmf_set_wsec_mode(struct net_device
*ndev
,
1396 struct cfg80211_connect_params
*sme
, bool mfp
)
1398 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1399 struct brcmf_cfg80211_security
*sec
;
1405 if (sme
->crypto
.n_ciphers_pairwise
) {
1406 switch (sme
->crypto
.ciphers_pairwise
[0]) {
1407 case WLAN_CIPHER_SUITE_WEP40
:
1408 case WLAN_CIPHER_SUITE_WEP104
:
1411 case WLAN_CIPHER_SUITE_TKIP
:
1412 pval
= TKIP_ENABLED
;
1414 case WLAN_CIPHER_SUITE_CCMP
:
1417 case WLAN_CIPHER_SUITE_AES_CMAC
:
1421 brcmf_err("invalid cipher pairwise (%d)\n",
1422 sme
->crypto
.ciphers_pairwise
[0]);
1426 if (sme
->crypto
.cipher_group
) {
1427 switch (sme
->crypto
.cipher_group
) {
1428 case WLAN_CIPHER_SUITE_WEP40
:
1429 case WLAN_CIPHER_SUITE_WEP104
:
1432 case WLAN_CIPHER_SUITE_TKIP
:
1433 gval
= TKIP_ENABLED
;
1435 case WLAN_CIPHER_SUITE_CCMP
:
1438 case WLAN_CIPHER_SUITE_AES_CMAC
:
1442 brcmf_err("invalid cipher group (%d)\n",
1443 sme
->crypto
.cipher_group
);
1448 brcmf_dbg(CONN
, "pval (%d) gval (%d)\n", pval
, gval
);
1449 /* In case of privacy, but no security and WPS then simulate */
1450 /* setting AES. WPS-2.0 allows no security */
1451 if (brcmf_find_wpsie(sme
->ie
, sme
->ie_len
) && !pval
&& !gval
&&
1456 wsec
= pval
| gval
| MFP_CAPABLE
;
1459 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "wsec", wsec
);
1461 brcmf_err("error (%d)\n", err
);
1465 sec
= &profile
->sec
;
1466 sec
->cipher_pairwise
= sme
->crypto
.ciphers_pairwise
[0];
1467 sec
->cipher_group
= sme
->crypto
.cipher_group
;
1473 brcmf_set_key_mgmt(struct net_device
*ndev
, struct cfg80211_connect_params
*sme
)
1475 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1476 struct brcmf_cfg80211_security
*sec
;
1480 if (sme
->crypto
.n_akm_suites
) {
1481 err
= brcmf_fil_bsscfg_int_get(netdev_priv(ndev
),
1484 brcmf_err("could not get wpa_auth (%d)\n", err
);
1487 if (val
& (WPA_AUTH_PSK
| WPA_AUTH_UNSPECIFIED
)) {
1488 switch (sme
->crypto
.akm_suites
[0]) {
1489 case WLAN_AKM_SUITE_8021X
:
1490 val
= WPA_AUTH_UNSPECIFIED
;
1492 case WLAN_AKM_SUITE_PSK
:
1496 brcmf_err("invalid cipher group (%d)\n",
1497 sme
->crypto
.cipher_group
);
1500 } else if (val
& (WPA2_AUTH_PSK
| WPA2_AUTH_UNSPECIFIED
)) {
1501 switch (sme
->crypto
.akm_suites
[0]) {
1502 case WLAN_AKM_SUITE_8021X
:
1503 val
= WPA2_AUTH_UNSPECIFIED
;
1505 case WLAN_AKM_SUITE_PSK
:
1506 val
= WPA2_AUTH_PSK
;
1509 brcmf_err("invalid cipher group (%d)\n",
1510 sme
->crypto
.cipher_group
);
1515 brcmf_dbg(CONN
, "setting wpa_auth to %d\n", val
);
1516 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
),
1519 brcmf_err("could not set wpa_auth (%d)\n", err
);
1523 sec
= &profile
->sec
;
1524 sec
->wpa_auth
= sme
->crypto
.akm_suites
[0];
1530 brcmf_set_sharedkey(struct net_device
*ndev
,
1531 struct cfg80211_connect_params
*sme
)
1533 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1534 struct brcmf_cfg80211_security
*sec
;
1535 struct brcmf_wsec_key key
;
1539 brcmf_dbg(CONN
, "key len (%d)\n", sme
->key_len
);
1541 if (sme
->key_len
== 0)
1544 sec
= &profile
->sec
;
1545 brcmf_dbg(CONN
, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1546 sec
->wpa_versions
, sec
->cipher_pairwise
);
1548 if (sec
->wpa_versions
& (NL80211_WPA_VERSION_1
| NL80211_WPA_VERSION_2
))
1551 if (!(sec
->cipher_pairwise
&
1552 (WLAN_CIPHER_SUITE_WEP40
| WLAN_CIPHER_SUITE_WEP104
)))
1555 memset(&key
, 0, sizeof(key
));
1556 key
.len
= (u32
) sme
->key_len
;
1557 key
.index
= (u32
) sme
->key_idx
;
1558 if (key
.len
> sizeof(key
.data
)) {
1559 brcmf_err("Too long key length (%u)\n", key
.len
);
1562 memcpy(key
.data
, sme
->key
, key
.len
);
1563 key
.flags
= BRCMF_PRIMARY_KEY
;
1564 switch (sec
->cipher_pairwise
) {
1565 case WLAN_CIPHER_SUITE_WEP40
:
1566 key
.algo
= CRYPTO_ALGO_WEP1
;
1568 case WLAN_CIPHER_SUITE_WEP104
:
1569 key
.algo
= CRYPTO_ALGO_WEP128
;
1572 brcmf_err("Invalid algorithm (%d)\n",
1573 sme
->crypto
.ciphers_pairwise
[0]);
1576 /* Set the new key/index */
1577 brcmf_dbg(CONN
, "key length (%d) key index (%d) algo (%d)\n",
1578 key
.len
, key
.index
, key
.algo
);
1579 brcmf_dbg(CONN
, "key \"%s\"\n", key
.data
);
1580 err
= send_key_to_dongle(ndev
, &key
);
1584 if (sec
->auth_type
== NL80211_AUTHTYPE_SHARED_KEY
) {
1585 brcmf_dbg(CONN
, "set auth_type to shared key\n");
1586 val
= WL_AUTH_SHARED_KEY
; /* shared key */
1587 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "auth", val
);
1589 brcmf_err("set auth failed (%d)\n", err
);
1595 enum nl80211_auth_type
brcmf_war_auth_type(struct brcmf_if
*ifp
,
1596 enum nl80211_auth_type type
)
1598 if (type
== NL80211_AUTHTYPE_AUTOMATIC
&&
1599 brcmf_feat_is_quirk_enabled(ifp
, BRCMF_FEAT_QUIRK_AUTO_AUTH
)) {
1600 brcmf_dbg(CONN
, "WAR: use OPEN instead of AUTO\n");
1601 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
1607 brcmf_cfg80211_connect(struct wiphy
*wiphy
, struct net_device
*ndev
,
1608 struct cfg80211_connect_params
*sme
)
1610 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1611 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1612 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
1613 struct ieee80211_channel
*chan
= sme
->channel
;
1614 struct brcmf_join_params join_params
;
1615 size_t join_params_size
;
1616 const struct brcmf_tlv
*rsn_ie
;
1617 const struct brcmf_vs_tlv
*wpa_ie
;
1620 struct brcmf_ext_join_params_le
*ext_join_params
;
1624 brcmf_dbg(TRACE
, "Enter\n");
1625 if (!check_vif_up(ifp
->vif
))
1629 brcmf_err("Invalid ssid\n");
1633 if (ifp
->vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
) {
1634 /* A normal (non P2P) connection request setup. */
1637 /* find the WPA_IE */
1638 wpa_ie
= brcmf_find_wpaie((u8
*)sme
->ie
, sme
->ie_len
);
1641 ie_len
= wpa_ie
->len
+ TLV_HDR_LEN
;
1643 /* find the RSN_IE */
1644 rsn_ie
= brcmf_parse_tlvs((const u8
*)sme
->ie
,
1649 ie_len
= rsn_ie
->len
+ TLV_HDR_LEN
;
1652 brcmf_fil_iovar_data_set(ifp
, "wpaie", ie
, ie_len
);
1655 err
= brcmf_vif_set_mgmt_ie(ifp
->vif
, BRCMF_VNDR_IE_ASSOCREQ_FLAG
,
1656 sme
->ie
, sme
->ie_len
);
1658 brcmf_err("Set Assoc REQ IE Failed\n");
1660 brcmf_dbg(TRACE
, "Applied Vndr IEs for Assoc request\n");
1662 set_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1666 ieee80211_frequency_to_channel(chan
->center_freq
);
1667 chanspec
= channel_to_chanspec(&cfg
->d11inf
, chan
);
1668 brcmf_dbg(CONN
, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1669 cfg
->channel
, chan
->center_freq
, chanspec
);
1675 brcmf_dbg(INFO
, "ie (%p), ie_len (%zd)\n", sme
->ie
, sme
->ie_len
);
1677 err
= brcmf_set_wpa_version(ndev
, sme
);
1679 brcmf_err("wl_set_wpa_version failed (%d)\n", err
);
1683 sme
->auth_type
= brcmf_war_auth_type(ifp
, sme
->auth_type
);
1684 err
= brcmf_set_auth_type(ndev
, sme
);
1686 brcmf_err("wl_set_auth_type failed (%d)\n", err
);
1690 err
= brcmf_set_wsec_mode(ndev
, sme
, sme
->mfp
== NL80211_MFP_REQUIRED
);
1692 brcmf_err("wl_set_set_cipher failed (%d)\n", err
);
1696 err
= brcmf_set_key_mgmt(ndev
, sme
);
1698 brcmf_err("wl_set_key_mgmt failed (%d)\n", err
);
1702 err
= brcmf_set_sharedkey(ndev
, sme
);
1704 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err
);
1708 profile
->ssid
.SSID_len
= min_t(u32
, (u32
)sizeof(profile
->ssid
.SSID
),
1709 (u32
)sme
->ssid_len
);
1710 memcpy(&profile
->ssid
.SSID
, sme
->ssid
, profile
->ssid
.SSID_len
);
1711 if (profile
->ssid
.SSID_len
< IEEE80211_MAX_SSID_LEN
) {
1712 profile
->ssid
.SSID
[profile
->ssid
.SSID_len
] = 0;
1713 brcmf_dbg(CONN
, "SSID \"%s\", len (%d)\n", profile
->ssid
.SSID
,
1714 profile
->ssid
.SSID_len
);
1717 /* Join with specific BSSID and cached SSID
1718 * If SSID is zero join based on BSSID only
1720 join_params_size
= offsetof(struct brcmf_ext_join_params_le
, assoc_le
) +
1721 offsetof(struct brcmf_assoc_params_le
, chanspec_list
);
1723 join_params_size
+= sizeof(u16
);
1724 ext_join_params
= kzalloc(join_params_size
, GFP_KERNEL
);
1725 if (ext_join_params
== NULL
) {
1729 ext_join_params
->ssid_le
.SSID_len
= cpu_to_le32(profile
->ssid
.SSID_len
);
1730 memcpy(&ext_join_params
->ssid_le
.SSID
, sme
->ssid
,
1731 profile
->ssid
.SSID_len
);
1733 /* Set up join scan parameters */
1734 ext_join_params
->scan_le
.scan_type
= -1;
1735 ext_join_params
->scan_le
.home_time
= cpu_to_le32(-1);
1738 memcpy(&ext_join_params
->assoc_le
.bssid
, sme
->bssid
, ETH_ALEN
);
1740 memset(&ext_join_params
->assoc_le
.bssid
, 0xFF, ETH_ALEN
);
1743 ext_join_params
->assoc_le
.chanspec_num
= cpu_to_le32(1);
1745 ext_join_params
->assoc_le
.chanspec_list
[0] =
1746 cpu_to_le16(chanspec
);
1747 /* Increase dwell time to receive probe response or detect
1748 * beacon from target AP at a noisy air only during connect
1751 ext_join_params
->scan_le
.active_time
=
1752 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS
);
1753 ext_join_params
->scan_le
.passive_time
=
1754 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS
);
1755 /* To sync with presence period of VSDB GO send probe request
1756 * more frequently. Probe request will be stopped when it gets
1757 * probe response from target AP/GO.
1759 ext_join_params
->scan_le
.nprobes
=
1760 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS
/
1761 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS
);
1763 ext_join_params
->scan_le
.active_time
= cpu_to_le32(-1);
1764 ext_join_params
->scan_le
.passive_time
= cpu_to_le32(-1);
1765 ext_join_params
->scan_le
.nprobes
= cpu_to_le32(-1);
1768 err
= brcmf_fil_bsscfg_data_set(ifp
, "join", ext_join_params
,
1770 kfree(ext_join_params
);
1772 /* This is it. join command worked, we are done */
1775 /* join command failed, fallback to set ssid */
1776 memset(&join_params
, 0, sizeof(join_params
));
1777 join_params_size
= sizeof(join_params
.ssid_le
);
1779 memcpy(&join_params
.ssid_le
.SSID
, sme
->ssid
, profile
->ssid
.SSID_len
);
1780 join_params
.ssid_le
.SSID_len
= cpu_to_le32(profile
->ssid
.SSID_len
);
1783 memcpy(join_params
.params_le
.bssid
, sme
->bssid
, ETH_ALEN
);
1785 memset(join_params
.params_le
.bssid
, 0xFF, ETH_ALEN
);
1788 join_params
.params_le
.chanspec_list
[0] = cpu_to_le16(chanspec
);
1789 join_params
.params_le
.chanspec_num
= cpu_to_le32(1);
1790 join_params_size
+= sizeof(join_params
.params_le
);
1792 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
1793 &join_params
, join_params_size
);
1795 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err
);
1799 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1800 brcmf_dbg(TRACE
, "Exit\n");
1805 brcmf_cfg80211_disconnect(struct wiphy
*wiphy
, struct net_device
*ndev
,
1808 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1809 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
1810 struct brcmf_scb_val_le scbval
;
1813 brcmf_dbg(TRACE
, "Enter. Reason code = %d\n", reason_code
);
1814 if (!check_vif_up(ifp
->vif
))
1817 clear_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
);
1818 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1819 cfg80211_disconnected(ndev
, reason_code
, NULL
, 0, GFP_KERNEL
);
1821 memcpy(&scbval
.ea
, &profile
->bssid
, ETH_ALEN
);
1822 scbval
.val
= cpu_to_le32(reason_code
);
1823 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_DISASSOC
,
1824 &scbval
, sizeof(scbval
));
1826 brcmf_err("error (%d)\n", err
);
1828 brcmf_dbg(TRACE
, "Exit\n");
1833 brcmf_cfg80211_set_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
1834 enum nl80211_tx_power_setting type
, s32 mbm
)
1837 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1838 struct net_device
*ndev
= cfg_to_ndev(cfg
);
1839 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1843 s32 dbm
= MBM_TO_DBM(mbm
);
1845 brcmf_dbg(TRACE
, "Enter\n");
1846 if (!check_vif_up(ifp
->vif
))
1850 case NL80211_TX_POWER_AUTOMATIC
:
1852 case NL80211_TX_POWER_LIMITED
:
1853 case NL80211_TX_POWER_FIXED
:
1855 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
1861 /* Make sure radio is off or on as far as software is concerned */
1862 disable
= WL_RADIO_SW_DISABLE
<< 16;
1863 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_RADIO
, disable
);
1865 brcmf_err("WLC_SET_RADIO error (%d)\n", err
);
1870 txpwrmw
= (u16
) dbm
;
1871 err
= brcmf_fil_iovar_int_set(ifp
, "qtxpower",
1872 (s32
)brcmf_mw_to_qdbm(txpwrmw
));
1874 brcmf_err("qtxpower error (%d)\n", err
);
1875 cfg
->conf
->tx_power
= dbm
;
1878 brcmf_dbg(TRACE
, "Exit\n");
1882 static s32
brcmf_cfg80211_get_tx_power(struct wiphy
*wiphy
,
1883 struct wireless_dev
*wdev
,
1886 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1887 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
1892 brcmf_dbg(TRACE
, "Enter\n");
1893 if (!check_vif_up(ifp
->vif
))
1896 err
= brcmf_fil_iovar_int_get(ifp
, "qtxpower", &txpwrdbm
);
1898 brcmf_err("error (%d)\n", err
);
1902 result
= (u8
) (txpwrdbm
& ~WL_TXPWR_OVERRIDE
);
1903 *dbm
= (s32
) brcmf_qdbm_to_mw(result
);
1906 brcmf_dbg(TRACE
, "Exit\n");
1911 brcmf_cfg80211_config_default_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
1912 u8 key_idx
, bool unicast
, bool multicast
)
1914 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1919 brcmf_dbg(TRACE
, "Enter\n");
1920 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
1921 if (!check_vif_up(ifp
->vif
))
1924 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
1926 brcmf_err("WLC_GET_WSEC error (%d)\n", err
);
1930 if (wsec
& WEP_ENABLED
) {
1931 /* Just select a new current key */
1933 err
= brcmf_fil_cmd_int_set(ifp
,
1934 BRCMF_C_SET_KEY_PRIMARY
, index
);
1936 brcmf_err("error (%d)\n", err
);
1939 brcmf_dbg(TRACE
, "Exit\n");
1944 brcmf_add_keyext(struct wiphy
*wiphy
, struct net_device
*ndev
,
1945 u8 key_idx
, const u8
*mac_addr
, struct key_params
*params
)
1947 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1948 struct brcmf_wsec_key key
;
1952 memset(&key
, 0, sizeof(key
));
1953 key
.index
= (u32
) key_idx
;
1954 /* Instead of bcast for ea address for default wep keys,
1955 driver needs it to be Null */
1956 if (!is_multicast_ether_addr(mac_addr
))
1957 memcpy((char *)&key
.ea
, (void *)mac_addr
, ETH_ALEN
);
1958 key
.len
= (u32
) params
->key_len
;
1959 /* check for key index change */
1962 err
= send_key_to_dongle(ndev
, &key
);
1964 brcmf_err("key delete error (%d)\n", err
);
1966 if (key
.len
> sizeof(key
.data
)) {
1967 brcmf_err("Invalid key length (%d)\n", key
.len
);
1971 brcmf_dbg(CONN
, "Setting the key index %d\n", key
.index
);
1972 memcpy(key
.data
, params
->key
, key
.len
);
1974 if (!brcmf_is_apmode(ifp
->vif
) &&
1975 (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)) {
1976 brcmf_dbg(CONN
, "Swapping RX/TX MIC key\n");
1977 memcpy(keybuf
, &key
.data
[24], sizeof(keybuf
));
1978 memcpy(&key
.data
[24], &key
.data
[16], sizeof(keybuf
));
1979 memcpy(&key
.data
[16], keybuf
, sizeof(keybuf
));
1982 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1983 if (params
->seq
&& params
->seq_len
== 6) {
1986 ivptr
= (u8
*) params
->seq
;
1987 key
.rxiv
.hi
= (ivptr
[5] << 24) | (ivptr
[4] << 16) |
1988 (ivptr
[3] << 8) | ivptr
[2];
1989 key
.rxiv
.lo
= (ivptr
[1] << 8) | ivptr
[0];
1990 key
.iv_initialized
= true;
1993 switch (params
->cipher
) {
1994 case WLAN_CIPHER_SUITE_WEP40
:
1995 key
.algo
= CRYPTO_ALGO_WEP1
;
1996 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP40\n");
1998 case WLAN_CIPHER_SUITE_WEP104
:
1999 key
.algo
= CRYPTO_ALGO_WEP128
;
2000 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP104\n");
2002 case WLAN_CIPHER_SUITE_TKIP
:
2003 key
.algo
= CRYPTO_ALGO_TKIP
;
2004 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_TKIP\n");
2006 case WLAN_CIPHER_SUITE_AES_CMAC
:
2007 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2008 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2010 case WLAN_CIPHER_SUITE_CCMP
:
2011 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2012 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_CCMP\n");
2015 brcmf_err("Invalid cipher (0x%x)\n", params
->cipher
);
2018 err
= send_key_to_dongle(ndev
, &key
);
2020 brcmf_err("wsec_key error (%d)\n", err
);
2026 brcmf_cfg80211_add_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2027 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
2028 struct key_params
*params
)
2030 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2031 struct brcmf_wsec_key key
;
2037 brcmf_dbg(TRACE
, "Enter\n");
2038 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2039 if (!check_vif_up(ifp
->vif
))
2043 (params
->cipher
!= WLAN_CIPHER_SUITE_WEP40
) &&
2044 (params
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)) {
2045 brcmf_dbg(TRACE
, "Exit");
2046 return brcmf_add_keyext(wiphy
, ndev
, key_idx
, mac_addr
, params
);
2048 memset(&key
, 0, sizeof(key
));
2050 key
.len
= (u32
) params
->key_len
;
2051 key
.index
= (u32
) key_idx
;
2053 if (key
.len
> sizeof(key
.data
)) {
2054 brcmf_err("Too long key length (%u)\n", key
.len
);
2058 memcpy(key
.data
, params
->key
, key
.len
);
2060 key
.flags
= BRCMF_PRIMARY_KEY
;
2061 switch (params
->cipher
) {
2062 case WLAN_CIPHER_SUITE_WEP40
:
2063 key
.algo
= CRYPTO_ALGO_WEP1
;
2065 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP40\n");
2067 case WLAN_CIPHER_SUITE_WEP104
:
2068 key
.algo
= CRYPTO_ALGO_WEP128
;
2070 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP104\n");
2072 case WLAN_CIPHER_SUITE_TKIP
:
2073 if (!brcmf_is_apmode(ifp
->vif
)) {
2074 brcmf_dbg(CONN
, "Swapping RX/TX MIC key\n");
2075 memcpy(keybuf
, &key
.data
[24], sizeof(keybuf
));
2076 memcpy(&key
.data
[24], &key
.data
[16], sizeof(keybuf
));
2077 memcpy(&key
.data
[16], keybuf
, sizeof(keybuf
));
2079 key
.algo
= CRYPTO_ALGO_TKIP
;
2081 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_TKIP\n");
2083 case WLAN_CIPHER_SUITE_AES_CMAC
:
2084 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2086 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2088 case WLAN_CIPHER_SUITE_CCMP
:
2089 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2091 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_CCMP\n");
2094 brcmf_err("Invalid cipher (0x%x)\n", params
->cipher
);
2099 err
= send_key_to_dongle(ndev
, &key
);
2103 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
2105 brcmf_err("get wsec error (%d)\n", err
);
2109 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", wsec
);
2111 brcmf_err("set wsec error (%d)\n", err
);
2116 brcmf_dbg(TRACE
, "Exit\n");
2121 brcmf_cfg80211_del_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2122 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
2124 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2125 struct brcmf_wsec_key key
;
2128 brcmf_dbg(TRACE
, "Enter\n");
2129 if (!check_vif_up(ifp
->vif
))
2132 if (key_idx
>= DOT11_MAX_DEFAULT_KEYS
) {
2133 /* we ignore this key index in this case */
2134 brcmf_err("invalid key index (%d)\n", key_idx
);
2138 memset(&key
, 0, sizeof(key
));
2140 key
.index
= (u32
) key_idx
;
2141 key
.flags
= BRCMF_PRIMARY_KEY
;
2142 key
.algo
= CRYPTO_ALGO_OFF
;
2144 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2146 /* Set the new key/index */
2147 err
= send_key_to_dongle(ndev
, &key
);
2149 brcmf_dbg(TRACE
, "Exit\n");
2154 brcmf_cfg80211_get_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2155 u8 key_idx
, bool pairwise
, const u8
*mac_addr
, void *cookie
,
2156 void (*callback
) (void *cookie
, struct key_params
* params
))
2158 struct key_params params
;
2159 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2160 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
2161 struct brcmf_cfg80211_security
*sec
;
2165 brcmf_dbg(TRACE
, "Enter\n");
2166 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2167 if (!check_vif_up(ifp
->vif
))
2170 memset(¶ms
, 0, sizeof(params
));
2172 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
2174 brcmf_err("WLC_GET_WSEC error (%d)\n", err
);
2175 /* Ignore this error, may happen during DISASSOC */
2179 if (wsec
& WEP_ENABLED
) {
2180 sec
= &profile
->sec
;
2181 if (sec
->cipher_pairwise
& WLAN_CIPHER_SUITE_WEP40
) {
2182 params
.cipher
= WLAN_CIPHER_SUITE_WEP40
;
2183 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP40\n");
2184 } else if (sec
->cipher_pairwise
& WLAN_CIPHER_SUITE_WEP104
) {
2185 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
2186 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP104\n");
2188 } else if (wsec
& TKIP_ENABLED
) {
2189 params
.cipher
= WLAN_CIPHER_SUITE_TKIP
;
2190 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_TKIP\n");
2191 } else if (wsec
& AES_ENABLED
) {
2192 params
.cipher
= WLAN_CIPHER_SUITE_AES_CMAC
;
2193 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2195 brcmf_err("Invalid algo (0x%x)\n", wsec
);
2199 callback(cookie
, ¶ms
);
2202 brcmf_dbg(TRACE
, "Exit\n");
2207 brcmf_cfg80211_config_default_mgmt_key(struct wiphy
*wiphy
,
2208 struct net_device
*ndev
, u8 key_idx
)
2210 brcmf_dbg(INFO
, "Not supported\n");
2216 brcmf_cfg80211_get_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
2217 const u8
*mac
, struct station_info
*sinfo
)
2219 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2220 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
2221 struct brcmf_scb_val_le scb_val
;
2225 u8
*bssid
= profile
->bssid
;
2226 struct brcmf_sta_info_le sta_info_le
;
2230 brcmf_dbg(TRACE
, "Enter, MAC %pM\n", mac
);
2231 if (!check_vif_up(ifp
->vif
))
2234 if (brcmf_is_apmode(ifp
->vif
)) {
2235 memcpy(&sta_info_le
, mac
, ETH_ALEN
);
2236 err
= brcmf_fil_iovar_data_get(ifp
, "sta_info",
2238 sizeof(sta_info_le
));
2240 brcmf_err("GET STA INFO failed, %d\n", err
);
2243 sinfo
->filled
= STATION_INFO_INACTIVE_TIME
;
2244 sinfo
->inactive_time
= le32_to_cpu(sta_info_le
.idle
) * 1000;
2245 if (le32_to_cpu(sta_info_le
.flags
) & BRCMF_STA_ASSOC
) {
2246 sinfo
->filled
|= STATION_INFO_CONNECTED_TIME
;
2247 sinfo
->connected_time
= le32_to_cpu(sta_info_le
.in
);
2249 brcmf_dbg(TRACE
, "STA idle time : %d ms, connected time :%d sec\n",
2250 sinfo
->inactive_time
, sinfo
->connected_time
);
2251 } else if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_STATION
) {
2252 if (memcmp(mac
, bssid
, ETH_ALEN
)) {
2253 brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
2258 /* Report the current tx rate */
2259 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_RATE
, &rate
);
2261 brcmf_err("Could not get rate (%d)\n", err
);
2264 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
2265 sinfo
->txrate
.legacy
= rate
* 5;
2266 brcmf_dbg(CONN
, "Rate %d Mbps\n", rate
/ 2);
2269 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
,
2270 &ifp
->vif
->sme_state
)) {
2271 memset(&scb_val
, 0, sizeof(scb_val
));
2272 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_RSSI
,
2273 &scb_val
, sizeof(scb_val
));
2275 brcmf_err("Could not get rssi (%d)\n", err
);
2278 rssi
= le32_to_cpu(scb_val
.val
);
2279 sinfo
->filled
|= STATION_INFO_SIGNAL
;
2280 sinfo
->signal
= rssi
;
2281 brcmf_dbg(CONN
, "RSSI %d dBm\n", rssi
);
2283 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_BCNPRD
,
2286 brcmf_err("Could not get beacon period (%d)\n",
2290 sinfo
->bss_param
.beacon_interval
=
2292 brcmf_dbg(CONN
, "Beacon peroid %d\n",
2295 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_DTIMPRD
,
2298 brcmf_err("Could not get DTIM period (%d)\n",
2302 sinfo
->bss_param
.dtim_period
= dtim_period
;
2303 brcmf_dbg(CONN
, "DTIM peroid %d\n",
2306 sinfo
->filled
|= STATION_INFO_BSS_PARAM
;
2311 brcmf_dbg(TRACE
, "Exit\n");
2316 brcmf_cfg80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*ndev
,
2317 bool enabled
, s32 timeout
)
2321 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2322 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2324 brcmf_dbg(TRACE
, "Enter\n");
2327 * Powersave enable/disable request is coming from the
2328 * cfg80211 even before the interface is up. In that
2329 * scenario, driver will be storing the power save
2330 * preference in cfg struct to apply this to
2331 * FW later while initializing the dongle
2333 cfg
->pwr_save
= enabled
;
2334 if (!check_vif_up(ifp
->vif
)) {
2336 brcmf_dbg(INFO
, "Device is not ready, storing the value in cfg_info struct\n");
2340 pm
= enabled
? PM_FAST
: PM_OFF
;
2341 /* Do not enable the power save after assoc if it is a p2p interface */
2342 if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_CLIENT
) {
2343 brcmf_dbg(INFO
, "Do not enable power save for P2P clients\n");
2346 brcmf_dbg(INFO
, "power save %s\n", (pm
? "enabled" : "disabled"));
2348 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, pm
);
2351 brcmf_err("net_device is not ready yet\n");
2353 brcmf_err("error (%d)\n", err
);
2356 brcmf_dbg(TRACE
, "Exit\n");
2360 static s32
brcmf_inform_single_bss(struct brcmf_cfg80211_info
*cfg
,
2361 struct brcmf_bss_info_le
*bi
)
2363 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
2364 struct ieee80211_channel
*notify_channel
;
2365 struct cfg80211_bss
*bss
;
2366 struct ieee80211_supported_band
*band
;
2367 struct brcmu_chan ch
;
2370 u16 notify_capability
;
2371 u16 notify_interval
;
2373 size_t notify_ielen
;
2376 if (le32_to_cpu(bi
->length
) > WL_BSS_INFO_MAX
) {
2377 brcmf_err("Bss info is larger than buffer. Discarding\n");
2382 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
2383 cfg
->d11inf
.decchspec(&ch
);
2384 bi
->ctl_ch
= ch
.chnum
;
2386 channel
= bi
->ctl_ch
;
2388 if (channel
<= CH_MAX_2G_CHANNEL
)
2389 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2391 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2393 freq
= ieee80211_channel_to_frequency(channel
, band
->band
);
2394 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
2396 notify_capability
= le16_to_cpu(bi
->capability
);
2397 notify_interval
= le16_to_cpu(bi
->beacon_period
);
2398 notify_ie
= (u8
*)bi
+ le16_to_cpu(bi
->ie_offset
);
2399 notify_ielen
= le32_to_cpu(bi
->ie_length
);
2400 notify_signal
= (s16
)le16_to_cpu(bi
->RSSI
) * 100;
2402 brcmf_dbg(CONN
, "bssid: %pM\n", bi
->BSSID
);
2403 brcmf_dbg(CONN
, "Channel: %d(%d)\n", channel
, freq
);
2404 brcmf_dbg(CONN
, "Capability: %X\n", notify_capability
);
2405 brcmf_dbg(CONN
, "Beacon interval: %d\n", notify_interval
);
2406 brcmf_dbg(CONN
, "Signal: %d\n", notify_signal
);
2408 bss
= cfg80211_inform_bss(wiphy
, notify_channel
,
2409 CFG80211_BSS_FTYPE_UNKNOWN
,
2410 (const u8
*)bi
->BSSID
,
2411 0, notify_capability
,
2412 notify_interval
, notify_ie
,
2413 notify_ielen
, notify_signal
,
2419 cfg80211_put_bss(wiphy
, bss
);
2424 static struct brcmf_bss_info_le
*
2425 next_bss_le(struct brcmf_scan_results
*list
, struct brcmf_bss_info_le
*bss
)
2428 return list
->bss_info_le
;
2429 return (struct brcmf_bss_info_le
*)((unsigned long)bss
+
2430 le32_to_cpu(bss
->length
));
2433 static s32
brcmf_inform_bss(struct brcmf_cfg80211_info
*cfg
)
2435 struct brcmf_scan_results
*bss_list
;
2436 struct brcmf_bss_info_le
*bi
= NULL
; /* must be initialized */
2440 bss_list
= (struct brcmf_scan_results
*)cfg
->escan_info
.escan_buf
;
2441 if (bss_list
->count
!= 0 &&
2442 bss_list
->version
!= BRCMF_BSS_INFO_VERSION
) {
2443 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2447 brcmf_dbg(SCAN
, "scanned AP count (%d)\n", bss_list
->count
);
2448 for (i
= 0; i
< bss_list
->count
; i
++) {
2449 bi
= next_bss_le(bss_list
, bi
);
2450 err
= brcmf_inform_single_bss(cfg
, bi
);
2457 static s32
wl_inform_ibss(struct brcmf_cfg80211_info
*cfg
,
2458 struct net_device
*ndev
, const u8
*bssid
)
2460 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
2461 struct ieee80211_channel
*notify_channel
;
2462 struct brcmf_bss_info_le
*bi
= NULL
;
2463 struct ieee80211_supported_band
*band
;
2464 struct cfg80211_bss
*bss
;
2465 struct brcmu_chan ch
;
2469 u16 notify_capability
;
2470 u16 notify_interval
;
2472 size_t notify_ielen
;
2475 brcmf_dbg(TRACE
, "Enter\n");
2477 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
2483 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
2485 err
= brcmf_fil_cmd_data_get(netdev_priv(ndev
), BRCMF_C_GET_BSS_INFO
,
2486 buf
, WL_BSS_INFO_MAX
);
2488 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err
);
2492 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
2494 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
2495 cfg
->d11inf
.decchspec(&ch
);
2497 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
2498 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2500 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2502 freq
= ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
2503 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
2505 notify_capability
= le16_to_cpu(bi
->capability
);
2506 notify_interval
= le16_to_cpu(bi
->beacon_period
);
2507 notify_ie
= (u8
*)bi
+ le16_to_cpu(bi
->ie_offset
);
2508 notify_ielen
= le32_to_cpu(bi
->ie_length
);
2509 notify_signal
= (s16
)le16_to_cpu(bi
->RSSI
) * 100;
2511 brcmf_dbg(CONN
, "channel: %d(%d)\n", ch
.chnum
, freq
);
2512 brcmf_dbg(CONN
, "capability: %X\n", notify_capability
);
2513 brcmf_dbg(CONN
, "beacon interval: %d\n", notify_interval
);
2514 brcmf_dbg(CONN
, "signal: %d\n", notify_signal
);
2516 bss
= cfg80211_inform_bss(wiphy
, notify_channel
,
2517 CFG80211_BSS_FTYPE_UNKNOWN
, bssid
, 0,
2518 notify_capability
, notify_interval
,
2519 notify_ie
, notify_ielen
, notify_signal
,
2527 cfg80211_put_bss(wiphy
, bss
);
2533 brcmf_dbg(TRACE
, "Exit\n");
2538 static s32
brcmf_update_bss_info(struct brcmf_cfg80211_info
*cfg
,
2539 struct brcmf_if
*ifp
)
2541 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ifp
->ndev
);
2542 struct brcmf_bss_info_le
*bi
;
2543 struct brcmf_ssid
*ssid
;
2544 const struct brcmf_tlv
*tim
;
2545 u16 beacon_interval
;
2551 brcmf_dbg(TRACE
, "Enter\n");
2552 if (brcmf_is_ibssmode(ifp
->vif
))
2555 ssid
= &profile
->ssid
;
2557 *(__le32
*)cfg
->extra_buf
= cpu_to_le32(WL_EXTRA_BUF_MAX
);
2558 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
2559 cfg
->extra_buf
, WL_EXTRA_BUF_MAX
);
2561 brcmf_err("Could not get bss info %d\n", err
);
2562 goto update_bss_info_out
;
2565 bi
= (struct brcmf_bss_info_le
*)(cfg
->extra_buf
+ 4);
2566 err
= brcmf_inform_single_bss(cfg
, bi
);
2568 goto update_bss_info_out
;
2570 ie
= ((u8
*)bi
) + le16_to_cpu(bi
->ie_offset
);
2571 ie_len
= le32_to_cpu(bi
->ie_length
);
2572 beacon_interval
= le16_to_cpu(bi
->beacon_period
);
2574 tim
= brcmf_parse_tlvs(ie
, ie_len
, WLAN_EID_TIM
);
2576 dtim_period
= tim
->data
[1];
2579 * active scan was done so we could not get dtim
2580 * information out of probe response.
2581 * so we speficially query dtim information to dongle.
2584 err
= brcmf_fil_iovar_int_get(ifp
, "dtim_assoc", &var
);
2586 brcmf_err("wl dtim_assoc failed (%d)\n", err
);
2587 goto update_bss_info_out
;
2589 dtim_period
= (u8
)var
;
2592 update_bss_info_out
:
2593 brcmf_dbg(TRACE
, "Exit");
2597 void brcmf_abort_scanning(struct brcmf_cfg80211_info
*cfg
)
2599 struct escan_info
*escan
= &cfg
->escan_info
;
2601 set_bit(BRCMF_SCAN_STATUS_ABORT
, &cfg
->scan_status
);
2602 if (cfg
->scan_request
) {
2603 escan
->escan_state
= WL_ESCAN_STATE_IDLE
;
2604 brcmf_notify_escan_complete(cfg
, escan
->ifp
, true, true);
2606 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
2607 clear_bit(BRCMF_SCAN_STATUS_ABORT
, &cfg
->scan_status
);
2610 static void brcmf_cfg80211_escan_timeout_worker(struct work_struct
*work
)
2612 struct brcmf_cfg80211_info
*cfg
=
2613 container_of(work
, struct brcmf_cfg80211_info
,
2614 escan_timeout_work
);
2616 brcmf_inform_bss(cfg
);
2617 brcmf_notify_escan_complete(cfg
, cfg
->escan_info
.ifp
, true, true);
2620 static void brcmf_escan_timeout(unsigned long data
)
2622 struct brcmf_cfg80211_info
*cfg
=
2623 (struct brcmf_cfg80211_info
*)data
;
2625 if (cfg
->scan_request
) {
2626 brcmf_err("timer expired\n");
2627 schedule_work(&cfg
->escan_timeout_work
);
2632 brcmf_compare_update_same_bss(struct brcmf_cfg80211_info
*cfg
,
2633 struct brcmf_bss_info_le
*bss
,
2634 struct brcmf_bss_info_le
*bss_info_le
)
2636 struct brcmu_chan ch_bss
, ch_bss_info_le
;
2638 ch_bss
.chspec
= le16_to_cpu(bss
->chanspec
);
2639 cfg
->d11inf
.decchspec(&ch_bss
);
2640 ch_bss_info_le
.chspec
= le16_to_cpu(bss_info_le
->chanspec
);
2641 cfg
->d11inf
.decchspec(&ch_bss_info_le
);
2643 if (!memcmp(&bss_info_le
->BSSID
, &bss
->BSSID
, ETH_ALEN
) &&
2644 ch_bss
.band
== ch_bss_info_le
.band
&&
2645 bss_info_le
->SSID_len
== bss
->SSID_len
&&
2646 !memcmp(bss_info_le
->SSID
, bss
->SSID
, bss_info_le
->SSID_len
)) {
2647 if ((bss
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
) ==
2648 (bss_info_le
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
)) {
2649 s16 bss_rssi
= le16_to_cpu(bss
->RSSI
);
2650 s16 bss_info_rssi
= le16_to_cpu(bss_info_le
->RSSI
);
2652 /* preserve max RSSI if the measurements are
2653 * both on-channel or both off-channel
2655 if (bss_info_rssi
> bss_rssi
)
2656 bss
->RSSI
= bss_info_le
->RSSI
;
2657 } else if ((bss
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
) &&
2658 (bss_info_le
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
) == 0) {
2659 /* preserve the on-channel rssi measurement
2660 * if the new measurement is off channel
2662 bss
->RSSI
= bss_info_le
->RSSI
;
2663 bss
->flags
|= BRCMF_BSS_RSSI_ON_CHANNEL
;
2671 brcmf_cfg80211_escan_handler(struct brcmf_if
*ifp
,
2672 const struct brcmf_event_msg
*e
, void *data
)
2674 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
2676 struct brcmf_escan_result_le
*escan_result_le
;
2677 struct brcmf_bss_info_le
*bss_info_le
;
2678 struct brcmf_bss_info_le
*bss
= NULL
;
2680 struct brcmf_scan_results
*list
;
2686 if (!test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
2687 brcmf_err("scan not ready, bssidx=%d\n", ifp
->bssidx
);
2691 if (status
== BRCMF_E_STATUS_PARTIAL
) {
2692 brcmf_dbg(SCAN
, "ESCAN Partial result\n");
2693 escan_result_le
= (struct brcmf_escan_result_le
*) data
;
2694 if (!escan_result_le
) {
2695 brcmf_err("Invalid escan result (NULL pointer)\n");
2698 if (le16_to_cpu(escan_result_le
->bss_count
) != 1) {
2699 brcmf_err("Invalid bss_count %d: ignoring\n",
2700 escan_result_le
->bss_count
);
2703 bss_info_le
= &escan_result_le
->bss_info_le
;
2705 if (brcmf_p2p_scan_finding_common_channel(cfg
, bss_info_le
))
2708 if (!cfg
->scan_request
) {
2709 brcmf_dbg(SCAN
, "result without cfg80211 request\n");
2713 bi_length
= le32_to_cpu(bss_info_le
->length
);
2714 if (bi_length
!= (le32_to_cpu(escan_result_le
->buflen
) -
2715 WL_ESCAN_RESULTS_FIXED_SIZE
)) {
2716 brcmf_err("Invalid bss_info length %d: ignoring\n",
2721 if (!(cfg_to_wiphy(cfg
)->interface_modes
&
2722 BIT(NL80211_IFTYPE_ADHOC
))) {
2723 if (le16_to_cpu(bss_info_le
->capability
) &
2724 WLAN_CAPABILITY_IBSS
) {
2725 brcmf_err("Ignoring IBSS result\n");
2730 list
= (struct brcmf_scan_results
*)
2731 cfg
->escan_info
.escan_buf
;
2732 if (bi_length
> WL_ESCAN_BUF_SIZE
- list
->buflen
) {
2733 brcmf_err("Buffer is too small: ignoring\n");
2737 for (i
= 0; i
< list
->count
; i
++) {
2738 bss
= bss
? (struct brcmf_bss_info_le
*)
2739 ((unsigned char *)bss
+
2740 le32_to_cpu(bss
->length
)) : list
->bss_info_le
;
2741 if (brcmf_compare_update_same_bss(cfg
, bss
,
2745 memcpy(&(cfg
->escan_info
.escan_buf
[list
->buflen
]),
2746 bss_info_le
, bi_length
);
2747 list
->version
= le32_to_cpu(bss_info_le
->version
);
2748 list
->buflen
+= bi_length
;
2751 cfg
->escan_info
.escan_state
= WL_ESCAN_STATE_IDLE
;
2752 if (brcmf_p2p_scan_finding_common_channel(cfg
, NULL
))
2754 if (cfg
->scan_request
) {
2755 brcmf_inform_bss(cfg
);
2756 aborted
= status
!= BRCMF_E_STATUS_SUCCESS
;
2757 brcmf_notify_escan_complete(cfg
, ifp
, aborted
, false);
2759 brcmf_dbg(SCAN
, "Ignored scan complete result 0x%x\n",
2766 static void brcmf_init_escan(struct brcmf_cfg80211_info
*cfg
)
2768 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ESCAN_RESULT
,
2769 brcmf_cfg80211_escan_handler
);
2770 cfg
->escan_info
.escan_state
= WL_ESCAN_STATE_IDLE
;
2771 /* Init scan_timeout timer */
2772 init_timer(&cfg
->escan_timeout
);
2773 cfg
->escan_timeout
.data
= (unsigned long) cfg
;
2774 cfg
->escan_timeout
.function
= brcmf_escan_timeout
;
2775 INIT_WORK(&cfg
->escan_timeout_work
,
2776 brcmf_cfg80211_escan_timeout_worker
);
2779 static __always_inline
void brcmf_delay(u32 ms
)
2781 if (ms
< 1000 / HZ
) {
2789 static s32
brcmf_config_wowl_pattern(struct brcmf_if
*ifp
, u8 cmd
[4],
2790 u8
*pattern
, u32 patternsize
, u8
*mask
,
2793 struct brcmf_fil_wowl_pattern_le
*filter
;
2800 masksize
= (patternsize
+ 7) / 8;
2801 patternoffset
= sizeof(*filter
) - sizeof(filter
->cmd
) + masksize
;
2803 bufsize
= sizeof(*filter
) + patternsize
+ masksize
;
2804 buf
= kzalloc(bufsize
, GFP_KERNEL
);
2807 filter
= (struct brcmf_fil_wowl_pattern_le
*)buf
;
2809 memcpy(filter
->cmd
, cmd
, 4);
2810 filter
->masksize
= cpu_to_le32(masksize
);
2811 filter
->offset
= cpu_to_le32(packet_offset
);
2812 filter
->patternoffset
= cpu_to_le32(patternoffset
);
2813 filter
->patternsize
= cpu_to_le32(patternsize
);
2814 filter
->type
= cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP
);
2816 if ((mask
) && (masksize
))
2817 memcpy(buf
+ sizeof(*filter
), mask
, masksize
);
2818 if ((pattern
) && (patternsize
))
2819 memcpy(buf
+ sizeof(*filter
) + masksize
, pattern
, patternsize
);
2821 ret
= brcmf_fil_iovar_data_set(ifp
, "wowl_pattern", buf
, bufsize
);
2827 static s32
brcmf_cfg80211_resume(struct wiphy
*wiphy
)
2829 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2830 struct net_device
*ndev
= cfg_to_ndev(cfg
);
2831 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2833 brcmf_dbg(TRACE
, "Enter\n");
2835 if (cfg
->wowl_enabled
) {
2836 brcmf_configure_arp_offload(ifp
, true);
2837 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
,
2838 cfg
->pre_wowl_pmmode
);
2839 brcmf_fil_iovar_int_set(ifp
, "wowl_clear", 0);
2840 brcmf_config_wowl_pattern(ifp
, "clr", NULL
, 0, NULL
, 0);
2841 cfg
->wowl_enabled
= false;
2846 static void brcmf_configure_wowl(struct brcmf_cfg80211_info
*cfg
,
2847 struct brcmf_if
*ifp
,
2848 struct cfg80211_wowlan
*wowl
)
2853 brcmf_dbg(TRACE
, "Suspend, wowl config.\n");
2855 brcmf_configure_arp_offload(ifp
, false);
2856 brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_PM
, &cfg
->pre_wowl_pmmode
);
2857 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, PM_MAX
);
2860 if (wowl
->disconnect
)
2861 wowl_config
= BRCMF_WOWL_DIS
| BRCMF_WOWL_BCN
| BRCMF_WOWL_RETR
;
2862 if (wowl
->magic_pkt
)
2863 wowl_config
|= BRCMF_WOWL_MAGIC
;
2864 if ((wowl
->patterns
) && (wowl
->n_patterns
)) {
2865 wowl_config
|= BRCMF_WOWL_NET
;
2866 for (i
= 0; i
< wowl
->n_patterns
; i
++) {
2867 brcmf_config_wowl_pattern(ifp
, "add",
2868 (u8
*)wowl
->patterns
[i
].pattern
,
2869 wowl
->patterns
[i
].pattern_len
,
2870 (u8
*)wowl
->patterns
[i
].mask
,
2871 wowl
->patterns
[i
].pkt_offset
);
2874 brcmf_fil_iovar_int_set(ifp
, "wowl", wowl_config
);
2875 brcmf_fil_iovar_int_set(ifp
, "wowl_activate", 1);
2876 brcmf_bus_wowl_config(cfg
->pub
->bus_if
, true);
2877 cfg
->wowl_enabled
= true;
2880 static s32
brcmf_cfg80211_suspend(struct wiphy
*wiphy
,
2881 struct cfg80211_wowlan
*wowl
)
2883 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2884 struct net_device
*ndev
= cfg_to_ndev(cfg
);
2885 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2886 struct brcmf_cfg80211_vif
*vif
;
2888 brcmf_dbg(TRACE
, "Enter\n");
2890 /* if the primary net_device is not READY there is nothing
2891 * we can do but pray resume goes smoothly.
2893 if (!check_vif_up(ifp
->vif
))
2896 /* end any scanning */
2897 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
2898 brcmf_abort_scanning(cfg
);
2901 brcmf_bus_wowl_config(cfg
->pub
->bus_if
, false);
2902 list_for_each_entry(vif
, &cfg
->vif_list
, list
) {
2903 if (!test_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
))
2905 /* While going to suspend if associated with AP
2906 * disassociate from AP to save power while system is
2907 * in suspended state
2909 brcmf_link_down(vif
);
2910 /* Make sure WPA_Supplicant receives all the event
2911 * generated due to DISASSOC call to the fw to keep
2912 * the state fw and WPA_Supplicant state consistent
2917 brcmf_set_mpc(ifp
, 1);
2920 /* Configure WOWL paramaters */
2921 brcmf_configure_wowl(cfg
, ifp
, wowl
);
2925 brcmf_dbg(TRACE
, "Exit\n");
2926 /* clear any scanning activity */
2927 cfg
->scan_status
= 0;
2932 brcmf_update_pmklist(struct net_device
*ndev
,
2933 struct brcmf_cfg80211_pmk_list
*pmk_list
, s32 err
)
2938 pmkid_len
= le32_to_cpu(pmk_list
->pmkids
.npmkid
);
2940 brcmf_dbg(CONN
, "No of elements %d\n", pmkid_len
);
2941 for (i
= 0; i
< pmkid_len
; i
++) {
2942 brcmf_dbg(CONN
, "PMKID[%d]: %pM =\n", i
,
2943 &pmk_list
->pmkids
.pmkid
[i
].BSSID
);
2944 for (j
= 0; j
< WLAN_PMKID_LEN
; j
++)
2945 brcmf_dbg(CONN
, "%02x\n",
2946 pmk_list
->pmkids
.pmkid
[i
].PMKID
[j
]);
2950 brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pmkid_info",
2951 (char *)pmk_list
, sizeof(*pmk_list
));
2957 brcmf_cfg80211_set_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
2958 struct cfg80211_pmksa
*pmksa
)
2960 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2961 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2962 struct pmkid_list
*pmkids
= &cfg
->pmk_list
->pmkids
;
2966 brcmf_dbg(TRACE
, "Enter\n");
2967 if (!check_vif_up(ifp
->vif
))
2970 pmkid_len
= le32_to_cpu(pmkids
->npmkid
);
2971 for (i
= 0; i
< pmkid_len
; i
++)
2972 if (!memcmp(pmksa
->bssid
, pmkids
->pmkid
[i
].BSSID
, ETH_ALEN
))
2974 if (i
< WL_NUM_PMKIDS_MAX
) {
2975 memcpy(pmkids
->pmkid
[i
].BSSID
, pmksa
->bssid
, ETH_ALEN
);
2976 memcpy(pmkids
->pmkid
[i
].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
2977 if (i
== pmkid_len
) {
2979 pmkids
->npmkid
= cpu_to_le32(pmkid_len
);
2984 brcmf_dbg(CONN
, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2985 pmkids
->pmkid
[pmkid_len
].BSSID
);
2986 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
2987 brcmf_dbg(CONN
, "%02x\n", pmkids
->pmkid
[pmkid_len
].PMKID
[i
]);
2989 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
2991 brcmf_dbg(TRACE
, "Exit\n");
2996 brcmf_cfg80211_del_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
2997 struct cfg80211_pmksa
*pmksa
)
2999 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3000 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3001 struct pmkid_list pmkid
;
3005 brcmf_dbg(TRACE
, "Enter\n");
3006 if (!check_vif_up(ifp
->vif
))
3009 memcpy(&pmkid
.pmkid
[0].BSSID
, pmksa
->bssid
, ETH_ALEN
);
3010 memcpy(&pmkid
.pmkid
[0].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
3012 brcmf_dbg(CONN
, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3013 &pmkid
.pmkid
[0].BSSID
);
3014 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
3015 brcmf_dbg(CONN
, "%02x\n", pmkid
.pmkid
[0].PMKID
[i
]);
3017 pmkid_len
= le32_to_cpu(cfg
->pmk_list
->pmkids
.npmkid
);
3018 for (i
= 0; i
< pmkid_len
; i
++)
3020 (pmksa
->bssid
, &cfg
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3025 && (i
< pmkid_len
)) {
3026 memset(&cfg
->pmk_list
->pmkids
.pmkid
[i
], 0,
3027 sizeof(struct pmkid
));
3028 for (; i
< (pmkid_len
- 1); i
++) {
3029 memcpy(&cfg
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3030 &cfg
->pmk_list
->pmkids
.pmkid
[i
+ 1].BSSID
,
3032 memcpy(&cfg
->pmk_list
->pmkids
.pmkid
[i
].PMKID
,
3033 &cfg
->pmk_list
->pmkids
.pmkid
[i
+ 1].PMKID
,
3036 cfg
->pmk_list
->pmkids
.npmkid
= cpu_to_le32(pmkid_len
- 1);
3040 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3042 brcmf_dbg(TRACE
, "Exit\n");
3048 brcmf_cfg80211_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
)
3050 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3051 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3054 brcmf_dbg(TRACE
, "Enter\n");
3055 if (!check_vif_up(ifp
->vif
))
3058 memset(cfg
->pmk_list
, 0, sizeof(*cfg
->pmk_list
));
3059 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3061 brcmf_dbg(TRACE
, "Exit\n");
3067 * PFN result doesn't have all the info which are
3068 * required by the supplicant
3069 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3070 * via wl_inform_single_bss in the required format. Escan does require the
3071 * scan request in the form of cfg80211_scan_request. For timebeing, create
3072 * cfg80211_scan_request one out of the received PNO event.
3075 brcmf_notify_sched_scan_results(struct brcmf_if
*ifp
,
3076 const struct brcmf_event_msg
*e
, void *data
)
3078 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
3079 struct brcmf_pno_net_info_le
*netinfo
, *netinfo_start
;
3080 struct cfg80211_scan_request
*request
= NULL
;
3081 struct cfg80211_ssid
*ssid
= NULL
;
3082 struct ieee80211_channel
*channel
= NULL
;
3083 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
3085 int channel_req
= 0;
3087 struct brcmf_pno_scanresults_le
*pfn_result
;
3091 brcmf_dbg(SCAN
, "Enter\n");
3093 if (e
->event_code
== BRCMF_E_PFN_NET_LOST
) {
3094 brcmf_dbg(SCAN
, "PFN NET LOST event. Do Nothing\n");
3098 pfn_result
= (struct brcmf_pno_scanresults_le
*)data
;
3099 result_count
= le32_to_cpu(pfn_result
->count
);
3100 status
= le32_to_cpu(pfn_result
->status
);
3103 * PFN event is limited to fit 512 bytes so we may get
3104 * multiple NET_FOUND events. For now place a warning here.
3106 WARN_ON(status
!= BRCMF_PNO_SCAN_COMPLETE
);
3107 brcmf_dbg(SCAN
, "PFN NET FOUND event. count: %d\n", result_count
);
3108 if (result_count
> 0) {
3111 request
= kzalloc(sizeof(*request
), GFP_KERNEL
);
3112 ssid
= kcalloc(result_count
, sizeof(*ssid
), GFP_KERNEL
);
3113 channel
= kcalloc(result_count
, sizeof(*channel
), GFP_KERNEL
);
3114 if (!request
|| !ssid
|| !channel
) {
3119 request
->wiphy
= wiphy
;
3120 data
+= sizeof(struct brcmf_pno_scanresults_le
);
3121 netinfo_start
= (struct brcmf_pno_net_info_le
*)data
;
3123 for (i
= 0; i
< result_count
; i
++) {
3124 netinfo
= &netinfo_start
[i
];
3126 brcmf_err("Invalid netinfo ptr. index: %d\n",
3132 brcmf_dbg(SCAN
, "SSID:%s Channel:%d\n",
3133 netinfo
->SSID
, netinfo
->channel
);
3134 memcpy(ssid
[i
].ssid
, netinfo
->SSID
, netinfo
->SSID_len
);
3135 ssid
[i
].ssid_len
= netinfo
->SSID_len
;
3138 channel_req
= netinfo
->channel
;
3139 if (channel_req
<= CH_MAX_2G_CHANNEL
)
3140 band
= NL80211_BAND_2GHZ
;
3142 band
= NL80211_BAND_5GHZ
;
3143 channel
[i
].center_freq
=
3144 ieee80211_channel_to_frequency(channel_req
,
3146 channel
[i
].band
= band
;
3147 channel
[i
].flags
|= IEEE80211_CHAN_NO_HT40
;
3148 request
->channels
[i
] = &channel
[i
];
3149 request
->n_channels
++;
3152 /* assign parsed ssid array */
3153 if (request
->n_ssids
)
3154 request
->ssids
= &ssid
[0];
3156 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
3157 /* Abort any on-going scan */
3158 brcmf_abort_scanning(cfg
);
3161 set_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
3162 cfg
->escan_info
.run
= brcmf_run_escan
;
3163 err
= brcmf_do_escan(cfg
, wiphy
, ifp
, request
);
3165 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
3168 cfg
->sched_escan
= true;
3169 cfg
->scan_request
= request
;
3171 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3184 cfg80211_sched_scan_stopped(wiphy
);
3188 static int brcmf_dev_pno_clean(struct net_device
*ndev
)
3193 ret
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "pfn", 0);
3196 ret
= brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pfnclear",
3200 brcmf_err("failed code %d\n", ret
);
3205 static int brcmf_dev_pno_config(struct net_device
*ndev
)
3207 struct brcmf_pno_param_le pfn_param
;
3209 memset(&pfn_param
, 0, sizeof(pfn_param
));
3210 pfn_param
.version
= cpu_to_le32(BRCMF_PNO_VERSION
);
3212 /* set extra pno params */
3213 pfn_param
.flags
= cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT
);
3214 pfn_param
.repeat
= BRCMF_PNO_REPEAT
;
3215 pfn_param
.exp
= BRCMF_PNO_FREQ_EXPO_MAX
;
3217 /* set up pno scan fr */
3218 pfn_param
.scan_freq
= cpu_to_le32(BRCMF_PNO_TIME
);
3220 return brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pfn_set",
3221 &pfn_param
, sizeof(pfn_param
));
3225 brcmf_cfg80211_sched_scan_start(struct wiphy
*wiphy
,
3226 struct net_device
*ndev
,
3227 struct cfg80211_sched_scan_request
*request
)
3229 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3230 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
3231 struct brcmf_pno_net_param_le pfn
;
3235 brcmf_dbg(SCAN
, "Enter n_match_sets:%d n_ssids:%d\n",
3236 request
->n_match_sets
, request
->n_ssids
);
3237 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
3238 brcmf_err("Scanning already: status (%lu)\n", cfg
->scan_status
);
3241 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
)) {
3242 brcmf_err("Scanning suppressed: status (%lu)\n",
3247 if (!request
->n_ssids
|| !request
->n_match_sets
) {
3248 brcmf_dbg(SCAN
, "Invalid sched scan req!! n_ssids:%d\n",
3253 if (request
->n_ssids
> 0) {
3254 for (i
= 0; i
< request
->n_ssids
; i
++) {
3255 /* Active scan req for ssids */
3256 brcmf_dbg(SCAN
, ">>> Active scan req for ssid (%s)\n",
3257 request
->ssids
[i
].ssid
);
3260 * match_set ssids is a supert set of n_ssid list,
3261 * so we need not add these set seperately.
3266 if (request
->n_match_sets
> 0) {
3267 /* clean up everything */
3268 ret
= brcmf_dev_pno_clean(ndev
);
3270 brcmf_err("failed error=%d\n", ret
);
3275 ret
= brcmf_dev_pno_config(ndev
);
3277 brcmf_err("PNO setup failed!! ret=%d\n", ret
);
3281 /* configure each match set */
3282 for (i
= 0; i
< request
->n_match_sets
; i
++) {
3283 struct cfg80211_ssid
*ssid
;
3286 ssid
= &request
->match_sets
[i
].ssid
;
3287 ssid_len
= ssid
->ssid_len
;
3290 brcmf_err("skip broadcast ssid\n");
3293 pfn
.auth
= cpu_to_le32(WLAN_AUTH_OPEN
);
3294 pfn
.wpa_auth
= cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY
);
3295 pfn
.wsec
= cpu_to_le32(0);
3296 pfn
.infra
= cpu_to_le32(1);
3297 pfn
.flags
= cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT
);
3298 pfn
.ssid
.SSID_len
= cpu_to_le32(ssid_len
);
3299 memcpy(pfn
.ssid
.SSID
, ssid
->ssid
, ssid_len
);
3300 ret
= brcmf_fil_iovar_data_set(ifp
, "pfn_add", &pfn
,
3302 brcmf_dbg(SCAN
, ">>> PNO filter %s for ssid (%s)\n",
3303 ret
== 0 ? "set" : "failed", ssid
->ssid
);
3305 /* Enable the PNO */
3306 if (brcmf_fil_iovar_int_set(ifp
, "pfn", 1) < 0) {
3307 brcmf_err("PNO enable failed!! ret=%d\n", ret
);
3317 static int brcmf_cfg80211_sched_scan_stop(struct wiphy
*wiphy
,
3318 struct net_device
*ndev
)
3320 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3322 brcmf_dbg(SCAN
, "enter\n");
3323 brcmf_dev_pno_clean(ndev
);
3324 if (cfg
->sched_escan
)
3325 brcmf_notify_escan_complete(cfg
, netdev_priv(ndev
), true, true);
3329 static s32
brcmf_configure_opensecurity(struct brcmf_if
*ifp
)
3334 err
= brcmf_fil_bsscfg_int_set(ifp
, "auth", 0);
3336 brcmf_err("auth error %d\n", err
);
3340 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", 0);
3342 brcmf_err("wsec error %d\n", err
);
3345 /* set upper-layer auth */
3346 err
= brcmf_fil_bsscfg_int_set(ifp
, "wpa_auth", WPA_AUTH_NONE
);
3348 brcmf_err("wpa_auth error %d\n", err
);
3355 static bool brcmf_valid_wpa_oui(u8
*oui
, bool is_rsn_ie
)
3358 return (memcmp(oui
, RSN_OUI
, TLV_OUI_LEN
) == 0);
3360 return (memcmp(oui
, WPA_OUI
, TLV_OUI_LEN
) == 0);
3364 brcmf_configure_wpaie(struct net_device
*ndev
,
3365 const struct brcmf_vs_tlv
*wpa_ie
,
3368 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3369 u32 auth
= 0; /* d11 open authentication */
3381 u32 wme_bss_disable
;
3383 brcmf_dbg(TRACE
, "Enter\n");
3387 len
= wpa_ie
->len
+ TLV_HDR_LEN
;
3388 data
= (u8
*)wpa_ie
;
3389 offset
= TLV_HDR_LEN
;
3391 offset
+= VS_IE_FIXED_HDR_LEN
;
3393 offset
+= WPA_IE_VERSION_LEN
;
3395 /* check for multicast cipher suite */
3396 if (offset
+ WPA_IE_MIN_OUI_LEN
> len
) {
3398 brcmf_err("no multicast cipher suite\n");
3402 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3404 brcmf_err("ivalid OUI\n");
3407 offset
+= TLV_OUI_LEN
;
3409 /* pick up multicast cipher */
3410 switch (data
[offset
]) {
3411 case WPA_CIPHER_NONE
:
3414 case WPA_CIPHER_WEP_40
:
3415 case WPA_CIPHER_WEP_104
:
3418 case WPA_CIPHER_TKIP
:
3419 gval
= TKIP_ENABLED
;
3421 case WPA_CIPHER_AES_CCM
:
3426 brcmf_err("Invalid multi cast cipher info\n");
3431 /* walk thru unicast cipher list and pick up what we recognize */
3432 count
= data
[offset
] + (data
[offset
+ 1] << 8);
3433 offset
+= WPA_IE_SUITE_COUNT_LEN
;
3434 /* Check for unicast suite(s) */
3435 if (offset
+ (WPA_IE_MIN_OUI_LEN
* count
) > len
) {
3437 brcmf_err("no unicast cipher suite\n");
3440 for (i
= 0; i
< count
; i
++) {
3441 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3443 brcmf_err("ivalid OUI\n");
3446 offset
+= TLV_OUI_LEN
;
3447 switch (data
[offset
]) {
3448 case WPA_CIPHER_NONE
:
3450 case WPA_CIPHER_WEP_40
:
3451 case WPA_CIPHER_WEP_104
:
3452 pval
|= WEP_ENABLED
;
3454 case WPA_CIPHER_TKIP
:
3455 pval
|= TKIP_ENABLED
;
3457 case WPA_CIPHER_AES_CCM
:
3458 pval
|= AES_ENABLED
;
3461 brcmf_err("Ivalid unicast security info\n");
3465 /* walk thru auth management suite list and pick up what we recognize */
3466 count
= data
[offset
] + (data
[offset
+ 1] << 8);
3467 offset
+= WPA_IE_SUITE_COUNT_LEN
;
3468 /* Check for auth key management suite(s) */
3469 if (offset
+ (WPA_IE_MIN_OUI_LEN
* count
) > len
) {
3471 brcmf_err("no auth key mgmt suite\n");
3474 for (i
= 0; i
< count
; i
++) {
3475 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3477 brcmf_err("ivalid OUI\n");
3480 offset
+= TLV_OUI_LEN
;
3481 switch (data
[offset
]) {
3483 brcmf_dbg(TRACE
, "RSN_AKM_NONE\n");
3484 wpa_auth
|= WPA_AUTH_NONE
;
3486 case RSN_AKM_UNSPECIFIED
:
3487 brcmf_dbg(TRACE
, "RSN_AKM_UNSPECIFIED\n");
3488 is_rsn_ie
? (wpa_auth
|= WPA2_AUTH_UNSPECIFIED
) :
3489 (wpa_auth
|= WPA_AUTH_UNSPECIFIED
);
3492 brcmf_dbg(TRACE
, "RSN_AKM_PSK\n");
3493 is_rsn_ie
? (wpa_auth
|= WPA2_AUTH_PSK
) :
3494 (wpa_auth
|= WPA_AUTH_PSK
);
3497 brcmf_err("Ivalid key mgmt info\n");
3503 wme_bss_disable
= 1;
3504 if ((offset
+ RSN_CAP_LEN
) <= len
) {
3505 rsn_cap
= data
[offset
] + (data
[offset
+ 1] << 8);
3506 if (rsn_cap
& RSN_CAP_PTK_REPLAY_CNTR_MASK
)
3507 wme_bss_disable
= 0;
3509 /* set wme_bss_disable to sync RSN Capabilities */
3510 err
= brcmf_fil_bsscfg_int_set(ifp
, "wme_bss_disable",
3513 brcmf_err("wme_bss_disable error %d\n", err
);
3517 /* FOR WPS , set SES_OW_ENABLED */
3518 wsec
= (pval
| gval
| SES_OW_ENABLED
);
3521 err
= brcmf_fil_bsscfg_int_set(ifp
, "auth", auth
);
3523 brcmf_err("auth error %d\n", err
);
3527 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", wsec
);
3529 brcmf_err("wsec error %d\n", err
);
3532 /* set upper-layer auth */
3533 err
= brcmf_fil_bsscfg_int_set(ifp
, "wpa_auth", wpa_auth
);
3535 brcmf_err("wpa_auth error %d\n", err
);
3544 brcmf_parse_vndr_ies(const u8
*vndr_ie_buf
, u32 vndr_ie_len
,
3545 struct parsed_vndr_ies
*vndr_ies
)
3547 struct brcmf_vs_tlv
*vndrie
;
3548 struct brcmf_tlv
*ie
;
3549 struct parsed_vndr_ie_info
*parsed_info
;
3552 remaining_len
= (s32
)vndr_ie_len
;
3553 memset(vndr_ies
, 0, sizeof(*vndr_ies
));
3555 ie
= (struct brcmf_tlv
*)vndr_ie_buf
;
3557 if (ie
->id
!= WLAN_EID_VENDOR_SPECIFIC
)
3559 vndrie
= (struct brcmf_vs_tlv
*)ie
;
3560 /* len should be bigger than OUI length + one */
3561 if (vndrie
->len
< (VS_IE_FIXED_HDR_LEN
- TLV_HDR_LEN
+ 1)) {
3562 brcmf_err("invalid vndr ie. length is too small %d\n",
3566 /* if wpa or wme ie, do not add ie */
3567 if (!memcmp(vndrie
->oui
, (u8
*)WPA_OUI
, TLV_OUI_LEN
) &&
3568 ((vndrie
->oui_type
== WPA_OUI_TYPE
) ||
3569 (vndrie
->oui_type
== WME_OUI_TYPE
))) {
3570 brcmf_dbg(TRACE
, "Found WPA/WME oui. Do not add it\n");
3574 parsed_info
= &vndr_ies
->ie_info
[vndr_ies
->count
];
3576 /* save vndr ie information */
3577 parsed_info
->ie_ptr
= (char *)vndrie
;
3578 parsed_info
->ie_len
= vndrie
->len
+ TLV_HDR_LEN
;
3579 memcpy(&parsed_info
->vndrie
, vndrie
, sizeof(*vndrie
));
3583 brcmf_dbg(TRACE
, "** OUI %02x %02x %02x, type 0x%02x\n",
3584 parsed_info
->vndrie
.oui
[0],
3585 parsed_info
->vndrie
.oui
[1],
3586 parsed_info
->vndrie
.oui
[2],
3587 parsed_info
->vndrie
.oui_type
);
3589 if (vndr_ies
->count
>= VNDR_IE_PARSE_LIMIT
)
3592 remaining_len
-= (ie
->len
+ TLV_HDR_LEN
);
3593 if (remaining_len
<= TLV_HDR_LEN
)
3596 ie
= (struct brcmf_tlv
*)(((u8
*)ie
) + ie
->len
+
3603 brcmf_vndr_ie(u8
*iebuf
, s32 pktflag
, u8
*ie_ptr
, u32 ie_len
, s8
*add_del_cmd
)
3609 strncpy(iebuf
, add_del_cmd
, VNDR_IE_CMD_LEN
- 1);
3610 iebuf
[VNDR_IE_CMD_LEN
- 1] = '\0';
3612 iecount_le
= cpu_to_le32(1);
3613 memcpy(&iebuf
[VNDR_IE_COUNT_OFFSET
], &iecount_le
, sizeof(iecount_le
));
3615 pktflag_le
= cpu_to_le32(pktflag
);
3616 memcpy(&iebuf
[VNDR_IE_PKTFLAG_OFFSET
], &pktflag_le
, sizeof(pktflag_le
));
3618 memcpy(&iebuf
[VNDR_IE_VSIE_OFFSET
], ie_ptr
, ie_len
);
3620 return ie_len
+ VNDR_IE_HDR_SIZE
;
3623 s32
brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif
*vif
, s32 pktflag
,
3624 const u8
*vndr_ie_buf
, u32 vndr_ie_len
)
3626 struct brcmf_if
*ifp
;
3627 struct vif_saved_ie
*saved_ie
;
3631 u8
*mgmt_ie_buf
= NULL
;
3632 int mgmt_ie_buf_len
;
3634 u32 del_add_ie_buf_len
= 0;
3635 u32 total_ie_buf_len
= 0;
3636 u32 parsed_ie_buf_len
= 0;
3637 struct parsed_vndr_ies old_vndr_ies
;
3638 struct parsed_vndr_ies new_vndr_ies
;
3639 struct parsed_vndr_ie_info
*vndrie_info
;
3642 int remained_buf_len
;
3647 saved_ie
= &vif
->saved_ie
;
3649 brcmf_dbg(TRACE
, "bssidx %d, pktflag : 0x%02X\n", ifp
->bssidx
, pktflag
);
3650 iovar_ie_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
3653 curr_ie_buf
= iovar_ie_buf
;
3655 case BRCMF_VNDR_IE_PRBREQ_FLAG
:
3656 mgmt_ie_buf
= saved_ie
->probe_req_ie
;
3657 mgmt_ie_len
= &saved_ie
->probe_req_ie_len
;
3658 mgmt_ie_buf_len
= sizeof(saved_ie
->probe_req_ie
);
3660 case BRCMF_VNDR_IE_PRBRSP_FLAG
:
3661 mgmt_ie_buf
= saved_ie
->probe_res_ie
;
3662 mgmt_ie_len
= &saved_ie
->probe_res_ie_len
;
3663 mgmt_ie_buf_len
= sizeof(saved_ie
->probe_res_ie
);
3665 case BRCMF_VNDR_IE_BEACON_FLAG
:
3666 mgmt_ie_buf
= saved_ie
->beacon_ie
;
3667 mgmt_ie_len
= &saved_ie
->beacon_ie_len
;
3668 mgmt_ie_buf_len
= sizeof(saved_ie
->beacon_ie
);
3670 case BRCMF_VNDR_IE_ASSOCREQ_FLAG
:
3671 mgmt_ie_buf
= saved_ie
->assoc_req_ie
;
3672 mgmt_ie_len
= &saved_ie
->assoc_req_ie_len
;
3673 mgmt_ie_buf_len
= sizeof(saved_ie
->assoc_req_ie
);
3677 brcmf_err("not suitable type\n");
3681 if (vndr_ie_len
> mgmt_ie_buf_len
) {
3683 brcmf_err("extra IE size too big\n");
3687 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3688 if (vndr_ie_buf
&& vndr_ie_len
&& curr_ie_buf
) {
3690 brcmf_parse_vndr_ies(vndr_ie_buf
, vndr_ie_len
, &new_vndr_ies
);
3691 for (i
= 0; i
< new_vndr_ies
.count
; i
++) {
3692 vndrie_info
= &new_vndr_ies
.ie_info
[i
];
3693 memcpy(ptr
+ parsed_ie_buf_len
, vndrie_info
->ie_ptr
,
3694 vndrie_info
->ie_len
);
3695 parsed_ie_buf_len
+= vndrie_info
->ie_len
;
3699 if (mgmt_ie_buf
&& *mgmt_ie_len
) {
3700 if (parsed_ie_buf_len
&& (parsed_ie_buf_len
== *mgmt_ie_len
) &&
3701 (memcmp(mgmt_ie_buf
, curr_ie_buf
,
3702 parsed_ie_buf_len
) == 0)) {
3703 brcmf_dbg(TRACE
, "Previous mgmt IE equals to current IE\n");
3707 /* parse old vndr_ie */
3708 brcmf_parse_vndr_ies(mgmt_ie_buf
, *mgmt_ie_len
, &old_vndr_ies
);
3710 /* make a command to delete old ie */
3711 for (i
= 0; i
< old_vndr_ies
.count
; i
++) {
3712 vndrie_info
= &old_vndr_ies
.ie_info
[i
];
3714 brcmf_dbg(TRACE
, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3715 vndrie_info
->vndrie
.id
,
3716 vndrie_info
->vndrie
.len
,
3717 vndrie_info
->vndrie
.oui
[0],
3718 vndrie_info
->vndrie
.oui
[1],
3719 vndrie_info
->vndrie
.oui
[2]);
3721 del_add_ie_buf_len
= brcmf_vndr_ie(curr_ie_buf
, pktflag
,
3722 vndrie_info
->ie_ptr
,
3723 vndrie_info
->ie_len
,
3725 curr_ie_buf
+= del_add_ie_buf_len
;
3726 total_ie_buf_len
+= del_add_ie_buf_len
;
3731 /* Add if there is any extra IE */
3732 if (mgmt_ie_buf
&& parsed_ie_buf_len
) {
3735 remained_buf_len
= mgmt_ie_buf_len
;
3737 /* make a command to add new ie */
3738 for (i
= 0; i
< new_vndr_ies
.count
; i
++) {
3739 vndrie_info
= &new_vndr_ies
.ie_info
[i
];
3741 /* verify remained buf size before copy data */
3742 if (remained_buf_len
< (vndrie_info
->vndrie
.len
+
3743 VNDR_IE_VSIE_OFFSET
)) {
3744 brcmf_err("no space in mgmt_ie_buf: len left %d",
3748 remained_buf_len
-= (vndrie_info
->ie_len
+
3749 VNDR_IE_VSIE_OFFSET
);
3751 brcmf_dbg(TRACE
, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3752 vndrie_info
->vndrie
.id
,
3753 vndrie_info
->vndrie
.len
,
3754 vndrie_info
->vndrie
.oui
[0],
3755 vndrie_info
->vndrie
.oui
[1],
3756 vndrie_info
->vndrie
.oui
[2]);
3758 del_add_ie_buf_len
= brcmf_vndr_ie(curr_ie_buf
, pktflag
,
3759 vndrie_info
->ie_ptr
,
3760 vndrie_info
->ie_len
,
3763 /* save the parsed IE in wl struct */
3764 memcpy(ptr
+ (*mgmt_ie_len
), vndrie_info
->ie_ptr
,
3765 vndrie_info
->ie_len
);
3766 *mgmt_ie_len
+= vndrie_info
->ie_len
;
3768 curr_ie_buf
+= del_add_ie_buf_len
;
3769 total_ie_buf_len
+= del_add_ie_buf_len
;
3772 if (total_ie_buf_len
) {
3773 err
= brcmf_fil_bsscfg_data_set(ifp
, "vndr_ie", iovar_ie_buf
,
3776 brcmf_err("vndr ie set error : %d\n", err
);
3780 kfree(iovar_ie_buf
);
3784 s32
brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif
*vif
)
3787 BRCMF_VNDR_IE_PRBREQ_FLAG
,
3788 BRCMF_VNDR_IE_PRBRSP_FLAG
,
3789 BRCMF_VNDR_IE_BEACON_FLAG
3793 for (i
= 0; i
< ARRAY_SIZE(pktflags
); i
++)
3794 brcmf_vif_set_mgmt_ie(vif
, pktflags
[i
], NULL
, 0);
3796 memset(&vif
->saved_ie
, 0, sizeof(vif
->saved_ie
));
3801 brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif
*vif
,
3802 struct cfg80211_beacon_data
*beacon
)
3806 /* Set Beacon IEs to FW */
3807 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_BEACON_FLAG
,
3808 beacon
->tail
, beacon
->tail_len
);
3810 brcmf_err("Set Beacon IE Failed\n");
3813 brcmf_dbg(TRACE
, "Applied Vndr IEs for Beacon\n");
3815 /* Set Probe Response IEs to FW */
3816 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_PRBRSP_FLAG
,
3817 beacon
->proberesp_ies
,
3818 beacon
->proberesp_ies_len
);
3820 brcmf_err("Set Probe Resp IE Failed\n");
3822 brcmf_dbg(TRACE
, "Applied Vndr IEs for Probe Resp\n");
3828 brcmf_cfg80211_start_ap(struct wiphy
*wiphy
, struct net_device
*ndev
,
3829 struct cfg80211_ap_settings
*settings
)
3832 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3833 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3834 const struct brcmf_tlv
*ssid_ie
;
3835 struct brcmf_ssid_le ssid_le
;
3837 const struct brcmf_tlv
*rsn_ie
;
3838 const struct brcmf_vs_tlv
*wpa_ie
;
3839 struct brcmf_join_params join_params
;
3840 enum nl80211_iftype dev_role
;
3841 struct brcmf_fil_bss_enable_le bss_enable
;
3844 brcmf_dbg(TRACE
, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3845 settings
->chandef
.chan
->hw_value
,
3846 settings
->chandef
.center_freq1
, settings
->chandef
.width
,
3847 settings
->beacon_interval
, settings
->dtim_period
);
3848 brcmf_dbg(TRACE
, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3849 settings
->ssid
, settings
->ssid_len
, settings
->auth_type
,
3850 settings
->inactivity_timeout
);
3852 dev_role
= ifp
->vif
->wdev
.iftype
;
3854 memset(&ssid_le
, 0, sizeof(ssid_le
));
3855 if (settings
->ssid
== NULL
|| settings
->ssid_len
== 0) {
3856 ie_offset
= DOT11_MGMT_HDR_LEN
+ DOT11_BCN_PRB_FIXED_LEN
;
3857 ssid_ie
= brcmf_parse_tlvs(
3858 (u8
*)&settings
->beacon
.head
[ie_offset
],
3859 settings
->beacon
.head_len
- ie_offset
,
3864 memcpy(ssid_le
.SSID
, ssid_ie
->data
, ssid_ie
->len
);
3865 ssid_le
.SSID_len
= cpu_to_le32(ssid_ie
->len
);
3866 brcmf_dbg(TRACE
, "SSID is (%s) in Head\n", ssid_le
.SSID
);
3868 memcpy(ssid_le
.SSID
, settings
->ssid
, settings
->ssid_len
);
3869 ssid_le
.SSID_len
= cpu_to_le32((u32
)settings
->ssid_len
);
3872 brcmf_set_mpc(ifp
, 0);
3873 brcmf_configure_arp_offload(ifp
, false);
3875 /* find the RSN_IE */
3876 rsn_ie
= brcmf_parse_tlvs((u8
*)settings
->beacon
.tail
,
3877 settings
->beacon
.tail_len
, WLAN_EID_RSN
);
3879 /* find the WPA_IE */
3880 wpa_ie
= brcmf_find_wpaie((u8
*)settings
->beacon
.tail
,
3881 settings
->beacon
.tail_len
);
3883 if ((wpa_ie
!= NULL
|| rsn_ie
!= NULL
)) {
3884 brcmf_dbg(TRACE
, "WPA(2) IE is found\n");
3885 if (wpa_ie
!= NULL
) {
3887 err
= brcmf_configure_wpaie(ndev
, wpa_ie
, false);
3892 err
= brcmf_configure_wpaie(ndev
,
3893 (struct brcmf_vs_tlv
*)rsn_ie
, true);
3898 brcmf_dbg(TRACE
, "No WPA(2) IEs found\n");
3899 brcmf_configure_opensecurity(ifp
);
3902 brcmf_config_ap_mgmt_ie(ifp
->vif
, &settings
->beacon
);
3904 chanspec
= chandef_to_chanspec(&cfg
->d11inf
, &settings
->chandef
);
3905 err
= brcmf_fil_iovar_int_set(ifp
, "chanspec", chanspec
);
3907 brcmf_err("Set Channel failed: chspec=%d, %d\n", chanspec
, err
);
3911 if (settings
->beacon_interval
) {
3912 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_BCNPRD
,
3913 settings
->beacon_interval
);
3915 brcmf_err("Beacon Interval Set Error, %d\n", err
);
3919 if (settings
->dtim_period
) {
3920 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_DTIMPRD
,
3921 settings
->dtim_period
);
3923 brcmf_err("DTIM Interval Set Error, %d\n", err
);
3928 if (dev_role
== NL80211_IFTYPE_AP
) {
3929 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
3931 brcmf_err("BRCMF_C_DOWN error %d\n", err
);
3934 brcmf_fil_iovar_int_set(ifp
, "apsta", 0);
3937 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, 1);
3939 brcmf_err("SET INFRA error %d\n", err
);
3942 if (dev_role
== NL80211_IFTYPE_AP
) {
3943 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_AP
, 1);
3945 brcmf_err("setting AP mode failed %d\n", err
);
3948 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 1);
3950 brcmf_err("BRCMF_C_UP error (%d)\n", err
);
3954 memset(&join_params
, 0, sizeof(join_params
));
3955 /* join parameters starts with ssid */
3956 memcpy(&join_params
.ssid_le
, &ssid_le
, sizeof(ssid_le
));
3958 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
3959 &join_params
, sizeof(join_params
));
3961 brcmf_err("SET SSID error (%d)\n", err
);
3964 brcmf_dbg(TRACE
, "AP mode configuration complete\n");
3966 err
= brcmf_fil_bsscfg_data_set(ifp
, "ssid", &ssid_le
,
3969 brcmf_err("setting ssid failed %d\n", err
);
3972 bss_enable
.bsscfg_idx
= cpu_to_le32(ifp
->bssidx
);
3973 bss_enable
.enable
= cpu_to_le32(1);
3974 err
= brcmf_fil_iovar_data_set(ifp
, "bss", &bss_enable
,
3975 sizeof(bss_enable
));
3977 brcmf_err("bss_enable config failed %d\n", err
);
3981 brcmf_dbg(TRACE
, "GO mode configuration complete\n");
3983 clear_bit(BRCMF_VIF_STATUS_AP_CREATING
, &ifp
->vif
->sme_state
);
3984 set_bit(BRCMF_VIF_STATUS_AP_CREATED
, &ifp
->vif
->sme_state
);
3988 brcmf_set_mpc(ifp
, 1);
3989 brcmf_configure_arp_offload(ifp
, true);
3994 static int brcmf_cfg80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*ndev
)
3996 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3998 struct brcmf_fil_bss_enable_le bss_enable
;
3999 struct brcmf_join_params join_params
;
4001 brcmf_dbg(TRACE
, "Enter\n");
4003 if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_AP
) {
4004 /* Due to most likely deauths outstanding we sleep */
4005 /* first to make sure they get processed by fw. */
4008 memset(&join_params
, 0, sizeof(join_params
));
4009 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
4010 &join_params
, sizeof(join_params
));
4012 brcmf_err("SET SSID error (%d)\n", err
);
4013 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
4015 brcmf_err("BRCMF_C_UP error %d\n", err
);
4016 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_AP
, 0);
4018 brcmf_err("setting AP mode failed %d\n", err
);
4019 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, 0);
4021 brcmf_err("setting INFRA mode failed %d\n", err
);
4023 bss_enable
.bsscfg_idx
= cpu_to_le32(ifp
->bssidx
);
4024 bss_enable
.enable
= cpu_to_le32(0);
4025 err
= brcmf_fil_iovar_data_set(ifp
, "bss", &bss_enable
,
4026 sizeof(bss_enable
));
4028 brcmf_err("bss_enable config failed %d\n", err
);
4030 brcmf_set_mpc(ifp
, 1);
4031 brcmf_configure_arp_offload(ifp
, true);
4032 set_bit(BRCMF_VIF_STATUS_AP_CREATING
, &ifp
->vif
->sme_state
);
4033 clear_bit(BRCMF_VIF_STATUS_AP_CREATED
, &ifp
->vif
->sme_state
);
4039 brcmf_cfg80211_change_beacon(struct wiphy
*wiphy
, struct net_device
*ndev
,
4040 struct cfg80211_beacon_data
*info
)
4042 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4045 brcmf_dbg(TRACE
, "Enter\n");
4047 err
= brcmf_config_ap_mgmt_ie(ifp
->vif
, info
);
4053 brcmf_cfg80211_del_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
4054 struct station_del_parameters
*params
)
4056 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4057 struct brcmf_scb_val_le scbval
;
4058 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4064 brcmf_dbg(TRACE
, "Enter %pM\n", params
->mac
);
4066 if (ifp
->vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
4067 ifp
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
4068 if (!check_vif_up(ifp
->vif
))
4071 memcpy(&scbval
.ea
, params
->mac
, ETH_ALEN
);
4072 scbval
.val
= cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING
);
4073 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON
,
4074 &scbval
, sizeof(scbval
));
4076 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err
);
4078 brcmf_dbg(TRACE
, "Exit\n");
4084 brcmf_cfg80211_mgmt_frame_register(struct wiphy
*wiphy
,
4085 struct wireless_dev
*wdev
,
4086 u16 frame_type
, bool reg
)
4088 struct brcmf_cfg80211_vif
*vif
;
4091 brcmf_dbg(TRACE
, "Enter, frame_type %04x, reg=%d\n", frame_type
, reg
);
4093 mgmt_type
= (frame_type
& IEEE80211_FCTL_STYPE
) >> 4;
4094 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4096 vif
->mgmt_rx_reg
|= BIT(mgmt_type
);
4098 vif
->mgmt_rx_reg
&= ~BIT(mgmt_type
);
4103 brcmf_cfg80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
4104 struct cfg80211_mgmt_tx_params
*params
, u64
*cookie
)
4106 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4107 struct ieee80211_channel
*chan
= params
->chan
;
4108 const u8
*buf
= params
->buf
;
4109 size_t len
= params
->len
;
4110 const struct ieee80211_mgmt
*mgmt
;
4111 struct brcmf_cfg80211_vif
*vif
;
4115 struct brcmf_fil_action_frame_le
*action_frame
;
4116 struct brcmf_fil_af_params_le
*af_params
;
4121 brcmf_dbg(TRACE
, "Enter\n");
4125 mgmt
= (const struct ieee80211_mgmt
*)buf
;
4127 if (!ieee80211_is_mgmt(mgmt
->frame_control
)) {
4128 brcmf_err("Driver only allows MGMT packet type\n");
4132 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4134 if (ieee80211_is_probe_resp(mgmt
->frame_control
)) {
4135 /* Right now the only reason to get a probe response */
4136 /* is for p2p listen response or for p2p GO from */
4137 /* wpa_supplicant. Unfortunately the probe is send */
4138 /* on primary ndev, while dongle wants it on the p2p */
4139 /* vif. Since this is only reason for a probe */
4140 /* response to be sent, the vif is taken from cfg. */
4141 /* If ever desired to send proberesp for non p2p */
4142 /* response then data should be checked for */
4143 /* "DIRECT-". Note in future supplicant will take */
4144 /* dedicated p2p wdev to do this and then this 'hack'*/
4145 /* is not needed anymore. */
4146 ie_offset
= DOT11_MGMT_HDR_LEN
+
4147 DOT11_BCN_PRB_FIXED_LEN
;
4148 ie_len
= len
- ie_offset
;
4149 if (vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
)
4150 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
4151 err
= brcmf_vif_set_mgmt_ie(vif
,
4152 BRCMF_VNDR_IE_PRBRSP_FLAG
,
4155 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, true,
4157 } else if (ieee80211_is_action(mgmt
->frame_control
)) {
4158 af_params
= kzalloc(sizeof(*af_params
), GFP_KERNEL
);
4159 if (af_params
== NULL
) {
4160 brcmf_err("unable to allocate frame\n");
4164 action_frame
= &af_params
->action_frame
;
4165 /* Add the packet Id */
4166 action_frame
->packet_id
= cpu_to_le32(*cookie
);
4168 memcpy(&action_frame
->da
[0], &mgmt
->da
[0], ETH_ALEN
);
4169 memcpy(&af_params
->bssid
[0], &mgmt
->bssid
[0], ETH_ALEN
);
4170 /* Add the length exepted for 802.11 header */
4171 action_frame
->len
= cpu_to_le16(len
- DOT11_MGMT_HDR_LEN
);
4172 /* Add the channel. Use the one specified as parameter if any or
4173 * the current one (got from the firmware) otherwise
4176 freq
= chan
->center_freq
;
4178 brcmf_fil_cmd_int_get(vif
->ifp
, BRCMF_C_GET_CHANNEL
,
4180 chan_nr
= ieee80211_frequency_to_channel(freq
);
4181 af_params
->channel
= cpu_to_le32(chan_nr
);
4183 memcpy(action_frame
->data
, &buf
[DOT11_MGMT_HDR_LEN
],
4184 le16_to_cpu(action_frame
->len
));
4186 brcmf_dbg(TRACE
, "Action frame, cookie=%lld, len=%d, freq=%d\n",
4187 *cookie
, le16_to_cpu(action_frame
->len
), freq
);
4189 ack
= brcmf_p2p_send_action_frame(cfg
, cfg_to_ndev(cfg
),
4192 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, ack
,
4196 brcmf_dbg(TRACE
, "Unhandled, fc=%04x!!\n", mgmt
->frame_control
);
4197 brcmf_dbg_hex_dump(true, buf
, len
, "payload, len=%Zu\n", len
);
4206 brcmf_cfg80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
4207 struct wireless_dev
*wdev
,
4210 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4211 struct brcmf_cfg80211_vif
*vif
;
4214 brcmf_dbg(TRACE
, "Enter p2p listen cancel\n");
4216 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
4218 brcmf_err("No p2p device available for probe response\n");
4222 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
4227 static int brcmf_cfg80211_crit_proto_start(struct wiphy
*wiphy
,
4228 struct wireless_dev
*wdev
,
4229 enum nl80211_crit_proto_id proto
,
4232 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4233 struct brcmf_cfg80211_vif
*vif
;
4235 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4237 /* only DHCP support for now */
4238 if (proto
!= NL80211_CRIT_PROTO_DHCP
)
4241 /* suppress and abort scanning */
4242 set_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
4243 brcmf_abort_scanning(cfg
);
4245 return brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_DISABLED
, duration
);
4248 static void brcmf_cfg80211_crit_proto_stop(struct wiphy
*wiphy
,
4249 struct wireless_dev
*wdev
)
4251 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4252 struct brcmf_cfg80211_vif
*vif
;
4254 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4256 brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_ENABLED
, 0);
4257 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
4261 brcmf_notify_tdls_peer_event(struct brcmf_if
*ifp
,
4262 const struct brcmf_event_msg
*e
, void *data
)
4264 switch (e
->reason
) {
4265 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED
:
4266 brcmf_dbg(TRACE
, "TDLS Peer Discovered\n");
4268 case BRCMF_E_REASON_TDLS_PEER_CONNECTED
:
4269 brcmf_dbg(TRACE
, "TDLS Peer Connected\n");
4270 brcmf_proto_add_tdls_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4272 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED
:
4273 brcmf_dbg(TRACE
, "TDLS Peer Disconnected\n");
4274 brcmf_proto_delete_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4281 static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper
)
4286 case NL80211_TDLS_DISCOVERY_REQ
:
4287 ret
= BRCMF_TDLS_MANUAL_EP_DISCOVERY
;
4289 case NL80211_TDLS_SETUP
:
4290 ret
= BRCMF_TDLS_MANUAL_EP_CREATE
;
4292 case NL80211_TDLS_TEARDOWN
:
4293 ret
= BRCMF_TDLS_MANUAL_EP_DELETE
;
4296 brcmf_err("unsupported operation: %d\n", oper
);
4302 static int brcmf_cfg80211_tdls_oper(struct wiphy
*wiphy
,
4303 struct net_device
*ndev
, const u8
*peer
,
4304 enum nl80211_tdls_operation oper
)
4306 struct brcmf_if
*ifp
;
4307 struct brcmf_tdls_iovar_le info
;
4310 ret
= brcmf_convert_nl80211_tdls_oper(oper
);
4314 ifp
= netdev_priv(ndev
);
4315 memset(&info
, 0, sizeof(info
));
4316 info
.mode
= (u8
)ret
;
4318 memcpy(info
.ea
, peer
, ETH_ALEN
);
4320 ret
= brcmf_fil_iovar_data_set(ifp
, "tdls_endpoint",
4321 &info
, sizeof(info
));
4323 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret
);
4328 static struct cfg80211_ops wl_cfg80211_ops
= {
4329 .add_virtual_intf
= brcmf_cfg80211_add_iface
,
4330 .del_virtual_intf
= brcmf_cfg80211_del_iface
,
4331 .change_virtual_intf
= brcmf_cfg80211_change_iface
,
4332 .scan
= brcmf_cfg80211_scan
,
4333 .set_wiphy_params
= brcmf_cfg80211_set_wiphy_params
,
4334 .join_ibss
= brcmf_cfg80211_join_ibss
,
4335 .leave_ibss
= brcmf_cfg80211_leave_ibss
,
4336 .get_station
= brcmf_cfg80211_get_station
,
4337 .set_tx_power
= brcmf_cfg80211_set_tx_power
,
4338 .get_tx_power
= brcmf_cfg80211_get_tx_power
,
4339 .add_key
= brcmf_cfg80211_add_key
,
4340 .del_key
= brcmf_cfg80211_del_key
,
4341 .get_key
= brcmf_cfg80211_get_key
,
4342 .set_default_key
= brcmf_cfg80211_config_default_key
,
4343 .set_default_mgmt_key
= brcmf_cfg80211_config_default_mgmt_key
,
4344 .set_power_mgmt
= brcmf_cfg80211_set_power_mgmt
,
4345 .connect
= brcmf_cfg80211_connect
,
4346 .disconnect
= brcmf_cfg80211_disconnect
,
4347 .suspend
= brcmf_cfg80211_suspend
,
4348 .resume
= brcmf_cfg80211_resume
,
4349 .set_pmksa
= brcmf_cfg80211_set_pmksa
,
4350 .del_pmksa
= brcmf_cfg80211_del_pmksa
,
4351 .flush_pmksa
= brcmf_cfg80211_flush_pmksa
,
4352 .start_ap
= brcmf_cfg80211_start_ap
,
4353 .stop_ap
= brcmf_cfg80211_stop_ap
,
4354 .change_beacon
= brcmf_cfg80211_change_beacon
,
4355 .del_station
= brcmf_cfg80211_del_station
,
4356 .sched_scan_start
= brcmf_cfg80211_sched_scan_start
,
4357 .sched_scan_stop
= brcmf_cfg80211_sched_scan_stop
,
4358 .mgmt_frame_register
= brcmf_cfg80211_mgmt_frame_register
,
4359 .mgmt_tx
= brcmf_cfg80211_mgmt_tx
,
4360 .remain_on_channel
= brcmf_p2p_remain_on_channel
,
4361 .cancel_remain_on_channel
= brcmf_cfg80211_cancel_remain_on_channel
,
4362 .start_p2p_device
= brcmf_p2p_start_device
,
4363 .stop_p2p_device
= brcmf_p2p_stop_device
,
4364 .crit_proto_start
= brcmf_cfg80211_crit_proto_start
,
4365 .crit_proto_stop
= brcmf_cfg80211_crit_proto_stop
,
4366 .tdls_oper
= brcmf_cfg80211_tdls_oper
,
4369 struct brcmf_cfg80211_vif
*brcmf_alloc_vif(struct brcmf_cfg80211_info
*cfg
,
4370 enum nl80211_iftype type
,
4373 struct brcmf_cfg80211_vif
*vif
;
4375 brcmf_dbg(TRACE
, "allocating virtual interface (size=%zu)\n",
4377 vif
= kzalloc(sizeof(*vif
), GFP_KERNEL
);
4379 return ERR_PTR(-ENOMEM
);
4381 vif
->wdev
.wiphy
= cfg
->wiphy
;
4382 vif
->wdev
.iftype
= type
;
4384 vif
->pm_block
= pm_block
;
4387 brcmf_init_prof(&vif
->profile
);
4389 list_add_tail(&vif
->list
, &cfg
->vif_list
);
4393 void brcmf_free_vif(struct brcmf_cfg80211_vif
*vif
)
4395 list_del(&vif
->list
);
4399 void brcmf_cfg80211_free_netdev(struct net_device
*ndev
)
4401 struct brcmf_cfg80211_vif
*vif
;
4402 struct brcmf_if
*ifp
;
4404 ifp
= netdev_priv(ndev
);
4407 brcmf_free_vif(vif
);
4411 static bool brcmf_is_linkup(const struct brcmf_event_msg
*e
)
4413 u32 event
= e
->event_code
;
4414 u32 status
= e
->status
;
4416 if (event
== BRCMF_E_SET_SSID
&& status
== BRCMF_E_STATUS_SUCCESS
) {
4417 brcmf_dbg(CONN
, "Processing set ssid\n");
4424 static bool brcmf_is_linkdown(const struct brcmf_event_msg
*e
)
4426 u32 event
= e
->event_code
;
4427 u16 flags
= e
->flags
;
4429 if ((event
== BRCMF_E_DEAUTH
) || (event
== BRCMF_E_DEAUTH_IND
) ||
4430 (event
== BRCMF_E_DISASSOC_IND
) ||
4431 ((event
== BRCMF_E_LINK
) && (!(flags
& BRCMF_EVENT_MSG_LINK
)))) {
4432 brcmf_dbg(CONN
, "Processing link down\n");
4438 static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info
*cfg
,
4439 const struct brcmf_event_msg
*e
)
4441 u32 event
= e
->event_code
;
4442 u32 status
= e
->status
;
4444 if (event
== BRCMF_E_LINK
&& status
== BRCMF_E_STATUS_NO_NETWORKS
) {
4445 brcmf_dbg(CONN
, "Processing Link %s & no network found\n",
4446 e
->flags
& BRCMF_EVENT_MSG_LINK
? "up" : "down");
4450 if (event
== BRCMF_E_SET_SSID
&& status
!= BRCMF_E_STATUS_SUCCESS
) {
4451 brcmf_dbg(CONN
, "Processing connecting & no network found\n");
4458 static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info
*cfg
)
4460 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4462 kfree(conn_info
->req_ie
);
4463 conn_info
->req_ie
= NULL
;
4464 conn_info
->req_ie_len
= 0;
4465 kfree(conn_info
->resp_ie
);
4466 conn_info
->resp_ie
= NULL
;
4467 conn_info
->resp_ie_len
= 0;
4470 static s32
brcmf_get_assoc_ies(struct brcmf_cfg80211_info
*cfg
,
4471 struct brcmf_if
*ifp
)
4473 struct brcmf_cfg80211_assoc_ielen_le
*assoc_info
;
4474 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4479 brcmf_clear_assoc_ies(cfg
);
4481 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_info",
4482 cfg
->extra_buf
, WL_ASSOC_INFO_MAX
);
4484 brcmf_err("could not get assoc info (%d)\n", err
);
4488 (struct brcmf_cfg80211_assoc_ielen_le
*)cfg
->extra_buf
;
4489 req_len
= le32_to_cpu(assoc_info
->req_len
);
4490 resp_len
= le32_to_cpu(assoc_info
->resp_len
);
4492 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_req_ies",
4496 brcmf_err("could not get assoc req (%d)\n", err
);
4499 conn_info
->req_ie_len
= req_len
;
4501 kmemdup(cfg
->extra_buf
, conn_info
->req_ie_len
,
4504 conn_info
->req_ie_len
= 0;
4505 conn_info
->req_ie
= NULL
;
4508 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_resp_ies",
4512 brcmf_err("could not get assoc resp (%d)\n", err
);
4515 conn_info
->resp_ie_len
= resp_len
;
4516 conn_info
->resp_ie
=
4517 kmemdup(cfg
->extra_buf
, conn_info
->resp_ie_len
,
4520 conn_info
->resp_ie_len
= 0;
4521 conn_info
->resp_ie
= NULL
;
4523 brcmf_dbg(CONN
, "req len (%d) resp len (%d)\n",
4524 conn_info
->req_ie_len
, conn_info
->resp_ie_len
);
4530 brcmf_bss_roaming_done(struct brcmf_cfg80211_info
*cfg
,
4531 struct net_device
*ndev
,
4532 const struct brcmf_event_msg
*e
)
4534 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4535 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4536 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4537 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
4538 struct ieee80211_channel
*notify_channel
= NULL
;
4539 struct ieee80211_supported_band
*band
;
4540 struct brcmf_bss_info_le
*bi
;
4541 struct brcmu_chan ch
;
4546 brcmf_dbg(TRACE
, "Enter\n");
4548 brcmf_get_assoc_ies(cfg
, ifp
);
4549 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4550 brcmf_update_bss_info(cfg
, ifp
);
4552 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
4558 /* data sent to dongle has to be little endian */
4559 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
4560 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
4561 buf
, WL_BSS_INFO_MAX
);
4566 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
4567 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
4568 cfg
->d11inf
.decchspec(&ch
);
4570 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
4571 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
4573 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
4575 freq
= ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
4576 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
4580 cfg80211_roamed(ndev
, notify_channel
, (u8
*)profile
->bssid
,
4581 conn_info
->req_ie
, conn_info
->req_ie_len
,
4582 conn_info
->resp_ie
, conn_info
->resp_ie_len
, GFP_KERNEL
);
4583 brcmf_dbg(CONN
, "Report roaming result\n");
4585 set_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
);
4586 brcmf_dbg(TRACE
, "Exit\n");
4591 brcmf_bss_connect_done(struct brcmf_cfg80211_info
*cfg
,
4592 struct net_device
*ndev
, const struct brcmf_event_msg
*e
,
4595 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4596 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4597 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4599 brcmf_dbg(TRACE
, "Enter\n");
4601 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4602 &ifp
->vif
->sme_state
)) {
4604 brcmf_get_assoc_ies(cfg
, ifp
);
4605 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4606 brcmf_update_bss_info(cfg
, ifp
);
4607 set_bit(BRCMF_VIF_STATUS_CONNECTED
,
4608 &ifp
->vif
->sme_state
);
4610 cfg80211_connect_result(ndev
,
4611 (u8
*)profile
->bssid
,
4613 conn_info
->req_ie_len
,
4615 conn_info
->resp_ie_len
,
4616 completed
? WLAN_STATUS_SUCCESS
:
4617 WLAN_STATUS_AUTH_TIMEOUT
,
4619 brcmf_dbg(CONN
, "Report connect result - connection %s\n",
4620 completed
? "succeeded" : "failed");
4622 brcmf_dbg(TRACE
, "Exit\n");
4627 brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info
*cfg
,
4628 struct net_device
*ndev
,
4629 const struct brcmf_event_msg
*e
, void *data
)
4631 static int generation
;
4632 u32 event
= e
->event_code
;
4633 u32 reason
= e
->reason
;
4634 struct station_info sinfo
;
4636 brcmf_dbg(CONN
, "event %d, reason %d\n", event
, reason
);
4637 if (event
== BRCMF_E_LINK
&& reason
== BRCMF_E_REASON_LINK_BSSCFG_DIS
&&
4638 ndev
!= cfg_to_ndev(cfg
)) {
4639 brcmf_dbg(CONN
, "AP mode link down\n");
4640 complete(&cfg
->vif_disabled
);
4644 if (((event
== BRCMF_E_ASSOC_IND
) || (event
== BRCMF_E_REASSOC_IND
)) &&
4645 (reason
== BRCMF_E_STATUS_SUCCESS
)) {
4646 memset(&sinfo
, 0, sizeof(sinfo
));
4647 sinfo
.filled
= STATION_INFO_ASSOC_REQ_IES
;
4649 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
4652 sinfo
.assoc_req_ies
= data
;
4653 sinfo
.assoc_req_ies_len
= e
->datalen
;
4655 sinfo
.generation
= generation
;
4656 cfg80211_new_sta(ndev
, e
->addr
, &sinfo
, GFP_KERNEL
);
4657 } else if ((event
== BRCMF_E_DISASSOC_IND
) ||
4658 (event
== BRCMF_E_DEAUTH_IND
) ||
4659 (event
== BRCMF_E_DEAUTH
)) {
4660 cfg80211_del_sta(ndev
, e
->addr
, GFP_KERNEL
);
4666 brcmf_notify_connect_status(struct brcmf_if
*ifp
,
4667 const struct brcmf_event_msg
*e
, void *data
)
4669 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4670 struct net_device
*ndev
= ifp
->ndev
;
4671 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4672 struct ieee80211_channel
*chan
;
4675 if ((e
->event_code
== BRCMF_E_DEAUTH
) ||
4676 (e
->event_code
== BRCMF_E_DEAUTH_IND
) ||
4677 (e
->event_code
== BRCMF_E_DISASSOC_IND
) ||
4678 ((e
->event_code
== BRCMF_E_LINK
) && (!e
->flags
))) {
4679 brcmf_proto_delete_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4682 if (brcmf_is_apmode(ifp
->vif
)) {
4683 err
= brcmf_notify_connect_status_ap(cfg
, ndev
, e
, data
);
4684 } else if (brcmf_is_linkup(e
)) {
4685 brcmf_dbg(CONN
, "Linkup\n");
4686 if (brcmf_is_ibssmode(ifp
->vif
)) {
4687 chan
= ieee80211_get_channel(cfg
->wiphy
, cfg
->channel
);
4688 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4689 wl_inform_ibss(cfg
, ndev
, e
->addr
);
4690 cfg80211_ibss_joined(ndev
, e
->addr
, chan
, GFP_KERNEL
);
4691 clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4692 &ifp
->vif
->sme_state
);
4693 set_bit(BRCMF_VIF_STATUS_CONNECTED
,
4694 &ifp
->vif
->sme_state
);
4696 brcmf_bss_connect_done(cfg
, ndev
, e
, true);
4697 } else if (brcmf_is_linkdown(e
)) {
4698 brcmf_dbg(CONN
, "Linkdown\n");
4699 if (!brcmf_is_ibssmode(ifp
->vif
)) {
4700 brcmf_bss_connect_done(cfg
, ndev
, e
, false);
4702 brcmf_link_down(ifp
->vif
);
4703 brcmf_init_prof(ndev_to_prof(ndev
));
4704 if (ndev
!= cfg_to_ndev(cfg
))
4705 complete(&cfg
->vif_disabled
);
4706 } else if (brcmf_is_nonetwork(cfg
, e
)) {
4707 if (brcmf_is_ibssmode(ifp
->vif
))
4708 clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4709 &ifp
->vif
->sme_state
);
4711 brcmf_bss_connect_done(cfg
, ndev
, e
, false);
4718 brcmf_notify_roaming_status(struct brcmf_if
*ifp
,
4719 const struct brcmf_event_msg
*e
, void *data
)
4721 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4722 u32 event
= e
->event_code
;
4723 u32 status
= e
->status
;
4725 if (event
== BRCMF_E_ROAM
&& status
== BRCMF_E_STATUS_SUCCESS
) {
4726 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
))
4727 brcmf_bss_roaming_done(cfg
, ifp
->ndev
, e
);
4729 brcmf_bss_connect_done(cfg
, ifp
->ndev
, e
, true);
4736 brcmf_notify_mic_status(struct brcmf_if
*ifp
,
4737 const struct brcmf_event_msg
*e
, void *data
)
4739 u16 flags
= e
->flags
;
4740 enum nl80211_key_type key_type
;
4742 if (flags
& BRCMF_EVENT_MSG_GROUP
)
4743 key_type
= NL80211_KEYTYPE_GROUP
;
4745 key_type
= NL80211_KEYTYPE_PAIRWISE
;
4747 cfg80211_michael_mic_failure(ifp
->ndev
, (u8
*)&e
->addr
, key_type
, -1,
4753 static s32
brcmf_notify_vif_event(struct brcmf_if
*ifp
,
4754 const struct brcmf_event_msg
*e
, void *data
)
4756 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4757 struct brcmf_if_event
*ifevent
= (struct brcmf_if_event
*)data
;
4758 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
4759 struct brcmf_cfg80211_vif
*vif
;
4761 brcmf_dbg(TRACE
, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4762 ifevent
->action
, ifevent
->flags
, ifevent
->ifidx
,
4765 mutex_lock(&event
->vif_event_lock
);
4766 event
->action
= ifevent
->action
;
4769 switch (ifevent
->action
) {
4770 case BRCMF_E_IF_ADD
:
4771 /* waiting process may have timed out */
4772 if (!cfg
->vif_event
.vif
) {
4773 mutex_unlock(&event
->vif_event_lock
);
4780 vif
->wdev
.netdev
= ifp
->ndev
;
4781 ifp
->ndev
->ieee80211_ptr
= &vif
->wdev
;
4782 SET_NETDEV_DEV(ifp
->ndev
, wiphy_dev(cfg
->wiphy
));
4784 mutex_unlock(&event
->vif_event_lock
);
4785 wake_up(&event
->vif_wq
);
4788 case BRCMF_E_IF_DEL
:
4789 mutex_unlock(&event
->vif_event_lock
);
4790 /* event may not be upon user request */
4791 if (brcmf_cfg80211_vif_event_armed(cfg
))
4792 wake_up(&event
->vif_wq
);
4795 case BRCMF_E_IF_CHANGE
:
4796 mutex_unlock(&event
->vif_event_lock
);
4797 wake_up(&event
->vif_wq
);
4801 mutex_unlock(&event
->vif_event_lock
);
4807 static void brcmf_init_conf(struct brcmf_cfg80211_conf
*conf
)
4809 conf
->frag_threshold
= (u32
)-1;
4810 conf
->rts_threshold
= (u32
)-1;
4811 conf
->retry_short
= (u32
)-1;
4812 conf
->retry_long
= (u32
)-1;
4813 conf
->tx_power
= -1;
4816 static void brcmf_register_event_handlers(struct brcmf_cfg80211_info
*cfg
)
4818 brcmf_fweh_register(cfg
->pub
, BRCMF_E_LINK
,
4819 brcmf_notify_connect_status
);
4820 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DEAUTH_IND
,
4821 brcmf_notify_connect_status
);
4822 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DEAUTH
,
4823 brcmf_notify_connect_status
);
4824 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DISASSOC_IND
,
4825 brcmf_notify_connect_status
);
4826 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ASSOC_IND
,
4827 brcmf_notify_connect_status
);
4828 brcmf_fweh_register(cfg
->pub
, BRCMF_E_REASSOC_IND
,
4829 brcmf_notify_connect_status
);
4830 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ROAM
,
4831 brcmf_notify_roaming_status
);
4832 brcmf_fweh_register(cfg
->pub
, BRCMF_E_MIC_ERROR
,
4833 brcmf_notify_mic_status
);
4834 brcmf_fweh_register(cfg
->pub
, BRCMF_E_SET_SSID
,
4835 brcmf_notify_connect_status
);
4836 brcmf_fweh_register(cfg
->pub
, BRCMF_E_PFN_NET_FOUND
,
4837 brcmf_notify_sched_scan_results
);
4838 brcmf_fweh_register(cfg
->pub
, BRCMF_E_IF
,
4839 brcmf_notify_vif_event
);
4840 brcmf_fweh_register(cfg
->pub
, BRCMF_E_P2P_PROBEREQ_MSG
,
4841 brcmf_p2p_notify_rx_mgmt_p2p_probereq
);
4842 brcmf_fweh_register(cfg
->pub
, BRCMF_E_P2P_DISC_LISTEN_COMPLETE
,
4843 brcmf_p2p_notify_listen_complete
);
4844 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_RX
,
4845 brcmf_p2p_notify_action_frame_rx
);
4846 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_COMPLETE
,
4847 brcmf_p2p_notify_action_tx_complete
);
4848 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE
,
4849 brcmf_p2p_notify_action_tx_complete
);
4852 static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info
*cfg
)
4856 kfree(cfg
->escan_ioctl_buf
);
4857 cfg
->escan_ioctl_buf
= NULL
;
4858 kfree(cfg
->extra_buf
);
4859 cfg
->extra_buf
= NULL
;
4860 kfree(cfg
->pmk_list
);
4861 cfg
->pmk_list
= NULL
;
4864 static s32
brcmf_init_priv_mem(struct brcmf_cfg80211_info
*cfg
)
4866 cfg
->conf
= kzalloc(sizeof(*cfg
->conf
), GFP_KERNEL
);
4868 goto init_priv_mem_out
;
4869 cfg
->escan_ioctl_buf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
4870 if (!cfg
->escan_ioctl_buf
)
4871 goto init_priv_mem_out
;
4872 cfg
->extra_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
4873 if (!cfg
->extra_buf
)
4874 goto init_priv_mem_out
;
4875 cfg
->pmk_list
= kzalloc(sizeof(*cfg
->pmk_list
), GFP_KERNEL
);
4877 goto init_priv_mem_out
;
4882 brcmf_deinit_priv_mem(cfg
);
4887 static s32
wl_init_priv(struct brcmf_cfg80211_info
*cfg
)
4891 cfg
->scan_request
= NULL
;
4892 cfg
->pwr_save
= true;
4893 cfg
->active_scan
= true; /* we do active scan per default */
4894 cfg
->dongle_up
= false; /* dongle is not up yet */
4895 err
= brcmf_init_priv_mem(cfg
);
4898 brcmf_register_event_handlers(cfg
);
4899 mutex_init(&cfg
->usr_sync
);
4900 brcmf_init_escan(cfg
);
4901 brcmf_init_conf(cfg
->conf
);
4902 init_completion(&cfg
->vif_disabled
);
4906 static void wl_deinit_priv(struct brcmf_cfg80211_info
*cfg
)
4908 cfg
->dongle_up
= false; /* dongle down */
4909 brcmf_abort_scanning(cfg
);
4910 brcmf_deinit_priv_mem(cfg
);
4913 static void init_vif_event(struct brcmf_cfg80211_vif_event
*event
)
4915 init_waitqueue_head(&event
->vif_wq
);
4916 mutex_init(&event
->vif_event_lock
);
4920 brcmf_dongle_roam(struct brcmf_if
*ifp
, u32 bcn_timeout
)
4923 __le32 roamtrigger
[2];
4924 __le32 roam_delta
[2];
4927 * Setup timeout if Beacons are lost and roam is
4928 * off to report link down
4930 if (brcmf_roamoff
) {
4931 err
= brcmf_fil_iovar_int_set(ifp
, "bcn_timeout", bcn_timeout
);
4933 brcmf_err("bcn_timeout error (%d)\n", err
);
4934 goto dongle_rom_out
;
4939 * Enable/Disable built-in roaming to allow supplicant
4940 * to take care of roaming
4942 brcmf_dbg(INFO
, "Internal Roaming = %s\n",
4943 brcmf_roamoff
? "Off" : "On");
4944 err
= brcmf_fil_iovar_int_set(ifp
, "roam_off", !!(brcmf_roamoff
));
4946 brcmf_err("roam_off error (%d)\n", err
);
4947 goto dongle_rom_out
;
4950 roamtrigger
[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL
);
4951 roamtrigger
[1] = cpu_to_le32(BRCM_BAND_ALL
);
4952 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_ROAM_TRIGGER
,
4953 (void *)roamtrigger
, sizeof(roamtrigger
));
4955 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err
);
4956 goto dongle_rom_out
;
4959 roam_delta
[0] = cpu_to_le32(WL_ROAM_DELTA
);
4960 roam_delta
[1] = cpu_to_le32(BRCM_BAND_ALL
);
4961 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_ROAM_DELTA
,
4962 (void *)roam_delta
, sizeof(roam_delta
));
4964 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err
);
4965 goto dongle_rom_out
;
4973 brcmf_dongle_scantime(struct brcmf_if
*ifp
, s32 scan_assoc_time
,
4974 s32 scan_unassoc_time
, s32 scan_passive_time
)
4978 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_CHANNEL_TIME
,
4981 if (err
== -EOPNOTSUPP
)
4982 brcmf_dbg(INFO
, "Scan assoc time is not supported\n");
4984 brcmf_err("Scan assoc time error (%d)\n", err
);
4985 goto dongle_scantime_out
;
4987 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_UNASSOC_TIME
,
4990 if (err
== -EOPNOTSUPP
)
4991 brcmf_dbg(INFO
, "Scan unassoc time is not supported\n");
4993 brcmf_err("Scan unassoc time error (%d)\n", err
);
4994 goto dongle_scantime_out
;
4997 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_PASSIVE_TIME
,
5000 if (err
== -EOPNOTSUPP
)
5001 brcmf_dbg(INFO
, "Scan passive time is not supported\n");
5003 brcmf_err("Scan passive time error (%d)\n", err
);
5004 goto dongle_scantime_out
;
5007 dongle_scantime_out
:
5011 /* Filter the list of channels received from firmware counting only
5012 * the 20MHz channels. The wiphy band data only needs those which get
5013 * flagged to indicate if they can take part in higher bandwidth.
5015 static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info
*cfg
,
5016 struct brcmf_chanspec_list
*chlist
,
5019 u32 total
= le32_to_cpu(chlist
->count
);
5020 struct brcmu_chan ch
;
5023 for (i
= 0; i
< total
; i
++) {
5024 ch
.chspec
= (u16
)le32_to_cpu(chlist
->element
[i
]);
5025 cfg
->d11inf
.decchspec(&ch
);
5027 /* Firmware gives a ordered list. We skip non-20MHz
5028 * channels is 2G. For 5G we can abort upon reaching
5029 * a non-20MHz channel in the list.
5031 if (ch
.bw
!= BRCMU_CHAN_BW_20
) {
5032 if (ch
.band
== BRCMU_CHAN_BAND_5G
)
5038 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
5040 else if (ch
.band
== BRCMU_CHAN_BAND_5G
)
5045 static void brcmf_update_bw40_channel_flag(struct ieee80211_channel
*channel
,
5046 struct brcmu_chan
*ch
)
5050 ht40_flag
= channel
->flags
& IEEE80211_CHAN_NO_HT40
;
5051 if (ch
->sb
== BRCMU_CHAN_SB_U
) {
5052 if (ht40_flag
== IEEE80211_CHAN_NO_HT40
)
5053 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40
;
5054 channel
->flags
|= IEEE80211_CHAN_NO_HT40PLUS
;
5056 /* It should be one of
5057 * IEEE80211_CHAN_NO_HT40 or
5058 * IEEE80211_CHAN_NO_HT40PLUS
5060 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40
;
5061 if (ht40_flag
== IEEE80211_CHAN_NO_HT40
)
5062 channel
->flags
|= IEEE80211_CHAN_NO_HT40MINUS
;
5066 static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info
*cfg
,
5069 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5070 struct ieee80211_supported_band
*band
;
5071 struct ieee80211_channel
*channel
;
5072 struct wiphy
*wiphy
;
5073 struct brcmf_chanspec_list
*list
;
5074 struct brcmu_chan ch
;
5080 u32 chcnt
[2] = { 0, 0 };
5083 pbuf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5088 list
= (struct brcmf_chanspec_list
*)pbuf
;
5090 err
= brcmf_fil_iovar_data_get(ifp
, "chanspecs", pbuf
,
5093 brcmf_err("get chanspecs error (%d)\n", err
);
5097 brcmf_count_20mhz_channels(cfg
, list
, chcnt
);
5098 wiphy
= cfg_to_wiphy(cfg
);
5100 band
= kmemdup(&__wl_band_2ghz
, sizeof(__wl_band_2ghz
),
5106 band
->channels
= kcalloc(chcnt
[0], sizeof(*channel
),
5108 if (band
->channels
== NULL
) {
5113 band
->n_channels
= 0;
5114 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
5117 band
= kmemdup(&__wl_band_5ghz_a
, sizeof(__wl_band_5ghz_a
),
5123 band
->channels
= kcalloc(chcnt
[1], sizeof(*channel
),
5125 if (band
->channels
== NULL
) {
5130 band
->n_channels
= 0;
5131 wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
5134 total
= le32_to_cpu(list
->count
);
5135 for (i
= 0; i
< total
; i
++) {
5136 ch
.chspec
= (u16
)le32_to_cpu(list
->element
[i
]);
5137 cfg
->d11inf
.decchspec(&ch
);
5139 if (ch
.band
== BRCMU_CHAN_BAND_2G
) {
5140 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5141 } else if (ch
.band
== BRCMU_CHAN_BAND_5G
) {
5142 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5144 brcmf_err("Invalid channel Spec. 0x%x.\n", ch
.chspec
);
5147 if (!(bw_cap
[band
->band
] & WLC_BW_40MHZ_BIT
) &&
5148 ch
.bw
== BRCMU_CHAN_BW_40
)
5150 if (!(bw_cap
[band
->band
] & WLC_BW_80MHZ_BIT
) &&
5151 ch
.bw
== BRCMU_CHAN_BW_80
)
5154 channel
= band
->channels
;
5155 index
= band
->n_channels
;
5156 for (j
= 0; j
< band
->n_channels
; j
++) {
5157 if (channel
[j
].hw_value
== ch
.chnum
) {
5162 channel
[index
].center_freq
=
5163 ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
5164 channel
[index
].hw_value
= ch
.chnum
;
5166 /* assuming the chanspecs order is HT20,
5167 * HT40 upper, HT40 lower, and VHT80.
5169 if (ch
.bw
== BRCMU_CHAN_BW_80
) {
5170 channel
[index
].flags
&= ~IEEE80211_CHAN_NO_80MHZ
;
5171 } else if (ch
.bw
== BRCMU_CHAN_BW_40
) {
5172 brcmf_update_bw40_channel_flag(&channel
[index
], &ch
);
5174 /* disable other bandwidths for now as mentioned
5175 * order assure they are enabled for subsequent
5178 channel
[index
].flags
= IEEE80211_CHAN_NO_HT40
|
5179 IEEE80211_CHAN_NO_80MHZ
;
5180 ch
.bw
= BRCMU_CHAN_BW_20
;
5181 cfg
->d11inf
.encchspec(&ch
);
5182 chaninfo
= ch
.chspec
;
5183 err
= brcmf_fil_bsscfg_int_get(ifp
, "per_chan_info",
5186 if (chaninfo
& WL_CHAN_RADAR
)
5187 channel
[index
].flags
|=
5188 (IEEE80211_CHAN_RADAR
|
5189 IEEE80211_CHAN_NO_IR
);
5190 if (chaninfo
& WL_CHAN_PASSIVE
)
5191 channel
[index
].flags
|=
5192 IEEE80211_CHAN_NO_IR
;
5195 if (index
== band
->n_channels
)
5202 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]->channels
);
5203 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]);
5204 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
5210 static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info
*cfg
)
5212 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5213 struct ieee80211_supported_band
*band
;
5214 struct brcmf_fil_bwcap_le band_bwcap
;
5215 struct brcmf_chanspec_list
*list
;
5219 struct brcmu_chan ch
;
5223 /* verify support for bw_cap command */
5225 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &val
);
5228 /* only set 2G bandwidth using bw_cap command */
5229 band_bwcap
.band
= cpu_to_le32(WLC_BAND_2G
);
5230 band_bwcap
.bw_cap
= cpu_to_le32(WLC_BW_CAP_40MHZ
);
5231 err
= brcmf_fil_iovar_data_set(ifp
, "bw_cap", &band_bwcap
,
5232 sizeof(band_bwcap
));
5234 brcmf_dbg(INFO
, "fallback to mimo_bw_cap\n");
5235 val
= WLC_N_BW_40ALL
;
5236 err
= brcmf_fil_iovar_int_set(ifp
, "mimo_bw_cap", val
);
5240 /* update channel info in 2G band */
5241 pbuf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5246 ch
.band
= BRCMU_CHAN_BAND_2G
;
5247 ch
.bw
= BRCMU_CHAN_BW_40
;
5248 ch
.sb
= BRCMU_CHAN_SB_NONE
;
5250 cfg
->d11inf
.encchspec(&ch
);
5252 /* pass encoded chanspec in query */
5253 *(__le16
*)pbuf
= cpu_to_le16(ch
.chspec
);
5255 err
= brcmf_fil_iovar_data_get(ifp
, "chanspecs", pbuf
,
5258 brcmf_err("get chanspecs error (%d)\n", err
);
5263 band
= cfg_to_wiphy(cfg
)->bands
[IEEE80211_BAND_2GHZ
];
5264 list
= (struct brcmf_chanspec_list
*)pbuf
;
5265 num_chan
= le32_to_cpu(list
->count
);
5266 for (i
= 0; i
< num_chan
; i
++) {
5267 ch
.chspec
= (u16
)le32_to_cpu(list
->element
[i
]);
5268 cfg
->d11inf
.decchspec(&ch
);
5269 if (WARN_ON(ch
.band
!= BRCMU_CHAN_BAND_2G
))
5271 if (WARN_ON(ch
.bw
!= BRCMU_CHAN_BW_40
))
5273 for (j
= 0; j
< band
->n_channels
; j
++) {
5274 if (band
->channels
[j
].hw_value
== ch
.chnum
)
5277 if (WARN_ON(j
== band
->n_channels
))
5280 brcmf_update_bw40_channel_flag(&band
->channels
[j
], &ch
);
5287 static void brcmf_get_bwcap(struct brcmf_if
*ifp
, u32 bw_cap
[])
5289 u32 band
, mimo_bwcap
;
5293 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &band
);
5295 bw_cap
[IEEE80211_BAND_2GHZ
] = band
;
5297 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &band
);
5299 bw_cap
[IEEE80211_BAND_5GHZ
] = band
;
5305 brcmf_dbg(INFO
, "fallback to mimo_bw_cap info\n");
5307 err
= brcmf_fil_iovar_int_get(ifp
, "mimo_bw_cap", &mimo_bwcap
);
5309 /* assume 20MHz if firmware does not give a clue */
5310 mimo_bwcap
= WLC_N_BW_20ALL
;
5312 switch (mimo_bwcap
) {
5313 case WLC_N_BW_40ALL
:
5314 bw_cap
[IEEE80211_BAND_2GHZ
] |= WLC_BW_40MHZ_BIT
;
5316 case WLC_N_BW_20IN2G_40IN5G
:
5317 bw_cap
[IEEE80211_BAND_5GHZ
] |= WLC_BW_40MHZ_BIT
;
5319 case WLC_N_BW_20ALL
:
5320 bw_cap
[IEEE80211_BAND_2GHZ
] |= WLC_BW_20MHZ_BIT
;
5321 bw_cap
[IEEE80211_BAND_5GHZ
] |= WLC_BW_20MHZ_BIT
;
5324 brcmf_err("invalid mimo_bw_cap value\n");
5328 static void brcmf_update_ht_cap(struct ieee80211_supported_band
*band
,
5329 u32 bw_cap
[2], u32 nchain
)
5331 band
->ht_cap
.ht_supported
= true;
5332 if (bw_cap
[band
->band
] & WLC_BW_40MHZ_BIT
) {
5333 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
5334 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5336 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
5337 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
5338 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
5339 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
5340 memset(band
->ht_cap
.mcs
.rx_mask
, 0xff, nchain
);
5341 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
5344 static __le16
brcmf_get_mcs_map(u32 nchain
, enum ieee80211_vht_mcs_support supp
)
5349 for (i
= 0, mcs_map
= 0xFFFF; i
< nchain
; i
++)
5350 mcs_map
= (mcs_map
<< 2) | supp
;
5352 return cpu_to_le16(mcs_map
);
5355 static void brcmf_update_vht_cap(struct ieee80211_supported_band
*band
,
5356 u32 bw_cap
[2], u32 nchain
)
5360 /* not allowed in 2.4G band */
5361 if (band
->band
== IEEE80211_BAND_2GHZ
)
5364 band
->vht_cap
.vht_supported
= true;
5365 /* 80MHz is mandatory */
5366 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SHORT_GI_80
;
5367 if (bw_cap
[band
->band
] & WLC_BW_160MHZ_BIT
) {
5368 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
5369 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SHORT_GI_160
;
5371 /* all support 256-QAM */
5372 mcs_map
= brcmf_get_mcs_map(nchain
, IEEE80211_VHT_MCS_SUPPORT_0_9
);
5373 band
->vht_cap
.vht_mcs
.rx_mcs_map
= mcs_map
;
5374 band
->vht_cap
.vht_mcs
.tx_mcs_map
= mcs_map
;
5377 static int brcmf_setup_wiphybands(struct wiphy
*wiphy
)
5379 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
5380 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5383 u32 bw_cap
[2] = { WLC_BW_20MHZ_BIT
, WLC_BW_20MHZ_BIT
};
5388 struct ieee80211_supported_band
*band
;
5390 (void)brcmf_fil_iovar_int_get(ifp
, "vhtmode", &vhtmode
);
5391 err
= brcmf_fil_iovar_int_get(ifp
, "nmode", &nmode
);
5393 brcmf_err("nmode error (%d)\n", err
);
5395 brcmf_get_bwcap(ifp
, bw_cap
);
5397 brcmf_dbg(INFO
, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5398 nmode
, vhtmode
, bw_cap
[IEEE80211_BAND_2GHZ
],
5399 bw_cap
[IEEE80211_BAND_5GHZ
]);
5401 err
= brcmf_fil_iovar_int_get(ifp
, "rxchain", &rxchain
);
5403 brcmf_err("rxchain error (%d)\n", err
);
5406 for (nchain
= 0; rxchain
; nchain
++)
5407 rxchain
= rxchain
& (rxchain
- 1);
5409 brcmf_dbg(INFO
, "nchain=%d\n", nchain
);
5411 err
= brcmf_construct_chaninfo(cfg
, bw_cap
);
5413 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err
);
5417 wiphy
= cfg_to_wiphy(cfg
);
5418 for (i
= 0; i
< ARRAY_SIZE(wiphy
->bands
); i
++) {
5419 band
= wiphy
->bands
[i
];
5424 brcmf_update_ht_cap(band
, bw_cap
, nchain
);
5426 brcmf_update_vht_cap(band
, bw_cap
, nchain
);
5432 static const struct ieee80211_iface_limit brcmf_iface_limits
[] = {
5435 .types
= BIT(NL80211_IFTYPE_STATION
) |
5436 BIT(NL80211_IFTYPE_ADHOC
) |
5437 BIT(NL80211_IFTYPE_AP
)
5441 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5442 BIT(NL80211_IFTYPE_P2P_GO
)
5446 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5449 static struct ieee80211_iface_combination brcmf_iface_combos
[] = {
5451 .max_interfaces
= BRCMF_IFACE_MAX_CNT
,
5452 .num_different_channels
= 1,
5453 .n_limits
= ARRAY_SIZE(brcmf_iface_limits
),
5454 .limits
= brcmf_iface_limits
5458 static const struct ieee80211_txrx_stypes
5459 brcmf_txrx_stypes
[NUM_NL80211_IFTYPES
] = {
5460 [NL80211_IFTYPE_STATION
] = {
5462 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5463 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5465 [NL80211_IFTYPE_P2P_CLIENT
] = {
5467 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5468 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5470 [NL80211_IFTYPE_P2P_GO
] = {
5472 .rx
= BIT(IEEE80211_STYPE_ASSOC_REQ
>> 4) |
5473 BIT(IEEE80211_STYPE_REASSOC_REQ
>> 4) |
5474 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4) |
5475 BIT(IEEE80211_STYPE_DISASSOC
>> 4) |
5476 BIT(IEEE80211_STYPE_AUTH
>> 4) |
5477 BIT(IEEE80211_STYPE_DEAUTH
>> 4) |
5478 BIT(IEEE80211_STYPE_ACTION
>> 4)
5480 [NL80211_IFTYPE_P2P_DEVICE
] = {
5482 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5483 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5487 static void brcmf_wiphy_pno_params(struct wiphy
*wiphy
)
5489 /* scheduled scan settings */
5490 wiphy
->max_sched_scan_ssids
= BRCMF_PNO_MAX_PFN_COUNT
;
5491 wiphy
->max_match_sets
= BRCMF_PNO_MAX_PFN_COUNT
;
5492 wiphy
->max_sched_scan_ie_len
= BRCMF_SCAN_IE_LEN_MAX
;
5493 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
5497 static const struct wiphy_wowlan_support brcmf_wowlan_support
= {
5498 .flags
= WIPHY_WOWLAN_MAGIC_PKT
| WIPHY_WOWLAN_DISCONNECT
,
5499 .n_patterns
= BRCMF_WOWL_MAXPATTERNS
,
5500 .pattern_max_len
= BRCMF_WOWL_MAXPATTERNSIZE
,
5501 .pattern_min_len
= 1,
5502 .max_pkt_offset
= 1500,
5506 static void brcmf_wiphy_wowl_params(struct wiphy
*wiphy
)
5510 wiphy
->wowlan
= &brcmf_wowlan_support
;
5514 static int brcmf_setup_wiphy(struct wiphy
*wiphy
, struct brcmf_if
*ifp
)
5516 struct ieee80211_iface_combination ifc_combo
;
5517 wiphy
->max_scan_ssids
= WL_NUM_SCAN_MAX
;
5518 wiphy
->max_scan_ie_len
= BRCMF_SCAN_IE_LEN_MAX
;
5519 wiphy
->max_num_pmkids
= WL_NUM_PMKIDS_MAX
;
5520 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5521 BIT(NL80211_IFTYPE_ADHOC
) |
5522 BIT(NL80211_IFTYPE_AP
) |
5523 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5524 BIT(NL80211_IFTYPE_P2P_GO
) |
5525 BIT(NL80211_IFTYPE_P2P_DEVICE
);
5526 /* need VSDB firmware feature for concurrent channels */
5527 ifc_combo
= brcmf_iface_combos
[0];
5528 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_MCHAN
))
5529 ifc_combo
.num_different_channels
= 2;
5530 wiphy
->iface_combinations
= kmemdup(&ifc_combo
,
5533 wiphy
->n_iface_combinations
= ARRAY_SIZE(brcmf_iface_combos
);
5534 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
5535 wiphy
->cipher_suites
= __wl_cipher_suites
;
5536 wiphy
->n_cipher_suites
= ARRAY_SIZE(__wl_cipher_suites
);
5537 wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
|
5538 WIPHY_FLAG_OFFCHAN_TX
|
5539 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
|
5540 WIPHY_FLAG_SUPPORTS_TDLS
;
5542 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_FW_ROAM
;
5543 wiphy
->mgmt_stypes
= brcmf_txrx_stypes
;
5544 wiphy
->max_remain_on_channel_duration
= 5000;
5545 brcmf_wiphy_pno_params(wiphy
);
5547 /* vendor commands/events support */
5548 wiphy
->vendor_commands
= brcmf_vendor_cmds
;
5549 wiphy
->n_vendor_commands
= BRCMF_VNDR_CMDS_LAST
- 1;
5551 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_WOWL
))
5552 brcmf_wiphy_wowl_params(wiphy
);
5554 return brcmf_setup_wiphybands(wiphy
);
5557 static s32
brcmf_config_dongle(struct brcmf_cfg80211_info
*cfg
)
5559 struct net_device
*ndev
;
5560 struct wireless_dev
*wdev
;
5561 struct brcmf_if
*ifp
;
5568 ndev
= cfg_to_ndev(cfg
);
5569 wdev
= ndev
->ieee80211_ptr
;
5570 ifp
= netdev_priv(ndev
);
5572 /* make sure RF is ready for work */
5573 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
5575 brcmf_dongle_scantime(ifp
, WL_SCAN_CHANNEL_TIME
,
5576 WL_SCAN_UNASSOC_TIME
, WL_SCAN_PASSIVE_TIME
);
5578 power_mode
= cfg
->pwr_save
? PM_FAST
: PM_OFF
;
5579 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, power_mode
);
5581 goto default_conf_out
;
5582 brcmf_dbg(INFO
, "power save set to %s\n",
5583 (power_mode
? "enabled" : "disabled"));
5585 err
= brcmf_dongle_roam(ifp
, WL_BEACON_TIMEOUT
);
5587 goto default_conf_out
;
5588 err
= brcmf_cfg80211_change_iface(wdev
->wiphy
, ndev
, wdev
->iftype
,
5591 goto default_conf_out
;
5593 brcmf_configure_arp_offload(ifp
, true);
5595 cfg
->dongle_up
= true;
5602 static s32
__brcmf_cfg80211_up(struct brcmf_if
*ifp
)
5604 set_bit(BRCMF_VIF_STATUS_READY
, &ifp
->vif
->sme_state
);
5606 return brcmf_config_dongle(ifp
->drvr
->config
);
5609 static s32
__brcmf_cfg80211_down(struct brcmf_if
*ifp
)
5611 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5614 * While going down, if associated with AP disassociate
5615 * from AP to save power
5617 if (check_vif_up(ifp
->vif
)) {
5618 brcmf_link_down(ifp
->vif
);
5620 /* Make sure WPA_Supplicant receives all the event
5621 generated due to DISASSOC call to the fw to keep
5622 the state fw and WPA_Supplicant state consistent
5627 brcmf_abort_scanning(cfg
);
5628 clear_bit(BRCMF_VIF_STATUS_READY
, &ifp
->vif
->sme_state
);
5633 s32
brcmf_cfg80211_up(struct net_device
*ndev
)
5635 struct brcmf_if
*ifp
= netdev_priv(ndev
);
5636 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5639 mutex_lock(&cfg
->usr_sync
);
5640 err
= __brcmf_cfg80211_up(ifp
);
5641 mutex_unlock(&cfg
->usr_sync
);
5646 s32
brcmf_cfg80211_down(struct net_device
*ndev
)
5648 struct brcmf_if
*ifp
= netdev_priv(ndev
);
5649 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5652 mutex_lock(&cfg
->usr_sync
);
5653 err
= __brcmf_cfg80211_down(ifp
);
5654 mutex_unlock(&cfg
->usr_sync
);
5659 enum nl80211_iftype
brcmf_cfg80211_get_iftype(struct brcmf_if
*ifp
)
5661 struct wireless_dev
*wdev
= &ifp
->vif
->wdev
;
5663 return wdev
->iftype
;
5666 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info
*cfg
,
5667 unsigned long state
)
5669 struct brcmf_cfg80211_vif
*vif
;
5671 list_for_each_entry(vif
, &cfg
->vif_list
, list
) {
5672 if (test_bit(state
, &vif
->sme_state
))
5678 static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event
*event
,
5683 mutex_lock(&event
->vif_event_lock
);
5684 evt_action
= event
->action
;
5685 mutex_unlock(&event
->vif_event_lock
);
5686 return evt_action
== action
;
5689 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info
*cfg
,
5690 struct brcmf_cfg80211_vif
*vif
)
5692 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5694 mutex_lock(&event
->vif_event_lock
);
5697 mutex_unlock(&event
->vif_event_lock
);
5700 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info
*cfg
)
5702 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5705 mutex_lock(&event
->vif_event_lock
);
5706 armed
= event
->vif
!= NULL
;
5707 mutex_unlock(&event
->vif_event_lock
);
5711 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info
*cfg
,
5712 u8 action
, ulong timeout
)
5714 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5716 return wait_event_timeout(event
->vif_wq
,
5717 vif_event_equals(event
, action
), timeout
);
5720 static void brcmf_free_wiphy(struct wiphy
*wiphy
)
5722 kfree(wiphy
->iface_combinations
);
5723 if (wiphy
->bands
[IEEE80211_BAND_2GHZ
]) {
5724 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]->channels
);
5725 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]);
5727 if (wiphy
->bands
[IEEE80211_BAND_5GHZ
]) {
5728 kfree(wiphy
->bands
[IEEE80211_BAND_5GHZ
]->channels
);
5729 kfree(wiphy
->bands
[IEEE80211_BAND_5GHZ
]);
5734 struct brcmf_cfg80211_info
*brcmf_cfg80211_attach(struct brcmf_pub
*drvr
,
5735 struct device
*busdev
)
5737 struct net_device
*ndev
= drvr
->iflist
[0]->ndev
;
5738 struct brcmf_cfg80211_info
*cfg
;
5739 struct wiphy
*wiphy
;
5740 struct brcmf_cfg80211_vif
*vif
;
5741 struct brcmf_if
*ifp
;
5747 brcmf_err("ndev is invalid\n");
5751 ifp
= netdev_priv(ndev
);
5752 wiphy
= wiphy_new(&wl_cfg80211_ops
, sizeof(struct brcmf_cfg80211_info
));
5754 brcmf_err("Could not allocate wiphy device\n");
5757 set_wiphy_dev(wiphy
, busdev
);
5759 cfg
= wiphy_priv(wiphy
);
5762 init_vif_event(&cfg
->vif_event
);
5763 INIT_LIST_HEAD(&cfg
->vif_list
);
5765 vif
= brcmf_alloc_vif(cfg
, NL80211_IFTYPE_STATION
, false);
5770 vif
->wdev
.netdev
= ndev
;
5771 ndev
->ieee80211_ptr
= &vif
->wdev
;
5772 SET_NETDEV_DEV(ndev
, wiphy_dev(cfg
->wiphy
));
5774 err
= wl_init_priv(cfg
);
5776 brcmf_err("Failed to init iwm_priv (%d)\n", err
);
5777 brcmf_free_vif(vif
);
5782 /* determine d11 io type before wiphy setup */
5783 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_VERSION
, &io_type
);
5785 brcmf_err("Failed to get D11 version (%d)\n", err
);
5788 cfg
->d11inf
.io_type
= (u8
)io_type
;
5789 brcmu_d11_attach(&cfg
->d11inf
);
5791 err
= brcmf_setup_wiphy(wiphy
, ifp
);
5795 brcmf_dbg(INFO
, "Registering custom regulatory\n");
5796 wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
;
5797 wiphy_apply_custom_regulatory(wiphy
, &brcmf_regdom
);
5799 /* firmware defaults to 40MHz disabled in 2G band. We signal
5800 * cfg80211 here that we do and have it decide we can enable
5801 * it. But first check if device does support 2G operation.
5803 if (wiphy
->bands
[IEEE80211_BAND_2GHZ
]) {
5804 cap
= &wiphy
->bands
[IEEE80211_BAND_2GHZ
]->ht_cap
.cap
;
5805 *cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5807 err
= wiphy_register(wiphy
);
5809 brcmf_err("Could not register wiphy device (%d)\n", err
);
5813 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
5814 * setup 40MHz in 2GHz band and enable OBSS scanning.
5816 if (cap
&& (*cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)) {
5817 err
= brcmf_enable_bw40_2g(cfg
);
5819 err
= brcmf_fil_iovar_int_set(ifp
, "obss_coex",
5820 BRCMF_OBSS_COEX_AUTO
);
5822 *cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5825 err
= brcmf_p2p_attach(cfg
);
5827 brcmf_err("P2P initilisation failed (%d)\n", err
);
5828 goto wiphy_unreg_out
;
5830 err
= brcmf_btcoex_attach(cfg
);
5832 brcmf_err("BT-coex initialisation failed (%d)\n", err
);
5833 brcmf_p2p_detach(&cfg
->p2p
);
5834 goto wiphy_unreg_out
;
5837 err
= brcmf_fil_iovar_int_set(ifp
, "tdls_enable", 1);
5839 brcmf_dbg(INFO
, "TDLS not enabled (%d)\n", err
);
5840 wiphy
->flags
&= ~WIPHY_FLAG_SUPPORTS_TDLS
;
5842 brcmf_fweh_register(cfg
->pub
, BRCMF_E_TDLS_PEER_EVENT
,
5843 brcmf_notify_tdls_peer_event
);
5849 wiphy_unregister(cfg
->wiphy
);
5851 wl_deinit_priv(cfg
);
5852 brcmf_free_vif(vif
);
5854 brcmf_free_wiphy(wiphy
);
5858 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info
*cfg
)
5863 WARN_ON(!list_empty(&cfg
->vif_list
));
5864 wiphy_unregister(cfg
->wiphy
);
5865 brcmf_btcoex_detach(cfg
);
5866 brcmf_p2p_detach(&cfg
->p2p
);
5867 wl_deinit_priv(cfg
);
5868 brcmf_free_wiphy(cfg
->wiphy
);