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>
22 #include <asm/uaccess.h>
24 #include <dngl_stats.h>
29 #include <linux/kthread.h>
30 #include <linux/netdevice.h>
31 #include <linux/sched.h>
32 #include <linux/etherdevice.h>
33 #include <linux/wireless.h>
34 #include <linux/ieee80211.h>
35 #include <net/cfg80211.h>
37 #include <net/rtnetlink.h>
38 #include <linux/mmc/sdio_func.h>
39 #include <linux/firmware.h>
40 #include <wl_cfg80211.h>
42 void sdioh_sdio_set_host_pm_flags(int flag);
44 static struct sdio_func *cfg80211_sdio_func;
45 static struct wl_dev *wl_cfg80211_dev;
46 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
48 u32 wl_dbg_level = WL_DBG_ERR | WL_DBG_INFO;
50 #define WL_4329_FW_FILE "brcm/bcm4329-fullmac-4.bin"
51 #define WL_4329_NVRAM_FILE "brcm/bcm4329-fullmac-4.txt"
54 ** cfg80211_ops api/callback list
56 static s32 wl_cfg80211_change_iface(struct wiphy *wiphy,
57 struct net_device *ndev,
58 enum nl80211_iftype type, u32 *flags,
59 struct vif_params *params);
60 static s32 __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
61 struct cfg80211_scan_request *request,
62 struct cfg80211_ssid *this_ssid);
63 static s32 wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
64 struct cfg80211_scan_request *request);
65 static s32 wl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed);
66 static s32 wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
67 struct cfg80211_ibss_params *params);
68 static s32 wl_cfg80211_leave_ibss(struct wiphy *wiphy,
69 struct net_device *dev);
70 static s32 wl_cfg80211_get_station(struct wiphy *wiphy,
71 struct net_device *dev, u8 *mac,
72 struct station_info *sinfo);
73 static s32 wl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
74 struct net_device *dev, bool enabled,
76 static s32 wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
77 struct net_device *dev,
79 const struct cfg80211_bitrate_mask
81 static int wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
82 struct cfg80211_connect_params *sme);
83 static s32 wl_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
85 static s32 wl_cfg80211_set_tx_power(struct wiphy *wiphy,
86 enum nl80211_tx_power_setting type,
88 static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm);
89 static s32 wl_cfg80211_config_default_key(struct wiphy *wiphy,
90 struct net_device *dev, u8 key_idx,
91 bool unicast, bool multicast);
92 static s32 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
93 u8 key_idx, bool pairwise, const u8 *mac_addr,
94 struct key_params *params);
95 static s32 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
96 u8 key_idx, bool pairwise, const u8 *mac_addr);
97 static s32 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
98 u8 key_idx, bool pairwise, const u8 *mac_addr,
99 void *cookie, void (*callback) (void *cookie,
103 static s32 wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
104 struct net_device *dev,
106 static s32 wl_cfg80211_resume(struct wiphy *wiphy);
107 static s32 wl_cfg80211_suspend(struct wiphy *wiphy);
108 static s32 wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
109 struct cfg80211_pmksa *pmksa);
110 static s32 wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
111 struct cfg80211_pmksa *pmksa);
112 static s32 wl_cfg80211_flush_pmksa(struct wiphy *wiphy,
113 struct net_device *dev);
115 ** event & event Q handlers for cfg80211 interfaces
117 static s32 wl_create_event_handler(struct wl_priv *wl);
118 static void wl_destroy_event_handler(struct wl_priv *wl);
119 static s32 wl_event_handler(void *data);
120 static void wl_init_eq(struct wl_priv *wl);
121 static void wl_flush_eq(struct wl_priv *wl);
122 static void wl_lock_eq(struct wl_priv *wl);
123 static void wl_unlock_eq(struct wl_priv *wl);
124 static void wl_init_eq_lock(struct wl_priv *wl);
125 static void wl_init_eloop_handler(struct wl_event_loop *el);
126 static struct wl_event_q *wl_deq_event(struct wl_priv *wl);
127 static s32 wl_enq_event(struct wl_priv *wl, u32 type,
128 const wl_event_msg_t *msg, void *data);
129 static void wl_put_event(struct wl_event_q *e);
130 static void wl_wakeup_event(struct wl_priv *wl);
131 static s32 wl_notify_connect_status(struct wl_priv *wl,
132 struct net_device *ndev,
133 const wl_event_msg_t *e, void *data);
134 static s32 wl_notify_roaming_status(struct wl_priv *wl,
135 struct net_device *ndev,
136 const wl_event_msg_t *e, void *data);
137 static s32 wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
138 const wl_event_msg_t *e, void *data);
139 static s32 wl_bss_connect_done(struct wl_priv *wl, struct net_device *ndev,
140 const wl_event_msg_t *e, void *data,
142 static s32 wl_bss_roaming_done(struct wl_priv *wl, struct net_device *ndev,
143 const wl_event_msg_t *e, void *data);
144 static s32 wl_notify_mic_status(struct wl_priv *wl, struct net_device *ndev,
145 const wl_event_msg_t *e, void *data);
148 ** register/deregister sdio function
150 struct sdio_func *wl_cfg80211_get_sdio_func(void);
151 static void wl_clear_sdio_func(void);
156 static s32 wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
158 static __used s32 wl_dev_bufvar_set(struct net_device *dev, s8 *name,
160 static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val);
161 static s32 wl_dev_intvar_get(struct net_device *dev, s8 *name,
163 static s32 wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg,
167 ** cfg80211 set_wiphy_params utilities
169 static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold);
170 static s32 wl_set_rts(struct net_device *dev, u32 frag_threshold);
171 static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l);
174 ** wl profile utilities
176 static s32 wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e,
177 void *data, s32 item);
178 static void *wl_read_prof(struct wl_priv *wl, s32 item);
179 static void wl_init_prof(struct wl_profile *prof);
182 ** cfg80211 connect utilites
184 static s32 wl_set_wpa_version(struct net_device *dev,
185 struct cfg80211_connect_params *sme);
186 static s32 wl_set_auth_type(struct net_device *dev,
187 struct cfg80211_connect_params *sme);
188 static s32 wl_set_set_cipher(struct net_device *dev,
189 struct cfg80211_connect_params *sme);
190 static s32 wl_set_key_mgmt(struct net_device *dev,
191 struct cfg80211_connect_params *sme);
192 static s32 wl_set_set_sharedkey(struct net_device *dev,
193 struct cfg80211_connect_params *sme);
194 static s32 wl_get_assoc_ies(struct wl_priv *wl);
195 static void wl_clear_assoc_ies(struct wl_priv *wl);
196 static void wl_ch_to_chanspec(int ch,
197 struct wl_join_params *join_params, size_t *join_params_size);
200 ** information element utilities
202 static __used s32 wl_add_ie(struct wl_priv *wl, u8 t, u8 l, u8 *v);
203 static s32 wl_mode_to_nl80211_iftype(s32 mode);
204 static struct wireless_dev *wl_alloc_wdev(s32 sizeof_iface,
206 static void wl_free_wdev(struct wl_priv *wl);
207 static s32 wl_inform_bss(struct wl_priv *wl);
208 static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi);
209 static s32 wl_update_bss_info(struct wl_priv *wl);
210 static s32 wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
211 u8 key_idx, const u8 *mac_addr,
212 struct key_params *params);
215 ** key indianess swap utilities
217 static void swap_key_from_BE(struct wl_wsec_key *key);
218 static void swap_key_to_BE(struct wl_wsec_key *key);
221 ** wl_priv memory init/deinit utilities
223 static s32 wl_init_priv_mem(struct wl_priv *wl);
224 static void wl_deinit_priv_mem(struct wl_priv *wl);
226 static void wl_delay(u32 ms);
229 ** store/restore cfg80211 instance data
231 static void wl_set_drvdata(struct wl_dev *dev, void *data);
232 static void *wl_get_drvdata(struct wl_dev *dev);
235 ** ibss mode utilities
237 static bool wl_is_ibssmode(struct wl_priv *wl);
240 ** dongle up/down , default configuration utilities
242 static bool wl_is_linkdown(struct wl_priv *wl, const wl_event_msg_t *e);
243 static bool wl_is_linkup(struct wl_priv *wl, const wl_event_msg_t *e);
244 static bool wl_is_nonetwork(struct wl_priv *wl, const wl_event_msg_t *e);
245 static void wl_link_down(struct wl_priv *wl);
246 static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype);
247 static s32 __wl_cfg80211_up(struct wl_priv *wl);
248 static s32 __wl_cfg80211_down(struct wl_priv *wl);
249 static s32 wl_dongle_probecap(struct wl_priv *wl);
250 static void wl_init_conf(struct wl_conf *conf);
253 ** dongle configuration utilities
255 #ifndef EMBEDDED_PLATFORM
256 static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype);
257 static s32 wl_dongle_country(struct net_device *ndev, u8 ccode);
258 static s32 wl_dongle_up(struct net_device *ndev, u32 up);
259 static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode);
260 static s32 wl_dongle_glom(struct net_device *ndev, u32 glom,
262 static s32 wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
263 s32 scan_unassoc_time);
264 static s32 wl_dongle_offload(struct net_device *ndev, s32 arpoe,
266 static s32 wl_pattern_atoh(s8 *src, s8 *dst);
267 static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode);
268 static s32 wl_update_wiphybands(struct wl_priv *wl);
269 #endif /* !EMBEDDED_PLATFORM */
271 static s32 wl_dongle_eventmsg(struct net_device *ndev);
272 static s32 wl_config_dongle(struct wl_priv *wl, bool need_lock);
273 static s32 wl_dongle_roam(struct net_device *ndev, u32 roamvar,
279 static void wl_iscan_timer(unsigned long data);
280 static void wl_term_iscan(struct wl_priv *wl);
281 static s32 wl_init_iscan(struct wl_priv *wl);
282 static s32 wl_iscan_thread(void *data);
283 static s32 wl_dev_iovar_setbuf(struct net_device *dev, s8 *iovar,
284 void *param, s32 paramlen, void *bufptr,
286 static s32 wl_dev_iovar_getbuf(struct net_device *dev, s8 *iovar,
287 void *param, s32 paramlen, void *bufptr,
289 static s32 wl_run_iscan(struct wl_iscan_ctrl *iscan, struct wlc_ssid *ssid,
291 static s32 wl_do_iscan(struct wl_priv *wl);
292 static s32 wl_wakeup_iscan(struct wl_iscan_ctrl *iscan);
293 static s32 wl_invoke_iscan(struct wl_priv *wl);
294 static s32 wl_get_iscan_results(struct wl_iscan_ctrl *iscan, u32 *status,
295 struct wl_scan_results **bss_list);
296 static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted);
297 static void wl_init_iscan_eloop(struct wl_iscan_eloop *el);
298 static s32 wl_iscan_done(struct wl_priv *wl);
299 static s32 wl_iscan_pending(struct wl_priv *wl);
300 static s32 wl_iscan_inprogress(struct wl_priv *wl);
301 static s32 wl_iscan_aborted(struct wl_priv *wl);
304 ** fw/nvram downloading handler
306 static void wl_init_fw(struct wl_fw_ctrl *fw);
309 * find most significant bit set
311 static __used u32 wl_find_msb(u16 bit16);
314 * update pmklist to dongle
316 static __used s32 wl_update_pmklist(struct net_device *dev,
317 struct wl_pmk_list *pmk_list, s32 err);
319 static void wl_set_mpc(struct net_device *ndev, int mpc);
324 static int wl_debugfs_add_netdev_params(struct wl_priv *wl);
325 static void wl_debugfs_remove_netdev(struct wl_priv *wl);
327 #define WL_PRIV_GET() \
329 struct wl_iface *ci; \
330 if (unlikely(!(wl_cfg80211_dev && \
331 (ci = wl_get_drvdata(wl_cfg80211_dev))))) { \
332 WL_ERR("wl_cfg80211_dev is unavailable\n"); \
338 #define CHECK_SYS_UP() \
340 struct wl_priv *wl = wiphy_to_wl(wiphy); \
341 if (unlikely(!test_bit(WL_STATUS_READY, &wl->status))) { \
342 WL_INFO("device is not ready : status (%d)\n", \
348 extern int dhd_wait_pend8021x(struct net_device *dev);
350 #if (WL_DBG_LEVEL > 0)
351 #define WL_DBG_ESTR_MAX 32
352 static s8 wl_dbg_estr[][WL_DBG_ESTR_MAX] = {
353 "SET_SSID", "JOIN", "START", "AUTH", "AUTH_IND",
354 "DEAUTH", "DEAUTH_IND", "ASSOC", "ASSOC_IND", "REASSOC",
355 "REASSOC_IND", "DISASSOC", "DISASSOC_IND", "QUIET_START", "QUIET_END",
356 "BEACON_RX", "LINK", "MIC_ERROR", "NDIS_LINK", "ROAM",
357 "TXFAIL", "PMKID_CACHE", "RETROGRADE_TSF", "PRUNE", "AUTOAUTH",
358 "EAPOL_MSG", "SCAN_COMPLETE", "ADDTS_IND", "DELTS_IND", "BCNSENT_IND",
359 "BCNRX_MSG", "BCNLOST_MSG", "ROAM_PREP", "PFN_NET_FOUND",
361 "RESET_COMPLETE", "JOIN_START", "ROAM_START", "ASSOC_START",
363 "RADIO", "PSM_WATCHDOG",
365 "SCAN_CONFIRM_IND", "PSK_SUP", "COUNTRY_CODE_CHANGED",
366 "EXCEEDED_MEDIUM_TIME", "ICV_ERROR",
367 "UNICAST_DECODE_ERROR", "MULTICAST_DECODE_ERROR", "TRACE",
369 "RSSI", "PFN_SCAN_COMPLETE", "ACTION_FRAME", "ACTION_FRAME_COMPLETE",
371 #endif /* WL_DBG_LEVEL */
373 #define CHAN2G(_channel, _freq, _flags) { \
374 .band = IEEE80211_BAND_2GHZ, \
375 .center_freq = (_freq), \
376 .hw_value = (_channel), \
378 .max_antenna_gain = 0, \
382 #define CHAN5G(_channel, _flags) { \
383 .band = IEEE80211_BAND_5GHZ, \
384 .center_freq = 5000 + (5 * (_channel)), \
385 .hw_value = (_channel), \
387 .max_antenna_gain = 0, \
391 #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
392 #define RATETAB_ENT(_rateid, _flags) \
394 .bitrate = RATE_TO_BASE100KBPS(_rateid), \
395 .hw_value = (_rateid), \
399 static struct ieee80211_rate __wl_rates[] = {
400 RATETAB_ENT(WLC_RATE_1M, 0),
401 RATETAB_ENT(WLC_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
402 RATETAB_ENT(WLC_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
403 RATETAB_ENT(WLC_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
404 RATETAB_ENT(WLC_RATE_6M, 0),
405 RATETAB_ENT(WLC_RATE_9M, 0),
406 RATETAB_ENT(WLC_RATE_12M, 0),
407 RATETAB_ENT(WLC_RATE_18M, 0),
408 RATETAB_ENT(WLC_RATE_24M, 0),
409 RATETAB_ENT(WLC_RATE_36M, 0),
410 RATETAB_ENT(WLC_RATE_48M, 0),
411 RATETAB_ENT(WLC_RATE_54M, 0),
414 #define wl_a_rates (__wl_rates + 4)
415 #define wl_a_rates_size 8
416 #define wl_g_rates (__wl_rates + 0)
417 #define wl_g_rates_size 12
419 static struct ieee80211_channel __wl_2ghz_channels[] = {
436 static struct ieee80211_channel __wl_5ghz_a_channels[] = {
437 CHAN5G(34, 0), CHAN5G(36, 0),
438 CHAN5G(38, 0), CHAN5G(40, 0),
439 CHAN5G(42, 0), CHAN5G(44, 0),
440 CHAN5G(46, 0), CHAN5G(48, 0),
441 CHAN5G(52, 0), CHAN5G(56, 0),
442 CHAN5G(60, 0), CHAN5G(64, 0),
443 CHAN5G(100, 0), CHAN5G(104, 0),
444 CHAN5G(108, 0), CHAN5G(112, 0),
445 CHAN5G(116, 0), CHAN5G(120, 0),
446 CHAN5G(124, 0), CHAN5G(128, 0),
447 CHAN5G(132, 0), CHAN5G(136, 0),
448 CHAN5G(140, 0), CHAN5G(149, 0),
449 CHAN5G(153, 0), CHAN5G(157, 0),
450 CHAN5G(161, 0), CHAN5G(165, 0),
451 CHAN5G(184, 0), CHAN5G(188, 0),
452 CHAN5G(192, 0), CHAN5G(196, 0),
453 CHAN5G(200, 0), CHAN5G(204, 0),
454 CHAN5G(208, 0), CHAN5G(212, 0),
458 static struct ieee80211_channel __wl_5ghz_n_channels[] = {
459 CHAN5G(32, 0), CHAN5G(34, 0),
460 CHAN5G(36, 0), CHAN5G(38, 0),
461 CHAN5G(40, 0), CHAN5G(42, 0),
462 CHAN5G(44, 0), CHAN5G(46, 0),
463 CHAN5G(48, 0), CHAN5G(50, 0),
464 CHAN5G(52, 0), CHAN5G(54, 0),
465 CHAN5G(56, 0), CHAN5G(58, 0),
466 CHAN5G(60, 0), CHAN5G(62, 0),
467 CHAN5G(64, 0), CHAN5G(66, 0),
468 CHAN5G(68, 0), CHAN5G(70, 0),
469 CHAN5G(72, 0), CHAN5G(74, 0),
470 CHAN5G(76, 0), CHAN5G(78, 0),
471 CHAN5G(80, 0), CHAN5G(82, 0),
472 CHAN5G(84, 0), CHAN5G(86, 0),
473 CHAN5G(88, 0), CHAN5G(90, 0),
474 CHAN5G(92, 0), CHAN5G(94, 0),
475 CHAN5G(96, 0), CHAN5G(98, 0),
476 CHAN5G(100, 0), CHAN5G(102, 0),
477 CHAN5G(104, 0), CHAN5G(106, 0),
478 CHAN5G(108, 0), CHAN5G(110, 0),
479 CHAN5G(112, 0), CHAN5G(114, 0),
480 CHAN5G(116, 0), CHAN5G(118, 0),
481 CHAN5G(120, 0), CHAN5G(122, 0),
482 CHAN5G(124, 0), CHAN5G(126, 0),
483 CHAN5G(128, 0), CHAN5G(130, 0),
484 CHAN5G(132, 0), CHAN5G(134, 0),
485 CHAN5G(136, 0), CHAN5G(138, 0),
486 CHAN5G(140, 0), CHAN5G(142, 0),
487 CHAN5G(144, 0), CHAN5G(145, 0),
488 CHAN5G(146, 0), CHAN5G(147, 0),
489 CHAN5G(148, 0), CHAN5G(149, 0),
490 CHAN5G(150, 0), CHAN5G(151, 0),
491 CHAN5G(152, 0), CHAN5G(153, 0),
492 CHAN5G(154, 0), CHAN5G(155, 0),
493 CHAN5G(156, 0), CHAN5G(157, 0),
494 CHAN5G(158, 0), CHAN5G(159, 0),
495 CHAN5G(160, 0), CHAN5G(161, 0),
496 CHAN5G(162, 0), CHAN5G(163, 0),
497 CHAN5G(164, 0), CHAN5G(165, 0),
498 CHAN5G(166, 0), CHAN5G(168, 0),
499 CHAN5G(170, 0), CHAN5G(172, 0),
500 CHAN5G(174, 0), CHAN5G(176, 0),
501 CHAN5G(178, 0), CHAN5G(180, 0),
502 CHAN5G(182, 0), CHAN5G(184, 0),
503 CHAN5G(186, 0), CHAN5G(188, 0),
504 CHAN5G(190, 0), CHAN5G(192, 0),
505 CHAN5G(194, 0), CHAN5G(196, 0),
506 CHAN5G(198, 0), CHAN5G(200, 0),
507 CHAN5G(202, 0), CHAN5G(204, 0),
508 CHAN5G(206, 0), CHAN5G(208, 0),
509 CHAN5G(210, 0), CHAN5G(212, 0),
510 CHAN5G(214, 0), CHAN5G(216, 0),
511 CHAN5G(218, 0), CHAN5G(220, 0),
512 CHAN5G(222, 0), CHAN5G(224, 0),
513 CHAN5G(226, 0), CHAN5G(228, 0),
516 static struct ieee80211_supported_band __wl_band_2ghz = {
517 .band = IEEE80211_BAND_2GHZ,
518 .channels = __wl_2ghz_channels,
519 .n_channels = ARRAY_SIZE(__wl_2ghz_channels),
520 .bitrates = wl_g_rates,
521 .n_bitrates = wl_g_rates_size,
524 static struct ieee80211_supported_band __wl_band_5ghz_a = {
525 .band = IEEE80211_BAND_5GHZ,
526 .channels = __wl_5ghz_a_channels,
527 .n_channels = ARRAY_SIZE(__wl_5ghz_a_channels),
528 .bitrates = wl_a_rates,
529 .n_bitrates = wl_a_rates_size,
532 static struct ieee80211_supported_band __wl_band_5ghz_n = {
533 .band = IEEE80211_BAND_5GHZ,
534 .channels = __wl_5ghz_n_channels,
535 .n_channels = ARRAY_SIZE(__wl_5ghz_n_channels),
536 .bitrates = wl_a_rates,
537 .n_bitrates = wl_a_rates_size,
540 static const u32 __wl_cipher_suites[] = {
541 WLAN_CIPHER_SUITE_WEP40,
542 WLAN_CIPHER_SUITE_WEP104,
543 WLAN_CIPHER_SUITE_TKIP,
544 WLAN_CIPHER_SUITE_CCMP,
545 WLAN_CIPHER_SUITE_AES_CMAC,
548 static void swap_key_from_BE(struct wl_wsec_key *key)
550 key->index = cpu_to_le32(key->index);
551 key->len = cpu_to_le32(key->len);
552 key->algo = cpu_to_le32(key->algo);
553 key->flags = cpu_to_le32(key->flags);
554 key->rxiv.hi = cpu_to_le32(key->rxiv.hi);
555 key->rxiv.lo = cpu_to_le16(key->rxiv.lo);
556 key->iv_initialized = cpu_to_le32(key->iv_initialized);
559 static void swap_key_to_BE(struct wl_wsec_key *key)
561 key->index = le32_to_cpu(key->index);
562 key->len = le32_to_cpu(key->len);
563 key->algo = le32_to_cpu(key->algo);
564 key->flags = le32_to_cpu(key->flags);
565 key->rxiv.hi = le32_to_cpu(key->rxiv.hi);
566 key->rxiv.lo = le16_to_cpu(key->rxiv.lo);
567 key->iv_initialized = le32_to_cpu(key->iv_initialized);
571 wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
578 memset(&ioc, 0, sizeof(ioc));
582 strcpy(ifr.ifr_name, dev->name);
583 ifr.ifr_data = (caddr_t)&ioc;
587 err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
594 wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
595 enum nl80211_iftype type, u32 *flags,
596 struct vif_params *params)
598 struct wl_priv *wl = wiphy_to_wl(wiphy);
599 struct wireless_dev *wdev;
606 case NL80211_IFTYPE_MONITOR:
607 case NL80211_IFTYPE_WDS:
608 WL_ERR("type (%d) : currently we do not support this type\n",
611 case NL80211_IFTYPE_ADHOC:
612 wl->conf->mode = WL_MODE_IBSS;
615 case NL80211_IFTYPE_STATION:
616 wl->conf->mode = WL_MODE_BSS;
624 infra = cpu_to_le32(infra);
625 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra));
627 WL_ERR("WLC_SET_INFRA error (%d)\n", err);
630 wdev = ndev->ieee80211_ptr;
634 WL_INFO("IF Type = %s\n",
635 (wl->conf->mode == WL_MODE_IBSS) ? "Adhoc" : "Infra");
641 static void wl_iscan_prep(struct wl_scan_params *params, struct wlc_ssid *ssid)
643 memcpy(params->bssid, ether_bcast, ETH_ALEN);
644 params->bss_type = DOT11_BSSTYPE_ANY;
645 params->scan_type = 0;
646 params->nprobes = -1;
647 params->active_time = -1;
648 params->passive_time = -1;
649 params->home_time = -1;
650 params->channel_num = 0;
652 params->nprobes = cpu_to_le32(params->nprobes);
653 params->active_time = cpu_to_le32(params->active_time);
654 params->passive_time = cpu_to_le32(params->passive_time);
655 params->home_time = cpu_to_le32(params->home_time);
656 if (ssid && ssid->SSID_len)
657 memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
662 wl_dev_iovar_setbuf(struct net_device *dev, s8 * iovar, void *param,
663 s32 paramlen, void *bufptr, s32 buflen)
667 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
670 return wl_dev_ioctl(dev, WLC_SET_VAR, bufptr, iolen);
674 wl_dev_iovar_getbuf(struct net_device *dev, s8 * iovar, void *param,
675 s32 paramlen, void *bufptr, s32 buflen)
679 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
682 return wl_dev_ioctl(dev, WLC_GET_VAR, bufptr, buflen);
686 wl_run_iscan(struct wl_iscan_ctrl *iscan, struct wlc_ssid *ssid, u16 action)
689 (WL_SCAN_PARAMS_FIXED_SIZE + offsetof(wl_iscan_params_t, params));
690 struct wl_iscan_params *params;
693 if (ssid && ssid->SSID_len)
694 params_size += sizeof(struct wlc_ssid);
695 params = kzalloc(params_size, GFP_KERNEL);
696 if (unlikely(!params))
698 BUG_ON(params_size >= WLC_IOCTL_SMLEN);
700 wl_iscan_prep(¶ms->params, ssid);
702 params->version = cpu_to_le32(ISCAN_REQ_VERSION);
703 params->action = cpu_to_le16(action);
704 params->scan_duration = cpu_to_le16(0);
706 /* params_size += offsetof(wl_iscan_params_t, params); */
707 err = wl_dev_iovar_setbuf(iscan->dev, "iscan", params, params_size,
708 iscan->ioctl_buf, WLC_IOCTL_SMLEN);
711 WL_INFO("system busy : iscan canceled\n");
713 WL_ERR("error (%d)\n", err);
720 static s32 wl_do_iscan(struct wl_priv *wl)
722 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
723 struct net_device *ndev = wl_to_ndev(wl);
724 struct wlc_ssid ssid;
728 /* Broadcast scan by default */
729 memset(&ssid, 0, sizeof(ssid));
731 iscan->state = WL_ISCAN_STATE_SCANING;
733 passive_scan = wl->active_scan ? 0 : 1;
734 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_SET_PASSIVE_SCAN,
735 &passive_scan, sizeof(passive_scan));
737 WL_DBG("error (%d)\n", err);
741 wl->iscan_kickstart = true;
742 wl_run_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
743 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
750 __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
751 struct cfg80211_scan_request *request,
752 struct cfg80211_ssid *this_ssid)
754 struct wl_priv *wl = ndev_to_wl(ndev);
755 struct cfg80211_ssid *ssids;
756 struct wl_scan_req *sr = wl_to_sr(wl);
762 if (unlikely(test_bit(WL_STATUS_SCANNING, &wl->status))) {
763 WL_ERR("Scanning already : status (%d)\n", (int)wl->status);
766 if (unlikely(test_bit(WL_STATUS_SCAN_ABORTING, &wl->status))) {
767 WL_ERR("Scanning being aborted : status (%d)\n",
774 if (request) { /* scan bss */
775 ssids = request->ssids;
776 if (wl->iscan_on && (!ssids || !ssids->ssid_len)) { /* for
778 * ssids->ssid_len has
779 * non-zero(ssid string)
781 * Otherwise this is 0.
782 * we do not iscan for
783 * specific scan request
787 } else { /* scan in ibss */
788 /* we don't do iscan in ibss */
791 wl->scan_request = request;
792 set_bit(WL_STATUS_SCANNING, &wl->status);
794 err = wl_do_iscan(wl);
800 WL_DBG("ssid \"%s\", ssid_len (%d)\n",
801 ssids->ssid, ssids->ssid_len);
802 memset(&sr->ssid, 0, sizeof(sr->ssid));
804 min_t(u8, sizeof(sr->ssid.SSID), ssids->ssid_len);
805 if (sr->ssid.SSID_len) {
806 memcpy(sr->ssid.SSID, ssids->ssid, sr->ssid.SSID_len);
807 sr->ssid.SSID_len = cpu_to_le32(sr->ssid.SSID_len);
808 WL_DBG("Specific scan ssid=\"%s\" len=%d\n",
809 sr->ssid.SSID, sr->ssid.SSID_len);
812 WL_DBG("Broadcast scan\n");
814 WL_DBG("sr->ssid.SSID_len (%d)\n", sr->ssid.SSID_len);
815 passive_scan = wl->active_scan ? 0 : 1;
816 err = wl_dev_ioctl(ndev, WLC_SET_PASSIVE_SCAN,
817 &passive_scan, sizeof(passive_scan));
819 WL_ERR("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
823 err = wl_dev_ioctl(ndev, WLC_SCAN, &sr->ssid,
827 WL_INFO("system busy : scan for \"%s\" canceled\n",
830 WL_ERR("WLC_SCAN error (%d)\n", err);
840 clear_bit(WL_STATUS_SCANNING, &wl->status);
841 wl->scan_request = NULL;
846 wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
847 struct cfg80211_scan_request *request)
852 err = __wl_cfg80211_scan(wiphy, ndev, request, NULL);
854 WL_DBG("scan error (%d)\n", err);
861 static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val)
863 s8 buf[WLC_IOCTL_SMLEN];
867 val = cpu_to_le32(val);
868 len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
871 err = wl_dev_ioctl(dev, WLC_SET_VAR, buf, len);
873 WL_ERR("error (%d)\n", err);
880 wl_dev_intvar_get(struct net_device *dev, s8 *name, s32 *retval)
883 s8 buf[WLC_IOCTL_SMLEN];
891 bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var),
894 err = wl_dev_ioctl(dev, WLC_GET_VAR, &var, len);
896 WL_ERR("error (%d)\n", err);
898 *retval = le32_to_cpu(var.val);
903 static s32 wl_set_rts(struct net_device *dev, u32 rts_threshold)
907 err = wl_dev_intvar_set(dev, "rtsthresh", rts_threshold);
909 WL_ERR("Error (%d)\n", err);
915 static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold)
919 err = wl_dev_intvar_set(dev, "fragthresh", frag_threshold);
921 WL_ERR("Error (%d)\n", err);
927 static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l)
930 u32 cmd = (l ? WLC_SET_LRL : WLC_SET_SRL);
932 retry = cpu_to_le32(retry);
933 err = wl_dev_ioctl(dev, cmd, &retry, sizeof(retry));
935 WL_ERR("cmd (%d) , error (%d)\n", cmd, err);
941 static s32 wl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
943 struct wl_priv *wl = wiphy_to_wl(wiphy);
944 struct net_device *ndev = wl_to_ndev(wl);
948 if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
949 (wl->conf->rts_threshold != wiphy->rts_threshold)) {
950 wl->conf->rts_threshold = wiphy->rts_threshold;
951 err = wl_set_rts(ndev, wl->conf->rts_threshold);
955 if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
956 (wl->conf->frag_threshold != wiphy->frag_threshold)) {
957 wl->conf->frag_threshold = wiphy->frag_threshold;
958 err = wl_set_frag(ndev, wl->conf->frag_threshold);
962 if (changed & WIPHY_PARAM_RETRY_LONG
963 && (wl->conf->retry_long != wiphy->retry_long)) {
964 wl->conf->retry_long = wiphy->retry_long;
965 err = wl_set_retry(ndev, wl->conf->retry_long, true);
969 if (changed & WIPHY_PARAM_RETRY_SHORT
970 && (wl->conf->retry_short != wiphy->retry_short)) {
971 wl->conf->retry_short = wiphy->retry_short;
972 err = wl_set_retry(ndev, wl->conf->retry_short, false);
982 wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
983 struct cfg80211_ibss_params *params)
985 struct wl_priv *wl = wiphy_to_wl(wiphy);
986 struct wl_join_params join_params;
987 size_t join_params_size = 0;
995 WL_DBG("SSID: %s\n", params->ssid);
997 WL_DBG("SSID: NULL, Not supported\n");
1002 WL_DBG("BSSID: %02X %02X %02X %02X %02X %02X\n",
1003 params->bssid[0], params->bssid[1], params->bssid[2],
1004 params->bssid[3], params->bssid[4], params->bssid[5]);
1006 WL_DBG("No BSSID specified\n");
1008 if (params->channel)
1009 WL_DBG("channel: %d\n", params->channel->center_freq);
1011 WL_DBG("no channel specified\n");
1013 if (params->channel_fixed)
1014 WL_DBG("fixed channel required\n");
1016 WL_DBG("no fixed channel required\n");
1018 if (params->ie && params->ie_len)
1019 WL_DBG("ie len: %d\n", params->ie_len);
1021 WL_DBG("no ie specified\n");
1023 if (params->beacon_interval)
1024 WL_DBG("beacon interval: %d\n", params->beacon_interval);
1026 WL_DBG("no beacon interval specified\n");
1028 if (params->basic_rates)
1029 WL_DBG("basic rates: %08X\n", params->basic_rates);
1031 WL_DBG("no basic rates specified\n");
1033 if (params->privacy)
1034 WL_DBG("privacy required\n");
1036 WL_DBG("no privacy required\n");
1038 /* Configure Privacy for starter */
1039 if (params->privacy)
1040 wsec |= WEP_ENABLED;
1042 err = wl_dev_intvar_set(dev, "wsec", wsec);
1043 if (unlikely(err)) {
1044 WL_ERR("wsec failed (%d)\n", err);
1048 /* Configure Beacon Interval for starter */
1049 if (params->beacon_interval)
1050 bcnprd = cpu_to_le32(params->beacon_interval);
1052 bcnprd = cpu_to_le32(100);
1054 err = wl_dev_ioctl(dev, WLC_SET_BCNPRD, &bcnprd, sizeof(bcnprd));
1055 if (unlikely(err)) {
1056 WL_ERR("WLC_SET_BCNPRD failed (%d)\n", err);
1060 /* Configure required join parameter */
1061 memset(&join_params, 0, sizeof(wl_join_params_t));
1064 join_params.ssid.SSID_len =
1065 (params->ssid_len > 32) ? 32 : params->ssid_len;
1066 memcpy(join_params.ssid.SSID, params->ssid, join_params.ssid.SSID_len);
1067 join_params.ssid.SSID_len = cpu_to_le32(join_params.ssid.SSID_len);
1068 join_params_size = sizeof(join_params.ssid);
1069 wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID);
1072 if (params->bssid) {
1073 memcpy(join_params.params.bssid, params->bssid, ETH_ALEN);
1075 sizeof(join_params.ssid) + WL_ASSOC_PARAMS_FIXED_SIZE;
1077 memcpy(join_params.params.bssid, ether_bcast, ETH_ALEN);
1079 wl_update_prof(wl, NULL, &join_params.params.bssid, WL_PROF_BSSID);
1082 if (params->channel) {
1086 ieee80211_frequency_to_channel(
1087 params->channel->center_freq);
1088 if (params->channel_fixed) {
1089 /* adding chanspec */
1090 wl_ch_to_chanspec(wl->channel,
1091 &join_params, &join_params_size);
1094 /* set channel for starter */
1095 target_channel = cpu_to_le32(wl->channel);
1096 err = wl_dev_ioctl(dev, WLC_SET_CHANNEL,
1097 &target_channel, sizeof(target_channel));
1098 if (unlikely(err)) {
1099 WL_ERR("WLC_SET_CHANNEL failed (%d)\n", err);
1105 wl->ibss_starter = false;
1108 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size);
1109 if (unlikely(err)) {
1110 WL_ERR("WLC_SET_SSID failed (%d)\n", err);
1114 set_bit(WL_STATUS_CONNECTING, &wl->status);
1120 static s32 wl_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1122 struct wl_priv *wl = wiphy_to_wl(wiphy);
1132 wl_set_wpa_version(struct net_device *dev, struct cfg80211_connect_params *sme)
1134 struct wl_priv *wl = ndev_to_wl(dev);
1135 struct wl_security *sec;
1139 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1140 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
1141 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1142 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1144 val = WPA_AUTH_DISABLED;
1145 WL_DBG("setting wpa_auth to 0x%0x\n", val);
1146 err = wl_dev_intvar_set(dev, "wpa_auth", val);
1147 if (unlikely(err)) {
1148 WL_ERR("set wpa_auth failed (%d)\n", err);
1151 sec = wl_read_prof(wl, WL_PROF_SEC);
1152 sec->wpa_versions = sme->crypto.wpa_versions;
1157 wl_set_auth_type(struct net_device *dev, struct cfg80211_connect_params *sme)
1159 struct wl_priv *wl = ndev_to_wl(dev);
1160 struct wl_security *sec;
1164 switch (sme->auth_type) {
1165 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1167 WL_DBG("open system\n");
1169 case NL80211_AUTHTYPE_SHARED_KEY:
1171 WL_DBG("shared key\n");
1173 case NL80211_AUTHTYPE_AUTOMATIC:
1175 WL_DBG("automatic\n");
1177 case NL80211_AUTHTYPE_NETWORK_EAP:
1178 WL_DBG("network eap\n");
1181 WL_ERR("invalid auth type (%d)\n", sme->auth_type);
1185 err = wl_dev_intvar_set(dev, "auth", val);
1186 if (unlikely(err)) {
1187 WL_ERR("set auth failed (%d)\n", err);
1190 sec = wl_read_prof(wl, WL_PROF_SEC);
1191 sec->auth_type = sme->auth_type;
1196 wl_set_set_cipher(struct net_device *dev, struct cfg80211_connect_params *sme)
1198 struct wl_priv *wl = ndev_to_wl(dev);
1199 struct wl_security *sec;
1204 if (sme->crypto.n_ciphers_pairwise) {
1205 switch (sme->crypto.ciphers_pairwise[0]) {
1206 case WLAN_CIPHER_SUITE_WEP40:
1207 case WLAN_CIPHER_SUITE_WEP104:
1210 case WLAN_CIPHER_SUITE_TKIP:
1211 pval = TKIP_ENABLED;
1213 case WLAN_CIPHER_SUITE_CCMP:
1216 case WLAN_CIPHER_SUITE_AES_CMAC:
1220 WL_ERR("invalid cipher pairwise (%d)\n",
1221 sme->crypto.ciphers_pairwise[0]);
1225 if (sme->crypto.cipher_group) {
1226 switch (sme->crypto.cipher_group) {
1227 case WLAN_CIPHER_SUITE_WEP40:
1228 case WLAN_CIPHER_SUITE_WEP104:
1231 case WLAN_CIPHER_SUITE_TKIP:
1232 gval = TKIP_ENABLED;
1234 case WLAN_CIPHER_SUITE_CCMP:
1237 case WLAN_CIPHER_SUITE_AES_CMAC:
1241 WL_ERR("invalid cipher group (%d)\n",
1242 sme->crypto.cipher_group);
1247 WL_DBG("pval (%d) gval (%d)\n", pval, gval);
1248 err = wl_dev_intvar_set(dev, "wsec", pval | gval);
1249 if (unlikely(err)) {
1250 WL_ERR("error (%d)\n", err);
1254 sec = wl_read_prof(wl, WL_PROF_SEC);
1255 sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
1256 sec->cipher_group = sme->crypto.cipher_group;
1262 wl_set_key_mgmt(struct net_device *dev, struct cfg80211_connect_params *sme)
1264 struct wl_priv *wl = ndev_to_wl(dev);
1265 struct wl_security *sec;
1269 if (sme->crypto.n_akm_suites) {
1270 err = wl_dev_intvar_get(dev, "wpa_auth", &val);
1271 if (unlikely(err)) {
1272 WL_ERR("could not get wpa_auth (%d)\n", err);
1275 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
1276 switch (sme->crypto.akm_suites[0]) {
1277 case WLAN_AKM_SUITE_8021X:
1278 val = WPA_AUTH_UNSPECIFIED;
1280 case WLAN_AKM_SUITE_PSK:
1284 WL_ERR("invalid cipher group (%d)\n",
1285 sme->crypto.cipher_group);
1288 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
1289 switch (sme->crypto.akm_suites[0]) {
1290 case WLAN_AKM_SUITE_8021X:
1291 val = WPA2_AUTH_UNSPECIFIED;
1293 case WLAN_AKM_SUITE_PSK:
1294 val = WPA2_AUTH_PSK;
1297 WL_ERR("invalid cipher group (%d)\n",
1298 sme->crypto.cipher_group);
1303 WL_DBG("setting wpa_auth to %d\n", val);
1304 err = wl_dev_intvar_set(dev, "wpa_auth", val);
1305 if (unlikely(err)) {
1306 WL_ERR("could not set wpa_auth (%d)\n", err);
1310 sec = wl_read_prof(wl, WL_PROF_SEC);
1311 sec->wpa_auth = sme->crypto.akm_suites[0];
1317 wl_set_set_sharedkey(struct net_device *dev,
1318 struct cfg80211_connect_params *sme)
1320 struct wl_priv *wl = ndev_to_wl(dev);
1321 struct wl_security *sec;
1322 struct wl_wsec_key key;
1326 WL_DBG("key len (%d)\n", sme->key_len);
1328 sec = wl_read_prof(wl, WL_PROF_SEC);
1329 WL_DBG("wpa_versions 0x%x cipher_pairwise 0x%x\n",
1330 sec->wpa_versions, sec->cipher_pairwise);
1332 (sec->wpa_versions & (NL80211_WPA_VERSION_1 |
1333 NL80211_WPA_VERSION_2))
1334 && (sec->cipher_pairwise & (WLAN_CIPHER_SUITE_WEP40 |
1335 WLAN_CIPHER_SUITE_WEP104))) {
1336 memset(&key, 0, sizeof(key));
1337 key.len = (u32) sme->key_len;
1338 key.index = (u32) sme->key_idx;
1339 if (unlikely(key.len > sizeof(key.data))) {
1340 WL_ERR("Too long key length (%u)\n", key.len);
1343 memcpy(key.data, sme->key, key.len);
1344 key.flags = WL_PRIMARY_KEY;
1345 switch (sec->cipher_pairwise) {
1346 case WLAN_CIPHER_SUITE_WEP40:
1347 key.algo = CRYPTO_ALGO_WEP1;
1349 case WLAN_CIPHER_SUITE_WEP104:
1350 key.algo = CRYPTO_ALGO_WEP128;
1353 WL_ERR("Invalid algorithm (%d)\n",
1354 sme->crypto.ciphers_pairwise[0]);
1357 /* Set the new key/index */
1358 WL_DBG("key length (%d) key index (%d) algo (%d)\n",
1359 key.len, key.index, key.algo);
1360 WL_DBG("key \"%s\"\n", key.data);
1361 swap_key_from_BE(&key);
1362 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key,
1364 if (unlikely(err)) {
1365 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1368 if (sec->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) {
1369 WL_DBG("set auth_type to shared key\n");
1370 val = 1; /* shared key */
1371 err = wl_dev_intvar_set(dev, "auth", val);
1372 if (unlikely(err)) {
1373 WL_ERR("set auth failed (%d)\n", err);
1383 wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1384 struct cfg80211_connect_params *sme)
1386 struct wl_priv *wl = wiphy_to_wl(wiphy);
1387 struct ieee80211_channel *chan = sme->channel;
1388 struct wl_join_params join_params;
1389 size_t join_params_size;
1394 if (unlikely(!sme->ssid)) {
1395 WL_ERR("Invalid ssid\n");
1400 ieee80211_frequency_to_channel(chan->center_freq);
1401 WL_DBG("channel (%d), center_req (%d)\n",
1402 wl->channel, chan->center_freq);
1405 WL_DBG("ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
1406 err = wl_set_wpa_version(dev, sme);
1410 err = wl_set_auth_type(dev, sme);
1414 err = wl_set_set_cipher(dev, sme);
1418 err = wl_set_key_mgmt(dev, sme);
1422 err = wl_set_set_sharedkey(dev, sme);
1426 wl_update_prof(wl, NULL, sme->bssid, WL_PROF_BSSID);
1428 ** Join with specific BSSID and cached SSID
1429 ** If SSID is zero join based on BSSID only
1431 memset(&join_params, 0, sizeof(join_params));
1432 join_params_size = sizeof(join_params.ssid);
1434 join_params.ssid.SSID_len = min(sizeof(join_params.ssid.SSID), sme->ssid_len);
1435 memcpy(&join_params.ssid.SSID, sme->ssid, join_params.ssid.SSID_len);
1436 join_params.ssid.SSID_len = cpu_to_le32(join_params.ssid.SSID_len);
1437 wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID);
1440 memcpy(join_params.params.bssid, sme->bssid, ETH_ALEN);
1442 memcpy(join_params.params.bssid, ether_bcast, ETH_ALEN);
1444 if (join_params.ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1445 WL_DBG("ssid \"%s\", len (%d)\n",
1446 join_params.ssid.SSID, join_params.ssid.SSID_len);
1449 wl_ch_to_chanspec(wl->channel, &join_params, &join_params_size);
1450 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size);
1451 if (unlikely(err)) {
1452 WL_ERR("error (%d)\n", err);
1455 set_bit(WL_STATUS_CONNECTING, &wl->status);
1461 wl_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1464 struct wl_priv *wl = wiphy_to_wl(wiphy);
1468 WL_DBG("Reason %d\n", reason_code);
1471 clear_bit(WL_STATUS_CONNECTED, &wl->status);
1473 scbval.val = reason_code;
1474 memcpy(&scbval.ea, wl_read_prof(wl, WL_PROF_BSSID), ETH_ALEN);
1475 scbval.val = cpu_to_le32(scbval.val);
1476 err = wl_dev_ioctl(dev, WLC_DISASSOC, &scbval,
1479 WL_ERR("error (%d)\n", err);
1481 wl->link_up = false;
1487 wl_cfg80211_set_tx_power(struct wiphy *wiphy,
1488 enum nl80211_tx_power_setting type, s32 dbm)
1491 struct wl_priv *wl = wiphy_to_wl(wiphy);
1492 struct net_device *ndev = wl_to_ndev(wl);
1499 case NL80211_TX_POWER_AUTOMATIC:
1501 case NL80211_TX_POWER_LIMITED:
1503 WL_ERR("TX_POWER_LIMITED - dbm is negative\n");
1507 case NL80211_TX_POWER_FIXED:
1509 WL_ERR("TX_POWER_FIXED - dbm is negative\n");
1514 /* Make sure radio is off or on as far as software is concerned */
1515 disable = WL_RADIO_SW_DISABLE << 16;
1516 disable = cpu_to_le32(disable);
1517 err = wl_dev_ioctl(ndev, WLC_SET_RADIO, &disable, sizeof(disable));
1518 if (unlikely(err)) {
1519 WL_ERR("WLC_SET_RADIO error (%d)\n", err);
1526 txpwrmw = (u16) dbm;
1527 err = wl_dev_intvar_set(ndev, "qtxpower",
1528 (s32) (bcm_mw_to_qdbm(txpwrmw)));
1529 if (unlikely(err)) {
1530 WL_ERR("qtxpower error (%d)\n", err);
1533 wl->conf->tx_power = dbm;
1538 static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm)
1540 struct wl_priv *wl = wiphy_to_wl(wiphy);
1541 struct net_device *ndev = wl_to_ndev(wl);
1547 err = wl_dev_intvar_get(ndev, "qtxpower", &txpwrdbm);
1548 if (unlikely(err)) {
1549 WL_ERR("error (%d)\n", err);
1552 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
1553 *dbm = (s32) bcm_qdbm_to_mw(result);
1559 wl_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *dev,
1560 u8 key_idx, bool unicast, bool multicast)
1566 WL_DBG("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);
1574 wsec = le32_to_cpu(wsec);
1575 if (wsec & WEP_ENABLED) {
1576 /* Just select a new current key */
1577 index = (u32) key_idx;
1578 index = cpu_to_le32(index);
1579 err = wl_dev_ioctl(dev, WLC_SET_KEY_PRIMARY, &index,
1581 if (unlikely(err)) {
1582 WL_ERR("error (%d)\n", err);
1589 wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1590 u8 key_idx, const u8 *mac_addr, struct key_params *params)
1592 struct wl_wsec_key key;
1595 memset(&key, 0, sizeof(key));
1596 key.index = (u32) key_idx;
1597 /* Instead of bcast for ea address for default wep keys,
1598 driver needs it to be Null */
1599 if (!is_multicast_ether_addr(mac_addr))
1600 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
1601 key.len = (u32) params->key_len;
1602 /* check for key index change */
1605 swap_key_from_BE(&key);
1606 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1607 if (unlikely(err)) {
1608 WL_ERR("key delete error (%d)\n", err);
1612 if (key.len > sizeof(key.data)) {
1613 WL_ERR("Invalid key length (%d)\n", key.len);
1617 WL_DBG("Setting the key index %d\n", key.index);
1618 memcpy(key.data, params->key, key.len);
1620 if (params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1622 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1623 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1624 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1627 /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
1628 if (params->seq && params->seq_len == 6) {
1631 ivptr = (u8 *) params->seq;
1632 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
1633 (ivptr[3] << 8) | ivptr[2];
1634 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
1635 key.iv_initialized = true;
1638 switch (params->cipher) {
1639 case WLAN_CIPHER_SUITE_WEP40:
1640 key.algo = CRYPTO_ALGO_WEP1;
1641 WL_DBG("WLAN_CIPHER_SUITE_WEP40\n");
1643 case WLAN_CIPHER_SUITE_WEP104:
1644 key.algo = CRYPTO_ALGO_WEP128;
1645 WL_DBG("WLAN_CIPHER_SUITE_WEP104\n");
1647 case WLAN_CIPHER_SUITE_TKIP:
1648 key.algo = CRYPTO_ALGO_TKIP;
1649 WL_DBG("WLAN_CIPHER_SUITE_TKIP\n");
1651 case WLAN_CIPHER_SUITE_AES_CMAC:
1652 key.algo = CRYPTO_ALGO_AES_CCM;
1653 WL_DBG("WLAN_CIPHER_SUITE_AES_CMAC\n");
1655 case WLAN_CIPHER_SUITE_CCMP:
1656 key.algo = CRYPTO_ALGO_AES_CCM;
1657 WL_DBG("WLAN_CIPHER_SUITE_CCMP\n");
1660 WL_ERR("Invalid cipher (0x%x)\n", params->cipher);
1663 swap_key_from_BE(&key);
1665 dhd_wait_pend8021x(dev);
1666 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1667 if (unlikely(err)) {
1668 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1676 wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1677 u8 key_idx, bool pairwise, const u8 *mac_addr,
1678 struct key_params *params)
1680 struct wl_wsec_key key;
1686 WL_DBG("key index (%d)\n", key_idx);
1690 return wl_add_keyext(wiphy, dev, key_idx, mac_addr, params);
1691 memset(&key, 0, sizeof(key));
1693 key.len = (u32) params->key_len;
1694 key.index = (u32) key_idx;
1696 if (unlikely(key.len > sizeof(key.data))) {
1697 WL_ERR("Too long key length (%u)\n", key.len);
1700 memcpy(key.data, params->key, key.len);
1702 key.flags = WL_PRIMARY_KEY;
1703 switch (params->cipher) {
1704 case WLAN_CIPHER_SUITE_WEP40:
1705 key.algo = CRYPTO_ALGO_WEP1;
1706 WL_DBG("WLAN_CIPHER_SUITE_WEP40\n");
1708 case WLAN_CIPHER_SUITE_WEP104:
1709 key.algo = CRYPTO_ALGO_WEP128;
1710 WL_DBG("WLAN_CIPHER_SUITE_WEP104\n");
1712 case WLAN_CIPHER_SUITE_TKIP:
1713 memcpy(keybuf, &key.data[24], sizeof(keybuf));
1714 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
1715 memcpy(&key.data[16], keybuf, sizeof(keybuf));
1716 key.algo = CRYPTO_ALGO_TKIP;
1717 WL_DBG("WLAN_CIPHER_SUITE_TKIP\n");
1719 case WLAN_CIPHER_SUITE_AES_CMAC:
1720 key.algo = CRYPTO_ALGO_AES_CCM;
1721 WL_DBG("WLAN_CIPHER_SUITE_AES_CMAC\n");
1723 case WLAN_CIPHER_SUITE_CCMP:
1724 key.algo = CRYPTO_ALGO_AES_CCM;
1725 WL_DBG("WLAN_CIPHER_SUITE_CCMP\n");
1728 WL_ERR("Invalid cipher (0x%x)\n", params->cipher);
1732 /* Set the new key/index */
1733 swap_key_from_BE(&key);
1734 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1735 if (unlikely(err)) {
1736 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1741 err = wl_dev_intvar_get(dev, "wsec", &wsec);
1742 if (unlikely(err)) {
1743 WL_ERR("get wsec error (%d)\n", err);
1746 wsec &= ~(WEP_ENABLED);
1748 err = wl_dev_intvar_set(dev, "wsec", wsec);
1749 if (unlikely(err)) {
1750 WL_ERR("set wsec error (%d)\n", err);
1754 val = 1; /* assume shared key. otherwise 0 */
1755 val = cpu_to_le32(val);
1756 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
1757 if (unlikely(err)) {
1758 WL_ERR("WLC_SET_AUTH error (%d)\n", err);
1765 wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1766 u8 key_idx, bool pairwise, const u8 *mac_addr)
1768 struct wl_wsec_key key;
1774 memset(&key, 0, sizeof(key));
1776 key.index = (u32) key_idx;
1777 key.flags = WL_PRIMARY_KEY;
1778 key.algo = CRYPTO_ALGO_OFF;
1780 WL_DBG("key index (%d)\n", key_idx);
1781 /* Set the new key/index */
1782 swap_key_from_BE(&key);
1783 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1784 if (unlikely(err)) {
1785 if (err == -EINVAL) {
1786 if (key.index >= DOT11_MAX_DEFAULT_KEYS) {
1787 /* we ignore this key index in this case */
1788 WL_DBG("invalid key index (%d)\n", key_idx);
1791 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1797 err = wl_dev_intvar_get(dev, "wsec", &wsec);
1798 if (unlikely(err)) {
1799 WL_ERR("get wsec error (%d)\n", err);
1802 wsec &= ~(WEP_ENABLED);
1804 err = wl_dev_intvar_set(dev, "wsec", wsec);
1805 if (unlikely(err)) {
1806 WL_ERR("set wsec error (%d)\n", err);
1810 val = 0; /* assume open key. otherwise 1 */
1811 val = cpu_to_le32(val);
1812 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
1813 if (unlikely(err)) {
1814 WL_ERR("WLC_SET_AUTH error (%d)\n", err);
1821 wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
1822 u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
1823 void (*callback) (void *cookie, struct key_params * params))
1825 struct key_params params;
1826 struct wl_wsec_key key;
1827 struct wl_priv *wl = wiphy_to_wl(wiphy);
1828 struct wl_security *sec;
1832 WL_DBG("key index (%d)\n", key_idx);
1835 memset(&key, 0, sizeof(key));
1836 key.index = key_idx;
1837 swap_key_to_BE(&key);
1838 memset(¶ms, 0, sizeof(params));
1839 params.key_len = (u8) min_t(u8, WLAN_MAX_KEY_LEN, key.len);
1840 memcpy(params.key, key.data, params.key_len);
1842 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec));
1843 if (unlikely(err)) {
1844 WL_ERR("WLC_GET_WSEC error (%d)\n", err);
1847 wsec = le32_to_cpu(wsec);
1850 sec = wl_read_prof(wl, WL_PROF_SEC);
1851 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
1852 params.cipher = WLAN_CIPHER_SUITE_WEP40;
1853 WL_DBG("WLAN_CIPHER_SUITE_WEP40\n");
1854 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
1855 params.cipher = WLAN_CIPHER_SUITE_WEP104;
1856 WL_DBG("WLAN_CIPHER_SUITE_WEP104\n");
1860 params.cipher = WLAN_CIPHER_SUITE_TKIP;
1861 WL_DBG("WLAN_CIPHER_SUITE_TKIP\n");
1864 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
1865 WL_DBG("WLAN_CIPHER_SUITE_AES_CMAC\n");
1868 WL_ERR("Invalid algo (0x%x)\n", wsec);
1872 callback(cookie, ¶ms);
1877 wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
1878 struct net_device *dev, u8 key_idx)
1880 WL_INFO("Not supported\n");
1886 wl_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1887 u8 *mac, struct station_info *sinfo)
1889 struct wl_priv *wl = wiphy_to_wl(wiphy);
1897 (memcmp(mac, wl_read_prof(wl, WL_PROF_BSSID), ETH_ALEN))) {
1898 WL_ERR("Wrong Mac address\n");
1902 /* Report the current tx rate */
1903 err = wl_dev_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate));
1905 WL_ERR("Could not get rate (%d)\n", err);
1907 rate = le32_to_cpu(rate);
1908 sinfo->filled |= STATION_INFO_TX_BITRATE;
1909 sinfo->txrate.legacy = rate * 5;
1910 WL_DBG("Rate %d Mbps\n", rate / 2);
1913 if (test_bit(WL_STATUS_CONNECTED, &wl->status)) {
1915 err = wl_dev_ioctl(dev, WLC_GET_RSSI, &scb_val,
1917 if (unlikely(err)) {
1918 WL_ERR("Could not get rssi (%d)\n", err);
1921 rssi = le32_to_cpu(scb_val.val);
1922 sinfo->filled |= STATION_INFO_SIGNAL;
1923 sinfo->signal = rssi;
1924 WL_DBG("RSSI %d dBm\n", rssi);
1931 wl_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1932 bool enabled, s32 timeout)
1938 pm = enabled ? PM_FAST : PM_OFF;
1939 pm = cpu_to_le32(pm);
1940 WL_DBG("power save %s\n", (pm ? "enabled" : "disabled"));
1941 err = wl_dev_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
1942 if (unlikely(err)) {
1944 WL_DBG("net_device is not ready yet\n");
1946 WL_ERR("error (%d)\n", err);
1952 static __used u32 wl_find_msb(u16 bit16)
1956 if (bit16 & 0xff00) {
1980 wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev,
1982 const struct cfg80211_bitrate_mask *mask)
1984 struct wl_rateset rateset;
1993 /* addr param is always NULL. ignore it */
1994 /* Get current rateset */
1995 err = wl_dev_ioctl(dev, WLC_GET_CURR_RATESET, &rateset,
1997 if (unlikely(err)) {
1998 WL_ERR("could not get current rateset (%d)\n", err);
2002 rateset.count = le32_to_cpu(rateset.count);
2004 legacy = wl_find_msb(mask->control[IEEE80211_BAND_2GHZ].legacy);
2006 legacy = wl_find_msb(mask->control[IEEE80211_BAND_5GHZ].legacy);
2008 val = wl_g_rates[legacy - 1].bitrate * 100000;
2010 if (val < rateset.count) {
2011 /* Select rate by rateset index */
2012 rate = rateset.rates[val] & 0x7f;
2014 /* Specified rate in bps */
2015 rate = val / 500000;
2018 WL_DBG("rate %d mbps\n", rate / 2);
2022 * Set rate override,
2023 * Since the is a/b/g-blind, both a/bg_rate are enforced.
2025 err_bg = wl_dev_intvar_set(dev, "bg_rate", rate);
2026 err_a = wl_dev_intvar_set(dev, "a_rate", rate);
2027 if (unlikely(err_bg && err_a)) {
2028 WL_ERR("could not set fixed rate (%d) (%d)\n", err_bg, err_a);
2029 return err_bg | err_a;
2035 static s32 wl_cfg80211_resume(struct wiphy *wiphy)
2037 struct wl_priv *wl = wiphy_to_wl(wiphy);
2038 struct net_device *ndev = wl_to_ndev(wl);
2041 * Check for WL_STATUS_READY before any function call which
2042 * could result is bus access. Don't block the resume for
2043 * any driver error conditions
2046 #if defined(CONFIG_PM_SLEEP)
2047 atomic_set(&dhd_mmc_suspend, false);
2048 #endif /* defined(CONFIG_PM_SLEEP) */
2050 if (test_bit(WL_STATUS_READY, &wl->status)) {
2051 /* Turn on Watchdog timer */
2052 wl_os_wd_timer(ndev, dhd_watchdog_ms);
2053 wl_invoke_iscan(wiphy_to_wl(wiphy));
2059 static s32 wl_cfg80211_suspend(struct wiphy *wiphy)
2061 struct wl_priv *wl = wiphy_to_wl(wiphy);
2062 struct net_device *ndev = wl_to_ndev(wl);
2066 * Check for WL_STATUS_READY before any function call which
2067 * could result is bus access. Don't block the suspend for
2068 * any driver error conditions
2072 * While going to suspend if associated with AP disassociate
2073 * from AP to save power while system is in suspended state
2075 if (test_bit(WL_STATUS_CONNECTED, &wl->status) &&
2076 test_bit(WL_STATUS_READY, &wl->status)) {
2077 WL_INFO("Disassociating from AP"
2078 " while entering suspend state\n");
2082 * Make sure WPA_Supplicant receives all the event
2083 * generated due to DISASSOC call to the fw to keep
2084 * the state fw and WPA_Supplicant state consistent
2091 set_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
2092 if (test_bit(WL_STATUS_READY, &wl->status))
2095 if (wl->scan_request) {
2096 /* Indidate scan abort to cfg80211 layer */
2097 WL_INFO("Terminating scan in progress\n");
2098 cfg80211_scan_done(wl->scan_request, true);
2099 wl->scan_request = NULL;
2101 clear_bit(WL_STATUS_SCANNING, &wl->status);
2102 clear_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
2103 clear_bit(WL_STATUS_CONNECTING, &wl->status);
2104 clear_bit(WL_STATUS_CONNECTED, &wl->status);
2106 /* Inform SDIO stack not to switch off power to the chip */
2107 sdioh_sdio_set_host_pm_flags(MMC_PM_KEEP_POWER);
2109 /* Turn off watchdog timer */
2110 if (test_bit(WL_STATUS_READY, &wl->status)) {
2111 WL_INFO("Terminate watchdog timer and enable MPC\n");
2112 wl_set_mpc(ndev, 1);
2113 wl_os_wd_timer(ndev, 0);
2116 #if defined(CONFIG_PM_SLEEP)
2117 atomic_set(&dhd_mmc_suspend, true);
2118 #endif /* defined(CONFIG_PM_SLEEP) */
2125 wl_update_pmklist(struct net_device *dev, struct wl_pmk_list *pmk_list,
2130 WL_DBG("No of elements %d\n", pmk_list->pmkids.npmkid);
2131 for (i = 0; i < pmk_list->pmkids.npmkid; i++) {
2132 WL_DBG("PMKID[%d]: %pM =\n", i,
2133 &pmk_list->pmkids.pmkid[i].BSSID);
2134 for (j = 0; j < WLAN_PMKID_LEN; j++) {
2135 WL_DBG("%02x\n", pmk_list->pmkids.pmkid[i].PMKID[j]);
2139 err = wl_dev_bufvar_set(dev, "pmkid_info", (char *)pmk_list,
2147 wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
2148 struct cfg80211_pmksa *pmksa)
2150 struct wl_priv *wl = wiphy_to_wl(wiphy);
2155 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++)
2156 if (!memcmp(pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID,
2159 if (i < WL_NUM_PMKIDS_MAX) {
2160 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID, pmksa->bssid,
2162 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID, pmksa->pmkid,
2164 if (i == wl->pmk_list->pmkids.npmkid)
2165 wl->pmk_list->pmkids.npmkid++;
2169 WL_DBG("set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2170 &wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].BSSID);
2171 for (i = 0; i < WLAN_PMKID_LEN; i++) {
2173 wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].
2177 err = wl_update_pmklist(dev, wl->pmk_list, err);
2183 wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
2184 struct cfg80211_pmksa *pmksa)
2186 struct wl_priv *wl = wiphy_to_wl(wiphy);
2187 struct _pmkid_list pmkid;
2192 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
2193 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
2195 WL_DBG("del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
2196 &pmkid.pmkid[0].BSSID);
2197 for (i = 0; i < WLAN_PMKID_LEN; i++) {
2198 WL_DBG("%02x\n", pmkid.pmkid[0].PMKID[i]);
2201 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++)
2203 (pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID,
2207 if ((wl->pmk_list->pmkids.npmkid > 0)
2208 && (i < wl->pmk_list->pmkids.npmkid)) {
2209 memset(&wl->pmk_list->pmkids.pmkid[i], 0, sizeof(pmkid_t));
2210 for (; i < (wl->pmk_list->pmkids.npmkid - 1); i++) {
2211 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID,
2212 &wl->pmk_list->pmkids.pmkid[i + 1].BSSID,
2214 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID,
2215 &wl->pmk_list->pmkids.pmkid[i + 1].PMKID,
2218 wl->pmk_list->pmkids.npmkid--;
2223 err = wl_update_pmklist(dev, wl->pmk_list, err);
2230 wl_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *dev)
2232 struct wl_priv *wl = wiphy_to_wl(wiphy);
2236 memset(wl->pmk_list, 0, sizeof(*wl->pmk_list));
2237 err = wl_update_pmklist(dev, wl->pmk_list, err);
2242 static struct cfg80211_ops wl_cfg80211_ops = {
2243 .change_virtual_intf = wl_cfg80211_change_iface,
2244 .scan = wl_cfg80211_scan,
2245 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
2246 .join_ibss = wl_cfg80211_join_ibss,
2247 .leave_ibss = wl_cfg80211_leave_ibss,
2248 .get_station = wl_cfg80211_get_station,
2249 .set_tx_power = wl_cfg80211_set_tx_power,
2250 .get_tx_power = wl_cfg80211_get_tx_power,
2251 .add_key = wl_cfg80211_add_key,
2252 .del_key = wl_cfg80211_del_key,
2253 .get_key = wl_cfg80211_get_key,
2254 .set_default_key = wl_cfg80211_config_default_key,
2255 .set_default_mgmt_key = wl_cfg80211_config_default_mgmt_key,
2256 .set_power_mgmt = wl_cfg80211_set_power_mgmt,
2257 .set_bitrate_mask = wl_cfg80211_set_bitrate_mask,
2258 .connect = wl_cfg80211_connect,
2259 .disconnect = wl_cfg80211_disconnect,
2260 .suspend = wl_cfg80211_suspend,
2261 .resume = wl_cfg80211_resume,
2262 .set_pmksa = wl_cfg80211_set_pmksa,
2263 .del_pmksa = wl_cfg80211_del_pmksa,
2264 .flush_pmksa = wl_cfg80211_flush_pmksa
2267 static s32 wl_mode_to_nl80211_iftype(s32 mode)
2273 return NL80211_IFTYPE_STATION;
2275 return NL80211_IFTYPE_ADHOC;
2277 return NL80211_IFTYPE_UNSPECIFIED;
2283 static struct wireless_dev *wl_alloc_wdev(s32 sizeof_iface,
2286 struct wireless_dev *wdev;
2289 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
2290 if (unlikely(!wdev)) {
2291 WL_ERR("Could not allocate wireless device\n");
2292 return ERR_PTR(-ENOMEM);
2295 wiphy_new(&wl_cfg80211_ops, sizeof(struct wl_priv) + sizeof_iface);
2296 if (unlikely(!wdev->wiphy)) {
2297 WL_ERR("Couldn not allocate wiphy device\n");
2301 set_wiphy_dev(wdev->wiphy, dev);
2302 wdev->wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
2303 wdev->wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
2304 wdev->wiphy->interface_modes =
2305 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
2306 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &__wl_band_2ghz;
2307 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_a; /* Set
2308 * it as 11a by default.
2309 * This will be updated with
2312 * if phy has 11n capability
2314 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2315 wdev->wiphy->cipher_suites = __wl_cipher_suites;
2316 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
2317 #ifndef WL_POWERSAVE_DISABLED
2318 wdev->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; /* enable power
2323 wdev->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
2324 #endif /* !WL_POWERSAVE_DISABLED */
2325 err = wiphy_register(wdev->wiphy);
2326 if (unlikely(err < 0)) {
2327 WL_ERR("Couldn not register wiphy device (%d)\n", err);
2328 goto wiphy_register_out;
2333 wiphy_free(wdev->wiphy);
2338 return ERR_PTR(err);
2341 static void wl_free_wdev(struct wl_priv *wl)
2343 struct wireless_dev *wdev = wl_to_wdev(wl);
2345 if (unlikely(!wdev)) {
2346 WL_ERR("wdev is invalid\n");
2349 wiphy_unregister(wdev->wiphy);
2350 wiphy_free(wdev->wiphy);
2352 wl_to_wdev(wl) = NULL;
2355 static s32 wl_inform_bss(struct wl_priv *wl)
2357 struct wl_scan_results *bss_list;
2358 struct wl_bss_info *bi = NULL; /* must be initialized */
2362 bss_list = wl->bss_list;
2363 if (unlikely(bss_list->version != WL_BSS_INFO_VERSION)) {
2364 WL_ERR("Version %d != WL_BSS_INFO_VERSION\n",
2368 WL_DBG("scanned AP count (%d)\n", bss_list->count);
2369 bi = next_bss(bss_list, bi);
2370 for_each_bss(bss_list, bi, i) {
2371 err = wl_inform_single_bss(wl, bi);
2379 static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi)
2381 struct wiphy *wiphy = wl_to_wiphy(wl);
2382 struct ieee80211_channel *notify_channel;
2383 struct cfg80211_bss *bss;
2384 struct ieee80211_supported_band *band;
2388 u64 notify_timestamp;
2389 u16 notify_capability;
2390 u16 notify_interval;
2392 size_t notify_ielen;
2395 if (unlikely(le32_to_cpu(bi->length) > WL_BSS_INFO_MAX)) {
2396 WL_ERR("Bss info is larger than buffer. Discarding\n");
2400 channel = bi->ctl_ch ? bi->ctl_ch :
2401 CHSPEC_CHANNEL(le16_to_cpu(bi->chanspec));
2403 if (channel <= CH_MAX_2G_CHANNEL)
2404 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2406 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2408 freq = ieee80211_channel_to_frequency(channel, band->band);
2409 notify_channel = ieee80211_get_channel(wiphy, freq);
2411 notify_timestamp = jiffies_to_msecs(jiffies)*1000; /* uSec */
2412 notify_capability = le16_to_cpu(bi->capability);
2413 notify_interval = le16_to_cpu(bi->beacon_period);
2414 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2415 notify_ielen = le16_to_cpu(bi->ie_length);
2416 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2418 WL_DBG("bssid: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
2419 bi->BSSID[0], bi->BSSID[1], bi->BSSID[2],
2420 bi->BSSID[3], bi->BSSID[4], bi->BSSID[5]);
2421 WL_DBG("Channel: %d(%d)\n", channel, freq);
2422 WL_DBG("Capability: %X\n", notify_capability);
2423 WL_DBG("Beacon interval: %d\n", notify_interval);
2424 WL_DBG("Signal: %d\n", notify_signal);
2425 WL_DBG("notify_timestamp: %#018llx\n", notify_timestamp);
2427 bss = cfg80211_inform_bss(wiphy, notify_channel, (const u8 *)bi->BSSID,
2428 notify_timestamp, notify_capability, notify_interval, notify_ie,
2429 notify_ielen, notify_signal, GFP_KERNEL);
2431 if (unlikely(!bss)) {
2432 WL_ERR("cfg80211_inform_bss_frame error\n");
2440 wl_inform_ibss(struct wl_priv *wl, struct net_device *dev, const u8 *bssid)
2442 struct wiphy *wiphy = wl_to_wiphy(wl);
2443 struct ieee80211_channel *notify_channel;
2444 struct wl_bss_info *bi = NULL;
2445 struct ieee80211_supported_band *band;
2450 u64 notify_timestamp;
2451 u16 notify_capability;
2452 u16 notify_interval;
2454 size_t notify_ielen;
2457 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2459 WL_ERR("kzalloc() failed\n");
2464 *(u32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2466 err = wl_dev_ioctl(dev, WLC_GET_BSS_INFO, buf, WL_BSS_INFO_MAX);
2467 if (unlikely(err)) {
2468 WL_ERR("WLC_GET_BSS_INFO failed: %d\n", err);
2472 bi = (wl_bss_info_t *)(buf + 4);
2474 channel = bi->ctl_ch ? bi->ctl_ch :
2475 CHSPEC_CHANNEL(le16_to_cpu(bi->chanspec));
2477 if (channel <= CH_MAX_2G_CHANNEL)
2478 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2480 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2482 freq = ieee80211_channel_to_frequency(channel, band->band);
2483 notify_channel = ieee80211_get_channel(wiphy, freq);
2485 notify_timestamp = jiffies_to_msecs(jiffies)*1000; /* uSec */
2486 notify_capability = le16_to_cpu(bi->capability);
2487 notify_interval = le16_to_cpu(bi->beacon_period);
2488 notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
2489 notify_ielen = le16_to_cpu(bi->ie_length);
2490 notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
2492 WL_DBG("channel: %d(%d)\n", channel, freq);
2493 WL_DBG("capability: %X\n", notify_capability);
2494 WL_DBG("beacon interval: %d\n", notify_interval);
2495 WL_DBG("signal: %d\n", notify_signal);
2496 WL_DBG("notify_timestamp: %#018llx\n", notify_timestamp);
2498 cfg80211_inform_bss(wiphy, notify_channel, bssid,
2499 notify_timestamp, notify_capability, notify_interval,
2500 notify_ie, notify_ielen, notify_signal, GFP_KERNEL);
2509 static bool wl_is_linkup(struct wl_priv *wl, const wl_event_msg_t *e)
2511 u32 event = be32_to_cpu(e->event_type);
2512 u32 status = be32_to_cpu(e->status);
2514 if (event == WLC_E_SET_SSID && status == WLC_E_STATUS_SUCCESS) {
2515 WL_DBG("Processing set ssid\n");
2523 static bool wl_is_linkdown(struct wl_priv *wl, const wl_event_msg_t *e)
2525 u32 event = be32_to_cpu(e->event_type);
2526 u16 flags = be16_to_cpu(e->flags);
2528 if (event == WLC_E_LINK && (!(flags & WLC_EVENT_MSG_LINK))) {
2529 WL_DBG("Processing link down\n");
2535 static bool wl_is_nonetwork(struct wl_priv *wl, const wl_event_msg_t *e)
2537 u32 event = be32_to_cpu(e->event_type);
2538 u32 status = be32_to_cpu(e->status);
2539 u16 flags = be16_to_cpu(e->flags);
2541 if (event == WLC_E_LINK && status == WLC_E_STATUS_NO_NETWORKS) {
2542 WL_DBG("Processing Link %s & no network found\n",
2543 flags & WLC_EVENT_MSG_LINK ? "up" : "down");
2547 if (event == WLC_E_SET_SSID && status != WLC_E_STATUS_SUCCESS) {
2548 WL_DBG("Processing connecting & no network found\n");
2556 wl_notify_connect_status(struct wl_priv *wl, struct net_device *ndev,
2557 const wl_event_msg_t *e, void *data)
2561 if (wl_is_linkup(wl, e)) {
2563 if (wl_is_ibssmode(wl)) {
2564 wl_update_prof(wl, NULL, (void *)e->addr,
2566 wl_inform_ibss(wl, ndev, e->addr);
2567 cfg80211_ibss_joined(ndev, e->addr, GFP_KERNEL);
2568 clear_bit(WL_STATUS_CONNECTING, &wl->status);
2569 set_bit(WL_STATUS_CONNECTED, &wl->status);
2571 wl_bss_connect_done(wl, ndev, e, data, true);
2572 } else if (wl_is_linkdown(wl, e)) {
2573 WL_DBG("Linkdown\n");
2574 if (wl_is_ibssmode(wl)) {
2575 if (test_and_clear_bit(WL_STATUS_CONNECTED,
2579 if (test_and_clear_bit(WL_STATUS_CONNECTED,
2581 cfg80211_disconnected(ndev, 0, NULL, 0,
2586 wl_init_prof(wl->profile);
2587 } else if (wl_is_nonetwork(wl, e)) {
2588 if (wl_is_ibssmode(wl))
2589 clear_bit(WL_STATUS_CONNECTING, &wl->status);
2591 wl_bss_connect_done(wl, ndev, e, data, false);
2598 wl_notify_roaming_status(struct wl_priv *wl, struct net_device *ndev,
2599 const wl_event_msg_t *e, void *data)
2602 u32 event = be32_to_cpu(e->event_type);
2603 u32 status = be32_to_cpu(e->status);
2605 if (event == WLC_E_ROAM && status == WLC_E_STATUS_SUCCESS) {
2606 if (test_bit(WL_STATUS_CONNECTED, &wl->status))
2607 wl_bss_roaming_done(wl, ndev, e, data);
2609 wl_bss_connect_done(wl, ndev, e, data, true);
2616 wl_dev_bufvar_set(struct net_device *dev, s8 *name, s8 *buf, s32 len)
2618 struct wl_priv *wl = ndev_to_wl(dev);
2621 buflen = bcm_mkiovar(name, buf, len, wl->ioctl_buf, WL_IOCTL_LEN_MAX);
2624 return wl_dev_ioctl(dev, WLC_SET_VAR, wl->ioctl_buf, buflen);
2628 wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
2631 struct wl_priv *wl = ndev_to_wl(dev);
2635 len = bcm_mkiovar(name, NULL, 0, wl->ioctl_buf, WL_IOCTL_LEN_MAX);
2637 err = wl_dev_ioctl(dev, WLC_GET_VAR, (void *)wl->ioctl_buf,
2639 if (unlikely(err)) {
2640 WL_ERR("error (%d)\n", err);
2643 memcpy(buf, wl->ioctl_buf, buf_len);
2648 static s32 wl_get_assoc_ies(struct wl_priv *wl)
2650 struct net_device *ndev = wl_to_ndev(wl);
2651 struct wl_assoc_ielen *assoc_info;
2652 struct wl_connect_info *conn_info = wl_to_conn(wl);
2657 wl_clear_assoc_ies(wl);
2659 err = wl_dev_bufvar_get(ndev, "assoc_info", wl->extra_buf,
2661 if (unlikely(err)) {
2662 WL_ERR("could not get assoc info (%d)\n", err);
2665 assoc_info = (struct wl_assoc_ielen *)wl->extra_buf;
2666 req_len = assoc_info->req_len;
2667 resp_len = assoc_info->resp_len;
2669 err = wl_dev_bufvar_get(ndev, "assoc_req_ies", wl->extra_buf,
2671 if (unlikely(err)) {
2672 WL_ERR("could not get assoc req (%d)\n", err);
2675 conn_info->req_ie_len = req_len;
2677 kmemdup(wl->extra_buf, conn_info->req_ie_len, GFP_KERNEL);
2679 conn_info->req_ie_len = 0;
2680 conn_info->req_ie = NULL;
2683 err = wl_dev_bufvar_get(ndev, "assoc_resp_ies", wl->extra_buf,
2685 if (unlikely(err)) {
2686 WL_ERR("could not get assoc resp (%d)\n", err);
2689 conn_info->resp_ie_len = resp_len;
2690 conn_info->resp_ie =
2691 kmemdup(wl->extra_buf, conn_info->resp_ie_len, GFP_KERNEL);
2693 conn_info->resp_ie_len = 0;
2694 conn_info->resp_ie = NULL;
2696 WL_DBG("req len (%d) resp len (%d)\n",
2697 conn_info->req_ie_len, conn_info->resp_ie_len);
2702 static void wl_clear_assoc_ies(struct wl_priv *wl)
2704 struct wl_connect_info *conn_info = wl_to_conn(wl);
2706 kfree(conn_info->req_ie);
2707 conn_info->req_ie = NULL;
2708 conn_info->req_ie_len = 0;
2709 kfree(conn_info->resp_ie);
2710 conn_info->resp_ie = NULL;
2711 conn_info->resp_ie_len = 0;
2715 static void wl_ch_to_chanspec(int ch, struct wl_join_params *join_params,
2716 size_t *join_params_size)
2718 chanspec_t chanspec = 0;
2721 join_params->params.chanspec_num = 1;
2722 join_params->params.chanspec_list[0] = ch;
2724 if (join_params->params.chanspec_list[0] <= CH_MAX_2G_CHANNEL)
2725 chanspec |= WL_CHANSPEC_BAND_2G;
2727 chanspec |= WL_CHANSPEC_BAND_5G;
2729 chanspec |= WL_CHANSPEC_BW_20;
2730 chanspec |= WL_CHANSPEC_CTL_SB_NONE;
2732 *join_params_size += WL_ASSOC_PARAMS_FIXED_SIZE +
2733 join_params->params.chanspec_num * sizeof(chanspec_t);
2735 join_params->params.chanspec_list[0] &= WL_CHANSPEC_CHAN_MASK;
2736 join_params->params.chanspec_list[0] |= chanspec;
2737 join_params->params.chanspec_list[0] =
2738 cpu_to_le16(join_params->params.chanspec_list[0]);
2740 join_params->params.chanspec_num =
2741 cpu_to_le32(join_params->params.chanspec_num);
2743 WL_DBG("join_params->params.chanspec_list[0]= %#X, channel %d, chanspec %#X\n",
2744 join_params->params.chanspec_list[0], ch, chanspec);
2748 static s32 wl_update_bss_info(struct wl_priv *wl)
2750 struct wl_bss_info *bi;
2751 struct wlc_ssid *ssid;
2752 struct bcm_tlv *tim;
2753 u16 beacon_interval;
2759 if (wl_is_ibssmode(wl))
2762 ssid = (struct wlc_ssid *)wl_read_prof(wl, WL_PROF_SSID);
2764 *(u32 *)wl->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
2765 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_BSS_INFO,
2766 wl->extra_buf, WL_EXTRA_BUF_MAX);
2767 if (unlikely(err)) {
2768 WL_ERR("Could not get bss info %d\n", err);
2769 goto update_bss_info_out;
2772 bi = (struct wl_bss_info *)(wl->extra_buf + 4);
2773 err = wl_inform_single_bss(wl, bi);
2775 goto update_bss_info_out;
2777 ie = ((u8 *)bi) + bi->ie_offset;
2778 ie_len = bi->ie_length;
2779 beacon_interval = cpu_to_le16(bi->beacon_period);
2781 tim = bcm_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
2783 dtim_period = tim->data[1];
2786 * active scan was done so we could not get dtim
2787 * information out of probe response.
2788 * so we speficially query dtim information to dongle.
2791 err = wl_dev_intvar_get(wl_to_ndev(wl), "dtim_assoc", &var);
2792 if (unlikely(err)) {
2793 WL_ERR("wl dtim_assoc failed (%d)\n", err);
2794 goto update_bss_info_out;
2796 dtim_period = (u8)var;
2799 wl_update_prof(wl, NULL, &beacon_interval, WL_PROF_BEACONINT);
2800 wl_update_prof(wl, NULL, &dtim_period, WL_PROF_DTIMPERIOD);
2802 update_bss_info_out:
2807 wl_bss_roaming_done(struct wl_priv *wl, struct net_device *ndev,
2808 const wl_event_msg_t *e, void *data)
2810 struct wl_connect_info *conn_info = wl_to_conn(wl);
2813 wl_get_assoc_ies(wl);
2814 wl_update_prof(wl, NULL, &e->addr, WL_PROF_BSSID);
2815 wl_update_bss_info(wl);
2817 cfg80211_roamed(ndev,
2818 (u8 *)wl_read_prof(wl, WL_PROF_BSSID),
2819 conn_info->req_ie, conn_info->req_ie_len,
2820 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
2821 WL_DBG("Report roaming result\n");
2823 set_bit(WL_STATUS_CONNECTED, &wl->status);
2829 wl_bss_connect_done(struct wl_priv *wl, struct net_device *ndev,
2830 const wl_event_msg_t *e, void *data, bool completed)
2832 struct wl_connect_info *conn_info = wl_to_conn(wl);
2836 if (test_and_clear_bit(WL_STATUS_CONNECTING, &wl->status)) {
2838 wl_get_assoc_ies(wl);
2839 wl_update_prof(wl, NULL, &e->addr, WL_PROF_BSSID);
2840 wl_update_bss_info(wl);
2842 cfg80211_connect_result(ndev,
2843 (u8 *)wl_read_prof(wl, WL_PROF_BSSID),
2845 conn_info->req_ie_len,
2847 conn_info->resp_ie_len,
2848 completed ? WLAN_STATUS_SUCCESS : WLAN_STATUS_AUTH_TIMEOUT,
2851 set_bit(WL_STATUS_CONNECTED, &wl->status);
2852 WL_DBG("Report connect result - connection %s\n",
2853 completed ? "succeeded" : "failed");
2859 wl_notify_mic_status(struct wl_priv *wl, struct net_device *ndev,
2860 const wl_event_msg_t *e, void *data)
2862 u16 flags = be16_to_cpu(e->flags);
2863 enum nl80211_key_type key_type;
2866 if (flags & WLC_EVENT_MSG_GROUP)
2867 key_type = NL80211_KEYTYPE_GROUP;
2869 key_type = NL80211_KEYTYPE_PAIRWISE;
2871 cfg80211_michael_mic_failure(ndev, (u8 *)&e->addr, key_type, -1,
2879 wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
2880 const wl_event_msg_t *e, void *data)
2882 struct channel_info channel_inform;
2883 struct wl_scan_results *bss_list;
2884 u32 len = WL_SCAN_BUF_MAX;
2887 if (wl->iscan_on && wl->iscan_kickstart)
2888 return wl_wakeup_iscan(wl_to_iscan(wl));
2890 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) {
2891 WL_ERR("Scan complete while device not scanning\n");
2894 if (unlikely(!wl->scan_request)) {
2897 err = wl_dev_ioctl(ndev, WLC_GET_CHANNEL, &channel_inform,
2898 sizeof(channel_inform));
2899 if (unlikely(err)) {
2900 WL_ERR("scan busy (%d)\n", err);
2903 channel_inform.scan_channel = le32_to_cpu(channel_inform.scan_channel);
2904 if (unlikely(channel_inform.scan_channel)) {
2906 WL_DBG("channel_inform.scan_channel (%d)\n",
2907 channel_inform.scan_channel);
2909 wl->bss_list = wl->scan_results;
2910 bss_list = wl->bss_list;
2911 memset(bss_list, 0, len);
2912 bss_list->buflen = cpu_to_le32(len);
2913 err = wl_dev_ioctl(ndev, WLC_SCAN_RESULTS, bss_list, len);
2914 if (unlikely(err)) {
2915 WL_ERR("%s Scan_results error (%d)\n", ndev->name, err);
2919 bss_list->buflen = le32_to_cpu(bss_list->buflen);
2920 bss_list->version = le32_to_cpu(bss_list->version);
2921 bss_list->count = le32_to_cpu(bss_list->count);
2923 err = wl_inform_bss(wl);
2928 if (wl->scan_request) {
2929 cfg80211_scan_done(wl->scan_request, false);
2930 wl_set_mpc(ndev, 1);
2931 wl->scan_request = NULL;
2937 static void wl_init_conf(struct wl_conf *conf)
2939 conf->mode = (u32)-1;
2940 conf->frag_threshold = (u32)-1;
2941 conf->rts_threshold = (u32)-1;
2942 conf->retry_short = (u32)-1;
2943 conf->retry_long = (u32)-1;
2944 conf->tx_power = -1;
2947 static void wl_init_prof(struct wl_profile *prof)
2949 memset(prof, 0, sizeof(*prof));
2952 static void wl_init_eloop_handler(struct wl_event_loop *el)
2954 memset(el, 0, sizeof(*el));
2955 el->handler[WLC_E_SCAN_COMPLETE] = wl_notify_scan_status;
2956 el->handler[WLC_E_LINK] = wl_notify_connect_status;
2957 el->handler[WLC_E_ROAM] = wl_notify_roaming_status;
2958 el->handler[WLC_E_MIC_ERROR] = wl_notify_mic_status;
2959 el->handler[WLC_E_SET_SSID] = wl_notify_connect_status;
2962 static s32 wl_init_priv_mem(struct wl_priv *wl)
2964 wl->scan_results = kzalloc(WL_SCAN_BUF_MAX, GFP_KERNEL);
2965 if (unlikely(!wl->scan_results)) {
2966 WL_ERR("Scan results alloc failed\n");
2967 goto init_priv_mem_out;
2969 wl->conf = kzalloc(sizeof(*wl->conf), GFP_KERNEL);
2970 if (unlikely(!wl->conf)) {
2971 WL_ERR("wl_conf alloc failed\n");
2972 goto init_priv_mem_out;
2974 wl->profile = kzalloc(sizeof(*wl->profile), GFP_KERNEL);
2975 if (unlikely(!wl->profile)) {
2976 WL_ERR("wl_profile alloc failed\n");
2977 goto init_priv_mem_out;
2979 wl->bss_info = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2980 if (unlikely(!wl->bss_info)) {
2981 WL_ERR("Bss information alloc failed\n");
2982 goto init_priv_mem_out;
2984 wl->scan_req_int = kzalloc(sizeof(*wl->scan_req_int), GFP_KERNEL);
2985 if (unlikely(!wl->scan_req_int)) {
2986 WL_ERR("Scan req alloc failed\n");
2987 goto init_priv_mem_out;
2989 wl->ioctl_buf = kzalloc(WL_IOCTL_LEN_MAX, GFP_KERNEL);
2990 if (unlikely(!wl->ioctl_buf)) {
2991 WL_ERR("Ioctl buf alloc failed\n");
2992 goto init_priv_mem_out;
2994 wl->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
2995 if (unlikely(!wl->extra_buf)) {
2996 WL_ERR("Extra buf alloc failed\n");
2997 goto init_priv_mem_out;
2999 wl->iscan = kzalloc(sizeof(*wl->iscan), GFP_KERNEL);
3000 if (unlikely(!wl->iscan)) {
3001 WL_ERR("Iscan buf alloc failed\n");
3002 goto init_priv_mem_out;
3004 wl->fw = kzalloc(sizeof(*wl->fw), GFP_KERNEL);
3005 if (unlikely(!wl->fw)) {
3006 WL_ERR("fw object alloc failed\n");
3007 goto init_priv_mem_out;
3009 wl->pmk_list = kzalloc(sizeof(*wl->pmk_list), GFP_KERNEL);
3010 if (unlikely(!wl->pmk_list)) {
3011 WL_ERR("pmk list alloc failed\n");
3012 goto init_priv_mem_out;
3018 wl_deinit_priv_mem(wl);
3023 static void wl_deinit_priv_mem(struct wl_priv *wl)
3025 kfree(wl->scan_results);
3026 wl->scan_results = NULL;
3027 kfree(wl->bss_info);
3028 wl->bss_info = NULL;
3033 kfree(wl->scan_req_int);
3034 wl->scan_req_int = NULL;
3035 kfree(wl->ioctl_buf);
3036 wl->ioctl_buf = NULL;
3037 kfree(wl->extra_buf);
3038 wl->extra_buf = NULL;
3043 kfree(wl->pmk_list);
3044 wl->pmk_list = NULL;
3047 static s32 wl_create_event_handler(struct wl_priv *wl)
3049 sema_init(&wl->event_sync, 0);
3050 wl->event_tsk = kthread_run(wl_event_handler, wl, "wl_event_handler");
3051 if (IS_ERR(wl->event_tsk)) {
3052 wl->event_tsk = NULL;
3053 WL_ERR("failed to create event thread\n");
3059 static void wl_destroy_event_handler(struct wl_priv *wl)
3061 if (wl->event_tsk) {
3062 send_sig(SIGTERM, wl->event_tsk, 1);
3063 kthread_stop(wl->event_tsk);
3064 wl->event_tsk = NULL;
3068 static void wl_term_iscan(struct wl_priv *wl)
3070 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
3072 if (wl->iscan_on && iscan->tsk) {
3073 iscan->state = WL_ISCAN_STATE_IDLE;
3074 send_sig(SIGTERM, iscan->tsk, 1);
3075 kthread_stop(iscan->tsk);
3080 static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted)
3082 struct wl_priv *wl = iscan_to_wl(iscan);
3083 struct net_device *ndev = wl_to_ndev(wl);
3085 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) {
3086 WL_ERR("Scan complete while device not scanning\n");
3089 if (likely(wl->scan_request)) {
3090 cfg80211_scan_done(wl->scan_request, aborted);
3091 wl_set_mpc(ndev, 1);
3092 wl->scan_request = NULL;
3094 wl->iscan_kickstart = false;
3097 static s32 wl_wakeup_iscan(struct wl_iscan_ctrl *iscan)
3099 if (likely(iscan->state != WL_ISCAN_STATE_IDLE)) {
3100 WL_DBG("wake up iscan\n");
3109 wl_get_iscan_results(struct wl_iscan_ctrl *iscan, u32 *status,
3110 struct wl_scan_results **bss_list)
3112 struct wl_iscan_results list;
3113 struct wl_scan_results *results;
3114 struct wl_iscan_results *list_buf;
3117 memset(iscan->scan_buf, 0, WL_ISCAN_BUF_MAX);
3118 list_buf = (struct wl_iscan_results *)iscan->scan_buf;
3119 results = &list_buf->results;
3120 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
3121 results->version = 0;
3124 memset(&list, 0, sizeof(list));
3125 list.results.buflen = cpu_to_le32(WL_ISCAN_BUF_MAX);
3126 err = wl_dev_iovar_getbuf(iscan->dev, "iscanresults", &list,
3127 WL_ISCAN_RESULTS_FIXED_SIZE, iscan->scan_buf,
3129 if (unlikely(err)) {
3130 WL_ERR("error (%d)\n", err);
3133 results->buflen = le32_to_cpu(results->buflen);
3134 results->version = le32_to_cpu(results->version);
3135 results->count = le32_to_cpu(results->count);
3136 WL_DBG("results->count = %d\n", results->count);
3137 WL_DBG("results->buflen = %d\n", results->buflen);
3138 *status = le32_to_cpu(list_buf->status);
3139 *bss_list = results;
3144 static s32 wl_iscan_done(struct wl_priv *wl)
3146 struct wl_iscan_ctrl *iscan = wl->iscan;
3149 iscan->state = WL_ISCAN_STATE_IDLE;
3152 wl_notify_iscan_complete(iscan, false);
3158 static s32 wl_iscan_pending(struct wl_priv *wl)
3160 struct wl_iscan_ctrl *iscan = wl->iscan;
3163 /* Reschedule the timer */
3164 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
3165 iscan->timer_on = 1;
3170 static s32 wl_iscan_inprogress(struct wl_priv *wl)
3172 struct wl_iscan_ctrl *iscan = wl->iscan;
3177 wl_run_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
3179 /* Reschedule the timer */
3180 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
3181 iscan->timer_on = 1;
3186 static s32 wl_iscan_aborted(struct wl_priv *wl)
3188 struct wl_iscan_ctrl *iscan = wl->iscan;
3191 iscan->state = WL_ISCAN_STATE_IDLE;
3193 wl_notify_iscan_complete(iscan, true);
3199 static s32 wl_iscan_thread(void *data)
3201 struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1 };
3202 struct wl_iscan_ctrl *iscan = (struct wl_iscan_ctrl *)data;
3203 struct wl_priv *wl = iscan_to_wl(iscan);
3204 struct wl_iscan_eloop *el = &iscan->el;
3208 sched_setscheduler(current, SCHED_FIFO, ¶m);
3209 allow_signal(SIGTERM);
3210 status = WL_SCAN_RESULTS_PARTIAL;
3211 while (likely(!down_interruptible(&iscan->sync))) {
3212 if (kthread_should_stop())
3214 if (iscan->timer_on) {
3215 del_timer_sync(&iscan->timer);
3216 iscan->timer_on = 0;
3219 err = wl_get_iscan_results(iscan, &status, &wl->bss_list);
3220 if (unlikely(err)) {
3221 status = WL_SCAN_RESULTS_ABORTED;
3222 WL_ERR("Abort iscan\n");
3225 el->handler[status] (wl);
3227 if (iscan->timer_on) {
3228 del_timer_sync(&iscan->timer);
3229 iscan->timer_on = 0;
3231 WL_DBG("%s was terminated\n", __func__);
3236 static void wl_iscan_timer(unsigned long data)
3238 struct wl_iscan_ctrl *iscan = (struct wl_iscan_ctrl *)data;
3241 iscan->timer_on = 0;
3242 WL_DBG("timer expired\n");
3243 wl_wakeup_iscan(iscan);
3247 static s32 wl_invoke_iscan(struct wl_priv *wl)
3249 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
3252 if (wl->iscan_on && !iscan->tsk) {
3253 iscan->state = WL_ISCAN_STATE_IDLE;
3254 sema_init(&iscan->sync, 0);
3255 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
3256 if (IS_ERR(iscan->tsk)) {
3257 WL_ERR("Could not create iscan thread\n");
3266 static void wl_init_iscan_eloop(struct wl_iscan_eloop *el)
3268 memset(el, 0, sizeof(*el));
3269 el->handler[WL_SCAN_RESULTS_SUCCESS] = wl_iscan_done;
3270 el->handler[WL_SCAN_RESULTS_PARTIAL] = wl_iscan_inprogress;
3271 el->handler[WL_SCAN_RESULTS_PENDING] = wl_iscan_pending;
3272 el->handler[WL_SCAN_RESULTS_ABORTED] = wl_iscan_aborted;
3273 el->handler[WL_SCAN_RESULTS_NO_MEM] = wl_iscan_aborted;
3276 static s32 wl_init_iscan(struct wl_priv *wl)
3278 struct wl_iscan_ctrl *iscan = wl_to_iscan(wl);
3282 iscan->dev = wl_to_ndev(wl);
3283 iscan->state = WL_ISCAN_STATE_IDLE;
3284 wl_init_iscan_eloop(&iscan->el);
3285 iscan->timer_ms = WL_ISCAN_TIMER_INTERVAL_MS;
3286 init_timer(&iscan->timer);
3287 iscan->timer.data = (unsigned long) iscan;
3288 iscan->timer.function = wl_iscan_timer;
3289 sema_init(&iscan->sync, 0);
3290 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
3291 if (IS_ERR(iscan->tsk)) {
3292 WL_ERR("Could not create iscan thread\n");
3302 static void wl_init_fw(struct wl_fw_ctrl *fw)
3304 fw->status = 0; /* init fw loading status.
3305 0 means nothing was loaded yet */
3308 static s32 wl_init_priv(struct wl_priv *wl)
3310 struct wiphy *wiphy = wl_to_wiphy(wl);
3313 wl->scan_request = NULL;
3314 wl->pwr_save = !!(wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT);
3315 wl->iscan_on = true; /* iscan on & off switch.
3316 we enable iscan per default */
3317 wl->roam_on = false; /* roam on & off switch.
3318 we enable roam per default */
3320 wl->iscan_kickstart = false;
3321 wl->active_scan = true; /* we do active scan for
3322 specific scan per default */
3323 wl->dongle_up = false; /* dongle is not up yet */
3325 err = wl_init_priv_mem(wl);
3328 if (unlikely(wl_create_event_handler(wl)))
3330 wl_init_eloop_handler(&wl->el);
3331 mutex_init(&wl->usr_sync);
3332 err = wl_init_iscan(wl);
3336 wl_init_conf(wl->conf);
3337 wl_init_prof(wl->profile);
3343 static void wl_deinit_priv(struct wl_priv *wl)
3345 wl_destroy_event_handler(wl);
3346 wl->dongle_up = false; /* dongle down */
3350 wl_deinit_priv_mem(wl);
3353 s32 wl_cfg80211_attach(struct net_device *ndev, void *data)
3355 struct wireless_dev *wdev;
3357 struct wl_iface *ci;
3360 if (unlikely(!ndev)) {
3361 WL_ERR("ndev is invalid\n");
3364 wl_cfg80211_dev = kzalloc(sizeof(struct wl_dev), GFP_KERNEL);
3365 if (unlikely(!wl_cfg80211_dev)) {
3366 WL_ERR("wl_cfg80211_dev is invalid\n");
3369 WL_DBG("func %p\n", wl_cfg80211_get_sdio_func());
3370 wdev = wl_alloc_wdev(sizeof(struct wl_iface), &wl_cfg80211_get_sdio_func()->dev);
3374 wdev->iftype = wl_mode_to_nl80211_iftype(WL_MODE_BSS);
3375 wl = wdev_to_wl(wdev);
3378 ci = (struct wl_iface *)wl_to_ci(wl);
3380 ndev->ieee80211_ptr = wdev;
3381 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
3382 wdev->netdev = ndev;
3383 err = wl_init_priv(wl);
3384 if (unlikely(err)) {
3385 WL_ERR("Failed to init iwm_priv (%d)\n", err);
3386 goto cfg80211_attach_out;
3388 wl_set_drvdata(wl_cfg80211_dev, ci);
3389 set_bit(WL_STATUS_READY, &wl->status);
3393 cfg80211_attach_out:
3398 void wl_cfg80211_detach(void)
3406 wl_set_drvdata(wl_cfg80211_dev, NULL);
3407 kfree(wl_cfg80211_dev);
3408 wl_cfg80211_dev = NULL;
3409 wl_clear_sdio_func();
3412 static void wl_wakeup_event(struct wl_priv *wl)
3414 up(&wl->event_sync);
3417 static s32 wl_event_handler(void *data)
3419 struct wl_priv *wl = (struct wl_priv *)data;
3420 struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1 };
3421 struct wl_event_q *e;
3423 sched_setscheduler(current, SCHED_FIFO, ¶m);
3424 allow_signal(SIGTERM);
3425 while (likely(!down_interruptible(&wl->event_sync))) {
3426 if (kthread_should_stop())
3428 e = wl_deq_event(wl);
3430 WL_ERR("event queue empty...\n");
3433 WL_DBG("event type (%d)\n", e->etype);
3434 if (wl->el.handler[e->etype]) {
3435 wl->el.handler[e->etype] (wl, wl_to_ndev(wl), &e->emsg,
3438 WL_DBG("Unknown Event (%d): ignoring\n", e->etype);
3442 WL_DBG("%s was terminated\n", __func__);
3447 wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t * e, void *data)
3449 u32 event_type = be32_to_cpu(e->event_type);
3450 struct wl_priv *wl = ndev_to_wl(ndev);
3451 #if (WL_DBG_LEVEL > 0)
3452 s8 *estr = (event_type <= sizeof(wl_dbg_estr) / WL_DBG_ESTR_MAX - 1) ?
3453 wl_dbg_estr[event_type] : (s8 *) "Unknown";
3454 #endif /* (WL_DBG_LEVEL > 0) */
3455 WL_DBG("event_type (%d):" "WLC_E_" "%s\n", event_type, estr);
3456 if (likely(!wl_enq_event(wl, event_type, e, data)))
3457 wl_wakeup_event(wl);
3460 static void wl_init_eq(struct wl_priv *wl)
3462 wl_init_eq_lock(wl);
3463 INIT_LIST_HEAD(&wl->eq_list);
3466 static void wl_flush_eq(struct wl_priv *wl)
3468 struct wl_event_q *e;
3471 while (!list_empty(&wl->eq_list)) {
3472 e = list_first_entry(&wl->eq_list, struct wl_event_q, eq_list);
3473 list_del(&e->eq_list);
3480 * retrieve first queued event from head
3483 static struct wl_event_q *wl_deq_event(struct wl_priv *wl)
3485 struct wl_event_q *e = NULL;
3488 if (likely(!list_empty(&wl->eq_list))) {
3489 e = list_first_entry(&wl->eq_list, struct wl_event_q, eq_list);
3490 list_del(&e->eq_list);
3498 ** push event to tail of the queue
3502 wl_enq_event(struct wl_priv *wl, u32 event, const wl_event_msg_t *msg,
3505 struct wl_event_q *e;
3508 e = kzalloc(sizeof(struct wl_event_q), GFP_KERNEL);
3510 WL_ERR("event alloc failed\n");
3515 memcpy(&e->emsg, msg, sizeof(wl_event_msg_t));
3519 list_add_tail(&e->eq_list, &wl->eq_list);
3525 static void wl_put_event(struct wl_event_q *e)
3530 void wl_cfg80211_sdio_func(void *func)
3532 cfg80211_sdio_func = (struct sdio_func *)func;
3535 static void wl_clear_sdio_func(void)
3537 cfg80211_sdio_func = NULL;
3540 struct sdio_func *wl_cfg80211_get_sdio_func(void)
3542 return cfg80211_sdio_func;
3545 static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype)
3551 case NL80211_IFTYPE_MONITOR:
3552 case NL80211_IFTYPE_WDS:
3553 WL_ERR("type (%d) : currently we do not support this mode\n",
3557 case NL80211_IFTYPE_ADHOC:
3560 case NL80211_IFTYPE_STATION:
3565 WL_ERR("invalid type (%d)\n", iftype);
3568 infra = cpu_to_le32(infra);
3569 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra));
3570 if (unlikely(err)) {
3571 WL_ERR("WLC_SET_INFRA error (%d)\n", err);
3578 #ifndef EMBEDDED_PLATFORM
3579 static s32 wl_dongle_country(struct net_device *ndev, u8 ccode)
3587 static s32 wl_dongle_up(struct net_device *ndev, u32 up)
3591 err = wl_dev_ioctl(ndev, WLC_UP, &up, sizeof(up));
3592 if (unlikely(err)) {
3593 WL_ERR("WLC_UP error (%d)\n", err);
3598 static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode)
3602 err = wl_dev_ioctl(ndev, WLC_SET_PM, &power_mode, sizeof(power_mode));
3603 if (unlikely(err)) {
3604 WL_ERR("WLC_SET_PM error (%d)\n", err);
3610 wl_dongle_glom(struct net_device *ndev, u32 glom, u32 dongle_align)
3612 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3616 /* Match Host and Dongle rx alignment */
3617 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
3619 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3620 if (unlikely(err)) {
3621 WL_ERR("txglomalign error (%d)\n", err);
3622 goto dongle_glom_out;
3624 /* disable glom option per default */
3625 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
3626 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3627 if (unlikely(err)) {
3628 WL_ERR("txglom error (%d)\n", err);
3629 goto dongle_glom_out;
3636 wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
3637 s32 scan_unassoc_time)
3641 err = wl_dev_ioctl(ndev, WLC_SET_SCAN_CHANNEL_TIME, &scan_assoc_time,
3642 sizeof(scan_assoc_time));
3644 if (err == -EOPNOTSUPP) {
3645 WL_INFO("Scan assoc time is not supported\n");
3647 WL_ERR("Scan assoc time error (%d)\n", err);
3649 goto dongle_scantime_out;
3651 err = wl_dev_ioctl(ndev, WLC_SET_SCAN_UNASSOC_TIME, &scan_unassoc_time,
3652 sizeof(scan_unassoc_time));
3654 if (err == -EOPNOTSUPP) {
3655 WL_INFO("Scan unassoc time is not supported\n");
3657 WL_ERR("Scan unassoc time error (%d)\n", err);
3659 goto dongle_scantime_out;
3662 dongle_scantime_out:
3667 wl_dongle_offload(struct net_device *ndev, s32 arpoe, s32 arp_ol)
3669 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3673 /* Set ARP offload */
3674 bcm_mkiovar("arpoe", (char *)&arpoe, 4, iovbuf, sizeof(iovbuf));
3675 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3677 if (err == -EOPNOTSUPP)
3678 WL_INFO("arpoe is not supported\n");
3680 WL_ERR("arpoe error (%d)\n", err);
3682 goto dongle_offload_out;
3684 bcm_mkiovar("arp_ol", (char *)&arp_ol, 4, iovbuf, sizeof(iovbuf));
3685 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3687 if (err == -EOPNOTSUPP)
3688 WL_INFO("arp_ol is not supported\n");
3690 WL_ERR("arp_ol error (%d)\n", err);
3692 goto dongle_offload_out;
3699 static s32 wl_pattern_atoh(s8 *src, s8 *dst)
3702 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
3703 WL_ERR("Mask invalid format. Needs to start with 0x\n");
3706 src = src + 2; /* Skip past 0x */
3707 if (strlen(src) % 2 != 0) {
3708 WL_ERR("Mask invalid format. Needs to be of even length\n");
3711 for (i = 0; *src != '\0'; i++) {
3713 strncpy(num, src, 2);
3715 dst[i] = (u8) simple_strtoul(num, NULL, 16);
3721 static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode)
3723 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3726 struct wl_pkt_filter pkt_filter;
3727 struct wl_pkt_filter *pkt_filterp;
3735 /* add a default packet filter pattern */
3736 str = "pkt_filter_add";
3737 str_len = strlen(str);
3738 strncpy(buf, str, str_len);
3739 buf[str_len] = '\0';
3740 buf_len = str_len + 1;
3742 pkt_filterp = (struct wl_pkt_filter *)(buf + str_len + 1);
3744 /* Parse packet filter id. */
3745 pkt_filter.id = cpu_to_le32(100);
3747 /* Parse filter polarity. */
3748 pkt_filter.negate_match = cpu_to_le32(0);
3750 /* Parse filter type. */
3751 pkt_filter.type = cpu_to_le32(0);
3753 /* Parse pattern filter offset. */
3754 pkt_filter.u.pattern.offset = cpu_to_le32(0);
3756 /* Parse pattern filter mask. */
3757 mask_size = cpu_to_le32(wl_pattern_atoh("0xff",
3758 (char *)pkt_filterp->u.pattern.
3761 /* Parse pattern filter pattern. */
3762 pattern_size = cpu_to_le32(wl_pattern_atoh("0x00",
3763 (char *)&pkt_filterp->u.
3768 if (mask_size != pattern_size) {
3769 WL_ERR("Mask and pattern not the same size\n");
3771 goto dongle_filter_out;
3774 pkt_filter.u.pattern.size_bytes = mask_size;
3775 buf_len += WL_PKT_FILTER_FIXED_LEN;
3776 buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
3778 /* Keep-alive attributes are set in local
3779 * variable (keep_alive_pkt), and
3780 * then memcpy'ed into buffer (keep_alive_pktp) since there is no
3781 * guarantee that the buffer is properly aligned.
3783 memcpy((char *)pkt_filterp, &pkt_filter,
3784 WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
3786 err = wl_dev_ioctl(ndev, WLC_SET_VAR, buf, buf_len);
3788 if (err == -EOPNOTSUPP) {
3789 WL_INFO("filter not supported\n");
3791 WL_ERR("filter (%d)\n", err);
3793 goto dongle_filter_out;
3796 /* set mode to allow pattern */
3797 bcm_mkiovar("pkt_filter_mode", (char *)&filter_mode, 4, iovbuf,
3799 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3801 if (err == -EOPNOTSUPP) {
3802 WL_INFO("filter_mode not supported\n");
3804 WL_ERR("filter_mode (%d)\n", err);
3806 goto dongle_filter_out;
3812 #endif /* !EMBEDDED_PLATFORM */
3814 static s32 wl_dongle_eventmsg(struct net_device *ndev)
3816 s8 iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
3818 s8 eventmask[WL_EVENTING_MASK_LEN];
3821 /* Setup event_msgs */
3822 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf,
3824 err = wl_dev_ioctl(ndev, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
3825 if (unlikely(err)) {
3826 WL_ERR("Get event_msgs error (%d)\n", err);
3827 goto dongle_eventmsg_out;
3829 memcpy(eventmask, iovbuf, WL_EVENTING_MASK_LEN);
3831 setbit(eventmask, WLC_E_SET_SSID);
3832 setbit(eventmask, WLC_E_ROAM);
3833 setbit(eventmask, WLC_E_PRUNE);
3834 setbit(eventmask, WLC_E_AUTH);
3835 setbit(eventmask, WLC_E_REASSOC);
3836 setbit(eventmask, WLC_E_REASSOC_IND);
3837 setbit(eventmask, WLC_E_DEAUTH_IND);
3838 setbit(eventmask, WLC_E_DISASSOC_IND);
3839 setbit(eventmask, WLC_E_DISASSOC);
3840 setbit(eventmask, WLC_E_JOIN);
3841 setbit(eventmask, WLC_E_ASSOC_IND);
3842 setbit(eventmask, WLC_E_PSK_SUP);
3843 setbit(eventmask, WLC_E_LINK);
3844 setbit(eventmask, WLC_E_NDIS_LINK);
3845 setbit(eventmask, WLC_E_MIC_ERROR);
3846 setbit(eventmask, WLC_E_PMKID_CACHE);
3847 setbit(eventmask, WLC_E_TXFAIL);
3848 setbit(eventmask, WLC_E_JOIN_START);
3849 setbit(eventmask, WLC_E_SCAN_COMPLETE);
3851 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf,
3853 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3854 if (unlikely(err)) {
3855 WL_ERR("Set event_msgs error (%d)\n", err);
3856 goto dongle_eventmsg_out;
3859 dongle_eventmsg_out:
3864 wl_dongle_roam(struct net_device *ndev, u32 roamvar, u32 bcn_timeout)
3872 * Setup timeout if Beacons are lost and roam is
3873 * off to report link down
3876 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout,
3877 sizeof(bcn_timeout), iovbuf, sizeof(iovbuf));
3878 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3879 if (unlikely(err)) {
3880 WL_ERR("bcn_timeout error (%d)\n", err);
3881 goto dongle_rom_out;
3886 * Enable/Disable built-in roaming to allow supplicant
3887 * to take care of roaming
3889 WL_INFO("Internal Roaming = %s\n", roamvar ? "Off" : "On");
3890 bcm_mkiovar("roam_off", (char *)&roamvar,
3891 sizeof(roamvar), iovbuf, sizeof(iovbuf));
3892 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3893 if (unlikely(err)) {
3894 WL_ERR("roam_off error (%d)\n", err);
3895 goto dongle_rom_out;
3898 roamtrigger[0] = WL_ROAM_TRIGGER_LEVEL;
3899 roamtrigger[1] = WLC_BAND_ALL;
3900 err = wl_dev_ioctl(ndev, WLC_SET_ROAM_TRIGGER,
3901 (void *)roamtrigger, sizeof(roamtrigger));
3902 if (unlikely(err)) {
3903 WL_ERR("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
3904 goto dongle_rom_out;
3907 roam_delta[0] = WL_ROAM_DELTA;
3908 roam_delta[1] = WLC_BAND_ALL;
3909 err = wl_dev_ioctl(ndev, WLC_SET_ROAM_DELTA,
3910 (void *)roam_delta, sizeof(roam_delta));
3911 if (unlikely(err)) {
3912 WL_ERR("WLC_SET_ROAM_DELTA error (%d)\n", err);
3913 goto dongle_rom_out;
3920 s32 wl_config_dongle(struct wl_priv *wl, bool need_lock)
3923 #define DHD_SDALIGN 32
3925 struct net_device *ndev;
3926 struct wireless_dev *wdev;
3932 ndev = wl_to_ndev(wl);
3933 wdev = ndev->ieee80211_ptr;
3937 #ifndef EMBEDDED_PLATFORM
3938 err = wl_dongle_up(ndev, 0);
3940 goto default_conf_out;
3941 err = wl_dongle_country(ndev, 0);
3943 goto default_conf_out;
3944 err = wl_dongle_power(ndev, PM_FAST);
3946 goto default_conf_out;
3947 err = wl_dongle_glom(ndev, 0, DHD_SDALIGN);
3949 goto default_conf_out;
3950 wl_dongle_scantime(ndev, 40, 80);
3951 wl_dongle_offload(ndev, 1, 0xf);
3952 wl_dongle_filter(ndev, 1);
3953 #endif /* !EMBEDDED_PLATFORM */
3955 err = wl_dongle_eventmsg(ndev);
3957 goto default_conf_out;
3958 err = wl_dongle_roam(ndev, (wl->roam_on ? 0 : 1), WL_BEACON_TIMEOUT);
3960 goto default_conf_out;
3961 err = wl_dongle_mode(ndev, wdev->iftype);
3962 if (unlikely(err && err != -EINPROGRESS))
3963 goto default_conf_out;
3964 err = wl_dongle_probecap(wl);
3966 goto default_conf_out;
3968 /* -EINPROGRESS: Call commit handler */
3974 wl->dongle_up = true;
3980 static s32 wl_update_wiphybands(struct wl_priv *wl)
3982 struct wiphy *wiphy;
3987 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_PHYLIST, &phy_list,
3989 if (unlikely(err)) {
3990 WL_ERR("error (%d)\n", err);
3994 phy = ((char *)&phy_list)[1];
3995 WL_DBG("%c phy\n", phy);
3996 if (phy == 'n' || phy == 'a') {
3997 wiphy = wl_to_wiphy(wl);
3998 wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_n;
4004 static s32 __wl_cfg80211_up(struct wl_priv *wl)
4008 wl_debugfs_add_netdev_params(wl);
4010 err = wl_config_dongle(wl, false);
4014 wl_invoke_iscan(wl);
4015 set_bit(WL_STATUS_READY, &wl->status);
4019 static s32 __wl_cfg80211_down(struct wl_priv *wl)
4023 /* Check if cfg80211 interface is already down */
4024 if (!test_bit(WL_STATUS_READY, &wl->status))
4025 return err; /* it is even not ready */
4027 set_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
4029 if (wl->scan_request) {
4030 cfg80211_scan_done(wl->scan_request, true); /* true
4032 /* wl_set_mpc(wl_to_ndev(wl), 1); */ /* BUG
4033 * this operation cannot help
4034 * but here because sdio
4035 * is already down through
4037 * Need to figure out how to
4038 * address this issue
4040 wl->scan_request = NULL;
4042 clear_bit(WL_STATUS_READY, &wl->status);
4043 clear_bit(WL_STATUS_SCANNING, &wl->status);
4044 clear_bit(WL_STATUS_SCAN_ABORTING, &wl->status);
4045 clear_bit(WL_STATUS_CONNECTED, &wl->status);
4047 wl_debugfs_remove_netdev(wl);
4052 s32 wl_cfg80211_up(void)
4058 mutex_lock(&wl->usr_sync);
4059 err = __wl_cfg80211_up(wl);
4060 mutex_unlock(&wl->usr_sync);
4065 s32 wl_cfg80211_down(void)
4071 mutex_lock(&wl->usr_sync);
4072 err = __wl_cfg80211_down(wl);
4073 mutex_unlock(&wl->usr_sync);
4078 static s32 wl_dongle_probecap(struct wl_priv *wl)
4082 err = wl_update_wiphybands(wl);
4089 static void *wl_read_prof(struct wl_priv *wl, s32 item)
4093 return &wl->profile->sec;
4095 return &wl->profile->active;
4097 return &wl->profile->bssid;
4099 return &wl->profile->ssid;
4101 WL_ERR("invalid item (%d)\n", item);
4106 wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e, void *data,
4110 struct wlc_ssid *ssid;
4114 ssid = (wlc_ssid_t *) data;
4115 memset(wl->profile->ssid.SSID, 0,
4116 sizeof(wl->profile->ssid.SSID));
4117 memcpy(wl->profile->ssid.SSID, ssid->SSID, ssid->SSID_len);
4118 wl->profile->ssid.SSID_len = ssid->SSID_len;
4122 memcpy(wl->profile->bssid, data, ETH_ALEN);
4124 memset(wl->profile->bssid, 0, ETH_ALEN);
4127 memcpy(&wl->profile->sec, data, sizeof(wl->profile->sec));
4130 wl->profile->active = *(bool *)data;
4132 case WL_PROF_BEACONINT:
4133 wl->profile->beacon_interval = *(u16 *)data;
4135 case WL_PROF_DTIMPERIOD:
4136 wl->profile->dtim_period = *(u8 *)data;
4139 WL_ERR("unsupported item (%d)\n", item);
4147 void wl_cfg80211_dbg_level(u32 level)
4150 * prohibit to change debug level
4151 * by insmod parameter.
4152 * eventually debug level will be configured
4153 * in compile time by using CONFIG_XXX
4155 /* wl_dbg_level = level; */
4158 static bool wl_is_ibssmode(struct wl_priv *wl)
4160 return wl->conf->mode == WL_MODE_IBSS;
4163 static __used s32 wl_add_ie(struct wl_priv *wl, u8 t, u8 l, u8 *v)
4165 struct wl_ie *ie = wl_to_ie(wl);
4168 if (unlikely(ie->offset + l + 2 > WL_TLV_INFO_MAX)) {
4169 WL_ERR("ei crosses buffer boundary\n");
4172 ie->buf[ie->offset] = t;
4173 ie->buf[ie->offset + 1] = l;
4174 memcpy(&ie->buf[ie->offset + 2], v, l);
4175 ie->offset += l + 2;
4181 static void wl_link_down(struct wl_priv *wl)
4183 struct net_device *dev = NULL;
4186 clear_bit(WL_STATUS_CONNECTED, &wl->status);
4189 dev = wl_to_ndev(wl);
4190 WL_INFO("Call WLC_DISASSOC to stop excess roaming\n ");
4191 err = wl_dev_ioctl(dev, WLC_DISASSOC, NULL, 0);
4193 WL_ERR("WLC_DISASSOC failed (%d)\n", err);
4194 wl->link_up = false;
4198 static void wl_lock_eq(struct wl_priv *wl)
4200 spin_lock_irq(&wl->eq_lock);
4203 static void wl_unlock_eq(struct wl_priv *wl)
4205 spin_unlock_irq(&wl->eq_lock);
4208 static void wl_init_eq_lock(struct wl_priv *wl)
4210 spin_lock_init(&wl->eq_lock);
4213 static void wl_delay(u32 ms)
4215 if (ms < 1000 / HZ) {
4223 static void wl_set_drvdata(struct wl_dev *dev, void *data)
4225 dev->driver_data = data;
4228 static void *wl_get_drvdata(struct wl_dev *dev)
4230 return dev->driver_data;
4233 s32 wl_cfg80211_read_fw(s8 *buf, u32 size)
4235 const struct firmware *fw_entry;
4240 fw_entry = wl->fw->fw_entry;
4242 if (fw_entry->size < wl->fw->ptr + size)
4243 size = fw_entry->size - wl->fw->ptr;
4245 memcpy(buf, &fw_entry->data[wl->fw->ptr], size);
4246 wl->fw->ptr += size;
4250 void wl_cfg80211_release_fw(void)
4255 release_firmware(wl->fw->fw_entry);
4259 void *wl_cfg80211_request_fw(s8 *file_name)
4262 const struct firmware *fw_entry = NULL;
4265 WL_DBG("file name : \"%s\"\n", file_name);
4268 if (!test_bit(WL_FW_LOADING_DONE, &wl->fw->status)) {
4269 err = request_firmware(&wl->fw->fw_entry, file_name,
4270 &wl_cfg80211_get_sdio_func()->dev);
4271 if (unlikely(err)) {
4272 WL_ERR("Could not download fw (%d)\n", err);
4275 set_bit(WL_FW_LOADING_DONE, &wl->fw->status);
4276 fw_entry = wl->fw->fw_entry;
4278 WL_DBG("fw size (%zd), data (%p)\n",
4279 fw_entry->size, fw_entry->data);
4281 } else if (!test_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status)) {
4282 err = request_firmware(&wl->fw->fw_entry, file_name,
4283 &wl_cfg80211_get_sdio_func()->dev);
4284 if (unlikely(err)) {
4285 WL_ERR("Could not download nvram (%d)\n", err);
4288 set_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status);
4289 fw_entry = wl->fw->fw_entry;
4291 WL_DBG("nvram size (%zd), data (%p)\n",
4292 fw_entry->size, fw_entry->data);
4295 WL_DBG("Downloading already done. Nothing to do more\n");
4300 if (unlikely(err)) {
4304 return (void *)fw_entry->data;
4307 s8 *wl_cfg80211_get_fwname(void)
4312 strcpy(wl->fw->fw_name, WL_4329_FW_FILE);
4313 return wl->fw->fw_name;
4316 s8 *wl_cfg80211_get_nvramname(void)
4321 strcpy(wl->fw->nvram_name, WL_4329_NVRAM_FILE);
4322 return wl->fw->nvram_name;
4325 static void wl_set_mpc(struct net_device *ndev, int mpc)
4329 err = wl_dev_intvar_set(ndev, "mpc", mpc);
4330 if (unlikely(err)) {
4331 WL_ERR("fail to set mpc\n");
4334 WL_DBG("MPC : %d\n", mpc);
4337 static int wl_debugfs_add_netdev_params(struct wl_priv *wl)
4339 char buf[10+IFNAMSIZ];
4343 sprintf(buf, "netdev:%s", wl_to_ndev(wl)->name);
4344 wl->debugfsdir = debugfs_create_dir(buf, wl_to_wiphy(wl)->debugfsdir);
4346 fd = debugfs_create_u16("beacon_int", S_IRUGO, wl->debugfsdir,
4347 (u16 *)&wl->profile->beacon_interval);
4353 fd = debugfs_create_u8("dtim_period", S_IRUGO, wl->debugfsdir,
4354 (u8 *)&wl->profile->dtim_period);
4364 static void wl_debugfs_remove_netdev(struct wl_priv *wl)
4366 debugfs_remove_recursive(wl->debugfsdir);
4367 wl->debugfsdir = NULL;