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 #include <linux/kernel.h>
18 #include <linux/if_arp.h>
19 #include <linux/sched.h>
25 #include <asm/uaccess.h>
27 #include <dngl_stats.h>
30 #include <linux/kthread.h>
31 #include <linux/netdevice.h>
32 #include <linux/sched.h>
33 #include <linux/etherdevice.h>
34 #include <linux/wireless.h>
35 #include <linux/ieee80211.h>
36 #include <net/cfg80211.h>
38 #include <net/rtnetlink.h>
39 #include <linux/mmc/sdio_func.h>
40 #include <linux/firmware.h>
41 #include <wl_cfg80211.h>
43 void sdioh_sdio_set_host_pm_flags(int flag);
45 static struct sdio_func *cfg80211_sdio_func;
46 static struct wl_dev *wl_cfg80211_dev;
47 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
49 u32 brcmf_dbg_level = WL_DBG_ERR;
51 #define WL_4329_FW_FILE "brcm/bcm4329-fullmac-4.bin"
52 #define WL_4329_NVRAM_FILE "brcm/bcm4329-fullmac-4.txt"
55 ** cfg80211_ops api/callback list
57 static s32 wl_cfg80211_change_iface(struct wiphy *wiphy,
58 struct net_device *ndev,
59 enum nl80211_iftype type, u32 *flags,
60 struct vif_params *params);
61 static s32 __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
62 struct cfg80211_scan_request *request,
63 struct cfg80211_ssid *this_ssid);
64 static s32 wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
65 struct cfg80211_scan_request *request);
66 static s32 wl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed);
67 static s32 wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
68 struct cfg80211_ibss_params *params);
69 static s32 wl_cfg80211_leave_ibss(struct wiphy *wiphy,
70 struct net_device *dev);
71 static s32 wl_cfg80211_get_station(struct wiphy *wiphy,
72 struct net_device *dev, u8 *mac,
73 struct station_info *sinfo);
74 static s32 wl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
75 struct net_device *dev, bool enabled,
77 static s32 wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
78 struct net_device *dev,
80 const struct cfg80211_bitrate_mask
82 static int wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
83 struct cfg80211_connect_params *sme);
84 static s32 wl_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
86 static s32 wl_cfg80211_set_tx_power(struct wiphy *wiphy,
87 enum nl80211_tx_power_setting type,
89 static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm);
90 static s32 wl_cfg80211_config_default_key(struct wiphy *wiphy,
91 struct net_device *dev, u8 key_idx,
92 bool unicast, bool multicast);
93 static s32 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
94 u8 key_idx, bool pairwise, const u8 *mac_addr,
95 struct key_params *params);
96 static s32 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
97 u8 key_idx, bool pairwise, const u8 *mac_addr);
98 static s32 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
99 u8 key_idx, bool pairwise, const u8 *mac_addr,
100 void *cookie, void (*callback) (void *cookie,
104 static s32 wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
105 struct net_device *dev,
107 static s32 wl_cfg80211_resume(struct wiphy *wiphy);
108 static s32 wl_cfg80211_suspend(struct wiphy *wiphy);
109 static s32 wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
110 struct cfg80211_pmksa *pmksa);
111 static s32 wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
112 struct cfg80211_pmksa *pmksa);
113 static s32 wl_cfg80211_flush_pmksa(struct wiphy *wiphy,
114 struct net_device *dev);
116 ** event & event Q handlers for cfg80211 interfaces
118 static s32 wl_create_event_handler(struct wl_priv *wl);
119 static void wl_destroy_event_handler(struct wl_priv *wl);
120 static s32 wl_event_handler(void *data);
121 static void wl_init_eq(struct wl_priv *wl);
122 static void wl_flush_eq(struct wl_priv *wl);
123 static void wl_lock_eq(struct wl_priv *wl);
124 static void wl_unlock_eq(struct wl_priv *wl);
125 static void wl_init_eq_lock(struct wl_priv *wl);
126 static void wl_init_eloop_handler(struct wl_event_loop *el);
127 static struct wl_event_q *wl_deq_event(struct wl_priv *wl);
128 static s32 wl_enq_event(struct wl_priv *wl, u32 type,
129 const wl_event_msg_t *msg, void *data);
130 static void wl_put_event(struct wl_event_q *e);
131 static void wl_wakeup_event(struct wl_priv *wl);
132 static s32 wl_notify_connect_status(struct wl_priv *wl,
133 struct net_device *ndev,
134 const wl_event_msg_t *e, void *data);
135 static s32 wl_notify_roaming_status(struct wl_priv *wl,
136 struct net_device *ndev,
137 const wl_event_msg_t *e, void *data);
138 static s32 wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
139 const wl_event_msg_t *e, void *data);
140 static s32 wl_bss_connect_done(struct wl_priv *wl, struct net_device *ndev,
141 const wl_event_msg_t *e, void *data,
143 static s32 wl_bss_roaming_done(struct wl_priv *wl, struct net_device *ndev,
144 const wl_event_msg_t *e, void *data);
145 static s32 wl_notify_mic_status(struct wl_priv *wl, struct net_device *ndev,
146 const wl_event_msg_t *e, void *data);
149 ** register/deregister sdio function
151 struct sdio_func *wl_cfg80211_get_sdio_func(void);
152 static void wl_clear_sdio_func(void);
157 static s32 wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
159 static __used s32 wl_dev_bufvar_set(struct net_device *dev, s8 *name,
161 static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val);
162 static s32 wl_dev_intvar_get(struct net_device *dev, s8 *name,
164 static s32 wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg,
168 ** cfg80211 set_wiphy_params utilities
170 static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold);
171 static s32 wl_set_rts(struct net_device *dev, u32 frag_threshold);
172 static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l);
175 ** wl profile utilities
177 static s32 wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e,
178 void *data, s32 item);
179 static void *wl_read_prof(struct wl_priv *wl, s32 item);
180 static void wl_init_prof(struct wl_profile *prof);
183 ** cfg80211 connect utilites
185 static s32 wl_set_wpa_version(struct net_device *dev,
186 struct cfg80211_connect_params *sme);
187 static s32 wl_set_auth_type(struct net_device *dev,
188 struct cfg80211_connect_params *sme);
189 static s32 wl_set_set_cipher(struct net_device *dev,
190 struct cfg80211_connect_params *sme);
191 static s32 wl_set_key_mgmt(struct net_device *dev,
192 struct cfg80211_connect_params *sme);
193 static s32 wl_set_set_sharedkey(struct net_device *dev,
194 struct cfg80211_connect_params *sme);
195 static s32 wl_get_assoc_ies(struct wl_priv *wl);
196 static void wl_clear_assoc_ies(struct wl_priv *wl);
197 static void wl_ch_to_chanspec(int ch,
198 struct wl_join_params *join_params, size_t *join_params_size);
201 ** information element utilities
203 static __used s32 wl_add_ie(struct wl_priv *wl, u8 t, u8 l, u8 *v);
204 static s32 wl_mode_to_nl80211_iftype(s32 mode);
205 static struct wireless_dev *wl_alloc_wdev(s32 sizeof_iface,
207 static void wl_free_wdev(struct wl_priv *wl);
208 static s32 wl_inform_bss(struct wl_priv *wl);
209 static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi);
210 static s32 wl_update_bss_info(struct wl_priv *wl);
211 static s32 wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
212 u8 key_idx, const u8 *mac_addr,
213 struct key_params *params);
216 ** key indianess swap utilities
218 static void swap_key_from_BE(struct wl_wsec_key *key);
219 static void swap_key_to_BE(struct wl_wsec_key *key);
222 ** wl_priv memory init/deinit utilities
224 static s32 wl_init_priv_mem(struct wl_priv *wl);
225 static void wl_deinit_priv_mem(struct wl_priv *wl);
227 static void wl_delay(u32 ms);
230 ** store/restore cfg80211 instance data
232 static void wl_set_drvdata(struct wl_dev *dev, void *data);
233 static void *wl_get_drvdata(struct wl_dev *dev);
236 ** ibss mode utilities
238 static bool wl_is_ibssmode(struct wl_priv *wl);
241 ** dongle up/down , default configuration utilities
243 static bool wl_is_linkdown(struct wl_priv *wl, const wl_event_msg_t *e);
244 static bool wl_is_linkup(struct wl_priv *wl, const wl_event_msg_t *e);
245 static bool wl_is_nonetwork(struct wl_priv *wl, const wl_event_msg_t *e);
246 static void wl_link_down(struct wl_priv *wl);
247 static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype);
248 static s32 __wl_cfg80211_up(struct wl_priv *wl);
249 static s32 __wl_cfg80211_down(struct wl_priv *wl);
250 static s32 wl_dongle_probecap(struct wl_priv *wl);
251 static void wl_init_conf(struct wl_conf *conf);
254 ** dongle configuration utilities
256 #ifndef EMBEDDED_PLATFORM
257 static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype);
258 static s32 wl_dongle_country(struct net_device *ndev, u8 ccode);
259 static s32 wl_dongle_up(struct net_device *ndev, u32 up);
260 static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode);
261 static s32 wl_dongle_glom(struct net_device *ndev, u32 glom,
263 static s32 wl_dongle_offload(struct net_device *ndev, s32 arpoe,
265 static s32 wl_pattern_atoh(s8 *src, s8 *dst);
266 static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode);
267 static s32 wl_update_wiphybands(struct wl_priv *wl);
268 #endif /* !EMBEDDED_PLATFORM */
270 static s32 wl_dongle_eventmsg(struct net_device *ndev);
271 static s32 wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
272 s32 scan_unassoc_time, s32 scan_passive_time);
273 static s32 wl_config_dongle(struct wl_priv *wl, bool need_lock);
274 static s32 wl_dongle_roam(struct net_device *ndev, u32 roamvar,
280 static void wl_iscan_timer(unsigned long data);
281 static void wl_term_iscan(struct wl_priv *wl);
282 static s32 wl_init_iscan(struct wl_priv *wl);
283 static s32 wl_iscan_thread(void *data);
284 static s32 wl_dev_iovar_setbuf(struct net_device *dev, s8 *iovar,
285 void *param, s32 paramlen, void *bufptr,
287 static s32 wl_dev_iovar_getbuf(struct net_device *dev, s8 *iovar,
288 void *param, s32 paramlen, void *bufptr,
290 static s32 wl_run_iscan(struct wl_iscan_ctrl *iscan, struct wlc_ssid *ssid,
292 static s32 wl_do_iscan(struct wl_priv *wl);
293 static s32 wl_wakeup_iscan(struct wl_iscan_ctrl *iscan);
294 static s32 wl_invoke_iscan(struct wl_priv *wl);
295 static s32 wl_get_iscan_results(struct wl_iscan_ctrl *iscan, u32 *status,
296 struct wl_scan_results **bss_list);
297 static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted);
298 static void wl_init_iscan_eloop(struct wl_iscan_eloop *el);
299 static s32 wl_iscan_done(struct wl_priv *wl);
300 static s32 wl_iscan_pending(struct wl_priv *wl);
301 static s32 wl_iscan_inprogress(struct wl_priv *wl);
302 static s32 wl_iscan_aborted(struct wl_priv *wl);
305 ** fw/nvram downloading handler
307 static void wl_init_fw(struct wl_fw_ctrl *fw);
310 * find most significant bit set
312 static __used u32 wl_find_msb(u16 bit16);
315 * update pmklist to dongle
317 static __used s32 wl_update_pmklist(struct net_device *dev,
318 struct wl_pmk_list *pmk_list, s32 err);
320 static void wl_set_mpc(struct net_device *ndev, int mpc);
325 static int wl_debugfs_add_netdev_params(struct wl_priv *wl);
326 static void wl_debugfs_remove_netdev(struct wl_priv *wl);
328 #define WL_PRIV_GET() \
330 struct wl_iface *ci; \
331 if (unlikely(!(wl_cfg80211_dev && \
332 (ci = wl_get_drvdata(wl_cfg80211_dev))))) { \
333 WL_ERR("wl_cfg80211_dev is unavailable\n"); \
339 #define CHECK_SYS_UP() \
341 struct wl_priv *wl = wiphy_to_wl(wiphy); \
342 if (unlikely(!test_bit(WL_STATUS_READY, &wl->status))) { \
343 WL_INFO("device is not ready : status (%d)\n", \
349 extern int dhd_wait_pend8021x(struct net_device *dev);
350 #define CHAN2G(_channel, _freq, _flags) { \
351 .band = IEEE80211_BAND_2GHZ, \
352 .center_freq = (_freq), \
353 .hw_value = (_channel), \
355 .max_antenna_gain = 0, \
359 #define CHAN5G(_channel, _flags) { \
360 .band = IEEE80211_BAND_5GHZ, \
361 .center_freq = 5000 + (5 * (_channel)), \
362 .hw_value = (_channel), \
364 .max_antenna_gain = 0, \
368 #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
369 #define RATETAB_ENT(_rateid, _flags) \
371 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
372 .hw_value = (_rateid), \
376 static struct ieee80211_rate __wl_rates[] = {
377 RATETAB_ENT(WLC_RATE_1M, 0),
378 RATETAB_ENT(WLC_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
379 RATETAB_ENT(WLC_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
380 RATETAB_ENT(WLC_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
381 RATETAB_ENT(WLC_RATE_6M, 0),
382 RATETAB_ENT(WLC_RATE_9M, 0),
383 RATETAB_ENT(WLC_RATE_12M, 0),
384 RATETAB_ENT(WLC_RATE_18M, 0),
385 RATETAB_ENT(WLC_RATE_24M, 0),
386 RATETAB_ENT(WLC_RATE_36M, 0),
387 RATETAB_ENT(WLC_RATE_48M, 0),
388 RATETAB_ENT(WLC_RATE_54M, 0),
391 #define wl_a_rates (__wl_rates + 4)
392 #define wl_a_rates_size 8
393 #define wl_g_rates (__wl_rates + 0)
394 #define wl_g_rates_size 12
396 static struct ieee80211_channel __wl_2ghz_channels[] = {
413 static struct ieee80211_channel __wl_5ghz_a_channels[] = {
414 CHAN5G(34, 0), CHAN5G(36, 0),
415 CHAN5G(38, 0), CHAN5G(40, 0),
416 CHAN5G(42, 0), CHAN5G(44, 0),
417 CHAN5G(46, 0), CHAN5G(48, 0),
418 CHAN5G(52, 0), CHAN5G(56, 0),
419 CHAN5G(60, 0), CHAN5G(64, 0),
420 CHAN5G(100, 0), CHAN5G(104, 0),
421 CHAN5G(108, 0), CHAN5G(112, 0),
422 CHAN5G(116, 0), CHAN5G(120, 0),
423 CHAN5G(124, 0), CHAN5G(128, 0),
424 CHAN5G(132, 0), CHAN5G(136, 0),
425 CHAN5G(140, 0), CHAN5G(149, 0),
426 CHAN5G(153, 0), CHAN5G(157, 0),
427 CHAN5G(161, 0), CHAN5G(165, 0),
428 CHAN5G(184, 0), CHAN5G(188, 0),
429 CHAN5G(192, 0), CHAN5G(196, 0),
430 CHAN5G(200, 0), CHAN5G(204, 0),
431 CHAN5G(208, 0), CHAN5G(212, 0),
435 static struct ieee80211_channel __wl_5ghz_n_channels[] = {
436 CHAN5G(32, 0), CHAN5G(34, 0),
437 CHAN5G(36, 0), CHAN5G(38, 0),
438 CHAN5G(40, 0), CHAN5G(42, 0),
439 CHAN5G(44, 0), CHAN5G(46, 0),
440 CHAN5G(48, 0), CHAN5G(50, 0),
441 CHAN5G(52, 0), CHAN5G(54, 0),
442 CHAN5G(56, 0), CHAN5G(58, 0),
443 CHAN5G(60, 0), CHAN5G(62, 0),
444 CHAN5G(64, 0), CHAN5G(66, 0),
445 CHAN5G(68, 0), CHAN5G(70, 0),
446 CHAN5G(72, 0), CHAN5G(74, 0),
447 CHAN5G(76, 0), CHAN5G(78, 0),
448 CHAN5G(80, 0), CHAN5G(82, 0),
449 CHAN5G(84, 0), CHAN5G(86, 0),
450 CHAN5G(88, 0), CHAN5G(90, 0),
451 CHAN5G(92, 0), CHAN5G(94, 0),
452 CHAN5G(96, 0), CHAN5G(98, 0),
453 CHAN5G(100, 0), CHAN5G(102, 0),
454 CHAN5G(104, 0), CHAN5G(106, 0),
455 CHAN5G(108, 0), CHAN5G(110, 0),
456 CHAN5G(112, 0), CHAN5G(114, 0),
457 CHAN5G(116, 0), CHAN5G(118, 0),
458 CHAN5G(120, 0), CHAN5G(122, 0),
459 CHAN5G(124, 0), CHAN5G(126, 0),
460 CHAN5G(128, 0), CHAN5G(130, 0),
461 CHAN5G(132, 0), CHAN5G(134, 0),
462 CHAN5G(136, 0), CHAN5G(138, 0),
463 CHAN5G(140, 0), CHAN5G(142, 0),
464 CHAN5G(144, 0), CHAN5G(145, 0),
465 CHAN5G(146, 0), CHAN5G(147, 0),
466 CHAN5G(148, 0), CHAN5G(149, 0),
467 CHAN5G(150, 0), CHAN5G(151, 0),
468 CHAN5G(152, 0), CHAN5G(153, 0),
469 CHAN5G(154, 0), CHAN5G(155, 0),
470 CHAN5G(156, 0), CHAN5G(157, 0),
471 CHAN5G(158, 0), CHAN5G(159, 0),
472 CHAN5G(160, 0), CHAN5G(161, 0),
473 CHAN5G(162, 0), CHAN5G(163, 0),
474 CHAN5G(164, 0), CHAN5G(165, 0),
475 CHAN5G(166, 0), CHAN5G(168, 0),
476 CHAN5G(170, 0), CHAN5G(172, 0),
477 CHAN5G(174, 0), CHAN5G(176, 0),
478 CHAN5G(178, 0), CHAN5G(180, 0),
479 CHAN5G(182, 0), CHAN5G(184, 0),
480 CHAN5G(186, 0), CHAN5G(188, 0),
481 CHAN5G(190, 0), CHAN5G(192, 0),
482 CHAN5G(194, 0), CHAN5G(196, 0),
483 CHAN5G(198, 0), CHAN5G(200, 0),
484 CHAN5G(202, 0), CHAN5G(204, 0),
485 CHAN5G(206, 0), CHAN5G(208, 0),
486 CHAN5G(210, 0), CHAN5G(212, 0),
487 CHAN5G(214, 0), CHAN5G(216, 0),
488 CHAN5G(218, 0), CHAN5G(220, 0),
489 CHAN5G(222, 0), CHAN5G(224, 0),
490 CHAN5G(226, 0), CHAN5G(228, 0),
493 static struct ieee80211_supported_band __wl_band_2ghz = {
494 .band = IEEE80211_BAND_2GHZ,
495 .channels = __wl_2ghz_channels,
496 .n_channels = ARRAY_SIZE(__wl_2ghz_channels),
497 .bitrates = wl_g_rates,
498 .n_bitrates = wl_g_rates_size,
501 static struct ieee80211_supported_band __wl_band_5ghz_a = {
502 .band = IEEE80211_BAND_5GHZ,
503 .channels = __wl_5ghz_a_channels,
504 .n_channels = ARRAY_SIZE(__wl_5ghz_a_channels),
505 .bitrates = wl_a_rates,
506 .n_bitrates = wl_a_rates_size,
509 static struct ieee80211_supported_band __wl_band_5ghz_n = {
510 .band = IEEE80211_BAND_5GHZ,
511 .channels = __wl_5ghz_n_channels,
512 .n_channels = ARRAY_SIZE(__wl_5ghz_n_channels),
513 .bitrates = wl_a_rates,
514 .n_bitrates = wl_a_rates_size,
517 static const u32 __wl_cipher_suites[] = {
518 WLAN_CIPHER_SUITE_WEP40,
519 WLAN_CIPHER_SUITE_WEP104,
520 WLAN_CIPHER_SUITE_TKIP,
521 WLAN_CIPHER_SUITE_CCMP,
522 WLAN_CIPHER_SUITE_AES_CMAC,
525 static void swap_key_from_BE(struct wl_wsec_key *key)
527 key->index = cpu_to_le32(key->index);
528 key->len = cpu_to_le32(key->len);
529 key->algo = cpu_to_le32(key->algo);
530 key->flags = cpu_to_le32(key->flags);
531 key->rxiv.hi = cpu_to_le32(key->rxiv.hi);
532 key->rxiv.lo = cpu_to_le16(key->rxiv.lo);
533 key->iv_initialized = cpu_to_le32(key->iv_initialized);
536 static void swap_key_to_BE(struct wl_wsec_key *key)
538 key->index = le32_to_cpu(key->index);
539 key->len = le32_to_cpu(key->len);
540 key->algo = le32_to_cpu(key->algo);
541 key->flags = le32_to_cpu(key->flags);
542 key->rxiv.hi = le32_to_cpu(key->rxiv.hi);
543 key->rxiv.lo = le16_to_cpu(key->rxiv.lo);
544 key->iv_initialized = le32_to_cpu(key->iv_initialized);
548 wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
555 memset(&ioc, 0, sizeof(ioc));
559 strcpy(ifr.ifr_name, dev->name);
560 ifr.ifr_data = (caddr_t)&ioc;
564 err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
571 wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
572 enum nl80211_iftype type, u32 *flags,
573 struct vif_params *params)
575 struct wl_priv *wl = wiphy_to_wl(wiphy);
576 struct wireless_dev *wdev;
584 case NL80211_IFTYPE_MONITOR:
585 case NL80211_IFTYPE_WDS:
586 WL_ERR("type (%d) : currently we do not support this type\n",
589 case NL80211_IFTYPE_ADHOC:
590 wl->conf->mode = WL_MODE_IBSS;
593 case NL80211_IFTYPE_STATION:
594 wl->conf->mode = WL_MODE_BSS;
602 infra = cpu_to_le32(infra);
603 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra));
605 WL_ERR("WLC_SET_INFRA error (%d)\n", err);
608 wdev = ndev->ieee80211_ptr;
612 WL_INFO("IF Type = %s\n",
613 (wl->conf->mode == WL_MODE_IBSS) ? "Adhoc" : "Infra");
621 static void wl_iscan_prep(struct wl_scan_params *params, struct wlc_ssid *ssid)
623 memcpy(params->bssid, ether_bcast, ETH_ALEN);
624 params->bss_type = DOT11_BSSTYPE_ANY;
625 params->scan_type = 0;
626 params->nprobes = -1;
627 params->active_time = -1;
628 params->passive_time = -1;
629 params->home_time = -1;
630 params->channel_num = 0;
632 params->nprobes = cpu_to_le32(params->nprobes);
633 params->active_time = cpu_to_le32(params->active_time);
634 params->passive_time = cpu_to_le32(params->passive_time);
635 params->home_time = cpu_to_le32(params->home_time);
636 if (ssid && ssid->SSID_len)
637 memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
642 wl_dev_iovar_setbuf(struct net_device *dev, s8 * iovar, void *param,
643 s32 paramlen, void *bufptr, s32 buflen)
647 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
650 return wl_dev_ioctl(dev, WLC_SET_VAR, bufptr, iolen);
654 wl_dev_iovar_getbuf(struct net_device *dev, s8 * iovar, void *param,
655 s32 paramlen, void *bufptr, s32 buflen)
659 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
662 return wl_dev_ioctl(dev, WLC_GET_VAR, bufptr, buflen);
666 wl_run_iscan(struct wl_iscan_ctrl *iscan, struct wlc_ssid *ssid, u16 action)
669 (WL_SCAN_PARAMS_FIXED_SIZE + offsetof(wl_iscan_params_t, params));
670 struct wl_iscan_params *params;
673 if (ssid && ssid->SSID_len)
674 params_size += sizeof(struct wlc_ssid);
675 params = kzalloc(params_size, GFP_KERNEL);
676 if (unlikely(!params))
678 BUG_ON(params_size >= WLC_IOCTL_SMLEN);
680 wl_iscan_prep(¶ms->params, ssid);
682 params->version = cpu_to_le32(ISCAN_REQ_VERSION);
683 params->action = cpu_to_le16(action);
684 params->scan_duration = cpu_to_le16(0);
686 /* params_size += offsetof(wl_iscan_params_t, params); */
687 err = wl_dev_iovar_setbuf(iscan->dev, "iscan", params, params_size,
688 iscan->ioctl_buf, WLC_IOCTL_SMLEN);
691 WL_INFO("system busy : iscan canceled\n");
693 WL_ERR("error (%d)\n", err);
700 static s32 wl_do_iscan(struct wl_priv *wl)
702 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
703 struct net_device *ndev = wl_to_ndev(wl);
704 struct wlc_ssid ssid;
708 /* Broadcast scan by default */
709 memset(&ssid, 0, sizeof(ssid));
711 iscan->state = WL_ISCAN_STATE_SCANING;
713 passive_scan = wl->active_scan ? 0 : 1;
714 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_SET_PASSIVE_SCAN,
715 &passive_scan, sizeof(passive_scan));
717 WL_ERR("error (%d)\n", err);
721 wl->iscan_kickstart = true;
722 wl_run_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
723 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
730 __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
731 struct cfg80211_scan_request *request,
732 struct cfg80211_ssid *this_ssid)
734 struct wl_priv *wl = ndev_to_wl(ndev);
735 struct cfg80211_ssid *ssids;
736 struct wl_scan_req *sr = wl_to_sr(wl);
742 if (unlikely(test_bit(WL_STATUS_SCANNING, &wl->status))) {
743 WL_ERR("Scanning already : status (%d)\n", (int)wl->status);
746 if (unlikely(test_bit(WL_STATUS_SCAN_ABORTING, &wl->status))) {
747 WL_ERR("Scanning being aborted : status (%d)\n",
751 if (test_bit(WL_STATUS_CONNECTING, &wl->status)) {
752 WL_ERR("Connecting : status (%d)\n",
761 ssids = request->ssids;
762 if (wl->iscan_on && (!ssids || !ssids->ssid_len))
766 /* we don't do iscan in ibss */
770 wl->scan_request = request;
771 set_bit(WL_STATUS_SCANNING, &wl->status);
773 err = wl_do_iscan(wl);
779 WL_SCAN("ssid \"%s\", ssid_len (%d)\n",
780 ssids->ssid, ssids->ssid_len);
781 memset(&sr->ssid, 0, sizeof(sr->ssid));
783 min_t(u8, sizeof(sr->ssid.SSID), ssids->ssid_len);
784 if (sr->ssid.SSID_len) {
785 memcpy(sr->ssid.SSID, ssids->ssid, sr->ssid.SSID_len);
786 sr->ssid.SSID_len = cpu_to_le32(sr->ssid.SSID_len);
789 WL_SCAN("Broadcast scan\n");
792 passive_scan = wl->active_scan ? 0 : 1;
793 err = wl_dev_ioctl(ndev, WLC_SET_PASSIVE_SCAN,
794 &passive_scan, sizeof(passive_scan));
796 WL_ERR("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
800 err = wl_dev_ioctl(ndev, WLC_SCAN, &sr->ssid,
804 WL_INFO("system busy : scan for \"%s\" canceled\n",
807 WL_ERR("WLC_SCAN error (%d)\n", err);
817 clear_bit(WL_STATUS_SCANNING, &wl->status);
818 wl->scan_request = NULL;
823 wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
824 struct cfg80211_scan_request *request)
832 err = __wl_cfg80211_scan(wiphy, ndev, request, NULL);
834 WL_ERR("scan error (%d)\n", err);
840 static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val)
842 s8 buf[WLC_IOCTL_SMLEN];
846 val = cpu_to_le32(val);
847 len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
850 err = wl_dev_ioctl(dev, WLC_SET_VAR, buf, len);
852 WL_ERR("error (%d)\n", err);
858 wl_dev_intvar_get(struct net_device *dev, s8 *name, s32 *retval)
861 s8 buf[WLC_IOCTL_SMLEN];
869 bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var),
872 err = wl_dev_ioctl(dev, WLC_GET_VAR, &var, len);
874 WL_ERR("error (%d)\n", err);
876 *retval = le32_to_cpu(var.val);
881 static s32 wl_set_rts(struct net_device *dev, u32 rts_threshold)
885 err = wl_dev_intvar_set(dev, "rtsthresh", rts_threshold);
887 WL_ERR("Error (%d)\n", err);
892 static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold)
896 err = wl_dev_intvar_set(dev, "fragthresh", frag_threshold);
898 WL_ERR("Error (%d)\n", err);
903 static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l)
906 u32 cmd = (l ? WLC_SET_LRL : WLC_SET_SRL);
908 retry = cpu_to_le32(retry);
909 err = wl_dev_ioctl(dev, cmd, &retry, sizeof(retry));
911 WL_ERR("cmd (%d) , error (%d)\n", cmd, err);
917 static s32 wl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
919 struct wl_priv *wl = wiphy_to_wl(wiphy);
920 struct net_device *ndev = wl_to_ndev(wl);
926 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
927 (wl->conf->rts_threshold != wiphy->rts_threshold)) {
928 wl->conf->rts_threshold = wiphy->rts_threshold;
929 err = wl_set_rts(ndev, wl->conf->rts_threshold);
933 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
934 (wl->conf->frag_threshold != wiphy->frag_threshold)) {
935 wl->conf->frag_threshold = wiphy->frag_threshold;
936 err = wl_set_frag(ndev, wl->conf->frag_threshold);
940 if (changed & WIPHY_PARAM_RETRY_LONG
941 && (wl->conf->retry_long != wiphy->retry_long)) {
942 wl->conf->retry_long = wiphy->retry_long;
943 err = wl_set_retry(ndev, wl->conf->retry_long, true);
947 if (changed & WIPHY_PARAM_RETRY_SHORT
948 && (wl->conf->retry_short != wiphy->retry_short)) {
949 wl->conf->retry_short = wiphy->retry_short;
950 err = wl_set_retry(ndev, wl->conf->retry_short, false);
961 wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
962 struct cfg80211_ibss_params *params)
964 struct wl_priv *wl = wiphy_to_wl(wiphy);
965 struct wl_join_params join_params;
966 size_t join_params_size = 0;
975 WL_CONN("SSID: %s\n", params->ssid);
977 WL_CONN("SSID: NULL, Not supported\n");
982 WL_CONN("BSSID: %02X %02X %02X %02X %02X %02X\n",
983 params->bssid[0], params->bssid[1], params->bssid[2],
984 params->bssid[3], params->bssid[4], params->bssid[5]);
986 WL_CONN("No BSSID specified\n");
989 WL_CONN("channel: %d\n", params->channel->center_freq);
991 WL_CONN("no channel specified\n");
993 if (params->channel_fixed)
994 WL_CONN("fixed channel required\n");
996 WL_CONN("no fixed channel required\n");
998 if (params->ie && params->ie_len)
999 WL_CONN("ie len: %d\n", params->ie_len);
1001 WL_CONN("no ie specified\n");
1003 if (params->beacon_interval)
1004 WL_CONN("beacon interval: %d\n", params->beacon_interval);
1006 WL_CONN("no beacon interval specified\n");
1008 if (params->basic_rates)
1009 WL_CONN("basic rates: %08X\n", params->basic_rates);
1011 WL_CONN("no basic rates specified\n");
1013 if (params->privacy)
1014 WL_CONN("privacy required\n");
1016 WL_CONN("no privacy required\n");
1018 /* Configure Privacy for starter */
1019 if (params->privacy)
1020 wsec |= WEP_ENABLED;
1022 err = wl_dev_intvar_set(dev, "wsec", wsec);
1023 if (unlikely(err)) {
1024 WL_ERR("wsec failed (%d)\n", err);
1028 /* Configure Beacon Interval for starter */
1029 if (params->beacon_interval)
1030 bcnprd = cpu_to_le32(params->beacon_interval);
1032 bcnprd = cpu_to_le32(100);
1034 err = wl_dev_ioctl(dev, WLC_SET_BCNPRD, &bcnprd, sizeof(bcnprd));
1035 if (unlikely(err)) {
1036 WL_ERR("WLC_SET_BCNPRD failed (%d)\n", err);
1040 /* Configure required join parameter */
1041 memset(&join_params, 0, sizeof(wl_join_params_t));
1044 join_params.ssid.SSID_len =
1045 (params->ssid_len > 32) ? 32 : params->ssid_len;
1046 memcpy(join_params.ssid.SSID, params->ssid, join_params.ssid.SSID_len);
1047 join_params.ssid.SSID_len = cpu_to_le32(join_params.ssid.SSID_len);
1048 join_params_size = sizeof(join_params.ssid);
1049 wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID);
1052 if (params->bssid) {
1053 memcpy(join_params.params.bssid, params->bssid, ETH_ALEN);
1055 sizeof(join_params.ssid) + WL_ASSOC_PARAMS_FIXED_SIZE;
1057 memcpy(join_params.params.bssid, ether_bcast, ETH_ALEN);
1059 wl_update_prof(wl, NULL, &join_params.params.bssid, WL_PROF_BSSID);
1062 if (params->channel) {
1066 ieee80211_frequency_to_channel(
1067 params->channel->center_freq);
1068 if (params->channel_fixed) {
1069 /* adding chanspec */
1070 wl_ch_to_chanspec(wl->channel,
1071 &join_params, &join_params_size);
1074 /* set channel for starter */
1075 target_channel = cpu_to_le32(wl->channel);
1076 err = wl_dev_ioctl(dev, WLC_SET_CHANNEL,
1077 &target_channel, sizeof(target_channel));
1078 if (unlikely(err)) {
1079 WL_ERR("WLC_SET_CHANNEL failed (%d)\n", err);
1085 wl->ibss_starter = false;
1088 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size);
1089 if (unlikely(err)) {
1090 WL_ERR("WLC_SET_SSID failed (%d)\n", err);
1094 set_bit(WL_STATUS_CONNECTING, &wl->status);
1101 static s32 wl_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1103 struct wl_priv *wl = wiphy_to_wl(wiphy);
1106 WL_TRACE("Enter\n");
1117 wl_set_wpa_version(struct net_device *dev, struct cfg80211_connect_params *sme)
1119 struct wl_priv *wl = ndev_to_wl(dev);
1120 struct wl_security *sec;
1124 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1125 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1126 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1127 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1129 val = WPA_AUTH_DISABLED;
1130 WL_CONN("setting wpa_auth to 0x%0x\n", val);
1131 err = wl_dev_intvar_set(dev, "wpa_auth", val);
1132 if (unlikely(err)) {
1133 WL_ERR("set wpa_auth failed (%d)\n", err);
1136 sec = wl_read_prof(wl, WL_PROF_SEC);
1137 sec->wpa_versions = sme->crypto.wpa_versions;
1142 wl_set_auth_type(struct net_device *dev, struct cfg80211_connect_params *sme)
1144 struct wl_priv *wl = ndev_to_wl(dev);
1145 struct wl_security *sec;
1149 switch (sme->auth_type) {
1150 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1152 WL_CONN("open system\n");
1154 case NL80211_AUTHTYPE_SHARED_KEY:
1156 WL_CONN("shared key\n");
1158 case NL80211_AUTHTYPE_AUTOMATIC:
1160 WL_CONN("automatic\n");
1162 case NL80211_AUTHTYPE_NETWORK_EAP:
1163 WL_CONN("network eap\n");
1166 WL_ERR("invalid auth type (%d)\n", sme->auth_type);
1170 err = wl_dev_intvar_set(dev, "auth", val);
1171 if (unlikely(err)) {
1172 WL_ERR("set auth failed (%d)\n", err);
1175 sec = wl_read_prof(wl, WL_PROF_SEC);
1176 sec->auth_type = sme->auth_type;
1181 wl_set_set_cipher(struct net_device *dev, struct cfg80211_connect_params *sme)
1183 struct wl_priv *wl = ndev_to_wl(dev);
1184 struct wl_security *sec;
1189 if (sme->crypto.n_ciphers_pairwise) {
1190 switch (sme->crypto.ciphers_pairwise[0]) {
1191 case WLAN_CIPHER_SUITE_WEP40:
1192 case WLAN_CIPHER_SUITE_WEP104:
1195 case WLAN_CIPHER_SUITE_TKIP:
1196 pval = TKIP_ENABLED;
1198 case WLAN_CIPHER_SUITE_CCMP:
1201 case WLAN_CIPHER_SUITE_AES_CMAC:
1205 WL_ERR("invalid cipher pairwise (%d)\n",
1206 sme->crypto.ciphers_pairwise[0]);
1210 if (sme->crypto.cipher_group) {
1211 switch (sme->crypto.cipher_group) {
1212 case WLAN_CIPHER_SUITE_WEP40:
1213 case WLAN_CIPHER_SUITE_WEP104:
1216 case WLAN_CIPHER_SUITE_TKIP:
1217 gval = TKIP_ENABLED;
1219 case WLAN_CIPHER_SUITE_CCMP:
1222 case WLAN_CIPHER_SUITE_AES_CMAC:
1226 WL_ERR("invalid cipher group (%d)\n",
1227 sme->crypto.cipher_group);
1232 WL_CONN("pval (%d) gval (%d)\n", pval, gval);
1233 err = wl_dev_intvar_set(dev, "wsec", pval | gval);
1234 if (unlikely(err)) {
1235 WL_ERR("error (%d)\n", err);
1239 sec = wl_read_prof(wl, WL_PROF_SEC);
1240 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1241 sec->cipher_group = sme->crypto.cipher_group;
1247 wl_set_key_mgmt(struct net_device *dev, struct cfg80211_connect_params *sme)
1249 struct wl_priv *wl = ndev_to_wl(dev);
1250 struct wl_security *sec;
1254 if (sme->crypto.n_akm_suites) {
1255 err = wl_dev_intvar_get(dev, "wpa_auth", &val);
1256 if (unlikely(err)) {
1257 WL_ERR("could not get wpa_auth (%d)\n", err);
1260 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1261 switch (sme->crypto.akm_suites[0]) {
1262 case WLAN_AKM_SUITE_8021X:
1263 val = WPA_AUTH_UNSPECIFIED;
1265 case WLAN_AKM_SUITE_PSK:
1269 WL_ERR("invalid cipher group (%d)\n",
1270 sme->crypto.cipher_group);
1273 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1274 switch (sme->crypto.akm_suites[0]) {
1275 case WLAN_AKM_SUITE_8021X:
1276 val = WPA2_AUTH_UNSPECIFIED;
1278 case WLAN_AKM_SUITE_PSK:
1279 val = WPA2_AUTH_PSK;
1282 WL_ERR("invalid cipher group (%d)\n",
1283 sme->crypto.cipher_group);
1288 WL_CONN("setting wpa_auth to %d\n", val);
1289 err = wl_dev_intvar_set(dev, "wpa_auth", val);
1290 if (unlikely(err)) {
1291 WL_ERR("could not set wpa_auth (%d)\n", err);
1295 sec = wl_read_prof(wl, WL_PROF_SEC);
1296 sec->wpa_auth = sme->crypto.akm_suites[0];
1302 wl_set_set_sharedkey(struct net_device *dev,
1303 struct cfg80211_connect_params *sme)
1305 struct wl_priv *wl = ndev_to_wl(dev);
1306 struct wl_security *sec;
1307 struct wl_wsec_key key;
1311 WL_CONN("key len (%d)\n", sme->key_len);
1313 sec = wl_read_prof(wl, WL_PROF_SEC);
1314 WL_CONN("wpa_versions 0x%x cipher_pairwise 0x%x\n",
1315 sec->wpa_versions, sec->cipher_pairwise);
1317 (sec->wpa_versions & (NL80211_WPA_VERSION_1 |
1318 NL80211_WPA_VERSION_2))
1319 && (sec->cipher_pairwise & (WLAN_CIPHER_SUITE_WEP40 |
1320 WLAN_CIPHER_SUITE_WEP104))) {
1321 memset(&key, 0, sizeof(key));
1322 key.len = (u32) sme->key_len;
1323 key.index = (u32) sme->key_idx;
1324 if (unlikely(key.len > sizeof(key.data))) {
1325 WL_ERR("Too long key length (%u)\n", key.len);
1328 memcpy(key.data, sme->key, key.len);
1329 key.flags = WL_PRIMARY_KEY;
1330 switch (sec->cipher_pairwise) {
1331 case WLAN_CIPHER_SUITE_WEP40:
1332 key.algo = CRYPTO_ALGO_WEP1;
1334 case WLAN_CIPHER_SUITE_WEP104:
1335 key.algo = CRYPTO_ALGO_WEP128;
1338 WL_ERR("Invalid algorithm (%d)\n",
1339 sme->crypto.ciphers_pairwise[0]);
1342 /* Set the new key/index */
1343 WL_CONN("key length (%d) key index (%d) algo (%d)\n",
1344 key.len, key.index, key.algo);
1345 WL_CONN("key \"%s\"\n", key.data);
1346 swap_key_from_BE(&key);
1347 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key,
1349 if (unlikely(err)) {
1350 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1353 if (sec->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) {
1354 WL_CONN("set auth_type to shared key\n");
1355 val = 1; /* shared key */
1356 err = wl_dev_intvar_set(dev, "auth", val);
1357 if (unlikely(err)) {
1358 WL_ERR("set auth failed (%d)\n", err);
1368 wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1369 struct cfg80211_connect_params *sme)
1371 struct wl_priv *wl = wiphy_to_wl(wiphy);
1372 struct ieee80211_channel *chan = sme->channel;
1373 struct wl_join_params join_params;
1374 size_t join_params_size;
1378 WL_TRACE("Enter\n");
1381 if (unlikely(!sme->ssid)) {
1382 WL_ERR("Invalid ssid\n");
1388 ieee80211_frequency_to_channel(chan->center_freq);
1389 WL_CONN("channel (%d), center_req (%d)\n",
1390 wl->channel, chan->center_freq);
1394 WL_INFO("ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
1396 err = wl_set_wpa_version(dev, sme);
1400 err = wl_set_auth_type(dev, sme);
1404 err = wl_set_set_cipher(dev, sme);
1408 err = wl_set_key_mgmt(dev, sme);
1412 err = wl_set_set_sharedkey(dev, sme);
1416 wl_update_prof(wl, NULL, sme->bssid, WL_PROF_BSSID);
1418 ** Join with specific BSSID and cached SSID
1419 ** If SSID is zero join based on BSSID only
1421 memset(&join_params, 0, sizeof(join_params));
1422 join_params_size = sizeof(join_params.ssid);
1424 join_params.ssid.SSID_len = min(sizeof(join_params.ssid.SSID), sme->ssid_len);
1425 memcpy(&join_params.ssid.SSID, sme->ssid, join_params.ssid.SSID_len);
1426 join_params.ssid.SSID_len = cpu_to_le32(join_params.ssid.SSID_len);
1427 wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID);
1430 memcpy(join_params.params.bssid, sme->bssid, ETH_ALEN);
1432 memcpy(join_params.params.bssid, ether_bcast, ETH_ALEN);
1434 if (join_params.ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1435 WL_CONN("ssid \"%s\", len (%d)\n",
1436 join_params.ssid.SSID, join_params.ssid.SSID_len);
1439 wl_ch_to_chanspec(wl->channel, &join_params, &join_params_size);
1440 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size);
1441 if (unlikely(err)) {
1442 WL_ERR("error (%d)\n", err);
1445 set_bit(WL_STATUS_CONNECTING, &wl->status);
1452 wl_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1455 struct wl_priv *wl = wiphy_to_wl(wiphy);
1459 WL_TRACE("Enter. Reason code = %d\n", reason_code);
1462 clear_bit(WL_STATUS_CONNECTED, &wl->status);
1464 scbval.val = reason_code;
1465 memcpy(&scbval.ea, wl_read_prof(wl, WL_PROF_BSSID), ETH_ALEN);
1466 scbval.val = cpu_to_le32(scbval.val);
1467 err = wl_dev_ioctl(dev, WLC_DISASSOC, &scbval,
1470 WL_ERR("error (%d)\n", err);
1472 wl->link_up = false;
1479 wl_cfg80211_set_tx_power(struct wiphy *wiphy,
1480 enum nl80211_tx_power_setting type, s32 dbm)
1483 struct wl_priv *wl = wiphy_to_wl(wiphy);
1484 struct net_device *ndev = wl_to_ndev(wl);
1489 WL_TRACE("Enter\n");
1493 case NL80211_TX_POWER_AUTOMATIC:
1495 case NL80211_TX_POWER_LIMITED:
1497 WL_ERR("TX_POWER_LIMITED - dbm is negative\n");
1502 case NL80211_TX_POWER_FIXED:
1504 WL_ERR("TX_POWER_FIXED - dbm is negative\n");
1510 /* Make sure radio is off or on as far as software is concerned */
1511 disable = WL_RADIO_SW_DISABLE << 16;
1512 disable = cpu_to_le32(disable);
1513 err = wl_dev_ioctl(ndev, WLC_SET_RADIO, &disable, sizeof(disable));
1515 WL_ERR("WLC_SET_RADIO error (%d)\n", err);
1520 txpwrmw = (u16) dbm;
1521 err = wl_dev_intvar_set(ndev, "qtxpower",
1522 (s32) (bcm_mw_to_qdbm(txpwrmw)));
1524 WL_ERR("qtxpower error (%d)\n", err);
1525 wl->conf->tx_power = dbm;
1532 static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm)
1534 struct wl_priv *wl = wiphy_to_wl(wiphy);
1535 struct net_device *ndev = wl_to_ndev(wl);
1540 WL_TRACE("Enter\n");
1543 err = wl_dev_intvar_get(ndev, "qtxpower", &txpwrdbm);
1544 if (unlikely(err)) {
1545 WL_ERR("error (%d)\n", err);
1549 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
1550 *dbm = (s32) bcm_qdbm_to_mw(result);
1558 wl_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *dev,
1559 u8 key_idx, bool unicast, bool multicast)
1565 WL_TRACE("Enter\n");
1566 WL_CONN("key index (%d)\n", key_idx);
1569 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec));
1570 if (unlikely(err)) {
1571 WL_ERR("WLC_GET_WSEC error (%d)\n", err);
1575 wsec = le32_to_cpu(wsec);
1576 if (wsec & WEP_ENABLED) {
1577 /* Just select a new current key */
1578 index = (u32) key_idx;
1579 index = cpu_to_le32(index);
1580 err = wl_dev_ioctl(dev, WLC_SET_KEY_PRIMARY, &index,
1583 WL_ERR("error (%d)\n", err);
1591 wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1592 u8 key_idx, const u8 *mac_addr, struct key_params *params)
1594 struct wl_wsec_key key;
1597 memset(&key, 0, sizeof(key));
1598 key.index = (u32) key_idx;
1599 /* Instead of bcast for ea address for default wep keys,
1600 driver needs it to be Null */
1601 if (!is_multicast_ether_addr(mac_addr))
1602 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
1603 key.len = (u32) params->key_len;
1604 /* check for key index change */
1607 swap_key_from_BE(&key);
1608 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1609 if (unlikely(err)) {
1610 WL_ERR("key delete error (%d)\n", err);
1614 if (key.len > sizeof(key.data)) {
1615 WL_ERR("Invalid key length (%d)\n", key.len);
1619 WL_CONN("Setting the key index %d\n", key.index);
1620 memcpy(key.data, params->key, key.len);
1622 if (params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1624 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1625 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1626 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1629 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1630 if (params->seq && params->seq_len == 6) {
1633 ivptr = (u8 *) params->seq;
1634 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
1635 (ivptr[3] << 8) | ivptr[2];
1636 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
1637 key.iv_initialized = true;
1640 switch (params->cipher) {
1641 case WLAN_CIPHER_SUITE_WEP40:
1642 key.algo = CRYPTO_ALGO_WEP1;
1643 WL_CONN("WLAN_CIPHER_SUITE_WEP40\n");
1645 case WLAN_CIPHER_SUITE_WEP104:
1646 key.algo = CRYPTO_ALGO_WEP128;
1647 WL_CONN("WLAN_CIPHER_SUITE_WEP104\n");
1649 case WLAN_CIPHER_SUITE_TKIP:
1650 key.algo = CRYPTO_ALGO_TKIP;
1651 WL_CONN("WLAN_CIPHER_SUITE_TKIP\n");
1653 case WLAN_CIPHER_SUITE_AES_CMAC:
1654 key.algo = CRYPTO_ALGO_AES_CCM;
1655 WL_CONN("WLAN_CIPHER_SUITE_AES_CMAC\n");
1657 case WLAN_CIPHER_SUITE_CCMP:
1658 key.algo = CRYPTO_ALGO_AES_CCM;
1659 WL_CONN("WLAN_CIPHER_SUITE_CCMP\n");
1662 WL_ERR("Invalid cipher (0x%x)\n", params->cipher);
1665 swap_key_from_BE(&key);
1667 dhd_wait_pend8021x(dev);
1668 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1669 if (unlikely(err)) {
1670 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1678 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1679 u8 key_idx, bool pairwise, const u8 *mac_addr,
1680 struct key_params *params)
1682 struct wl_wsec_key key;
1688 WL_TRACE("Enter\n");
1689 WL_CONN("key index (%d)\n", key_idx);
1694 return wl_add_keyext(wiphy, dev, key_idx, mac_addr, params);
1696 memset(&key, 0, sizeof(key));
1698 key.len = (u32) params->key_len;
1699 key.index = (u32) key_idx;
1701 if (unlikely(key.len > sizeof(key.data))) {
1702 WL_ERR("Too long key length (%u)\n", key.len);
1706 memcpy(key.data, params->key, key.len);
1708 key.flags = WL_PRIMARY_KEY;
1709 switch (params->cipher) {
1710 case WLAN_CIPHER_SUITE_WEP40:
1711 key.algo = CRYPTO_ALGO_WEP1;
1712 WL_CONN("WLAN_CIPHER_SUITE_WEP40\n");
1714 case WLAN_CIPHER_SUITE_WEP104:
1715 key.algo = CRYPTO_ALGO_WEP128;
1716 WL_CONN("WLAN_CIPHER_SUITE_WEP104\n");
1718 case WLAN_CIPHER_SUITE_TKIP:
1719 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1720 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1721 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1722 key.algo = CRYPTO_ALGO_TKIP;
1723 WL_CONN("WLAN_CIPHER_SUITE_TKIP\n");
1725 case WLAN_CIPHER_SUITE_AES_CMAC:
1726 key.algo = CRYPTO_ALGO_AES_CCM;
1727 WL_CONN("WLAN_CIPHER_SUITE_AES_CMAC\n");
1729 case WLAN_CIPHER_SUITE_CCMP:
1730 key.algo = CRYPTO_ALGO_AES_CCM;
1731 WL_CONN("WLAN_CIPHER_SUITE_CCMP\n");
1734 WL_ERR("Invalid cipher (0x%x)\n", params->cipher);
1739 /* Set the new key/index */
1740 swap_key_from_BE(&key);
1741 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1742 if (unlikely(err)) {
1743 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1748 err = wl_dev_intvar_get(dev, "wsec", &wsec);
1749 if (unlikely(err)) {
1750 WL_ERR("get wsec error (%d)\n", err);
1753 wsec &= ~(WEP_ENABLED);
1755 err = wl_dev_intvar_set(dev, "wsec", wsec);
1756 if (unlikely(err)) {
1757 WL_ERR("set wsec error (%d)\n", err);
1761 val = 1; /* assume shared key. otherwise 0 */
1762 val = cpu_to_le32(val);
1763 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
1765 WL_ERR("WLC_SET_AUTH error (%d)\n", err);
1772 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1773 u8 key_idx, bool pairwise, const u8 *mac_addr)
1775 struct wl_wsec_key key;
1780 WL_TRACE("Enter\n");
1782 memset(&key, 0, sizeof(key));
1784 key.index = (u32) key_idx;
1785 key.flags = WL_PRIMARY_KEY;
1786 key.algo = CRYPTO_ALGO_OFF;
1788 WL_CONN("key index (%d)\n", key_idx);
1789 /* Set the new key/index */
1790 swap_key_from_BE(&key);
1791 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1792 if (unlikely(err)) {
1793 if (err == -EINVAL) {
1794 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
1795 /* we ignore this key index in this case */
1796 WL_ERR("invalid key index (%d)\n", key_idx);
1798 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1800 /* Ignore this error, may happen during DISASSOC */
1806 err = wl_dev_intvar_get(dev, "wsec", &wsec);
1807 if (unlikely(err)) {
1808 WL_ERR("get wsec error (%d)\n", err);
1809 /* Ignore this error, may happen during DISASSOC */
1813 wsec &= ~(WEP_ENABLED);
1815 err = wl_dev_intvar_set(dev, "wsec", wsec);
1816 if (unlikely(err)) {
1817 WL_ERR("set wsec error (%d)\n", err);
1818 /* Ignore this error, may happen during DISASSOC */
1823 val = 0; /* assume open key. otherwise 1 */
1824 val = cpu_to_le32(val);
1825 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
1826 if (unlikely(err)) {
1827 WL_ERR("WLC_SET_AUTH error (%d)\n", err);
1828 /* Ignore this error, may happen during DISASSOC */
1837 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
1838 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
1839 void (*callback) (void *cookie, struct key_params * params))
1841 struct key_params params;
1842 struct wl_wsec_key key;
1843 struct wl_priv *wl = wiphy_to_wl(wiphy);
1844 struct wl_security *sec;
1848 WL_TRACE("Enter\n");
1849 WL_CONN("key index (%d)\n", key_idx);
1852 memset(&key, 0, sizeof(key));
1853 key.index = key_idx;
1854 swap_key_to_BE(&key);
1855 memset(¶ms, 0, sizeof(params));
1856 params.key_len = (u8) min_t(u8, WLAN_MAX_KEY_LEN, key.len);
1857 memcpy(params.key, key.data, params.key_len);
1859 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec));
1860 if (unlikely(err)) {
1861 WL_ERR("WLC_GET_WSEC error (%d)\n", err);
1862 /* Ignore this error, may happen during DISASSOC */
1866 wsec = le32_to_cpu(wsec);
1869 sec = wl_read_prof(wl, WL_PROF_SEC);
1870 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
1871 params.cipher = WLAN_CIPHER_SUITE_WEP40;
1872 WL_CONN("WLAN_CIPHER_SUITE_WEP40\n");
1873 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
1874 params.cipher = WLAN_CIPHER_SUITE_WEP104;
1875 WL_CONN("WLAN_CIPHER_SUITE_WEP104\n");
1879 params.cipher = WLAN_CIPHER_SUITE_TKIP;
1880 WL_CONN("WLAN_CIPHER_SUITE_TKIP\n");
1883 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
1884 WL_CONN("WLAN_CIPHER_SUITE_AES_CMAC\n");
1887 WL_ERR("Invalid algo (0x%x)\n", wsec);
1891 callback(cookie, ¶ms);
1899 wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
1900 struct net_device *dev, u8 key_idx)
1902 WL_INFO("Not supported\n");
1909 wl_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1910 u8 *mac, struct station_info *sinfo)
1912 struct wl_priv *wl = wiphy_to_wl(wiphy);
1917 u8 *bssid = wl_read_prof(wl, WL_PROF_BSSID);
1919 WL_TRACE("Enter\n");
1923 (memcmp(mac, bssid, ETH_ALEN))) {
1924 WL_ERR("Wrong Mac address cfg_mac-%X:%X:%X:%X:%X:%X"
1925 "wl_bssid-%X:%X:%X:%X:%X:%X\n",
1926 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
1927 bssid[0], bssid[1], bssid[2], bssid[3],
1928 bssid[4], bssid[5]);
1933 /* Report the current tx rate */
1934 err = wl_dev_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate));
1936 WL_ERR("Could not get rate (%d)\n", err);
1938 rate = le32_to_cpu(rate);
1939 sinfo->filled |= STATION_INFO_TX_BITRATE;
1940 sinfo->txrate.legacy = rate * 5;
1941 WL_CONN("Rate %d Mbps\n", rate / 2);
1944 if (test_bit(WL_STATUS_CONNECTED, &wl->status)) {
1946 err = wl_dev_ioctl(dev, WLC_GET_RSSI, &scb_val,
1948 if (unlikely(err)) {
1949 WL_ERR("Could not get rssi (%d)\n", err);
1951 rssi = le32_to_cpu(scb_val.val);
1952 sinfo->filled |= STATION_INFO_SIGNAL;
1953 sinfo->signal = rssi;
1954 WL_CONN("RSSI %d dBm\n", rssi);
1963 wl_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1964 bool enabled, s32 timeout)
1969 WL_TRACE("Enter\n");
1972 pm = enabled ? PM_FAST : PM_OFF;
1973 pm = cpu_to_le32(pm);
1974 WL_INFO("power save %s\n", (pm ? "enabled" : "disabled"));
1976 err = wl_dev_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
1977 if (unlikely(err)) {
1979 WL_ERR("net_device is not ready yet\n");
1981 WL_ERR("error (%d)\n", err);
1987 static __used u32 wl_find_msb(u16 bit16)
1991 if (bit16 & 0xff00) {
2015 wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev,
2017 const struct cfg80211_bitrate_mask *mask)
2019 struct wl_rateset rateset;
2027 WL_TRACE("Enter\n");
2030 /* addr param is always NULL. ignore it */
2031 /* Get current rateset */
2032 err = wl_dev_ioctl(dev, WLC_GET_CURR_RATESET, &rateset,
2034 if (unlikely(err)) {
2035 WL_ERR("could not get current rateset (%d)\n", err);
2039 rateset.count = le32_to_cpu(rateset.count);
2041 legacy = wl_find_msb(mask->control[IEEE80211_BAND_2GHZ].legacy);
2043 legacy = wl_find_msb(mask->control[IEEE80211_BAND_5GHZ].legacy);
2045 val = wl_g_rates[legacy - 1].bitrate * 100000;
2047 if (val < rateset.count)
2048 /* Select rate by rateset index */
2049 rate = rateset.rates[val] & 0x7f;
2051 /* Specified rate in bps */
2052 rate = val / 500000;
2054 WL_CONN("rate %d mbps\n", rate / 2);
2058 * Set rate override,
2059 * Since the is a/b/g-blind, both a/bg_rate are enforced.
2061 err_bg = wl_dev_intvar_set(dev, "bg_rate", rate);
2062 err_a = wl_dev_intvar_set(dev, "a_rate", rate);
2063 if (unlikely(err_bg && err_a)) {
2064 WL_ERR("could not set fixed rate (%d) (%d)\n", err_bg, err_a);
2065 err = err_bg | err_a;
2073 static s32 wl_cfg80211_resume(struct wiphy *wiphy)
2075 struct wl_priv *wl = wiphy_to_wl(wiphy);
2076 struct net_device *ndev = wl_to_ndev(wl);
2079 * Check for WL_STATUS_READY before any function call which
2080 * could result is bus access. Don't block the resume for
2081 * any driver error conditions
2083 WL_TRACE("Enter\n");
2085 #if defined(CONFIG_PM_SLEEP)
2086 atomic_set(&dhd_mmc_suspend, false);
2087 #endif /* defined(CONFIG_PM_SLEEP) */
2089 if (test_bit(WL_STATUS_READY, &wl->status)) {
2090 /* Turn on Watchdog timer */
2091 wl_os_wd_timer(ndev, dhd_watchdog_ms);
2092 wl_invoke_iscan(wiphy_to_wl(wiphy));
2099 static s32 wl_cfg80211_suspend(struct wiphy *wiphy)
2101 struct wl_priv *wl = wiphy_to_wl(wiphy);
2102 struct net_device *ndev = wl_to_ndev(wl);
2104 WL_TRACE("Enter\n");
2107 * Check for WL_STATUS_READY before any function call which
2108 * could result is bus access. Don't block the suspend for
2109 * any driver error conditions
2113 * While going to suspend if associated with AP disassociate
2114 * from AP to save power while system is in suspended state
2116 if (test_bit(WL_STATUS_CONNECTED, &wl->status) &&
2117 test_bit(WL_STATUS_READY, &wl->status)) {
2118 WL_INFO("Disassociating from AP"
2119 " while entering suspend state\n");
2123 * Make sure WPA_Supplicant receives all the event
2124 * generated due to DISASSOC call to the fw to keep
2125 * the state fw and WPA_Supplicant state consistent
2132 set_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
2133 if (test_bit(WL_STATUS_READY, &wl->status))
2136 if (wl->scan_request) {
2137 /* Indidate scan abort to cfg80211 layer */
2138 WL_INFO("Terminating scan in progress\n");
2139 cfg80211_scan_done(wl->scan_request, true);
2140 wl->scan_request = NULL;
2142 clear_bit(WL_STATUS_SCANNING, &wl->status);
2143 clear_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
2144 clear_bit(WL_STATUS_CONNECTING, &wl->status);
2145 clear_bit(WL_STATUS_CONNECTED, &wl->status);
2147 /* Inform SDIO stack not to switch off power to the chip */
2148 sdioh_sdio_set_host_pm_flags(MMC_PM_KEEP_POWER);
2150 /* Turn off watchdog timer */
2151 if (test_bit(WL_STATUS_READY, &wl->status)) {
2152 WL_INFO("Terminate watchdog timer and enable MPC\n");
2153 wl_set_mpc(ndev, 1);
2154 wl_os_wd_timer(ndev, 0);
2157 #if defined(CONFIG_PM_SLEEP)
2158 atomic_set(&dhd_mmc_suspend, true);
2159 #endif /* defined(CONFIG_PM_SLEEP) */
2167 wl_update_pmklist(struct net_device *dev, struct wl_pmk_list *pmk_list,
2172 WL_CONN("No of elements %d\n", pmk_list->pmkids.npmkid);
2173 for (i = 0; i < pmk_list->pmkids.npmkid; i++) {
2174 WL_CONN("PMKID[%d]: %pM =\n", i,
2175 &pmk_list->pmkids.pmkid[i].BSSID);
2176 for (j = 0; j < WLAN_PMKID_LEN; j++)
2177 WL_CONN("%02x\n", pmk_list->pmkids.pmkid[i].PMKID[j]);
2181 wl_dev_bufvar_set(dev, "pmkid_info", (char *)pmk_list,
2188 wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
2189 struct cfg80211_pmksa *pmksa)
2191 struct wl_priv *wl = wiphy_to_wl(wiphy);
2195 WL_TRACE("Enter\n");
2198 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++)
2199 if (!memcmp(pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID,
2202 if (i < WL_NUM_PMKIDS_MAX) {
2203 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID, pmksa->bssid,
2205 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID, pmksa->pmkid,
2207 if (i == wl->pmk_list->pmkids.npmkid)
2208 wl->pmk_list->pmkids.npmkid++;
2212 WL_CONN("set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2213 &wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].BSSID);
2214 for (i = 0; i < WLAN_PMKID_LEN; i++)
2216 wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].
2219 err = wl_update_pmklist(dev, wl->pmk_list, err);
2226 wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
2227 struct cfg80211_pmksa *pmksa)
2229 struct wl_priv *wl = wiphy_to_wl(wiphy);
2230 struct _pmkid_list pmkid;
2234 WL_TRACE("Enter\n");
2236 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
2237 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2239 WL_CONN("del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
2240 &pmkid.pmkid[0].BSSID);
2241 for (i = 0; i < WLAN_PMKID_LEN; i++)
2242 WL_CONN("%02x\n", pmkid.pmkid[0].PMKID[i]);
2244 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++)
2246 (pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID,
2250 if ((wl->pmk_list->pmkids.npmkid > 0)
2251 && (i < wl->pmk_list->pmkids.npmkid)) {
2252 memset(&wl->pmk_list->pmkids.pmkid[i], 0, sizeof(pmkid_t));
2253 for (; i < (wl->pmk_list->pmkids.npmkid - 1); i++) {
2254 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID,
2255 &wl->pmk_list->pmkids.pmkid[i + 1].BSSID,
2257 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID,
2258 &wl->pmk_list->pmkids.pmkid[i + 1].PMKID,
2261 wl->pmk_list->pmkids.npmkid--;
2265 err = wl_update_pmklist(dev, wl->pmk_list, err);
2273 wl_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
2275 struct wl_priv *wl = wiphy_to_wl(wiphy);
2278 WL_TRACE("Enter\n");
2281 memset(wl->pmk_list, 0, sizeof(*wl->pmk_list));
2282 err = wl_update_pmklist(dev, wl->pmk_list, err);
2289 static struct cfg80211_ops wl_cfg80211_ops = {
2290 .change_virtual_intf = wl_cfg80211_change_iface,
2291 .scan = wl_cfg80211_scan,
2292 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
2293 .join_ibss = wl_cfg80211_join_ibss,
2294 .leave_ibss = wl_cfg80211_leave_ibss,
2295 .get_station = wl_cfg80211_get_station,
2296 .set_tx_power = wl_cfg80211_set_tx_power,
2297 .get_tx_power = wl_cfg80211_get_tx_power,
2298 .add_key = wl_cfg80211_add_key,
2299 .del_key = wl_cfg80211_del_key,
2300 .get_key = wl_cfg80211_get_key,
2301 .set_default_key = wl_cfg80211_config_default_key,
2302 .set_default_mgmt_key = wl_cfg80211_config_default_mgmt_key,
2303 .set_power_mgmt = wl_cfg80211_set_power_mgmt,
2304 .set_bitrate_mask = wl_cfg80211_set_bitrate_mask,
2305 .connect = wl_cfg80211_connect,
2306 .disconnect = wl_cfg80211_disconnect,
2307 .suspend = wl_cfg80211_suspend,
2308 .resume = wl_cfg80211_resume,
2309 .set_pmksa = wl_cfg80211_set_pmksa,
2310 .del_pmksa = wl_cfg80211_del_pmksa,
2311 .flush_pmksa = wl_cfg80211_flush_pmksa
2314 static s32 wl_mode_to_nl80211_iftype(s32 mode)
2320 return NL80211_IFTYPE_STATION;
2322 return NL80211_IFTYPE_ADHOC;
2324 return NL80211_IFTYPE_UNSPECIFIED;
2330 static struct wireless_dev *wl_alloc_wdev(s32 sizeof_iface,
2333 struct wireless_dev *wdev;
2336 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
2337 if (unlikely(!wdev)) {
2338 WL_ERR("Could not allocate wireless device\n");
2339 return ERR_PTR(-ENOMEM);
2342 wiphy_new(&wl_cfg80211_ops, sizeof(struct wl_priv) + sizeof_iface);
2343 if (unlikely(!wdev->wiphy)) {
2344 WL_ERR("Couldn not allocate wiphy device\n");
2348 set_wiphy_dev(wdev->wiphy, dev);
2349 wdev->wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
2350 wdev->wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
2351 wdev->wiphy->interface_modes =
2352 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
2353 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &__wl_band_2ghz;
2354 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_a; /* Set
2355 * it as 11a by default.
2356 * This will be updated with
2359 * if phy has 11n capability
2361 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2362 wdev->wiphy->cipher_suites = __wl_cipher_suites;
2363 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
2364 #ifndef WL_POWERSAVE_DISABLED
2365 wdev->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; /* enable power
2370 wdev->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
2371 #endif /* !WL_POWERSAVE_DISABLED */
2372 err = wiphy_register(wdev->wiphy);
2373 if (unlikely(err < 0)) {
2374 WL_ERR("Couldn not register wiphy device (%d)\n", err);
2375 goto wiphy_register_out;
2380 wiphy_free(wdev->wiphy);
2385 return ERR_PTR(err);
2388 static void wl_free_wdev(struct wl_priv *wl)
2390 struct wireless_dev *wdev = wl_to_wdev(wl);
2392 if (unlikely(!wdev)) {
2393 WL_ERR("wdev is invalid\n");
2396 wiphy_unregister(wdev->wiphy);
2397 wiphy_free(wdev->wiphy);
2399 wl_to_wdev(wl) = NULL;
2402 static s32 wl_inform_bss(struct wl_priv *wl)
2404 struct wl_scan_results *bss_list;
2405 struct wl_bss_info *bi = NULL; /* must be initialized */
2409 bss_list = wl->bss_list;
2410 if (unlikely(bss_list->version != WL_BSS_INFO_VERSION)) {
2411 WL_ERR("Version %d != WL_BSS_INFO_VERSION\n",
2415 WL_SCAN("scanned AP count (%d)\n", bss_list->count);
2416 bi = next_bss(bss_list, bi);
2417 for_each_bss(bss_list, bi, i) {
2418 err = wl_inform_single_bss(wl, bi);
2426 static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi)
2428 struct wiphy *wiphy = wl_to_wiphy(wl);
2429 struct ieee80211_channel *notify_channel;
2430 struct cfg80211_bss *bss;
2431 struct ieee80211_supported_band *band;
2435 u64 notify_timestamp;
2436 u16 notify_capability;
2437 u16 notify_interval;
2439 size_t notify_ielen;
2442 if (unlikely(le32_to_cpu(bi->length) > WL_BSS_INFO_MAX)) {
2443 WL_ERR("Bss info is larger than buffer. Discarding\n");
2447 channel = bi->ctl_ch ? bi->ctl_ch :
2448 CHSPEC_CHANNEL(le16_to_cpu(bi->chanspec));
2450 if (channel <= CH_MAX_2G_CHANNEL)
2451 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2453 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2455 freq = ieee80211_channel_to_frequency(channel, band->band);
2456 notify_channel = ieee80211_get_channel(wiphy, freq);
2458 notify_timestamp = jiffies_to_msecs(jiffies)*1000; /* uSec */
2459 notify_capability = le16_to_cpu(bi->capability);
2460 notify_interval = le16_to_cpu(bi->beacon_period);
2461 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2462 notify_ielen = le16_to_cpu(bi->ie_length);
2463 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2465 WL_CONN("bssid: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2466 bi->BSSID[0], bi->BSSID[1], bi->BSSID[2],
2467 bi->BSSID[3], bi->BSSID[4], bi->BSSID[5]);
2468 WL_CONN("Channel: %d(%d)\n", channel, freq);
2469 WL_CONN("Capability: %X\n", notify_capability);
2470 WL_CONN("Beacon interval: %d\n", notify_interval);
2471 WL_CONN("Signal: %d\n", notify_signal);
2472 WL_CONN("notify_timestamp: %#018llx\n", notify_timestamp);
2474 bss = cfg80211_inform_bss(wiphy, notify_channel, (const u8 *)bi->BSSID,
2475 notify_timestamp, notify_capability, notify_interval, notify_ie,
2476 notify_ielen, notify_signal, GFP_KERNEL);
2478 if (unlikely(!bss)) {
2479 WL_ERR("cfg80211_inform_bss_frame error\n");
2487 wl_inform_ibss(struct wl_priv *wl, struct net_device *dev, const u8 *bssid)
2489 struct wiphy *wiphy = wl_to_wiphy(wl);
2490 struct ieee80211_channel *notify_channel;
2491 struct wl_bss_info *bi = NULL;
2492 struct ieee80211_supported_band *band;
2497 u64 notify_timestamp;
2498 u16 notify_capability;
2499 u16 notify_interval;
2501 size_t notify_ielen;
2504 WL_TRACE("Enter\n");
2506 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2508 WL_ERR("kzalloc() failed\n");
2513 *(u32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2515 err = wl_dev_ioctl(dev, WLC_GET_BSS_INFO, buf, WL_BSS_INFO_MAX);
2516 if (unlikely(err)) {
2517 WL_ERR("WLC_GET_BSS_INFO failed: %d\n", err);
2521 bi = (wl_bss_info_t *)(buf + 4);
2523 channel = bi->ctl_ch ? bi->ctl_ch :
2524 CHSPEC_CHANNEL(le16_to_cpu(bi->chanspec));
2526 if (channel <= CH_MAX_2G_CHANNEL)
2527 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2529 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2531 freq = ieee80211_channel_to_frequency(channel, band->band);
2532 notify_channel = ieee80211_get_channel(wiphy, freq);
2534 notify_timestamp = jiffies_to_msecs(jiffies)*1000; /* uSec */
2535 notify_capability = le16_to_cpu(bi->capability);
2536 notify_interval = le16_to_cpu(bi->beacon_period);
2537 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2538 notify_ielen = le16_to_cpu(bi->ie_length);
2539 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2541 WL_CONN("channel: %d(%d)\n", channel, freq);
2542 WL_CONN("capability: %X\n", notify_capability);
2543 WL_CONN("beacon interval: %d\n", notify_interval);
2544 WL_CONN("signal: %d\n", notify_signal);
2545 WL_CONN("notify_timestamp: %#018llx\n", notify_timestamp);
2547 cfg80211_inform_bss(wiphy, notify_channel, bssid,
2548 notify_timestamp, notify_capability, notify_interval,
2549 notify_ie, notify_ielen, notify_signal, GFP_KERNEL);
2560 static bool wl_is_linkup(struct wl_priv *wl, const wl_event_msg_t *e)
2562 u32 event = be32_to_cpu(e->event_type);
2563 u32 status = be32_to_cpu(e->status);
2565 if (event == WLC_E_SET_SSID && status == WLC_E_STATUS_SUCCESS) {
2566 WL_CONN("Processing set ssid\n");
2574 static bool wl_is_linkdown(struct wl_priv *wl, const wl_event_msg_t *e)
2576 u32 event = be32_to_cpu(e->event_type);
2577 u16 flags = be16_to_cpu(e->flags);
2579 if (event == WLC_E_LINK && (!(flags & WLC_EVENT_MSG_LINK))) {
2580 WL_CONN("Processing link down\n");
2586 static bool wl_is_nonetwork(struct wl_priv *wl, const wl_event_msg_t *e)
2588 u32 event = be32_to_cpu(e->event_type);
2589 u32 status = be32_to_cpu(e->status);
2590 u16 flags = be16_to_cpu(e->flags);
2592 if (event == WLC_E_LINK && status == WLC_E_STATUS_NO_NETWORKS) {
2593 WL_CONN("Processing Link %s & no network found\n",
2594 flags & WLC_EVENT_MSG_LINK ? "up" : "down");
2598 if (event == WLC_E_SET_SSID && status != WLC_E_STATUS_SUCCESS) {
2599 WL_CONN("Processing connecting & no network found\n");
2607 wl_notify_connect_status(struct wl_priv *wl, struct net_device *ndev,
2608 const wl_event_msg_t *e, void *data)
2612 if (wl_is_linkup(wl, e)) {
2613 WL_CONN("Linkup\n");
2614 if (wl_is_ibssmode(wl)) {
2615 wl_update_prof(wl, NULL, (void *)e->addr,
2617 wl_inform_ibss(wl, ndev, e->addr);
2618 cfg80211_ibss_joined(ndev, e->addr, GFP_KERNEL);
2619 clear_bit(WL_STATUS_CONNECTING, &wl->status);
2620 set_bit(WL_STATUS_CONNECTED, &wl->status);
2622 wl_bss_connect_done(wl, ndev, e, data, true);
2623 } else if (wl_is_linkdown(wl, e)) {
2624 WL_CONN("Linkdown\n");
2625 if (wl_is_ibssmode(wl)) {
2626 if (test_and_clear_bit(WL_STATUS_CONNECTED,
2630 if (test_and_clear_bit(WL_STATUS_CONNECTED,
2632 cfg80211_disconnected(ndev, 0, NULL, 0,
2637 wl_init_prof(wl->profile);
2638 } else if (wl_is_nonetwork(wl, e)) {
2639 if (wl_is_ibssmode(wl))
2640 clear_bit(WL_STATUS_CONNECTING, &wl->status);
2642 wl_bss_connect_done(wl, ndev, e, data, false);
2649 wl_notify_roaming_status(struct wl_priv *wl, struct net_device *ndev,
2650 const wl_event_msg_t *e, void *data)
2653 u32 event = be32_to_cpu(e->event_type);
2654 u32 status = be32_to_cpu(e->status);
2656 if (event == WLC_E_ROAM && status == WLC_E_STATUS_SUCCESS) {
2657 if (test_bit(WL_STATUS_CONNECTED, &wl->status))
2658 wl_bss_roaming_done(wl, ndev, e, data);
2660 wl_bss_connect_done(wl, ndev, e, data, true);
2667 wl_dev_bufvar_set(struct net_device *dev, s8 *name, s8 *buf, s32 len)
2669 struct wl_priv *wl = ndev_to_wl(dev);
2672 buflen = bcm_mkiovar(name, buf, len, wl->ioctl_buf, WL_IOCTL_LEN_MAX);
2675 return wl_dev_ioctl(dev, WLC_SET_VAR, wl->ioctl_buf, buflen);
2679 wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
2682 struct wl_priv *wl = ndev_to_wl(dev);
2686 len = bcm_mkiovar(name, NULL, 0, wl->ioctl_buf, WL_IOCTL_LEN_MAX);
2688 err = wl_dev_ioctl(dev, WLC_GET_VAR, (void *)wl->ioctl_buf,
2690 if (unlikely(err)) {
2691 WL_ERR("error (%d)\n", err);
2694 memcpy(buf, wl->ioctl_buf, buf_len);
2699 static s32 wl_get_assoc_ies(struct wl_priv *wl)
2701 struct net_device *ndev = wl_to_ndev(wl);
2702 struct wl_assoc_ielen *assoc_info;
2703 struct wl_connect_info *conn_info = wl_to_conn(wl);
2708 wl_clear_assoc_ies(wl);
2710 err = wl_dev_bufvar_get(ndev, "assoc_info", wl->extra_buf,
2712 if (unlikely(err)) {
2713 WL_ERR("could not get assoc info (%d)\n", err);
2716 assoc_info = (struct wl_assoc_ielen *)wl->extra_buf;
2717 req_len = assoc_info->req_len;
2718 resp_len = assoc_info->resp_len;
2720 err = wl_dev_bufvar_get(ndev, "assoc_req_ies", wl->extra_buf,
2722 if (unlikely(err)) {
2723 WL_ERR("could not get assoc req (%d)\n", err);
2726 conn_info->req_ie_len = req_len;
2728 kmemdup(wl->extra_buf, conn_info->req_ie_len, GFP_KERNEL);
2730 conn_info->req_ie_len = 0;
2731 conn_info->req_ie = NULL;
2734 err = wl_dev_bufvar_get(ndev, "assoc_resp_ies", wl->extra_buf,
2736 if (unlikely(err)) {
2737 WL_ERR("could not get assoc resp (%d)\n", err);
2740 conn_info->resp_ie_len = resp_len;
2741 conn_info->resp_ie =
2742 kmemdup(wl->extra_buf, conn_info->resp_ie_len, GFP_KERNEL);
2744 conn_info->resp_ie_len = 0;
2745 conn_info->resp_ie = NULL;
2747 WL_CONN("req len (%d) resp len (%d)\n",
2748 conn_info->req_ie_len, conn_info->resp_ie_len);
2753 static void wl_clear_assoc_ies(struct wl_priv *wl)
2755 struct wl_connect_info *conn_info = wl_to_conn(wl);
2757 kfree(conn_info->req_ie);
2758 conn_info->req_ie = NULL;
2759 conn_info->req_ie_len = 0;
2760 kfree(conn_info->resp_ie);
2761 conn_info->resp_ie = NULL;
2762 conn_info->resp_ie_len = 0;
2766 static void wl_ch_to_chanspec(int ch, struct wl_join_params *join_params,
2767 size_t *join_params_size)
2769 chanspec_t chanspec = 0;
2772 join_params->params.chanspec_num = 1;
2773 join_params->params.chanspec_list[0] = ch;
2775 if (join_params->params.chanspec_list[0] <= CH_MAX_2G_CHANNEL)
2776 chanspec |= WL_CHANSPEC_BAND_2G;
2778 chanspec |= WL_CHANSPEC_BAND_5G;
2780 chanspec |= WL_CHANSPEC_BW_20;
2781 chanspec |= WL_CHANSPEC_CTL_SB_NONE;
2783 *join_params_size += WL_ASSOC_PARAMS_FIXED_SIZE +
2784 join_params->params.chanspec_num * sizeof(chanspec_t);
2786 join_params->params.chanspec_list[0] &= WL_CHANSPEC_CHAN_MASK;
2787 join_params->params.chanspec_list[0] |= chanspec;
2788 join_params->params.chanspec_list[0] =
2789 cpu_to_le16(join_params->params.chanspec_list[0]);
2791 join_params->params.chanspec_num =
2792 cpu_to_le32(join_params->params.chanspec_num);
2794 WL_CONN("join_params->params.chanspec_list[0]= %#X,"
2795 "channel %d, chanspec %#X\n",
2796 join_params->params.chanspec_list[0], ch, chanspec);
2800 static s32 wl_update_bss_info(struct wl_priv *wl)
2802 struct wl_bss_info *bi;
2803 struct wlc_ssid *ssid;
2804 struct bcm_tlv *tim;
2805 u16 beacon_interval;
2811 WL_TRACE("Enter\n");
2812 if (wl_is_ibssmode(wl))
2815 ssid = (struct wlc_ssid *)wl_read_prof(wl, WL_PROF_SSID);
2817 *(u32 *)wl->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
2818 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_BSS_INFO,
2819 wl->extra_buf, WL_EXTRA_BUF_MAX);
2820 if (unlikely(err)) {
2821 WL_ERR("Could not get bss info %d\n", err);
2822 goto update_bss_info_out;
2825 bi = (struct wl_bss_info *)(wl->extra_buf + 4);
2826 err = wl_inform_single_bss(wl, bi);
2828 goto update_bss_info_out;
2830 ie = ((u8 *)bi) + bi->ie_offset;
2831 ie_len = bi->ie_length;
2832 beacon_interval = cpu_to_le16(bi->beacon_period);
2834 tim = bcm_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
2836 dtim_period = tim->data[1];
2839 * active scan was done so we could not get dtim
2840 * information out of probe response.
2841 * so we speficially query dtim information to dongle.
2844 err = wl_dev_intvar_get(wl_to_ndev(wl), "dtim_assoc", &var);
2845 if (unlikely(err)) {
2846 WL_ERR("wl dtim_assoc failed (%d)\n", err);
2847 goto update_bss_info_out;
2849 dtim_period = (u8)var;
2852 wl_update_prof(wl, NULL, &beacon_interval, WL_PROF_BEACONINT);
2853 wl_update_prof(wl, NULL, &dtim_period, WL_PROF_DTIMPERIOD);
2855 update_bss_info_out:
2861 wl_bss_roaming_done(struct wl_priv *wl, struct net_device *ndev,
2862 const wl_event_msg_t *e, void *data)
2864 struct wl_connect_info *conn_info = wl_to_conn(wl);
2867 WL_TRACE("Enter\n");
2869 wl_get_assoc_ies(wl);
2870 wl_update_prof(wl, NULL, &e->addr, WL_PROF_BSSID);
2871 wl_update_bss_info(wl);
2873 cfg80211_roamed(ndev, NULL,
2874 (u8 *)wl_read_prof(wl, WL_PROF_BSSID),
2875 conn_info->req_ie, conn_info->req_ie_len,
2876 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
2877 WL_CONN("Report roaming result\n");
2879 set_bit(WL_STATUS_CONNECTED, &wl->status);
2885 wl_bss_connect_done(struct wl_priv *wl, struct net_device *ndev,
2886 const wl_event_msg_t *e, void *data, bool completed)
2888 struct wl_connect_info *conn_info = wl_to_conn(wl);
2891 WL_TRACE("Enter\n");
2893 if (test_and_clear_bit(WL_STATUS_CONNECTING, &wl->status)) {
2895 wl_get_assoc_ies(wl);
2896 wl_update_prof(wl, NULL, &e->addr, WL_PROF_BSSID);
2897 wl_update_bss_info(wl);
2899 cfg80211_connect_result(ndev,
2900 (u8 *)wl_read_prof(wl, WL_PROF_BSSID),
2902 conn_info->req_ie_len,
2904 conn_info->resp_ie_len,
2905 completed ? WLAN_STATUS_SUCCESS : WLAN_STATUS_AUTH_TIMEOUT,
2908 set_bit(WL_STATUS_CONNECTED, &wl->status);
2909 WL_CONN("Report connect result - connection %s\n",
2910 completed ? "succeeded" : "failed");
2917 wl_notify_mic_status(struct wl_priv *wl, struct net_device *ndev,
2918 const wl_event_msg_t *e, void *data)
2920 u16 flags = be16_to_cpu(e->flags);
2921 enum nl80211_key_type key_type;
2924 if (flags & WLC_EVENT_MSG_GROUP)
2925 key_type = NL80211_KEYTYPE_GROUP;
2927 key_type = NL80211_KEYTYPE_PAIRWISE;
2929 cfg80211_michael_mic_failure(ndev, (u8 *)&e->addr, key_type, -1,
2937 wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
2938 const wl_event_msg_t *e, void *data)
2940 struct channel_info channel_inform;
2941 struct wl_scan_results *bss_list;
2942 u32 len = WL_SCAN_BUF_MAX;
2944 bool scan_abort = false;
2946 WL_TRACE("Enter\n");
2948 if (wl->iscan_on && wl->iscan_kickstart) {
2950 return wl_wakeup_iscan(wl_to_iscan(wl));
2953 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) {
2954 WL_ERR("Scan complete while device not scanning\n");
2960 err = wl_dev_ioctl(ndev, WLC_GET_CHANNEL, &channel_inform,
2961 sizeof(channel_inform));
2962 if (unlikely(err)) {
2963 WL_ERR("scan busy (%d)\n", err);
2967 channel_inform.scan_channel = le32_to_cpu(channel_inform.scan_channel);
2968 if (unlikely(channel_inform.scan_channel)) {
2970 WL_CONN("channel_inform.scan_channel (%d)\n",
2971 channel_inform.scan_channel);
2973 wl->bss_list = wl->scan_results;
2974 bss_list = wl->bss_list;
2975 memset(bss_list, 0, len);
2976 bss_list->buflen = cpu_to_le32(len);
2978 err = wl_dev_ioctl(ndev, WLC_SCAN_RESULTS, bss_list, len);
2979 if (unlikely(err)) {
2980 WL_ERR("%s Scan_results error (%d)\n", ndev->name, err);
2985 bss_list->buflen = le32_to_cpu(bss_list->buflen);
2986 bss_list->version = le32_to_cpu(bss_list->version);
2987 bss_list->count = le32_to_cpu(bss_list->count);
2989 err = wl_inform_bss(wl);
2996 if (wl->scan_request) {
2997 WL_SCAN("calling cfg80211_scan_done\n");
2998 cfg80211_scan_done(wl->scan_request, scan_abort);
2999 wl_set_mpc(ndev, 1);
3000 wl->scan_request = NULL;
3008 static void wl_init_conf(struct wl_conf *conf)
3010 conf->mode = (u32)-1;
3011 conf->frag_threshold = (u32)-1;
3012 conf->rts_threshold = (u32)-1;
3013 conf->retry_short = (u32)-1;
3014 conf->retry_long = (u32)-1;
3015 conf->tx_power = -1;
3018 static void wl_init_prof(struct wl_profile *prof)
3020 memset(prof, 0, sizeof(*prof));
3023 static void wl_init_eloop_handler(struct wl_event_loop *el)
3025 memset(el, 0, sizeof(*el));
3026 el->handler[WLC_E_SCAN_COMPLETE] = wl_notify_scan_status;
3027 el->handler[WLC_E_LINK] = wl_notify_connect_status;
3028 el->handler[WLC_E_ROAM] = wl_notify_roaming_status;
3029 el->handler[WLC_E_MIC_ERROR] = wl_notify_mic_status;
3030 el->handler[WLC_E_SET_SSID] = wl_notify_connect_status;
3033 static s32 wl_init_priv_mem(struct wl_priv *wl)
3035 wl->scan_results = kzalloc(WL_SCAN_BUF_MAX, GFP_KERNEL);
3036 if (unlikely(!wl->scan_results)) {
3037 WL_ERR("Scan results alloc failed\n");
3038 goto init_priv_mem_out;
3040 wl->conf = kzalloc(sizeof(*wl->conf), GFP_KERNEL);
3041 if (unlikely(!wl->conf)) {
3042 WL_ERR("wl_conf alloc failed\n");
3043 goto init_priv_mem_out;
3045 wl->profile = kzalloc(sizeof(*wl->profile), GFP_KERNEL);
3046 if (unlikely(!wl->profile)) {
3047 WL_ERR("wl_profile alloc failed\n");
3048 goto init_priv_mem_out;
3050 wl->bss_info = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
3051 if (unlikely(!wl->bss_info)) {
3052 WL_ERR("Bss information alloc failed\n");
3053 goto init_priv_mem_out;
3055 wl->scan_req_int = kzalloc(sizeof(*wl->scan_req_int), GFP_KERNEL);
3056 if (unlikely(!wl->scan_req_int)) {
3057 WL_ERR("Scan req alloc failed\n");
3058 goto init_priv_mem_out;
3060 wl->ioctl_buf = kzalloc(WL_IOCTL_LEN_MAX, GFP_KERNEL);
3061 if (unlikely(!wl->ioctl_buf)) {
3062 WL_ERR("Ioctl buf alloc failed\n");
3063 goto init_priv_mem_out;
3065 wl->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
3066 if (unlikely(!wl->extra_buf)) {
3067 WL_ERR("Extra buf alloc failed\n");
3068 goto init_priv_mem_out;
3070 wl->iscan = kzalloc(sizeof(*wl->iscan), GFP_KERNEL);
3071 if (unlikely(!wl->iscan)) {
3072 WL_ERR("Iscan buf alloc failed\n");
3073 goto init_priv_mem_out;
3075 wl->fw = kzalloc(sizeof(*wl->fw), GFP_KERNEL);
3076 if (unlikely(!wl->fw)) {
3077 WL_ERR("fw object alloc failed\n");
3078 goto init_priv_mem_out;
3080 wl->pmk_list = kzalloc(sizeof(*wl->pmk_list), GFP_KERNEL);
3081 if (unlikely(!wl->pmk_list)) {
3082 WL_ERR("pmk list alloc failed\n");
3083 goto init_priv_mem_out;
3089 wl_deinit_priv_mem(wl);
3094 static void wl_deinit_priv_mem(struct wl_priv *wl)
3096 kfree(wl->scan_results);
3097 wl->scan_results = NULL;
3098 kfree(wl->bss_info);
3099 wl->bss_info = NULL;
3104 kfree(wl->scan_req_int);
3105 wl->scan_req_int = NULL;
3106 kfree(wl->ioctl_buf);
3107 wl->ioctl_buf = NULL;
3108 kfree(wl->extra_buf);
3109 wl->extra_buf = NULL;
3114 kfree(wl->pmk_list);
3115 wl->pmk_list = NULL;
3118 static s32 wl_create_event_handler(struct wl_priv *wl)
3120 sema_init(&wl->event_sync, 0);
3121 wl->event_tsk = kthread_run(wl_event_handler, wl, "wl_event_handler");
3122 if (IS_ERR(wl->event_tsk)) {
3123 wl->event_tsk = NULL;
3124 WL_ERR("failed to create event thread\n");
3130 static void wl_destroy_event_handler(struct wl_priv *wl)
3132 if (wl->event_tsk) {
3133 send_sig(SIGTERM, wl->event_tsk, 1);
3134 kthread_stop(wl->event_tsk);
3135 wl->event_tsk = NULL;
3139 static void wl_term_iscan(struct wl_priv *wl)
3141 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
3143 if (wl->iscan_on && iscan->tsk) {
3144 iscan->state = WL_ISCAN_STATE_IDLE;
3145 send_sig(SIGTERM, iscan->tsk, 1);
3146 kthread_stop(iscan->tsk);
3151 static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted)
3153 struct wl_priv *wl = iscan_to_wl(iscan);
3154 struct net_device *ndev = wl_to_ndev(wl);
3156 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) {
3157 WL_ERR("Scan complete while device not scanning\n");
3160 if (likely(wl->scan_request)) {
3161 WL_SCAN("ISCAN Completed scan: %s\n",
3162 aborted ? "Aborted" : "Done");
3163 cfg80211_scan_done(wl->scan_request, aborted);
3164 wl_set_mpc(ndev, 1);
3165 wl->scan_request = NULL;
3167 wl->iscan_kickstart = false;
3170 static s32 wl_wakeup_iscan(struct wl_iscan_ctrl *iscan)
3172 if (likely(iscan->state != WL_ISCAN_STATE_IDLE)) {
3173 WL_SCAN("wake up iscan\n");
3182 wl_get_iscan_results(struct wl_iscan_ctrl *iscan, u32 *status,
3183 struct wl_scan_results **bss_list)
3185 struct wl_iscan_results list;
3186 struct wl_scan_results *results;
3187 struct wl_iscan_results *list_buf;
3190 memset(iscan->scan_buf, 0, WL_ISCAN_BUF_MAX);
3191 list_buf = (struct wl_iscan_results *)iscan->scan_buf;
3192 results = &list_buf->results;
3193 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
3194 results->version = 0;
3197 memset(&list, 0, sizeof(list));
3198 list.results.buflen = cpu_to_le32(WL_ISCAN_BUF_MAX);
3199 err = wl_dev_iovar_getbuf(iscan->dev, "iscanresults", &list,
3200 WL_ISCAN_RESULTS_FIXED_SIZE, iscan->scan_buf,
3202 if (unlikely(err)) {
3203 WL_ERR("error (%d)\n", err);
3206 results->buflen = le32_to_cpu(results->buflen);
3207 results->version = le32_to_cpu(results->version);
3208 results->count = le32_to_cpu(results->count);
3209 WL_SCAN("results->count = %d\n", results->count);
3210 WL_SCAN("results->buflen = %d\n", results->buflen);
3211 *status = le32_to_cpu(list_buf->status);
3212 *bss_list = results;
3217 static s32 wl_iscan_done(struct wl_priv *wl)
3219 struct wl_iscan_ctrl *iscan = wl->iscan;
3222 iscan->state = WL_ISCAN_STATE_IDLE;
3225 wl_notify_iscan_complete(iscan, false);
3231 static s32 wl_iscan_pending(struct wl_priv *wl)
3233 struct wl_iscan_ctrl *iscan = wl->iscan;
3236 /* Reschedule the timer */
3237 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
3238 iscan->timer_on = 1;
3243 static s32 wl_iscan_inprogress(struct wl_priv *wl)
3245 struct wl_iscan_ctrl *iscan = wl->iscan;
3250 wl_run_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
3252 /* Reschedule the timer */
3253 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
3254 iscan->timer_on = 1;
3259 static s32 wl_iscan_aborted(struct wl_priv *wl)
3261 struct wl_iscan_ctrl *iscan = wl->iscan;
3264 iscan->state = WL_ISCAN_STATE_IDLE;
3266 wl_notify_iscan_complete(iscan, true);
3272 static s32 wl_iscan_thread(void *data)
3274 struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1 };
3275 struct wl_iscan_ctrl *iscan = (struct wl_iscan_ctrl *)data;
3276 struct wl_priv *wl = iscan_to_wl(iscan);
3277 struct wl_iscan_eloop *el = &iscan->el;
3281 sched_setscheduler(current, SCHED_FIFO, ¶m);
3282 allow_signal(SIGTERM);
3283 status = WL_SCAN_RESULTS_PARTIAL;
3284 while (likely(!down_interruptible(&iscan->sync))) {
3285 if (kthread_should_stop())
3287 if (iscan->timer_on) {
3288 del_timer_sync(&iscan->timer);
3289 iscan->timer_on = 0;
3292 err = wl_get_iscan_results(iscan, &status, &wl->bss_list);
3293 if (unlikely(err)) {
3294 status = WL_SCAN_RESULTS_ABORTED;
3295 WL_ERR("Abort iscan\n");
3298 el->handler[status] (wl);
3300 if (iscan->timer_on) {
3301 del_timer_sync(&iscan->timer);
3302 iscan->timer_on = 0;
3304 WL_SCAN("ISCAN thread terminated\n");
3309 static void wl_iscan_timer(unsigned long data)
3311 struct wl_iscan_ctrl *iscan = (struct wl_iscan_ctrl *)data;
3314 iscan->timer_on = 0;
3315 WL_SCAN("timer expired\n");
3316 wl_wakeup_iscan(iscan);
3320 static s32 wl_invoke_iscan(struct wl_priv *wl)
3322 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
3325 if (wl->iscan_on && !iscan->tsk) {
3326 iscan->state = WL_ISCAN_STATE_IDLE;
3327 sema_init(&iscan->sync, 0);
3328 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
3329 if (IS_ERR(iscan->tsk)) {
3330 WL_ERR("Could not create iscan thread\n");
3339 static void wl_init_iscan_eloop(struct wl_iscan_eloop *el)
3341 memset(el, 0, sizeof(*el));
3342 el->handler[WL_SCAN_RESULTS_SUCCESS] = wl_iscan_done;
3343 el->handler[WL_SCAN_RESULTS_PARTIAL] = wl_iscan_inprogress;
3344 el->handler[WL_SCAN_RESULTS_PENDING] = wl_iscan_pending;
3345 el->handler[WL_SCAN_RESULTS_ABORTED] = wl_iscan_aborted;
3346 el->handler[WL_SCAN_RESULTS_NO_MEM] = wl_iscan_aborted;
3349 static s32 wl_init_iscan(struct wl_priv *wl)
3351 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
3355 iscan->dev = wl_to_ndev(wl);
3356 iscan->state = WL_ISCAN_STATE_IDLE;
3357 wl_init_iscan_eloop(&iscan->el);
3358 iscan->timer_ms = WL_ISCAN_TIMER_INTERVAL_MS;
3359 init_timer(&iscan->timer);
3360 iscan->timer.data = (unsigned long) iscan;
3361 iscan->timer.function = wl_iscan_timer;
3362 sema_init(&iscan->sync, 0);
3363 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
3364 if (IS_ERR(iscan->tsk)) {
3365 WL_ERR("Could not create iscan thread\n");
3375 static void wl_init_fw(struct wl_fw_ctrl *fw)
3377 fw->status = 0; /* init fw loading status.
3378 0 means nothing was loaded yet */
3381 static s32 wl_init_priv(struct wl_priv *wl)
3383 struct wiphy *wiphy = wl_to_wiphy(wl);
3386 wl->scan_request = NULL;
3387 wl->pwr_save = !!(wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT);
3388 wl->iscan_on = true; /* iscan on & off switch.
3389 we enable iscan per default */
3390 wl->roam_on = false; /* roam on & off switch.
3391 we enable roam per default */
3393 wl->iscan_kickstart = false;
3394 wl->active_scan = true; /* we do active scan for
3395 specific scan per default */
3396 wl->dongle_up = false; /* dongle is not up yet */
3398 err = wl_init_priv_mem(wl);
3401 if (unlikely(wl_create_event_handler(wl)))
3403 wl_init_eloop_handler(&wl->el);
3404 mutex_init(&wl->usr_sync);
3405 err = wl_init_iscan(wl);
3409 wl_init_conf(wl->conf);
3410 wl_init_prof(wl->profile);
3416 static void wl_deinit_priv(struct wl_priv *wl)
3418 wl_destroy_event_handler(wl);
3419 wl->dongle_up = false; /* dongle down */
3423 wl_deinit_priv_mem(wl);
3426 s32 wl_cfg80211_attach(struct net_device *ndev, void *data)
3428 struct wireless_dev *wdev;
3430 struct wl_iface *ci;
3433 if (unlikely(!ndev)) {
3434 WL_ERR("ndev is invalid\n");
3437 wl_cfg80211_dev = kzalloc(sizeof(struct wl_dev), GFP_KERNEL);
3438 if (unlikely(!wl_cfg80211_dev)) {
3439 WL_ERR("wl_cfg80211_dev is invalid\n");
3442 WL_INFO("func %p\n", wl_cfg80211_get_sdio_func());
3443 wdev = wl_alloc_wdev(sizeof(struct wl_iface), &wl_cfg80211_get_sdio_func()->dev);
3447 wdev->iftype = wl_mode_to_nl80211_iftype(WL_MODE_BSS);
3448 wl = wdev_to_wl(wdev);
3451 ci = (struct wl_iface *)wl_to_ci(wl);
3453 ndev->ieee80211_ptr = wdev;
3454 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
3455 wdev->netdev = ndev;
3456 err = wl_init_priv(wl);
3457 if (unlikely(err)) {
3458 WL_ERR("Failed to init iwm_priv (%d)\n", err);
3459 goto cfg80211_attach_out;
3461 wl_set_drvdata(wl_cfg80211_dev, ci);
3465 cfg80211_attach_out:
3470 void wl_cfg80211_detach(void)
3478 wl_set_drvdata(wl_cfg80211_dev, NULL);
3479 kfree(wl_cfg80211_dev);
3480 wl_cfg80211_dev = NULL;
3481 wl_clear_sdio_func();
3484 static void wl_wakeup_event(struct wl_priv *wl)
3486 up(&wl->event_sync);
3489 static s32 wl_event_handler(void *data)
3491 struct wl_priv *wl = (struct wl_priv *)data;
3492 struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1 };
3493 struct wl_event_q *e;
3495 sched_setscheduler(current, SCHED_FIFO, ¶m);
3496 allow_signal(SIGTERM);
3497 while (likely(!down_interruptible(&wl->event_sync))) {
3498 if (kthread_should_stop())
3500 e = wl_deq_event(wl);
3502 WL_ERR("event queue empty...\n");
3505 WL_INFO("event type (%d)\n", e->etype);
3506 if (wl->el.handler[e->etype]) {
3507 wl->el.handler[e->etype] (wl, wl_to_ndev(wl), &e->emsg,
3510 WL_INFO("Unknown Event (%d): ignoring\n", e->etype);
3514 WL_INFO("was terminated\n");
3519 wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t * e, void *data)
3521 u32 event_type = be32_to_cpu(e->event_type);
3522 struct wl_priv *wl = ndev_to_wl(ndev);
3524 if (likely(!wl_enq_event(wl, event_type, e, data)))
3525 wl_wakeup_event(wl);
3528 static void wl_init_eq(struct wl_priv *wl)
3530 wl_init_eq_lock(wl);
3531 INIT_LIST_HEAD(&wl->eq_list);
3534 static void wl_flush_eq(struct wl_priv *wl)
3536 struct wl_event_q *e;
3539 while (!list_empty(&wl->eq_list)) {
3540 e = list_first_entry(&wl->eq_list, struct wl_event_q, eq_list);
3541 list_del(&e->eq_list);
3548 * retrieve first queued event from head
3551 static struct wl_event_q *wl_deq_event(struct wl_priv *wl)
3553 struct wl_event_q *e = NULL;
3556 if (likely(!list_empty(&wl->eq_list))) {
3557 e = list_first_entry(&wl->eq_list, struct wl_event_q, eq_list);
3558 list_del(&e->eq_list);
3566 ** push event to tail of the queue
3570 wl_enq_event(struct wl_priv *wl, u32 event, const wl_event_msg_t *msg,
3573 struct wl_event_q *e;
3576 e = kzalloc(sizeof(struct wl_event_q), GFP_KERNEL);
3578 WL_ERR("event alloc failed\n");
3583 memcpy(&e->emsg, msg, sizeof(wl_event_msg_t));
3587 list_add_tail(&e->eq_list, &wl->eq_list);
3593 static void wl_put_event(struct wl_event_q *e)
3598 void wl_cfg80211_sdio_func(void *func)
3600 cfg80211_sdio_func = (struct sdio_func *)func;
3603 static void wl_clear_sdio_func(void)
3605 cfg80211_sdio_func = NULL;
3608 struct sdio_func *wl_cfg80211_get_sdio_func(void)
3610 return cfg80211_sdio_func;
3613 static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype)
3619 case NL80211_IFTYPE_MONITOR:
3620 case NL80211_IFTYPE_WDS:
3621 WL_ERR("type (%d) : currently we do not support this mode\n",
3625 case NL80211_IFTYPE_ADHOC:
3628 case NL80211_IFTYPE_STATION:
3633 WL_ERR("invalid type (%d)\n", iftype);
3636 infra = cpu_to_le32(infra);
3637 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra));
3638 if (unlikely(err)) {
3639 WL_ERR("WLC_SET_INFRA error (%d)\n", err);
3646 #ifndef EMBEDDED_PLATFORM
3647 static s32 wl_dongle_country(struct net_device *ndev, u8 ccode)
3655 static s32 wl_dongle_up(struct net_device *ndev, u32 up)
3659 err = wl_dev_ioctl(ndev, WLC_UP, &up, sizeof(up));
3660 if (unlikely(err)) {
3661 WL_ERR("WLC_UP error (%d)\n", err);
3666 static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode)
3670 err = wl_dev_ioctl(ndev, WLC_SET_PM, &power_mode, sizeof(power_mode));
3671 if (unlikely(err)) {
3672 WL_ERR("WLC_SET_PM error (%d)\n", err);
3678 wl_dongle_glom(struct net_device *ndev, u32 glom, u32 dongle_align)
3680 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3684 /* Match Host and Dongle rx alignment */
3685 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
3687 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3688 if (unlikely(err)) {
3689 WL_ERR("txglomalign error (%d)\n", err);
3690 goto dongle_glom_out;
3692 /* disable glom option per default */
3693 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
3694 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3695 if (unlikely(err)) {
3696 WL_ERR("txglom error (%d)\n", err);
3697 goto dongle_glom_out;
3704 wl_dongle_offload(struct net_device *ndev, s32 arpoe, s32 arp_ol)
3706 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3710 /* Set ARP offload */
3711 bcm_mkiovar("arpoe", (char *)&arpoe, 4, iovbuf, sizeof(iovbuf));
3712 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3714 if (err == -EOPNOTSUPP)
3715 WL_INFO("arpoe is not supported\n");
3717 WL_ERR("arpoe error (%d)\n", err);
3719 goto dongle_offload_out;
3721 bcm_mkiovar("arp_ol", (char *)&arp_ol, 4, iovbuf, sizeof(iovbuf));
3722 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3724 if (err == -EOPNOTSUPP)
3725 WL_INFO("arp_ol is not supported\n");
3727 WL_ERR("arp_ol error (%d)\n", err);
3729 goto dongle_offload_out;
3736 static s32 wl_pattern_atoh(s8 *src, s8 *dst)
3739 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
3740 WL_ERR("Mask invalid format. Needs to start with 0x\n");
3743 src = src + 2; /* Skip past 0x */
3744 if (strlen(src) % 2 != 0) {
3745 WL_ERR("Mask invalid format. Needs to be of even length\n");
3748 for (i = 0; *src != '\0'; i++) {
3750 strncpy(num, src, 2);
3752 dst[i] = (u8) simple_strtoul(num, NULL, 16);
3758 static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode)
3760 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3763 struct wl_pkt_filter pkt_filter;
3764 struct wl_pkt_filter *pkt_filterp;
3772 /* add a default packet filter pattern */
3773 str = "pkt_filter_add";
3774 str_len = strlen(str);
3775 strncpy(buf, str, str_len);
3776 buf[str_len] = '\0';
3777 buf_len = str_len + 1;
3779 pkt_filterp = (struct wl_pkt_filter *)(buf + str_len + 1);
3781 /* Parse packet filter id. */
3782 pkt_filter.id = cpu_to_le32(100);
3784 /* Parse filter polarity. */
3785 pkt_filter.negate_match = cpu_to_le32(0);
3787 /* Parse filter type. */
3788 pkt_filter.type = cpu_to_le32(0);
3790 /* Parse pattern filter offset. */
3791 pkt_filter.u.pattern.offset = cpu_to_le32(0);
3793 /* Parse pattern filter mask. */
3794 mask_size = cpu_to_le32(wl_pattern_atoh("0xff",
3795 (char *)pkt_filterp->u.pattern.
3798 /* Parse pattern filter pattern. */
3799 pattern_size = cpu_to_le32(wl_pattern_atoh("0x00",
3800 (char *)&pkt_filterp->u.
3805 if (mask_size != pattern_size) {
3806 WL_ERR("Mask and pattern not the same size\n");
3808 goto dongle_filter_out;
3811 pkt_filter.u.pattern.size_bytes = mask_size;
3812 buf_len += WL_PKT_FILTER_FIXED_LEN;
3813 buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
3815 /* Keep-alive attributes are set in local
3816 * variable (keep_alive_pkt), and
3817 * then memcpy'ed into buffer (keep_alive_pktp) since there is no
3818 * guarantee that the buffer is properly aligned.
3820 memcpy((char *)pkt_filterp, &pkt_filter,
3821 WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
3823 err = wl_dev_ioctl(ndev, WLC_SET_VAR, buf, buf_len);
3825 if (err == -EOPNOTSUPP) {
3826 WL_INFO("filter not supported\n");
3828 WL_ERR("filter (%d)\n", err);
3830 goto dongle_filter_out;
3833 /* set mode to allow pattern */
3834 bcm_mkiovar("pkt_filter_mode", (char *)&filter_mode, 4, iovbuf,
3836 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3838 if (err == -EOPNOTSUPP) {
3839 WL_INFO("filter_mode not supported\n");
3841 WL_ERR("filter_mode (%d)\n", err);
3843 goto dongle_filter_out;
3849 #endif /* !EMBEDDED_PLATFORM */
3851 static s32 wl_dongle_eventmsg(struct net_device *ndev)
3853 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3855 s8 eventmask[WL_EVENTING_MASK_LEN];
3858 WL_TRACE("Enter\n");
3860 /* Setup event_msgs */
3861 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf,
3863 err = wl_dev_ioctl(ndev, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
3864 if (unlikely(err)) {
3865 WL_ERR("Get event_msgs error (%d)\n", err);
3866 goto dongle_eventmsg_out;
3868 memcpy(eventmask, iovbuf, WL_EVENTING_MASK_LEN);
3870 setbit(eventmask, WLC_E_SET_SSID);
3871 setbit(eventmask, WLC_E_ROAM);
3872 setbit(eventmask, WLC_E_PRUNE);
3873 setbit(eventmask, WLC_E_AUTH);
3874 setbit(eventmask, WLC_E_REASSOC);
3875 setbit(eventmask, WLC_E_REASSOC_IND);
3876 setbit(eventmask, WLC_E_DEAUTH_IND);
3877 setbit(eventmask, WLC_E_DISASSOC_IND);
3878 setbit(eventmask, WLC_E_DISASSOC);
3879 setbit(eventmask, WLC_E_JOIN);
3880 setbit(eventmask, WLC_E_ASSOC_IND);
3881 setbit(eventmask, WLC_E_PSK_SUP);
3882 setbit(eventmask, WLC_E_LINK);
3883 setbit(eventmask, WLC_E_NDIS_LINK);
3884 setbit(eventmask, WLC_E_MIC_ERROR);
3885 setbit(eventmask, WLC_E_PMKID_CACHE);
3886 setbit(eventmask, WLC_E_TXFAIL);
3887 setbit(eventmask, WLC_E_JOIN_START);
3888 setbit(eventmask, WLC_E_SCAN_COMPLETE);
3890 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf,
3892 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3893 if (unlikely(err)) {
3894 WL_ERR("Set event_msgs error (%d)\n", err);
3895 goto dongle_eventmsg_out;
3898 dongle_eventmsg_out:
3904 wl_dongle_roam(struct net_device *ndev, u32 roamvar, u32 bcn_timeout)
3912 * Setup timeout if Beacons are lost and roam is
3913 * off to report link down
3916 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout,
3917 sizeof(bcn_timeout), iovbuf, sizeof(iovbuf));
3918 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3919 if (unlikely(err)) {
3920 WL_ERR("bcn_timeout error (%d)\n", err);
3921 goto dongle_rom_out;
3926 * Enable/Disable built-in roaming to allow supplicant
3927 * to take care of roaming
3929 WL_INFO("Internal Roaming = %s\n", roamvar ? "Off" : "On");
3930 bcm_mkiovar("roam_off", (char *)&roamvar,
3931 sizeof(roamvar), iovbuf, sizeof(iovbuf));
3932 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3933 if (unlikely(err)) {
3934 WL_ERR("roam_off error (%d)\n", err);
3935 goto dongle_rom_out;
3938 roamtrigger[0] = WL_ROAM_TRIGGER_LEVEL;
3939 roamtrigger[1] = WLC_BAND_ALL;
3940 err = wl_dev_ioctl(ndev, WLC_SET_ROAM_TRIGGER,
3941 (void *)roamtrigger, sizeof(roamtrigger));
3942 if (unlikely(err)) {
3943 WL_ERR("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
3944 goto dongle_rom_out;
3947 roam_delta[0] = WL_ROAM_DELTA;
3948 roam_delta[1] = WLC_BAND_ALL;
3949 err = wl_dev_ioctl(ndev, WLC_SET_ROAM_DELTA,
3950 (void *)roam_delta, sizeof(roam_delta));
3951 if (unlikely(err)) {
3952 WL_ERR("WLC_SET_ROAM_DELTA error (%d)\n", err);
3953 goto dongle_rom_out;
3961 wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
3962 s32 scan_unassoc_time, s32 scan_passive_time)
3966 err = wl_dev_ioctl(ndev, WLC_SET_SCAN_CHANNEL_TIME, &scan_assoc_time,
3967 sizeof(scan_assoc_time));
3969 if (err == -EOPNOTSUPP)
3970 WL_INFO("Scan assoc time is not supported\n");
3972 WL_ERR("Scan assoc time error (%d)\n", err);
3973 goto dongle_scantime_out;
3975 err = wl_dev_ioctl(ndev, WLC_SET_SCAN_UNASSOC_TIME, &scan_unassoc_time,
3976 sizeof(scan_unassoc_time));
3978 if (err == -EOPNOTSUPP)
3979 WL_INFO("Scan unassoc time is not supported\n");
3981 WL_ERR("Scan unassoc time error (%d)\n", err);
3982 goto dongle_scantime_out;
3985 err = wl_dev_ioctl(ndev, WLC_SET_SCAN_PASSIVE_TIME, &scan_passive_time,
3986 sizeof(scan_passive_time));
3988 if (err == -EOPNOTSUPP)
3989 WL_INFO("Scan passive time is not supported\n");
3991 WL_ERR("Scan passive time error (%d)\n", err);
3992 goto dongle_scantime_out;
3995 dongle_scantime_out:
3999 s32 wl_config_dongle(struct wl_priv *wl, bool need_lock)
4002 #define DHD_SDALIGN 32
4004 struct net_device *ndev;
4005 struct wireless_dev *wdev;
4011 ndev = wl_to_ndev(wl);
4012 wdev = ndev->ieee80211_ptr;
4016 #ifndef EMBEDDED_PLATFORM
4017 err = wl_dongle_up(ndev, 0);
4019 goto default_conf_out;
4020 err = wl_dongle_country(ndev, 0);
4022 goto default_conf_out;
4023 err = wl_dongle_power(ndev, PM_FAST);
4025 goto default_conf_out;
4026 err = wl_dongle_glom(ndev, 0, DHD_SDALIGN);
4028 goto default_conf_out;
4030 wl_dongle_offload(ndev, 1, 0xf);
4031 wl_dongle_filter(ndev, 1);
4032 #endif /* !EMBEDDED_PLATFORM */
4034 wl_dongle_scantime(ndev, WL_SCAN_CHANNEL_TIME,
4035 WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
4037 err = wl_dongle_eventmsg(ndev);
4039 goto default_conf_out;
4040 err = wl_dongle_roam(ndev, (wl->roam_on ? 0 : 1), WL_BEACON_TIMEOUT);
4042 goto default_conf_out;
4043 err = wl_dongle_mode(ndev, wdev->iftype);
4044 if (unlikely(err && err != -EINPROGRESS))
4045 goto default_conf_out;
4046 err = wl_dongle_probecap(wl);
4048 goto default_conf_out;
4050 /* -EINPROGRESS: Call commit handler */
4056 wl->dongle_up = true;
4062 static s32 wl_update_wiphybands(struct wl_priv *wl)
4064 struct wiphy *wiphy;
4069 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_PHYLIST, &phy_list,
4071 if (unlikely(err)) {
4072 WL_ERR("error (%d)\n", err);
4076 phy = ((char *)&phy_list)[1];
4077 WL_INFO("%c phy\n", phy);
4078 if (phy == 'n' || phy == 'a') {
4079 wiphy = wl_to_wiphy(wl);
4080 wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_n;
4086 static s32 __wl_cfg80211_up(struct wl_priv *wl)
4090 set_bit(WL_STATUS_READY, &wl->status);
4092 wl_debugfs_add_netdev_params(wl);
4094 err = wl_config_dongle(wl, false);
4098 wl_invoke_iscan(wl);
4103 static s32 __wl_cfg80211_down(struct wl_priv *wl)
4105 set_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
4107 if (wl->scan_request) {
4108 cfg80211_scan_done(wl->scan_request, true);
4109 /* May need to perform this to cover rmmod */
4110 /* wl_set_mpc(wl_to_ndev(wl), 1); */
4111 wl->scan_request = NULL;
4113 clear_bit(WL_STATUS_READY, &wl->status);
4114 clear_bit(WL_STATUS_SCANNING, &wl->status);
4115 clear_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
4116 clear_bit(WL_STATUS_CONNECTING, &wl->status);
4117 clear_bit(WL_STATUS_CONNECTED, &wl->status);
4119 wl_debugfs_remove_netdev(wl);
4124 s32 wl_cfg80211_up(void)
4130 mutex_lock(&wl->usr_sync);
4131 err = __wl_cfg80211_up(wl);
4132 mutex_unlock(&wl->usr_sync);
4137 s32 wl_cfg80211_down(void)
4143 mutex_lock(&wl->usr_sync);
4144 err = __wl_cfg80211_down(wl);
4145 mutex_unlock(&wl->usr_sync);
4150 static s32 wl_dongle_probecap(struct wl_priv *wl)
4154 err = wl_update_wiphybands(wl);
4161 static void *wl_read_prof(struct wl_priv *wl, s32 item)
4165 return &wl->profile->sec;
4167 return &wl->profile->bssid;
4169 return &wl->profile->ssid;
4171 WL_ERR("invalid item (%d)\n", item);
4176 wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e, void *data,
4180 struct wlc_ssid *ssid;
4184 ssid = (wlc_ssid_t *) data;
4185 memset(wl->profile->ssid.SSID, 0,
4186 sizeof(wl->profile->ssid.SSID));
4187 memcpy(wl->profile->ssid.SSID, ssid->SSID, ssid->SSID_len);
4188 wl->profile->ssid.SSID_len = ssid->SSID_len;
4192 memcpy(wl->profile->bssid, data, ETH_ALEN);
4194 memset(wl->profile->bssid, 0, ETH_ALEN);
4197 memcpy(&wl->profile->sec, data, sizeof(wl->profile->sec));
4199 case WL_PROF_BEACONINT:
4200 wl->profile->beacon_interval = *(u16 *)data;
4202 case WL_PROF_DTIMPERIOD:
4203 wl->profile->dtim_period = *(u8 *)data;
4206 WL_ERR("unsupported item (%d)\n", item);
4214 static bool wl_is_ibssmode(struct wl_priv *wl)
4216 return wl->conf->mode == WL_MODE_IBSS;
4219 static __used s32 wl_add_ie(struct wl_priv *wl, u8 t, u8 l, u8 *v)
4221 struct wl_ie *ie = wl_to_ie(wl);
4224 if (unlikely(ie->offset + l + 2 > WL_TLV_INFO_MAX)) {
4225 WL_ERR("ei crosses buffer boundary\n");
4228 ie->buf[ie->offset] = t;
4229 ie->buf[ie->offset + 1] = l;
4230 memcpy(&ie->buf[ie->offset + 2], v, l);
4231 ie->offset += l + 2;
4237 static void wl_link_down(struct wl_priv *wl)
4239 struct net_device *dev = NULL;
4242 WL_TRACE("Enter\n");
4243 clear_bit(WL_STATUS_CONNECTED, &wl->status);
4246 dev = wl_to_ndev(wl);
4247 WL_INFO("Call WLC_DISASSOC to stop excess roaming\n ");
4248 err = wl_dev_ioctl(dev, WLC_DISASSOC, NULL, 0);
4250 WL_ERR("WLC_DISASSOC failed (%d)\n", err);
4251 wl->link_up = false;
4256 static void wl_lock_eq(struct wl_priv *wl)
4258 spin_lock_irq(&wl->eq_lock);
4261 static void wl_unlock_eq(struct wl_priv *wl)
4263 spin_unlock_irq(&wl->eq_lock);
4266 static void wl_init_eq_lock(struct wl_priv *wl)
4268 spin_lock_init(&wl->eq_lock);
4271 static void wl_delay(u32 ms)
4273 if (ms < 1000 / HZ) {
4281 static void wl_set_drvdata(struct wl_dev *dev, void *data)
4283 dev->driver_data = data;
4286 static void *wl_get_drvdata(struct wl_dev *dev)
4288 return dev->driver_data;
4291 s32 wl_cfg80211_read_fw(s8 *buf, u32 size)
4293 const struct firmware *fw_entry;
4298 fw_entry = wl->fw->fw_entry;
4300 if (fw_entry->size < wl->fw->ptr + size)
4301 size = fw_entry->size - wl->fw->ptr;
4303 memcpy(buf, &fw_entry->data[wl->fw->ptr], size);
4304 wl->fw->ptr += size;
4308 void wl_cfg80211_release_fw(void)
4313 release_firmware(wl->fw->fw_entry);
4317 void *wl_cfg80211_request_fw(s8 *file_name)
4320 const struct firmware *fw_entry = NULL;
4323 WL_INFO("file name : \"%s\"\n", file_name);
4326 if (!test_bit(WL_FW_LOADING_DONE, &wl->fw->status)) {
4327 err = request_firmware(&wl->fw->fw_entry, file_name,
4328 &wl_cfg80211_get_sdio_func()->dev);
4329 if (unlikely(err)) {
4330 WL_ERR("Could not download fw (%d)\n", err);
4333 set_bit(WL_FW_LOADING_DONE, &wl->fw->status);
4334 fw_entry = wl->fw->fw_entry;
4336 WL_INFO("fw size (%zd), data (%p)\n",
4337 fw_entry->size, fw_entry->data);
4339 } else if (!test_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status)) {
4340 err = request_firmware(&wl->fw->fw_entry, file_name,
4341 &wl_cfg80211_get_sdio_func()->dev);
4342 if (unlikely(err)) {
4343 WL_ERR("Could not download nvram (%d)\n", err);
4346 set_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status);
4347 fw_entry = wl->fw->fw_entry;
4349 WL_INFO("nvram size (%zd), data (%p)\n",
4350 fw_entry->size, fw_entry->data);
4353 WL_INFO("Downloading already done. Nothing to do more\n");
4358 if (unlikely(err)) {
4362 return (void *)fw_entry->data;
4365 s8 *wl_cfg80211_get_fwname(void)
4370 strcpy(wl->fw->fw_name, WL_4329_FW_FILE);
4371 return wl->fw->fw_name;
4374 s8 *wl_cfg80211_get_nvramname(void)
4379 strcpy(wl->fw->nvram_name, WL_4329_NVRAM_FILE);
4380 return wl->fw->nvram_name;
4383 static void wl_set_mpc(struct net_device *ndev, int mpc)
4386 struct wl_priv *wl = ndev_to_wl(ndev);
4388 if (test_bit(WL_STATUS_READY, &wl->status)) {
4389 err = wl_dev_intvar_set(ndev, "mpc", mpc);
4390 if (unlikely(err)) {
4391 WL_ERR("fail to set mpc\n");
4394 WL_INFO("MPC : %d\n", mpc);
4398 static int wl_debugfs_add_netdev_params(struct wl_priv *wl)
4400 char buf[10+IFNAMSIZ];
4404 sprintf(buf, "netdev:%s", wl_to_ndev(wl)->name);
4405 wl->debugfsdir = debugfs_create_dir(buf, wl_to_wiphy(wl)->debugfsdir);
4407 fd = debugfs_create_u16("beacon_int", S_IRUGO, wl->debugfsdir,
4408 (u16 *)&wl->profile->beacon_interval);
4414 fd = debugfs_create_u8("dtim_period", S_IRUGO, wl->debugfsdir,
4415 (u8 *)&wl->profile->dtim_period);
4425 static void wl_debugfs_remove_netdev(struct wl_priv *wl)
4427 debugfs_remove_recursive(wl->debugfsdir);
4428 wl->debugfsdir = NULL;