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