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"
43 #define BRCMF_SCAN_IE_LEN_MAX 2048
44 #define BRCMF_PNO_VERSION 2
45 #define BRCMF_PNO_TIME 30
46 #define BRCMF_PNO_REPEAT 4
47 #define BRCMF_PNO_FREQ_EXPO_MAX 3
48 #define BRCMF_PNO_MAX_PFN_COUNT 16
49 #define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
50 #define BRCMF_PNO_HIDDEN_BIT 2
51 #define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
52 #define BRCMF_PNO_SCAN_COMPLETE 1
53 #define BRCMF_PNO_SCAN_INCOMPLETE 0
55 #define BRCMF_IFACE_MAX_CNT 3
57 #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
58 #define WPA_OUI_TYPE 1
59 #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
60 #define WME_OUI_TYPE 2
61 #define WPS_OUI_TYPE 4
63 #define VS_IE_FIXED_HDR_LEN 6
64 #define WPA_IE_VERSION_LEN 2
65 #define WPA_IE_MIN_OUI_LEN 4
66 #define WPA_IE_SUITE_COUNT_LEN 2
68 #define WPA_CIPHER_NONE 0 /* None */
69 #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
70 #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
71 #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
72 #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
74 #define RSN_AKM_NONE 0 /* None (IBSS) */
75 #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
76 #define RSN_AKM_PSK 2 /* Pre-shared Key */
77 #define RSN_CAP_LEN 2 /* Length of RSN capabilities */
78 #define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
80 #define VNDR_IE_CMD_LEN 4 /* length of the set command
81 * string :"add", "del" (+ NUL)
83 #define VNDR_IE_COUNT_OFFSET 4
84 #define VNDR_IE_PKTFLAG_OFFSET 8
85 #define VNDR_IE_VSIE_OFFSET 12
86 #define VNDR_IE_HDR_SIZE 12
87 #define VNDR_IE_PARSE_LIMIT 5
89 #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
90 #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
92 #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
93 #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
94 #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
96 #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
97 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
99 static bool check_vif_up(struct brcmf_cfg80211_vif
*vif
)
101 if (!test_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
)) {
102 brcmf_dbg(INFO
, "device is not ready : status (%lu)\n",
109 #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
110 #define RATETAB_ENT(_rateid, _flags) \
112 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
113 .hw_value = (_rateid), \
117 static struct ieee80211_rate __wl_rates
[] = {
118 RATETAB_ENT(BRCM_RATE_1M
, 0),
119 RATETAB_ENT(BRCM_RATE_2M
, IEEE80211_RATE_SHORT_PREAMBLE
),
120 RATETAB_ENT(BRCM_RATE_5M5
, IEEE80211_RATE_SHORT_PREAMBLE
),
121 RATETAB_ENT(BRCM_RATE_11M
, IEEE80211_RATE_SHORT_PREAMBLE
),
122 RATETAB_ENT(BRCM_RATE_6M
, 0),
123 RATETAB_ENT(BRCM_RATE_9M
, 0),
124 RATETAB_ENT(BRCM_RATE_12M
, 0),
125 RATETAB_ENT(BRCM_RATE_18M
, 0),
126 RATETAB_ENT(BRCM_RATE_24M
, 0),
127 RATETAB_ENT(BRCM_RATE_36M
, 0),
128 RATETAB_ENT(BRCM_RATE_48M
, 0),
129 RATETAB_ENT(BRCM_RATE_54M
, 0),
132 #define wl_a_rates (__wl_rates + 4)
133 #define wl_a_rates_size 8
134 #define wl_g_rates (__wl_rates + 0)
135 #define wl_g_rates_size 12
137 /* Band templates duplicated per wiphy. The channel info
138 * is filled in after querying the device.
140 static const struct ieee80211_supported_band __wl_band_2ghz
= {
141 .band
= IEEE80211_BAND_2GHZ
,
142 .bitrates
= wl_g_rates
,
143 .n_bitrates
= wl_g_rates_size
,
146 static const struct ieee80211_supported_band __wl_band_5ghz_a
= {
147 .band
= IEEE80211_BAND_5GHZ
,
148 .bitrates
= wl_a_rates
,
149 .n_bitrates
= wl_a_rates_size
,
152 /* This is to override regulatory domains defined in cfg80211 module (reg.c)
153 * By default world regulatory domain defined in reg.c puts the flags
154 * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
155 * With respect to these flags, wpa_supplicant doesn't * start p2p
156 * operations on 5GHz channels. All the changes in world regulatory
157 * domain are to be done here.
159 static const struct ieee80211_regdomain brcmf_regdom
= {
163 /* IEEE 802.11b/g, channels 1..11 */
164 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
166 /* IEEE 802.11 channel 14 - Only JP enables
167 * this and for 802.11b only
169 REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
170 /* IEEE 802.11a, channel 36..64 */
171 REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
172 /* IEEE 802.11a, channel 100..165 */
173 REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
176 static const u32 __wl_cipher_suites
[] = {
177 WLAN_CIPHER_SUITE_WEP40
,
178 WLAN_CIPHER_SUITE_WEP104
,
179 WLAN_CIPHER_SUITE_TKIP
,
180 WLAN_CIPHER_SUITE_CCMP
,
181 WLAN_CIPHER_SUITE_AES_CMAC
,
184 /* Vendor specific ie. id = 221, oui and type defines exact ie */
185 struct brcmf_vs_tlv
{
192 struct parsed_vndr_ie_info
{
194 u32 ie_len
; /* total length including id & length field */
195 struct brcmf_vs_tlv vndrie
;
198 struct parsed_vndr_ies
{
200 struct parsed_vndr_ie_info ie_info
[VNDR_IE_PARSE_LIMIT
];
203 static int brcmf_roamoff
;
204 module_param_named(roamoff
, brcmf_roamoff
, int, S_IRUSR
);
205 MODULE_PARM_DESC(roamoff
, "do not use internal roaming engine");
207 /* Quarter dBm units to mW
208 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
209 * Table is offset so the last entry is largest mW value that fits in
213 #define QDBM_OFFSET 153 /* Offset for first entry */
214 #define QDBM_TABLE_LEN 40 /* Table size */
216 /* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
217 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
219 #define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
221 /* Largest mW value that will round down to the last table entry,
222 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
223 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
224 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
226 #define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
228 static const u16 nqdBm_to_mW_map
[QDBM_TABLE_LEN
] = {
229 /* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
230 /* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
231 /* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
232 /* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
233 /* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
234 /* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
237 static u16
brcmf_qdbm_to_mw(u8 qdbm
)
240 int idx
= qdbm
- QDBM_OFFSET
;
242 if (idx
>= QDBM_TABLE_LEN
)
243 /* clamp to max u16 mW value */
246 /* scale the qdBm index up to the range of the table 0-40
247 * where an offset of 40 qdBm equals a factor of 10 mW.
254 /* return the mW value scaled down to the correct factor of 10,
255 * adding in factor/2 to get proper rounding.
257 return (nqdBm_to_mW_map
[idx
] + factor
/ 2) / factor
;
260 static u8
brcmf_mw_to_qdbm(u16 mw
)
267 /* handle boundary case */
271 offset
= QDBM_OFFSET
;
273 /* move mw into the range of the table */
274 while (mw_uint
< QDBM_TABLE_LOW_BOUND
) {
279 for (qdbm
= 0; qdbm
< QDBM_TABLE_LEN
- 1; qdbm
++) {
280 boundary
= nqdBm_to_mW_map
[qdbm
] + (nqdBm_to_mW_map
[qdbm
+ 1] -
281 nqdBm_to_mW_map
[qdbm
]) / 2;
282 if (mw_uint
< boundary
)
291 static u16
chandef_to_chanspec(struct brcmu_d11inf
*d11inf
,
292 struct cfg80211_chan_def
*ch
)
294 struct brcmu_chan ch_inf
;
297 brcmf_dbg(TRACE
, "chandef: control %d center %d width %d\n",
298 ch
->chan
->center_freq
, ch
->center_freq1
, ch
->width
);
299 ch_inf
.chnum
= ieee80211_frequency_to_channel(ch
->center_freq1
);
300 primary_offset
= ch
->center_freq1
- ch
->chan
->center_freq
;
302 case NL80211_CHAN_WIDTH_20
:
303 case NL80211_CHAN_WIDTH_20_NOHT
:
304 ch_inf
.bw
= BRCMU_CHAN_BW_20
;
305 WARN_ON(primary_offset
!= 0);
307 case NL80211_CHAN_WIDTH_40
:
308 ch_inf
.bw
= BRCMU_CHAN_BW_40
;
309 if (primary_offset
< 0)
310 ch_inf
.sb
= BRCMU_CHAN_SB_U
;
312 ch_inf
.sb
= BRCMU_CHAN_SB_L
;
314 case NL80211_CHAN_WIDTH_80
:
315 ch_inf
.bw
= BRCMU_CHAN_BW_80
;
316 if (primary_offset
< 0) {
317 if (primary_offset
< -CH_10MHZ_APART
)
318 ch_inf
.sb
= BRCMU_CHAN_SB_UU
;
320 ch_inf
.sb
= BRCMU_CHAN_SB_UL
;
322 if (primary_offset
> CH_10MHZ_APART
)
323 ch_inf
.sb
= BRCMU_CHAN_SB_LL
;
325 ch_inf
.sb
= BRCMU_CHAN_SB_LU
;
328 case NL80211_CHAN_WIDTH_80P80
:
329 case NL80211_CHAN_WIDTH_160
:
330 case NL80211_CHAN_WIDTH_5
:
331 case NL80211_CHAN_WIDTH_10
:
335 switch (ch
->chan
->band
) {
336 case IEEE80211_BAND_2GHZ
:
337 ch_inf
.band
= BRCMU_CHAN_BAND_2G
;
339 case IEEE80211_BAND_5GHZ
:
340 ch_inf
.band
= BRCMU_CHAN_BAND_5G
;
342 case IEEE80211_BAND_60GHZ
:
346 d11inf
->encchspec(&ch_inf
);
348 return ch_inf
.chspec
;
351 u16
channel_to_chanspec(struct brcmu_d11inf
*d11inf
,
352 struct ieee80211_channel
*ch
)
354 struct brcmu_chan ch_inf
;
356 ch_inf
.chnum
= ieee80211_frequency_to_channel(ch
->center_freq
);
357 ch_inf
.bw
= BRCMU_CHAN_BW_20
;
358 d11inf
->encchspec(&ch_inf
);
360 return ch_inf
.chspec
;
363 /* Traverse a string of 1-byte tag/1-byte length/variable-length value
364 * triples, returning a pointer to the substring whose first element
367 const struct brcmf_tlv
*
368 brcmf_parse_tlvs(const void *buf
, int buflen
, uint key
)
370 const struct brcmf_tlv
*elt
= buf
;
373 /* find tagged parameter */
374 while (totlen
>= TLV_HDR_LEN
) {
377 /* validate remaining totlen */
378 if ((elt
->id
== key
) && (totlen
>= (len
+ TLV_HDR_LEN
)))
381 elt
= (struct brcmf_tlv
*)((u8
*)elt
+ (len
+ TLV_HDR_LEN
));
382 totlen
-= (len
+ TLV_HDR_LEN
);
388 /* Is any of the tlvs the expected entry? If
389 * not update the tlvs buffer pointer/length.
392 brcmf_tlv_has_ie(const u8
*ie
, const u8
**tlvs
, u32
*tlvs_len
,
393 const u8
*oui
, u32 oui_len
, u8 type
)
395 /* If the contents match the OUI and the type */
396 if (ie
[TLV_LEN_OFF
] >= oui_len
+ 1 &&
397 !memcmp(&ie
[TLV_BODY_OFF
], oui
, oui_len
) &&
398 type
== ie
[TLV_BODY_OFF
+ oui_len
]) {
404 /* point to the next ie */
405 ie
+= ie
[TLV_LEN_OFF
] + TLV_HDR_LEN
;
406 /* calculate the length of the rest of the buffer */
407 *tlvs_len
-= (int)(ie
- *tlvs
);
408 /* update the pointer to the start of the buffer */
414 static struct brcmf_vs_tlv
*
415 brcmf_find_wpaie(const u8
*parse
, u32 len
)
417 const struct brcmf_tlv
*ie
;
419 while ((ie
= brcmf_parse_tlvs(parse
, len
, WLAN_EID_VENDOR_SPECIFIC
))) {
420 if (brcmf_tlv_has_ie((const u8
*)ie
, &parse
, &len
,
421 WPA_OUI
, TLV_OUI_LEN
, WPA_OUI_TYPE
))
422 return (struct brcmf_vs_tlv
*)ie
;
427 static struct brcmf_vs_tlv
*
428 brcmf_find_wpsie(const u8
*parse
, u32 len
)
430 const struct brcmf_tlv
*ie
;
432 while ((ie
= brcmf_parse_tlvs(parse
, len
, WLAN_EID_VENDOR_SPECIFIC
))) {
433 if (brcmf_tlv_has_ie((u8
*)ie
, &parse
, &len
,
434 WPA_OUI
, TLV_OUI_LEN
, WPS_OUI_TYPE
))
435 return (struct brcmf_vs_tlv
*)ie
;
441 static void convert_key_from_CPU(struct brcmf_wsec_key
*key
,
442 struct brcmf_wsec_key_le
*key_le
)
444 key_le
->index
= cpu_to_le32(key
->index
);
445 key_le
->len
= cpu_to_le32(key
->len
);
446 key_le
->algo
= cpu_to_le32(key
->algo
);
447 key_le
->flags
= cpu_to_le32(key
->flags
);
448 key_le
->rxiv
.hi
= cpu_to_le32(key
->rxiv
.hi
);
449 key_le
->rxiv
.lo
= cpu_to_le16(key
->rxiv
.lo
);
450 key_le
->iv_initialized
= cpu_to_le32(key
->iv_initialized
);
451 memcpy(key_le
->data
, key
->data
, sizeof(key
->data
));
452 memcpy(key_le
->ea
, key
->ea
, sizeof(key
->ea
));
456 send_key_to_dongle(struct brcmf_if
*ifp
, struct brcmf_wsec_key
*key
)
459 struct brcmf_wsec_key_le key_le
;
461 convert_key_from_CPU(key
, &key_le
);
463 brcmf_netdev_wait_pend8021x(ifp
);
465 err
= brcmf_fil_bsscfg_data_set(ifp
, "wsec_key", &key_le
,
469 brcmf_err("wsec_key error (%d)\n", err
);
474 brcmf_configure_arp_offload(struct brcmf_if
*ifp
, bool enable
)
480 mode
= BRCMF_ARP_OL_AGENT
| BRCMF_ARP_OL_PEER_AUTO_REPLY
;
484 /* Try to set and enable ARP offload feature, this may fail, then it */
485 /* is simply not supported and err 0 will be returned */
486 err
= brcmf_fil_iovar_int_set(ifp
, "arp_ol", mode
);
488 brcmf_dbg(TRACE
, "failed to set ARP offload mode to 0x%x, err = %d\n",
492 err
= brcmf_fil_iovar_int_set(ifp
, "arpoe", enable
);
494 brcmf_dbg(TRACE
, "failed to configure (%d) ARP offload err = %d\n",
498 brcmf_dbg(TRACE
, "successfully configured (%d) ARP offload to 0x%x\n",
506 brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev
*wdev
)
508 struct brcmf_cfg80211_vif
*vif
;
509 struct brcmf_if
*ifp
;
511 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
514 if ((wdev
->iftype
== NL80211_IFTYPE_ADHOC
) ||
515 (wdev
->iftype
== NL80211_IFTYPE_AP
) ||
516 (wdev
->iftype
== NL80211_IFTYPE_P2P_GO
))
517 brcmf_proto_configure_addr_mode(ifp
->drvr
, ifp
->ifidx
,
520 brcmf_proto_configure_addr_mode(ifp
->drvr
, ifp
->ifidx
,
524 static int brcmf_cfg80211_request_ap_if(struct brcmf_if
*ifp
)
526 struct brcmf_mbss_ssid_le mbss_ssid_le
;
530 memset(&mbss_ssid_le
, 0, sizeof(mbss_ssid_le
));
531 bsscfgidx
= brcmf_get_next_free_bsscfgidx(ifp
->drvr
);
535 mbss_ssid_le
.bsscfgidx
= cpu_to_le32(bsscfgidx
);
536 mbss_ssid_le
.SSID_len
= cpu_to_le32(5);
537 sprintf(mbss_ssid_le
.SSID
, "ssid%d" , bsscfgidx
);
539 err
= brcmf_fil_bsscfg_data_set(ifp
, "bsscfg:ssid", &mbss_ssid_le
,
540 sizeof(mbss_ssid_le
));
542 brcmf_err("setting ssid failed %d\n", err
);
548 * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
550 * @wiphy: wiphy device of new interface.
551 * @name: name of the new interface.
553 * @params: contains mac address for AP device.
556 struct wireless_dev
*brcmf_ap_add_vif(struct wiphy
*wiphy
, const char *name
,
557 u32
*flags
, struct vif_params
*params
)
559 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
560 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
561 struct brcmf_cfg80211_vif
*vif
;
564 if (brcmf_cfg80211_vif_event_armed(cfg
))
565 return ERR_PTR(-EBUSY
);
567 brcmf_dbg(INFO
, "Adding vif \"%s\"\n", name
);
569 vif
= brcmf_alloc_vif(cfg
, NL80211_IFTYPE_AP
, false);
571 return (struct wireless_dev
*)vif
;
573 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
575 err
= brcmf_cfg80211_request_ap_if(ifp
);
577 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
581 /* wait for firmware event */
582 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_ADD
,
583 msecs_to_jiffies(1500));
584 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
586 brcmf_err("timeout occurred\n");
591 /* interface created in firmware */
594 brcmf_err("no if pointer provided\n");
599 strncpy(ifp
->ndev
->name
, name
, sizeof(ifp
->ndev
->name
) - 1);
600 err
= brcmf_net_attach(ifp
, true);
602 brcmf_err("Registering netdevice failed\n");
606 return &ifp
->vif
->wdev
;
613 static bool brcmf_is_apmode(struct brcmf_cfg80211_vif
*vif
)
615 enum nl80211_iftype iftype
;
617 iftype
= vif
->wdev
.iftype
;
618 return iftype
== NL80211_IFTYPE_AP
|| iftype
== NL80211_IFTYPE_P2P_GO
;
621 static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif
*vif
)
623 return vif
->wdev
.iftype
== NL80211_IFTYPE_ADHOC
;
626 static struct wireless_dev
*brcmf_cfg80211_add_iface(struct wiphy
*wiphy
,
628 enum nl80211_iftype type
,
630 struct vif_params
*params
)
632 struct wireless_dev
*wdev
;
634 brcmf_dbg(TRACE
, "enter: %s type %d\n", name
, type
);
636 case NL80211_IFTYPE_ADHOC
:
637 case NL80211_IFTYPE_STATION
:
638 case NL80211_IFTYPE_AP_VLAN
:
639 case NL80211_IFTYPE_WDS
:
640 case NL80211_IFTYPE_MONITOR
:
641 case NL80211_IFTYPE_MESH_POINT
:
642 return ERR_PTR(-EOPNOTSUPP
);
643 case NL80211_IFTYPE_AP
:
644 wdev
= brcmf_ap_add_vif(wiphy
, name
, flags
, params
);
646 brcmf_cfg80211_update_proto_addr_mode(wdev
);
648 case NL80211_IFTYPE_P2P_CLIENT
:
649 case NL80211_IFTYPE_P2P_GO
:
650 case NL80211_IFTYPE_P2P_DEVICE
:
651 wdev
= brcmf_p2p_add_vif(wiphy
, name
, type
, flags
, params
);
653 brcmf_cfg80211_update_proto_addr_mode(wdev
);
655 case NL80211_IFTYPE_UNSPECIFIED
:
657 return ERR_PTR(-EINVAL
);
661 static void brcmf_scan_config_mpc(struct brcmf_if
*ifp
, int mpc
)
663 if (brcmf_feat_is_quirk_enabled(ifp
, BRCMF_FEAT_QUIRK_NEED_MPC
))
664 brcmf_set_mpc(ifp
, mpc
);
667 void brcmf_set_mpc(struct brcmf_if
*ifp
, int mpc
)
671 if (check_vif_up(ifp
->vif
)) {
672 err
= brcmf_fil_iovar_int_set(ifp
, "mpc", mpc
);
674 brcmf_err("fail to set mpc\n");
677 brcmf_dbg(INFO
, "MPC : %d\n", mpc
);
681 s32
brcmf_notify_escan_complete(struct brcmf_cfg80211_info
*cfg
,
682 struct brcmf_if
*ifp
, bool aborted
,
685 struct brcmf_scan_params_le params_le
;
686 struct cfg80211_scan_request
*scan_request
;
689 brcmf_dbg(SCAN
, "Enter\n");
691 /* clear scan request, because the FW abort can cause a second call */
692 /* to this functon and might cause a double cfg80211_scan_done */
693 scan_request
= cfg
->scan_request
;
694 cfg
->scan_request
= NULL
;
696 if (timer_pending(&cfg
->escan_timeout
))
697 del_timer_sync(&cfg
->escan_timeout
);
700 /* Do a scan abort to stop the driver's scan engine */
701 brcmf_dbg(SCAN
, "ABORT scan in firmware\n");
702 memset(¶ms_le
, 0, sizeof(params_le
));
703 memset(params_le
.bssid
, 0xFF, ETH_ALEN
);
704 params_le
.bss_type
= DOT11_BSSTYPE_ANY
;
705 params_le
.scan_type
= 0;
706 params_le
.channel_num
= cpu_to_le32(1);
707 params_le
.nprobes
= cpu_to_le32(1);
708 params_le
.active_time
= cpu_to_le32(-1);
709 params_le
.passive_time
= cpu_to_le32(-1);
710 params_le
.home_time
= cpu_to_le32(-1);
711 /* Scan is aborted by setting channel_list[0] to -1 */
712 params_le
.channel_list
[0] = cpu_to_le16(-1);
713 /* E-Scan (or anyother type) can be aborted by SCAN */
714 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCAN
,
715 ¶ms_le
, sizeof(params_le
));
717 brcmf_err("Scan abort failed\n");
720 brcmf_scan_config_mpc(ifp
, 1);
723 * e-scan can be initiated by scheduled scan
724 * which takes precedence.
726 if (cfg
->sched_escan
) {
727 brcmf_dbg(SCAN
, "scheduled scan completed\n");
728 cfg
->sched_escan
= false;
730 cfg80211_sched_scan_results(cfg_to_wiphy(cfg
));
731 } else if (scan_request
) {
732 brcmf_dbg(SCAN
, "ESCAN Completed scan: %s\n",
733 aborted
? "Aborted" : "Done");
734 cfg80211_scan_done(scan_request
, aborted
);
736 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
737 brcmf_dbg(SCAN
, "Scan complete, probably P2P scan\n");
743 int brcmf_cfg80211_del_iface(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
745 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
746 struct net_device
*ndev
= wdev
->netdev
;
748 /* vif event pending in firmware */
749 if (brcmf_cfg80211_vif_event_armed(cfg
))
753 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
) &&
754 cfg
->escan_info
.ifp
== netdev_priv(ndev
))
755 brcmf_notify_escan_complete(cfg
, netdev_priv(ndev
),
758 brcmf_fil_iovar_int_set(netdev_priv(ndev
), "mpc", 1);
761 switch (wdev
->iftype
) {
762 case NL80211_IFTYPE_ADHOC
:
763 case NL80211_IFTYPE_STATION
:
764 case NL80211_IFTYPE_AP
:
765 case NL80211_IFTYPE_AP_VLAN
:
766 case NL80211_IFTYPE_WDS
:
767 case NL80211_IFTYPE_MONITOR
:
768 case NL80211_IFTYPE_MESH_POINT
:
770 case NL80211_IFTYPE_P2P_CLIENT
:
771 case NL80211_IFTYPE_P2P_GO
:
772 case NL80211_IFTYPE_P2P_DEVICE
:
773 return brcmf_p2p_del_vif(wiphy
, wdev
);
774 case NL80211_IFTYPE_UNSPECIFIED
:
782 brcmf_cfg80211_change_iface(struct wiphy
*wiphy
, struct net_device
*ndev
,
783 enum nl80211_iftype type
, u32
*flags
,
784 struct vif_params
*params
)
786 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
787 struct brcmf_if
*ifp
= netdev_priv(ndev
);
788 struct brcmf_cfg80211_vif
*vif
= ifp
->vif
;
793 brcmf_dbg(TRACE
, "Enter, ndev=%p, type=%d\n", ndev
, type
);
796 case NL80211_IFTYPE_MONITOR
:
797 case NL80211_IFTYPE_WDS
:
798 brcmf_err("type (%d) : currently we do not support this type\n",
801 case NL80211_IFTYPE_ADHOC
:
804 case NL80211_IFTYPE_STATION
:
805 /* Ignore change for p2p IF. Unclear why supplicant does this */
806 if ((vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_CLIENT
) ||
807 (vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_GO
)) {
808 brcmf_dbg(TRACE
, "Ignoring cmd for p2p if\n");
809 /* WAR: It is unexpected to get a change of VIF for P2P
810 * IF, but it happens. The request can not be handled
811 * but returning EPERM causes a crash. Returning 0
812 * without setting ieee80211_ptr->iftype causes trace
813 * (WARN_ON) but it works with wpa_supplicant
819 case NL80211_IFTYPE_AP
:
820 case NL80211_IFTYPE_P2P_GO
:
829 if (type
== NL80211_IFTYPE_P2P_GO
) {
830 brcmf_dbg(INFO
, "IF Type = P2P GO\n");
831 err
= brcmf_p2p_ifchange(cfg
, BRCMF_FIL_P2P_IF_GO
);
834 set_bit(BRCMF_VIF_STATUS_AP_CREATING
, &vif
->sme_state
);
835 brcmf_dbg(INFO
, "IF Type = AP\n");
838 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, infra
);
840 brcmf_err("WLC_SET_INFRA error (%d)\n", err
);
844 brcmf_dbg(INFO
, "IF Type = %s\n", brcmf_is_ibssmode(vif
) ?
847 ndev
->ieee80211_ptr
->iftype
= type
;
849 brcmf_cfg80211_update_proto_addr_mode(&vif
->wdev
);
852 brcmf_dbg(TRACE
, "Exit\n");
857 static void brcmf_escan_prep(struct brcmf_cfg80211_info
*cfg
,
858 struct brcmf_scan_params_le
*params_le
,
859 struct cfg80211_scan_request
*request
)
867 struct brcmf_ssid_le ssid_le
;
869 memset(params_le
->bssid
, 0xFF, ETH_ALEN
);
870 params_le
->bss_type
= DOT11_BSSTYPE_ANY
;
871 params_le
->scan_type
= 0;
872 params_le
->channel_num
= 0;
873 params_le
->nprobes
= cpu_to_le32(-1);
874 params_le
->active_time
= cpu_to_le32(-1);
875 params_le
->passive_time
= cpu_to_le32(-1);
876 params_le
->home_time
= cpu_to_le32(-1);
877 memset(¶ms_le
->ssid_le
, 0, sizeof(params_le
->ssid_le
));
879 /* if request is null exit so it will be all channel broadcast scan */
883 n_ssids
= request
->n_ssids
;
884 n_channels
= request
->n_channels
;
885 /* Copy channel array if applicable */
886 brcmf_dbg(SCAN
, "### List of channelspecs to scan ### %d\n",
888 if (n_channels
> 0) {
889 for (i
= 0; i
< n_channels
; i
++) {
890 chanspec
= channel_to_chanspec(&cfg
->d11inf
,
891 request
->channels
[i
]);
892 brcmf_dbg(SCAN
, "Chan : %d, Channel spec: %x\n",
893 request
->channels
[i
]->hw_value
, chanspec
);
894 params_le
->channel_list
[i
] = cpu_to_le16(chanspec
);
897 brcmf_dbg(SCAN
, "Scanning all channels\n");
899 /* Copy ssid array if applicable */
900 brcmf_dbg(SCAN
, "### List of SSIDs to scan ### %d\n", n_ssids
);
902 offset
= offsetof(struct brcmf_scan_params_le
, channel_list
) +
903 n_channels
* sizeof(u16
);
904 offset
= roundup(offset
, sizeof(u32
));
905 ptr
= (char *)params_le
+ offset
;
906 for (i
= 0; i
< n_ssids
; i
++) {
907 memset(&ssid_le
, 0, sizeof(ssid_le
));
909 cpu_to_le32(request
->ssids
[i
].ssid_len
);
910 memcpy(ssid_le
.SSID
, request
->ssids
[i
].ssid
,
911 request
->ssids
[i
].ssid_len
);
912 if (!ssid_le
.SSID_len
)
913 brcmf_dbg(SCAN
, "%d: Broadcast scan\n", i
);
915 brcmf_dbg(SCAN
, "%d: scan for %s size =%d\n",
916 i
, ssid_le
.SSID
, ssid_le
.SSID_len
);
917 memcpy(ptr
, &ssid_le
, sizeof(ssid_le
));
918 ptr
+= sizeof(ssid_le
);
921 brcmf_dbg(SCAN
, "Broadcast scan %p\n", request
->ssids
);
922 if ((request
->ssids
) && request
->ssids
->ssid_len
) {
923 brcmf_dbg(SCAN
, "SSID %s len=%d\n",
924 params_le
->ssid_le
.SSID
,
925 request
->ssids
->ssid_len
);
926 params_le
->ssid_le
.SSID_len
=
927 cpu_to_le32(request
->ssids
->ssid_len
);
928 memcpy(¶ms_le
->ssid_le
.SSID
, request
->ssids
->ssid
,
929 request
->ssids
->ssid_len
);
932 /* Adding mask to channel numbers */
933 params_le
->channel_num
=
934 cpu_to_le32((n_ssids
<< BRCMF_SCAN_PARAMS_NSSID_SHIFT
) |
935 (n_channels
& BRCMF_SCAN_PARAMS_COUNT_MASK
));
939 brcmf_run_escan(struct brcmf_cfg80211_info
*cfg
, struct brcmf_if
*ifp
,
940 struct cfg80211_scan_request
*request
, u16 action
)
942 s32 params_size
= BRCMF_SCAN_PARAMS_FIXED_SIZE
+
943 offsetof(struct brcmf_escan_params_le
, params_le
);
944 struct brcmf_escan_params_le
*params
;
947 brcmf_dbg(SCAN
, "E-SCAN START\n");
949 if (request
!= NULL
) {
950 /* Allocate space for populating ssids in struct */
951 params_size
+= sizeof(u32
) * ((request
->n_channels
+ 1) / 2);
953 /* Allocate space for populating ssids in struct */
954 params_size
+= sizeof(struct brcmf_ssid
) * request
->n_ssids
;
957 params
= kzalloc(params_size
, GFP_KERNEL
);
962 BUG_ON(params_size
+ sizeof("escan") >= BRCMF_DCMD_MEDLEN
);
963 brcmf_escan_prep(cfg
, ¶ms
->params_le
, request
);
964 params
->version
= cpu_to_le32(BRCMF_ESCAN_REQ_VERSION
);
965 params
->action
= cpu_to_le16(action
);
966 params
->sync_id
= cpu_to_le16(0x1234);
968 err
= brcmf_fil_iovar_data_set(ifp
, "escan", params
, params_size
);
971 brcmf_dbg(INFO
, "system busy : escan canceled\n");
973 brcmf_err("error (%d)\n", err
);
982 brcmf_do_escan(struct brcmf_cfg80211_info
*cfg
, struct wiphy
*wiphy
,
983 struct brcmf_if
*ifp
, struct cfg80211_scan_request
*request
)
987 struct brcmf_scan_results
*results
;
988 struct escan_info
*escan
= &cfg
->escan_info
;
990 brcmf_dbg(SCAN
, "Enter\n");
992 escan
->wiphy
= wiphy
;
993 escan
->escan_state
= WL_ESCAN_STATE_SCANNING
;
994 passive_scan
= cfg
->active_scan
? 0 : 1;
995 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PASSIVE_SCAN
,
998 brcmf_err("error (%d)\n", err
);
1001 brcmf_scan_config_mpc(ifp
, 0);
1002 results
= (struct brcmf_scan_results
*)cfg
->escan_info
.escan_buf
;
1003 results
->version
= 0;
1005 results
->buflen
= WL_ESCAN_RESULTS_FIXED_SIZE
;
1007 err
= escan
->run(cfg
, ifp
, request
, WL_ESCAN_ACTION_START
);
1009 brcmf_scan_config_mpc(ifp
, 1);
1014 brcmf_cfg80211_escan(struct wiphy
*wiphy
, struct brcmf_cfg80211_vif
*vif
,
1015 struct cfg80211_scan_request
*request
,
1016 struct cfg80211_ssid
*this_ssid
)
1018 struct brcmf_if
*ifp
= vif
->ifp
;
1019 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1020 struct cfg80211_ssid
*ssids
;
1021 struct brcmf_cfg80211_scan_req
*sr
= &cfg
->scan_req_int
;
1028 brcmf_dbg(SCAN
, "START ESCAN\n");
1030 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
1031 brcmf_err("Scanning already: status (%lu)\n", cfg
->scan_status
);
1034 if (test_bit(BRCMF_SCAN_STATUS_ABORT
, &cfg
->scan_status
)) {
1035 brcmf_err("Scanning being aborted: status (%lu)\n",
1039 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
)) {
1040 brcmf_err("Scanning suppressed: status (%lu)\n",
1044 if (test_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
)) {
1045 brcmf_err("Connecting: status (%lu)\n", ifp
->vif
->sme_state
);
1049 /* If scan req comes for p2p0, send it over primary I/F */
1050 if (vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
1051 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1053 /* Arm scan timeout timer */
1054 mod_timer(&cfg
->escan_timeout
, jiffies
+
1055 WL_ESCAN_TIMER_INTERVAL_MS
* HZ
/ 1000);
1060 ssids
= request
->ssids
;
1064 /* we don't do escan in ibss */
1068 cfg
->scan_request
= request
;
1069 set_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
1071 cfg
->escan_info
.run
= brcmf_run_escan
;
1072 err
= brcmf_p2p_scan_prep(wiphy
, request
, vif
);
1076 err
= brcmf_do_escan(cfg
, wiphy
, vif
->ifp
, request
);
1080 brcmf_dbg(SCAN
, "ssid \"%s\", ssid_len (%d)\n",
1081 ssids
->ssid
, ssids
->ssid_len
);
1082 memset(&sr
->ssid_le
, 0, sizeof(sr
->ssid_le
));
1083 SSID_len
= min_t(u8
, sizeof(sr
->ssid_le
.SSID
), ssids
->ssid_len
);
1084 sr
->ssid_le
.SSID_len
= cpu_to_le32(0);
1087 memcpy(sr
->ssid_le
.SSID
, ssids
->ssid
, SSID_len
);
1088 sr
->ssid_le
.SSID_len
= cpu_to_le32(SSID_len
);
1091 brcmf_dbg(SCAN
, "Broadcast scan\n");
1093 passive_scan
= cfg
->active_scan
? 0 : 1;
1094 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PASSIVE_SCAN
,
1097 brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err
);
1100 brcmf_scan_config_mpc(ifp
, 0);
1101 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCAN
,
1102 &sr
->ssid_le
, sizeof(sr
->ssid_le
));
1105 brcmf_dbg(INFO
, "BUSY: scan for \"%s\" canceled\n",
1108 brcmf_err("WLC_SCAN error (%d)\n", err
);
1110 brcmf_scan_config_mpc(ifp
, 1);
1118 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
1119 if (timer_pending(&cfg
->escan_timeout
))
1120 del_timer_sync(&cfg
->escan_timeout
);
1121 cfg
->scan_request
= NULL
;
1126 brcmf_cfg80211_scan(struct wiphy
*wiphy
, struct cfg80211_scan_request
*request
)
1128 struct brcmf_cfg80211_vif
*vif
;
1131 brcmf_dbg(TRACE
, "Enter\n");
1132 vif
= container_of(request
->wdev
, struct brcmf_cfg80211_vif
, wdev
);
1133 if (!check_vif_up(vif
))
1136 err
= brcmf_cfg80211_escan(wiphy
, vif
, request
, NULL
);
1139 brcmf_err("scan error (%d)\n", err
);
1141 brcmf_dbg(TRACE
, "Exit\n");
1145 static s32
brcmf_set_rts(struct net_device
*ndev
, u32 rts_threshold
)
1149 err
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "rtsthresh",
1152 brcmf_err("Error (%d)\n", err
);
1157 static s32
brcmf_set_frag(struct net_device
*ndev
, u32 frag_threshold
)
1161 err
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "fragthresh",
1164 brcmf_err("Error (%d)\n", err
);
1169 static s32
brcmf_set_retry(struct net_device
*ndev
, u32 retry
, bool l
)
1172 u32 cmd
= (l
? BRCMF_C_SET_LRL
: BRCMF_C_SET_SRL
);
1174 err
= brcmf_fil_cmd_int_set(netdev_priv(ndev
), cmd
, retry
);
1176 brcmf_err("cmd (%d) , error (%d)\n", cmd
, err
);
1182 static s32
brcmf_cfg80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1184 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1185 struct net_device
*ndev
= cfg_to_ndev(cfg
);
1186 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1189 brcmf_dbg(TRACE
, "Enter\n");
1190 if (!check_vif_up(ifp
->vif
))
1193 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
&&
1194 (cfg
->conf
->rts_threshold
!= wiphy
->rts_threshold
)) {
1195 cfg
->conf
->rts_threshold
= wiphy
->rts_threshold
;
1196 err
= brcmf_set_rts(ndev
, cfg
->conf
->rts_threshold
);
1200 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
&&
1201 (cfg
->conf
->frag_threshold
!= wiphy
->frag_threshold
)) {
1202 cfg
->conf
->frag_threshold
= wiphy
->frag_threshold
;
1203 err
= brcmf_set_frag(ndev
, cfg
->conf
->frag_threshold
);
1207 if (changed
& WIPHY_PARAM_RETRY_LONG
1208 && (cfg
->conf
->retry_long
!= wiphy
->retry_long
)) {
1209 cfg
->conf
->retry_long
= wiphy
->retry_long
;
1210 err
= brcmf_set_retry(ndev
, cfg
->conf
->retry_long
, true);
1214 if (changed
& WIPHY_PARAM_RETRY_SHORT
1215 && (cfg
->conf
->retry_short
!= wiphy
->retry_short
)) {
1216 cfg
->conf
->retry_short
= wiphy
->retry_short
;
1217 err
= brcmf_set_retry(ndev
, cfg
->conf
->retry_short
, false);
1223 brcmf_dbg(TRACE
, "Exit\n");
1227 static void brcmf_init_prof(struct brcmf_cfg80211_profile
*prof
)
1229 memset(prof
, 0, sizeof(*prof
));
1232 static void brcmf_link_down(struct brcmf_cfg80211_vif
*vif
)
1234 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(vif
->wdev
.wiphy
);
1237 brcmf_dbg(TRACE
, "Enter\n");
1239 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &vif
->sme_state
)) {
1240 brcmf_dbg(INFO
, "Call WLC_DISASSOC to stop excess roaming\n ");
1241 err
= brcmf_fil_cmd_data_set(vif
->ifp
,
1242 BRCMF_C_DISASSOC
, NULL
, 0);
1244 brcmf_err("WLC_DISASSOC failed (%d)\n", err
);
1246 clear_bit(BRCMF_VIF_STATUS_CONNECTED
, &vif
->sme_state
);
1247 cfg80211_disconnected(vif
->wdev
.netdev
, 0, NULL
, 0, GFP_KERNEL
);
1250 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &vif
->sme_state
);
1251 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
1252 brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_ENABLED
, 0);
1253 brcmf_dbg(TRACE
, "Exit\n");
1257 brcmf_cfg80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*ndev
,
1258 struct cfg80211_ibss_params
*params
)
1260 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1261 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1262 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
1263 struct brcmf_join_params join_params
;
1264 size_t join_params_size
= 0;
1270 brcmf_dbg(TRACE
, "Enter\n");
1271 if (!check_vif_up(ifp
->vif
))
1275 brcmf_dbg(CONN
, "SSID: %s\n", params
->ssid
);
1277 brcmf_dbg(CONN
, "SSID: NULL, Not supported\n");
1281 set_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1284 brcmf_dbg(CONN
, "BSSID: %pM\n", params
->bssid
);
1286 brcmf_dbg(CONN
, "No BSSID specified\n");
1288 if (params
->chandef
.chan
)
1289 brcmf_dbg(CONN
, "channel: %d\n",
1290 params
->chandef
.chan
->center_freq
);
1292 brcmf_dbg(CONN
, "no channel specified\n");
1294 if (params
->channel_fixed
)
1295 brcmf_dbg(CONN
, "fixed channel required\n");
1297 brcmf_dbg(CONN
, "no fixed channel required\n");
1299 if (params
->ie
&& params
->ie_len
)
1300 brcmf_dbg(CONN
, "ie len: %d\n", params
->ie_len
);
1302 brcmf_dbg(CONN
, "no ie specified\n");
1304 if (params
->beacon_interval
)
1305 brcmf_dbg(CONN
, "beacon interval: %d\n",
1306 params
->beacon_interval
);
1308 brcmf_dbg(CONN
, "no beacon interval specified\n");
1310 if (params
->basic_rates
)
1311 brcmf_dbg(CONN
, "basic rates: %08X\n", params
->basic_rates
);
1313 brcmf_dbg(CONN
, "no basic rates specified\n");
1315 if (params
->privacy
)
1316 brcmf_dbg(CONN
, "privacy required\n");
1318 brcmf_dbg(CONN
, "no privacy required\n");
1320 /* Configure Privacy for starter */
1321 if (params
->privacy
)
1322 wsec
|= WEP_ENABLED
;
1324 err
= brcmf_fil_iovar_int_set(ifp
, "wsec", wsec
);
1326 brcmf_err("wsec failed (%d)\n", err
);
1330 /* Configure Beacon Interval for starter */
1331 if (params
->beacon_interval
)
1332 bcnprd
= params
->beacon_interval
;
1336 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_BCNPRD
, bcnprd
);
1338 brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err
);
1342 /* Configure required join parameter */
1343 memset(&join_params
, 0, sizeof(struct brcmf_join_params
));
1346 profile
->ssid
.SSID_len
= min_t(u32
, params
->ssid_len
, 32);
1347 memcpy(profile
->ssid
.SSID
, params
->ssid
, profile
->ssid
.SSID_len
);
1348 memcpy(join_params
.ssid_le
.SSID
, params
->ssid
, profile
->ssid
.SSID_len
);
1349 join_params
.ssid_le
.SSID_len
= cpu_to_le32(profile
->ssid
.SSID_len
);
1350 join_params_size
= sizeof(join_params
.ssid_le
);
1353 if (params
->bssid
) {
1354 memcpy(join_params
.params_le
.bssid
, params
->bssid
, ETH_ALEN
);
1355 join_params_size
= sizeof(join_params
.ssid_le
) +
1356 BRCMF_ASSOC_PARAMS_FIXED_SIZE
;
1357 memcpy(profile
->bssid
, params
->bssid
, ETH_ALEN
);
1359 memset(join_params
.params_le
.bssid
, 0xFF, ETH_ALEN
);
1360 memset(profile
->bssid
, 0, ETH_ALEN
);
1364 if (params
->chandef
.chan
) {
1368 ieee80211_frequency_to_channel(
1369 params
->chandef
.chan
->center_freq
);
1370 if (params
->channel_fixed
) {
1371 /* adding chanspec */
1372 chanspec
= chandef_to_chanspec(&cfg
->d11inf
,
1374 join_params
.params_le
.chanspec_list
[0] =
1375 cpu_to_le16(chanspec
);
1376 join_params
.params_le
.chanspec_num
= cpu_to_le32(1);
1377 join_params_size
+= sizeof(join_params
.params_le
);
1380 /* set channel for starter */
1381 target_channel
= cfg
->channel
;
1382 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_CHANNEL
,
1385 brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err
);
1391 cfg
->ibss_starter
= false;
1394 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
1395 &join_params
, join_params_size
);
1397 brcmf_err("WLC_SET_SSID failed (%d)\n", err
);
1403 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1404 brcmf_dbg(TRACE
, "Exit\n");
1409 brcmf_cfg80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*ndev
)
1411 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1413 brcmf_dbg(TRACE
, "Enter\n");
1414 if (!check_vif_up(ifp
->vif
))
1417 brcmf_link_down(ifp
->vif
);
1419 brcmf_dbg(TRACE
, "Exit\n");
1424 static s32
brcmf_set_wpa_version(struct net_device
*ndev
,
1425 struct cfg80211_connect_params
*sme
)
1427 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1428 struct brcmf_cfg80211_security
*sec
;
1432 if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_1
)
1433 val
= WPA_AUTH_PSK
| WPA_AUTH_UNSPECIFIED
;
1434 else if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_2
)
1435 val
= WPA2_AUTH_PSK
| WPA2_AUTH_UNSPECIFIED
;
1437 val
= WPA_AUTH_DISABLED
;
1438 brcmf_dbg(CONN
, "setting wpa_auth to 0x%0x\n", val
);
1439 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "wpa_auth", val
);
1441 brcmf_err("set wpa_auth failed (%d)\n", err
);
1444 sec
= &profile
->sec
;
1445 sec
->wpa_versions
= sme
->crypto
.wpa_versions
;
1449 static s32
brcmf_set_auth_type(struct net_device
*ndev
,
1450 struct cfg80211_connect_params
*sme
)
1452 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1453 struct brcmf_cfg80211_security
*sec
;
1457 switch (sme
->auth_type
) {
1458 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
1460 brcmf_dbg(CONN
, "open system\n");
1462 case NL80211_AUTHTYPE_SHARED_KEY
:
1464 brcmf_dbg(CONN
, "shared key\n");
1466 case NL80211_AUTHTYPE_AUTOMATIC
:
1468 brcmf_dbg(CONN
, "automatic\n");
1470 case NL80211_AUTHTYPE_NETWORK_EAP
:
1471 brcmf_dbg(CONN
, "network eap\n");
1474 brcmf_err("invalid auth type (%d)\n", sme
->auth_type
);
1478 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "auth", val
);
1480 brcmf_err("set auth failed (%d)\n", err
);
1483 sec
= &profile
->sec
;
1484 sec
->auth_type
= sme
->auth_type
;
1489 brcmf_set_wsec_mode(struct net_device
*ndev
,
1490 struct cfg80211_connect_params
*sme
, bool mfp
)
1492 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1493 struct brcmf_cfg80211_security
*sec
;
1499 if (sme
->crypto
.n_ciphers_pairwise
) {
1500 switch (sme
->crypto
.ciphers_pairwise
[0]) {
1501 case WLAN_CIPHER_SUITE_WEP40
:
1502 case WLAN_CIPHER_SUITE_WEP104
:
1505 case WLAN_CIPHER_SUITE_TKIP
:
1506 pval
= TKIP_ENABLED
;
1508 case WLAN_CIPHER_SUITE_CCMP
:
1511 case WLAN_CIPHER_SUITE_AES_CMAC
:
1515 brcmf_err("invalid cipher pairwise (%d)\n",
1516 sme
->crypto
.ciphers_pairwise
[0]);
1520 if (sme
->crypto
.cipher_group
) {
1521 switch (sme
->crypto
.cipher_group
) {
1522 case WLAN_CIPHER_SUITE_WEP40
:
1523 case WLAN_CIPHER_SUITE_WEP104
:
1526 case WLAN_CIPHER_SUITE_TKIP
:
1527 gval
= TKIP_ENABLED
;
1529 case WLAN_CIPHER_SUITE_CCMP
:
1532 case WLAN_CIPHER_SUITE_AES_CMAC
:
1536 brcmf_err("invalid cipher group (%d)\n",
1537 sme
->crypto
.cipher_group
);
1542 brcmf_dbg(CONN
, "pval (%d) gval (%d)\n", pval
, gval
);
1543 /* In case of privacy, but no security and WPS then simulate */
1544 /* setting AES. WPS-2.0 allows no security */
1545 if (brcmf_find_wpsie(sme
->ie
, sme
->ie_len
) && !pval
&& !gval
&&
1550 wsec
= pval
| gval
| MFP_CAPABLE
;
1553 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "wsec", wsec
);
1555 brcmf_err("error (%d)\n", err
);
1559 sec
= &profile
->sec
;
1560 sec
->cipher_pairwise
= sme
->crypto
.ciphers_pairwise
[0];
1561 sec
->cipher_group
= sme
->crypto
.cipher_group
;
1567 brcmf_set_key_mgmt(struct net_device
*ndev
, struct cfg80211_connect_params
*sme
)
1569 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1570 struct brcmf_cfg80211_security
*sec
;
1574 if (sme
->crypto
.n_akm_suites
) {
1575 err
= brcmf_fil_bsscfg_int_get(netdev_priv(ndev
),
1578 brcmf_err("could not get wpa_auth (%d)\n", err
);
1581 if (val
& (WPA_AUTH_PSK
| WPA_AUTH_UNSPECIFIED
)) {
1582 switch (sme
->crypto
.akm_suites
[0]) {
1583 case WLAN_AKM_SUITE_8021X
:
1584 val
= WPA_AUTH_UNSPECIFIED
;
1586 case WLAN_AKM_SUITE_PSK
:
1590 brcmf_err("invalid cipher group (%d)\n",
1591 sme
->crypto
.cipher_group
);
1594 } else if (val
& (WPA2_AUTH_PSK
| WPA2_AUTH_UNSPECIFIED
)) {
1595 switch (sme
->crypto
.akm_suites
[0]) {
1596 case WLAN_AKM_SUITE_8021X
:
1597 val
= WPA2_AUTH_UNSPECIFIED
;
1599 case WLAN_AKM_SUITE_PSK
:
1600 val
= WPA2_AUTH_PSK
;
1603 brcmf_err("invalid cipher group (%d)\n",
1604 sme
->crypto
.cipher_group
);
1609 brcmf_dbg(CONN
, "setting wpa_auth to %d\n", val
);
1610 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
),
1613 brcmf_err("could not set wpa_auth (%d)\n", err
);
1617 sec
= &profile
->sec
;
1618 sec
->wpa_auth
= sme
->crypto
.akm_suites
[0];
1624 brcmf_set_sharedkey(struct net_device
*ndev
,
1625 struct cfg80211_connect_params
*sme
)
1627 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ndev
);
1628 struct brcmf_cfg80211_security
*sec
;
1629 struct brcmf_wsec_key key
;
1633 brcmf_dbg(CONN
, "key len (%d)\n", sme
->key_len
);
1635 if (sme
->key_len
== 0)
1638 sec
= &profile
->sec
;
1639 brcmf_dbg(CONN
, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
1640 sec
->wpa_versions
, sec
->cipher_pairwise
);
1642 if (sec
->wpa_versions
& (NL80211_WPA_VERSION_1
| NL80211_WPA_VERSION_2
))
1645 if (!(sec
->cipher_pairwise
&
1646 (WLAN_CIPHER_SUITE_WEP40
| WLAN_CIPHER_SUITE_WEP104
)))
1649 memset(&key
, 0, sizeof(key
));
1650 key
.len
= (u32
) sme
->key_len
;
1651 key
.index
= (u32
) sme
->key_idx
;
1652 if (key
.len
> sizeof(key
.data
)) {
1653 brcmf_err("Too long key length (%u)\n", key
.len
);
1656 memcpy(key
.data
, sme
->key
, key
.len
);
1657 key
.flags
= BRCMF_PRIMARY_KEY
;
1658 switch (sec
->cipher_pairwise
) {
1659 case WLAN_CIPHER_SUITE_WEP40
:
1660 key
.algo
= CRYPTO_ALGO_WEP1
;
1662 case WLAN_CIPHER_SUITE_WEP104
:
1663 key
.algo
= CRYPTO_ALGO_WEP128
;
1666 brcmf_err("Invalid algorithm (%d)\n",
1667 sme
->crypto
.ciphers_pairwise
[0]);
1670 /* Set the new key/index */
1671 brcmf_dbg(CONN
, "key length (%d) key index (%d) algo (%d)\n",
1672 key
.len
, key
.index
, key
.algo
);
1673 brcmf_dbg(CONN
, "key \"%s\"\n", key
.data
);
1674 err
= send_key_to_dongle(netdev_priv(ndev
), &key
);
1678 if (sec
->auth_type
== NL80211_AUTHTYPE_SHARED_KEY
) {
1679 brcmf_dbg(CONN
, "set auth_type to shared key\n");
1680 val
= WL_AUTH_SHARED_KEY
; /* shared key */
1681 err
= brcmf_fil_bsscfg_int_set(netdev_priv(ndev
), "auth", val
);
1683 brcmf_err("set auth failed (%d)\n", err
);
1689 enum nl80211_auth_type
brcmf_war_auth_type(struct brcmf_if
*ifp
,
1690 enum nl80211_auth_type type
)
1692 if (type
== NL80211_AUTHTYPE_AUTOMATIC
&&
1693 brcmf_feat_is_quirk_enabled(ifp
, BRCMF_FEAT_QUIRK_AUTO_AUTH
)) {
1694 brcmf_dbg(CONN
, "WAR: use OPEN instead of AUTO\n");
1695 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
1701 brcmf_cfg80211_connect(struct wiphy
*wiphy
, struct net_device
*ndev
,
1702 struct cfg80211_connect_params
*sme
)
1704 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1705 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1706 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
1707 struct ieee80211_channel
*chan
= sme
->channel
;
1708 struct brcmf_join_params join_params
;
1709 size_t join_params_size
;
1710 const struct brcmf_tlv
*rsn_ie
;
1711 const struct brcmf_vs_tlv
*wpa_ie
;
1714 struct brcmf_ext_join_params_le
*ext_join_params
;
1718 brcmf_dbg(TRACE
, "Enter\n");
1719 if (!check_vif_up(ifp
->vif
))
1723 brcmf_err("Invalid ssid\n");
1727 if (ifp
->vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
) {
1728 /* A normal (non P2P) connection request setup. */
1731 /* find the WPA_IE */
1732 wpa_ie
= brcmf_find_wpaie((u8
*)sme
->ie
, sme
->ie_len
);
1735 ie_len
= wpa_ie
->len
+ TLV_HDR_LEN
;
1737 /* find the RSN_IE */
1738 rsn_ie
= brcmf_parse_tlvs((const u8
*)sme
->ie
,
1743 ie_len
= rsn_ie
->len
+ TLV_HDR_LEN
;
1746 brcmf_fil_iovar_data_set(ifp
, "wpaie", ie
, ie_len
);
1749 err
= brcmf_vif_set_mgmt_ie(ifp
->vif
, BRCMF_VNDR_IE_ASSOCREQ_FLAG
,
1750 sme
->ie
, sme
->ie_len
);
1752 brcmf_err("Set Assoc REQ IE Failed\n");
1754 brcmf_dbg(TRACE
, "Applied Vndr IEs for Assoc request\n");
1756 set_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1760 ieee80211_frequency_to_channel(chan
->center_freq
);
1761 chanspec
= channel_to_chanspec(&cfg
->d11inf
, chan
);
1762 brcmf_dbg(CONN
, "channel=%d, center_req=%d, chanspec=0x%04x\n",
1763 cfg
->channel
, chan
->center_freq
, chanspec
);
1769 brcmf_dbg(INFO
, "ie (%p), ie_len (%zd)\n", sme
->ie
, sme
->ie_len
);
1771 err
= brcmf_set_wpa_version(ndev
, sme
);
1773 brcmf_err("wl_set_wpa_version failed (%d)\n", err
);
1777 sme
->auth_type
= brcmf_war_auth_type(ifp
, sme
->auth_type
);
1778 err
= brcmf_set_auth_type(ndev
, sme
);
1780 brcmf_err("wl_set_auth_type failed (%d)\n", err
);
1784 err
= brcmf_set_wsec_mode(ndev
, sme
, sme
->mfp
== NL80211_MFP_REQUIRED
);
1786 brcmf_err("wl_set_set_cipher failed (%d)\n", err
);
1790 err
= brcmf_set_key_mgmt(ndev
, sme
);
1792 brcmf_err("wl_set_key_mgmt failed (%d)\n", err
);
1796 err
= brcmf_set_sharedkey(ndev
, sme
);
1798 brcmf_err("brcmf_set_sharedkey failed (%d)\n", err
);
1802 profile
->ssid
.SSID_len
= min_t(u32
, (u32
)sizeof(profile
->ssid
.SSID
),
1803 (u32
)sme
->ssid_len
);
1804 memcpy(&profile
->ssid
.SSID
, sme
->ssid
, profile
->ssid
.SSID_len
);
1805 if (profile
->ssid
.SSID_len
< IEEE80211_MAX_SSID_LEN
) {
1806 profile
->ssid
.SSID
[profile
->ssid
.SSID_len
] = 0;
1807 brcmf_dbg(CONN
, "SSID \"%s\", len (%d)\n", profile
->ssid
.SSID
,
1808 profile
->ssid
.SSID_len
);
1811 /* Join with specific BSSID and cached SSID
1812 * If SSID is zero join based on BSSID only
1814 join_params_size
= offsetof(struct brcmf_ext_join_params_le
, assoc_le
) +
1815 offsetof(struct brcmf_assoc_params_le
, chanspec_list
);
1817 join_params_size
+= sizeof(u16
);
1818 ext_join_params
= kzalloc(join_params_size
, GFP_KERNEL
);
1819 if (ext_join_params
== NULL
) {
1823 ext_join_params
->ssid_le
.SSID_len
= cpu_to_le32(profile
->ssid
.SSID_len
);
1824 memcpy(&ext_join_params
->ssid_le
.SSID
, sme
->ssid
,
1825 profile
->ssid
.SSID_len
);
1827 /* Set up join scan parameters */
1828 ext_join_params
->scan_le
.scan_type
= -1;
1829 ext_join_params
->scan_le
.home_time
= cpu_to_le32(-1);
1832 memcpy(&ext_join_params
->assoc_le
.bssid
, sme
->bssid
, ETH_ALEN
);
1834 memset(&ext_join_params
->assoc_le
.bssid
, 0xFF, ETH_ALEN
);
1837 ext_join_params
->assoc_le
.chanspec_num
= cpu_to_le32(1);
1839 ext_join_params
->assoc_le
.chanspec_list
[0] =
1840 cpu_to_le16(chanspec
);
1841 /* Increase dwell time to receive probe response or detect
1842 * beacon from target AP at a noisy air only during connect
1845 ext_join_params
->scan_le
.active_time
=
1846 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS
);
1847 ext_join_params
->scan_le
.passive_time
=
1848 cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS
);
1849 /* To sync with presence period of VSDB GO send probe request
1850 * more frequently. Probe request will be stopped when it gets
1851 * probe response from target AP/GO.
1853 ext_join_params
->scan_le
.nprobes
=
1854 cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS
/
1855 BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS
);
1857 ext_join_params
->scan_le
.active_time
= cpu_to_le32(-1);
1858 ext_join_params
->scan_le
.passive_time
= cpu_to_le32(-1);
1859 ext_join_params
->scan_le
.nprobes
= cpu_to_le32(-1);
1862 err
= brcmf_fil_bsscfg_data_set(ifp
, "join", ext_join_params
,
1864 kfree(ext_join_params
);
1866 /* This is it. join command worked, we are done */
1869 /* join command failed, fallback to set ssid */
1870 memset(&join_params
, 0, sizeof(join_params
));
1871 join_params_size
= sizeof(join_params
.ssid_le
);
1873 memcpy(&join_params
.ssid_le
.SSID
, sme
->ssid
, profile
->ssid
.SSID_len
);
1874 join_params
.ssid_le
.SSID_len
= cpu_to_le32(profile
->ssid
.SSID_len
);
1877 memcpy(join_params
.params_le
.bssid
, sme
->bssid
, ETH_ALEN
);
1879 memset(join_params
.params_le
.bssid
, 0xFF, ETH_ALEN
);
1882 join_params
.params_le
.chanspec_list
[0] = cpu_to_le16(chanspec
);
1883 join_params
.params_le
.chanspec_num
= cpu_to_le32(1);
1884 join_params_size
+= sizeof(join_params
.params_le
);
1886 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
1887 &join_params
, join_params_size
);
1889 brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err
);
1893 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1894 brcmf_dbg(TRACE
, "Exit\n");
1899 brcmf_cfg80211_disconnect(struct wiphy
*wiphy
, struct net_device
*ndev
,
1902 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1903 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
1904 struct brcmf_scb_val_le scbval
;
1907 brcmf_dbg(TRACE
, "Enter. Reason code = %d\n", reason_code
);
1908 if (!check_vif_up(ifp
->vif
))
1911 clear_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
);
1912 clear_bit(BRCMF_VIF_STATUS_CONNECTING
, &ifp
->vif
->sme_state
);
1913 cfg80211_disconnected(ndev
, reason_code
, NULL
, 0, GFP_KERNEL
);
1915 memcpy(&scbval
.ea
, &profile
->bssid
, ETH_ALEN
);
1916 scbval
.val
= cpu_to_le32(reason_code
);
1917 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_DISASSOC
,
1918 &scbval
, sizeof(scbval
));
1920 brcmf_err("error (%d)\n", err
);
1922 brcmf_dbg(TRACE
, "Exit\n");
1927 brcmf_cfg80211_set_tx_power(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
1928 enum nl80211_tx_power_setting type
, s32 mbm
)
1931 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1932 struct net_device
*ndev
= cfg_to_ndev(cfg
);
1933 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1937 s32 dbm
= MBM_TO_DBM(mbm
);
1939 brcmf_dbg(TRACE
, "Enter\n");
1940 if (!check_vif_up(ifp
->vif
))
1944 case NL80211_TX_POWER_AUTOMATIC
:
1946 case NL80211_TX_POWER_LIMITED
:
1947 case NL80211_TX_POWER_FIXED
:
1949 brcmf_err("TX_POWER_FIXED - dbm is negative\n");
1955 /* Make sure radio is off or on as far as software is concerned */
1956 disable
= WL_RADIO_SW_DISABLE
<< 16;
1957 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_RADIO
, disable
);
1959 brcmf_err("WLC_SET_RADIO error (%d)\n", err
);
1964 txpwrmw
= (u16
) dbm
;
1965 err
= brcmf_fil_iovar_int_set(ifp
, "qtxpower",
1966 (s32
)brcmf_mw_to_qdbm(txpwrmw
));
1968 brcmf_err("qtxpower error (%d)\n", err
);
1969 cfg
->conf
->tx_power
= dbm
;
1972 brcmf_dbg(TRACE
, "Exit\n");
1976 static s32
brcmf_cfg80211_get_tx_power(struct wiphy
*wiphy
,
1977 struct wireless_dev
*wdev
,
1980 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1981 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
1986 brcmf_dbg(TRACE
, "Enter\n");
1987 if (!check_vif_up(ifp
->vif
))
1990 err
= brcmf_fil_iovar_int_get(ifp
, "qtxpower", &txpwrdbm
);
1992 brcmf_err("error (%d)\n", err
);
1996 result
= (u8
) (txpwrdbm
& ~WL_TXPWR_OVERRIDE
);
1997 *dbm
= (s32
) brcmf_qdbm_to_mw(result
);
2000 brcmf_dbg(TRACE
, "Exit\n");
2005 brcmf_cfg80211_config_default_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2006 u8 key_idx
, bool unicast
, bool multicast
)
2008 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2013 brcmf_dbg(TRACE
, "Enter\n");
2014 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2015 if (!check_vif_up(ifp
->vif
))
2018 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
2020 brcmf_err("WLC_GET_WSEC error (%d)\n", err
);
2024 if (wsec
& WEP_ENABLED
) {
2025 /* Just select a new current key */
2027 err
= brcmf_fil_cmd_int_set(ifp
,
2028 BRCMF_C_SET_KEY_PRIMARY
, index
);
2030 brcmf_err("error (%d)\n", err
);
2033 brcmf_dbg(TRACE
, "Exit\n");
2038 brcmf_add_keyext(struct wiphy
*wiphy
, struct net_device
*ndev
,
2039 u8 key_idx
, const u8
*mac_addr
, struct key_params
*params
)
2041 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2042 struct brcmf_wsec_key key
;
2046 memset(&key
, 0, sizeof(key
));
2047 key
.index
= (u32
) key_idx
;
2048 /* Instead of bcast for ea address for default wep keys,
2049 driver needs it to be Null */
2050 if (!is_multicast_ether_addr(mac_addr
))
2051 memcpy((char *)&key
.ea
, (void *)mac_addr
, ETH_ALEN
);
2052 key
.len
= (u32
) params
->key_len
;
2053 /* check for key index change */
2056 err
= send_key_to_dongle(ifp
, &key
);
2058 brcmf_err("key delete error (%d)\n", err
);
2060 if (key
.len
> sizeof(key
.data
)) {
2061 brcmf_err("Invalid key length (%d)\n", key
.len
);
2065 brcmf_dbg(CONN
, "Setting the key index %d\n", key
.index
);
2066 memcpy(key
.data
, params
->key
, key
.len
);
2068 if (!brcmf_is_apmode(ifp
->vif
) &&
2069 (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)) {
2070 brcmf_dbg(CONN
, "Swapping RX/TX MIC key\n");
2071 memcpy(keybuf
, &key
.data
[24], sizeof(keybuf
));
2072 memcpy(&key
.data
[24], &key
.data
[16], sizeof(keybuf
));
2073 memcpy(&key
.data
[16], keybuf
, sizeof(keybuf
));
2076 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
2077 if (params
->seq
&& params
->seq_len
== 6) {
2080 ivptr
= (u8
*) params
->seq
;
2081 key
.rxiv
.hi
= (ivptr
[5] << 24) | (ivptr
[4] << 16) |
2082 (ivptr
[3] << 8) | ivptr
[2];
2083 key
.rxiv
.lo
= (ivptr
[1] << 8) | ivptr
[0];
2084 key
.iv_initialized
= true;
2087 switch (params
->cipher
) {
2088 case WLAN_CIPHER_SUITE_WEP40
:
2089 key
.algo
= CRYPTO_ALGO_WEP1
;
2090 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP40\n");
2092 case WLAN_CIPHER_SUITE_WEP104
:
2093 key
.algo
= CRYPTO_ALGO_WEP128
;
2094 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP104\n");
2096 case WLAN_CIPHER_SUITE_TKIP
:
2097 key
.algo
= CRYPTO_ALGO_TKIP
;
2098 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_TKIP\n");
2100 case WLAN_CIPHER_SUITE_AES_CMAC
:
2101 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2102 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2104 case WLAN_CIPHER_SUITE_CCMP
:
2105 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2106 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_CCMP\n");
2109 brcmf_err("Invalid cipher (0x%x)\n", params
->cipher
);
2112 err
= send_key_to_dongle(ifp
, &key
);
2114 brcmf_err("wsec_key error (%d)\n", err
);
2120 brcmf_cfg80211_add_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2121 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
2122 struct key_params
*params
)
2124 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2125 struct brcmf_wsec_key
*key
;
2131 brcmf_dbg(TRACE
, "Enter\n");
2132 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2133 if (!check_vif_up(ifp
->vif
))
2136 if (key_idx
>= BRCMF_MAX_DEFAULT_KEYS
) {
2137 /* we ignore this key index in this case */
2138 brcmf_err("invalid key index (%d)\n", key_idx
);
2143 (params
->cipher
!= WLAN_CIPHER_SUITE_WEP40
) &&
2144 (params
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)) {
2145 brcmf_dbg(TRACE
, "Exit");
2146 return brcmf_add_keyext(wiphy
, ndev
, key_idx
, mac_addr
, params
);
2149 key
= &ifp
->vif
->profile
.key
[key_idx
];
2150 memset(key
, 0, sizeof(*key
));
2152 if (params
->key_len
> sizeof(key
->data
)) {
2153 brcmf_err("Too long key length (%u)\n", params
->key_len
);
2157 key
->len
= params
->key_len
;
2158 key
->index
= key_idx
;
2160 memcpy(key
->data
, params
->key
, key
->len
);
2162 key
->flags
= BRCMF_PRIMARY_KEY
;
2163 switch (params
->cipher
) {
2164 case WLAN_CIPHER_SUITE_WEP40
:
2165 key
->algo
= CRYPTO_ALGO_WEP1
;
2167 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP40\n");
2169 case WLAN_CIPHER_SUITE_WEP104
:
2170 key
->algo
= CRYPTO_ALGO_WEP128
;
2172 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP104\n");
2174 case WLAN_CIPHER_SUITE_TKIP
:
2175 if (!brcmf_is_apmode(ifp
->vif
)) {
2176 brcmf_dbg(CONN
, "Swapping RX/TX MIC key\n");
2177 memcpy(keybuf
, &key
->data
[24], sizeof(keybuf
));
2178 memcpy(&key
->data
[24], &key
->data
[16], sizeof(keybuf
));
2179 memcpy(&key
->data
[16], keybuf
, sizeof(keybuf
));
2181 key
->algo
= CRYPTO_ALGO_TKIP
;
2183 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_TKIP\n");
2185 case WLAN_CIPHER_SUITE_AES_CMAC
:
2186 key
->algo
= CRYPTO_ALGO_AES_CCM
;
2188 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2190 case WLAN_CIPHER_SUITE_CCMP
:
2191 key
->algo
= CRYPTO_ALGO_AES_CCM
;
2193 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_CCMP\n");
2196 brcmf_err("Invalid cipher (0x%x)\n", params
->cipher
);
2201 err
= send_key_to_dongle(ifp
, key
);
2205 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
2207 brcmf_err("get wsec error (%d)\n", err
);
2211 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", wsec
);
2213 brcmf_err("set wsec error (%d)\n", err
);
2218 brcmf_dbg(TRACE
, "Exit\n");
2223 brcmf_cfg80211_del_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2224 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
2226 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2227 struct brcmf_wsec_key key
;
2230 brcmf_dbg(TRACE
, "Enter\n");
2231 if (!check_vif_up(ifp
->vif
))
2234 if (key_idx
>= BRCMF_MAX_DEFAULT_KEYS
) {
2235 /* we ignore this key index in this case */
2236 brcmf_err("invalid key index (%d)\n", key_idx
);
2240 memset(&key
, 0, sizeof(key
));
2242 key
.index
= (u32
) key_idx
;
2243 key
.flags
= BRCMF_PRIMARY_KEY
;
2244 key
.algo
= CRYPTO_ALGO_OFF
;
2246 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2248 /* Set the new key/index */
2249 err
= send_key_to_dongle(ifp
, &key
);
2251 brcmf_dbg(TRACE
, "Exit\n");
2256 brcmf_cfg80211_get_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2257 u8 key_idx
, bool pairwise
, const u8
*mac_addr
, void *cookie
,
2258 void (*callback
) (void *cookie
, struct key_params
* params
))
2260 struct key_params params
;
2261 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2262 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
2263 struct brcmf_cfg80211_security
*sec
;
2267 brcmf_dbg(TRACE
, "Enter\n");
2268 brcmf_dbg(CONN
, "key index (%d)\n", key_idx
);
2269 if (!check_vif_up(ifp
->vif
))
2272 memset(¶ms
, 0, sizeof(params
));
2274 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
2276 brcmf_err("WLC_GET_WSEC error (%d)\n", err
);
2277 /* Ignore this error, may happen during DISASSOC */
2281 if (wsec
& WEP_ENABLED
) {
2282 sec
= &profile
->sec
;
2283 if (sec
->cipher_pairwise
& WLAN_CIPHER_SUITE_WEP40
) {
2284 params
.cipher
= WLAN_CIPHER_SUITE_WEP40
;
2285 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP40\n");
2286 } else if (sec
->cipher_pairwise
& WLAN_CIPHER_SUITE_WEP104
) {
2287 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
2288 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_WEP104\n");
2290 } else if (wsec
& TKIP_ENABLED
) {
2291 params
.cipher
= WLAN_CIPHER_SUITE_TKIP
;
2292 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_TKIP\n");
2293 } else if (wsec
& AES_ENABLED
) {
2294 params
.cipher
= WLAN_CIPHER_SUITE_AES_CMAC
;
2295 brcmf_dbg(CONN
, "WLAN_CIPHER_SUITE_AES_CMAC\n");
2297 brcmf_err("Invalid algo (0x%x)\n", wsec
);
2301 callback(cookie
, ¶ms
);
2304 brcmf_dbg(TRACE
, "Exit\n");
2309 brcmf_cfg80211_config_default_mgmt_key(struct wiphy
*wiphy
,
2310 struct net_device
*ndev
, u8 key_idx
)
2312 brcmf_dbg(INFO
, "Not supported\n");
2318 brcmf_cfg80211_reconfigure_wep(struct brcmf_if
*ifp
)
2322 struct brcmf_wsec_key
*key
;
2325 for (key_idx
= 0; key_idx
< BRCMF_MAX_DEFAULT_KEYS
; key_idx
++) {
2326 key
= &ifp
->vif
->profile
.key
[key_idx
];
2327 if ((key
->algo
== CRYPTO_ALGO_WEP1
) ||
2328 (key
->algo
== CRYPTO_ALGO_WEP128
))
2331 if (key_idx
== BRCMF_MAX_DEFAULT_KEYS
)
2334 err
= send_key_to_dongle(ifp
, key
);
2336 brcmf_err("Setting WEP key failed (%d)\n", err
);
2339 err
= brcmf_fil_bsscfg_int_get(ifp
, "wsec", &wsec
);
2341 brcmf_err("get wsec error (%d)\n", err
);
2344 wsec
|= WEP_ENABLED
;
2345 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", wsec
);
2347 brcmf_err("set wsec error (%d)\n", err
);
2351 brcmf_cfg80211_get_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
2352 const u8
*mac
, struct station_info
*sinfo
)
2354 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2355 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
2356 struct brcmf_scb_val_le scb_val
;
2360 u8
*bssid
= profile
->bssid
;
2361 struct brcmf_sta_info_le sta_info_le
;
2365 brcmf_dbg(TRACE
, "Enter, MAC %pM\n", mac
);
2366 if (!check_vif_up(ifp
->vif
))
2369 if (brcmf_is_apmode(ifp
->vif
)) {
2370 memcpy(&sta_info_le
, mac
, ETH_ALEN
);
2371 err
= brcmf_fil_iovar_data_get(ifp
, "sta_info",
2373 sizeof(sta_info_le
));
2375 brcmf_err("GET STA INFO failed, %d\n", err
);
2378 sinfo
->filled
= BIT(NL80211_STA_INFO_INACTIVE_TIME
);
2379 sinfo
->inactive_time
= le32_to_cpu(sta_info_le
.idle
) * 1000;
2380 if (le32_to_cpu(sta_info_le
.flags
) & BRCMF_STA_ASSOC
) {
2381 sinfo
->filled
|= BIT(NL80211_STA_INFO_CONNECTED_TIME
);
2382 sinfo
->connected_time
= le32_to_cpu(sta_info_le
.in
);
2384 brcmf_dbg(TRACE
, "STA idle time : %d ms, connected time :%d sec\n",
2385 sinfo
->inactive_time
, sinfo
->connected_time
);
2386 } else if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_STATION
) {
2387 if (memcmp(mac
, bssid
, ETH_ALEN
)) {
2388 brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
2393 /* Report the current tx rate */
2394 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_RATE
, &rate
);
2396 brcmf_err("Could not get rate (%d)\n", err
);
2399 sinfo
->filled
|= BIT(NL80211_STA_INFO_TX_BITRATE
);
2400 sinfo
->txrate
.legacy
= rate
* 5;
2401 brcmf_dbg(CONN
, "Rate %d Mbps\n", rate
/ 2);
2404 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
,
2405 &ifp
->vif
->sme_state
)) {
2406 memset(&scb_val
, 0, sizeof(scb_val
));
2407 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_RSSI
,
2408 &scb_val
, sizeof(scb_val
));
2410 brcmf_err("Could not get rssi (%d)\n", err
);
2413 rssi
= le32_to_cpu(scb_val
.val
);
2414 sinfo
->filled
|= BIT(NL80211_STA_INFO_SIGNAL
);
2415 sinfo
->signal
= rssi
;
2416 brcmf_dbg(CONN
, "RSSI %d dBm\n", rssi
);
2418 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_BCNPRD
,
2421 brcmf_err("Could not get beacon period (%d)\n",
2425 sinfo
->bss_param
.beacon_interval
=
2427 brcmf_dbg(CONN
, "Beacon peroid %d\n",
2430 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_DTIMPRD
,
2433 brcmf_err("Could not get DTIM period (%d)\n",
2437 sinfo
->bss_param
.dtim_period
= dtim_period
;
2438 brcmf_dbg(CONN
, "DTIM peroid %d\n",
2441 sinfo
->filled
|= BIT(NL80211_STA_INFO_BSS_PARAM
);
2446 brcmf_dbg(TRACE
, "Exit\n");
2451 brcmf_cfg80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*ndev
,
2452 bool enabled
, s32 timeout
)
2456 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2457 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2459 brcmf_dbg(TRACE
, "Enter\n");
2462 * Powersave enable/disable request is coming from the
2463 * cfg80211 even before the interface is up. In that
2464 * scenario, driver will be storing the power save
2465 * preference in cfg struct to apply this to
2466 * FW later while initializing the dongle
2468 cfg
->pwr_save
= enabled
;
2469 if (!check_vif_up(ifp
->vif
)) {
2471 brcmf_dbg(INFO
, "Device is not ready, storing the value in cfg_info struct\n");
2475 pm
= enabled
? PM_FAST
: PM_OFF
;
2476 /* Do not enable the power save after assoc if it is a p2p interface */
2477 if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_P2P_CLIENT
) {
2478 brcmf_dbg(INFO
, "Do not enable power save for P2P clients\n");
2481 brcmf_dbg(INFO
, "power save %s\n", (pm
? "enabled" : "disabled"));
2483 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, pm
);
2486 brcmf_err("net_device is not ready yet\n");
2488 brcmf_err("error (%d)\n", err
);
2491 brcmf_dbg(TRACE
, "Exit\n");
2495 static s32
brcmf_inform_single_bss(struct brcmf_cfg80211_info
*cfg
,
2496 struct brcmf_bss_info_le
*bi
)
2498 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
2499 struct ieee80211_channel
*notify_channel
;
2500 struct cfg80211_bss
*bss
;
2501 struct ieee80211_supported_band
*band
;
2502 struct brcmu_chan ch
;
2505 u16 notify_capability
;
2506 u16 notify_interval
;
2508 size_t notify_ielen
;
2511 if (le32_to_cpu(bi
->length
) > WL_BSS_INFO_MAX
) {
2512 brcmf_err("Bss info is larger than buffer. Discarding\n");
2517 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
2518 cfg
->d11inf
.decchspec(&ch
);
2519 bi
->ctl_ch
= ch
.chnum
;
2521 channel
= bi
->ctl_ch
;
2523 if (channel
<= CH_MAX_2G_CHANNEL
)
2524 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2526 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2528 freq
= ieee80211_channel_to_frequency(channel
, band
->band
);
2529 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
2531 notify_capability
= le16_to_cpu(bi
->capability
);
2532 notify_interval
= le16_to_cpu(bi
->beacon_period
);
2533 notify_ie
= (u8
*)bi
+ le16_to_cpu(bi
->ie_offset
);
2534 notify_ielen
= le32_to_cpu(bi
->ie_length
);
2535 notify_signal
= (s16
)le16_to_cpu(bi
->RSSI
) * 100;
2537 brcmf_dbg(CONN
, "bssid: %pM\n", bi
->BSSID
);
2538 brcmf_dbg(CONN
, "Channel: %d(%d)\n", channel
, freq
);
2539 brcmf_dbg(CONN
, "Capability: %X\n", notify_capability
);
2540 brcmf_dbg(CONN
, "Beacon interval: %d\n", notify_interval
);
2541 brcmf_dbg(CONN
, "Signal: %d\n", notify_signal
);
2543 bss
= cfg80211_inform_bss(wiphy
, notify_channel
,
2544 CFG80211_BSS_FTYPE_UNKNOWN
,
2545 (const u8
*)bi
->BSSID
,
2546 0, notify_capability
,
2547 notify_interval
, notify_ie
,
2548 notify_ielen
, notify_signal
,
2554 cfg80211_put_bss(wiphy
, bss
);
2559 static struct brcmf_bss_info_le
*
2560 next_bss_le(struct brcmf_scan_results
*list
, struct brcmf_bss_info_le
*bss
)
2563 return list
->bss_info_le
;
2564 return (struct brcmf_bss_info_le
*)((unsigned long)bss
+
2565 le32_to_cpu(bss
->length
));
2568 static s32
brcmf_inform_bss(struct brcmf_cfg80211_info
*cfg
)
2570 struct brcmf_scan_results
*bss_list
;
2571 struct brcmf_bss_info_le
*bi
= NULL
; /* must be initialized */
2575 bss_list
= (struct brcmf_scan_results
*)cfg
->escan_info
.escan_buf
;
2576 if (bss_list
->count
!= 0 &&
2577 bss_list
->version
!= BRCMF_BSS_INFO_VERSION
) {
2578 brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
2582 brcmf_dbg(SCAN
, "scanned AP count (%d)\n", bss_list
->count
);
2583 for (i
= 0; i
< bss_list
->count
; i
++) {
2584 bi
= next_bss_le(bss_list
, bi
);
2585 err
= brcmf_inform_single_bss(cfg
, bi
);
2592 static s32
wl_inform_ibss(struct brcmf_cfg80211_info
*cfg
,
2593 struct net_device
*ndev
, const u8
*bssid
)
2595 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
2596 struct ieee80211_channel
*notify_channel
;
2597 struct brcmf_bss_info_le
*bi
= NULL
;
2598 struct ieee80211_supported_band
*band
;
2599 struct cfg80211_bss
*bss
;
2600 struct brcmu_chan ch
;
2604 u16 notify_capability
;
2605 u16 notify_interval
;
2607 size_t notify_ielen
;
2610 brcmf_dbg(TRACE
, "Enter\n");
2612 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
2618 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
2620 err
= brcmf_fil_cmd_data_get(netdev_priv(ndev
), BRCMF_C_GET_BSS_INFO
,
2621 buf
, WL_BSS_INFO_MAX
);
2623 brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err
);
2627 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
2629 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
2630 cfg
->d11inf
.decchspec(&ch
);
2632 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
2633 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2635 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2637 freq
= ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
2638 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
2640 notify_capability
= le16_to_cpu(bi
->capability
);
2641 notify_interval
= le16_to_cpu(bi
->beacon_period
);
2642 notify_ie
= (u8
*)bi
+ le16_to_cpu(bi
->ie_offset
);
2643 notify_ielen
= le32_to_cpu(bi
->ie_length
);
2644 notify_signal
= (s16
)le16_to_cpu(bi
->RSSI
) * 100;
2646 brcmf_dbg(CONN
, "channel: %d(%d)\n", ch
.chnum
, freq
);
2647 brcmf_dbg(CONN
, "capability: %X\n", notify_capability
);
2648 brcmf_dbg(CONN
, "beacon interval: %d\n", notify_interval
);
2649 brcmf_dbg(CONN
, "signal: %d\n", notify_signal
);
2651 bss
= cfg80211_inform_bss(wiphy
, notify_channel
,
2652 CFG80211_BSS_FTYPE_UNKNOWN
, bssid
, 0,
2653 notify_capability
, notify_interval
,
2654 notify_ie
, notify_ielen
, notify_signal
,
2662 cfg80211_put_bss(wiphy
, bss
);
2668 brcmf_dbg(TRACE
, "Exit\n");
2673 static s32
brcmf_update_bss_info(struct brcmf_cfg80211_info
*cfg
,
2674 struct brcmf_if
*ifp
)
2676 struct brcmf_cfg80211_profile
*profile
= ndev_to_prof(ifp
->ndev
);
2677 struct brcmf_bss_info_le
*bi
;
2678 struct brcmf_ssid
*ssid
;
2679 const struct brcmf_tlv
*tim
;
2680 u16 beacon_interval
;
2686 brcmf_dbg(TRACE
, "Enter\n");
2687 if (brcmf_is_ibssmode(ifp
->vif
))
2690 ssid
= &profile
->ssid
;
2692 *(__le32
*)cfg
->extra_buf
= cpu_to_le32(WL_EXTRA_BUF_MAX
);
2693 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
2694 cfg
->extra_buf
, WL_EXTRA_BUF_MAX
);
2696 brcmf_err("Could not get bss info %d\n", err
);
2697 goto update_bss_info_out
;
2700 bi
= (struct brcmf_bss_info_le
*)(cfg
->extra_buf
+ 4);
2701 err
= brcmf_inform_single_bss(cfg
, bi
);
2703 goto update_bss_info_out
;
2705 ie
= ((u8
*)bi
) + le16_to_cpu(bi
->ie_offset
);
2706 ie_len
= le32_to_cpu(bi
->ie_length
);
2707 beacon_interval
= le16_to_cpu(bi
->beacon_period
);
2709 tim
= brcmf_parse_tlvs(ie
, ie_len
, WLAN_EID_TIM
);
2711 dtim_period
= tim
->data
[1];
2714 * active scan was done so we could not get dtim
2715 * information out of probe response.
2716 * so we speficially query dtim information to dongle.
2719 err
= brcmf_fil_iovar_int_get(ifp
, "dtim_assoc", &var
);
2721 brcmf_err("wl dtim_assoc failed (%d)\n", err
);
2722 goto update_bss_info_out
;
2724 dtim_period
= (u8
)var
;
2727 update_bss_info_out
:
2728 brcmf_dbg(TRACE
, "Exit");
2732 void brcmf_abort_scanning(struct brcmf_cfg80211_info
*cfg
)
2734 struct escan_info
*escan
= &cfg
->escan_info
;
2736 set_bit(BRCMF_SCAN_STATUS_ABORT
, &cfg
->scan_status
);
2737 if (cfg
->scan_request
) {
2738 escan
->escan_state
= WL_ESCAN_STATE_IDLE
;
2739 brcmf_notify_escan_complete(cfg
, escan
->ifp
, true, true);
2741 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
2742 clear_bit(BRCMF_SCAN_STATUS_ABORT
, &cfg
->scan_status
);
2745 static void brcmf_cfg80211_escan_timeout_worker(struct work_struct
*work
)
2747 struct brcmf_cfg80211_info
*cfg
=
2748 container_of(work
, struct brcmf_cfg80211_info
,
2749 escan_timeout_work
);
2751 brcmf_inform_bss(cfg
);
2752 brcmf_notify_escan_complete(cfg
, cfg
->escan_info
.ifp
, true, true);
2755 static void brcmf_escan_timeout(unsigned long data
)
2757 struct brcmf_cfg80211_info
*cfg
=
2758 (struct brcmf_cfg80211_info
*)data
;
2760 if (cfg
->scan_request
) {
2761 brcmf_err("timer expired\n");
2762 schedule_work(&cfg
->escan_timeout_work
);
2767 brcmf_compare_update_same_bss(struct brcmf_cfg80211_info
*cfg
,
2768 struct brcmf_bss_info_le
*bss
,
2769 struct brcmf_bss_info_le
*bss_info_le
)
2771 struct brcmu_chan ch_bss
, ch_bss_info_le
;
2773 ch_bss
.chspec
= le16_to_cpu(bss
->chanspec
);
2774 cfg
->d11inf
.decchspec(&ch_bss
);
2775 ch_bss_info_le
.chspec
= le16_to_cpu(bss_info_le
->chanspec
);
2776 cfg
->d11inf
.decchspec(&ch_bss_info_le
);
2778 if (!memcmp(&bss_info_le
->BSSID
, &bss
->BSSID
, ETH_ALEN
) &&
2779 ch_bss
.band
== ch_bss_info_le
.band
&&
2780 bss_info_le
->SSID_len
== bss
->SSID_len
&&
2781 !memcmp(bss_info_le
->SSID
, bss
->SSID
, bss_info_le
->SSID_len
)) {
2782 if ((bss
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
) ==
2783 (bss_info_le
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
)) {
2784 s16 bss_rssi
= le16_to_cpu(bss
->RSSI
);
2785 s16 bss_info_rssi
= le16_to_cpu(bss_info_le
->RSSI
);
2787 /* preserve max RSSI if the measurements are
2788 * both on-channel or both off-channel
2790 if (bss_info_rssi
> bss_rssi
)
2791 bss
->RSSI
= bss_info_le
->RSSI
;
2792 } else if ((bss
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
) &&
2793 (bss_info_le
->flags
& BRCMF_BSS_RSSI_ON_CHANNEL
) == 0) {
2794 /* preserve the on-channel rssi measurement
2795 * if the new measurement is off channel
2797 bss
->RSSI
= bss_info_le
->RSSI
;
2798 bss
->flags
|= BRCMF_BSS_RSSI_ON_CHANNEL
;
2806 brcmf_cfg80211_escan_handler(struct brcmf_if
*ifp
,
2807 const struct brcmf_event_msg
*e
, void *data
)
2809 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
2811 struct brcmf_escan_result_le
*escan_result_le
;
2812 struct brcmf_bss_info_le
*bss_info_le
;
2813 struct brcmf_bss_info_le
*bss
= NULL
;
2815 struct brcmf_scan_results
*list
;
2821 if (!test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
2822 brcmf_err("scan not ready, bssidx=%d\n", ifp
->bssidx
);
2826 if (status
== BRCMF_E_STATUS_PARTIAL
) {
2827 brcmf_dbg(SCAN
, "ESCAN Partial result\n");
2828 escan_result_le
= (struct brcmf_escan_result_le
*) data
;
2829 if (!escan_result_le
) {
2830 brcmf_err("Invalid escan result (NULL pointer)\n");
2833 if (le16_to_cpu(escan_result_le
->bss_count
) != 1) {
2834 brcmf_err("Invalid bss_count %d: ignoring\n",
2835 escan_result_le
->bss_count
);
2838 bss_info_le
= &escan_result_le
->bss_info_le
;
2840 if (brcmf_p2p_scan_finding_common_channel(cfg
, bss_info_le
))
2843 if (!cfg
->scan_request
) {
2844 brcmf_dbg(SCAN
, "result without cfg80211 request\n");
2848 bi_length
= le32_to_cpu(bss_info_le
->length
);
2849 if (bi_length
!= (le32_to_cpu(escan_result_le
->buflen
) -
2850 WL_ESCAN_RESULTS_FIXED_SIZE
)) {
2851 brcmf_err("Invalid bss_info length %d: ignoring\n",
2856 if (!(cfg_to_wiphy(cfg
)->interface_modes
&
2857 BIT(NL80211_IFTYPE_ADHOC
))) {
2858 if (le16_to_cpu(bss_info_le
->capability
) &
2859 WLAN_CAPABILITY_IBSS
) {
2860 brcmf_err("Ignoring IBSS result\n");
2865 list
= (struct brcmf_scan_results
*)
2866 cfg
->escan_info
.escan_buf
;
2867 if (bi_length
> WL_ESCAN_BUF_SIZE
- list
->buflen
) {
2868 brcmf_err("Buffer is too small: ignoring\n");
2872 for (i
= 0; i
< list
->count
; i
++) {
2873 bss
= bss
? (struct brcmf_bss_info_le
*)
2874 ((unsigned char *)bss
+
2875 le32_to_cpu(bss
->length
)) : list
->bss_info_le
;
2876 if (brcmf_compare_update_same_bss(cfg
, bss
,
2880 memcpy(&(cfg
->escan_info
.escan_buf
[list
->buflen
]),
2881 bss_info_le
, bi_length
);
2882 list
->version
= le32_to_cpu(bss_info_le
->version
);
2883 list
->buflen
+= bi_length
;
2886 cfg
->escan_info
.escan_state
= WL_ESCAN_STATE_IDLE
;
2887 if (brcmf_p2p_scan_finding_common_channel(cfg
, NULL
))
2889 if (cfg
->scan_request
) {
2890 brcmf_inform_bss(cfg
);
2891 aborted
= status
!= BRCMF_E_STATUS_SUCCESS
;
2892 brcmf_notify_escan_complete(cfg
, ifp
, aborted
, false);
2894 brcmf_dbg(SCAN
, "Ignored scan complete result 0x%x\n",
2901 static void brcmf_init_escan(struct brcmf_cfg80211_info
*cfg
)
2903 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ESCAN_RESULT
,
2904 brcmf_cfg80211_escan_handler
);
2905 cfg
->escan_info
.escan_state
= WL_ESCAN_STATE_IDLE
;
2906 /* Init scan_timeout timer */
2907 init_timer(&cfg
->escan_timeout
);
2908 cfg
->escan_timeout
.data
= (unsigned long) cfg
;
2909 cfg
->escan_timeout
.function
= brcmf_escan_timeout
;
2910 INIT_WORK(&cfg
->escan_timeout_work
,
2911 brcmf_cfg80211_escan_timeout_worker
);
2914 static __always_inline
void brcmf_delay(u32 ms
)
2916 if (ms
< 1000 / HZ
) {
2924 static s32
brcmf_config_wowl_pattern(struct brcmf_if
*ifp
, u8 cmd
[4],
2925 u8
*pattern
, u32 patternsize
, u8
*mask
,
2928 struct brcmf_fil_wowl_pattern_le
*filter
;
2935 masksize
= (patternsize
+ 7) / 8;
2936 patternoffset
= sizeof(*filter
) - sizeof(filter
->cmd
) + masksize
;
2938 bufsize
= sizeof(*filter
) + patternsize
+ masksize
;
2939 buf
= kzalloc(bufsize
, GFP_KERNEL
);
2942 filter
= (struct brcmf_fil_wowl_pattern_le
*)buf
;
2944 memcpy(filter
->cmd
, cmd
, 4);
2945 filter
->masksize
= cpu_to_le32(masksize
);
2946 filter
->offset
= cpu_to_le32(packet_offset
);
2947 filter
->patternoffset
= cpu_to_le32(patternoffset
);
2948 filter
->patternsize
= cpu_to_le32(patternsize
);
2949 filter
->type
= cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP
);
2951 if ((mask
) && (masksize
))
2952 memcpy(buf
+ sizeof(*filter
), mask
, masksize
);
2953 if ((pattern
) && (patternsize
))
2954 memcpy(buf
+ sizeof(*filter
) + masksize
, pattern
, patternsize
);
2956 ret
= brcmf_fil_iovar_data_set(ifp
, "wowl_pattern", buf
, bufsize
);
2962 static s32
brcmf_cfg80211_resume(struct wiphy
*wiphy
)
2964 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
2965 struct net_device
*ndev
= cfg_to_ndev(cfg
);
2966 struct brcmf_if
*ifp
= netdev_priv(ndev
);
2968 brcmf_dbg(TRACE
, "Enter\n");
2970 if (cfg
->wowl_enabled
) {
2971 brcmf_configure_arp_offload(ifp
, true);
2972 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
,
2973 cfg
->pre_wowl_pmmode
);
2974 brcmf_fil_iovar_int_set(ifp
, "wowl_clear", 0);
2975 brcmf_config_wowl_pattern(ifp
, "clr", NULL
, 0, NULL
, 0);
2976 cfg
->wowl_enabled
= false;
2981 static void brcmf_configure_wowl(struct brcmf_cfg80211_info
*cfg
,
2982 struct brcmf_if
*ifp
,
2983 struct cfg80211_wowlan
*wowl
)
2988 brcmf_dbg(TRACE
, "Suspend, wowl config.\n");
2990 brcmf_configure_arp_offload(ifp
, false);
2991 brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_PM
, &cfg
->pre_wowl_pmmode
);
2992 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, PM_MAX
);
2995 if (wowl
->disconnect
)
2996 wowl_config
= BRCMF_WOWL_DIS
| BRCMF_WOWL_BCN
| BRCMF_WOWL_RETR
;
2997 if (wowl
->magic_pkt
)
2998 wowl_config
|= BRCMF_WOWL_MAGIC
;
2999 if ((wowl
->patterns
) && (wowl
->n_patterns
)) {
3000 wowl_config
|= BRCMF_WOWL_NET
;
3001 for (i
= 0; i
< wowl
->n_patterns
; i
++) {
3002 brcmf_config_wowl_pattern(ifp
, "add",
3003 (u8
*)wowl
->patterns
[i
].pattern
,
3004 wowl
->patterns
[i
].pattern_len
,
3005 (u8
*)wowl
->patterns
[i
].mask
,
3006 wowl
->patterns
[i
].pkt_offset
);
3009 brcmf_fil_iovar_int_set(ifp
, "wowl", wowl_config
);
3010 brcmf_fil_iovar_int_set(ifp
, "wowl_activate", 1);
3011 brcmf_bus_wowl_config(cfg
->pub
->bus_if
, true);
3012 cfg
->wowl_enabled
= true;
3015 static s32
brcmf_cfg80211_suspend(struct wiphy
*wiphy
,
3016 struct cfg80211_wowlan
*wowl
)
3018 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3019 struct net_device
*ndev
= cfg_to_ndev(cfg
);
3020 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3021 struct brcmf_cfg80211_vif
*vif
;
3023 brcmf_dbg(TRACE
, "Enter\n");
3025 /* if the primary net_device is not READY there is nothing
3026 * we can do but pray resume goes smoothly.
3028 if (!check_vif_up(ifp
->vif
))
3031 /* end any scanning */
3032 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
3033 brcmf_abort_scanning(cfg
);
3036 brcmf_bus_wowl_config(cfg
->pub
->bus_if
, false);
3037 list_for_each_entry(vif
, &cfg
->vif_list
, list
) {
3038 if (!test_bit(BRCMF_VIF_STATUS_READY
, &vif
->sme_state
))
3040 /* While going to suspend if associated with AP
3041 * disassociate from AP to save power while system is
3042 * in suspended state
3044 brcmf_link_down(vif
);
3045 /* Make sure WPA_Supplicant receives all the event
3046 * generated due to DISASSOC call to the fw to keep
3047 * the state fw and WPA_Supplicant state consistent
3052 brcmf_set_mpc(ifp
, 1);
3055 /* Configure WOWL paramaters */
3056 brcmf_configure_wowl(cfg
, ifp
, wowl
);
3060 brcmf_dbg(TRACE
, "Exit\n");
3061 /* clear any scanning activity */
3062 cfg
->scan_status
= 0;
3067 brcmf_update_pmklist(struct net_device
*ndev
,
3068 struct brcmf_cfg80211_pmk_list
*pmk_list
, s32 err
)
3073 pmkid_len
= le32_to_cpu(pmk_list
->pmkids
.npmkid
);
3075 brcmf_dbg(CONN
, "No of elements %d\n", pmkid_len
);
3076 for (i
= 0; i
< pmkid_len
; i
++) {
3077 brcmf_dbg(CONN
, "PMKID[%d]: %pM =\n", i
,
3078 &pmk_list
->pmkids
.pmkid
[i
].BSSID
);
3079 for (j
= 0; j
< WLAN_PMKID_LEN
; j
++)
3080 brcmf_dbg(CONN
, "%02x\n",
3081 pmk_list
->pmkids
.pmkid
[i
].PMKID
[j
]);
3085 brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pmkid_info",
3086 (char *)pmk_list
, sizeof(*pmk_list
));
3092 brcmf_cfg80211_set_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
3093 struct cfg80211_pmksa
*pmksa
)
3095 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3096 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3097 struct pmkid_list
*pmkids
= &cfg
->pmk_list
->pmkids
;
3101 brcmf_dbg(TRACE
, "Enter\n");
3102 if (!check_vif_up(ifp
->vif
))
3105 pmkid_len
= le32_to_cpu(pmkids
->npmkid
);
3106 for (i
= 0; i
< pmkid_len
; i
++)
3107 if (!memcmp(pmksa
->bssid
, pmkids
->pmkid
[i
].BSSID
, ETH_ALEN
))
3109 if (i
< WL_NUM_PMKIDS_MAX
) {
3110 memcpy(pmkids
->pmkid
[i
].BSSID
, pmksa
->bssid
, ETH_ALEN
);
3111 memcpy(pmkids
->pmkid
[i
].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
3112 if (i
== pmkid_len
) {
3114 pmkids
->npmkid
= cpu_to_le32(pmkid_len
);
3119 brcmf_dbg(CONN
, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
3120 pmkids
->pmkid
[pmkid_len
].BSSID
);
3121 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
3122 brcmf_dbg(CONN
, "%02x\n", pmkids
->pmkid
[pmkid_len
].PMKID
[i
]);
3124 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3126 brcmf_dbg(TRACE
, "Exit\n");
3131 brcmf_cfg80211_del_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
3132 struct cfg80211_pmksa
*pmksa
)
3134 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3135 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3136 struct pmkid_list pmkid
;
3140 brcmf_dbg(TRACE
, "Enter\n");
3141 if (!check_vif_up(ifp
->vif
))
3144 memcpy(&pmkid
.pmkid
[0].BSSID
, pmksa
->bssid
, ETH_ALEN
);
3145 memcpy(&pmkid
.pmkid
[0].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
3147 brcmf_dbg(CONN
, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3148 &pmkid
.pmkid
[0].BSSID
);
3149 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
3150 brcmf_dbg(CONN
, "%02x\n", pmkid
.pmkid
[0].PMKID
[i
]);
3152 pmkid_len
= le32_to_cpu(cfg
->pmk_list
->pmkids
.npmkid
);
3153 for (i
= 0; i
< pmkid_len
; i
++)
3155 (pmksa
->bssid
, &cfg
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3160 && (i
< pmkid_len
)) {
3161 memset(&cfg
->pmk_list
->pmkids
.pmkid
[i
], 0,
3162 sizeof(struct pmkid
));
3163 for (; i
< (pmkid_len
- 1); i
++) {
3164 memcpy(&cfg
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3165 &cfg
->pmk_list
->pmkids
.pmkid
[i
+ 1].BSSID
,
3167 memcpy(&cfg
->pmk_list
->pmkids
.pmkid
[i
].PMKID
,
3168 &cfg
->pmk_list
->pmkids
.pmkid
[i
+ 1].PMKID
,
3171 cfg
->pmk_list
->pmkids
.npmkid
= cpu_to_le32(pmkid_len
- 1);
3175 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3177 brcmf_dbg(TRACE
, "Exit\n");
3183 brcmf_cfg80211_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
)
3185 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3186 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3189 brcmf_dbg(TRACE
, "Enter\n");
3190 if (!check_vif_up(ifp
->vif
))
3193 memset(cfg
->pmk_list
, 0, sizeof(*cfg
->pmk_list
));
3194 err
= brcmf_update_pmklist(ndev
, cfg
->pmk_list
, err
);
3196 brcmf_dbg(TRACE
, "Exit\n");
3202 * PFN result doesn't have all the info which are
3203 * required by the supplicant
3204 * (For e.g IEs) Do a target Escan so that sched scan results are reported
3205 * via wl_inform_single_bss in the required format. Escan does require the
3206 * scan request in the form of cfg80211_scan_request. For timebeing, create
3207 * cfg80211_scan_request one out of the received PNO event.
3210 brcmf_notify_sched_scan_results(struct brcmf_if
*ifp
,
3211 const struct brcmf_event_msg
*e
, void *data
)
3213 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
3214 struct brcmf_pno_net_info_le
*netinfo
, *netinfo_start
;
3215 struct cfg80211_scan_request
*request
= NULL
;
3216 struct cfg80211_ssid
*ssid
= NULL
;
3217 struct ieee80211_channel
*channel
= NULL
;
3218 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
3220 int channel_req
= 0;
3222 struct brcmf_pno_scanresults_le
*pfn_result
;
3226 brcmf_dbg(SCAN
, "Enter\n");
3228 if (e
->event_code
== BRCMF_E_PFN_NET_LOST
) {
3229 brcmf_dbg(SCAN
, "PFN NET LOST event. Do Nothing\n");
3233 pfn_result
= (struct brcmf_pno_scanresults_le
*)data
;
3234 result_count
= le32_to_cpu(pfn_result
->count
);
3235 status
= le32_to_cpu(pfn_result
->status
);
3238 * PFN event is limited to fit 512 bytes so we may get
3239 * multiple NET_FOUND events. For now place a warning here.
3241 WARN_ON(status
!= BRCMF_PNO_SCAN_COMPLETE
);
3242 brcmf_dbg(SCAN
, "PFN NET FOUND event. count: %d\n", result_count
);
3243 if (result_count
> 0) {
3246 request
= kzalloc(sizeof(*request
), GFP_KERNEL
);
3247 ssid
= kcalloc(result_count
, sizeof(*ssid
), GFP_KERNEL
);
3248 channel
= kcalloc(result_count
, sizeof(*channel
), GFP_KERNEL
);
3249 if (!request
|| !ssid
|| !channel
) {
3254 request
->wiphy
= wiphy
;
3255 data
+= sizeof(struct brcmf_pno_scanresults_le
);
3256 netinfo_start
= (struct brcmf_pno_net_info_le
*)data
;
3258 for (i
= 0; i
< result_count
; i
++) {
3259 netinfo
= &netinfo_start
[i
];
3261 brcmf_err("Invalid netinfo ptr. index: %d\n",
3267 brcmf_dbg(SCAN
, "SSID:%s Channel:%d\n",
3268 netinfo
->SSID
, netinfo
->channel
);
3269 memcpy(ssid
[i
].ssid
, netinfo
->SSID
, netinfo
->SSID_len
);
3270 ssid
[i
].ssid_len
= netinfo
->SSID_len
;
3273 channel_req
= netinfo
->channel
;
3274 if (channel_req
<= CH_MAX_2G_CHANNEL
)
3275 band
= NL80211_BAND_2GHZ
;
3277 band
= NL80211_BAND_5GHZ
;
3278 channel
[i
].center_freq
=
3279 ieee80211_channel_to_frequency(channel_req
,
3281 channel
[i
].band
= band
;
3282 channel
[i
].flags
|= IEEE80211_CHAN_NO_HT40
;
3283 request
->channels
[i
] = &channel
[i
];
3284 request
->n_channels
++;
3287 /* assign parsed ssid array */
3288 if (request
->n_ssids
)
3289 request
->ssids
= &ssid
[0];
3291 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
3292 /* Abort any on-going scan */
3293 brcmf_abort_scanning(cfg
);
3296 set_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
3297 cfg
->escan_info
.run
= brcmf_run_escan
;
3298 err
= brcmf_do_escan(cfg
, wiphy
, ifp
, request
);
3300 clear_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
);
3303 cfg
->sched_escan
= true;
3304 cfg
->scan_request
= request
;
3306 brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
3319 cfg80211_sched_scan_stopped(wiphy
);
3323 static int brcmf_dev_pno_clean(struct net_device
*ndev
)
3328 ret
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "pfn", 0);
3331 ret
= brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pfnclear",
3335 brcmf_err("failed code %d\n", ret
);
3340 static int brcmf_dev_pno_config(struct net_device
*ndev
)
3342 struct brcmf_pno_param_le pfn_param
;
3344 memset(&pfn_param
, 0, sizeof(pfn_param
));
3345 pfn_param
.version
= cpu_to_le32(BRCMF_PNO_VERSION
);
3347 /* set extra pno params */
3348 pfn_param
.flags
= cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT
);
3349 pfn_param
.repeat
= BRCMF_PNO_REPEAT
;
3350 pfn_param
.exp
= BRCMF_PNO_FREQ_EXPO_MAX
;
3352 /* set up pno scan fr */
3353 pfn_param
.scan_freq
= cpu_to_le32(BRCMF_PNO_TIME
);
3355 return brcmf_fil_iovar_data_set(netdev_priv(ndev
), "pfn_set",
3356 &pfn_param
, sizeof(pfn_param
));
3360 brcmf_cfg80211_sched_scan_start(struct wiphy
*wiphy
,
3361 struct net_device
*ndev
,
3362 struct cfg80211_sched_scan_request
*request
)
3364 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3365 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
3366 struct brcmf_pno_net_param_le pfn
;
3370 brcmf_dbg(SCAN
, "Enter n_match_sets:%d n_ssids:%d\n",
3371 request
->n_match_sets
, request
->n_ssids
);
3372 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
)) {
3373 brcmf_err("Scanning already: status (%lu)\n", cfg
->scan_status
);
3376 if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
)) {
3377 brcmf_err("Scanning suppressed: status (%lu)\n",
3382 if (!request
->n_ssids
|| !request
->n_match_sets
) {
3383 brcmf_dbg(SCAN
, "Invalid sched scan req!! n_ssids:%d\n",
3388 if (request
->n_ssids
> 0) {
3389 for (i
= 0; i
< request
->n_ssids
; i
++) {
3390 /* Active scan req for ssids */
3391 brcmf_dbg(SCAN
, ">>> Active scan req for ssid (%s)\n",
3392 request
->ssids
[i
].ssid
);
3395 * match_set ssids is a supert set of n_ssid list,
3396 * so we need not add these set seperately.
3401 if (request
->n_match_sets
> 0) {
3402 /* clean up everything */
3403 ret
= brcmf_dev_pno_clean(ndev
);
3405 brcmf_err("failed error=%d\n", ret
);
3410 ret
= brcmf_dev_pno_config(ndev
);
3412 brcmf_err("PNO setup failed!! ret=%d\n", ret
);
3416 /* configure each match set */
3417 for (i
= 0; i
< request
->n_match_sets
; i
++) {
3418 struct cfg80211_ssid
*ssid
;
3421 ssid
= &request
->match_sets
[i
].ssid
;
3422 ssid_len
= ssid
->ssid_len
;
3425 brcmf_err("skip broadcast ssid\n");
3428 pfn
.auth
= cpu_to_le32(WLAN_AUTH_OPEN
);
3429 pfn
.wpa_auth
= cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY
);
3430 pfn
.wsec
= cpu_to_le32(0);
3431 pfn
.infra
= cpu_to_le32(1);
3432 pfn
.flags
= cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT
);
3433 pfn
.ssid
.SSID_len
= cpu_to_le32(ssid_len
);
3434 memcpy(pfn
.ssid
.SSID
, ssid
->ssid
, ssid_len
);
3435 ret
= brcmf_fil_iovar_data_set(ifp
, "pfn_add", &pfn
,
3437 brcmf_dbg(SCAN
, ">>> PNO filter %s for ssid (%s)\n",
3438 ret
== 0 ? "set" : "failed", ssid
->ssid
);
3440 /* Enable the PNO */
3441 if (brcmf_fil_iovar_int_set(ifp
, "pfn", 1) < 0) {
3442 brcmf_err("PNO enable failed!! ret=%d\n", ret
);
3452 static int brcmf_cfg80211_sched_scan_stop(struct wiphy
*wiphy
,
3453 struct net_device
*ndev
)
3455 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3457 brcmf_dbg(SCAN
, "enter\n");
3458 brcmf_dev_pno_clean(ndev
);
3459 if (cfg
->sched_escan
)
3460 brcmf_notify_escan_complete(cfg
, netdev_priv(ndev
), true, true);
3464 static s32
brcmf_configure_opensecurity(struct brcmf_if
*ifp
)
3469 err
= brcmf_fil_bsscfg_int_set(ifp
, "auth", 0);
3471 brcmf_err("auth error %d\n", err
);
3475 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", 0);
3477 brcmf_err("wsec error %d\n", err
);
3480 /* set upper-layer auth */
3481 err
= brcmf_fil_bsscfg_int_set(ifp
, "wpa_auth", WPA_AUTH_NONE
);
3483 brcmf_err("wpa_auth error %d\n", err
);
3490 static bool brcmf_valid_wpa_oui(u8
*oui
, bool is_rsn_ie
)
3493 return (memcmp(oui
, RSN_OUI
, TLV_OUI_LEN
) == 0);
3495 return (memcmp(oui
, WPA_OUI
, TLV_OUI_LEN
) == 0);
3499 brcmf_configure_wpaie(struct brcmf_if
*ifp
,
3500 const struct brcmf_vs_tlv
*wpa_ie
,
3503 u32 auth
= 0; /* d11 open authentication */
3515 u32 wme_bss_disable
;
3517 brcmf_dbg(TRACE
, "Enter\n");
3521 len
= wpa_ie
->len
+ TLV_HDR_LEN
;
3522 data
= (u8
*)wpa_ie
;
3523 offset
= TLV_HDR_LEN
;
3525 offset
+= VS_IE_FIXED_HDR_LEN
;
3527 offset
+= WPA_IE_VERSION_LEN
;
3529 /* check for multicast cipher suite */
3530 if (offset
+ WPA_IE_MIN_OUI_LEN
> len
) {
3532 brcmf_err("no multicast cipher suite\n");
3536 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3538 brcmf_err("ivalid OUI\n");
3541 offset
+= TLV_OUI_LEN
;
3543 /* pick up multicast cipher */
3544 switch (data
[offset
]) {
3545 case WPA_CIPHER_NONE
:
3548 case WPA_CIPHER_WEP_40
:
3549 case WPA_CIPHER_WEP_104
:
3552 case WPA_CIPHER_TKIP
:
3553 gval
= TKIP_ENABLED
;
3555 case WPA_CIPHER_AES_CCM
:
3560 brcmf_err("Invalid multi cast cipher info\n");
3565 /* walk thru unicast cipher list and pick up what we recognize */
3566 count
= data
[offset
] + (data
[offset
+ 1] << 8);
3567 offset
+= WPA_IE_SUITE_COUNT_LEN
;
3568 /* Check for unicast suite(s) */
3569 if (offset
+ (WPA_IE_MIN_OUI_LEN
* count
) > len
) {
3571 brcmf_err("no unicast cipher suite\n");
3574 for (i
= 0; i
< count
; i
++) {
3575 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3577 brcmf_err("ivalid OUI\n");
3580 offset
+= TLV_OUI_LEN
;
3581 switch (data
[offset
]) {
3582 case WPA_CIPHER_NONE
:
3584 case WPA_CIPHER_WEP_40
:
3585 case WPA_CIPHER_WEP_104
:
3586 pval
|= WEP_ENABLED
;
3588 case WPA_CIPHER_TKIP
:
3589 pval
|= TKIP_ENABLED
;
3591 case WPA_CIPHER_AES_CCM
:
3592 pval
|= AES_ENABLED
;
3595 brcmf_err("Ivalid unicast security info\n");
3599 /* walk thru auth management suite list and pick up what we recognize */
3600 count
= data
[offset
] + (data
[offset
+ 1] << 8);
3601 offset
+= WPA_IE_SUITE_COUNT_LEN
;
3602 /* Check for auth key management suite(s) */
3603 if (offset
+ (WPA_IE_MIN_OUI_LEN
* count
) > len
) {
3605 brcmf_err("no auth key mgmt suite\n");
3608 for (i
= 0; i
< count
; i
++) {
3609 if (!brcmf_valid_wpa_oui(&data
[offset
], is_rsn_ie
)) {
3611 brcmf_err("ivalid OUI\n");
3614 offset
+= TLV_OUI_LEN
;
3615 switch (data
[offset
]) {
3617 brcmf_dbg(TRACE
, "RSN_AKM_NONE\n");
3618 wpa_auth
|= WPA_AUTH_NONE
;
3620 case RSN_AKM_UNSPECIFIED
:
3621 brcmf_dbg(TRACE
, "RSN_AKM_UNSPECIFIED\n");
3622 is_rsn_ie
? (wpa_auth
|= WPA2_AUTH_UNSPECIFIED
) :
3623 (wpa_auth
|= WPA_AUTH_UNSPECIFIED
);
3626 brcmf_dbg(TRACE
, "RSN_AKM_PSK\n");
3627 is_rsn_ie
? (wpa_auth
|= WPA2_AUTH_PSK
) :
3628 (wpa_auth
|= WPA_AUTH_PSK
);
3631 brcmf_err("Ivalid key mgmt info\n");
3637 wme_bss_disable
= 1;
3638 if ((offset
+ RSN_CAP_LEN
) <= len
) {
3639 rsn_cap
= data
[offset
] + (data
[offset
+ 1] << 8);
3640 if (rsn_cap
& RSN_CAP_PTK_REPLAY_CNTR_MASK
)
3641 wme_bss_disable
= 0;
3643 /* set wme_bss_disable to sync RSN Capabilities */
3644 err
= brcmf_fil_bsscfg_int_set(ifp
, "wme_bss_disable",
3647 brcmf_err("wme_bss_disable error %d\n", err
);
3651 /* FOR WPS , set SES_OW_ENABLED */
3652 wsec
= (pval
| gval
| SES_OW_ENABLED
);
3655 err
= brcmf_fil_bsscfg_int_set(ifp
, "auth", auth
);
3657 brcmf_err("auth error %d\n", err
);
3661 err
= brcmf_fil_bsscfg_int_set(ifp
, "wsec", wsec
);
3663 brcmf_err("wsec error %d\n", err
);
3666 /* set upper-layer auth */
3667 err
= brcmf_fil_bsscfg_int_set(ifp
, "wpa_auth", wpa_auth
);
3669 brcmf_err("wpa_auth error %d\n", err
);
3678 brcmf_parse_vndr_ies(const u8
*vndr_ie_buf
, u32 vndr_ie_len
,
3679 struct parsed_vndr_ies
*vndr_ies
)
3681 struct brcmf_vs_tlv
*vndrie
;
3682 struct brcmf_tlv
*ie
;
3683 struct parsed_vndr_ie_info
*parsed_info
;
3686 remaining_len
= (s32
)vndr_ie_len
;
3687 memset(vndr_ies
, 0, sizeof(*vndr_ies
));
3689 ie
= (struct brcmf_tlv
*)vndr_ie_buf
;
3691 if (ie
->id
!= WLAN_EID_VENDOR_SPECIFIC
)
3693 vndrie
= (struct brcmf_vs_tlv
*)ie
;
3694 /* len should be bigger than OUI length + one */
3695 if (vndrie
->len
< (VS_IE_FIXED_HDR_LEN
- TLV_HDR_LEN
+ 1)) {
3696 brcmf_err("invalid vndr ie. length is too small %d\n",
3700 /* if wpa or wme ie, do not add ie */
3701 if (!memcmp(vndrie
->oui
, (u8
*)WPA_OUI
, TLV_OUI_LEN
) &&
3702 ((vndrie
->oui_type
== WPA_OUI_TYPE
) ||
3703 (vndrie
->oui_type
== WME_OUI_TYPE
))) {
3704 brcmf_dbg(TRACE
, "Found WPA/WME oui. Do not add it\n");
3708 parsed_info
= &vndr_ies
->ie_info
[vndr_ies
->count
];
3710 /* save vndr ie information */
3711 parsed_info
->ie_ptr
= (char *)vndrie
;
3712 parsed_info
->ie_len
= vndrie
->len
+ TLV_HDR_LEN
;
3713 memcpy(&parsed_info
->vndrie
, vndrie
, sizeof(*vndrie
));
3717 brcmf_dbg(TRACE
, "** OUI %02x %02x %02x, type 0x%02x\n",
3718 parsed_info
->vndrie
.oui
[0],
3719 parsed_info
->vndrie
.oui
[1],
3720 parsed_info
->vndrie
.oui
[2],
3721 parsed_info
->vndrie
.oui_type
);
3723 if (vndr_ies
->count
>= VNDR_IE_PARSE_LIMIT
)
3726 remaining_len
-= (ie
->len
+ TLV_HDR_LEN
);
3727 if (remaining_len
<= TLV_HDR_LEN
)
3730 ie
= (struct brcmf_tlv
*)(((u8
*)ie
) + ie
->len
+
3737 brcmf_vndr_ie(u8
*iebuf
, s32 pktflag
, u8
*ie_ptr
, u32 ie_len
, s8
*add_del_cmd
)
3743 strncpy(iebuf
, add_del_cmd
, VNDR_IE_CMD_LEN
- 1);
3744 iebuf
[VNDR_IE_CMD_LEN
- 1] = '\0';
3746 iecount_le
= cpu_to_le32(1);
3747 memcpy(&iebuf
[VNDR_IE_COUNT_OFFSET
], &iecount_le
, sizeof(iecount_le
));
3749 pktflag_le
= cpu_to_le32(pktflag
);
3750 memcpy(&iebuf
[VNDR_IE_PKTFLAG_OFFSET
], &pktflag_le
, sizeof(pktflag_le
));
3752 memcpy(&iebuf
[VNDR_IE_VSIE_OFFSET
], ie_ptr
, ie_len
);
3754 return ie_len
+ VNDR_IE_HDR_SIZE
;
3757 s32
brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif
*vif
, s32 pktflag
,
3758 const u8
*vndr_ie_buf
, u32 vndr_ie_len
)
3760 struct brcmf_if
*ifp
;
3761 struct vif_saved_ie
*saved_ie
;
3765 u8
*mgmt_ie_buf
= NULL
;
3766 int mgmt_ie_buf_len
;
3768 u32 del_add_ie_buf_len
= 0;
3769 u32 total_ie_buf_len
= 0;
3770 u32 parsed_ie_buf_len
= 0;
3771 struct parsed_vndr_ies old_vndr_ies
;
3772 struct parsed_vndr_ies new_vndr_ies
;
3773 struct parsed_vndr_ie_info
*vndrie_info
;
3776 int remained_buf_len
;
3781 saved_ie
= &vif
->saved_ie
;
3783 brcmf_dbg(TRACE
, "bssidx %d, pktflag : 0x%02X\n", ifp
->bssidx
, pktflag
);
3784 iovar_ie_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
3787 curr_ie_buf
= iovar_ie_buf
;
3789 case BRCMF_VNDR_IE_PRBREQ_FLAG
:
3790 mgmt_ie_buf
= saved_ie
->probe_req_ie
;
3791 mgmt_ie_len
= &saved_ie
->probe_req_ie_len
;
3792 mgmt_ie_buf_len
= sizeof(saved_ie
->probe_req_ie
);
3794 case BRCMF_VNDR_IE_PRBRSP_FLAG
:
3795 mgmt_ie_buf
= saved_ie
->probe_res_ie
;
3796 mgmt_ie_len
= &saved_ie
->probe_res_ie_len
;
3797 mgmt_ie_buf_len
= sizeof(saved_ie
->probe_res_ie
);
3799 case BRCMF_VNDR_IE_BEACON_FLAG
:
3800 mgmt_ie_buf
= saved_ie
->beacon_ie
;
3801 mgmt_ie_len
= &saved_ie
->beacon_ie_len
;
3802 mgmt_ie_buf_len
= sizeof(saved_ie
->beacon_ie
);
3804 case BRCMF_VNDR_IE_ASSOCREQ_FLAG
:
3805 mgmt_ie_buf
= saved_ie
->assoc_req_ie
;
3806 mgmt_ie_len
= &saved_ie
->assoc_req_ie_len
;
3807 mgmt_ie_buf_len
= sizeof(saved_ie
->assoc_req_ie
);
3811 brcmf_err("not suitable type\n");
3815 if (vndr_ie_len
> mgmt_ie_buf_len
) {
3817 brcmf_err("extra IE size too big\n");
3821 /* parse and save new vndr_ie in curr_ie_buff before comparing it */
3822 if (vndr_ie_buf
&& vndr_ie_len
&& curr_ie_buf
) {
3824 brcmf_parse_vndr_ies(vndr_ie_buf
, vndr_ie_len
, &new_vndr_ies
);
3825 for (i
= 0; i
< new_vndr_ies
.count
; i
++) {
3826 vndrie_info
= &new_vndr_ies
.ie_info
[i
];
3827 memcpy(ptr
+ parsed_ie_buf_len
, vndrie_info
->ie_ptr
,
3828 vndrie_info
->ie_len
);
3829 parsed_ie_buf_len
+= vndrie_info
->ie_len
;
3833 if (mgmt_ie_buf
&& *mgmt_ie_len
) {
3834 if (parsed_ie_buf_len
&& (parsed_ie_buf_len
== *mgmt_ie_len
) &&
3835 (memcmp(mgmt_ie_buf
, curr_ie_buf
,
3836 parsed_ie_buf_len
) == 0)) {
3837 brcmf_dbg(TRACE
, "Previous mgmt IE equals to current IE\n");
3841 /* parse old vndr_ie */
3842 brcmf_parse_vndr_ies(mgmt_ie_buf
, *mgmt_ie_len
, &old_vndr_ies
);
3844 /* make a command to delete old ie */
3845 for (i
= 0; i
< old_vndr_ies
.count
; i
++) {
3846 vndrie_info
= &old_vndr_ies
.ie_info
[i
];
3848 brcmf_dbg(TRACE
, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
3849 vndrie_info
->vndrie
.id
,
3850 vndrie_info
->vndrie
.len
,
3851 vndrie_info
->vndrie
.oui
[0],
3852 vndrie_info
->vndrie
.oui
[1],
3853 vndrie_info
->vndrie
.oui
[2]);
3855 del_add_ie_buf_len
= brcmf_vndr_ie(curr_ie_buf
, pktflag
,
3856 vndrie_info
->ie_ptr
,
3857 vndrie_info
->ie_len
,
3859 curr_ie_buf
+= del_add_ie_buf_len
;
3860 total_ie_buf_len
+= del_add_ie_buf_len
;
3865 /* Add if there is any extra IE */
3866 if (mgmt_ie_buf
&& parsed_ie_buf_len
) {
3869 remained_buf_len
= mgmt_ie_buf_len
;
3871 /* make a command to add new ie */
3872 for (i
= 0; i
< new_vndr_ies
.count
; i
++) {
3873 vndrie_info
= &new_vndr_ies
.ie_info
[i
];
3875 /* verify remained buf size before copy data */
3876 if (remained_buf_len
< (vndrie_info
->vndrie
.len
+
3877 VNDR_IE_VSIE_OFFSET
)) {
3878 brcmf_err("no space in mgmt_ie_buf: len left %d",
3882 remained_buf_len
-= (vndrie_info
->ie_len
+
3883 VNDR_IE_VSIE_OFFSET
);
3885 brcmf_dbg(TRACE
, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
3886 vndrie_info
->vndrie
.id
,
3887 vndrie_info
->vndrie
.len
,
3888 vndrie_info
->vndrie
.oui
[0],
3889 vndrie_info
->vndrie
.oui
[1],
3890 vndrie_info
->vndrie
.oui
[2]);
3892 del_add_ie_buf_len
= brcmf_vndr_ie(curr_ie_buf
, pktflag
,
3893 vndrie_info
->ie_ptr
,
3894 vndrie_info
->ie_len
,
3897 /* save the parsed IE in wl struct */
3898 memcpy(ptr
+ (*mgmt_ie_len
), vndrie_info
->ie_ptr
,
3899 vndrie_info
->ie_len
);
3900 *mgmt_ie_len
+= vndrie_info
->ie_len
;
3902 curr_ie_buf
+= del_add_ie_buf_len
;
3903 total_ie_buf_len
+= del_add_ie_buf_len
;
3906 if (total_ie_buf_len
) {
3907 err
= brcmf_fil_bsscfg_data_set(ifp
, "vndr_ie", iovar_ie_buf
,
3910 brcmf_err("vndr ie set error : %d\n", err
);
3914 kfree(iovar_ie_buf
);
3918 s32
brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif
*vif
)
3921 BRCMF_VNDR_IE_PRBREQ_FLAG
,
3922 BRCMF_VNDR_IE_PRBRSP_FLAG
,
3923 BRCMF_VNDR_IE_BEACON_FLAG
3927 for (i
= 0; i
< ARRAY_SIZE(pktflags
); i
++)
3928 brcmf_vif_set_mgmt_ie(vif
, pktflags
[i
], NULL
, 0);
3930 memset(&vif
->saved_ie
, 0, sizeof(vif
->saved_ie
));
3935 brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif
*vif
,
3936 struct cfg80211_beacon_data
*beacon
)
3940 /* Set Beacon IEs to FW */
3941 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_BEACON_FLAG
,
3942 beacon
->tail
, beacon
->tail_len
);
3944 brcmf_err("Set Beacon IE Failed\n");
3947 brcmf_dbg(TRACE
, "Applied Vndr IEs for Beacon\n");
3949 /* Set Probe Response IEs to FW */
3950 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_PRBRSP_FLAG
,
3951 beacon
->proberesp_ies
,
3952 beacon
->proberesp_ies_len
);
3954 brcmf_err("Set Probe Resp IE Failed\n");
3956 brcmf_dbg(TRACE
, "Applied Vndr IEs for Probe Resp\n");
3962 brcmf_cfg80211_start_ap(struct wiphy
*wiphy
, struct net_device
*ndev
,
3963 struct cfg80211_ap_settings
*settings
)
3966 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
3967 struct brcmf_if
*ifp
= netdev_priv(ndev
);
3968 const struct brcmf_tlv
*ssid_ie
;
3969 const struct brcmf_tlv
*country_ie
;
3970 struct brcmf_ssid_le ssid_le
;
3972 const struct brcmf_tlv
*rsn_ie
;
3973 const struct brcmf_vs_tlv
*wpa_ie
;
3974 struct brcmf_join_params join_params
;
3975 enum nl80211_iftype dev_role
;
3976 struct brcmf_fil_bss_enable_le bss_enable
;
3981 brcmf_dbg(TRACE
, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
3982 settings
->chandef
.chan
->hw_value
,
3983 settings
->chandef
.center_freq1
, settings
->chandef
.width
,
3984 settings
->beacon_interval
, settings
->dtim_period
);
3985 brcmf_dbg(TRACE
, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
3986 settings
->ssid
, settings
->ssid_len
, settings
->auth_type
,
3987 settings
->inactivity_timeout
);
3988 dev_role
= ifp
->vif
->wdev
.iftype
;
3989 mbss
= ifp
->vif
->mbss
;
3991 /* store current 11d setting */
3992 brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_REGULATORY
, &ifp
->vif
->is_11d
);
3993 country_ie
= brcmf_parse_tlvs((u8
*)settings
->beacon
.tail
,
3994 settings
->beacon
.tail_len
,
3996 is_11d
= country_ie
? 1 : 0;
3998 memset(&ssid_le
, 0, sizeof(ssid_le
));
3999 if (settings
->ssid
== NULL
|| settings
->ssid_len
== 0) {
4000 ie_offset
= DOT11_MGMT_HDR_LEN
+ DOT11_BCN_PRB_FIXED_LEN
;
4001 ssid_ie
= brcmf_parse_tlvs(
4002 (u8
*)&settings
->beacon
.head
[ie_offset
],
4003 settings
->beacon
.head_len
- ie_offset
,
4008 memcpy(ssid_le
.SSID
, ssid_ie
->data
, ssid_ie
->len
);
4009 ssid_le
.SSID_len
= cpu_to_le32(ssid_ie
->len
);
4010 brcmf_dbg(TRACE
, "SSID is (%s) in Head\n", ssid_le
.SSID
);
4012 memcpy(ssid_le
.SSID
, settings
->ssid
, settings
->ssid_len
);
4013 ssid_le
.SSID_len
= cpu_to_le32((u32
)settings
->ssid_len
);
4017 brcmf_set_mpc(ifp
, 0);
4018 brcmf_configure_arp_offload(ifp
, false);
4021 /* find the RSN_IE */
4022 rsn_ie
= brcmf_parse_tlvs((u8
*)settings
->beacon
.tail
,
4023 settings
->beacon
.tail_len
, WLAN_EID_RSN
);
4025 /* find the WPA_IE */
4026 wpa_ie
= brcmf_find_wpaie((u8
*)settings
->beacon
.tail
,
4027 settings
->beacon
.tail_len
);
4029 if ((wpa_ie
!= NULL
|| rsn_ie
!= NULL
)) {
4030 brcmf_dbg(TRACE
, "WPA(2) IE is found\n");
4031 if (wpa_ie
!= NULL
) {
4033 err
= brcmf_configure_wpaie(ifp
, wpa_ie
, false);
4037 struct brcmf_vs_tlv
*tmp_ie
;
4039 tmp_ie
= (struct brcmf_vs_tlv
*)rsn_ie
;
4042 err
= brcmf_configure_wpaie(ifp
, tmp_ie
, true);
4047 brcmf_dbg(TRACE
, "No WPA(2) IEs found\n");
4048 brcmf_configure_opensecurity(ifp
);
4051 brcmf_config_ap_mgmt_ie(ifp
->vif
, &settings
->beacon
);
4054 chanspec
= chandef_to_chanspec(&cfg
->d11inf
,
4055 &settings
->chandef
);
4056 err
= brcmf_fil_iovar_int_set(ifp
, "chanspec", chanspec
);
4058 brcmf_err("Set Channel failed: chspec=%d, %d\n",
4063 if (is_11d
!= ifp
->vif
->is_11d
) {
4064 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_REGULATORY
,
4067 brcmf_err("Regulatory Set Error, %d\n", err
);
4071 if (settings
->beacon_interval
) {
4072 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_BCNPRD
,
4073 settings
->beacon_interval
);
4075 brcmf_err("Beacon Interval Set Error, %d\n",
4080 if (settings
->dtim_period
) {
4081 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_DTIMPRD
,
4082 settings
->dtim_period
);
4084 brcmf_err("DTIM Interval Set Error, %d\n", err
);
4089 if (dev_role
== NL80211_IFTYPE_AP
) {
4090 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
4092 brcmf_err("BRCMF_C_DOWN error %d\n", err
);
4095 brcmf_fil_iovar_int_set(ifp
, "apsta", 0);
4098 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, 1);
4100 brcmf_err("SET INFRA error %d\n", err
);
4103 } else if (WARN_ON(is_11d
!= ifp
->vif
->is_11d
)) {
4104 /* Multiple-BSS should use same 11d configuration */
4108 if (dev_role
== NL80211_IFTYPE_AP
) {
4109 if ((brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_MBSS
)) && (!mbss
))
4110 brcmf_fil_iovar_int_set(ifp
, "mbss", 1);
4112 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_AP
, 1);
4114 brcmf_err("setting AP mode failed %d\n", err
);
4117 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 1);
4119 brcmf_err("BRCMF_C_UP error (%d)\n", err
);
4122 /* On DOWN the firmware removes the WEP keys, reconfigure
4123 * them if they were set.
4125 brcmf_cfg80211_reconfigure_wep(ifp
);
4127 memset(&join_params
, 0, sizeof(join_params
));
4128 /* join parameters starts with ssid */
4129 memcpy(&join_params
.ssid_le
, &ssid_le
, sizeof(ssid_le
));
4131 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
4132 &join_params
, sizeof(join_params
));
4134 brcmf_err("SET SSID error (%d)\n", err
);
4137 brcmf_dbg(TRACE
, "AP mode configuration complete\n");
4139 err
= brcmf_fil_bsscfg_data_set(ifp
, "ssid", &ssid_le
,
4142 brcmf_err("setting ssid failed %d\n", err
);
4145 bss_enable
.bsscfg_idx
= cpu_to_le32(ifp
->bssidx
);
4146 bss_enable
.enable
= cpu_to_le32(1);
4147 err
= brcmf_fil_iovar_data_set(ifp
, "bss", &bss_enable
,
4148 sizeof(bss_enable
));
4150 brcmf_err("bss_enable config failed %d\n", err
);
4154 brcmf_dbg(TRACE
, "GO mode configuration complete\n");
4156 clear_bit(BRCMF_VIF_STATUS_AP_CREATING
, &ifp
->vif
->sme_state
);
4157 set_bit(BRCMF_VIF_STATUS_AP_CREATED
, &ifp
->vif
->sme_state
);
4160 if ((err
) && (!mbss
)) {
4161 brcmf_set_mpc(ifp
, 1);
4162 brcmf_configure_arp_offload(ifp
, true);
4167 static int brcmf_cfg80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*ndev
)
4169 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4171 struct brcmf_fil_bss_enable_le bss_enable
;
4172 struct brcmf_join_params join_params
;
4174 brcmf_dbg(TRACE
, "Enter\n");
4176 if (ifp
->vif
->wdev
.iftype
== NL80211_IFTYPE_AP
) {
4177 /* Due to most likely deauths outstanding we sleep */
4178 /* first to make sure they get processed by fw. */
4181 if (ifp
->vif
->mbss
) {
4182 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
4186 memset(&join_params
, 0, sizeof(join_params
));
4187 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SSID
,
4188 &join_params
, sizeof(join_params
));
4190 brcmf_err("SET SSID error (%d)\n", err
);
4191 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_DOWN
, 1);
4193 brcmf_err("BRCMF_C_DOWN error %d\n", err
);
4194 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_AP
, 0);
4196 brcmf_err("setting AP mode failed %d\n", err
);
4197 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_INFRA
, 0);
4199 brcmf_err("setting INFRA mode failed %d\n", err
);
4200 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_MBSS
))
4201 brcmf_fil_iovar_int_set(ifp
, "mbss", 0);
4202 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_REGULATORY
,
4205 brcmf_err("restoring REGULATORY setting failed %d\n",
4207 /* Bring device back up so it can be used again */
4208 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 1);
4210 brcmf_err("BRCMF_C_UP error %d\n", err
);
4212 bss_enable
.bsscfg_idx
= cpu_to_le32(ifp
->bssidx
);
4213 bss_enable
.enable
= cpu_to_le32(0);
4214 err
= brcmf_fil_iovar_data_set(ifp
, "bss", &bss_enable
,
4215 sizeof(bss_enable
));
4217 brcmf_err("bss_enable config failed %d\n", err
);
4219 brcmf_set_mpc(ifp
, 1);
4220 brcmf_configure_arp_offload(ifp
, true);
4221 set_bit(BRCMF_VIF_STATUS_AP_CREATING
, &ifp
->vif
->sme_state
);
4222 clear_bit(BRCMF_VIF_STATUS_AP_CREATED
, &ifp
->vif
->sme_state
);
4228 brcmf_cfg80211_change_beacon(struct wiphy
*wiphy
, struct net_device
*ndev
,
4229 struct cfg80211_beacon_data
*info
)
4231 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4234 brcmf_dbg(TRACE
, "Enter\n");
4236 err
= brcmf_config_ap_mgmt_ie(ifp
->vif
, info
);
4242 brcmf_cfg80211_del_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
4243 struct station_del_parameters
*params
)
4245 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4246 struct brcmf_scb_val_le scbval
;
4247 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4253 brcmf_dbg(TRACE
, "Enter %pM\n", params
->mac
);
4255 if (ifp
->vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
)
4256 ifp
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
4257 if (!check_vif_up(ifp
->vif
))
4260 memcpy(&scbval
.ea
, params
->mac
, ETH_ALEN
);
4261 scbval
.val
= cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING
);
4262 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON
,
4263 &scbval
, sizeof(scbval
));
4265 brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err
);
4267 brcmf_dbg(TRACE
, "Exit\n");
4272 brcmf_cfg80211_change_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
4273 const u8
*mac
, struct station_parameters
*params
)
4275 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4278 brcmf_dbg(TRACE
, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac
,
4279 params
->sta_flags_mask
, params
->sta_flags_set
);
4281 /* Ignore all 00 MAC */
4282 if (is_zero_ether_addr(mac
))
4285 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4288 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
4289 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SCB_AUTHORIZE
,
4290 (void *)mac
, ETH_ALEN
);
4292 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_SCB_DEAUTHORIZE
,
4293 (void *)mac
, ETH_ALEN
);
4295 brcmf_err("Setting SCB (de-)authorize failed, %d\n", err
);
4301 brcmf_cfg80211_mgmt_frame_register(struct wiphy
*wiphy
,
4302 struct wireless_dev
*wdev
,
4303 u16 frame_type
, bool reg
)
4305 struct brcmf_cfg80211_vif
*vif
;
4308 brcmf_dbg(TRACE
, "Enter, frame_type %04x, reg=%d\n", frame_type
, reg
);
4310 mgmt_type
= (frame_type
& IEEE80211_FCTL_STYPE
) >> 4;
4311 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4313 vif
->mgmt_rx_reg
|= BIT(mgmt_type
);
4315 vif
->mgmt_rx_reg
&= ~BIT(mgmt_type
);
4320 brcmf_cfg80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
4321 struct cfg80211_mgmt_tx_params
*params
, u64
*cookie
)
4323 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4324 struct ieee80211_channel
*chan
= params
->chan
;
4325 const u8
*buf
= params
->buf
;
4326 size_t len
= params
->len
;
4327 const struct ieee80211_mgmt
*mgmt
;
4328 struct brcmf_cfg80211_vif
*vif
;
4332 struct brcmf_fil_action_frame_le
*action_frame
;
4333 struct brcmf_fil_af_params_le
*af_params
;
4338 brcmf_dbg(TRACE
, "Enter\n");
4342 mgmt
= (const struct ieee80211_mgmt
*)buf
;
4344 if (!ieee80211_is_mgmt(mgmt
->frame_control
)) {
4345 brcmf_err("Driver only allows MGMT packet type\n");
4349 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4351 if (ieee80211_is_probe_resp(mgmt
->frame_control
)) {
4352 /* Right now the only reason to get a probe response */
4353 /* is for p2p listen response or for p2p GO from */
4354 /* wpa_supplicant. Unfortunately the probe is send */
4355 /* on primary ndev, while dongle wants it on the p2p */
4356 /* vif. Since this is only reason for a probe */
4357 /* response to be sent, the vif is taken from cfg. */
4358 /* If ever desired to send proberesp for non p2p */
4359 /* response then data should be checked for */
4360 /* "DIRECT-". Note in future supplicant will take */
4361 /* dedicated p2p wdev to do this and then this 'hack'*/
4362 /* is not needed anymore. */
4363 ie_offset
= DOT11_MGMT_HDR_LEN
+
4364 DOT11_BCN_PRB_FIXED_LEN
;
4365 ie_len
= len
- ie_offset
;
4366 if (vif
== cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
)
4367 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
4368 err
= brcmf_vif_set_mgmt_ie(vif
,
4369 BRCMF_VNDR_IE_PRBRSP_FLAG
,
4372 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, true,
4374 } else if (ieee80211_is_action(mgmt
->frame_control
)) {
4375 af_params
= kzalloc(sizeof(*af_params
), GFP_KERNEL
);
4376 if (af_params
== NULL
) {
4377 brcmf_err("unable to allocate frame\n");
4381 action_frame
= &af_params
->action_frame
;
4382 /* Add the packet Id */
4383 action_frame
->packet_id
= cpu_to_le32(*cookie
);
4385 memcpy(&action_frame
->da
[0], &mgmt
->da
[0], ETH_ALEN
);
4386 memcpy(&af_params
->bssid
[0], &mgmt
->bssid
[0], ETH_ALEN
);
4387 /* Add the length exepted for 802.11 header */
4388 action_frame
->len
= cpu_to_le16(len
- DOT11_MGMT_HDR_LEN
);
4389 /* Add the channel. Use the one specified as parameter if any or
4390 * the current one (got from the firmware) otherwise
4393 freq
= chan
->center_freq
;
4395 brcmf_fil_cmd_int_get(vif
->ifp
, BRCMF_C_GET_CHANNEL
,
4397 chan_nr
= ieee80211_frequency_to_channel(freq
);
4398 af_params
->channel
= cpu_to_le32(chan_nr
);
4400 memcpy(action_frame
->data
, &buf
[DOT11_MGMT_HDR_LEN
],
4401 le16_to_cpu(action_frame
->len
));
4403 brcmf_dbg(TRACE
, "Action frame, cookie=%lld, len=%d, freq=%d\n",
4404 *cookie
, le16_to_cpu(action_frame
->len
), freq
);
4406 ack
= brcmf_p2p_send_action_frame(cfg
, cfg_to_ndev(cfg
),
4409 cfg80211_mgmt_tx_status(wdev
, *cookie
, buf
, len
, ack
,
4413 brcmf_dbg(TRACE
, "Unhandled, fc=%04x!!\n", mgmt
->frame_control
);
4414 brcmf_dbg_hex_dump(true, buf
, len
, "payload, len=%Zu\n", len
);
4423 brcmf_cfg80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
4424 struct wireless_dev
*wdev
,
4427 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4428 struct brcmf_cfg80211_vif
*vif
;
4431 brcmf_dbg(TRACE
, "Enter p2p listen cancel\n");
4433 vif
= cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
4435 brcmf_err("No p2p device available for probe response\n");
4439 brcmf_p2p_cancel_remain_on_channel(vif
->ifp
);
4444 static int brcmf_cfg80211_crit_proto_start(struct wiphy
*wiphy
,
4445 struct wireless_dev
*wdev
,
4446 enum nl80211_crit_proto_id proto
,
4449 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4450 struct brcmf_cfg80211_vif
*vif
;
4452 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4454 /* only DHCP support for now */
4455 if (proto
!= NL80211_CRIT_PROTO_DHCP
)
4458 /* suppress and abort scanning */
4459 set_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
4460 brcmf_abort_scanning(cfg
);
4462 return brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_DISABLED
, duration
);
4465 static void brcmf_cfg80211_crit_proto_stop(struct wiphy
*wiphy
,
4466 struct wireless_dev
*wdev
)
4468 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
4469 struct brcmf_cfg80211_vif
*vif
;
4471 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
4473 brcmf_btcoex_set_mode(vif
, BRCMF_BTCOEX_ENABLED
, 0);
4474 clear_bit(BRCMF_SCAN_STATUS_SUPPRESS
, &cfg
->scan_status
);
4478 brcmf_notify_tdls_peer_event(struct brcmf_if
*ifp
,
4479 const struct brcmf_event_msg
*e
, void *data
)
4481 switch (e
->reason
) {
4482 case BRCMF_E_REASON_TDLS_PEER_DISCOVERED
:
4483 brcmf_dbg(TRACE
, "TDLS Peer Discovered\n");
4485 case BRCMF_E_REASON_TDLS_PEER_CONNECTED
:
4486 brcmf_dbg(TRACE
, "TDLS Peer Connected\n");
4487 brcmf_proto_add_tdls_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4489 case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED
:
4490 brcmf_dbg(TRACE
, "TDLS Peer Disconnected\n");
4491 brcmf_proto_delete_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4498 static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper
)
4503 case NL80211_TDLS_DISCOVERY_REQ
:
4504 ret
= BRCMF_TDLS_MANUAL_EP_DISCOVERY
;
4506 case NL80211_TDLS_SETUP
:
4507 ret
= BRCMF_TDLS_MANUAL_EP_CREATE
;
4509 case NL80211_TDLS_TEARDOWN
:
4510 ret
= BRCMF_TDLS_MANUAL_EP_DELETE
;
4513 brcmf_err("unsupported operation: %d\n", oper
);
4519 static int brcmf_cfg80211_tdls_oper(struct wiphy
*wiphy
,
4520 struct net_device
*ndev
, const u8
*peer
,
4521 enum nl80211_tdls_operation oper
)
4523 struct brcmf_if
*ifp
;
4524 struct brcmf_tdls_iovar_le info
;
4527 ret
= brcmf_convert_nl80211_tdls_oper(oper
);
4531 ifp
= netdev_priv(ndev
);
4532 memset(&info
, 0, sizeof(info
));
4533 info
.mode
= (u8
)ret
;
4535 memcpy(info
.ea
, peer
, ETH_ALEN
);
4537 ret
= brcmf_fil_iovar_data_set(ifp
, "tdls_endpoint",
4538 &info
, sizeof(info
));
4540 brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret
);
4545 static struct cfg80211_ops wl_cfg80211_ops
= {
4546 .add_virtual_intf
= brcmf_cfg80211_add_iface
,
4547 .del_virtual_intf
= brcmf_cfg80211_del_iface
,
4548 .change_virtual_intf
= brcmf_cfg80211_change_iface
,
4549 .scan
= brcmf_cfg80211_scan
,
4550 .set_wiphy_params
= brcmf_cfg80211_set_wiphy_params
,
4551 .join_ibss
= brcmf_cfg80211_join_ibss
,
4552 .leave_ibss
= brcmf_cfg80211_leave_ibss
,
4553 .get_station
= brcmf_cfg80211_get_station
,
4554 .set_tx_power
= brcmf_cfg80211_set_tx_power
,
4555 .get_tx_power
= brcmf_cfg80211_get_tx_power
,
4556 .add_key
= brcmf_cfg80211_add_key
,
4557 .del_key
= brcmf_cfg80211_del_key
,
4558 .get_key
= brcmf_cfg80211_get_key
,
4559 .set_default_key
= brcmf_cfg80211_config_default_key
,
4560 .set_default_mgmt_key
= brcmf_cfg80211_config_default_mgmt_key
,
4561 .set_power_mgmt
= brcmf_cfg80211_set_power_mgmt
,
4562 .connect
= brcmf_cfg80211_connect
,
4563 .disconnect
= brcmf_cfg80211_disconnect
,
4564 .suspend
= brcmf_cfg80211_suspend
,
4565 .resume
= brcmf_cfg80211_resume
,
4566 .set_pmksa
= brcmf_cfg80211_set_pmksa
,
4567 .del_pmksa
= brcmf_cfg80211_del_pmksa
,
4568 .flush_pmksa
= brcmf_cfg80211_flush_pmksa
,
4569 .start_ap
= brcmf_cfg80211_start_ap
,
4570 .stop_ap
= brcmf_cfg80211_stop_ap
,
4571 .change_beacon
= brcmf_cfg80211_change_beacon
,
4572 .del_station
= brcmf_cfg80211_del_station
,
4573 .change_station
= brcmf_cfg80211_change_station
,
4574 .sched_scan_start
= brcmf_cfg80211_sched_scan_start
,
4575 .sched_scan_stop
= brcmf_cfg80211_sched_scan_stop
,
4576 .mgmt_frame_register
= brcmf_cfg80211_mgmt_frame_register
,
4577 .mgmt_tx
= brcmf_cfg80211_mgmt_tx
,
4578 .remain_on_channel
= brcmf_p2p_remain_on_channel
,
4579 .cancel_remain_on_channel
= brcmf_cfg80211_cancel_remain_on_channel
,
4580 .start_p2p_device
= brcmf_p2p_start_device
,
4581 .stop_p2p_device
= brcmf_p2p_stop_device
,
4582 .crit_proto_start
= brcmf_cfg80211_crit_proto_start
,
4583 .crit_proto_stop
= brcmf_cfg80211_crit_proto_stop
,
4584 .tdls_oper
= brcmf_cfg80211_tdls_oper
,
4587 struct brcmf_cfg80211_vif
*brcmf_alloc_vif(struct brcmf_cfg80211_info
*cfg
,
4588 enum nl80211_iftype type
,
4591 struct brcmf_cfg80211_vif
*vif_walk
;
4592 struct brcmf_cfg80211_vif
*vif
;
4595 brcmf_dbg(TRACE
, "allocating virtual interface (size=%zu)\n",
4597 vif
= kzalloc(sizeof(*vif
), GFP_KERNEL
);
4599 return ERR_PTR(-ENOMEM
);
4601 vif
->wdev
.wiphy
= cfg
->wiphy
;
4602 vif
->wdev
.iftype
= type
;
4604 vif
->pm_block
= pm_block
;
4607 brcmf_init_prof(&vif
->profile
);
4609 if (type
== NL80211_IFTYPE_AP
) {
4611 list_for_each_entry(vif_walk
, &cfg
->vif_list
, list
) {
4612 if (vif_walk
->wdev
.iftype
== NL80211_IFTYPE_AP
) {
4620 list_add_tail(&vif
->list
, &cfg
->vif_list
);
4624 void brcmf_free_vif(struct brcmf_cfg80211_vif
*vif
)
4626 list_del(&vif
->list
);
4630 void brcmf_cfg80211_free_netdev(struct net_device
*ndev
)
4632 struct brcmf_cfg80211_vif
*vif
;
4633 struct brcmf_if
*ifp
;
4635 ifp
= netdev_priv(ndev
);
4638 brcmf_free_vif(vif
);
4642 static bool brcmf_is_linkup(const struct brcmf_event_msg
*e
)
4644 u32 event
= e
->event_code
;
4645 u32 status
= e
->status
;
4647 if (event
== BRCMF_E_SET_SSID
&& status
== BRCMF_E_STATUS_SUCCESS
) {
4648 brcmf_dbg(CONN
, "Processing set ssid\n");
4655 static bool brcmf_is_linkdown(const struct brcmf_event_msg
*e
)
4657 u32 event
= e
->event_code
;
4658 u16 flags
= e
->flags
;
4660 if ((event
== BRCMF_E_DEAUTH
) || (event
== BRCMF_E_DEAUTH_IND
) ||
4661 (event
== BRCMF_E_DISASSOC_IND
) ||
4662 ((event
== BRCMF_E_LINK
) && (!(flags
& BRCMF_EVENT_MSG_LINK
)))) {
4663 brcmf_dbg(CONN
, "Processing link down\n");
4669 static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info
*cfg
,
4670 const struct brcmf_event_msg
*e
)
4672 u32 event
= e
->event_code
;
4673 u32 status
= e
->status
;
4675 if (event
== BRCMF_E_LINK
&& status
== BRCMF_E_STATUS_NO_NETWORKS
) {
4676 brcmf_dbg(CONN
, "Processing Link %s & no network found\n",
4677 e
->flags
& BRCMF_EVENT_MSG_LINK
? "up" : "down");
4681 if (event
== BRCMF_E_SET_SSID
&& status
!= BRCMF_E_STATUS_SUCCESS
) {
4682 brcmf_dbg(CONN
, "Processing connecting & no network found\n");
4689 static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info
*cfg
)
4691 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4693 kfree(conn_info
->req_ie
);
4694 conn_info
->req_ie
= NULL
;
4695 conn_info
->req_ie_len
= 0;
4696 kfree(conn_info
->resp_ie
);
4697 conn_info
->resp_ie
= NULL
;
4698 conn_info
->resp_ie_len
= 0;
4701 static s32
brcmf_get_assoc_ies(struct brcmf_cfg80211_info
*cfg
,
4702 struct brcmf_if
*ifp
)
4704 struct brcmf_cfg80211_assoc_ielen_le
*assoc_info
;
4705 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4710 brcmf_clear_assoc_ies(cfg
);
4712 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_info",
4713 cfg
->extra_buf
, WL_ASSOC_INFO_MAX
);
4715 brcmf_err("could not get assoc info (%d)\n", err
);
4719 (struct brcmf_cfg80211_assoc_ielen_le
*)cfg
->extra_buf
;
4720 req_len
= le32_to_cpu(assoc_info
->req_len
);
4721 resp_len
= le32_to_cpu(assoc_info
->resp_len
);
4723 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_req_ies",
4727 brcmf_err("could not get assoc req (%d)\n", err
);
4730 conn_info
->req_ie_len
= req_len
;
4732 kmemdup(cfg
->extra_buf
, conn_info
->req_ie_len
,
4735 conn_info
->req_ie_len
= 0;
4736 conn_info
->req_ie
= NULL
;
4739 err
= brcmf_fil_iovar_data_get(ifp
, "assoc_resp_ies",
4743 brcmf_err("could not get assoc resp (%d)\n", err
);
4746 conn_info
->resp_ie_len
= resp_len
;
4747 conn_info
->resp_ie
=
4748 kmemdup(cfg
->extra_buf
, conn_info
->resp_ie_len
,
4751 conn_info
->resp_ie_len
= 0;
4752 conn_info
->resp_ie
= NULL
;
4754 brcmf_dbg(CONN
, "req len (%d) resp len (%d)\n",
4755 conn_info
->req_ie_len
, conn_info
->resp_ie_len
);
4761 brcmf_bss_roaming_done(struct brcmf_cfg80211_info
*cfg
,
4762 struct net_device
*ndev
,
4763 const struct brcmf_event_msg
*e
)
4765 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4766 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4767 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4768 struct wiphy
*wiphy
= cfg_to_wiphy(cfg
);
4769 struct ieee80211_channel
*notify_channel
= NULL
;
4770 struct ieee80211_supported_band
*band
;
4771 struct brcmf_bss_info_le
*bi
;
4772 struct brcmu_chan ch
;
4777 brcmf_dbg(TRACE
, "Enter\n");
4779 brcmf_get_assoc_ies(cfg
, ifp
);
4780 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4781 brcmf_update_bss_info(cfg
, ifp
);
4783 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
4789 /* data sent to dongle has to be little endian */
4790 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
4791 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSS_INFO
,
4792 buf
, WL_BSS_INFO_MAX
);
4797 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
4798 ch
.chspec
= le16_to_cpu(bi
->chanspec
);
4799 cfg
->d11inf
.decchspec(&ch
);
4801 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
4802 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
4804 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
4806 freq
= ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
4807 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
4811 cfg80211_roamed(ndev
, notify_channel
, (u8
*)profile
->bssid
,
4812 conn_info
->req_ie
, conn_info
->req_ie_len
,
4813 conn_info
->resp_ie
, conn_info
->resp_ie_len
, GFP_KERNEL
);
4814 brcmf_dbg(CONN
, "Report roaming result\n");
4816 set_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
);
4817 brcmf_dbg(TRACE
, "Exit\n");
4822 brcmf_bss_connect_done(struct brcmf_cfg80211_info
*cfg
,
4823 struct net_device
*ndev
, const struct brcmf_event_msg
*e
,
4826 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4827 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4828 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg
);
4830 brcmf_dbg(TRACE
, "Enter\n");
4832 if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4833 &ifp
->vif
->sme_state
)) {
4835 brcmf_get_assoc_ies(cfg
, ifp
);
4836 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4837 brcmf_update_bss_info(cfg
, ifp
);
4838 set_bit(BRCMF_VIF_STATUS_CONNECTED
,
4839 &ifp
->vif
->sme_state
);
4841 cfg80211_connect_result(ndev
,
4842 (u8
*)profile
->bssid
,
4844 conn_info
->req_ie_len
,
4846 conn_info
->resp_ie_len
,
4847 completed
? WLAN_STATUS_SUCCESS
:
4848 WLAN_STATUS_AUTH_TIMEOUT
,
4850 brcmf_dbg(CONN
, "Report connect result - connection %s\n",
4851 completed
? "succeeded" : "failed");
4853 brcmf_dbg(TRACE
, "Exit\n");
4858 brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info
*cfg
,
4859 struct net_device
*ndev
,
4860 const struct brcmf_event_msg
*e
, void *data
)
4862 struct brcmf_if
*ifp
= netdev_priv(ndev
);
4863 static int generation
;
4864 u32 event
= e
->event_code
;
4865 u32 reason
= e
->reason
;
4866 struct station_info sinfo
;
4868 brcmf_dbg(CONN
, "event %d, reason %d\n", event
, reason
);
4869 if (event
== BRCMF_E_LINK
&& reason
== BRCMF_E_REASON_LINK_BSSCFG_DIS
&&
4870 ndev
!= cfg_to_ndev(cfg
)) {
4871 brcmf_dbg(CONN
, "AP mode link down\n");
4872 complete(&cfg
->vif_disabled
);
4874 brcmf_remove_interface(ifp
->drvr
, ifp
->bssidx
);
4878 if (((event
== BRCMF_E_ASSOC_IND
) || (event
== BRCMF_E_REASSOC_IND
)) &&
4879 (reason
== BRCMF_E_STATUS_SUCCESS
)) {
4880 memset(&sinfo
, 0, sizeof(sinfo
));
4882 brcmf_err("No IEs present in ASSOC/REASSOC_IND");
4885 sinfo
.assoc_req_ies
= data
;
4886 sinfo
.assoc_req_ies_len
= e
->datalen
;
4888 sinfo
.generation
= generation
;
4889 cfg80211_new_sta(ndev
, e
->addr
, &sinfo
, GFP_KERNEL
);
4890 } else if ((event
== BRCMF_E_DISASSOC_IND
) ||
4891 (event
== BRCMF_E_DEAUTH_IND
) ||
4892 (event
== BRCMF_E_DEAUTH
)) {
4893 cfg80211_del_sta(ndev
, e
->addr
, GFP_KERNEL
);
4899 brcmf_notify_connect_status(struct brcmf_if
*ifp
,
4900 const struct brcmf_event_msg
*e
, void *data
)
4902 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4903 struct net_device
*ndev
= ifp
->ndev
;
4904 struct brcmf_cfg80211_profile
*profile
= &ifp
->vif
->profile
;
4905 struct ieee80211_channel
*chan
;
4908 if ((e
->event_code
== BRCMF_E_DEAUTH
) ||
4909 (e
->event_code
== BRCMF_E_DEAUTH_IND
) ||
4910 (e
->event_code
== BRCMF_E_DISASSOC_IND
) ||
4911 ((e
->event_code
== BRCMF_E_LINK
) && (!e
->flags
))) {
4912 brcmf_proto_delete_peer(ifp
->drvr
, ifp
->ifidx
, (u8
*)e
->addr
);
4915 if (brcmf_is_apmode(ifp
->vif
)) {
4916 err
= brcmf_notify_connect_status_ap(cfg
, ndev
, e
, data
);
4917 } else if (brcmf_is_linkup(e
)) {
4918 brcmf_dbg(CONN
, "Linkup\n");
4919 if (brcmf_is_ibssmode(ifp
->vif
)) {
4920 chan
= ieee80211_get_channel(cfg
->wiphy
, cfg
->channel
);
4921 memcpy(profile
->bssid
, e
->addr
, ETH_ALEN
);
4922 wl_inform_ibss(cfg
, ndev
, e
->addr
);
4923 cfg80211_ibss_joined(ndev
, e
->addr
, chan
, GFP_KERNEL
);
4924 clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4925 &ifp
->vif
->sme_state
);
4926 set_bit(BRCMF_VIF_STATUS_CONNECTED
,
4927 &ifp
->vif
->sme_state
);
4929 brcmf_bss_connect_done(cfg
, ndev
, e
, true);
4930 } else if (brcmf_is_linkdown(e
)) {
4931 brcmf_dbg(CONN
, "Linkdown\n");
4932 if (!brcmf_is_ibssmode(ifp
->vif
)) {
4933 brcmf_bss_connect_done(cfg
, ndev
, e
, false);
4935 brcmf_link_down(ifp
->vif
);
4936 brcmf_init_prof(ndev_to_prof(ndev
));
4937 if (ndev
!= cfg_to_ndev(cfg
))
4938 complete(&cfg
->vif_disabled
);
4939 } else if (brcmf_is_nonetwork(cfg
, e
)) {
4940 if (brcmf_is_ibssmode(ifp
->vif
))
4941 clear_bit(BRCMF_VIF_STATUS_CONNECTING
,
4942 &ifp
->vif
->sme_state
);
4944 brcmf_bss_connect_done(cfg
, ndev
, e
, false);
4951 brcmf_notify_roaming_status(struct brcmf_if
*ifp
,
4952 const struct brcmf_event_msg
*e
, void *data
)
4954 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4955 u32 event
= e
->event_code
;
4956 u32 status
= e
->status
;
4958 if (event
== BRCMF_E_ROAM
&& status
== BRCMF_E_STATUS_SUCCESS
) {
4959 if (test_bit(BRCMF_VIF_STATUS_CONNECTED
, &ifp
->vif
->sme_state
))
4960 brcmf_bss_roaming_done(cfg
, ifp
->ndev
, e
);
4962 brcmf_bss_connect_done(cfg
, ifp
->ndev
, e
, true);
4969 brcmf_notify_mic_status(struct brcmf_if
*ifp
,
4970 const struct brcmf_event_msg
*e
, void *data
)
4972 u16 flags
= e
->flags
;
4973 enum nl80211_key_type key_type
;
4975 if (flags
& BRCMF_EVENT_MSG_GROUP
)
4976 key_type
= NL80211_KEYTYPE_GROUP
;
4978 key_type
= NL80211_KEYTYPE_PAIRWISE
;
4980 cfg80211_michael_mic_failure(ifp
->ndev
, (u8
*)&e
->addr
, key_type
, -1,
4986 static s32
brcmf_notify_vif_event(struct brcmf_if
*ifp
,
4987 const struct brcmf_event_msg
*e
, void *data
)
4989 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
4990 struct brcmf_if_event
*ifevent
= (struct brcmf_if_event
*)data
;
4991 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
4992 struct brcmf_cfg80211_vif
*vif
;
4994 brcmf_dbg(TRACE
, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
4995 ifevent
->action
, ifevent
->flags
, ifevent
->ifidx
,
4998 mutex_lock(&event
->vif_event_lock
);
4999 event
->action
= ifevent
->action
;
5002 switch (ifevent
->action
) {
5003 case BRCMF_E_IF_ADD
:
5004 /* waiting process may have timed out */
5005 if (!cfg
->vif_event
.vif
) {
5006 mutex_unlock(&event
->vif_event_lock
);
5013 vif
->wdev
.netdev
= ifp
->ndev
;
5014 ifp
->ndev
->ieee80211_ptr
= &vif
->wdev
;
5015 SET_NETDEV_DEV(ifp
->ndev
, wiphy_dev(cfg
->wiphy
));
5017 mutex_unlock(&event
->vif_event_lock
);
5018 wake_up(&event
->vif_wq
);
5021 case BRCMF_E_IF_DEL
:
5022 mutex_unlock(&event
->vif_event_lock
);
5023 /* event may not be upon user request */
5024 if (brcmf_cfg80211_vif_event_armed(cfg
))
5025 wake_up(&event
->vif_wq
);
5028 case BRCMF_E_IF_CHANGE
:
5029 mutex_unlock(&event
->vif_event_lock
);
5030 wake_up(&event
->vif_wq
);
5034 mutex_unlock(&event
->vif_event_lock
);
5040 static void brcmf_init_conf(struct brcmf_cfg80211_conf
*conf
)
5042 conf
->frag_threshold
= (u32
)-1;
5043 conf
->rts_threshold
= (u32
)-1;
5044 conf
->retry_short
= (u32
)-1;
5045 conf
->retry_long
= (u32
)-1;
5046 conf
->tx_power
= -1;
5049 static void brcmf_register_event_handlers(struct brcmf_cfg80211_info
*cfg
)
5051 brcmf_fweh_register(cfg
->pub
, BRCMF_E_LINK
,
5052 brcmf_notify_connect_status
);
5053 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DEAUTH_IND
,
5054 brcmf_notify_connect_status
);
5055 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DEAUTH
,
5056 brcmf_notify_connect_status
);
5057 brcmf_fweh_register(cfg
->pub
, BRCMF_E_DISASSOC_IND
,
5058 brcmf_notify_connect_status
);
5059 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ASSOC_IND
,
5060 brcmf_notify_connect_status
);
5061 brcmf_fweh_register(cfg
->pub
, BRCMF_E_REASSOC_IND
,
5062 brcmf_notify_connect_status
);
5063 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ROAM
,
5064 brcmf_notify_roaming_status
);
5065 brcmf_fweh_register(cfg
->pub
, BRCMF_E_MIC_ERROR
,
5066 brcmf_notify_mic_status
);
5067 brcmf_fweh_register(cfg
->pub
, BRCMF_E_SET_SSID
,
5068 brcmf_notify_connect_status
);
5069 brcmf_fweh_register(cfg
->pub
, BRCMF_E_PFN_NET_FOUND
,
5070 brcmf_notify_sched_scan_results
);
5071 brcmf_fweh_register(cfg
->pub
, BRCMF_E_IF
,
5072 brcmf_notify_vif_event
);
5073 brcmf_fweh_register(cfg
->pub
, BRCMF_E_P2P_PROBEREQ_MSG
,
5074 brcmf_p2p_notify_rx_mgmt_p2p_probereq
);
5075 brcmf_fweh_register(cfg
->pub
, BRCMF_E_P2P_DISC_LISTEN_COMPLETE
,
5076 brcmf_p2p_notify_listen_complete
);
5077 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_RX
,
5078 brcmf_p2p_notify_action_frame_rx
);
5079 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_COMPLETE
,
5080 brcmf_p2p_notify_action_tx_complete
);
5081 brcmf_fweh_register(cfg
->pub
, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE
,
5082 brcmf_p2p_notify_action_tx_complete
);
5085 static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info
*cfg
)
5089 kfree(cfg
->escan_ioctl_buf
);
5090 cfg
->escan_ioctl_buf
= NULL
;
5091 kfree(cfg
->extra_buf
);
5092 cfg
->extra_buf
= NULL
;
5093 kfree(cfg
->pmk_list
);
5094 cfg
->pmk_list
= NULL
;
5097 static s32
brcmf_init_priv_mem(struct brcmf_cfg80211_info
*cfg
)
5099 cfg
->conf
= kzalloc(sizeof(*cfg
->conf
), GFP_KERNEL
);
5101 goto init_priv_mem_out
;
5102 cfg
->escan_ioctl_buf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5103 if (!cfg
->escan_ioctl_buf
)
5104 goto init_priv_mem_out
;
5105 cfg
->extra_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
5106 if (!cfg
->extra_buf
)
5107 goto init_priv_mem_out
;
5108 cfg
->pmk_list
= kzalloc(sizeof(*cfg
->pmk_list
), GFP_KERNEL
);
5110 goto init_priv_mem_out
;
5115 brcmf_deinit_priv_mem(cfg
);
5120 static s32
wl_init_priv(struct brcmf_cfg80211_info
*cfg
)
5124 cfg
->scan_request
= NULL
;
5125 cfg
->pwr_save
= true;
5126 cfg
->active_scan
= true; /* we do active scan per default */
5127 cfg
->dongle_up
= false; /* dongle is not up yet */
5128 err
= brcmf_init_priv_mem(cfg
);
5131 brcmf_register_event_handlers(cfg
);
5132 mutex_init(&cfg
->usr_sync
);
5133 brcmf_init_escan(cfg
);
5134 brcmf_init_conf(cfg
->conf
);
5135 init_completion(&cfg
->vif_disabled
);
5139 static void wl_deinit_priv(struct brcmf_cfg80211_info
*cfg
)
5141 cfg
->dongle_up
= false; /* dongle down */
5142 brcmf_abort_scanning(cfg
);
5143 brcmf_deinit_priv_mem(cfg
);
5146 static void init_vif_event(struct brcmf_cfg80211_vif_event
*event
)
5148 init_waitqueue_head(&event
->vif_wq
);
5149 mutex_init(&event
->vif_event_lock
);
5153 brcmf_dongle_roam(struct brcmf_if
*ifp
, u32 bcn_timeout
)
5156 __le32 roamtrigger
[2];
5157 __le32 roam_delta
[2];
5160 * Setup timeout if Beacons are lost and roam is
5161 * off to report link down
5163 if (brcmf_roamoff
) {
5164 err
= brcmf_fil_iovar_int_set(ifp
, "bcn_timeout", bcn_timeout
);
5166 brcmf_err("bcn_timeout error (%d)\n", err
);
5167 goto dongle_rom_out
;
5172 * Enable/Disable built-in roaming to allow supplicant
5173 * to take care of roaming
5175 brcmf_dbg(INFO
, "Internal Roaming = %s\n",
5176 brcmf_roamoff
? "Off" : "On");
5177 err
= brcmf_fil_iovar_int_set(ifp
, "roam_off", !!(brcmf_roamoff
));
5179 brcmf_err("roam_off error (%d)\n", err
);
5180 goto dongle_rom_out
;
5183 roamtrigger
[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL
);
5184 roamtrigger
[1] = cpu_to_le32(BRCM_BAND_ALL
);
5185 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_ROAM_TRIGGER
,
5186 (void *)roamtrigger
, sizeof(roamtrigger
));
5188 brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err
);
5189 goto dongle_rom_out
;
5192 roam_delta
[0] = cpu_to_le32(WL_ROAM_DELTA
);
5193 roam_delta
[1] = cpu_to_le32(BRCM_BAND_ALL
);
5194 err
= brcmf_fil_cmd_data_set(ifp
, BRCMF_C_SET_ROAM_DELTA
,
5195 (void *)roam_delta
, sizeof(roam_delta
));
5197 brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err
);
5198 goto dongle_rom_out
;
5206 brcmf_dongle_scantime(struct brcmf_if
*ifp
, s32 scan_assoc_time
,
5207 s32 scan_unassoc_time
, s32 scan_passive_time
)
5211 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_CHANNEL_TIME
,
5214 if (err
== -EOPNOTSUPP
)
5215 brcmf_dbg(INFO
, "Scan assoc time is not supported\n");
5217 brcmf_err("Scan assoc time error (%d)\n", err
);
5218 goto dongle_scantime_out
;
5220 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_UNASSOC_TIME
,
5223 if (err
== -EOPNOTSUPP
)
5224 brcmf_dbg(INFO
, "Scan unassoc time is not supported\n");
5226 brcmf_err("Scan unassoc time error (%d)\n", err
);
5227 goto dongle_scantime_out
;
5230 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_PASSIVE_TIME
,
5233 if (err
== -EOPNOTSUPP
)
5234 brcmf_dbg(INFO
, "Scan passive time is not supported\n");
5236 brcmf_err("Scan passive time error (%d)\n", err
);
5237 goto dongle_scantime_out
;
5240 dongle_scantime_out
:
5244 /* Filter the list of channels received from firmware counting only
5245 * the 20MHz channels. The wiphy band data only needs those which get
5246 * flagged to indicate if they can take part in higher bandwidth.
5248 static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info
*cfg
,
5249 struct brcmf_chanspec_list
*chlist
,
5252 u32 total
= le32_to_cpu(chlist
->count
);
5253 struct brcmu_chan ch
;
5256 for (i
= 0; i
< total
; i
++) {
5257 ch
.chspec
= (u16
)le32_to_cpu(chlist
->element
[i
]);
5258 cfg
->d11inf
.decchspec(&ch
);
5260 /* Firmware gives a ordered list. We skip non-20MHz
5261 * channels is 2G. For 5G we can abort upon reaching
5262 * a non-20MHz channel in the list.
5264 if (ch
.bw
!= BRCMU_CHAN_BW_20
) {
5265 if (ch
.band
== BRCMU_CHAN_BAND_5G
)
5271 if (ch
.band
== BRCMU_CHAN_BAND_2G
)
5273 else if (ch
.band
== BRCMU_CHAN_BAND_5G
)
5278 static void brcmf_update_bw40_channel_flag(struct ieee80211_channel
*channel
,
5279 struct brcmu_chan
*ch
)
5283 ht40_flag
= channel
->flags
& IEEE80211_CHAN_NO_HT40
;
5284 if (ch
->sb
== BRCMU_CHAN_SB_U
) {
5285 if (ht40_flag
== IEEE80211_CHAN_NO_HT40
)
5286 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40
;
5287 channel
->flags
|= IEEE80211_CHAN_NO_HT40PLUS
;
5289 /* It should be one of
5290 * IEEE80211_CHAN_NO_HT40 or
5291 * IEEE80211_CHAN_NO_HT40PLUS
5293 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40
;
5294 if (ht40_flag
== IEEE80211_CHAN_NO_HT40
)
5295 channel
->flags
|= IEEE80211_CHAN_NO_HT40MINUS
;
5299 static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info
*cfg
,
5302 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5303 struct ieee80211_supported_band
*band
;
5304 struct ieee80211_channel
*channel
;
5305 struct wiphy
*wiphy
;
5306 struct brcmf_chanspec_list
*list
;
5307 struct brcmu_chan ch
;
5313 u32 chcnt
[2] = { 0, 0 };
5316 pbuf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5321 list
= (struct brcmf_chanspec_list
*)pbuf
;
5323 err
= brcmf_fil_iovar_data_get(ifp
, "chanspecs", pbuf
,
5326 brcmf_err("get chanspecs error (%d)\n", err
);
5330 brcmf_count_20mhz_channels(cfg
, list
, chcnt
);
5331 wiphy
= cfg_to_wiphy(cfg
);
5333 band
= kmemdup(&__wl_band_2ghz
, sizeof(__wl_band_2ghz
),
5339 band
->channels
= kcalloc(chcnt
[0], sizeof(*channel
),
5341 if (band
->channels
== NULL
) {
5346 band
->n_channels
= 0;
5347 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
5350 band
= kmemdup(&__wl_band_5ghz_a
, sizeof(__wl_band_5ghz_a
),
5356 band
->channels
= kcalloc(chcnt
[1], sizeof(*channel
),
5358 if (band
->channels
== NULL
) {
5363 band
->n_channels
= 0;
5364 wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
5367 total
= le32_to_cpu(list
->count
);
5368 for (i
= 0; i
< total
; i
++) {
5369 ch
.chspec
= (u16
)le32_to_cpu(list
->element
[i
]);
5370 cfg
->d11inf
.decchspec(&ch
);
5372 if (ch
.band
== BRCMU_CHAN_BAND_2G
) {
5373 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
5374 } else if (ch
.band
== BRCMU_CHAN_BAND_5G
) {
5375 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
5377 brcmf_err("Invalid channel Spec. 0x%x.\n", ch
.chspec
);
5380 if (!(bw_cap
[band
->band
] & WLC_BW_40MHZ_BIT
) &&
5381 ch
.bw
== BRCMU_CHAN_BW_40
)
5383 if (!(bw_cap
[band
->band
] & WLC_BW_80MHZ_BIT
) &&
5384 ch
.bw
== BRCMU_CHAN_BW_80
)
5387 channel
= band
->channels
;
5388 index
= band
->n_channels
;
5389 for (j
= 0; j
< band
->n_channels
; j
++) {
5390 if (channel
[j
].hw_value
== ch
.chnum
) {
5395 channel
[index
].center_freq
=
5396 ieee80211_channel_to_frequency(ch
.chnum
, band
->band
);
5397 channel
[index
].hw_value
= ch
.chnum
;
5399 /* assuming the chanspecs order is HT20,
5400 * HT40 upper, HT40 lower, and VHT80.
5402 if (ch
.bw
== BRCMU_CHAN_BW_80
) {
5403 channel
[index
].flags
&= ~IEEE80211_CHAN_NO_80MHZ
;
5404 } else if (ch
.bw
== BRCMU_CHAN_BW_40
) {
5405 brcmf_update_bw40_channel_flag(&channel
[index
], &ch
);
5407 /* disable other bandwidths for now as mentioned
5408 * order assure they are enabled for subsequent
5411 channel
[index
].flags
= IEEE80211_CHAN_NO_HT40
|
5412 IEEE80211_CHAN_NO_80MHZ
;
5413 ch
.bw
= BRCMU_CHAN_BW_20
;
5414 cfg
->d11inf
.encchspec(&ch
);
5415 chaninfo
= ch
.chspec
;
5416 err
= brcmf_fil_bsscfg_int_get(ifp
, "per_chan_info",
5419 if (chaninfo
& WL_CHAN_RADAR
)
5420 channel
[index
].flags
|=
5421 (IEEE80211_CHAN_RADAR
|
5422 IEEE80211_CHAN_NO_IR
);
5423 if (chaninfo
& WL_CHAN_PASSIVE
)
5424 channel
[index
].flags
|=
5425 IEEE80211_CHAN_NO_IR
;
5428 if (index
== band
->n_channels
)
5435 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]->channels
);
5436 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]);
5437 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
5443 static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info
*cfg
)
5445 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5446 struct ieee80211_supported_band
*band
;
5447 struct brcmf_fil_bwcap_le band_bwcap
;
5448 struct brcmf_chanspec_list
*list
;
5452 struct brcmu_chan ch
;
5456 /* verify support for bw_cap command */
5458 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &val
);
5461 /* only set 2G bandwidth using bw_cap command */
5462 band_bwcap
.band
= cpu_to_le32(WLC_BAND_2G
);
5463 band_bwcap
.bw_cap
= cpu_to_le32(WLC_BW_CAP_40MHZ
);
5464 err
= brcmf_fil_iovar_data_set(ifp
, "bw_cap", &band_bwcap
,
5465 sizeof(band_bwcap
));
5467 brcmf_dbg(INFO
, "fallback to mimo_bw_cap\n");
5468 val
= WLC_N_BW_40ALL
;
5469 err
= brcmf_fil_iovar_int_set(ifp
, "mimo_bw_cap", val
);
5473 /* update channel info in 2G band */
5474 pbuf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
5479 ch
.band
= BRCMU_CHAN_BAND_2G
;
5480 ch
.bw
= BRCMU_CHAN_BW_40
;
5481 ch
.sb
= BRCMU_CHAN_SB_NONE
;
5483 cfg
->d11inf
.encchspec(&ch
);
5485 /* pass encoded chanspec in query */
5486 *(__le16
*)pbuf
= cpu_to_le16(ch
.chspec
);
5488 err
= brcmf_fil_iovar_data_get(ifp
, "chanspecs", pbuf
,
5491 brcmf_err("get chanspecs error (%d)\n", err
);
5496 band
= cfg_to_wiphy(cfg
)->bands
[IEEE80211_BAND_2GHZ
];
5497 list
= (struct brcmf_chanspec_list
*)pbuf
;
5498 num_chan
= le32_to_cpu(list
->count
);
5499 for (i
= 0; i
< num_chan
; i
++) {
5500 ch
.chspec
= (u16
)le32_to_cpu(list
->element
[i
]);
5501 cfg
->d11inf
.decchspec(&ch
);
5502 if (WARN_ON(ch
.band
!= BRCMU_CHAN_BAND_2G
))
5504 if (WARN_ON(ch
.bw
!= BRCMU_CHAN_BW_40
))
5506 for (j
= 0; j
< band
->n_channels
; j
++) {
5507 if (band
->channels
[j
].hw_value
== ch
.chnum
)
5510 if (WARN_ON(j
== band
->n_channels
))
5513 brcmf_update_bw40_channel_flag(&band
->channels
[j
], &ch
);
5520 static void brcmf_get_bwcap(struct brcmf_if
*ifp
, u32 bw_cap
[])
5522 u32 band
, mimo_bwcap
;
5526 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &band
);
5528 bw_cap
[IEEE80211_BAND_2GHZ
] = band
;
5530 err
= brcmf_fil_iovar_int_get(ifp
, "bw_cap", &band
);
5532 bw_cap
[IEEE80211_BAND_5GHZ
] = band
;
5538 brcmf_dbg(INFO
, "fallback to mimo_bw_cap info\n");
5540 err
= brcmf_fil_iovar_int_get(ifp
, "mimo_bw_cap", &mimo_bwcap
);
5542 /* assume 20MHz if firmware does not give a clue */
5543 mimo_bwcap
= WLC_N_BW_20ALL
;
5545 switch (mimo_bwcap
) {
5546 case WLC_N_BW_40ALL
:
5547 bw_cap
[IEEE80211_BAND_2GHZ
] |= WLC_BW_40MHZ_BIT
;
5549 case WLC_N_BW_20IN2G_40IN5G
:
5550 bw_cap
[IEEE80211_BAND_5GHZ
] |= WLC_BW_40MHZ_BIT
;
5552 case WLC_N_BW_20ALL
:
5553 bw_cap
[IEEE80211_BAND_2GHZ
] |= WLC_BW_20MHZ_BIT
;
5554 bw_cap
[IEEE80211_BAND_5GHZ
] |= WLC_BW_20MHZ_BIT
;
5557 brcmf_err("invalid mimo_bw_cap value\n");
5561 static void brcmf_update_ht_cap(struct ieee80211_supported_band
*band
,
5562 u32 bw_cap
[2], u32 nchain
)
5564 band
->ht_cap
.ht_supported
= true;
5565 if (bw_cap
[band
->band
] & WLC_BW_40MHZ_BIT
) {
5566 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
5567 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
5569 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
5570 band
->ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
5571 band
->ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
5572 band
->ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
5573 memset(band
->ht_cap
.mcs
.rx_mask
, 0xff, nchain
);
5574 band
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
5577 static __le16
brcmf_get_mcs_map(u32 nchain
, enum ieee80211_vht_mcs_support supp
)
5582 for (i
= 0, mcs_map
= 0xFFFF; i
< nchain
; i
++)
5583 mcs_map
= (mcs_map
<< 2) | supp
;
5585 return cpu_to_le16(mcs_map
);
5588 static void brcmf_update_vht_cap(struct ieee80211_supported_band
*band
,
5589 u32 bw_cap
[2], u32 nchain
)
5593 /* not allowed in 2.4G band */
5594 if (band
->band
== IEEE80211_BAND_2GHZ
)
5597 band
->vht_cap
.vht_supported
= true;
5598 /* 80MHz is mandatory */
5599 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SHORT_GI_80
;
5600 if (bw_cap
[band
->band
] & WLC_BW_160MHZ_BIT
) {
5601 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
5602 band
->vht_cap
.cap
|= IEEE80211_VHT_CAP_SHORT_GI_160
;
5604 /* all support 256-QAM */
5605 mcs_map
= brcmf_get_mcs_map(nchain
, IEEE80211_VHT_MCS_SUPPORT_0_9
);
5606 band
->vht_cap
.vht_mcs
.rx_mcs_map
= mcs_map
;
5607 band
->vht_cap
.vht_mcs
.tx_mcs_map
= mcs_map
;
5610 static int brcmf_setup_wiphybands(struct wiphy
*wiphy
)
5612 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
5613 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5616 u32 bw_cap
[2] = { WLC_BW_20MHZ_BIT
, WLC_BW_20MHZ_BIT
};
5621 struct ieee80211_supported_band
*band
;
5623 (void)brcmf_fil_iovar_int_get(ifp
, "vhtmode", &vhtmode
);
5624 err
= brcmf_fil_iovar_int_get(ifp
, "nmode", &nmode
);
5626 brcmf_err("nmode error (%d)\n", err
);
5628 brcmf_get_bwcap(ifp
, bw_cap
);
5630 brcmf_dbg(INFO
, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
5631 nmode
, vhtmode
, bw_cap
[IEEE80211_BAND_2GHZ
],
5632 bw_cap
[IEEE80211_BAND_5GHZ
]);
5634 err
= brcmf_fil_iovar_int_get(ifp
, "rxchain", &rxchain
);
5636 brcmf_err("rxchain error (%d)\n", err
);
5639 for (nchain
= 0; rxchain
; nchain
++)
5640 rxchain
= rxchain
& (rxchain
- 1);
5642 brcmf_dbg(INFO
, "nchain=%d\n", nchain
);
5644 err
= brcmf_construct_chaninfo(cfg
, bw_cap
);
5646 brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err
);
5650 wiphy
= cfg_to_wiphy(cfg
);
5651 for (i
= 0; i
< ARRAY_SIZE(wiphy
->bands
); i
++) {
5652 band
= wiphy
->bands
[i
];
5657 brcmf_update_ht_cap(band
, bw_cap
, nchain
);
5659 brcmf_update_vht_cap(band
, bw_cap
, nchain
);
5665 static const struct ieee80211_iface_limit brcmf_iface_limits_mbss
[] = {
5668 .types
= BIT(NL80211_IFTYPE_STATION
) |
5669 BIT(NL80211_IFTYPE_ADHOC
)
5673 .types
= BIT(NL80211_IFTYPE_AP
)
5677 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5678 BIT(NL80211_IFTYPE_P2P_GO
)
5682 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5686 static const struct ieee80211_iface_limit brcmf_iface_limits_sbss
[] = {
5689 .types
= BIT(NL80211_IFTYPE_STATION
) |
5690 BIT(NL80211_IFTYPE_ADHOC
) |
5691 BIT(NL80211_IFTYPE_AP
)
5695 .types
= BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5696 BIT(NL80211_IFTYPE_P2P_GO
)
5700 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
)
5703 static struct ieee80211_iface_combination brcmf_iface_combos
[] = {
5705 .max_interfaces
= BRCMF_IFACE_MAX_CNT
,
5706 .num_different_channels
= 1,
5707 .n_limits
= ARRAY_SIZE(brcmf_iface_limits_sbss
),
5708 .limits
= brcmf_iface_limits_sbss
,
5712 static const struct ieee80211_txrx_stypes
5713 brcmf_txrx_stypes
[NUM_NL80211_IFTYPES
] = {
5714 [NL80211_IFTYPE_STATION
] = {
5716 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5717 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5719 [NL80211_IFTYPE_P2P_CLIENT
] = {
5721 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5722 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5724 [NL80211_IFTYPE_P2P_GO
] = {
5726 .rx
= BIT(IEEE80211_STYPE_ASSOC_REQ
>> 4) |
5727 BIT(IEEE80211_STYPE_REASSOC_REQ
>> 4) |
5728 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4) |
5729 BIT(IEEE80211_STYPE_DISASSOC
>> 4) |
5730 BIT(IEEE80211_STYPE_AUTH
>> 4) |
5731 BIT(IEEE80211_STYPE_DEAUTH
>> 4) |
5732 BIT(IEEE80211_STYPE_ACTION
>> 4)
5734 [NL80211_IFTYPE_P2P_DEVICE
] = {
5736 .rx
= BIT(IEEE80211_STYPE_ACTION
>> 4) |
5737 BIT(IEEE80211_STYPE_PROBE_REQ
>> 4)
5741 static void brcmf_wiphy_pno_params(struct wiphy
*wiphy
)
5743 /* scheduled scan settings */
5744 wiphy
->max_sched_scan_ssids
= BRCMF_PNO_MAX_PFN_COUNT
;
5745 wiphy
->max_match_sets
= BRCMF_PNO_MAX_PFN_COUNT
;
5746 wiphy
->max_sched_scan_ie_len
= BRCMF_SCAN_IE_LEN_MAX
;
5747 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
5751 static const struct wiphy_wowlan_support brcmf_wowlan_support
= {
5752 .flags
= WIPHY_WOWLAN_MAGIC_PKT
| WIPHY_WOWLAN_DISCONNECT
,
5753 .n_patterns
= BRCMF_WOWL_MAXPATTERNS
,
5754 .pattern_max_len
= BRCMF_WOWL_MAXPATTERNSIZE
,
5755 .pattern_min_len
= 1,
5756 .max_pkt_offset
= 1500,
5760 static void brcmf_wiphy_wowl_params(struct wiphy
*wiphy
)
5764 wiphy
->wowlan
= &brcmf_wowlan_support
;
5768 static int brcmf_setup_wiphy(struct wiphy
*wiphy
, struct brcmf_if
*ifp
)
5770 struct ieee80211_iface_combination ifc_combo
;
5771 wiphy
->max_scan_ssids
= WL_NUM_SCAN_MAX
;
5772 wiphy
->max_scan_ie_len
= BRCMF_SCAN_IE_LEN_MAX
;
5773 wiphy
->max_num_pmkids
= WL_NUM_PMKIDS_MAX
;
5774 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5775 BIT(NL80211_IFTYPE_ADHOC
) |
5776 BIT(NL80211_IFTYPE_AP
) |
5777 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
5778 BIT(NL80211_IFTYPE_P2P_GO
) |
5779 BIT(NL80211_IFTYPE_P2P_DEVICE
);
5780 /* need VSDB firmware feature for concurrent channels */
5781 ifc_combo
= brcmf_iface_combos
[0];
5782 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_MCHAN
))
5783 ifc_combo
.num_different_channels
= 2;
5784 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_MBSS
)) {
5785 ifc_combo
.n_limits
= ARRAY_SIZE(brcmf_iface_limits_mbss
),
5786 ifc_combo
.limits
= brcmf_iface_limits_mbss
;
5788 wiphy
->iface_combinations
= kmemdup(&ifc_combo
,
5791 wiphy
->n_iface_combinations
= ARRAY_SIZE(brcmf_iface_combos
);
5792 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
5793 wiphy
->cipher_suites
= __wl_cipher_suites
;
5794 wiphy
->n_cipher_suites
= ARRAY_SIZE(__wl_cipher_suites
);
5795 wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
|
5796 WIPHY_FLAG_OFFCHAN_TX
|
5797 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
|
5798 WIPHY_FLAG_SUPPORTS_TDLS
;
5800 wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_FW_ROAM
;
5801 wiphy
->mgmt_stypes
= brcmf_txrx_stypes
;
5802 wiphy
->max_remain_on_channel_duration
= 5000;
5803 brcmf_wiphy_pno_params(wiphy
);
5805 /* vendor commands/events support */
5806 wiphy
->vendor_commands
= brcmf_vendor_cmds
;
5807 wiphy
->n_vendor_commands
= BRCMF_VNDR_CMDS_LAST
- 1;
5809 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_WOWL
))
5810 brcmf_wiphy_wowl_params(wiphy
);
5812 return brcmf_setup_wiphybands(wiphy
);
5815 static s32
brcmf_config_dongle(struct brcmf_cfg80211_info
*cfg
)
5817 struct net_device
*ndev
;
5818 struct wireless_dev
*wdev
;
5819 struct brcmf_if
*ifp
;
5826 ndev
= cfg_to_ndev(cfg
);
5827 wdev
= ndev
->ieee80211_ptr
;
5828 ifp
= netdev_priv(ndev
);
5830 /* make sure RF is ready for work */
5831 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
5833 brcmf_dongle_scantime(ifp
, WL_SCAN_CHANNEL_TIME
,
5834 WL_SCAN_UNASSOC_TIME
, WL_SCAN_PASSIVE_TIME
);
5836 power_mode
= cfg
->pwr_save
? PM_FAST
: PM_OFF
;
5837 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PM
, power_mode
);
5839 goto default_conf_out
;
5840 brcmf_dbg(INFO
, "power save set to %s\n",
5841 (power_mode
? "enabled" : "disabled"));
5843 err
= brcmf_dongle_roam(ifp
, WL_BEACON_TIMEOUT
);
5845 goto default_conf_out
;
5846 err
= brcmf_cfg80211_change_iface(wdev
->wiphy
, ndev
, wdev
->iftype
,
5849 goto default_conf_out
;
5851 brcmf_configure_arp_offload(ifp
, true);
5853 cfg
->dongle_up
= true;
5860 static s32
__brcmf_cfg80211_up(struct brcmf_if
*ifp
)
5862 set_bit(BRCMF_VIF_STATUS_READY
, &ifp
->vif
->sme_state
);
5864 return brcmf_config_dongle(ifp
->drvr
->config
);
5867 static s32
__brcmf_cfg80211_down(struct brcmf_if
*ifp
)
5869 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5872 * While going down, if associated with AP disassociate
5873 * from AP to save power
5875 if (check_vif_up(ifp
->vif
)) {
5876 brcmf_link_down(ifp
->vif
);
5878 /* Make sure WPA_Supplicant receives all the event
5879 generated due to DISASSOC call to the fw to keep
5880 the state fw and WPA_Supplicant state consistent
5885 brcmf_abort_scanning(cfg
);
5886 clear_bit(BRCMF_VIF_STATUS_READY
, &ifp
->vif
->sme_state
);
5891 s32
brcmf_cfg80211_up(struct net_device
*ndev
)
5893 struct brcmf_if
*ifp
= netdev_priv(ndev
);
5894 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5897 mutex_lock(&cfg
->usr_sync
);
5898 err
= __brcmf_cfg80211_up(ifp
);
5899 mutex_unlock(&cfg
->usr_sync
);
5904 s32
brcmf_cfg80211_down(struct net_device
*ndev
)
5906 struct brcmf_if
*ifp
= netdev_priv(ndev
);
5907 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
5910 mutex_lock(&cfg
->usr_sync
);
5911 err
= __brcmf_cfg80211_down(ifp
);
5912 mutex_unlock(&cfg
->usr_sync
);
5917 enum nl80211_iftype
brcmf_cfg80211_get_iftype(struct brcmf_if
*ifp
)
5919 struct wireless_dev
*wdev
= &ifp
->vif
->wdev
;
5921 return wdev
->iftype
;
5924 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info
*cfg
,
5925 unsigned long state
)
5927 struct brcmf_cfg80211_vif
*vif
;
5929 list_for_each_entry(vif
, &cfg
->vif_list
, list
) {
5930 if (test_bit(state
, &vif
->sme_state
))
5936 static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event
*event
,
5941 mutex_lock(&event
->vif_event_lock
);
5942 evt_action
= event
->action
;
5943 mutex_unlock(&event
->vif_event_lock
);
5944 return evt_action
== action
;
5947 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info
*cfg
,
5948 struct brcmf_cfg80211_vif
*vif
)
5950 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5952 mutex_lock(&event
->vif_event_lock
);
5955 mutex_unlock(&event
->vif_event_lock
);
5958 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info
*cfg
)
5960 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5963 mutex_lock(&event
->vif_event_lock
);
5964 armed
= event
->vif
!= NULL
;
5965 mutex_unlock(&event
->vif_event_lock
);
5969 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info
*cfg
,
5970 u8 action
, ulong timeout
)
5972 struct brcmf_cfg80211_vif_event
*event
= &cfg
->vif_event
;
5974 return wait_event_timeout(event
->vif_wq
,
5975 vif_event_equals(event
, action
), timeout
);
5978 static void brcmf_cfg80211_reg_notifier(struct wiphy
*wiphy
,
5979 struct regulatory_request
*req
)
5981 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
5982 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
5983 struct brcmf_fil_country_le ccreq
;
5986 brcmf_dbg(TRACE
, "enter: initiator=%d, alpha=%c%c\n", req
->initiator
,
5987 req
->alpha2
[0], req
->alpha2
[1]);
5989 /* ignore non-ISO3166 country codes */
5990 for (i
= 0; i
< sizeof(req
->alpha2
); i
++)
5991 if (req
->alpha2
[i
] < 'A' || req
->alpha2
[i
] > 'Z') {
5992 brcmf_err("not a ISO3166 code\n");
5995 memset(&ccreq
, 0, sizeof(ccreq
));
5996 ccreq
.rev
= cpu_to_le32(-1);
5997 memcpy(ccreq
.ccode
, req
->alpha2
, sizeof(req
->alpha2
));
5998 brcmf_fil_iovar_data_set(ifp
, "country", &ccreq
, sizeof(ccreq
));
6001 static void brcmf_free_wiphy(struct wiphy
*wiphy
)
6003 kfree(wiphy
->iface_combinations
);
6004 if (wiphy
->bands
[IEEE80211_BAND_2GHZ
]) {
6005 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]->channels
);
6006 kfree(wiphy
->bands
[IEEE80211_BAND_2GHZ
]);
6008 if (wiphy
->bands
[IEEE80211_BAND_5GHZ
]) {
6009 kfree(wiphy
->bands
[IEEE80211_BAND_5GHZ
]->channels
);
6010 kfree(wiphy
->bands
[IEEE80211_BAND_5GHZ
]);
6015 struct brcmf_cfg80211_info
*brcmf_cfg80211_attach(struct brcmf_pub
*drvr
,
6016 struct device
*busdev
)
6018 struct net_device
*ndev
= drvr
->iflist
[0]->ndev
;
6019 struct brcmf_cfg80211_info
*cfg
;
6020 struct wiphy
*wiphy
;
6021 struct brcmf_cfg80211_vif
*vif
;
6022 struct brcmf_if
*ifp
;
6028 brcmf_err("ndev is invalid\n");
6032 ifp
= netdev_priv(ndev
);
6033 wiphy
= wiphy_new(&wl_cfg80211_ops
, sizeof(struct brcmf_cfg80211_info
));
6035 brcmf_err("Could not allocate wiphy device\n");
6038 set_wiphy_dev(wiphy
, busdev
);
6040 cfg
= wiphy_priv(wiphy
);
6043 init_vif_event(&cfg
->vif_event
);
6044 INIT_LIST_HEAD(&cfg
->vif_list
);
6046 vif
= brcmf_alloc_vif(cfg
, NL80211_IFTYPE_STATION
, false);
6051 vif
->wdev
.netdev
= ndev
;
6052 ndev
->ieee80211_ptr
= &vif
->wdev
;
6053 SET_NETDEV_DEV(ndev
, wiphy_dev(cfg
->wiphy
));
6055 err
= wl_init_priv(cfg
);
6057 brcmf_err("Failed to init iwm_priv (%d)\n", err
);
6058 brcmf_free_vif(vif
);
6063 /* determine d11 io type before wiphy setup */
6064 err
= brcmf_fil_cmd_int_get(ifp
, BRCMF_C_GET_VERSION
, &io_type
);
6066 brcmf_err("Failed to get D11 version (%d)\n", err
);
6069 cfg
->d11inf
.io_type
= (u8
)io_type
;
6070 brcmu_d11_attach(&cfg
->d11inf
);
6072 err
= brcmf_setup_wiphy(wiphy
, ifp
);
6076 brcmf_dbg(INFO
, "Registering custom regulatory\n");
6077 wiphy
->reg_notifier
= brcmf_cfg80211_reg_notifier
;
6078 wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
;
6079 wiphy_apply_custom_regulatory(wiphy
, &brcmf_regdom
);
6081 /* firmware defaults to 40MHz disabled in 2G band. We signal
6082 * cfg80211 here that we do and have it decide we can enable
6083 * it. But first check if device does support 2G operation.
6085 if (wiphy
->bands
[IEEE80211_BAND_2GHZ
]) {
6086 cap
= &wiphy
->bands
[IEEE80211_BAND_2GHZ
]->ht_cap
.cap
;
6087 *cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
6089 err
= wiphy_register(wiphy
);
6091 brcmf_err("Could not register wiphy device (%d)\n", err
);
6095 /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
6096 * setup 40MHz in 2GHz band and enable OBSS scanning.
6098 if (cap
&& (*cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)) {
6099 err
= brcmf_enable_bw40_2g(cfg
);
6101 err
= brcmf_fil_iovar_int_set(ifp
, "obss_coex",
6102 BRCMF_OBSS_COEX_AUTO
);
6104 *cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
6107 err
= brcmf_p2p_attach(cfg
);
6109 brcmf_err("P2P initilisation failed (%d)\n", err
);
6110 goto wiphy_unreg_out
;
6112 err
= brcmf_btcoex_attach(cfg
);
6114 brcmf_err("BT-coex initialisation failed (%d)\n", err
);
6115 brcmf_p2p_detach(&cfg
->p2p
);
6116 goto wiphy_unreg_out
;
6119 err
= brcmf_fil_iovar_int_set(ifp
, "tdls_enable", 1);
6121 brcmf_dbg(INFO
, "TDLS not enabled (%d)\n", err
);
6122 wiphy
->flags
&= ~WIPHY_FLAG_SUPPORTS_TDLS
;
6124 brcmf_fweh_register(cfg
->pub
, BRCMF_E_TDLS_PEER_EVENT
,
6125 brcmf_notify_tdls_peer_event
);
6131 wiphy_unregister(cfg
->wiphy
);
6133 wl_deinit_priv(cfg
);
6134 brcmf_free_vif(vif
);
6136 brcmf_free_wiphy(wiphy
);
6140 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info
*cfg
)
6145 WARN_ON(!list_empty(&cfg
->vif_list
));
6146 wiphy_unregister(cfg
->wiphy
);
6147 brcmf_btcoex_detach(cfg
);
6148 brcmf_p2p_detach(&cfg
->p2p
);
6149 wl_deinit_priv(cfg
);
6150 brcmf_free_wiphy(cfg
->wiphy
);