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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/kernel.h>
22 #include <linux/if_arp.h>
23 #include <linux/sched.h>
24 #include <linux/kthread.h>
25 #include <linux/netdevice.h>
26 #include <linux/bitops.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ieee80211.h>
29 #include <linux/uaccess.h>
30 #include <net/cfg80211.h>
31 #include <net/netlink.h>
33 #include <brcmu_utils.h>
35 #include <brcmu_wifi.h>
37 #include "wl_cfg80211.h"
39 #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
40 (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
42 static const u8 ether_bcast
[ETH_ALEN
] = {255, 255, 255, 255, 255, 255};
44 static u32 brcmf_dbg_level
= WL_DBG_ERR
;
46 static void brcmf_set_drvdata(struct brcmf_cfg80211_dev
*dev
, void *data
)
48 dev
->driver_data
= data
;
51 static void *brcmf_get_drvdata(struct brcmf_cfg80211_dev
*dev
)
56 data
= dev
->driver_data
;
61 struct brcmf_cfg80211_priv
*brcmf_priv_get(struct brcmf_cfg80211_dev
*cfg_dev
)
63 struct brcmf_cfg80211_iface
*ci
= brcmf_get_drvdata(cfg_dev
);
67 static bool check_sys_up(struct wiphy
*wiphy
)
69 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
70 if (!test_bit(WL_STATUS_READY
, &cfg_priv
->status
)) {
71 WL_INFO("device is not ready : status (%d)\n",
72 (int)cfg_priv
->status
);
78 #define CHAN2G(_channel, _freq, _flags) { \
79 .band = IEEE80211_BAND_2GHZ, \
80 .center_freq = (_freq), \
81 .hw_value = (_channel), \
83 .max_antenna_gain = 0, \
87 #define CHAN5G(_channel, _flags) { \
88 .band = IEEE80211_BAND_5GHZ, \
89 .center_freq = 5000 + (5 * (_channel)), \
90 .hw_value = (_channel), \
92 .max_antenna_gain = 0, \
96 #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
97 #define RATETAB_ENT(_rateid, _flags) \
99 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
100 .hw_value = (_rateid), \
104 static struct ieee80211_rate __wl_rates
[] = {
105 RATETAB_ENT(BRCM_RATE_1M
, 0),
106 RATETAB_ENT(BRCM_RATE_2M
, IEEE80211_RATE_SHORT_PREAMBLE
),
107 RATETAB_ENT(BRCM_RATE_5M5
, IEEE80211_RATE_SHORT_PREAMBLE
),
108 RATETAB_ENT(BRCM_RATE_11M
, IEEE80211_RATE_SHORT_PREAMBLE
),
109 RATETAB_ENT(BRCM_RATE_6M
, 0),
110 RATETAB_ENT(BRCM_RATE_9M
, 0),
111 RATETAB_ENT(BRCM_RATE_12M
, 0),
112 RATETAB_ENT(BRCM_RATE_18M
, 0),
113 RATETAB_ENT(BRCM_RATE_24M
, 0),
114 RATETAB_ENT(BRCM_RATE_36M
, 0),
115 RATETAB_ENT(BRCM_RATE_48M
, 0),
116 RATETAB_ENT(BRCM_RATE_54M
, 0),
119 #define wl_a_rates (__wl_rates + 4)
120 #define wl_a_rates_size 8
121 #define wl_g_rates (__wl_rates + 0)
122 #define wl_g_rates_size 12
124 static struct ieee80211_channel __wl_2ghz_channels
[] = {
141 static struct ieee80211_channel __wl_5ghz_a_channels
[] = {
142 CHAN5G(34, 0), CHAN5G(36, 0),
143 CHAN5G(38, 0), CHAN5G(40, 0),
144 CHAN5G(42, 0), CHAN5G(44, 0),
145 CHAN5G(46, 0), CHAN5G(48, 0),
146 CHAN5G(52, 0), CHAN5G(56, 0),
147 CHAN5G(60, 0), CHAN5G(64, 0),
148 CHAN5G(100, 0), CHAN5G(104, 0),
149 CHAN5G(108, 0), CHAN5G(112, 0),
150 CHAN5G(116, 0), CHAN5G(120, 0),
151 CHAN5G(124, 0), CHAN5G(128, 0),
152 CHAN5G(132, 0), CHAN5G(136, 0),
153 CHAN5G(140, 0), CHAN5G(149, 0),
154 CHAN5G(153, 0), CHAN5G(157, 0),
155 CHAN5G(161, 0), CHAN5G(165, 0),
156 CHAN5G(184, 0), CHAN5G(188, 0),
157 CHAN5G(192, 0), CHAN5G(196, 0),
158 CHAN5G(200, 0), CHAN5G(204, 0),
159 CHAN5G(208, 0), CHAN5G(212, 0),
163 static struct ieee80211_channel __wl_5ghz_n_channels
[] = {
164 CHAN5G(32, 0), CHAN5G(34, 0),
165 CHAN5G(36, 0), CHAN5G(38, 0),
166 CHAN5G(40, 0), CHAN5G(42, 0),
167 CHAN5G(44, 0), CHAN5G(46, 0),
168 CHAN5G(48, 0), CHAN5G(50, 0),
169 CHAN5G(52, 0), CHAN5G(54, 0),
170 CHAN5G(56, 0), CHAN5G(58, 0),
171 CHAN5G(60, 0), CHAN5G(62, 0),
172 CHAN5G(64, 0), CHAN5G(66, 0),
173 CHAN5G(68, 0), CHAN5G(70, 0),
174 CHAN5G(72, 0), CHAN5G(74, 0),
175 CHAN5G(76, 0), CHAN5G(78, 0),
176 CHAN5G(80, 0), CHAN5G(82, 0),
177 CHAN5G(84, 0), CHAN5G(86, 0),
178 CHAN5G(88, 0), CHAN5G(90, 0),
179 CHAN5G(92, 0), CHAN5G(94, 0),
180 CHAN5G(96, 0), CHAN5G(98, 0),
181 CHAN5G(100, 0), CHAN5G(102, 0),
182 CHAN5G(104, 0), CHAN5G(106, 0),
183 CHAN5G(108, 0), CHAN5G(110, 0),
184 CHAN5G(112, 0), CHAN5G(114, 0),
185 CHAN5G(116, 0), CHAN5G(118, 0),
186 CHAN5G(120, 0), CHAN5G(122, 0),
187 CHAN5G(124, 0), CHAN5G(126, 0),
188 CHAN5G(128, 0), CHAN5G(130, 0),
189 CHAN5G(132, 0), CHAN5G(134, 0),
190 CHAN5G(136, 0), CHAN5G(138, 0),
191 CHAN5G(140, 0), CHAN5G(142, 0),
192 CHAN5G(144, 0), CHAN5G(145, 0),
193 CHAN5G(146, 0), CHAN5G(147, 0),
194 CHAN5G(148, 0), CHAN5G(149, 0),
195 CHAN5G(150, 0), CHAN5G(151, 0),
196 CHAN5G(152, 0), CHAN5G(153, 0),
197 CHAN5G(154, 0), CHAN5G(155, 0),
198 CHAN5G(156, 0), CHAN5G(157, 0),
199 CHAN5G(158, 0), CHAN5G(159, 0),
200 CHAN5G(160, 0), CHAN5G(161, 0),
201 CHAN5G(162, 0), CHAN5G(163, 0),
202 CHAN5G(164, 0), CHAN5G(165, 0),
203 CHAN5G(166, 0), CHAN5G(168, 0),
204 CHAN5G(170, 0), CHAN5G(172, 0),
205 CHAN5G(174, 0), CHAN5G(176, 0),
206 CHAN5G(178, 0), CHAN5G(180, 0),
207 CHAN5G(182, 0), CHAN5G(184, 0),
208 CHAN5G(186, 0), CHAN5G(188, 0),
209 CHAN5G(190, 0), CHAN5G(192, 0),
210 CHAN5G(194, 0), CHAN5G(196, 0),
211 CHAN5G(198, 0), CHAN5G(200, 0),
212 CHAN5G(202, 0), CHAN5G(204, 0),
213 CHAN5G(206, 0), CHAN5G(208, 0),
214 CHAN5G(210, 0), CHAN5G(212, 0),
215 CHAN5G(214, 0), CHAN5G(216, 0),
216 CHAN5G(218, 0), CHAN5G(220, 0),
217 CHAN5G(222, 0), CHAN5G(224, 0),
218 CHAN5G(226, 0), CHAN5G(228, 0),
221 static struct ieee80211_supported_band __wl_band_2ghz
= {
222 .band
= IEEE80211_BAND_2GHZ
,
223 .channels
= __wl_2ghz_channels
,
224 .n_channels
= ARRAY_SIZE(__wl_2ghz_channels
),
225 .bitrates
= wl_g_rates
,
226 .n_bitrates
= wl_g_rates_size
,
229 static struct ieee80211_supported_band __wl_band_5ghz_a
= {
230 .band
= IEEE80211_BAND_5GHZ
,
231 .channels
= __wl_5ghz_a_channels
,
232 .n_channels
= ARRAY_SIZE(__wl_5ghz_a_channels
),
233 .bitrates
= wl_a_rates
,
234 .n_bitrates
= wl_a_rates_size
,
237 static struct ieee80211_supported_band __wl_band_5ghz_n
= {
238 .band
= IEEE80211_BAND_5GHZ
,
239 .channels
= __wl_5ghz_n_channels
,
240 .n_channels
= ARRAY_SIZE(__wl_5ghz_n_channels
),
241 .bitrates
= wl_a_rates
,
242 .n_bitrates
= wl_a_rates_size
,
245 static const u32 __wl_cipher_suites
[] = {
246 WLAN_CIPHER_SUITE_WEP40
,
247 WLAN_CIPHER_SUITE_WEP104
,
248 WLAN_CIPHER_SUITE_TKIP
,
249 WLAN_CIPHER_SUITE_CCMP
,
250 WLAN_CIPHER_SUITE_AES_CMAC
,
253 /* tag_ID/length/value_buffer tuple */
260 /* Quarter dBm units to mW
261 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
262 * Table is offset so the last entry is largest mW value that fits in
266 #define QDBM_OFFSET 153 /* Offset for first entry */
267 #define QDBM_TABLE_LEN 40 /* Table size */
269 /* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
270 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
272 #define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
274 /* Largest mW value that will round down to the last table entry,
275 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
276 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
277 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
279 #define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
281 static const u16 nqdBm_to_mW_map
[QDBM_TABLE_LEN
] = {
282 /* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
283 /* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
284 /* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
285 /* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
286 /* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
287 /* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
290 static u16
brcmf_qdbm_to_mw(u8 qdbm
)
293 int idx
= qdbm
- QDBM_OFFSET
;
295 if (idx
>= QDBM_TABLE_LEN
)
296 /* clamp to max u16 mW value */
299 /* scale the qdBm index up to the range of the table 0-40
300 * where an offset of 40 qdBm equals a factor of 10 mW.
307 /* return the mW value scaled down to the correct factor of 10,
308 * adding in factor/2 to get proper rounding.
310 return (nqdBm_to_mW_map
[idx
] + factor
/ 2) / factor
;
313 static u8
brcmf_mw_to_qdbm(u16 mw
)
320 /* handle boundary case */
324 offset
= QDBM_OFFSET
;
326 /* move mw into the range of the table */
327 while (mw_uint
< QDBM_TABLE_LOW_BOUND
) {
332 for (qdbm
= 0; qdbm
< QDBM_TABLE_LEN
- 1; qdbm
++) {
333 boundary
= nqdBm_to_mW_map
[qdbm
] + (nqdBm_to_mW_map
[qdbm
+ 1] -
334 nqdBm_to_mW_map
[qdbm
]) / 2;
335 if (mw_uint
< boundary
)
344 /* function for reading/writing a single u32 from/to the dongle */
346 brcmf_exec_dcmd_u32(struct net_device
*ndev
, u32 cmd
, u32
*par
)
349 __le32 par_le
= cpu_to_le32(*par
);
351 err
= brcmf_exec_dcmd(ndev
, cmd
, &par_le
, sizeof(__le32
));
352 *par
= le32_to_cpu(par_le
);
357 static void convert_key_from_CPU(struct brcmf_wsec_key
*key
,
358 struct brcmf_wsec_key_le
*key_le
)
360 key_le
->index
= cpu_to_le32(key
->index
);
361 key_le
->len
= cpu_to_le32(key
->len
);
362 key_le
->algo
= cpu_to_le32(key
->algo
);
363 key_le
->flags
= cpu_to_le32(key
->flags
);
364 key_le
->rxiv
.hi
= cpu_to_le32(key
->rxiv
.hi
);
365 key_le
->rxiv
.lo
= cpu_to_le16(key
->rxiv
.lo
);
366 key_le
->iv_initialized
= cpu_to_le32(key
->iv_initialized
);
367 memcpy(key_le
->data
, key
->data
, sizeof(key
->data
));
368 memcpy(key_le
->ea
, key
->ea
, sizeof(key
->ea
));
371 static int send_key_to_dongle(struct net_device
*ndev
,
372 struct brcmf_wsec_key
*key
)
375 struct brcmf_wsec_key_le key_le
;
377 convert_key_from_CPU(key
, &key_le
);
378 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_KEY
, &key_le
, sizeof(key_le
));
380 WL_ERR("WLC_SET_KEY error (%d)\n", err
);
385 brcmf_cfg80211_change_iface(struct wiphy
*wiphy
, struct net_device
*ndev
,
386 enum nl80211_iftype type
, u32
*flags
,
387 struct vif_params
*params
)
389 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
390 struct wireless_dev
*wdev
;
395 if (!check_sys_up(wiphy
))
399 case NL80211_IFTYPE_MONITOR
:
400 case NL80211_IFTYPE_WDS
:
401 WL_ERR("type (%d) : currently we do not support this type\n",
404 case NL80211_IFTYPE_ADHOC
:
405 cfg_priv
->conf
->mode
= WL_MODE_IBSS
;
408 case NL80211_IFTYPE_STATION
:
409 cfg_priv
->conf
->mode
= WL_MODE_BSS
;
417 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_INFRA
, &infra
);
419 WL_ERR("WLC_SET_INFRA error (%d)\n", err
);
422 wdev
= ndev
->ieee80211_ptr
;
426 WL_INFO("IF Type = %s\n",
427 (cfg_priv
->conf
->mode
== WL_MODE_IBSS
) ? "Adhoc" : "Infra");
435 static s32
brcmf_dev_intvar_set(struct net_device
*ndev
, s8
*name
, s32 val
)
437 s8 buf
[BRCMF_DCMD_SMLEN
];
442 val_le
= cpu_to_le32(val
);
443 len
= brcmf_c_mkiovar(name
, (char *)(&val_le
), sizeof(val_le
), buf
,
447 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_VAR
, buf
, len
);
449 WL_ERR("error (%d)\n", err
);
455 brcmf_dev_intvar_get(struct net_device
*ndev
, s8
*name
, s32
*retval
)
458 s8 buf
[BRCMF_DCMD_SMLEN
];
466 brcmf_c_mkiovar(name
, (char *)(&data_null
), 0, (char *)(&var
),
469 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_GET_VAR
, &var
, len
);
471 WL_ERR("error (%d)\n", err
);
473 *retval
= le32_to_cpu(var
.val
);
478 static void brcmf_set_mpc(struct net_device
*ndev
, int mpc
)
481 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
483 if (test_bit(WL_STATUS_READY
, &cfg_priv
->status
)) {
484 err
= brcmf_dev_intvar_set(ndev
, "mpc", mpc
);
486 WL_ERR("fail to set mpc\n");
489 WL_INFO("MPC : %d\n", mpc
);
493 static void brcmf_iscan_prep(struct brcmf_scan_params_le
*params_le
,
494 struct brcmf_ssid
*ssid
)
496 memcpy(params_le
->bssid
, ether_bcast
, ETH_ALEN
);
497 params_le
->bss_type
= DOT11_BSSTYPE_ANY
;
498 params_le
->scan_type
= 0;
499 params_le
->channel_num
= 0;
500 params_le
->nprobes
= cpu_to_le32(-1);
501 params_le
->active_time
= cpu_to_le32(-1);
502 params_le
->passive_time
= cpu_to_le32(-1);
503 params_le
->home_time
= cpu_to_le32(-1);
504 if (ssid
&& ssid
->SSID_len
)
505 memcpy(¶ms_le
->ssid_le
, ssid
, sizeof(struct brcmf_ssid
));
509 brcmf_dev_iovar_setbuf(struct net_device
*ndev
, s8
* iovar
, void *param
,
510 s32 paramlen
, void *bufptr
, s32 buflen
)
514 iolen
= brcmf_c_mkiovar(iovar
, param
, paramlen
, bufptr
, buflen
);
517 return brcmf_exec_dcmd(ndev
, BRCMF_C_SET_VAR
, bufptr
, iolen
);
521 brcmf_dev_iovar_getbuf(struct net_device
*ndev
, s8
* iovar
, void *param
,
522 s32 paramlen
, void *bufptr
, s32 buflen
)
526 iolen
= brcmf_c_mkiovar(iovar
, param
, paramlen
, bufptr
, buflen
);
529 return brcmf_exec_dcmd(ndev
, BRCMF_C_GET_VAR
, bufptr
, buflen
);
533 brcmf_run_iscan(struct brcmf_cfg80211_iscan_ctrl
*iscan
,
534 struct brcmf_ssid
*ssid
, u16 action
)
536 s32 params_size
= BRCMF_SCAN_PARAMS_FIXED_SIZE
+
537 offsetof(struct brcmf_iscan_params_le
, params_le
);
538 struct brcmf_iscan_params_le
*params
;
541 if (ssid
&& ssid
->SSID_len
)
542 params_size
+= sizeof(struct brcmf_ssid
);
543 params
= kzalloc(params_size
, GFP_KERNEL
);
546 BUG_ON(params_size
>= BRCMF_DCMD_SMLEN
);
548 brcmf_iscan_prep(¶ms
->params_le
, ssid
);
550 params
->version
= cpu_to_le32(BRCMF_ISCAN_REQ_VERSION
);
551 params
->action
= cpu_to_le16(action
);
552 params
->scan_duration
= cpu_to_le16(0);
554 err
= brcmf_dev_iovar_setbuf(iscan
->ndev
, "iscan", params
, params_size
,
555 iscan
->dcmd_buf
, BRCMF_DCMD_SMLEN
);
558 WL_INFO("system busy : iscan canceled\n");
560 WL_ERR("error (%d)\n", err
);
567 static s32
brcmf_do_iscan(struct brcmf_cfg80211_priv
*cfg_priv
)
569 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_to_iscan(cfg_priv
);
570 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
571 struct brcmf_ssid ssid
;
575 /* Broadcast scan by default */
576 memset(&ssid
, 0, sizeof(ssid
));
578 iscan
->state
= WL_ISCAN_STATE_SCANING
;
580 passive_scan
= cfg_priv
->active_scan
? 0 : cpu_to_le32(1);
581 err
= brcmf_exec_dcmd(cfg_to_ndev(cfg_priv
), BRCMF_C_SET_PASSIVE_SCAN
,
582 &passive_scan
, sizeof(passive_scan
));
584 WL_ERR("error (%d)\n", err
);
587 brcmf_set_mpc(ndev
, 0);
588 cfg_priv
->iscan_kickstart
= true;
589 err
= brcmf_run_iscan(iscan
, &ssid
, BRCMF_SCAN_ACTION_START
);
591 brcmf_set_mpc(ndev
, 1);
592 cfg_priv
->iscan_kickstart
= false;
595 mod_timer(&iscan
->timer
, jiffies
+ iscan
->timer_ms
* HZ
/ 1000);
601 brcmf_cfg80211_iscan(struct wiphy
*wiphy
, struct net_device
*ndev
,
602 struct cfg80211_scan_request
*request
,
603 struct cfg80211_ssid
*this_ssid
)
605 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
606 struct cfg80211_ssid
*ssids
;
607 struct brcmf_cfg80211_scan_req
*sr
= cfg_priv
->scan_req_int
;
614 if (test_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
)) {
615 WL_ERR("Scanning already : status (%lu)\n", cfg_priv
->status
);
618 if (test_bit(WL_STATUS_SCAN_ABORTING
, &cfg_priv
->status
)) {
619 WL_ERR("Scanning being aborted : status (%lu)\n",
623 if (test_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
)) {
624 WL_ERR("Connecting : status (%lu)\n",
633 ssids
= request
->ssids
;
634 if (cfg_priv
->iscan_on
&& (!ssids
|| !ssids
->ssid_len
))
638 /* we don't do iscan in ibss */
642 cfg_priv
->scan_request
= request
;
643 set_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
);
645 err
= brcmf_do_iscan(cfg_priv
);
651 WL_SCAN("ssid \"%s\", ssid_len (%d)\n",
652 ssids
->ssid
, ssids
->ssid_len
);
653 memset(&sr
->ssid_le
, 0, sizeof(sr
->ssid_le
));
654 SSID_len
= min_t(u8
, sizeof(sr
->ssid_le
.SSID
), ssids
->ssid_len
);
655 sr
->ssid_le
.SSID_len
= cpu_to_le32(0);
657 memcpy(sr
->ssid_le
.SSID
, ssids
->ssid
, SSID_len
);
658 sr
->ssid_le
.SSID_len
= cpu_to_le32(SSID_len
);
661 WL_SCAN("Broadcast scan\n");
664 passive_scan
= cfg_priv
->active_scan
? 0 : cpu_to_le32(1);
665 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_PASSIVE_SCAN
,
666 &passive_scan
, sizeof(passive_scan
));
668 WL_ERR("WLC_SET_PASSIVE_SCAN error (%d)\n", err
);
671 brcmf_set_mpc(ndev
, 0);
672 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SCAN
, &sr
->ssid_le
,
673 sizeof(sr
->ssid_le
));
676 WL_INFO("system busy : scan for \"%s\" "
677 "canceled\n", sr
->ssid_le
.SSID
);
679 WL_ERR("WLC_SCAN error (%d)\n", err
);
681 brcmf_set_mpc(ndev
, 1);
689 clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
);
690 cfg_priv
->scan_request
= NULL
;
694 static void brcmf_escan_prep(struct brcmf_scan_params_le
*params_le
,
695 struct cfg80211_scan_request
*request
)
703 struct ieee80211_channel
*req_channel
;
705 struct brcmf_ssid ssid
;
707 memcpy(params_le
->bssid
, ether_bcast
, ETH_ALEN
);
708 params_le
->bss_type
= DOT11_BSSTYPE_ANY
;
709 params_le
->scan_type
= 0;
710 params_le
->channel_num
= 0;
711 params_le
->nprobes
= cpu_to_le32(-1);
712 params_le
->active_time
= cpu_to_le32(-1);
713 params_le
->passive_time
= cpu_to_le32(-1);
714 params_le
->home_time
= cpu_to_le32(-1);
715 memset(¶ms_le
->ssid_le
, 0, sizeof(params_le
->ssid_le
));
717 /* if request is null exit so it will be all channel broadcast scan */
721 n_ssids
= request
->n_ssids
;
722 n_channels
= request
->n_channels
;
723 /* Copy channel array if applicable */
724 WL_SCAN("### List of channelspecs to scan ### %d\n", n_channels
);
725 if (n_channels
> 0) {
726 for (i
= 0; i
< n_channels
; i
++) {
728 req_channel
= request
->channels
[i
];
729 channel
= ieee80211_frequency_to_channel(
730 req_channel
->center_freq
);
731 if (req_channel
->band
== IEEE80211_BAND_2GHZ
)
732 chanspec
|= WL_CHANSPEC_BAND_2G
;
734 chanspec
|= WL_CHANSPEC_BAND_5G
;
736 if (req_channel
->flags
& IEEE80211_CHAN_NO_HT40
) {
737 chanspec
|= WL_CHANSPEC_BW_20
;
738 chanspec
|= WL_CHANSPEC_CTL_SB_NONE
;
740 chanspec
|= WL_CHANSPEC_BW_40
;
741 if (req_channel
->flags
&
742 IEEE80211_CHAN_NO_HT40PLUS
)
743 chanspec
|= WL_CHANSPEC_CTL_SB_LOWER
;
745 chanspec
|= WL_CHANSPEC_CTL_SB_UPPER
;
748 params_le
->channel_list
[i
] =
749 (channel
& WL_CHANSPEC_CHAN_MASK
) |
751 WL_SCAN("Chan : %d, Channel spec: %x\n",
752 channel
, params_le
->channel_list
[i
]);
753 params_le
->channel_list
[i
] =
754 cpu_to_le16(params_le
->channel_list
[i
]);
757 WL_SCAN("Scanning all channels\n");
759 /* Copy ssid array if applicable */
760 WL_SCAN("### List of SSIDs to scan ### %d\n", n_ssids
);
762 offset
= offsetof(struct brcmf_scan_params_le
, channel_list
) +
763 n_channels
* sizeof(u16
);
764 offset
= roundup(offset
, sizeof(u32
));
765 ptr
= (char *)params_le
+ offset
;
766 for (i
= 0; i
< n_ssids
; i
++) {
767 memset(&ssid
, 0, sizeof(ssid
));
768 ssid
.SSID_len
= cpu_to_le32(request
->ssids
[i
].ssid_len
);
769 memcpy(ssid
.SSID
, request
->ssids
[i
].ssid
,
770 request
->ssids
[i
].ssid_len
);
772 WL_SCAN("%d: Broadcast scan\n", i
);
774 WL_SCAN("%d: scan for %s size =%d\n", i
,
775 ssid
.SSID
, ssid
.SSID_len
);
776 memcpy(ptr
, &ssid
, sizeof(ssid
));
780 WL_SCAN("Broadcast scan %p\n", request
->ssids
);
781 if ((request
->ssids
) && request
->ssids
->ssid_len
) {
782 WL_SCAN("SSID %s len=%d\n", params_le
->ssid_le
.SSID
,
783 request
->ssids
->ssid_len
);
784 params_le
->ssid_le
.SSID_len
=
785 cpu_to_le32(request
->ssids
->ssid_len
);
786 memcpy(¶ms_le
->ssid_le
.SSID
, request
->ssids
->ssid
,
787 request
->ssids
->ssid_len
);
790 /* Adding mask to channel numbers */
791 params_le
->channel_num
=
792 cpu_to_le32((n_ssids
<< BRCMF_SCAN_PARAMS_NSSID_SHIFT
) |
793 (n_channels
& BRCMF_SCAN_PARAMS_COUNT_MASK
));
797 brcmf_notify_escan_complete(struct brcmf_cfg80211_priv
*cfg_priv
,
798 struct net_device
*ndev
,
799 bool aborted
, bool fw_abort
)
801 struct brcmf_scan_params_le params_le
;
802 struct cfg80211_scan_request
*scan_request
;
807 /* clear scan request, because the FW abort can cause a second call */
808 /* to this functon and might cause a double cfg80211_scan_done */
809 scan_request
= cfg_priv
->scan_request
;
810 cfg_priv
->scan_request
= NULL
;
812 if (timer_pending(&cfg_priv
->escan_timeout
))
813 del_timer_sync(&cfg_priv
->escan_timeout
);
816 /* Do a scan abort to stop the driver's scan engine */
817 WL_SCAN("ABORT scan in firmware\n");
818 memset(¶ms_le
, 0, sizeof(params_le
));
819 memcpy(params_le
.bssid
, ether_bcast
, ETH_ALEN
);
820 params_le
.bss_type
= DOT11_BSSTYPE_ANY
;
821 params_le
.scan_type
= 0;
822 params_le
.channel_num
= cpu_to_le32(1);
823 params_le
.nprobes
= cpu_to_le32(1);
824 params_le
.active_time
= cpu_to_le32(-1);
825 params_le
.passive_time
= cpu_to_le32(-1);
826 params_le
.home_time
= cpu_to_le32(-1);
827 /* Scan is aborted by setting channel_list[0] to -1 */
828 params_le
.channel_list
[0] = cpu_to_le16(-1);
829 /* E-Scan (or anyother type) can be aborted by SCAN */
830 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SCAN
, ¶ms_le
,
833 WL_ERR("Scan abort failed\n");
836 WL_SCAN("ESCAN Completed scan: %s\n",
837 aborted
? "Aborted" : "Done");
838 cfg80211_scan_done(scan_request
, aborted
);
839 brcmf_set_mpc(ndev
, 1);
841 if (!test_and_clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
)) {
842 WL_ERR("Scan complete while device not scanning\n");
850 brcmf_run_escan(struct brcmf_cfg80211_priv
*cfg_priv
, struct net_device
*ndev
,
851 struct cfg80211_scan_request
*request
, u16 action
)
853 s32 params_size
= BRCMF_SCAN_PARAMS_FIXED_SIZE
+
854 offsetof(struct brcmf_escan_params_le
, params_le
);
855 struct brcmf_escan_params_le
*params
;
858 WL_SCAN("E-SCAN START\n");
860 if (request
!= NULL
) {
861 /* Allocate space for populating ssids in struct */
862 params_size
+= sizeof(u32
) * ((request
->n_channels
+ 1) / 2);
864 /* Allocate space for populating ssids in struct */
865 params_size
+= sizeof(struct brcmf_ssid
) * request
->n_ssids
;
868 params
= kzalloc(params_size
, GFP_KERNEL
);
873 BUG_ON(params_size
+ sizeof("escan") >= BRCMF_DCMD_MEDLEN
);
874 brcmf_escan_prep(¶ms
->params_le
, request
);
875 params
->version
= cpu_to_le32(BRCMF_ESCAN_REQ_VERSION
);
876 params
->action
= cpu_to_le16(action
);
877 params
->sync_id
= cpu_to_le16(0x1234);
879 err
= brcmf_dev_iovar_setbuf(ndev
, "escan", params
, params_size
,
880 cfg_priv
->escan_ioctl_buf
, BRCMF_DCMD_MEDLEN
);
883 WL_INFO("system busy : escan canceled\n");
885 WL_ERR("error (%d)\n", err
);
894 brcmf_do_escan(struct brcmf_cfg80211_priv
*cfg_priv
, struct wiphy
*wiphy
,
895 struct net_device
*ndev
, struct cfg80211_scan_request
*request
)
899 struct brcmf_scan_results
*results
;
902 cfg_priv
->escan_info
.ndev
= ndev
;
903 cfg_priv
->escan_info
.wiphy
= wiphy
;
904 cfg_priv
->escan_info
.escan_state
= WL_ESCAN_STATE_SCANNING
;
905 passive_scan
= cfg_priv
->active_scan
? 0 : cpu_to_le32(1);
906 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_PASSIVE_SCAN
,
907 &passive_scan
, sizeof(passive_scan
));
909 WL_ERR("error (%d)\n", err
);
912 brcmf_set_mpc(ndev
, 0);
913 results
= (struct brcmf_scan_results
*)cfg_priv
->escan_info
.escan_buf
;
914 results
->version
= 0;
916 results
->buflen
= WL_ESCAN_RESULTS_FIXED_SIZE
;
918 err
= brcmf_run_escan(cfg_priv
, ndev
, request
, WL_ESCAN_ACTION_START
);
920 brcmf_set_mpc(ndev
, 1);
925 brcmf_cfg80211_escan(struct wiphy
*wiphy
, struct net_device
*ndev
,
926 struct cfg80211_scan_request
*request
,
927 struct cfg80211_ssid
*this_ssid
)
929 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
930 struct cfg80211_ssid
*ssids
;
931 struct brcmf_cfg80211_scan_req
*sr
= cfg_priv
->scan_req_int
;
938 WL_SCAN("START ESCAN\n");
940 if (test_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
)) {
941 WL_ERR("Scanning already : status (%lu)\n", cfg_priv
->status
);
944 if (test_bit(WL_STATUS_SCAN_ABORTING
, &cfg_priv
->status
)) {
945 WL_ERR("Scanning being aborted : status (%lu)\n",
949 if (test_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
)) {
950 WL_ERR("Connecting : status (%lu)\n",
955 /* Arm scan timeout timer */
956 mod_timer(&cfg_priv
->escan_timeout
, jiffies
+
957 WL_ESCAN_TIMER_INTERVAL_MS
* HZ
/ 1000);
962 ssids
= request
->ssids
;
966 /* we don't do escan in ibss */
970 cfg_priv
->scan_request
= request
;
971 set_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
);
973 err
= brcmf_do_escan(cfg_priv
, wiphy
, ndev
, request
);
979 WL_SCAN("ssid \"%s\", ssid_len (%d)\n",
980 ssids
->ssid
, ssids
->ssid_len
);
981 memset(&sr
->ssid_le
, 0, sizeof(sr
->ssid_le
));
982 SSID_len
= min_t(u8
, sizeof(sr
->ssid_le
.SSID
), ssids
->ssid_len
);
983 sr
->ssid_le
.SSID_len
= cpu_to_le32(0);
986 memcpy(sr
->ssid_le
.SSID
, ssids
->ssid
, SSID_len
);
987 sr
->ssid_le
.SSID_len
= cpu_to_le32(SSID_len
);
990 WL_SCAN("Broadcast scan\n");
992 passive_scan
= cfg_priv
->active_scan
? 0 : cpu_to_le32(1);
993 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_PASSIVE_SCAN
,
994 &passive_scan
, sizeof(passive_scan
));
996 WL_ERR("WLC_SET_PASSIVE_SCAN error (%d)\n", err
);
999 brcmf_set_mpc(ndev
, 0);
1000 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SCAN
, &sr
->ssid_le
,
1001 sizeof(sr
->ssid_le
));
1004 WL_INFO("BUSY: scan for \"%s\" canceled\n",
1007 WL_ERR("WLC_SCAN error (%d)\n", err
);
1009 brcmf_set_mpc(ndev
, 1);
1017 clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
);
1018 if (timer_pending(&cfg_priv
->escan_timeout
))
1019 del_timer_sync(&cfg_priv
->escan_timeout
);
1020 cfg_priv
->scan_request
= NULL
;
1025 brcmf_cfg80211_scan(struct wiphy
*wiphy
,
1026 struct cfg80211_scan_request
*request
)
1028 struct net_device
*ndev
= request
->wdev
->netdev
;
1029 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
1032 WL_TRACE("Enter\n");
1034 if (!check_sys_up(wiphy
))
1037 if (cfg_priv
->iscan_on
)
1038 err
= brcmf_cfg80211_iscan(wiphy
, ndev
, request
, NULL
);
1039 else if (cfg_priv
->escan_on
)
1040 err
= brcmf_cfg80211_escan(wiphy
, ndev
, request
, NULL
);
1043 WL_ERR("scan error (%d)\n", err
);
1049 static s32
brcmf_set_rts(struct net_device
*ndev
, u32 rts_threshold
)
1053 err
= brcmf_dev_intvar_set(ndev
, "rtsthresh", rts_threshold
);
1055 WL_ERR("Error (%d)\n", err
);
1060 static s32
brcmf_set_frag(struct net_device
*ndev
, u32 frag_threshold
)
1064 err
= brcmf_dev_intvar_set(ndev
, "fragthresh", frag_threshold
);
1066 WL_ERR("Error (%d)\n", err
);
1071 static s32
brcmf_set_retry(struct net_device
*ndev
, u32 retry
, bool l
)
1074 u32 cmd
= (l
? BRCM_SET_LRL
: BRCM_SET_SRL
);
1076 err
= brcmf_exec_dcmd_u32(ndev
, cmd
, &retry
);
1078 WL_ERR("cmd (%d) , error (%d)\n", cmd
, err
);
1084 static s32
brcmf_cfg80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1086 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1087 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
1090 WL_TRACE("Enter\n");
1091 if (!check_sys_up(wiphy
))
1094 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
&&
1095 (cfg_priv
->conf
->rts_threshold
!= wiphy
->rts_threshold
)) {
1096 cfg_priv
->conf
->rts_threshold
= wiphy
->rts_threshold
;
1097 err
= brcmf_set_rts(ndev
, cfg_priv
->conf
->rts_threshold
);
1101 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
&&
1102 (cfg_priv
->conf
->frag_threshold
!= wiphy
->frag_threshold
)) {
1103 cfg_priv
->conf
->frag_threshold
= wiphy
->frag_threshold
;
1104 err
= brcmf_set_frag(ndev
, cfg_priv
->conf
->frag_threshold
);
1108 if (changed
& WIPHY_PARAM_RETRY_LONG
1109 && (cfg_priv
->conf
->retry_long
!= wiphy
->retry_long
)) {
1110 cfg_priv
->conf
->retry_long
= wiphy
->retry_long
;
1111 err
= brcmf_set_retry(ndev
, cfg_priv
->conf
->retry_long
, true);
1115 if (changed
& WIPHY_PARAM_RETRY_SHORT
1116 && (cfg_priv
->conf
->retry_short
!= wiphy
->retry_short
)) {
1117 cfg_priv
->conf
->retry_short
= wiphy
->retry_short
;
1118 err
= brcmf_set_retry(ndev
, cfg_priv
->conf
->retry_short
, false);
1128 static void *brcmf_read_prof(struct brcmf_cfg80211_priv
*cfg_priv
, s32 item
)
1132 return &cfg_priv
->profile
->sec
;
1134 return &cfg_priv
->profile
->bssid
;
1136 return &cfg_priv
->profile
->ssid
;
1138 WL_ERR("invalid item (%d)\n", item
);
1143 brcmf_update_prof(struct brcmf_cfg80211_priv
*cfg_priv
,
1144 const struct brcmf_event_msg
*e
, void *data
, s32 item
)
1147 struct brcmf_ssid
*ssid
;
1151 ssid
= (struct brcmf_ssid
*) data
;
1152 memset(cfg_priv
->profile
->ssid
.SSID
, 0,
1153 sizeof(cfg_priv
->profile
->ssid
.SSID
));
1154 memcpy(cfg_priv
->profile
->ssid
.SSID
,
1155 ssid
->SSID
, ssid
->SSID_len
);
1156 cfg_priv
->profile
->ssid
.SSID_len
= ssid
->SSID_len
;
1160 memcpy(cfg_priv
->profile
->bssid
, data
, ETH_ALEN
);
1162 memset(cfg_priv
->profile
->bssid
, 0, ETH_ALEN
);
1165 memcpy(&cfg_priv
->profile
->sec
, data
,
1166 sizeof(cfg_priv
->profile
->sec
));
1168 case WL_PROF_BEACONINT
:
1169 cfg_priv
->profile
->beacon_interval
= *(u16
*)data
;
1171 case WL_PROF_DTIMPERIOD
:
1172 cfg_priv
->profile
->dtim_period
= *(u8
*)data
;
1175 WL_ERR("unsupported item (%d)\n", item
);
1183 static void brcmf_init_prof(struct brcmf_cfg80211_profile
*prof
)
1185 memset(prof
, 0, sizeof(*prof
));
1188 static void brcmf_ch_to_chanspec(int ch
, struct brcmf_join_params
*join_params
,
1189 size_t *join_params_size
)
1194 if (ch
<= CH_MAX_2G_CHANNEL
)
1195 chanspec
|= WL_CHANSPEC_BAND_2G
;
1197 chanspec
|= WL_CHANSPEC_BAND_5G
;
1199 chanspec
|= WL_CHANSPEC_BW_20
;
1200 chanspec
|= WL_CHANSPEC_CTL_SB_NONE
;
1202 *join_params_size
+= BRCMF_ASSOC_PARAMS_FIXED_SIZE
+
1205 chanspec
|= (ch
& WL_CHANSPEC_CHAN_MASK
);
1206 join_params
->params_le
.chanspec_list
[0] = cpu_to_le16(chanspec
);
1207 join_params
->params_le
.chanspec_num
= cpu_to_le32(1);
1209 WL_CONN("join_params->params.chanspec_list[0]= %#X,"
1210 "channel %d, chanspec %#X\n",
1211 chanspec
, ch
, chanspec
);
1215 static void brcmf_link_down(struct brcmf_cfg80211_priv
*cfg_priv
)
1217 struct net_device
*ndev
= NULL
;
1220 WL_TRACE("Enter\n");
1222 if (cfg_priv
->link_up
) {
1223 ndev
= cfg_to_ndev(cfg_priv
);
1224 WL_INFO("Call WLC_DISASSOC to stop excess roaming\n ");
1225 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_DISASSOC
, NULL
, 0);
1227 WL_ERR("WLC_DISASSOC failed (%d)\n", err
);
1228 cfg_priv
->link_up
= false;
1234 brcmf_cfg80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*ndev
,
1235 struct cfg80211_ibss_params
*params
)
1237 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1238 struct brcmf_join_params join_params
;
1239 size_t join_params_size
= 0;
1243 struct brcmf_ssid ssid
;
1245 WL_TRACE("Enter\n");
1246 if (!check_sys_up(wiphy
))
1250 WL_CONN("SSID: %s\n", params
->ssid
);
1252 WL_CONN("SSID: NULL, Not supported\n");
1256 set_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
1259 WL_CONN("BSSID: %pM\n", params
->bssid
);
1261 WL_CONN("No BSSID specified\n");
1263 if (params
->channel
)
1264 WL_CONN("channel: %d\n", params
->channel
->center_freq
);
1266 WL_CONN("no channel specified\n");
1268 if (params
->channel_fixed
)
1269 WL_CONN("fixed channel required\n");
1271 WL_CONN("no fixed channel required\n");
1273 if (params
->ie
&& params
->ie_len
)
1274 WL_CONN("ie len: %d\n", params
->ie_len
);
1276 WL_CONN("no ie specified\n");
1278 if (params
->beacon_interval
)
1279 WL_CONN("beacon interval: %d\n", params
->beacon_interval
);
1281 WL_CONN("no beacon interval specified\n");
1283 if (params
->basic_rates
)
1284 WL_CONN("basic rates: %08X\n", params
->basic_rates
);
1286 WL_CONN("no basic rates specified\n");
1288 if (params
->privacy
)
1289 WL_CONN("privacy required\n");
1291 WL_CONN("no privacy required\n");
1293 /* Configure Privacy for starter */
1294 if (params
->privacy
)
1295 wsec
|= WEP_ENABLED
;
1297 err
= brcmf_dev_intvar_set(ndev
, "wsec", wsec
);
1299 WL_ERR("wsec failed (%d)\n", err
);
1303 /* Configure Beacon Interval for starter */
1304 if (params
->beacon_interval
)
1305 bcnprd
= params
->beacon_interval
;
1309 err
= brcmf_exec_dcmd_u32(ndev
, BRCM_SET_BCNPRD
, &bcnprd
);
1311 WL_ERR("WLC_SET_BCNPRD failed (%d)\n", err
);
1315 /* Configure required join parameter */
1316 memset(&join_params
, 0, sizeof(struct brcmf_join_params
));
1319 ssid
.SSID_len
= min_t(u32
, params
->ssid_len
, 32);
1320 memcpy(ssid
.SSID
, params
->ssid
, ssid
.SSID_len
);
1321 memcpy(join_params
.ssid_le
.SSID
, params
->ssid
, ssid
.SSID_len
);
1322 join_params
.ssid_le
.SSID_len
= cpu_to_le32(ssid
.SSID_len
);
1323 join_params_size
= sizeof(join_params
.ssid_le
);
1324 brcmf_update_prof(cfg_priv
, NULL
, &ssid
, WL_PROF_SSID
);
1327 if (params
->bssid
) {
1328 memcpy(join_params
.params_le
.bssid
, params
->bssid
, ETH_ALEN
);
1329 join_params_size
= sizeof(join_params
.ssid_le
) +
1330 BRCMF_ASSOC_PARAMS_FIXED_SIZE
;
1332 memcpy(join_params
.params_le
.bssid
, ether_bcast
, ETH_ALEN
);
1335 brcmf_update_prof(cfg_priv
, NULL
,
1336 &join_params
.params_le
.bssid
, WL_PROF_BSSID
);
1339 if (params
->channel
) {
1343 ieee80211_frequency_to_channel(
1344 params
->channel
->center_freq
);
1345 if (params
->channel_fixed
) {
1346 /* adding chanspec */
1347 brcmf_ch_to_chanspec(cfg_priv
->channel
,
1348 &join_params
, &join_params_size
);
1351 /* set channel for starter */
1352 target_channel
= cfg_priv
->channel
;
1353 err
= brcmf_exec_dcmd_u32(ndev
, BRCM_SET_CHANNEL
,
1356 WL_ERR("WLC_SET_CHANNEL failed (%d)\n", err
);
1360 cfg_priv
->channel
= 0;
1362 cfg_priv
->ibss_starter
= false;
1365 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_SSID
,
1366 &join_params
, join_params_size
);
1368 WL_ERR("WLC_SET_SSID failed (%d)\n", err
);
1374 clear_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
1380 brcmf_cfg80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*ndev
)
1382 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1385 WL_TRACE("Enter\n");
1386 if (!check_sys_up(wiphy
))
1389 brcmf_link_down(cfg_priv
);
1396 static s32
brcmf_set_wpa_version(struct net_device
*ndev
,
1397 struct cfg80211_connect_params
*sme
)
1399 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
1400 struct brcmf_cfg80211_security
*sec
;
1404 if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_1
)
1405 val
= WPA_AUTH_PSK
| WPA_AUTH_UNSPECIFIED
;
1406 else if (sme
->crypto
.wpa_versions
& NL80211_WPA_VERSION_2
)
1407 val
= WPA2_AUTH_PSK
| WPA2_AUTH_UNSPECIFIED
;
1409 val
= WPA_AUTH_DISABLED
;
1410 WL_CONN("setting wpa_auth to 0x%0x\n", val
);
1411 err
= brcmf_dev_intvar_set(ndev
, "wpa_auth", val
);
1413 WL_ERR("set wpa_auth failed (%d)\n", err
);
1416 sec
= brcmf_read_prof(cfg_priv
, WL_PROF_SEC
);
1417 sec
->wpa_versions
= sme
->crypto
.wpa_versions
;
1421 static s32
brcmf_set_auth_type(struct net_device
*ndev
,
1422 struct cfg80211_connect_params
*sme
)
1424 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
1425 struct brcmf_cfg80211_security
*sec
;
1429 switch (sme
->auth_type
) {
1430 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
1432 WL_CONN("open system\n");
1434 case NL80211_AUTHTYPE_SHARED_KEY
:
1436 WL_CONN("shared key\n");
1438 case NL80211_AUTHTYPE_AUTOMATIC
:
1440 WL_CONN("automatic\n");
1442 case NL80211_AUTHTYPE_NETWORK_EAP
:
1443 WL_CONN("network eap\n");
1446 WL_ERR("invalid auth type (%d)\n", sme
->auth_type
);
1450 err
= brcmf_dev_intvar_set(ndev
, "auth", val
);
1452 WL_ERR("set auth failed (%d)\n", err
);
1455 sec
= brcmf_read_prof(cfg_priv
, WL_PROF_SEC
);
1456 sec
->auth_type
= sme
->auth_type
;
1461 brcmf_set_set_cipher(struct net_device
*ndev
,
1462 struct cfg80211_connect_params
*sme
)
1464 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
1465 struct brcmf_cfg80211_security
*sec
;
1470 if (sme
->crypto
.n_ciphers_pairwise
) {
1471 switch (sme
->crypto
.ciphers_pairwise
[0]) {
1472 case WLAN_CIPHER_SUITE_WEP40
:
1473 case WLAN_CIPHER_SUITE_WEP104
:
1476 case WLAN_CIPHER_SUITE_TKIP
:
1477 pval
= TKIP_ENABLED
;
1479 case WLAN_CIPHER_SUITE_CCMP
:
1482 case WLAN_CIPHER_SUITE_AES_CMAC
:
1486 WL_ERR("invalid cipher pairwise (%d)\n",
1487 sme
->crypto
.ciphers_pairwise
[0]);
1491 if (sme
->crypto
.cipher_group
) {
1492 switch (sme
->crypto
.cipher_group
) {
1493 case WLAN_CIPHER_SUITE_WEP40
:
1494 case WLAN_CIPHER_SUITE_WEP104
:
1497 case WLAN_CIPHER_SUITE_TKIP
:
1498 gval
= TKIP_ENABLED
;
1500 case WLAN_CIPHER_SUITE_CCMP
:
1503 case WLAN_CIPHER_SUITE_AES_CMAC
:
1507 WL_ERR("invalid cipher group (%d)\n",
1508 sme
->crypto
.cipher_group
);
1513 WL_CONN("pval (%d) gval (%d)\n", pval
, gval
);
1514 err
= brcmf_dev_intvar_set(ndev
, "wsec", pval
| gval
);
1516 WL_ERR("error (%d)\n", err
);
1520 sec
= brcmf_read_prof(cfg_priv
, WL_PROF_SEC
);
1521 sec
->cipher_pairwise
= sme
->crypto
.ciphers_pairwise
[0];
1522 sec
->cipher_group
= sme
->crypto
.cipher_group
;
1528 brcmf_set_key_mgmt(struct net_device
*ndev
, struct cfg80211_connect_params
*sme
)
1530 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
1531 struct brcmf_cfg80211_security
*sec
;
1535 if (sme
->crypto
.n_akm_suites
) {
1536 err
= brcmf_dev_intvar_get(ndev
, "wpa_auth", &val
);
1538 WL_ERR("could not get wpa_auth (%d)\n", err
);
1541 if (val
& (WPA_AUTH_PSK
| WPA_AUTH_UNSPECIFIED
)) {
1542 switch (sme
->crypto
.akm_suites
[0]) {
1543 case WLAN_AKM_SUITE_8021X
:
1544 val
= WPA_AUTH_UNSPECIFIED
;
1546 case WLAN_AKM_SUITE_PSK
:
1550 WL_ERR("invalid cipher group (%d)\n",
1551 sme
->crypto
.cipher_group
);
1554 } else if (val
& (WPA2_AUTH_PSK
| WPA2_AUTH_UNSPECIFIED
)) {
1555 switch (sme
->crypto
.akm_suites
[0]) {
1556 case WLAN_AKM_SUITE_8021X
:
1557 val
= WPA2_AUTH_UNSPECIFIED
;
1559 case WLAN_AKM_SUITE_PSK
:
1560 val
= WPA2_AUTH_PSK
;
1563 WL_ERR("invalid cipher group (%d)\n",
1564 sme
->crypto
.cipher_group
);
1569 WL_CONN("setting wpa_auth to %d\n", val
);
1570 err
= brcmf_dev_intvar_set(ndev
, "wpa_auth", val
);
1572 WL_ERR("could not set wpa_auth (%d)\n", err
);
1576 sec
= brcmf_read_prof(cfg_priv
, WL_PROF_SEC
);
1577 sec
->wpa_auth
= sme
->crypto
.akm_suites
[0];
1583 brcmf_set_wep_sharedkey(struct net_device
*ndev
,
1584 struct cfg80211_connect_params
*sme
)
1586 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
1587 struct brcmf_cfg80211_security
*sec
;
1588 struct brcmf_wsec_key key
;
1592 WL_CONN("key len (%d)\n", sme
->key_len
);
1594 if (sme
->key_len
== 0)
1597 sec
= brcmf_read_prof(cfg_priv
, WL_PROF_SEC
);
1598 WL_CONN("wpa_versions 0x%x cipher_pairwise 0x%x\n",
1599 sec
->wpa_versions
, sec
->cipher_pairwise
);
1601 if (sec
->wpa_versions
& (NL80211_WPA_VERSION_1
| NL80211_WPA_VERSION_2
))
1604 if (sec
->cipher_pairwise
&
1605 (WLAN_CIPHER_SUITE_WEP40
| WLAN_CIPHER_SUITE_WEP104
)) {
1606 memset(&key
, 0, sizeof(key
));
1607 key
.len
= (u32
) sme
->key_len
;
1608 key
.index
= (u32
) sme
->key_idx
;
1609 if (key
.len
> sizeof(key
.data
)) {
1610 WL_ERR("Too long key length (%u)\n", key
.len
);
1613 memcpy(key
.data
, sme
->key
, key
.len
);
1614 key
.flags
= BRCMF_PRIMARY_KEY
;
1615 switch (sec
->cipher_pairwise
) {
1616 case WLAN_CIPHER_SUITE_WEP40
:
1617 key
.algo
= CRYPTO_ALGO_WEP1
;
1619 case WLAN_CIPHER_SUITE_WEP104
:
1620 key
.algo
= CRYPTO_ALGO_WEP128
;
1623 WL_ERR("Invalid algorithm (%d)\n",
1624 sme
->crypto
.ciphers_pairwise
[0]);
1627 /* Set the new key/index */
1628 WL_CONN("key length (%d) key index (%d) algo (%d)\n",
1629 key
.len
, key
.index
, key
.algo
);
1630 WL_CONN("key \"%s\"\n", key
.data
);
1631 err
= send_key_to_dongle(ndev
, &key
);
1635 if (sec
->auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
) {
1636 WL_CONN("set auth_type to shared key\n");
1637 val
= 1; /* shared key */
1638 err
= brcmf_dev_intvar_set(ndev
, "auth", val
);
1640 WL_ERR("set auth failed (%d)\n", err
);
1649 brcmf_cfg80211_connect(struct wiphy
*wiphy
, struct net_device
*ndev
,
1650 struct cfg80211_connect_params
*sme
)
1652 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1653 struct ieee80211_channel
*chan
= sme
->channel
;
1654 struct brcmf_join_params join_params
;
1655 size_t join_params_size
;
1656 struct brcmf_ssid ssid
;
1660 WL_TRACE("Enter\n");
1661 if (!check_sys_up(wiphy
))
1665 WL_ERR("Invalid ssid\n");
1669 set_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
1673 ieee80211_frequency_to_channel(chan
->center_freq
);
1674 WL_CONN("channel (%d), center_req (%d)\n",
1675 cfg_priv
->channel
, chan
->center_freq
);
1677 cfg_priv
->channel
= 0;
1679 WL_INFO("ie (%p), ie_len (%zd)\n", sme
->ie
, sme
->ie_len
);
1681 err
= brcmf_set_wpa_version(ndev
, sme
);
1683 WL_ERR("wl_set_wpa_version failed (%d)\n", err
);
1687 err
= brcmf_set_auth_type(ndev
, sme
);
1689 WL_ERR("wl_set_auth_type failed (%d)\n", err
);
1693 err
= brcmf_set_set_cipher(ndev
, sme
);
1695 WL_ERR("wl_set_set_cipher failed (%d)\n", err
);
1699 err
= brcmf_set_key_mgmt(ndev
, sme
);
1701 WL_ERR("wl_set_key_mgmt failed (%d)\n", err
);
1705 err
= brcmf_set_wep_sharedkey(ndev
, sme
);
1707 WL_ERR("brcmf_set_wep_sharedkey failed (%d)\n", err
);
1711 memset(&join_params
, 0, sizeof(join_params
));
1712 join_params_size
= sizeof(join_params
.ssid_le
);
1714 ssid
.SSID_len
= min_t(u32
, sizeof(ssid
.SSID
), (u32
)sme
->ssid_len
);
1715 memcpy(&join_params
.ssid_le
.SSID
, sme
->ssid
, ssid
.SSID_len
);
1716 memcpy(&ssid
.SSID
, sme
->ssid
, ssid
.SSID_len
);
1717 join_params
.ssid_le
.SSID_len
= cpu_to_le32(ssid
.SSID_len
);
1718 brcmf_update_prof(cfg_priv
, NULL
, &ssid
, WL_PROF_SSID
);
1720 memcpy(join_params
.params_le
.bssid
, ether_bcast
, ETH_ALEN
);
1722 if (ssid
.SSID_len
< IEEE80211_MAX_SSID_LEN
)
1723 WL_CONN("ssid \"%s\", len (%d)\n",
1724 ssid
.SSID
, ssid
.SSID_len
);
1726 brcmf_ch_to_chanspec(cfg_priv
->channel
,
1727 &join_params
, &join_params_size
);
1728 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_SSID
,
1729 &join_params
, join_params_size
);
1731 WL_ERR("WLC_SET_SSID failed (%d)\n", err
);
1735 clear_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
1741 brcmf_cfg80211_disconnect(struct wiphy
*wiphy
, struct net_device
*ndev
,
1744 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1745 struct brcmf_scb_val_le scbval
;
1748 WL_TRACE("Enter. Reason code = %d\n", reason_code
);
1749 if (!check_sys_up(wiphy
))
1752 clear_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
);
1754 memcpy(&scbval
.ea
, brcmf_read_prof(cfg_priv
, WL_PROF_BSSID
), ETH_ALEN
);
1755 scbval
.val
= cpu_to_le32(reason_code
);
1756 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_DISASSOC
, &scbval
,
1757 sizeof(struct brcmf_scb_val_le
));
1759 WL_ERR("error (%d)\n", err
);
1761 cfg_priv
->link_up
= false;
1768 brcmf_cfg80211_set_tx_power(struct wiphy
*wiphy
,
1769 enum nl80211_tx_power_setting type
, s32 mbm
)
1772 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1773 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
1777 s32 dbm
= MBM_TO_DBM(mbm
);
1779 WL_TRACE("Enter\n");
1780 if (!check_sys_up(wiphy
))
1784 case NL80211_TX_POWER_AUTOMATIC
:
1786 case NL80211_TX_POWER_LIMITED
:
1787 case NL80211_TX_POWER_FIXED
:
1789 WL_ERR("TX_POWER_FIXED - dbm is negative\n");
1795 /* Make sure radio is off or on as far as software is concerned */
1796 disable
= WL_RADIO_SW_DISABLE
<< 16;
1797 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_RADIO
, &disable
);
1799 WL_ERR("WLC_SET_RADIO error (%d)\n", err
);
1804 txpwrmw
= (u16
) dbm
;
1805 err
= brcmf_dev_intvar_set(ndev
, "qtxpower",
1806 (s32
) (brcmf_mw_to_qdbm(txpwrmw
)));
1808 WL_ERR("qtxpower error (%d)\n", err
);
1809 cfg_priv
->conf
->tx_power
= dbm
;
1816 static s32
brcmf_cfg80211_get_tx_power(struct wiphy
*wiphy
, s32
*dbm
)
1818 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
1819 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
1824 WL_TRACE("Enter\n");
1825 if (!check_sys_up(wiphy
))
1828 err
= brcmf_dev_intvar_get(ndev
, "qtxpower", &txpwrdbm
);
1830 WL_ERR("error (%d)\n", err
);
1834 result
= (u8
) (txpwrdbm
& ~WL_TXPWR_OVERRIDE
);
1835 *dbm
= (s32
) brcmf_qdbm_to_mw(result
);
1843 brcmf_cfg80211_config_default_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
1844 u8 key_idx
, bool unicast
, bool multicast
)
1850 WL_TRACE("Enter\n");
1851 WL_CONN("key index (%d)\n", key_idx
);
1852 if (!check_sys_up(wiphy
))
1855 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_GET_WSEC
, &wsec
);
1857 WL_ERR("WLC_GET_WSEC error (%d)\n", err
);
1861 if (wsec
& WEP_ENABLED
) {
1862 /* Just select a new current key */
1864 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_KEY_PRIMARY
,
1867 WL_ERR("error (%d)\n", err
);
1875 brcmf_add_keyext(struct wiphy
*wiphy
, struct net_device
*ndev
,
1876 u8 key_idx
, const u8
*mac_addr
, struct key_params
*params
)
1878 struct brcmf_wsec_key key
;
1879 struct brcmf_wsec_key_le key_le
;
1882 memset(&key
, 0, sizeof(key
));
1883 key
.index
= (u32
) key_idx
;
1884 /* Instead of bcast for ea address for default wep keys,
1885 driver needs it to be Null */
1886 if (!is_multicast_ether_addr(mac_addr
))
1887 memcpy((char *)&key
.ea
, (void *)mac_addr
, ETH_ALEN
);
1888 key
.len
= (u32
) params
->key_len
;
1889 /* check for key index change */
1892 err
= send_key_to_dongle(ndev
, &key
);
1896 if (key
.len
> sizeof(key
.data
)) {
1897 WL_ERR("Invalid key length (%d)\n", key
.len
);
1901 WL_CONN("Setting the key index %d\n", key
.index
);
1902 memcpy(key
.data
, params
->key
, key
.len
);
1904 if (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
1906 memcpy(keybuf
, &key
.data
[24], sizeof(keybuf
));
1907 memcpy(&key
.data
[24], &key
.data
[16], sizeof(keybuf
));
1908 memcpy(&key
.data
[16], keybuf
, sizeof(keybuf
));
1911 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1912 if (params
->seq
&& params
->seq_len
== 6) {
1915 ivptr
= (u8
*) params
->seq
;
1916 key
.rxiv
.hi
= (ivptr
[5] << 24) | (ivptr
[4] << 16) |
1917 (ivptr
[3] << 8) | ivptr
[2];
1918 key
.rxiv
.lo
= (ivptr
[1] << 8) | ivptr
[0];
1919 key
.iv_initialized
= true;
1922 switch (params
->cipher
) {
1923 case WLAN_CIPHER_SUITE_WEP40
:
1924 key
.algo
= CRYPTO_ALGO_WEP1
;
1925 WL_CONN("WLAN_CIPHER_SUITE_WEP40\n");
1927 case WLAN_CIPHER_SUITE_WEP104
:
1928 key
.algo
= CRYPTO_ALGO_WEP128
;
1929 WL_CONN("WLAN_CIPHER_SUITE_WEP104\n");
1931 case WLAN_CIPHER_SUITE_TKIP
:
1932 key
.algo
= CRYPTO_ALGO_TKIP
;
1933 WL_CONN("WLAN_CIPHER_SUITE_TKIP\n");
1935 case WLAN_CIPHER_SUITE_AES_CMAC
:
1936 key
.algo
= CRYPTO_ALGO_AES_CCM
;
1937 WL_CONN("WLAN_CIPHER_SUITE_AES_CMAC\n");
1939 case WLAN_CIPHER_SUITE_CCMP
:
1940 key
.algo
= CRYPTO_ALGO_AES_CCM
;
1941 WL_CONN("WLAN_CIPHER_SUITE_CCMP\n");
1944 WL_ERR("Invalid cipher (0x%x)\n", params
->cipher
);
1947 convert_key_from_CPU(&key
, &key_le
);
1949 brcmf_netdev_wait_pend8021x(ndev
);
1950 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_KEY
, &key_le
,
1953 WL_ERR("WLC_SET_KEY error (%d)\n", err
);
1961 brcmf_cfg80211_add_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
1962 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
1963 struct key_params
*params
)
1965 struct brcmf_wsec_key key
;
1971 WL_TRACE("Enter\n");
1972 WL_CONN("key index (%d)\n", key_idx
);
1973 if (!check_sys_up(wiphy
))
1978 return brcmf_add_keyext(wiphy
, ndev
, key_idx
, mac_addr
, params
);
1980 memset(&key
, 0, sizeof(key
));
1982 key
.len
= (u32
) params
->key_len
;
1983 key
.index
= (u32
) key_idx
;
1985 if (key
.len
> sizeof(key
.data
)) {
1986 WL_ERR("Too long key length (%u)\n", key
.len
);
1990 memcpy(key
.data
, params
->key
, key
.len
);
1992 key
.flags
= BRCMF_PRIMARY_KEY
;
1993 switch (params
->cipher
) {
1994 case WLAN_CIPHER_SUITE_WEP40
:
1995 key
.algo
= CRYPTO_ALGO_WEP1
;
1996 WL_CONN("WLAN_CIPHER_SUITE_WEP40\n");
1998 case WLAN_CIPHER_SUITE_WEP104
:
1999 key
.algo
= CRYPTO_ALGO_WEP128
;
2000 WL_CONN("WLAN_CIPHER_SUITE_WEP104\n");
2002 case WLAN_CIPHER_SUITE_TKIP
:
2003 memcpy(keybuf
, &key
.data
[24], sizeof(keybuf
));
2004 memcpy(&key
.data
[24], &key
.data
[16], sizeof(keybuf
));
2005 memcpy(&key
.data
[16], keybuf
, sizeof(keybuf
));
2006 key
.algo
= CRYPTO_ALGO_TKIP
;
2007 WL_CONN("WLAN_CIPHER_SUITE_TKIP\n");
2009 case WLAN_CIPHER_SUITE_AES_CMAC
:
2010 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2011 WL_CONN("WLAN_CIPHER_SUITE_AES_CMAC\n");
2013 case WLAN_CIPHER_SUITE_CCMP
:
2014 key
.algo
= CRYPTO_ALGO_AES_CCM
;
2015 WL_CONN("WLAN_CIPHER_SUITE_CCMP\n");
2018 WL_ERR("Invalid cipher (0x%x)\n", params
->cipher
);
2023 err
= send_key_to_dongle(ndev
, &key
); /* Set the new key/index */
2028 err
= brcmf_dev_intvar_get(ndev
, "wsec", &wsec
);
2030 WL_ERR("get wsec error (%d)\n", err
);
2033 wsec
&= ~(WEP_ENABLED
);
2035 err
= brcmf_dev_intvar_set(ndev
, "wsec", wsec
);
2037 WL_ERR("set wsec error (%d)\n", err
);
2041 val
= 1; /* assume shared key. otherwise 0 */
2042 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_AUTH
, &val
);
2044 WL_ERR("WLC_SET_AUTH error (%d)\n", err
);
2051 brcmf_cfg80211_del_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2052 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
2054 struct brcmf_wsec_key key
;
2059 WL_TRACE("Enter\n");
2060 if (!check_sys_up(wiphy
))
2063 memset(&key
, 0, sizeof(key
));
2065 key
.index
= (u32
) key_idx
;
2066 key
.flags
= BRCMF_PRIMARY_KEY
;
2067 key
.algo
= CRYPTO_ALGO_OFF
;
2069 WL_CONN("key index (%d)\n", key_idx
);
2071 /* Set the new key/index */
2072 err
= send_key_to_dongle(ndev
, &key
);
2074 if (err
== -EINVAL
) {
2075 if (key
.index
>= DOT11_MAX_DEFAULT_KEYS
)
2076 /* we ignore this key index in this case */
2077 WL_ERR("invalid key index (%d)\n", key_idx
);
2079 /* Ignore this error, may happen during DISASSOC */
2085 err
= brcmf_dev_intvar_get(ndev
, "wsec", &wsec
);
2087 WL_ERR("get wsec error (%d)\n", err
);
2088 /* Ignore this error, may happen during DISASSOC */
2092 wsec
&= ~(WEP_ENABLED
);
2094 err
= brcmf_dev_intvar_set(ndev
, "wsec", wsec
);
2096 WL_ERR("set wsec error (%d)\n", err
);
2097 /* Ignore this error, may happen during DISASSOC */
2102 val
= 0; /* assume open key. otherwise 1 */
2103 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_AUTH
, &val
);
2105 WL_ERR("WLC_SET_AUTH error (%d)\n", err
);
2106 /* Ignore this error, may happen during DISASSOC */
2115 brcmf_cfg80211_get_key(struct wiphy
*wiphy
, struct net_device
*ndev
,
2116 u8 key_idx
, bool pairwise
, const u8
*mac_addr
, void *cookie
,
2117 void (*callback
) (void *cookie
, struct key_params
* params
))
2119 struct key_params params
;
2120 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
2121 struct brcmf_cfg80211_security
*sec
;
2125 WL_TRACE("Enter\n");
2126 WL_CONN("key index (%d)\n", key_idx
);
2127 if (!check_sys_up(wiphy
))
2130 memset(¶ms
, 0, sizeof(params
));
2132 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_GET_WSEC
, &wsec
);
2134 WL_ERR("WLC_GET_WSEC error (%d)\n", err
);
2135 /* Ignore this error, may happen during DISASSOC */
2141 sec
= brcmf_read_prof(cfg_priv
, WL_PROF_SEC
);
2142 if (sec
->cipher_pairwise
& WLAN_CIPHER_SUITE_WEP40
) {
2143 params
.cipher
= WLAN_CIPHER_SUITE_WEP40
;
2144 WL_CONN("WLAN_CIPHER_SUITE_WEP40\n");
2145 } else if (sec
->cipher_pairwise
& WLAN_CIPHER_SUITE_WEP104
) {
2146 params
.cipher
= WLAN_CIPHER_SUITE_WEP104
;
2147 WL_CONN("WLAN_CIPHER_SUITE_WEP104\n");
2151 params
.cipher
= WLAN_CIPHER_SUITE_TKIP
;
2152 WL_CONN("WLAN_CIPHER_SUITE_TKIP\n");
2155 params
.cipher
= WLAN_CIPHER_SUITE_AES_CMAC
;
2156 WL_CONN("WLAN_CIPHER_SUITE_AES_CMAC\n");
2159 WL_ERR("Invalid algo (0x%x)\n", wsec
);
2163 callback(cookie
, ¶ms
);
2171 brcmf_cfg80211_config_default_mgmt_key(struct wiphy
*wiphy
,
2172 struct net_device
*ndev
, u8 key_idx
)
2174 WL_INFO("Not supported\n");
2180 brcmf_cfg80211_get_station(struct wiphy
*wiphy
, struct net_device
*ndev
,
2181 u8
*mac
, struct station_info
*sinfo
)
2183 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
2184 struct brcmf_scb_val_le scb_val
;
2188 u8
*bssid
= brcmf_read_prof(cfg_priv
, WL_PROF_BSSID
);
2190 WL_TRACE("Enter\n");
2191 if (!check_sys_up(wiphy
))
2194 if (memcmp(mac
, bssid
, ETH_ALEN
)) {
2195 WL_ERR("Wrong Mac address cfg_mac-%X:%X:%X:%X:%X:%X"
2196 "wl_bssid-%X:%X:%X:%X:%X:%X\n",
2197 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5],
2198 bssid
[0], bssid
[1], bssid
[2], bssid
[3],
2199 bssid
[4], bssid
[5]);
2204 /* Report the current tx rate */
2205 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_GET_RATE
, &rate
);
2207 WL_ERR("Could not get rate (%d)\n", err
);
2209 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
2210 sinfo
->txrate
.legacy
= rate
* 5;
2211 WL_CONN("Rate %d Mbps\n", rate
/ 2);
2214 if (test_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
)) {
2215 memset(&scb_val
, 0, sizeof(scb_val
));
2216 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_GET_RSSI
, &scb_val
,
2217 sizeof(struct brcmf_scb_val_le
));
2219 WL_ERR("Could not get rssi (%d)\n", err
);
2221 rssi
= le32_to_cpu(scb_val
.val
);
2222 sinfo
->filled
|= STATION_INFO_SIGNAL
;
2223 sinfo
->signal
= rssi
;
2224 WL_CONN("RSSI %d dBm\n", rssi
);
2234 brcmf_cfg80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*ndev
,
2235 bool enabled
, s32 timeout
)
2239 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
2241 WL_TRACE("Enter\n");
2244 * Powersave enable/disable request is coming from the
2245 * cfg80211 even before the interface is up. In that
2246 * scenario, driver will be storing the power save
2247 * preference in cfg_priv struct to apply this to
2248 * FW later while initializing the dongle
2250 cfg_priv
->pwr_save
= enabled
;
2251 if (!test_bit(WL_STATUS_READY
, &cfg_priv
->status
)) {
2253 WL_INFO("Device is not ready,"
2254 "storing the value in cfg_priv struct\n");
2258 pm
= enabled
? PM_FAST
: PM_OFF
;
2259 WL_INFO("power save %s\n", (pm
? "enabled" : "disabled"));
2261 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_PM
, &pm
);
2264 WL_ERR("net_device is not ready yet\n");
2266 WL_ERR("error (%d)\n", err
);
2274 brcmf_cfg80211_set_bitrate_mask(struct wiphy
*wiphy
, struct net_device
*ndev
,
2276 const struct cfg80211_bitrate_mask
*mask
)
2278 struct brcm_rateset_le rateset_le
;
2286 WL_TRACE("Enter\n");
2287 if (!check_sys_up(wiphy
))
2290 /* addr param is always NULL. ignore it */
2291 /* Get current rateset */
2292 err
= brcmf_exec_dcmd(ndev
, BRCM_GET_CURR_RATESET
, &rateset_le
,
2293 sizeof(rateset_le
));
2295 WL_ERR("could not get current rateset (%d)\n", err
);
2299 legacy
= ffs(mask
->control
[IEEE80211_BAND_2GHZ
].legacy
& 0xFFFF);
2301 legacy
= ffs(mask
->control
[IEEE80211_BAND_5GHZ
].legacy
&
2304 val
= wl_g_rates
[legacy
- 1].bitrate
* 100000;
2306 if (val
< le32_to_cpu(rateset_le
.count
))
2307 /* Select rate by rateset index */
2308 rate
= rateset_le
.rates
[val
] & 0x7f;
2310 /* Specified rate in bps */
2311 rate
= val
/ 500000;
2313 WL_CONN("rate %d mbps\n", rate
/ 2);
2317 * Set rate override,
2318 * Since the is a/b/g-blind, both a/bg_rate are enforced.
2320 err_bg
= brcmf_dev_intvar_set(ndev
, "bg_rate", rate
);
2321 err_a
= brcmf_dev_intvar_set(ndev
, "a_rate", rate
);
2322 if (err_bg
&& err_a
) {
2323 WL_ERR("could not set fixed rate (%d) (%d)\n", err_bg
, err_a
);
2324 err
= err_bg
| err_a
;
2332 static s32
brcmf_inform_single_bss(struct brcmf_cfg80211_priv
*cfg_priv
,
2333 struct brcmf_bss_info_le
*bi
)
2335 struct wiphy
*wiphy
= cfg_to_wiphy(cfg_priv
);
2336 struct ieee80211_channel
*notify_channel
;
2337 struct cfg80211_bss
*bss
;
2338 struct ieee80211_supported_band
*band
;
2342 u16 notify_capability
;
2343 u16 notify_interval
;
2345 size_t notify_ielen
;
2348 if (le32_to_cpu(bi
->length
) > WL_BSS_INFO_MAX
) {
2349 WL_ERR("Bss info is larger than buffer. Discarding\n");
2353 channel
= bi
->ctl_ch
? bi
->ctl_ch
:
2354 CHSPEC_CHANNEL(le16_to_cpu(bi
->chanspec
));
2356 if (channel
<= CH_MAX_2G_CHANNEL
)
2357 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2359 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2361 freq
= ieee80211_channel_to_frequency(channel
, band
->band
);
2362 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
2364 notify_capability
= le16_to_cpu(bi
->capability
);
2365 notify_interval
= le16_to_cpu(bi
->beacon_period
);
2366 notify_ie
= (u8
*)bi
+ le16_to_cpu(bi
->ie_offset
);
2367 notify_ielen
= le32_to_cpu(bi
->ie_length
);
2368 notify_signal
= (s16
)le16_to_cpu(bi
->RSSI
) * 100;
2370 WL_CONN("bssid: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2371 bi
->BSSID
[0], bi
->BSSID
[1], bi
->BSSID
[2],
2372 bi
->BSSID
[3], bi
->BSSID
[4], bi
->BSSID
[5]);
2373 WL_CONN("Channel: %d(%d)\n", channel
, freq
);
2374 WL_CONN("Capability: %X\n", notify_capability
);
2375 WL_CONN("Beacon interval: %d\n", notify_interval
);
2376 WL_CONN("Signal: %d\n", notify_signal
);
2378 bss
= cfg80211_inform_bss(wiphy
, notify_channel
, (const u8
*)bi
->BSSID
,
2379 0, notify_capability
, notify_interval
, notify_ie
,
2380 notify_ielen
, notify_signal
, GFP_KERNEL
);
2385 cfg80211_put_bss(bss
);
2390 static struct brcmf_bss_info_le
*
2391 next_bss_le(struct brcmf_scan_results
*list
, struct brcmf_bss_info_le
*bss
)
2394 return list
->bss_info_le
;
2395 return (struct brcmf_bss_info_le
*)((unsigned long)bss
+
2396 le32_to_cpu(bss
->length
));
2399 static s32
brcmf_inform_bss(struct brcmf_cfg80211_priv
*cfg_priv
)
2401 struct brcmf_scan_results
*bss_list
;
2402 struct brcmf_bss_info_le
*bi
= NULL
; /* must be initialized */
2406 bss_list
= cfg_priv
->bss_list
;
2407 if (bss_list
->version
!= BRCMF_BSS_INFO_VERSION
) {
2408 WL_ERR("Version %d != WL_BSS_INFO_VERSION\n",
2412 WL_SCAN("scanned AP count (%d)\n", bss_list
->count
);
2413 for (i
= 0; i
< bss_list
->count
&& i
< WL_AP_MAX
; i
++) {
2414 bi
= next_bss_le(bss_list
, bi
);
2415 err
= brcmf_inform_single_bss(cfg_priv
, bi
);
2422 static s32
wl_inform_ibss(struct brcmf_cfg80211_priv
*cfg_priv
,
2423 struct net_device
*ndev
, const u8
*bssid
)
2425 struct wiphy
*wiphy
= cfg_to_wiphy(cfg_priv
);
2426 struct ieee80211_channel
*notify_channel
;
2427 struct brcmf_bss_info_le
*bi
= NULL
;
2428 struct ieee80211_supported_band
*band
;
2429 struct cfg80211_bss
*bss
;
2434 u16 notify_capability
;
2435 u16 notify_interval
;
2437 size_t notify_ielen
;
2440 WL_TRACE("Enter\n");
2442 buf
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
2448 *(__le32
*)buf
= cpu_to_le32(WL_BSS_INFO_MAX
);
2450 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_GET_BSS_INFO
, buf
, WL_BSS_INFO_MAX
);
2452 WL_ERR("WLC_GET_BSS_INFO failed: %d\n", err
);
2456 bi
= (struct brcmf_bss_info_le
*)(buf
+ 4);
2458 channel
= bi
->ctl_ch
? bi
->ctl_ch
:
2459 CHSPEC_CHANNEL(le16_to_cpu(bi
->chanspec
));
2461 if (channel
<= CH_MAX_2G_CHANNEL
)
2462 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2464 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2466 freq
= ieee80211_channel_to_frequency(channel
, band
->band
);
2467 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
2469 notify_capability
= le16_to_cpu(bi
->capability
);
2470 notify_interval
= le16_to_cpu(bi
->beacon_period
);
2471 notify_ie
= (u8
*)bi
+ le16_to_cpu(bi
->ie_offset
);
2472 notify_ielen
= le32_to_cpu(bi
->ie_length
);
2473 notify_signal
= (s16
)le16_to_cpu(bi
->RSSI
) * 100;
2475 WL_CONN("channel: %d(%d)\n", channel
, freq
);
2476 WL_CONN("capability: %X\n", notify_capability
);
2477 WL_CONN("beacon interval: %d\n", notify_interval
);
2478 WL_CONN("signal: %d\n", notify_signal
);
2480 bss
= cfg80211_inform_bss(wiphy
, notify_channel
, bssid
,
2481 0, notify_capability
, notify_interval
,
2482 notify_ie
, notify_ielen
, notify_signal
, GFP_KERNEL
);
2489 cfg80211_put_bss(bss
);
2500 static bool brcmf_is_ibssmode(struct brcmf_cfg80211_priv
*cfg_priv
)
2502 return cfg_priv
->conf
->mode
== WL_MODE_IBSS
;
2506 * Traverse a string of 1-byte tag/1-byte length/variable-length value
2507 * triples, returning a pointer to the substring whose first element
2510 static struct brcmf_tlv
*brcmf_parse_tlvs(void *buf
, int buflen
, uint key
)
2512 struct brcmf_tlv
*elt
;
2515 elt
= (struct brcmf_tlv
*) buf
;
2518 /* find tagged parameter */
2519 while (totlen
>= 2) {
2522 /* validate remaining totlen */
2523 if ((elt
->id
== key
) && (totlen
>= (len
+ 2)))
2526 elt
= (struct brcmf_tlv
*) ((u8
*) elt
+ (len
+ 2));
2527 totlen
-= (len
+ 2);
2533 static s32
brcmf_update_bss_info(struct brcmf_cfg80211_priv
*cfg_priv
)
2535 struct brcmf_bss_info_le
*bi
;
2536 struct brcmf_ssid
*ssid
;
2537 struct brcmf_tlv
*tim
;
2538 u16 beacon_interval
;
2544 WL_TRACE("Enter\n");
2545 if (brcmf_is_ibssmode(cfg_priv
))
2548 ssid
= (struct brcmf_ssid
*)brcmf_read_prof(cfg_priv
, WL_PROF_SSID
);
2550 *(__le32
*)cfg_priv
->extra_buf
= cpu_to_le32(WL_EXTRA_BUF_MAX
);
2551 err
= brcmf_exec_dcmd(cfg_to_ndev(cfg_priv
), BRCMF_C_GET_BSS_INFO
,
2552 cfg_priv
->extra_buf
, WL_EXTRA_BUF_MAX
);
2554 WL_ERR("Could not get bss info %d\n", err
);
2555 goto update_bss_info_out
;
2558 bi
= (struct brcmf_bss_info_le
*)(cfg_priv
->extra_buf
+ 4);
2559 err
= brcmf_inform_single_bss(cfg_priv
, bi
);
2561 goto update_bss_info_out
;
2563 ie
= ((u8
*)bi
) + le16_to_cpu(bi
->ie_offset
);
2564 ie_len
= le32_to_cpu(bi
->ie_length
);
2565 beacon_interval
= le16_to_cpu(bi
->beacon_period
);
2567 tim
= brcmf_parse_tlvs(ie
, ie_len
, WLAN_EID_TIM
);
2569 dtim_period
= tim
->data
[1];
2572 * active scan was done so we could not get dtim
2573 * information out of probe response.
2574 * so we speficially query dtim information to dongle.
2577 err
= brcmf_dev_intvar_get(cfg_to_ndev(cfg_priv
),
2578 "dtim_assoc", &var
);
2580 WL_ERR("wl dtim_assoc failed (%d)\n", err
);
2581 goto update_bss_info_out
;
2583 dtim_period
= (u8
)var
;
2586 brcmf_update_prof(cfg_priv
, NULL
, &beacon_interval
, WL_PROF_BEACONINT
);
2587 brcmf_update_prof(cfg_priv
, NULL
, &dtim_period
, WL_PROF_DTIMPERIOD
);
2589 update_bss_info_out
:
2594 static void brcmf_term_iscan(struct brcmf_cfg80211_priv
*cfg_priv
)
2596 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_to_iscan(cfg_priv
);
2597 struct brcmf_ssid ssid
;
2599 if (cfg_priv
->iscan_on
) {
2600 iscan
->state
= WL_ISCAN_STATE_IDLE
;
2602 if (iscan
->timer_on
) {
2603 del_timer_sync(&iscan
->timer
);
2604 iscan
->timer_on
= 0;
2607 cancel_work_sync(&iscan
->work
);
2609 /* Abort iscan running in FW */
2610 memset(&ssid
, 0, sizeof(ssid
));
2611 brcmf_run_iscan(iscan
, &ssid
, WL_SCAN_ACTION_ABORT
);
2615 static void brcmf_notify_iscan_complete(struct brcmf_cfg80211_iscan_ctrl
*iscan
,
2618 struct brcmf_cfg80211_priv
*cfg_priv
= iscan_to_cfg(iscan
);
2619 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
2621 if (!test_and_clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
)) {
2622 WL_ERR("Scan complete while device not scanning\n");
2625 if (cfg_priv
->scan_request
) {
2626 WL_SCAN("ISCAN Completed scan: %s\n",
2627 aborted
? "Aborted" : "Done");
2628 cfg80211_scan_done(cfg_priv
->scan_request
, aborted
);
2629 brcmf_set_mpc(ndev
, 1);
2630 cfg_priv
->scan_request
= NULL
;
2632 cfg_priv
->iscan_kickstart
= false;
2635 static s32
brcmf_wakeup_iscan(struct brcmf_cfg80211_iscan_ctrl
*iscan
)
2637 if (iscan
->state
!= WL_ISCAN_STATE_IDLE
) {
2638 WL_SCAN("wake up iscan\n");
2639 schedule_work(&iscan
->work
);
2647 brcmf_get_iscan_results(struct brcmf_cfg80211_iscan_ctrl
*iscan
, u32
*status
,
2648 struct brcmf_scan_results
**bss_list
)
2650 struct brcmf_iscan_results list
;
2651 struct brcmf_scan_results
*results
;
2652 struct brcmf_scan_results_le
*results_le
;
2653 struct brcmf_iscan_results
*list_buf
;
2656 memset(iscan
->scan_buf
, 0, WL_ISCAN_BUF_MAX
);
2657 list_buf
= (struct brcmf_iscan_results
*)iscan
->scan_buf
;
2658 results
= &list_buf
->results
;
2659 results_le
= &list_buf
->results_le
;
2660 results
->buflen
= BRCMF_ISCAN_RESULTS_FIXED_SIZE
;
2661 results
->version
= 0;
2664 memset(&list
, 0, sizeof(list
));
2665 list
.results_le
.buflen
= cpu_to_le32(WL_ISCAN_BUF_MAX
);
2666 err
= brcmf_dev_iovar_getbuf(iscan
->ndev
, "iscanresults", &list
,
2667 BRCMF_ISCAN_RESULTS_FIXED_SIZE
,
2668 iscan
->scan_buf
, WL_ISCAN_BUF_MAX
);
2670 WL_ERR("error (%d)\n", err
);
2673 results
->buflen
= le32_to_cpu(results_le
->buflen
);
2674 results
->version
= le32_to_cpu(results_le
->version
);
2675 results
->count
= le32_to_cpu(results_le
->count
);
2676 WL_SCAN("results->count = %d\n", results_le
->count
);
2677 WL_SCAN("results->buflen = %d\n", results_le
->buflen
);
2678 *status
= le32_to_cpu(list_buf
->status_le
);
2679 WL_SCAN("status = %d\n", *status
);
2680 *bss_list
= results
;
2685 static s32
brcmf_iscan_done(struct brcmf_cfg80211_priv
*cfg_priv
)
2687 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_priv
->iscan
;
2690 iscan
->state
= WL_ISCAN_STATE_IDLE
;
2691 brcmf_inform_bss(cfg_priv
);
2692 brcmf_notify_iscan_complete(iscan
, false);
2697 static s32
brcmf_iscan_pending(struct brcmf_cfg80211_priv
*cfg_priv
)
2699 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_priv
->iscan
;
2702 /* Reschedule the timer */
2703 mod_timer(&iscan
->timer
, jiffies
+ iscan
->timer_ms
* HZ
/ 1000);
2704 iscan
->timer_on
= 1;
2709 static s32
brcmf_iscan_inprogress(struct brcmf_cfg80211_priv
*cfg_priv
)
2711 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_priv
->iscan
;
2714 brcmf_inform_bss(cfg_priv
);
2715 brcmf_run_iscan(iscan
, NULL
, BRCMF_SCAN_ACTION_CONTINUE
);
2716 /* Reschedule the timer */
2717 mod_timer(&iscan
->timer
, jiffies
+ iscan
->timer_ms
* HZ
/ 1000);
2718 iscan
->timer_on
= 1;
2723 static s32
brcmf_iscan_aborted(struct brcmf_cfg80211_priv
*cfg_priv
)
2725 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_priv
->iscan
;
2728 iscan
->state
= WL_ISCAN_STATE_IDLE
;
2729 brcmf_notify_iscan_complete(iscan
, true);
2734 static void brcmf_cfg80211_iscan_handler(struct work_struct
*work
)
2736 struct brcmf_cfg80211_iscan_ctrl
*iscan
=
2737 container_of(work
, struct brcmf_cfg80211_iscan_ctrl
,
2739 struct brcmf_cfg80211_priv
*cfg_priv
= iscan_to_cfg(iscan
);
2740 struct brcmf_cfg80211_iscan_eloop
*el
= &iscan
->el
;
2741 u32 status
= BRCMF_SCAN_RESULTS_PARTIAL
;
2743 if (iscan
->timer_on
) {
2744 del_timer_sync(&iscan
->timer
);
2745 iscan
->timer_on
= 0;
2748 if (brcmf_get_iscan_results(iscan
, &status
, &cfg_priv
->bss_list
)) {
2749 status
= BRCMF_SCAN_RESULTS_ABORTED
;
2750 WL_ERR("Abort iscan\n");
2753 el
->handler
[status
](cfg_priv
);
2756 static void brcmf_iscan_timer(unsigned long data
)
2758 struct brcmf_cfg80211_iscan_ctrl
*iscan
=
2759 (struct brcmf_cfg80211_iscan_ctrl
*)data
;
2762 iscan
->timer_on
= 0;
2763 WL_SCAN("timer expired\n");
2764 brcmf_wakeup_iscan(iscan
);
2768 static s32
brcmf_invoke_iscan(struct brcmf_cfg80211_priv
*cfg_priv
)
2770 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_to_iscan(cfg_priv
);
2772 if (cfg_priv
->iscan_on
) {
2773 iscan
->state
= WL_ISCAN_STATE_IDLE
;
2774 INIT_WORK(&iscan
->work
, brcmf_cfg80211_iscan_handler
);
2780 static void brcmf_init_iscan_eloop(struct brcmf_cfg80211_iscan_eloop
*el
)
2782 memset(el
, 0, sizeof(*el
));
2783 el
->handler
[BRCMF_SCAN_RESULTS_SUCCESS
] = brcmf_iscan_done
;
2784 el
->handler
[BRCMF_SCAN_RESULTS_PARTIAL
] = brcmf_iscan_inprogress
;
2785 el
->handler
[BRCMF_SCAN_RESULTS_PENDING
] = brcmf_iscan_pending
;
2786 el
->handler
[BRCMF_SCAN_RESULTS_ABORTED
] = brcmf_iscan_aborted
;
2787 el
->handler
[BRCMF_SCAN_RESULTS_NO_MEM
] = brcmf_iscan_aborted
;
2790 static s32
brcmf_init_iscan(struct brcmf_cfg80211_priv
*cfg_priv
)
2792 struct brcmf_cfg80211_iscan_ctrl
*iscan
= cfg_to_iscan(cfg_priv
);
2795 if (cfg_priv
->iscan_on
) {
2796 iscan
->ndev
= cfg_to_ndev(cfg_priv
);
2797 brcmf_init_iscan_eloop(&iscan
->el
);
2798 iscan
->timer_ms
= WL_ISCAN_TIMER_INTERVAL_MS
;
2799 init_timer(&iscan
->timer
);
2800 iscan
->timer
.data
= (unsigned long) iscan
;
2801 iscan
->timer
.function
= brcmf_iscan_timer
;
2802 err
= brcmf_invoke_iscan(cfg_priv
);
2804 iscan
->data
= cfg_priv
;
2810 static void brcmf_cfg80211_escan_timeout_worker(struct work_struct
*work
)
2812 struct brcmf_cfg80211_priv
*cfg_priv
=
2813 container_of(work
, struct brcmf_cfg80211_priv
,
2814 escan_timeout_work
);
2816 brcmf_notify_escan_complete(cfg_priv
,
2817 cfg_priv
->escan_info
.ndev
, true, true);
2820 static void brcmf_escan_timeout(unsigned long data
)
2822 struct brcmf_cfg80211_priv
*cfg_priv
=
2823 (struct brcmf_cfg80211_priv
*)data
;
2825 if (cfg_priv
->scan_request
) {
2826 WL_ERR("timer expired\n");
2827 if (cfg_priv
->escan_on
)
2828 schedule_work(&cfg_priv
->escan_timeout_work
);
2833 brcmf_compare_update_same_bss(struct brcmf_bss_info_le
*bss
,
2834 struct brcmf_bss_info_le
*bss_info_le
)
2836 if (!memcmp(&bss_info_le
->BSSID
, &bss
->BSSID
, ETH_ALEN
) &&
2837 (CHSPEC_BAND(le16_to_cpu(bss_info_le
->chanspec
)) ==
2838 CHSPEC_BAND(le16_to_cpu(bss
->chanspec
))) &&
2839 bss_info_le
->SSID_len
== bss
->SSID_len
&&
2840 !memcmp(bss_info_le
->SSID
, bss
->SSID
, bss_info_le
->SSID_len
)) {
2841 if ((bss
->flags
& WLC_BSS_RSSI_ON_CHANNEL
) ==
2842 (bss_info_le
->flags
& WLC_BSS_RSSI_ON_CHANNEL
)) {
2843 /* preserve max RSSI if the measurements are
2844 * both on-channel or both off-channel
2846 if (bss_info_le
->RSSI
> bss
->RSSI
)
2847 bss
->RSSI
= bss_info_le
->RSSI
;
2848 } else if ((bss
->flags
& WLC_BSS_RSSI_ON_CHANNEL
) &&
2849 (bss_info_le
->flags
& WLC_BSS_RSSI_ON_CHANNEL
) == 0) {
2850 /* preserve the on-channel rssi measurement
2851 * if the new measurement is off channel
2853 bss
->RSSI
= bss_info_le
->RSSI
;
2854 bss
->flags
|= WLC_BSS_RSSI_ON_CHANNEL
;
2862 brcmf_cfg80211_escan_handler(struct brcmf_cfg80211_priv
*cfg_priv
,
2863 struct net_device
*ndev
,
2864 const struct brcmf_event_msg
*e
, void *data
)
2868 struct brcmf_escan_result_le
*escan_result_le
;
2869 struct brcmf_bss_info_le
*bss_info_le
;
2870 struct brcmf_bss_info_le
*bss
= NULL
;
2872 struct brcmf_scan_results
*list
;
2876 status
= be32_to_cpu(e
->status
);
2878 if (!ndev
|| !cfg_priv
->escan_on
||
2879 !test_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
)) {
2880 WL_ERR("scan not ready ndev %p wl->escan_on %d drv_status %x\n",
2881 ndev
, cfg_priv
->escan_on
,
2882 !test_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
));
2886 if (status
== BRCMF_E_STATUS_PARTIAL
) {
2887 WL_SCAN("ESCAN Partial result\n");
2888 escan_result_le
= (struct brcmf_escan_result_le
*) data
;
2889 if (!escan_result_le
) {
2890 WL_ERR("Invalid escan result (NULL pointer)\n");
2893 if (!cfg_priv
->scan_request
) {
2894 WL_SCAN("result without cfg80211 request\n");
2898 if (le16_to_cpu(escan_result_le
->bss_count
) != 1) {
2899 WL_ERR("Invalid bss_count %d: ignoring\n",
2900 escan_result_le
->bss_count
);
2903 bss_info_le
= &escan_result_le
->bss_info_le
;
2905 bi_length
= le32_to_cpu(bss_info_le
->length
);
2906 if (bi_length
!= (le32_to_cpu(escan_result_le
->buflen
) -
2907 WL_ESCAN_RESULTS_FIXED_SIZE
)) {
2908 WL_ERR("Invalid bss_info length %d: ignoring\n",
2913 if (!(cfg_to_wiphy(cfg_priv
)->interface_modes
&
2914 BIT(NL80211_IFTYPE_ADHOC
))) {
2915 if (le16_to_cpu(bss_info_le
->capability
) &
2916 WLAN_CAPABILITY_IBSS
) {
2917 WL_ERR("Ignoring IBSS result\n");
2922 list
= (struct brcmf_scan_results
*)
2923 cfg_priv
->escan_info
.escan_buf
;
2924 if (bi_length
> WL_ESCAN_BUF_SIZE
- list
->buflen
) {
2925 WL_ERR("Buffer is too small: ignoring\n");
2929 for (i
= 0; i
< list
->count
; i
++) {
2930 bss
= bss
? (struct brcmf_bss_info_le
*)
2931 ((unsigned char *)bss
+
2932 le32_to_cpu(bss
->length
)) : list
->bss_info_le
;
2933 if (brcmf_compare_update_same_bss(bss
, bss_info_le
))
2936 memcpy(&(cfg_priv
->escan_info
.escan_buf
[list
->buflen
]),
2937 bss_info_le
, bi_length
);
2938 list
->version
= le32_to_cpu(bss_info_le
->version
);
2939 list
->buflen
+= bi_length
;
2942 cfg_priv
->escan_info
.escan_state
= WL_ESCAN_STATE_IDLE
;
2943 if (cfg_priv
->scan_request
) {
2944 cfg_priv
->bss_list
= (struct brcmf_scan_results
*)
2945 cfg_priv
->escan_info
.escan_buf
;
2946 brcmf_inform_bss(cfg_priv
);
2947 aborted
= status
!= BRCMF_E_STATUS_SUCCESS
;
2948 brcmf_notify_escan_complete(cfg_priv
, ndev
, aborted
,
2951 WL_ERR("Unexpected scan result 0x%x\n", status
);
2957 static void brcmf_init_escan(struct brcmf_cfg80211_priv
*cfg_priv
)
2960 if (cfg_priv
->escan_on
) {
2961 cfg_priv
->el
.handler
[BRCMF_E_ESCAN_RESULT
] =
2962 brcmf_cfg80211_escan_handler
;
2963 cfg_priv
->escan_info
.escan_state
= WL_ESCAN_STATE_IDLE
;
2964 /* Init scan_timeout timer */
2965 init_timer(&cfg_priv
->escan_timeout
);
2966 cfg_priv
->escan_timeout
.data
= (unsigned long) cfg_priv
;
2967 cfg_priv
->escan_timeout
.function
= brcmf_escan_timeout
;
2968 INIT_WORK(&cfg_priv
->escan_timeout_work
,
2969 brcmf_cfg80211_escan_timeout_worker
);
2973 static __always_inline
void brcmf_delay(u32 ms
)
2975 if (ms
< 1000 / HZ
) {
2983 static s32
brcmf_cfg80211_resume(struct wiphy
*wiphy
)
2985 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
2988 * Check for WL_STATUS_READY before any function call which
2989 * could result is bus access. Don't block the resume for
2990 * any driver error conditions
2992 WL_TRACE("Enter\n");
2994 if (test_bit(WL_STATUS_READY
, &cfg_priv
->status
))
2995 brcmf_invoke_iscan(wiphy_to_cfg(wiphy
));
3001 static s32
brcmf_cfg80211_suspend(struct wiphy
*wiphy
,
3002 struct cfg80211_wowlan
*wow
)
3004 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
3005 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
3007 WL_TRACE("Enter\n");
3010 * Check for WL_STATUS_READY before any function call which
3011 * could result is bus access. Don't block the suspend for
3012 * any driver error conditions
3016 * While going to suspend if associated with AP disassociate
3017 * from AP to save power while system is in suspended state
3019 if ((test_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
) ||
3020 test_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
)) &&
3021 test_bit(WL_STATUS_READY
, &cfg_priv
->status
)) {
3022 WL_INFO("Disassociating from AP"
3023 " while entering suspend state\n");
3024 brcmf_link_down(cfg_priv
);
3027 * Make sure WPA_Supplicant receives all the event
3028 * generated due to DISASSOC call to the fw to keep
3029 * the state fw and WPA_Supplicant state consistent
3034 set_bit(WL_STATUS_SCAN_ABORTING
, &cfg_priv
->status
);
3035 if (test_bit(WL_STATUS_READY
, &cfg_priv
->status
))
3036 brcmf_term_iscan(cfg_priv
);
3038 if (cfg_priv
->scan_request
) {
3039 /* Indidate scan abort to cfg80211 layer */
3040 WL_INFO("Terminating scan in progress\n");
3041 cfg80211_scan_done(cfg_priv
->scan_request
, true);
3042 cfg_priv
->scan_request
= NULL
;
3044 clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
);
3045 clear_bit(WL_STATUS_SCAN_ABORTING
, &cfg_priv
->status
);
3047 /* Turn off watchdog timer */
3048 if (test_bit(WL_STATUS_READY
, &cfg_priv
->status
))
3049 brcmf_set_mpc(ndev
, 1);
3057 brcmf_dev_bufvar_set(struct net_device
*ndev
, s8
*name
, s8
*buf
, s32 len
)
3059 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
3062 buflen
= brcmf_c_mkiovar(name
, buf
, len
, cfg_priv
->dcmd_buf
,
3066 return brcmf_exec_dcmd(ndev
, BRCMF_C_SET_VAR
, cfg_priv
->dcmd_buf
,
3071 brcmf_dev_bufvar_get(struct net_device
*ndev
, s8
*name
, s8
*buf
,
3074 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
3078 len
= brcmf_c_mkiovar(name
, NULL
, 0, cfg_priv
->dcmd_buf
,
3081 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_GET_VAR
, cfg_priv
->dcmd_buf
,
3084 WL_ERR("error (%d)\n", err
);
3087 memcpy(buf
, cfg_priv
->dcmd_buf
, buf_len
);
3093 brcmf_update_pmklist(struct net_device
*ndev
,
3094 struct brcmf_cfg80211_pmk_list
*pmk_list
, s32 err
)
3099 pmkid_len
= le32_to_cpu(pmk_list
->pmkids
.npmkid
);
3101 WL_CONN("No of elements %d\n", pmkid_len
);
3102 for (i
= 0; i
< pmkid_len
; i
++) {
3103 WL_CONN("PMKID[%d]: %pM =\n", i
,
3104 &pmk_list
->pmkids
.pmkid
[i
].BSSID
);
3105 for (j
= 0; j
< WLAN_PMKID_LEN
; j
++)
3106 WL_CONN("%02x\n", pmk_list
->pmkids
.pmkid
[i
].PMKID
[j
]);
3110 brcmf_dev_bufvar_set(ndev
, "pmkid_info", (char *)pmk_list
,
3117 brcmf_cfg80211_set_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
3118 struct cfg80211_pmksa
*pmksa
)
3120 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
3121 struct pmkid_list
*pmkids
= &cfg_priv
->pmk_list
->pmkids
;
3126 WL_TRACE("Enter\n");
3127 if (!check_sys_up(wiphy
))
3130 pmkid_len
= le32_to_cpu(pmkids
->npmkid
);
3131 for (i
= 0; i
< pmkid_len
; i
++)
3132 if (!memcmp(pmksa
->bssid
, pmkids
->pmkid
[i
].BSSID
, ETH_ALEN
))
3134 if (i
< WL_NUM_PMKIDS_MAX
) {
3135 memcpy(pmkids
->pmkid
[i
].BSSID
, pmksa
->bssid
, ETH_ALEN
);
3136 memcpy(pmkids
->pmkid
[i
].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
3137 if (i
== pmkid_len
) {
3139 pmkids
->npmkid
= cpu_to_le32(pmkid_len
);
3144 WL_CONN("set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
3145 pmkids
->pmkid
[pmkid_len
].BSSID
);
3146 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
3147 WL_CONN("%02x\n", pmkids
->pmkid
[pmkid_len
].PMKID
[i
]);
3149 err
= brcmf_update_pmklist(ndev
, cfg_priv
->pmk_list
, err
);
3156 brcmf_cfg80211_del_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
,
3157 struct cfg80211_pmksa
*pmksa
)
3159 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
3160 struct pmkid_list pmkid
;
3164 WL_TRACE("Enter\n");
3165 if (!check_sys_up(wiphy
))
3168 memcpy(&pmkid
.pmkid
[0].BSSID
, pmksa
->bssid
, ETH_ALEN
);
3169 memcpy(&pmkid
.pmkid
[0].PMKID
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
3171 WL_CONN("del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
3172 &pmkid
.pmkid
[0].BSSID
);
3173 for (i
= 0; i
< WLAN_PMKID_LEN
; i
++)
3174 WL_CONN("%02x\n", pmkid
.pmkid
[0].PMKID
[i
]);
3176 pmkid_len
= le32_to_cpu(cfg_priv
->pmk_list
->pmkids
.npmkid
);
3177 for (i
= 0; i
< pmkid_len
; i
++)
3179 (pmksa
->bssid
, &cfg_priv
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3184 && (i
< pmkid_len
)) {
3185 memset(&cfg_priv
->pmk_list
->pmkids
.pmkid
[i
], 0,
3186 sizeof(struct pmkid
));
3187 for (; i
< (pmkid_len
- 1); i
++) {
3188 memcpy(&cfg_priv
->pmk_list
->pmkids
.pmkid
[i
].BSSID
,
3189 &cfg_priv
->pmk_list
->pmkids
.pmkid
[i
+ 1].BSSID
,
3191 memcpy(&cfg_priv
->pmk_list
->pmkids
.pmkid
[i
].PMKID
,
3192 &cfg_priv
->pmk_list
->pmkids
.pmkid
[i
+ 1].PMKID
,
3195 cfg_priv
->pmk_list
->pmkids
.npmkid
= cpu_to_le32(pmkid_len
- 1);
3199 err
= brcmf_update_pmklist(ndev
, cfg_priv
->pmk_list
, err
);
3207 brcmf_cfg80211_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*ndev
)
3209 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
3212 WL_TRACE("Enter\n");
3213 if (!check_sys_up(wiphy
))
3216 memset(cfg_priv
->pmk_list
, 0, sizeof(*cfg_priv
->pmk_list
));
3217 err
= brcmf_update_pmklist(ndev
, cfg_priv
->pmk_list
, err
);
3224 #ifdef CONFIG_NL80211_TESTMODE
3225 static int brcmf_cfg80211_testmode(struct wiphy
*wiphy
, void *data
, int len
)
3227 struct brcmf_cfg80211_priv
*cfg_priv
= wiphy_to_cfg(wiphy
);
3228 struct net_device
*ndev
= cfg_priv
->wdev
->netdev
;
3229 struct brcmf_dcmd
*dcmd
= data
;
3230 struct sk_buff
*reply
;
3233 ret
= brcmf_netlink_dcmd(ndev
, dcmd
);
3235 reply
= cfg80211_testmode_alloc_reply_skb(wiphy
, sizeof(*dcmd
));
3236 nla_put(reply
, NL80211_ATTR_TESTDATA
, sizeof(*dcmd
), dcmd
);
3237 ret
= cfg80211_testmode_reply(reply
);
3243 static struct cfg80211_ops wl_cfg80211_ops
= {
3244 .change_virtual_intf
= brcmf_cfg80211_change_iface
,
3245 .scan
= brcmf_cfg80211_scan
,
3246 .set_wiphy_params
= brcmf_cfg80211_set_wiphy_params
,
3247 .join_ibss
= brcmf_cfg80211_join_ibss
,
3248 .leave_ibss
= brcmf_cfg80211_leave_ibss
,
3249 .get_station
= brcmf_cfg80211_get_station
,
3250 .set_tx_power
= brcmf_cfg80211_set_tx_power
,
3251 .get_tx_power
= brcmf_cfg80211_get_tx_power
,
3252 .add_key
= brcmf_cfg80211_add_key
,
3253 .del_key
= brcmf_cfg80211_del_key
,
3254 .get_key
= brcmf_cfg80211_get_key
,
3255 .set_default_key
= brcmf_cfg80211_config_default_key
,
3256 .set_default_mgmt_key
= brcmf_cfg80211_config_default_mgmt_key
,
3257 .set_power_mgmt
= brcmf_cfg80211_set_power_mgmt
,
3258 .set_bitrate_mask
= brcmf_cfg80211_set_bitrate_mask
,
3259 .connect
= brcmf_cfg80211_connect
,
3260 .disconnect
= brcmf_cfg80211_disconnect
,
3261 .suspend
= brcmf_cfg80211_suspend
,
3262 .resume
= brcmf_cfg80211_resume
,
3263 .set_pmksa
= brcmf_cfg80211_set_pmksa
,
3264 .del_pmksa
= brcmf_cfg80211_del_pmksa
,
3265 .flush_pmksa
= brcmf_cfg80211_flush_pmksa
,
3266 #ifdef CONFIG_NL80211_TESTMODE
3267 .testmode_cmd
= brcmf_cfg80211_testmode
3271 static s32
brcmf_mode_to_nl80211_iftype(s32 mode
)
3277 return NL80211_IFTYPE_STATION
;
3279 return NL80211_IFTYPE_ADHOC
;
3281 return NL80211_IFTYPE_UNSPECIFIED
;
3287 static struct wireless_dev
*brcmf_alloc_wdev(s32 sizeof_iface
,
3288 struct device
*ndev
)
3290 struct wireless_dev
*wdev
;
3293 wdev
= kzalloc(sizeof(*wdev
), GFP_KERNEL
);
3295 return ERR_PTR(-ENOMEM
);
3298 wiphy_new(&wl_cfg80211_ops
,
3299 sizeof(struct brcmf_cfg80211_priv
) + sizeof_iface
);
3301 WL_ERR("Could not allocate wiphy device\n");
3305 set_wiphy_dev(wdev
->wiphy
, ndev
);
3306 wdev
->wiphy
->max_scan_ssids
= WL_NUM_SCAN_MAX
;
3307 wdev
->wiphy
->max_num_pmkids
= WL_NUM_PMKIDS_MAX
;
3308 wdev
->wiphy
->interface_modes
=
3309 BIT(NL80211_IFTYPE_STATION
) | BIT(NL80211_IFTYPE_ADHOC
);
3310 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &__wl_band_2ghz
;
3311 wdev
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &__wl_band_5ghz_a
; /* Set
3312 * it as 11a by default.
3313 * This will be updated with
3316 * if phy has 11n capability
3318 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
3319 wdev
->wiphy
->cipher_suites
= __wl_cipher_suites
;
3320 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(__wl_cipher_suites
);
3321 wdev
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
; /* enable power
3325 err
= wiphy_register(wdev
->wiphy
);
3327 WL_ERR("Could not register wiphy device (%d)\n", err
);
3328 goto wiphy_register_out
;
3333 wiphy_free(wdev
->wiphy
);
3338 return ERR_PTR(err
);
3341 static void brcmf_free_wdev(struct brcmf_cfg80211_priv
*cfg_priv
)
3343 struct wireless_dev
*wdev
= cfg_priv
->wdev
;
3346 WL_ERR("wdev is invalid\n");
3349 wiphy_unregister(wdev
->wiphy
);
3350 wiphy_free(wdev
->wiphy
);
3352 cfg_priv
->wdev
= NULL
;
3355 static bool brcmf_is_linkup(struct brcmf_cfg80211_priv
*cfg_priv
,
3356 const struct brcmf_event_msg
*e
)
3358 u32 event
= be32_to_cpu(e
->event_type
);
3359 u32 status
= be32_to_cpu(e
->status
);
3361 if (event
== BRCMF_E_SET_SSID
&& status
== BRCMF_E_STATUS_SUCCESS
) {
3362 WL_CONN("Processing set ssid\n");
3363 cfg_priv
->link_up
= true;
3370 static bool brcmf_is_linkdown(struct brcmf_cfg80211_priv
*cfg_priv
,
3371 const struct brcmf_event_msg
*e
)
3373 u32 event
= be32_to_cpu(e
->event_type
);
3374 u16 flags
= be16_to_cpu(e
->flags
);
3376 if (event
== BRCMF_E_LINK
&& (!(flags
& BRCMF_EVENT_MSG_LINK
))) {
3377 WL_CONN("Processing link down\n");
3383 static bool brcmf_is_nonetwork(struct brcmf_cfg80211_priv
*cfg_priv
,
3384 const struct brcmf_event_msg
*e
)
3386 u32 event
= be32_to_cpu(e
->event_type
);
3387 u32 status
= be32_to_cpu(e
->status
);
3389 if (event
== BRCMF_E_LINK
&& status
== BRCMF_E_STATUS_NO_NETWORKS
) {
3390 WL_CONN("Processing Link %s & no network found\n",
3391 be16_to_cpu(e
->flags
) & BRCMF_EVENT_MSG_LINK
?
3396 if (event
== BRCMF_E_SET_SSID
&& status
!= BRCMF_E_STATUS_SUCCESS
) {
3397 WL_CONN("Processing connecting & no network found\n");
3404 static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_priv
*cfg_priv
)
3406 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg_priv
);
3408 kfree(conn_info
->req_ie
);
3409 conn_info
->req_ie
= NULL
;
3410 conn_info
->req_ie_len
= 0;
3411 kfree(conn_info
->resp_ie
);
3412 conn_info
->resp_ie
= NULL
;
3413 conn_info
->resp_ie_len
= 0;
3416 static s32
brcmf_get_assoc_ies(struct brcmf_cfg80211_priv
*cfg_priv
)
3418 struct net_device
*ndev
= cfg_to_ndev(cfg_priv
);
3419 struct brcmf_cfg80211_assoc_ielen_le
*assoc_info
;
3420 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg_priv
);
3425 brcmf_clear_assoc_ies(cfg_priv
);
3427 err
= brcmf_dev_bufvar_get(ndev
, "assoc_info", cfg_priv
->extra_buf
,
3430 WL_ERR("could not get assoc info (%d)\n", err
);
3434 (struct brcmf_cfg80211_assoc_ielen_le
*)cfg_priv
->extra_buf
;
3435 req_len
= le32_to_cpu(assoc_info
->req_len
);
3436 resp_len
= le32_to_cpu(assoc_info
->resp_len
);
3438 err
= brcmf_dev_bufvar_get(ndev
, "assoc_req_ies",
3439 cfg_priv
->extra_buf
,
3442 WL_ERR("could not get assoc req (%d)\n", err
);
3445 conn_info
->req_ie_len
= req_len
;
3447 kmemdup(cfg_priv
->extra_buf
, conn_info
->req_ie_len
,
3450 conn_info
->req_ie_len
= 0;
3451 conn_info
->req_ie
= NULL
;
3454 err
= brcmf_dev_bufvar_get(ndev
, "assoc_resp_ies",
3455 cfg_priv
->extra_buf
,
3458 WL_ERR("could not get assoc resp (%d)\n", err
);
3461 conn_info
->resp_ie_len
= resp_len
;
3462 conn_info
->resp_ie
=
3463 kmemdup(cfg_priv
->extra_buf
, conn_info
->resp_ie_len
,
3466 conn_info
->resp_ie_len
= 0;
3467 conn_info
->resp_ie
= NULL
;
3469 WL_CONN("req len (%d) resp len (%d)\n",
3470 conn_info
->req_ie_len
, conn_info
->resp_ie_len
);
3476 brcmf_bss_roaming_done(struct brcmf_cfg80211_priv
*cfg_priv
,
3477 struct net_device
*ndev
,
3478 const struct brcmf_event_msg
*e
)
3480 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg_priv
);
3481 struct wiphy
*wiphy
= cfg_to_wiphy(cfg_priv
);
3482 struct brcmf_channel_info_le channel_le
;
3483 struct ieee80211_channel
*notify_channel
;
3484 struct ieee80211_supported_band
*band
;
3489 WL_TRACE("Enter\n");
3491 brcmf_get_assoc_ies(cfg_priv
);
3492 brcmf_update_prof(cfg_priv
, NULL
, &e
->addr
, WL_PROF_BSSID
);
3493 brcmf_update_bss_info(cfg_priv
);
3495 brcmf_exec_dcmd(ndev
, BRCMF_C_GET_CHANNEL
, &channel_le
,
3496 sizeof(channel_le
));
3498 target_channel
= le32_to_cpu(channel_le
.target_channel
);
3499 WL_CONN("Roamed to channel %d\n", target_channel
);
3501 if (target_channel
<= CH_MAX_2G_CHANNEL
)
3502 band
= wiphy
->bands
[IEEE80211_BAND_2GHZ
];
3504 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
3506 freq
= ieee80211_channel_to_frequency(target_channel
, band
->band
);
3507 notify_channel
= ieee80211_get_channel(wiphy
, freq
);
3509 cfg80211_roamed(ndev
, notify_channel
,
3510 (u8
*)brcmf_read_prof(cfg_priv
, WL_PROF_BSSID
),
3511 conn_info
->req_ie
, conn_info
->req_ie_len
,
3512 conn_info
->resp_ie
, conn_info
->resp_ie_len
, GFP_KERNEL
);
3513 WL_CONN("Report roaming result\n");
3515 set_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
);
3521 brcmf_bss_connect_done(struct brcmf_cfg80211_priv
*cfg_priv
,
3522 struct net_device
*ndev
, const struct brcmf_event_msg
*e
,
3525 struct brcmf_cfg80211_connect_info
*conn_info
= cfg_to_conn(cfg_priv
);
3528 WL_TRACE("Enter\n");
3530 if (test_and_clear_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
)) {
3532 brcmf_get_assoc_ies(cfg_priv
);
3533 brcmf_update_prof(cfg_priv
, NULL
, &e
->addr
,
3535 brcmf_update_bss_info(cfg_priv
);
3537 cfg80211_connect_result(ndev
,
3538 (u8
*)brcmf_read_prof(cfg_priv
,
3541 conn_info
->req_ie_len
,
3543 conn_info
->resp_ie_len
,
3544 completed
? WLAN_STATUS_SUCCESS
:
3545 WLAN_STATUS_AUTH_TIMEOUT
,
3548 set_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
);
3549 WL_CONN("Report connect result - connection %s\n",
3550 completed
? "succeeded" : "failed");
3557 brcmf_notify_connect_status(struct brcmf_cfg80211_priv
*cfg_priv
,
3558 struct net_device
*ndev
,
3559 const struct brcmf_event_msg
*e
, void *data
)
3563 if (brcmf_is_linkup(cfg_priv
, e
)) {
3564 WL_CONN("Linkup\n");
3565 if (brcmf_is_ibssmode(cfg_priv
)) {
3566 brcmf_update_prof(cfg_priv
, NULL
, (void *)e
->addr
,
3568 wl_inform_ibss(cfg_priv
, ndev
, e
->addr
);
3569 cfg80211_ibss_joined(ndev
, e
->addr
, GFP_KERNEL
);
3570 clear_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
3571 set_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
);
3573 brcmf_bss_connect_done(cfg_priv
, ndev
, e
, true);
3574 } else if (brcmf_is_linkdown(cfg_priv
, e
)) {
3575 WL_CONN("Linkdown\n");
3576 if (brcmf_is_ibssmode(cfg_priv
)) {
3577 clear_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
3578 if (test_and_clear_bit(WL_STATUS_CONNECTED
,
3580 brcmf_link_down(cfg_priv
);
3582 brcmf_bss_connect_done(cfg_priv
, ndev
, e
, false);
3583 if (test_and_clear_bit(WL_STATUS_CONNECTED
,
3584 &cfg_priv
->status
)) {
3585 cfg80211_disconnected(ndev
, 0, NULL
, 0,
3587 brcmf_link_down(cfg_priv
);
3590 brcmf_init_prof(cfg_priv
->profile
);
3591 } else if (brcmf_is_nonetwork(cfg_priv
, e
)) {
3592 if (brcmf_is_ibssmode(cfg_priv
))
3593 clear_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
);
3595 brcmf_bss_connect_done(cfg_priv
, ndev
, e
, false);
3602 brcmf_notify_roaming_status(struct brcmf_cfg80211_priv
*cfg_priv
,
3603 struct net_device
*ndev
,
3604 const struct brcmf_event_msg
*e
, void *data
)
3607 u32 event
= be32_to_cpu(e
->event_type
);
3608 u32 status
= be32_to_cpu(e
->status
);
3610 if (event
== BRCMF_E_ROAM
&& status
== BRCMF_E_STATUS_SUCCESS
) {
3611 if (test_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
))
3612 brcmf_bss_roaming_done(cfg_priv
, ndev
, e
);
3614 brcmf_bss_connect_done(cfg_priv
, ndev
, e
, true);
3621 brcmf_notify_mic_status(struct brcmf_cfg80211_priv
*cfg_priv
,
3622 struct net_device
*ndev
,
3623 const struct brcmf_event_msg
*e
, void *data
)
3625 u16 flags
= be16_to_cpu(e
->flags
);
3626 enum nl80211_key_type key_type
;
3628 if (flags
& BRCMF_EVENT_MSG_GROUP
)
3629 key_type
= NL80211_KEYTYPE_GROUP
;
3631 key_type
= NL80211_KEYTYPE_PAIRWISE
;
3633 cfg80211_michael_mic_failure(ndev
, (u8
*)&e
->addr
, key_type
, -1,
3640 brcmf_notify_scan_status(struct brcmf_cfg80211_priv
*cfg_priv
,
3641 struct net_device
*ndev
,
3642 const struct brcmf_event_msg
*e
, void *data
)
3644 struct brcmf_channel_info_le channel_inform_le
;
3645 struct brcmf_scan_results_le
*bss_list_le
;
3646 u32 len
= WL_SCAN_BUF_MAX
;
3648 bool scan_abort
= false;
3651 WL_TRACE("Enter\n");
3653 if (cfg_priv
->iscan_on
&& cfg_priv
->iscan_kickstart
) {
3655 return brcmf_wakeup_iscan(cfg_to_iscan(cfg_priv
));
3658 if (!test_and_clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
)) {
3659 WL_ERR("Scan complete while device not scanning\n");
3665 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_GET_CHANNEL
, &channel_inform_le
,
3666 sizeof(channel_inform_le
));
3668 WL_ERR("scan busy (%d)\n", err
);
3672 scan_channel
= le32_to_cpu(channel_inform_le
.scan_channel
);
3674 WL_CONN("channel_inform.scan_channel (%d)\n", scan_channel
);
3675 cfg_priv
->bss_list
= cfg_priv
->scan_results
;
3676 bss_list_le
= (struct brcmf_scan_results_le
*) cfg_priv
->bss_list
;
3678 memset(cfg_priv
->scan_results
, 0, len
);
3679 bss_list_le
->buflen
= cpu_to_le32(len
);
3680 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SCAN_RESULTS
,
3681 cfg_priv
->scan_results
, len
);
3683 WL_ERR("%s Scan_results error (%d)\n", ndev
->name
, err
);
3688 cfg_priv
->scan_results
->buflen
= le32_to_cpu(bss_list_le
->buflen
);
3689 cfg_priv
->scan_results
->version
= le32_to_cpu(bss_list_le
->version
);
3690 cfg_priv
->scan_results
->count
= le32_to_cpu(bss_list_le
->count
);
3692 err
= brcmf_inform_bss(cfg_priv
);
3697 if (cfg_priv
->scan_request
) {
3698 WL_SCAN("calling cfg80211_scan_done\n");
3699 cfg80211_scan_done(cfg_priv
->scan_request
, scan_abort
);
3700 brcmf_set_mpc(ndev
, 1);
3701 cfg_priv
->scan_request
= NULL
;
3709 static void brcmf_init_conf(struct brcmf_cfg80211_conf
*conf
)
3711 conf
->mode
= (u32
)-1;
3712 conf
->frag_threshold
= (u32
)-1;
3713 conf
->rts_threshold
= (u32
)-1;
3714 conf
->retry_short
= (u32
)-1;
3715 conf
->retry_long
= (u32
)-1;
3716 conf
->tx_power
= -1;
3719 static void brcmf_init_eloop_handler(struct brcmf_cfg80211_event_loop
*el
)
3721 memset(el
, 0, sizeof(*el
));
3722 el
->handler
[BRCMF_E_SCAN_COMPLETE
] = brcmf_notify_scan_status
;
3723 el
->handler
[BRCMF_E_LINK
] = brcmf_notify_connect_status
;
3724 el
->handler
[BRCMF_E_ROAM
] = brcmf_notify_roaming_status
;
3725 el
->handler
[BRCMF_E_MIC_ERROR
] = brcmf_notify_mic_status
;
3726 el
->handler
[BRCMF_E_SET_SSID
] = brcmf_notify_connect_status
;
3729 static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_priv
*cfg_priv
)
3731 kfree(cfg_priv
->scan_results
);
3732 cfg_priv
->scan_results
= NULL
;
3733 kfree(cfg_priv
->bss_info
);
3734 cfg_priv
->bss_info
= NULL
;
3735 kfree(cfg_priv
->conf
);
3736 cfg_priv
->conf
= NULL
;
3737 kfree(cfg_priv
->profile
);
3738 cfg_priv
->profile
= NULL
;
3739 kfree(cfg_priv
->scan_req_int
);
3740 cfg_priv
->scan_req_int
= NULL
;
3741 kfree(cfg_priv
->escan_ioctl_buf
);
3742 cfg_priv
->escan_ioctl_buf
= NULL
;
3743 kfree(cfg_priv
->dcmd_buf
);
3744 cfg_priv
->dcmd_buf
= NULL
;
3745 kfree(cfg_priv
->extra_buf
);
3746 cfg_priv
->extra_buf
= NULL
;
3747 kfree(cfg_priv
->iscan
);
3748 cfg_priv
->iscan
= NULL
;
3749 kfree(cfg_priv
->pmk_list
);
3750 cfg_priv
->pmk_list
= NULL
;
3753 static s32
brcmf_init_priv_mem(struct brcmf_cfg80211_priv
*cfg_priv
)
3755 cfg_priv
->scan_results
= kzalloc(WL_SCAN_BUF_MAX
, GFP_KERNEL
);
3756 if (!cfg_priv
->scan_results
)
3757 goto init_priv_mem_out
;
3758 cfg_priv
->conf
= kzalloc(sizeof(*cfg_priv
->conf
), GFP_KERNEL
);
3759 if (!cfg_priv
->conf
)
3760 goto init_priv_mem_out
;
3761 cfg_priv
->profile
= kzalloc(sizeof(*cfg_priv
->profile
), GFP_KERNEL
);
3762 if (!cfg_priv
->profile
)
3763 goto init_priv_mem_out
;
3764 cfg_priv
->bss_info
= kzalloc(WL_BSS_INFO_MAX
, GFP_KERNEL
);
3765 if (!cfg_priv
->bss_info
)
3766 goto init_priv_mem_out
;
3767 cfg_priv
->scan_req_int
= kzalloc(sizeof(*cfg_priv
->scan_req_int
),
3769 if (!cfg_priv
->scan_req_int
)
3770 goto init_priv_mem_out
;
3771 cfg_priv
->escan_ioctl_buf
= kzalloc(BRCMF_DCMD_MEDLEN
, GFP_KERNEL
);
3772 if (!cfg_priv
->escan_ioctl_buf
)
3773 goto init_priv_mem_out
;
3774 cfg_priv
->dcmd_buf
= kzalloc(WL_DCMD_LEN_MAX
, GFP_KERNEL
);
3775 if (!cfg_priv
->dcmd_buf
)
3776 goto init_priv_mem_out
;
3777 cfg_priv
->extra_buf
= kzalloc(WL_EXTRA_BUF_MAX
, GFP_KERNEL
);
3778 if (!cfg_priv
->extra_buf
)
3779 goto init_priv_mem_out
;
3780 cfg_priv
->iscan
= kzalloc(sizeof(*cfg_priv
->iscan
), GFP_KERNEL
);
3781 if (!cfg_priv
->iscan
)
3782 goto init_priv_mem_out
;
3783 cfg_priv
->pmk_list
= kzalloc(sizeof(*cfg_priv
->pmk_list
), GFP_KERNEL
);
3784 if (!cfg_priv
->pmk_list
)
3785 goto init_priv_mem_out
;
3790 brcmf_deinit_priv_mem(cfg_priv
);
3796 * retrieve first queued event from head
3799 static struct brcmf_cfg80211_event_q
*brcmf_deq_event(
3800 struct brcmf_cfg80211_priv
*cfg_priv
)
3802 struct brcmf_cfg80211_event_q
*e
= NULL
;
3804 spin_lock_irq(&cfg_priv
->evt_q_lock
);
3805 if (!list_empty(&cfg_priv
->evt_q_list
)) {
3806 e
= list_first_entry(&cfg_priv
->evt_q_list
,
3807 struct brcmf_cfg80211_event_q
, evt_q_list
);
3808 list_del(&e
->evt_q_list
);
3810 spin_unlock_irq(&cfg_priv
->evt_q_lock
);
3816 * push event to tail of the queue
3818 * remark: this function may not sleep as it is called in atomic context.
3822 brcmf_enq_event(struct brcmf_cfg80211_priv
*cfg_priv
, u32 event
,
3823 const struct brcmf_event_msg
*msg
, void *data
)
3825 struct brcmf_cfg80211_event_q
*e
;
3831 total_len
= sizeof(struct brcmf_cfg80211_event_q
);
3833 data_len
= be32_to_cpu(msg
->datalen
);
3836 total_len
+= data_len
;
3837 e
= kzalloc(total_len
, GFP_ATOMIC
);
3842 memcpy(&e
->emsg
, msg
, sizeof(struct brcmf_event_msg
));
3844 memcpy(&e
->edata
, data
, data_len
);
3846 spin_lock_irqsave(&cfg_priv
->evt_q_lock
, flags
);
3847 list_add_tail(&e
->evt_q_list
, &cfg_priv
->evt_q_list
);
3848 spin_unlock_irqrestore(&cfg_priv
->evt_q_lock
, flags
);
3853 static void brcmf_put_event(struct brcmf_cfg80211_event_q
*e
)
3858 static void brcmf_cfg80211_event_handler(struct work_struct
*work
)
3860 struct brcmf_cfg80211_priv
*cfg_priv
=
3861 container_of(work
, struct brcmf_cfg80211_priv
,
3863 struct brcmf_cfg80211_event_q
*e
;
3865 e
= brcmf_deq_event(cfg_priv
);
3867 WL_ERR("event queue empty...\n");
3872 WL_INFO("event type (%d)\n", e
->etype
);
3873 if (cfg_priv
->el
.handler
[e
->etype
])
3874 cfg_priv
->el
.handler
[e
->etype
](cfg_priv
,
3875 cfg_to_ndev(cfg_priv
),
3876 &e
->emsg
, e
->edata
);
3878 WL_INFO("Unknown Event (%d): ignoring\n", e
->etype
);
3880 } while ((e
= brcmf_deq_event(cfg_priv
)));
3884 static void brcmf_init_eq(struct brcmf_cfg80211_priv
*cfg_priv
)
3886 spin_lock_init(&cfg_priv
->evt_q_lock
);
3887 INIT_LIST_HEAD(&cfg_priv
->evt_q_list
);
3890 static void brcmf_flush_eq(struct brcmf_cfg80211_priv
*cfg_priv
)
3892 struct brcmf_cfg80211_event_q
*e
;
3894 spin_lock_irq(&cfg_priv
->evt_q_lock
);
3895 while (!list_empty(&cfg_priv
->evt_q_list
)) {
3896 e
= list_first_entry(&cfg_priv
->evt_q_list
,
3897 struct brcmf_cfg80211_event_q
, evt_q_list
);
3898 list_del(&e
->evt_q_list
);
3901 spin_unlock_irq(&cfg_priv
->evt_q_lock
);
3904 static s32
wl_init_priv(struct brcmf_cfg80211_priv
*cfg_priv
)
3908 cfg_priv
->scan_request
= NULL
;
3909 cfg_priv
->pwr_save
= true;
3910 #ifdef CONFIG_BRCMISCAN
3911 cfg_priv
->iscan_on
= true; /* iscan on & off switch.
3912 we enable iscan per default */
3913 cfg_priv
->escan_on
= false; /* escan on & off switch.
3914 we disable escan per default */
3916 cfg_priv
->iscan_on
= false; /* iscan on & off switch.
3917 we disable iscan per default */
3918 cfg_priv
->escan_on
= true; /* escan on & off switch.
3919 we enable escan per default */
3921 cfg_priv
->roam_on
= true; /* roam on & off switch.
3922 we enable roam per default */
3924 cfg_priv
->iscan_kickstart
= false;
3925 cfg_priv
->active_scan
= true; /* we do active scan for
3926 specific scan per default */
3927 cfg_priv
->dongle_up
= false; /* dongle is not up yet */
3928 brcmf_init_eq(cfg_priv
);
3929 err
= brcmf_init_priv_mem(cfg_priv
);
3932 INIT_WORK(&cfg_priv
->event_work
, brcmf_cfg80211_event_handler
);
3933 brcmf_init_eloop_handler(&cfg_priv
->el
);
3934 mutex_init(&cfg_priv
->usr_sync
);
3935 err
= brcmf_init_iscan(cfg_priv
);
3938 brcmf_init_escan(cfg_priv
);
3939 brcmf_init_conf(cfg_priv
->conf
);
3940 brcmf_init_prof(cfg_priv
->profile
);
3941 brcmf_link_down(cfg_priv
);
3946 static void wl_deinit_priv(struct brcmf_cfg80211_priv
*cfg_priv
)
3948 cancel_work_sync(&cfg_priv
->event_work
);
3949 cfg_priv
->dongle_up
= false; /* dongle down */
3950 brcmf_flush_eq(cfg_priv
);
3951 brcmf_link_down(cfg_priv
);
3952 brcmf_term_iscan(cfg_priv
);
3953 brcmf_deinit_priv_mem(cfg_priv
);
3956 struct brcmf_cfg80211_dev
*brcmf_cfg80211_attach(struct net_device
*ndev
,
3957 struct device
*busdev
,
3960 struct wireless_dev
*wdev
;
3961 struct brcmf_cfg80211_priv
*cfg_priv
;
3962 struct brcmf_cfg80211_iface
*ci
;
3963 struct brcmf_cfg80211_dev
*cfg_dev
;
3967 WL_ERR("ndev is invalid\n");
3970 cfg_dev
= kzalloc(sizeof(struct brcmf_cfg80211_dev
), GFP_KERNEL
);
3974 wdev
= brcmf_alloc_wdev(sizeof(struct brcmf_cfg80211_iface
), busdev
);
3980 wdev
->iftype
= brcmf_mode_to_nl80211_iftype(WL_MODE_BSS
);
3981 cfg_priv
= wdev_to_cfg(wdev
);
3982 cfg_priv
->wdev
= wdev
;
3983 cfg_priv
->pub
= data
;
3984 ci
= (struct brcmf_cfg80211_iface
*)&cfg_priv
->ci
;
3985 ci
->cfg_priv
= cfg_priv
;
3986 ndev
->ieee80211_ptr
= wdev
;
3987 SET_NETDEV_DEV(ndev
, wiphy_dev(wdev
->wiphy
));
3988 wdev
->netdev
= ndev
;
3989 err
= wl_init_priv(cfg_priv
);
3991 WL_ERR("Failed to init iwm_priv (%d)\n", err
);
3992 goto cfg80211_attach_out
;
3994 brcmf_set_drvdata(cfg_dev
, ci
);
3998 cfg80211_attach_out
:
3999 brcmf_free_wdev(cfg_priv
);
4004 void brcmf_cfg80211_detach(struct brcmf_cfg80211_dev
*cfg_dev
)
4006 struct brcmf_cfg80211_priv
*cfg_priv
;
4008 cfg_priv
= brcmf_priv_get(cfg_dev
);
4010 wl_deinit_priv(cfg_priv
);
4011 brcmf_free_wdev(cfg_priv
);
4012 brcmf_set_drvdata(cfg_dev
, NULL
);
4017 brcmf_cfg80211_event(struct net_device
*ndev
,
4018 const struct brcmf_event_msg
*e
, void *data
)
4020 u32 event_type
= be32_to_cpu(e
->event_type
);
4021 struct brcmf_cfg80211_priv
*cfg_priv
= ndev_to_cfg(ndev
);
4023 if (!brcmf_enq_event(cfg_priv
, event_type
, e
, data
))
4024 schedule_work(&cfg_priv
->event_work
);
4027 static s32
brcmf_dongle_mode(struct net_device
*ndev
, s32 iftype
)
4033 case NL80211_IFTYPE_MONITOR
:
4034 case NL80211_IFTYPE_WDS
:
4035 WL_ERR("type (%d) : currently we do not support this mode\n",
4039 case NL80211_IFTYPE_ADHOC
:
4042 case NL80211_IFTYPE_STATION
:
4047 WL_ERR("invalid type (%d)\n", iftype
);
4050 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_INFRA
, &infra
);
4052 WL_ERR("WLC_SET_INFRA error (%d)\n", err
);
4059 static s32
brcmf_dongle_eventmsg(struct net_device
*ndev
)
4061 /* Room for "event_msgs" + '\0' + bitvec */
4062 s8 iovbuf
[BRCMF_EVENTING_MASK_LEN
+ 12];
4063 s8 eventmask
[BRCMF_EVENTING_MASK_LEN
];
4066 WL_TRACE("Enter\n");
4068 /* Setup event_msgs */
4069 brcmf_c_mkiovar("event_msgs", eventmask
, BRCMF_EVENTING_MASK_LEN
,
4070 iovbuf
, sizeof(iovbuf
));
4071 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_GET_VAR
, iovbuf
, sizeof(iovbuf
));
4073 WL_ERR("Get event_msgs error (%d)\n", err
);
4074 goto dongle_eventmsg_out
;
4076 memcpy(eventmask
, iovbuf
, BRCMF_EVENTING_MASK_LEN
);
4078 setbit(eventmask
, BRCMF_E_SET_SSID
);
4079 setbit(eventmask
, BRCMF_E_ROAM
);
4080 setbit(eventmask
, BRCMF_E_PRUNE
);
4081 setbit(eventmask
, BRCMF_E_AUTH
);
4082 setbit(eventmask
, BRCMF_E_REASSOC
);
4083 setbit(eventmask
, BRCMF_E_REASSOC_IND
);
4084 setbit(eventmask
, BRCMF_E_DEAUTH_IND
);
4085 setbit(eventmask
, BRCMF_E_DISASSOC_IND
);
4086 setbit(eventmask
, BRCMF_E_DISASSOC
);
4087 setbit(eventmask
, BRCMF_E_JOIN
);
4088 setbit(eventmask
, BRCMF_E_ASSOC_IND
);
4089 setbit(eventmask
, BRCMF_E_PSK_SUP
);
4090 setbit(eventmask
, BRCMF_E_LINK
);
4091 setbit(eventmask
, BRCMF_E_NDIS_LINK
);
4092 setbit(eventmask
, BRCMF_E_MIC_ERROR
);
4093 setbit(eventmask
, BRCMF_E_PMKID_CACHE
);
4094 setbit(eventmask
, BRCMF_E_TXFAIL
);
4095 setbit(eventmask
, BRCMF_E_JOIN_START
);
4096 setbit(eventmask
, BRCMF_E_SCAN_COMPLETE
);
4097 setbit(eventmask
, BRCMF_E_ESCAN_RESULT
);
4099 brcmf_c_mkiovar("event_msgs", eventmask
, BRCMF_EVENTING_MASK_LEN
,
4100 iovbuf
, sizeof(iovbuf
));
4101 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_VAR
, iovbuf
, sizeof(iovbuf
));
4103 WL_ERR("Set event_msgs error (%d)\n", err
);
4104 goto dongle_eventmsg_out
;
4107 dongle_eventmsg_out
:
4113 brcmf_dongle_roam(struct net_device
*ndev
, u32 roamvar
, u32 bcn_timeout
)
4117 __le32 roamtrigger
[2];
4118 __le32 roam_delta
[2];
4123 * Setup timeout if Beacons are lost and roam is
4124 * off to report link down
4127 bcn_to_le
= cpu_to_le32(bcn_timeout
);
4128 brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_to_le
,
4129 sizeof(bcn_to_le
), iovbuf
, sizeof(iovbuf
));
4130 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_VAR
,
4131 iovbuf
, sizeof(iovbuf
));
4133 WL_ERR("bcn_timeout error (%d)\n", err
);
4134 goto dongle_rom_out
;
4139 * Enable/Disable built-in roaming to allow supplicant
4140 * to take care of roaming
4142 WL_INFO("Internal Roaming = %s\n", roamvar
? "Off" : "On");
4143 roamvar_le
= cpu_to_le32(roamvar
);
4144 brcmf_c_mkiovar("roam_off", (char *)&roamvar_le
,
4145 sizeof(roamvar_le
), iovbuf
, sizeof(iovbuf
));
4146 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_VAR
, iovbuf
, sizeof(iovbuf
));
4148 WL_ERR("roam_off error (%d)\n", err
);
4149 goto dongle_rom_out
;
4152 roamtrigger
[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL
);
4153 roamtrigger
[1] = cpu_to_le32(BRCM_BAND_ALL
);
4154 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_ROAM_TRIGGER
,
4155 (void *)roamtrigger
, sizeof(roamtrigger
));
4157 WL_ERR("WLC_SET_ROAM_TRIGGER error (%d)\n", err
);
4158 goto dongle_rom_out
;
4161 roam_delta
[0] = cpu_to_le32(WL_ROAM_DELTA
);
4162 roam_delta
[1] = cpu_to_le32(BRCM_BAND_ALL
);
4163 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_ROAM_DELTA
,
4164 (void *)roam_delta
, sizeof(roam_delta
));
4166 WL_ERR("WLC_SET_ROAM_DELTA error (%d)\n", err
);
4167 goto dongle_rom_out
;
4175 brcmf_dongle_scantime(struct net_device
*ndev
, s32 scan_assoc_time
,
4176 s32 scan_unassoc_time
, s32 scan_passive_time
)
4179 __le32 scan_assoc_tm_le
= cpu_to_le32(scan_assoc_time
);
4180 __le32 scan_unassoc_tm_le
= cpu_to_le32(scan_unassoc_time
);
4181 __le32 scan_passive_tm_le
= cpu_to_le32(scan_passive_time
);
4183 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_SCAN_CHANNEL_TIME
,
4184 &scan_assoc_tm_le
, sizeof(scan_assoc_tm_le
));
4186 if (err
== -EOPNOTSUPP
)
4187 WL_INFO("Scan assoc time is not supported\n");
4189 WL_ERR("Scan assoc time error (%d)\n", err
);
4190 goto dongle_scantime_out
;
4192 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_SCAN_UNASSOC_TIME
,
4193 &scan_unassoc_tm_le
, sizeof(scan_unassoc_tm_le
));
4195 if (err
== -EOPNOTSUPP
)
4196 WL_INFO("Scan unassoc time is not supported\n");
4198 WL_ERR("Scan unassoc time error (%d)\n", err
);
4199 goto dongle_scantime_out
;
4202 err
= brcmf_exec_dcmd(ndev
, BRCMF_C_SET_SCAN_PASSIVE_TIME
,
4203 &scan_passive_tm_le
, sizeof(scan_passive_tm_le
));
4205 if (err
== -EOPNOTSUPP
)
4206 WL_INFO("Scan passive time is not supported\n");
4208 WL_ERR("Scan passive time error (%d)\n", err
);
4209 goto dongle_scantime_out
;
4212 dongle_scantime_out
:
4216 static s32
wl_update_wiphybands(struct brcmf_cfg80211_priv
*cfg_priv
)
4218 struct wiphy
*wiphy
;
4223 err
= brcmf_exec_dcmd(cfg_to_ndev(cfg_priv
), BRCM_GET_PHYLIST
,
4224 &phy_list
, sizeof(phy_list
));
4226 WL_ERR("error (%d)\n", err
);
4230 phy
= ((char *)&phy_list
)[1];
4231 WL_INFO("%c phy\n", phy
);
4232 if (phy
== 'n' || phy
== 'a') {
4233 wiphy
= cfg_to_wiphy(cfg_priv
);
4234 wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &__wl_band_5ghz_n
;
4240 static s32
brcmf_dongle_probecap(struct brcmf_cfg80211_priv
*cfg_priv
)
4242 return wl_update_wiphybands(cfg_priv
);
4245 static s32
brcmf_config_dongle(struct brcmf_cfg80211_priv
*cfg_priv
)
4247 struct net_device
*ndev
;
4248 struct wireless_dev
*wdev
;
4252 if (cfg_priv
->dongle_up
)
4255 ndev
= cfg_to_ndev(cfg_priv
);
4256 wdev
= ndev
->ieee80211_ptr
;
4258 brcmf_dongle_scantime(ndev
, WL_SCAN_CHANNEL_TIME
,
4259 WL_SCAN_UNASSOC_TIME
, WL_SCAN_PASSIVE_TIME
);
4261 err
= brcmf_dongle_eventmsg(ndev
);
4263 goto default_conf_out
;
4265 power_mode
= cfg_priv
->pwr_save
? PM_FAST
: PM_OFF
;
4266 err
= brcmf_exec_dcmd_u32(ndev
, BRCMF_C_SET_PM
, &power_mode
);
4268 goto default_conf_out
;
4269 WL_INFO("power save set to %s\n",
4270 (power_mode
? "enabled" : "disabled"));
4272 err
= brcmf_dongle_roam(ndev
, (cfg_priv
->roam_on
? 0 : 1),
4275 goto default_conf_out
;
4276 err
= brcmf_dongle_mode(ndev
, wdev
->iftype
);
4277 if (err
&& err
!= -EINPROGRESS
)
4278 goto default_conf_out
;
4279 err
= brcmf_dongle_probecap(cfg_priv
);
4281 goto default_conf_out
;
4283 /* -EINPROGRESS: Call commit handler */
4287 cfg_priv
->dongle_up
= true;
4293 static int brcmf_debugfs_add_netdev_params(struct brcmf_cfg80211_priv
*cfg_priv
)
4295 char buf
[10+IFNAMSIZ
];
4299 sprintf(buf
, "netdev:%s", cfg_to_ndev(cfg_priv
)->name
);
4300 cfg_priv
->debugfsdir
= debugfs_create_dir(buf
,
4301 cfg_to_wiphy(cfg_priv
)->debugfsdir
);
4303 fd
= debugfs_create_u16("beacon_int", S_IRUGO
, cfg_priv
->debugfsdir
,
4304 (u16
*)&cfg_priv
->profile
->beacon_interval
);
4310 fd
= debugfs_create_u8("dtim_period", S_IRUGO
, cfg_priv
->debugfsdir
,
4311 (u8
*)&cfg_priv
->profile
->dtim_period
);
4321 static void brcmf_debugfs_remove_netdev(struct brcmf_cfg80211_priv
*cfg_priv
)
4323 debugfs_remove_recursive(cfg_priv
->debugfsdir
);
4324 cfg_priv
->debugfsdir
= NULL
;
4327 static s32
__brcmf_cfg80211_up(struct brcmf_cfg80211_priv
*cfg_priv
)
4331 set_bit(WL_STATUS_READY
, &cfg_priv
->status
);
4333 brcmf_debugfs_add_netdev_params(cfg_priv
);
4335 err
= brcmf_config_dongle(cfg_priv
);
4339 brcmf_invoke_iscan(cfg_priv
);
4344 static s32
__brcmf_cfg80211_down(struct brcmf_cfg80211_priv
*cfg_priv
)
4347 * While going down, if associated with AP disassociate
4348 * from AP to save power
4350 if ((test_bit(WL_STATUS_CONNECTED
, &cfg_priv
->status
) ||
4351 test_bit(WL_STATUS_CONNECTING
, &cfg_priv
->status
)) &&
4352 test_bit(WL_STATUS_READY
, &cfg_priv
->status
)) {
4353 WL_INFO("Disassociating from AP");
4354 brcmf_link_down(cfg_priv
);
4356 /* Make sure WPA_Supplicant receives all the event
4357 generated due to DISASSOC call to the fw to keep
4358 the state fw and WPA_Supplicant state consistent
4363 set_bit(WL_STATUS_SCAN_ABORTING
, &cfg_priv
->status
);
4364 brcmf_term_iscan(cfg_priv
);
4365 if (cfg_priv
->scan_request
) {
4366 cfg80211_scan_done(cfg_priv
->scan_request
, true);
4367 /* May need to perform this to cover rmmod */
4368 /* wl_set_mpc(cfg_to_ndev(wl), 1); */
4369 cfg_priv
->scan_request
= NULL
;
4371 clear_bit(WL_STATUS_READY
, &cfg_priv
->status
);
4372 clear_bit(WL_STATUS_SCANNING
, &cfg_priv
->status
);
4373 clear_bit(WL_STATUS_SCAN_ABORTING
, &cfg_priv
->status
);
4375 brcmf_debugfs_remove_netdev(cfg_priv
);
4380 s32
brcmf_cfg80211_up(struct brcmf_cfg80211_dev
*cfg_dev
)
4382 struct brcmf_cfg80211_priv
*cfg_priv
;
4385 cfg_priv
= brcmf_priv_get(cfg_dev
);
4386 mutex_lock(&cfg_priv
->usr_sync
);
4387 err
= __brcmf_cfg80211_up(cfg_priv
);
4388 mutex_unlock(&cfg_priv
->usr_sync
);
4393 s32
brcmf_cfg80211_down(struct brcmf_cfg80211_dev
*cfg_dev
)
4395 struct brcmf_cfg80211_priv
*cfg_priv
;
4398 cfg_priv
= brcmf_priv_get(cfg_dev
);
4399 mutex_lock(&cfg_priv
->usr_sync
);
4400 err
= __brcmf_cfg80211_down(cfg_priv
);
4401 mutex_unlock(&cfg_priv
->usr_sync
);
4406 static __used s32
brcmf_add_ie(struct brcmf_cfg80211_priv
*cfg_priv
,
4409 struct brcmf_cfg80211_ie
*ie
= &cfg_priv
->ie
;
4412 if (ie
->offset
+ l
+ 2 > WL_TLV_INFO_MAX
) {
4413 WL_ERR("ei crosses buffer boundary\n");
4416 ie
->buf
[ie
->offset
] = t
;
4417 ie
->buf
[ie
->offset
+ 1] = l
;
4418 memcpy(&ie
->buf
[ie
->offset
+ 2], v
, l
);
4419 ie
->offset
+= l
+ 2;