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 #ifndef _wl_cfg80211_h_
18 #define _wl_cfg80211_h_
20 #include <linux/wireless.h>
21 #include <net/cfg80211.h>
31 #define WL_DBG_CONN (1 << 5)
32 #define WL_DBG_SCAN (1 << 4)
33 #define WL_DBG_TRACE (1 << 3)
34 #define WL_DBG_INFO (1 << 1)
35 #define WL_DBG_ERR (1 << 0)
36 #define WL_DBG_MASK ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
37 (WL_DBG_SCAN) | (WL_DBG_CONN))
39 #define WL_ERR(fmt, args...) \
41 if (wl_dbg_level & WL_DBG_ERR) { \
42 if (net_ratelimit()) { \
43 printk(KERN_ERR "ERROR @%s : " fmt, \
50 #define WL_INFO(fmt, args...) \
52 if (wl_dbg_level & WL_DBG_INFO) { \
53 if (net_ratelimit()) { \
54 printk(KERN_ERR "INFO @%s : " fmt, \
60 #define WL_TRACE(fmt, args...) \
62 if (wl_dbg_level & WL_DBG_TRACE) { \
63 if (net_ratelimit()) { \
64 printk(KERN_ERR "TRACE @%s : " fmt, \
70 #define WL_SCAN(fmt, args...) \
72 if (wl_dbg_level & WL_DBG_SCAN) { \
73 if (net_ratelimit()) { \
74 printk(KERN_ERR "SCAN @%s : " fmt, \
80 #define WL_CONN(fmt, args...) \
82 if (wl_dbg_level & WL_DBG_CONN) { \
83 if (net_ratelimit()) { \
84 printk(KERN_ERR "CONN @%s : " fmt, \
90 #else /* (defined BCMDBG) */
91 #define WL_INFO(fmt, args...)
92 #define WL_TRACE(fmt, args...)
93 #define WL_SCAN(fmt, args...)
94 #define WL_CONN(fmt, args...)
95 #endif /* (defined BCMDBG) */
98 #define WL_SCAN_RETRY_MAX 3 /* used for ibss scan */
99 #define WL_NUM_SCAN_MAX 1
100 #define WL_NUM_PMKIDS_MAX MAXPMKID /* will be used
104 #define WL_SCAN_BUF_MAX (1024 * 8)
105 #define WL_TLV_INFO_MAX 1024
106 #define WL_BSS_INFO_MAX 2048
107 #define WL_ASSOC_INFO_MAX 512 /*
108 * needs to grab assoc info from dongle to
109 * report it to cfg80211 through "connect"
112 #define WL_IOCTL_LEN_MAX 1024
113 #define WL_EXTRA_BUF_MAX 2048
114 #define WL_ISCAN_BUF_MAX 2048 /*
115 * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
116 * to reduce iteration
118 #define WL_ISCAN_TIMER_INTERVAL_MS 3000
119 #define WL_SCAN_ERSULTS_LAST (WL_SCAN_RESULTS_NO_MEM+1)
120 #define WL_AP_MAX 256 /* virtually unlimitted as long
121 * as kernel memory allows
123 #define WL_FILE_NAME_MAX 256
125 #define WL_ROAM_TRIGGER_LEVEL -75
126 #define WL_ROAM_DELTA 20
127 #define WL_BEACON_TIMEOUT 3
129 #define WL_SCAN_CHANNEL_TIME 40
130 #define WL_SCAN_UNASSOC_TIME 40
131 #define WL_SCAN_PASSIVE_TIME 120
137 WL_STATUS_SCAN_ABORTING,
138 WL_STATUS_CONNECTING,
149 /* dongle profile list */
162 /* dongle iscan state */
163 enum wl_iscan_state {
165 WL_ISCAN_STATE_SCANING
168 /* fw downloading status */
171 WL_NVRAM_LOADING_DONE
174 /* beacon / probe_response */
175 struct beacon_proberesp {
180 } __attribute__ ((packed));
182 /* dongle configuration */
184 u32 mode; /* adhoc , infrastructure or ap */
190 struct ieee80211_channel channel;
193 /* cfg80211 main event loop */
194 struct wl_event_loop {
195 s32(*handler[WLC_E_LAST]) (struct wl_priv *wl,
196 struct net_device *ndev,
197 const wl_event_msg_t *e, void *data);
200 /* representing interface of cfg80211 plane */
206 void *driver_data; /* to store cfg80211 object information */
209 /* bss inform structure for cfg80211 interface */
210 struct wl_cfg80211_bss_info {
218 /* basic structure of scan request */
220 struct wlc_ssid ssid;
223 /* basic structure of information element */
226 u8 buf[WL_TLV_INFO_MAX];
229 /* event queue for cfg80211 main event */
231 struct list_head eq_list;
237 /* security information with currently associated ap */
246 /* ibss information for currently joined ibss network */
248 u8 beacon_interval; /* in millisecond */
249 u8 atim; /* in millisecond */
258 struct wlc_ssid ssid;
262 struct wl_security sec;
267 /* dongle iscan event loop */
268 struct wl_iscan_eloop {
269 s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl);
272 /* dongle iscan controller */
273 struct wl_iscan_ctrl {
274 struct net_device *dev;
275 struct timer_list timer;
279 struct task_struct *tsk;
280 struct semaphore sync;
281 struct wl_iscan_eloop el;
283 s8 ioctl_buf[WLC_IOCTL_SMLEN];
284 s8 scan_buf[WL_ISCAN_BUF_MAX];
287 /* association inform */
288 struct wl_connect_info {
295 /* firmware /nvram downloading controller */
297 const struct firmware *fw_entry;
298 unsigned long status;
300 s8 fw_name[WL_FILE_NAME_MAX];
301 s8 nvram_name[WL_FILE_NAME_MAX];
304 /* assoc ie length */
305 struct wl_assoc_ielen {
313 pmkid_t foo[MAXPMKID - 1];
316 /* dongle private data of cfg80211 interface */
318 struct wireless_dev *wdev; /* representing wl cfg80211 device */
319 struct wl_conf *conf; /* dongle configuration */
320 struct cfg80211_scan_request *scan_request; /* scan request
322 struct wl_event_loop el; /* main event loop */
323 struct list_head eq_list; /* used for event queue */
324 spinlock_t eq_lock; /* for event queue synchronization */
325 struct mutex usr_sync; /* maily for dongle up/down synchronization */
326 struct wl_scan_results *bss_list; /* bss_list holding scanned
328 struct wl_scan_results *scan_results;
329 struct wl_scan_req *scan_req_int; /* scan request object for
331 struct wl_cfg80211_bss_info *bss_info; /* bss information for
333 struct wl_ie ie; /* information element object for
335 struct semaphore event_sync; /* for synchronization of main event
337 struct wl_profile *profile; /* holding dongle profile */
338 struct wl_iscan_ctrl *iscan; /* iscan controller */
339 struct wl_connect_info conn_info; /* association information
341 struct wl_fw_ctrl *fw; /* control firwmare / nvram paramter
343 struct wl_pmk_list *pmk_list; /* wpa2 pmk list */
344 struct task_struct *event_tsk; /* task of main event handler thread */
345 unsigned long status; /* current dongle status */
347 u32 channel; /* current channel */
348 bool iscan_on; /* iscan on/off switch */
349 bool iscan_kickstart; /* indicate iscan already started */
350 bool active_scan; /* current scan mode */
351 bool ibss_starter; /* indicates this sta is ibss starter */
352 bool link_up; /* link/connection up flag */
353 bool pwr_save; /* indicate whether dongle to support
355 bool dongle_up; /* indicate whether dongle up or not */
356 bool roam_on; /* on/off switch for dongle self-roaming */
357 bool scan_tried; /* indicates if first scan attempted */
358 u8 *ioctl_buf; /* ioctl buffer */
359 u8 *extra_buf; /* maily to grab assoc information */
360 struct dentry *debugfsdir;
361 u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN)));
364 #define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy))
365 #define wl_to_wiphy(w) (w->wdev->wiphy)
366 #define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w)))
367 #define wl_to_wdev(w) (w->wdev)
368 #define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w)))
369 #define wl_to_ndev(w) (w->wdev->netdev)
370 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
371 #define ci_to_wl(c) (ci->wl)
372 #define wl_to_ci(w) (&w->ci)
373 #define wl_to_sr(w) (w->scan_req_int)
374 #define wl_to_ie(w) (&w->ie)
375 #define iscan_to_wl(i) ((struct wl_priv *)(i->data))
376 #define wl_to_iscan(w) (w->iscan)
377 #define wl_to_conn(w) (&w->conn_info)
379 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list,
380 struct wl_bss_info *bss)
383 (struct wl_bss_info *)((unsigned long)bss +
384 le32_to_cpu(bss->length)) :
388 #define for_each_bss(list, bss, __i) \
389 for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
391 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
392 extern void wl_cfg80211_detach(void);
393 /* event handler from dongle */
394 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
396 extern void wl_cfg80211_sdio_func(void *func); /* set sdio function info */
397 extern struct sdio_func *wl_cfg80211_get_sdio_func(void); /* set sdio function info */
398 extern s32 wl_cfg80211_up(void); /* dongle up */
399 extern s32 wl_cfg80211_down(void); /* dongle down */
400 extern void wl_cfg80211_dbg_level(u32 level); /* set dongle
402 extern void *wl_cfg80211_request_fw(s8 *file_name); /* request fw /nvram
404 extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size); /* read fw
406 extern void wl_cfg80211_release_fw(void); /* release fw */
407 extern s8 *wl_cfg80211_get_fwname(void); /* get firmware name for
409 extern s8 *wl_cfg80211_get_nvramname(void); /* get nvram name for
411 extern void wl_os_wd_timer(struct net_device *ndev, uint wdtick);
413 #endif /* _wl_cfg80211_h_ */