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