8116d63d56e6cf524416fd5d4039f58817701681
[linux-2.6.git] / drivers / net / wireless / bcmdhd / wl_cfg80211.h
1 /*
2  * Linux cfg80211 driver
3  *
4  * Copyright (C) 1999-2011, Broadcom Corporation
5  * 
6  *         Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  * 
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  * 
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id: wl_cfg80211.h,v 1.1.4.1.2.8 2011/02/09 01:37:52 Exp $
25  */
26
27 #ifndef _wl_cfg80211_h_
28 #define _wl_cfg80211_h_
29
30 #include <linux/wireless.h>
31 #include <typedefs.h>
32 #include <proto/ethernet.h>
33 #include <wlioctl.h>
34 #include <linux/wireless.h>
35 #include <net/cfg80211.h>
36 #include <linux/rfkill.h>
37
38 #include <wl_cfgp2p.h>
39
40 struct wl_conf;
41 struct wl_iface;
42 struct wl_priv;
43 struct wl_security;
44 struct wl_ibss;
45
46
47 #define htod32(i) i
48 #define htod16(i) i
49 #define dtoh32(i) i
50 #define dtoh16(i) i
51 #define htodchanspec(i) i
52 #define dtohchanspec(i) i
53
54 #define WL_DBG_NONE     0
55 #define WL_DBG_SCAN     (1 << 3)
56 #define WL_DBG_DBG      (1 << 2)
57 #define WL_DBG_INFO     (1 << 1)
58 #define WL_DBG_ERR      (1 << 0)
59 #define WL_DBG_MASK ((WL_DBG_DBG | WL_DBG_INFO | WL_DBG_ERR) << 1)
60
61 /* 0 invalidates all debug messages.  default is 1 */
62 #define WL_DBG_LEVEL 0xFF
63
64 #define WL_ERR(args)                                                                    \
65 do {                                                                            \
66         if (wl_dbg_level & WL_DBG_ERR) {                                \
67                         printk(KERN_ERR "CFG80211-ERROR) %s : ", __func__);     \
68                         printk args;                                            \
69                 }                                                               \
70 } while (0)
71 #define WL_INFO(args)                                                                   \
72 do {                                                                            \
73         if (wl_dbg_level & WL_DBG_INFO) {                               \
74                         printk(KERN_ERR "CFG80211-INFO) %s : ", __func__);      \
75                         printk args;                                            \
76                 }                                                               \
77 } while (0)
78 #define WL_SCAN(args)                                                           \
79 do {                                                                    \
80         if (wl_dbg_level & WL_DBG_SCAN) {                       \
81                 printk(KERN_ERR "CFG80211-SCAN) %s :", __func__);       \
82                 printk args;                                                    \
83         }                                                                       \
84 } while (0)
85 #if (WL_DBG_LEVEL > 0)
86 #define WL_DBG(args)                                                            \
87 do {                                                                    \
88         if (wl_dbg_level & WL_DBG_DBG) {                        \
89                 printk(KERN_ERR "CFG80211-DEBUG) %s :", __func__);      \
90                 printk args;                                                    \
91         }                                                                       \
92 } while (0)
93 #else                           /* !(WL_DBG_LEVEL > 0) */
94 #define WL_DBG(args)
95 #endif                          /* (WL_DBG_LEVEL > 0) */
96
97 #define WL_SCAN_RETRY_MAX       3       /* used for ibss scan */
98 #define WL_NUM_PMKIDS_MAX       MAXPMKID        /* will be used
99                                                  * for 2.6.33 kernel
100                                                  * or later
101                                                  */
102 #define WL_SCAN_BUF_MAX                 (1024 * 8)
103 #define WL_TLV_INFO_MAX                 1024
104 #define WL_SCAN_IE_LEN_MAX      2048
105 #define WL_BSS_INFO_MAX                 2048
106 #define WL_ASSOC_INFO_MAX       512     /*
107                                  * needs to grab assoc info from dongle to
108                                  * report it to cfg80211 through "connect"
109                                  * event
110                                  */
111 #define WL_IOCTL_LEN_MAX        1024
112 #define WL_EXTRA_BUF_MAX        2048
113 #define WL_ISCAN_BUF_MAX        2048    /*
114                                  * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
115                                  * to reduce iteration
116                                  */
117 #define WL_ISCAN_TIMER_INTERVAL_MS      3000
118 #define WL_SCAN_ERSULTS_LAST    (WL_SCAN_RESULTS_NO_MEM+1)
119 #define WL_AP_MAX       256     /* virtually unlimitted as long
120                                  * as kernel memory allows
121                                  */
122 #define WL_FILE_NAME_MAX                256
123 #define WL_DWELL_TIME   200
124 #define VWDEV_CNT 3
125 /* dongle status */
126 enum wl_status {
127         WL_STATUS_READY = 0,
128         WL_STATUS_SCANNING,
129         WL_STATUS_SCAN_ABORTING,
130         WL_STATUS_CONNECTING,
131         WL_STATUS_CONNECTED,
132         WL_STATUS_AP_CREATING,
133         WL_STATUS_AP_CREATED
134 };
135
136 /* wi-fi mode */
137 enum wl_mode {
138         WL_MODE_BSS,
139         WL_MODE_IBSS,
140         WL_MODE_AP
141 };
142
143 /* dongle profile list */
144 enum wl_prof_list {
145         WL_PROF_MODE,
146         WL_PROF_SSID,
147         WL_PROF_SEC,
148         WL_PROF_IBSS,
149         WL_PROF_BAND,
150         WL_PROF_BSSID,
151         WL_PROF_ACT,
152         WL_PROF_BEACONINT,
153         WL_PROF_DTIMPERIOD
154 };
155
156 /* dongle iscan state */
157 enum wl_iscan_state {
158         WL_ISCAN_STATE_IDLE,
159         WL_ISCAN_STATE_SCANING
160 };
161
162 /* donlge escan state */
163 enum wl_escan_state {
164     WL_ESCAN_STATE_IDLE,
165     WL_ESCAN_STATE_SCANING
166 };
167 /* fw downloading status */
168 enum wl_fw_status {
169         WL_FW_LOADING_DONE,
170         WL_NVRAM_LOADING_DONE
171 };
172
173 /* beacon / probe_response */
174 struct beacon_proberesp {
175         __le64 timestamp;
176         __le16 beacon_int;
177         __le16 capab_info;
178         u8 variable[0];
179 } __attribute__ ((packed));
180
181 /* dongle configuration */
182 struct wl_conf {
183         struct net_mode {
184                 struct net_device *ndev;
185                 s32 type;
186         } mode [VWDEV_CNT + 1];         /* adhoc , infrastructure or ap */
187         u32 frag_threshold;
188         u32 rts_threshold;
189         u32 retry_short;
190         u32 retry_long;
191         s32 tx_power;
192         struct ieee80211_channel channel;
193 };
194
195 typedef s32(*EVENT_HANDLER) (struct wl_priv *wl,
196                             struct net_device *ndev, const wl_event_msg_t *e, void *data);
197
198
199 /* bss inform structure for cfg80211 interface */
200 struct wl_cfg80211_bss_info {
201         u16 band;
202         u16 channel;
203         s16 rssi;
204         u16 frame_len;
205         u8 frame_buf[1];
206 };
207
208 /* basic structure of scan request */
209 struct wl_scan_req {
210         struct wlc_ssid ssid;
211 };
212
213 /* basic structure of information element */
214 struct wl_ie {
215         u16 offset;
216         u8 buf[WL_TLV_INFO_MAX];
217 };
218
219 /* event queue for cfg80211 main event */
220 struct wl_event_q {
221         struct list_head eq_list;
222         u32 etype;
223         wl_event_msg_t emsg;
224         s8 edata[1];
225 };
226
227 /* security information with currently associated ap */
228 struct wl_security {
229         u32 wpa_versions;
230         u32 auth_type;
231         u32 cipher_pairwise;
232         u32 cipher_group;
233         u32 wpa_auth;
234 };
235
236 /* ibss information for currently joined ibss network */
237 struct wl_ibss {
238         u8 beacon_interval;     /* in millisecond */
239         u8 atim;                /* in millisecond */
240         s8 join_only;
241         u8 band;
242         u8 channel;
243 };
244
245 /* dongle profile */
246 struct wl_profile {
247         u32 mode;
248         struct wlc_ssid ssid;
249         u8 bssid[ETHER_ADDR_LEN];
250         u16 beacon_interval;
251         u8 dtim_period;
252         struct wl_security sec;
253         struct wl_ibss ibss;
254         s32 band;
255         bool active;
256 };
257
258 typedef s32(*ISCAN_HANDLER) (struct wl_priv *wl);
259
260 /* dongle iscan controller */
261 struct wl_iscan_ctrl {
262         struct net_device *dev;
263         struct timer_list timer;
264         u32 timer_ms;
265         u32 timer_on;
266         s32 state;
267         struct task_struct *tsk;
268         struct semaphore sync;
269         ISCAN_HANDLER iscan_handler[WL_SCAN_ERSULTS_LAST];
270         void *data;
271         s8 ioctl_buf[WLC_IOCTL_SMLEN];
272         s8 scan_buf[WL_ISCAN_BUF_MAX];
273 };
274
275 /* association inform */
276 #define MAX_REQ_LINE 1024
277 struct wl_connect_info {
278         u8 req_ie[MAX_REQ_LINE];
279         s32 req_ie_len;
280         u8 resp_ie[MAX_REQ_LINE];
281         s32 resp_ie_len;
282 };
283
284 /* firmware /nvram downloading controller */
285 struct wl_fw_ctrl {
286         const struct firmware *fw_entry;
287         unsigned long status;
288         u32 ptr;
289         s8 fw_name[WL_FILE_NAME_MAX];
290         s8 nvram_name[WL_FILE_NAME_MAX];
291 };
292
293 /* assoc ie length */
294 struct wl_assoc_ielen {
295         u32 req_len;
296         u32 resp_len;
297 };
298
299 /* wpa2 pmk list */
300 struct wl_pmk_list {
301         pmkid_list_t pmkids;
302         pmkid_t foo[MAXPMKID - 1];
303 };
304
305
306 #define ESCAN_BUF_SIZE (64 * 1024)
307
308 struct escan_info {
309     u32 escan_state;
310     u8 escan_buf[ESCAN_BUF_SIZE];
311     struct wiphy *wiphy;
312 };
313
314 struct ap_info {
315 /* Structure to hold WPS, WPA IEs for a AP */
316         u8   probe_res_ie[IE_MAX_LEN];
317         u8   beacon_ie[IE_MAX_LEN];
318         u32 probe_res_ie_len;
319         u32 beacon_ie_len;
320         u8 *wpa_ie;
321         u8 *rsn_ie;
322         u8 *wps_ie;
323         bool security_mode;
324 };
325 /* dongle private data of cfg80211 interface */
326 struct wl_priv {
327         struct wireless_dev *wdev;      /* representing wl cfg80211 device */
328         struct wireless_dev *vwdev[VWDEV_CNT];
329         struct wl_conf *conf;   /* dongle configuration */
330         struct cfg80211_scan_request *scan_request;     /* scan request object */
331         EVENT_HANDLER evt_handler[WLC_E_LAST];
332         struct list_head eq_list;       /* used for event queue */
333         spinlock_t eq_lock;     /* for event queue synchronization */
334         struct mutex usr_sync;  /* maily for dongle up/down synchronization */
335         struct wl_scan_results *bss_list;
336         struct wl_scan_results *scan_results;
337
338         /* scan request object for internal purpose */
339         struct wl_scan_req *scan_req_int;
340
341         /* bss information for cfg80211 layer */
342         struct wl_cfg80211_bss_info *bss_info;
343         /* information element object for internal purpose */
344         struct wl_ie ie;
345         u8 scan_ie_buf[2048];
346         int scan_ie_len;
347         struct ether_addr bssid;        /* bssid of currently engaged network */
348
349         /* for synchronization of main event thread */
350         struct wl_profile *profile;     /* holding dongle profile */
351         struct wl_iscan_ctrl *iscan;    /* iscan controller */
352
353         /* association information container */
354         struct wl_connect_info conn_info;
355
356         /* control firwmare and nvram paramter downloading */
357         struct wl_fw_ctrl *fw;
358         struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
359         tsk_ctl_t event_tsk;            /* task of main event handler thread */
360         unsigned long status;           /* current dongle status */
361         void *pub;
362         u32 channel;            /* current channel */
363         bool iscan_on;          /* iscan on/off switch */
364         bool iscan_kickstart;   /* indicate iscan already started */
365         bool escan_on;      /* escan on/off switch */
366         struct escan_info escan_info;   /* escan information */
367         bool active_scan;       /* current scan mode */
368         bool ibss_starter;      /* indicates this sta is ibss starter */
369         bool link_up;           /* link/connection up flag */
370
371         /* indicate whether dongle to support power save mode */
372         bool pwr_save;
373         bool dongle_up;         /* indicate whether dongle up or not */
374         bool roam_on;           /* on/off switch for dongle self-roaming */
375         bool scan_tried;        /* indicates if first scan attempted */
376         u8 *ioctl_buf;  /* ioctl buffer */
377         u8 *escan_ioctl_buf;
378         u8 *extra_buf;  /* maily to grab assoc information */
379         struct dentry *debugfsdir;
380         struct rfkill *rfkill;
381         bool rf_blocked;
382         struct ieee80211_channel remain_on_chan;
383         enum nl80211_channel_type remain_on_chan_type;
384         u64 cache_cookie;
385         wait_queue_head_t dongle_event_wait;
386         struct ap_info *ap_info;
387         struct p2p_info *p2p;
388         bool p2p_supported;
389         s8 last_eventmask[WL_EVENTING_MASK_LEN];
390 };
391
392 #define wl_to_wiphy(w) (w->wdev->wiphy)
393 #define wl_to_prmry_ndev(w) (w->wdev->netdev)
394 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
395 #define wl_to_sr(w) (w->scan_req_int)
396 #define wl_to_ie(w) (&w->ie)
397 #define iscan_to_wl(i) ((struct wl_priv *)(i->data))
398 #define wl_to_iscan(w) (w->iscan)
399 #define wl_to_conn(w) (&w->conn_info)
400 #define wiphy_from_scan(w) (w->escan_info.wiphy)
401 #define wl_get_drv_status(wl, stat)   (test_bit(WL_STATUS_ ## stat, &(wl)->status))
402 #define wl_set_drv_status(wl, stat)   (set_bit(WL_STATUS_ ## stat, &(wl)->status))
403 #define wl_clr_drv_status(wl, stat)   (clear_bit(WL_STATUS_ ## stat, &(wl)->status))
404 #define wl_chg_drv_status(wl, stat)   (change_bit(WL_STATUS_ ## stat, &(wl)->status))
405
406 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
407 {
408         return bss = bss ?
409                 (struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
410 }
411 static inline s32 alloc_idx_vwdev(struct wl_priv *wl)
412 {
413         s32 i = 0;
414         for (i = 0; i < VWDEV_CNT; i++) {
415                 if (wl->vwdev[i] == NULL)
416                                 return i;
417         }
418         return -1;
419 }
420
421 static inline s32 get_idx_vwdev_by_netdev(struct wl_priv *wl, struct net_device *ndev)
422 {
423         s32 i = 0;
424         for (i = 0; i < VWDEV_CNT; i++) {
425                 if ((wl->vwdev[i] != NULL) && (wl->vwdev[i]->netdev == ndev))
426                                 return i;
427         }
428         return -1;
429 }
430
431 static inline s32 get_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev)
432 {
433         s32 i = 0;
434         for (i = 0; i <= VWDEV_CNT; i++) {
435                 if (wl->conf->mode[i].ndev != NULL && (wl->conf->mode[i].ndev == ndev))
436                         return wl->conf->mode[i].type;
437         }
438         return -1;
439 }
440 static inline void set_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev, s32 type)
441 {
442         s32 i = 0;
443         for (i = 0; i <= VWDEV_CNT; i++) {
444                 if (type == -1) {
445                         /* free the info of netdev */
446                         if (wl->conf->mode[i].ndev == ndev) {
447                                 wl->conf->mode[i].ndev = NULL;
448                                 wl->conf->mode[i].type = -1;
449                                 break;
450                         }
451
452                 } else {
453                         if ((wl->conf->mode[i].ndev != NULL)&&
454                         (wl->conf->mode[i].ndev == ndev)) {
455                                 /* update type of ndev */
456                                 wl->conf->mode[i].type = type;
457                                 break;
458                         }
459                         else if ((wl->conf->mode[i].ndev == NULL)&&
460                         (wl->conf->mode[i].type == -1)) {
461                                 wl->conf->mode[i].ndev = ndev;
462                                 wl->conf->mode[i].type = type;
463                                 break;
464                         }
465                 }
466         }
467 }
468 #define free_vwdev_by_index(wl, __i) do {      \
469                                                 if (wl->vwdev[__i] != NULL) \
470                                                         kfree(wl->vwdev[__i]); \
471                                                 wl->vwdev[__i] = NULL; \
472                                         } while (0)
473
474 #define for_each_bss(list, bss, __i)    \
475         for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
476
477 /* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0.
478  * In addtion to that, wpa_version is WPA_VERSION_1
479  */
480 #define is_wps_conn(_sme) \
481         ((_sme->crypto.wpa_versions & NL80211_WPA_VERSION_1) && \
482          (!_sme->crypto.n_ciphers_pairwise) && \
483          (!_sme->crypto.cipher_group))
484 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
485 extern s32 wl_cfg80211_attach_post(struct net_device *ndev);
486 extern void wl_cfg80211_detach(void);
487 /* event handler from dongle */
488 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
489             void *data);
490 extern void wl_cfg80211_set_sdio_func(void *func);      /* set sdio function info */
491 extern struct sdio_func *wl_cfg80211_get_sdio_func(void);       /* set sdio function info */
492 extern s32 wl_cfg80211_up(void);        /* dongle up */
493 extern s32 wl_cfg80211_down(void);      /* dongle down */
494 extern s32 wl_cfg80211_notify_ifadd(struct net_device *net, s32 idx, s32 bssidx,
495 int (*_net_attach)(dhd_pub_t *dhdp, int ifidx));
496 extern s32 wl_cfg80211_ifdel_ops(struct net_device *net);
497 extern s32 wl_cfg80211_notify_ifdel(struct net_device *net);
498 extern s32 wl_cfg80211_is_progress_ifadd(void);
499 extern s32 wl_cfg80211_is_progress_ifchange(void);
500 extern s32 wl_cfg80211_is_progress_ifadd(void);
501 extern s32 wl_cfg80211_notify_ifchange(void);
502 extern void wl_cfg80211_dbg_level(u32 level);
503 extern void *wl_cfg80211_request_fw(s8 *file_name);
504 extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size);
505 extern void wl_cfg80211_release_fw(void);
506 extern s8 *wl_cfg80211_get_fwname(void);
507 extern s8 *wl_cfg80211_get_nvramname(void);
508 extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
509 #ifdef CONFIG_SYSCTL
510 extern s32 wl_cfg80211_sysctl_export_devaddr(void *data);
511 #endif
512
513 /* do scan abort */
514 extern s32
515 wl_cfg80211_scan_abort(struct wl_priv *wl, struct net_device *ndev);
516
517 extern s32
518 wl_cfg80211_if_is_group_owner(void);
519 #endif                          /* _wl_cfg80211_h_ */