Initial commit
[kernel/linux-3.0.git] / drivers / staging / brcm80211 / brcmfmac / wl_cfg80211.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
17 #ifndef _wl_cfg80211_h_
18 #define _wl_cfg80211_h_
19
20 #include <linux/wireless.h>
21 #include <linux/wireless.h>
22 #include <net/cfg80211.h>
23 #include <wlioctl.h>
24
25 struct wl_conf;
26 struct wl_iface;
27 struct wl_priv;
28 struct wl_security;
29 struct wl_ibss;
30
31 #define WL_DBG_NONE             0
32 #define WL_DBG_CONN             (1 << 5)
33 #define WL_DBG_SCAN             (1 << 4)
34 #define WL_DBG_TRACE            (1 << 3)
35 #define WL_DBG_INFO             (1 << 1)
36 #define WL_DBG_ERR              (1 << 0)
37 #define WL_DBG_MASK             ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
38                                 (WL_DBG_SCAN) | (WL_DBG_CONN))
39
40 #define WL_ERR(fmt, args...)                                    \
41 do {                                                            \
42         if (wl_dbg_level & WL_DBG_ERR) {                        \
43                 if (net_ratelimit()) {                          \
44                         printk(KERN_ERR "ERROR @%s : " fmt,     \
45                                 __func__, ##args);              \
46                 }                                               \
47         }                                                       \
48 } while (0)
49
50 #if (defined BCMDBG)
51 #define WL_INFO(fmt, args...)                                   \
52 do {                                                            \
53         if (wl_dbg_level & WL_DBG_INFO) {                       \
54                 if (net_ratelimit()) {                          \
55                         printk(KERN_ERR "INFO @%s : " fmt,      \
56                                 __func__, ##args);              \
57                 }                                               \
58         }                                                       \
59 } while (0)
60
61 #define WL_TRACE(fmt, args...)                                  \
62 do {                                                            \
63         if (wl_dbg_level & WL_DBG_TRACE) {                      \
64                 if (net_ratelimit()) {                          \
65                         printk(KERN_ERR "TRACE @%s : " fmt,     \
66                                 __func__, ##args);              \
67                 }                                               \
68         }                                                       \
69 } while (0)
70
71 #define WL_SCAN(fmt, args...)                                   \
72 do {                                                            \
73         if (wl_dbg_level & WL_DBG_SCAN) {                       \
74                 if (net_ratelimit()) {                          \
75                         printk(KERN_ERR "SCAN @%s : " fmt,      \
76                                 __func__, ##args);              \
77                 }                                               \
78         }                                                       \
79 } while (0)
80
81 #define WL_CONN(fmt, args...)                                   \
82 do {                                                            \
83         if (wl_dbg_level & WL_DBG_CONN) {                       \
84                 if (net_ratelimit()) {                          \
85                         printk(KERN_ERR "CONN @%s : " fmt,      \
86                                 __func__, ##args);              \
87                 }                                               \
88         }                                                       \
89 } while (0)
90
91 #else /* (defined BCMDBG) */
92 #define WL_INFO(fmt, args...)
93 #define WL_TRACE(fmt, args...)
94 #define WL_SCAN(fmt, args...)
95 #define WL_CONN(fmt, args...)
96 #endif /* (defined BCMDBG) */
97
98
99 #define WL_SCAN_RETRY_MAX       3       /* used for ibss scan */
100 #define WL_NUM_SCAN_MAX         1
101 #define WL_NUM_PMKIDS_MAX       MAXPMKID        /* will be used
102                                                  * for 2.6.33 kernel
103                                                  * or later
104                                                  */
105 #define WL_SCAN_BUF_MAX                 (1024 * 8)
106 #define WL_TLV_INFO_MAX                 1024
107 #define WL_BSS_INFO_MAX                 2048
108 #define WL_ASSOC_INFO_MAX       512     /*
109                                  * needs to grab assoc info from dongle to
110                                  * report it to cfg80211 through "connect"
111                                  * event
112                                  */
113 #define WL_IOCTL_LEN_MAX        1024
114 #define WL_EXTRA_BUF_MAX        2048
115 #define WL_ISCAN_BUF_MAX        2048    /*
116                                  * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
117                                  * to reduce iteration
118                                  */
119 #define WL_ISCAN_TIMER_INTERVAL_MS      3000
120 #define WL_SCAN_ERSULTS_LAST    (WL_SCAN_RESULTS_NO_MEM+1)
121 #define WL_AP_MAX       256     /* virtually unlimitted as long
122                                  * as kernel memory allows
123                                  */
124 #define WL_FILE_NAME_MAX                256
125
126 #define WL_ROAM_TRIGGER_LEVEL           -75
127 #define WL_ROAM_DELTA                   20
128 #define WL_BEACON_TIMEOUT               3
129
130 #define WL_SCAN_CHANNEL_TIME            40
131 #define WL_SCAN_UNASSOC_TIME            40
132 #define WL_SCAN_PASSIVE_TIME            120
133
134 /* dongle status */
135 enum wl_status {
136         WL_STATUS_READY,
137         WL_STATUS_SCANNING,
138         WL_STATUS_SCAN_ABORTING,
139         WL_STATUS_CONNECTING,
140         WL_STATUS_CONNECTED
141 };
142
143 /* wi-fi mode */
144 enum wl_mode {
145         WL_MODE_BSS,
146         WL_MODE_IBSS,
147         WL_MODE_AP
148 };
149
150 /* dongle profile list */
151 enum wl_prof_list {
152         WL_PROF_MODE,
153         WL_PROF_SSID,
154         WL_PROF_SEC,
155         WL_PROF_IBSS,
156         WL_PROF_BAND,
157         WL_PROF_BSSID,
158         WL_PROF_ACT,
159         WL_PROF_BEACONINT,
160         WL_PROF_DTIMPERIOD
161 };
162
163 /* dongle iscan state */
164 enum wl_iscan_state {
165         WL_ISCAN_STATE_IDLE,
166         WL_ISCAN_STATE_SCANING
167 };
168
169 /* fw downloading status */
170 enum wl_fw_status {
171         WL_FW_LOADING_DONE,
172         WL_NVRAM_LOADING_DONE
173 };
174
175 /* beacon / probe_response */
176 struct beacon_proberesp {
177         __le64 timestamp;
178         __le16 beacon_int;
179         __le16 capab_info;
180         u8 variable[0];
181 } __attribute__ ((packed));
182
183 /* dongle configuration */
184 struct wl_conf {
185         u32 mode;               /* adhoc , infrastructure or ap */
186         u32 frag_threshold;
187         u32 rts_threshold;
188         u32 retry_short;
189         u32 retry_long;
190         s32 tx_power;
191         struct ieee80211_channel channel;
192 };
193
194 /* cfg80211 main event loop */
195 struct wl_event_loop {
196         s32(*handler[WLC_E_LAST]) (struct wl_priv *wl,
197                                      struct net_device *ndev,
198                                      const wl_event_msg_t *e, void *data);
199 };
200
201 /* representing interface of cfg80211 plane */
202 struct wl_iface {
203         struct wl_priv *wl;
204 };
205
206 struct wl_dev {
207         void *driver_data;      /* to store cfg80211 object information */
208 };
209
210 /* bss inform structure for cfg80211 interface */
211 struct wl_cfg80211_bss_info {
212         u16 band;
213         u16 channel;
214         s16 rssi;
215         u16 frame_len;
216         u8 frame_buf[1];
217 };
218
219 /* basic structure of scan request */
220 struct wl_scan_req {
221         struct wlc_ssid ssid;
222 };
223
224 /* basic structure of information element */
225 struct wl_ie {
226         u16 offset;
227         u8 buf[WL_TLV_INFO_MAX];
228 };
229
230 /* event queue for cfg80211 main event */
231 struct wl_event_q {
232         struct list_head eq_list;
233         u32 etype;
234         wl_event_msg_t emsg;
235         s8 edata[1];
236 };
237
238 /* security information with currently associated ap */
239 struct wl_security {
240         u32 wpa_versions;
241         u32 auth_type;
242         u32 cipher_pairwise;
243         u32 cipher_group;
244         u32 wpa_auth;
245 };
246
247 /* ibss information for currently joined ibss network */
248 struct wl_ibss {
249         u8 beacon_interval;     /* in millisecond */
250         u8 atim;                /* in millisecond */
251         s8 join_only;
252         u8 band;
253         u8 channel;
254 };
255
256 /* dongle profile */
257 struct wl_profile {
258         u32 mode;
259         struct wlc_ssid ssid;
260         u8 bssid[ETH_ALEN];
261         u16 beacon_interval;
262         u8 dtim_period;
263         struct wl_security sec;
264         struct wl_ibss ibss;
265         s32 band;
266 };
267
268 /* dongle iscan event loop */
269 struct wl_iscan_eloop {
270         s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl);
271 };
272
273 /* dongle iscan controller */
274 struct wl_iscan_ctrl {
275         struct net_device *dev;
276         struct timer_list timer;
277         u32 timer_ms;
278         u32 timer_on;
279         s32 state;
280         struct task_struct *tsk;
281         struct semaphore sync;
282         struct wl_iscan_eloop el;
283         void *data;
284         s8 ioctl_buf[WLC_IOCTL_SMLEN];
285         s8 scan_buf[WL_ISCAN_BUF_MAX];
286 };
287
288 /* association inform */
289 struct wl_connect_info {
290         u8 *req_ie;
291         s32 req_ie_len;
292         u8 *resp_ie;
293         s32 resp_ie_len;
294 };
295
296 /* firmware /nvram downloading controller */
297 struct wl_fw_ctrl {
298         const struct firmware *fw_entry;
299         unsigned long status;
300         u32 ptr;
301         s8 fw_name[WL_FILE_NAME_MAX];
302         s8 nvram_name[WL_FILE_NAME_MAX];
303 };
304
305 /* assoc ie length */
306 struct wl_assoc_ielen {
307         u32 req_len;
308         u32 resp_len;
309 };
310
311 /* wpa2 pmk list */
312 struct wl_pmk_list {
313         pmkid_list_t pmkids;
314         pmkid_t foo[MAXPMKID - 1];
315 };
316
317 /* dongle private data of cfg80211 interface */
318 struct wl_priv {
319         struct wireless_dev *wdev;      /* representing wl cfg80211 device */
320         struct wl_conf *conf;   /* dongle configuration */
321         struct cfg80211_scan_request *scan_request;     /* scan request
322                                                          object */
323         struct wl_event_loop el;        /* main event loop */
324         struct list_head eq_list;       /* used for event queue */
325         spinlock_t eq_lock;     /* for event queue synchronization */
326         struct mutex usr_sync;  /* maily for dongle up/down synchronization */
327         struct wl_scan_results *bss_list;       /* bss_list holding scanned
328                                                  ap information */
329         struct wl_scan_results *scan_results;
330         struct wl_scan_req *scan_req_int;       /* scan request object for
331                                                  internal purpose */
332         struct wl_cfg80211_bss_info *bss_info;  /* bss information for
333                                                  cfg80211 layer */
334         struct wl_ie ie;        /* information element object for
335                                          internal purpose */
336         struct semaphore event_sync;    /* for synchronization of main event
337                                          thread */
338         struct wl_profile *profile;     /* holding dongle profile */
339         struct wl_iscan_ctrl *iscan;    /* iscan controller */
340         struct wl_connect_info conn_info;       /* association information
341                                                  container */
342         struct wl_fw_ctrl *fw;  /* control firwmare / nvram paramter
343                                  downloading */
344         struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
345         struct task_struct *event_tsk;  /* task of main event handler thread */
346         unsigned long status;           /* current dongle status */
347         void *pub;
348         u32 channel;            /* current channel */
349         bool iscan_on;          /* iscan on/off switch */
350         bool iscan_kickstart;   /* indicate iscan already started */
351         bool active_scan;       /* current scan mode */
352         bool ibss_starter;      /* indicates this sta is ibss starter */
353         bool link_up;           /* link/connection up flag */
354         bool pwr_save;          /* indicate whether dongle to support
355                                          power save mode */
356         bool dongle_up;         /* indicate whether dongle up or not */
357         bool roam_on;           /* on/off switch for dongle self-roaming */
358         bool scan_tried;        /* indicates if first scan attempted */
359         u8 *ioctl_buf;  /* ioctl buffer */
360         u8 *extra_buf;  /* maily to grab assoc information */
361         struct dentry *debugfsdir;
362         u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN)));
363 };
364
365 #define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy))
366 #define wl_to_wiphy(w) (w->wdev->wiphy)
367 #define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w)))
368 #define wl_to_wdev(w) (w->wdev)
369 #define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w)))
370 #define wl_to_ndev(w) (w->wdev->netdev)
371 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
372 #define ci_to_wl(c) (ci->wl)
373 #define wl_to_ci(w) (&w->ci)
374 #define wl_to_sr(w) (w->scan_req_int)
375 #define wl_to_ie(w) (&w->ie)
376 #define iscan_to_wl(i) ((struct wl_priv *)(i->data))
377 #define wl_to_iscan(w) (w->iscan)
378 #define wl_to_conn(w) (&w->conn_info)
379
380 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list,
381                                            struct wl_bss_info *bss)
382 {
383         return bss = bss ?
384                 (struct wl_bss_info *)((unsigned long)bss +
385                                        le32_to_cpu(bss->length)) :
386                 list->bss_info;
387 }
388
389 #define for_each_bss(list, bss, __i)    \
390         for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
391
392 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
393 extern void wl_cfg80211_detach(void);
394 /* event handler from dongle */
395 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
396                               void *data);
397 extern void wl_cfg80211_sdio_func(void *func);  /* set sdio function info */
398 extern struct sdio_func *wl_cfg80211_get_sdio_func(void);       /* set sdio function info */
399 extern s32 wl_cfg80211_up(void);        /* dongle up */
400 extern s32 wl_cfg80211_down(void);      /* dongle down */
401 extern void wl_cfg80211_dbg_level(u32 level);   /* set dongle
402                                                          debugging level */
403 extern void *wl_cfg80211_request_fw(s8 *file_name);     /* request fw /nvram
404                                                          downloading */
405 extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size);      /* read fw
406                                                                  image */
407 extern void wl_cfg80211_release_fw(void);       /* release fw */
408 extern s8 *wl_cfg80211_get_fwname(void);        /* get firmware name for
409                                                  the dongle */
410 extern s8 *wl_cfg80211_get_nvramname(void);     /* get nvram name for
411                                                  the dongle */
412 extern void wl_os_wd_timer(struct net_device *ndev, uint wdtick);
413
414 #endif                          /* _wl_cfg80211_h_ */