]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/net/wireless/bcmdhd/wl_cfg80211.h
bcmdhd: ensure work completion before freeing
[sojka/nv-tegra/linux-3.10.git] / drivers / net / wireless / bcmdhd / wl_cfg80211.h
1 /*
2  * Linux cfg80211 driver
3  *
4  * Copyright (C) 1999-2013, 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 431563 2013-10-24 01:50:16Z $
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 <linux/workqueue.h>
36 #include <net/cfg80211.h>
37 #include <linux/rfkill.h>
38
39 #include <wl_cfgp2p.h>
40
41 struct wl_conf;
42 struct wl_iface;
43 struct wl_priv;
44 struct wl_security;
45 struct wl_ibss;
46
47
48 #define htod32(i) i
49 #define htod16(i) i
50 #define dtoh32(i) i
51 #define dtoh16(i) i
52 #define htodchanspec(i) i
53 #define dtohchanspec(i) i
54
55 #define WL_DBG_NONE     0
56 #define WL_DBG_P2P_ACTION (1 << 5)
57 #define WL_DBG_TRACE    (1 << 4)
58 #define WL_DBG_SCAN     (1 << 3)
59 #define WL_DBG_DBG      (1 << 2)
60 #define WL_DBG_INFO     (1 << 1)
61 #define WL_DBG_ERR      (1 << 0)
62
63 /* 0 invalidates all debug messages.  default is 1 */
64 #define WL_DBG_LEVEL 0xFF
65
66 #define CFG80211_ERROR_TEXT             "CFG80211-ERROR) "
67
68 #if defined(DHD_DEBUG)
69 #define WL_ERR(args)                                                                    \
70 do {                                                                            \
71         if (wl_dbg_level & WL_DBG_ERR) {                                \
72                         printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);        \
73                         printk args;                                            \
74                 }                                                               \
75 } while (0)
76 #else /* defined(DHD_DEBUG) */
77 #define WL_ERR(args)                                                                    \
78 do {                                                                            \
79         if ((wl_dbg_level & WL_DBG_ERR) && net_ratelimit()) {                           \
80                         printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);        \
81                         printk args;                                            \
82                 }                                                               \
83 } while (0)
84 #endif /* defined(DHD_DEBUG) */
85
86 #ifdef WL_INFO
87 #undef WL_INFO
88 #endif
89 #define WL_INFO(args)                                                                   \
90 do {                                                                            \
91         if (wl_dbg_level & WL_DBG_INFO) {                               \
92                         printk(KERN_INFO "CFG80211-INFO) %s : ", __func__);     \
93                         printk args;                                            \
94                 }                                                               \
95 } while (0)
96 #ifdef WL_SCAN
97 #undef WL_SCAN
98 #endif
99 #define WL_SCAN(args)                                                           \
100 do {                                                                    \
101         if (wl_dbg_level & WL_DBG_SCAN) {                       \
102                 printk(KERN_INFO "CFG80211-SCAN) %s :", __func__);      \
103                 printk args;                                                    \
104         }                                                                       \
105 } while (0)
106 #ifdef WL_TRACE
107 #undef WL_TRACE
108 #endif
109 #define WL_TRACE(args)                                                          \
110 do {                                                                    \
111         if (wl_dbg_level & WL_DBG_TRACE) {                      \
112                 printk(KERN_INFO "CFG80211-TRACE) %s :", __func__);     \
113                 printk args;                                                    \
114         }                                                                       \
115 } while (0)
116 #ifdef WL_TRACE_HW4
117 #undef WL_TRACE_HW4
118 #endif
119 #define WL_TRACE_HW4                    WL_TRACE
120 #if (WL_DBG_LEVEL > 0)
121 #define WL_DBG(args)                                                            \
122 do {                                                                    \
123         if (wl_dbg_level & WL_DBG_DBG) {                        \
124                 printk(KERN_DEBUG "CFG80211-DEBUG) %s :", __func__);    \
125                 printk args;                                                    \
126         }                                                                       \
127 } while (0)
128 #else                           /* !(WL_DBG_LEVEL > 0) */
129 #define WL_DBG(args)
130 #endif                          /* (WL_DBG_LEVEL > 0) */
131 #define WL_PNO(x)
132 #define WL_SD(x)
133
134
135 #define WL_SCAN_RETRY_MAX       3
136 #define WL_NUM_PMKIDS_MAX       MAXPMKID
137 #define WL_SCAN_BUF_MAX         (1024 * 8)
138 #define WL_TLV_INFO_MAX         1500
139 #define WL_SCAN_IE_LEN_MAX      2048
140 #define WL_BSS_INFO_MAX         2048
141 #define WL_ASSOC_INFO_MAX       512
142 #define WL_IOCTL_LEN_MAX        2048
143 #define WL_EXTRA_BUF_MAX        2048
144 #define WL_ISCAN_BUF_MAX        2048
145 #define WL_ISCAN_TIMER_INTERVAL_MS      3000
146 #define WL_SCAN_ERSULTS_LAST    (WL_SCAN_RESULTS_NO_MEM+1)
147 #define WL_AP_MAX               256
148 #define WL_FILE_NAME_MAX        256
149 #define WL_DWELL_TIME           200
150 #define WL_MED_DWELL_TIME       400
151 #define WL_MIN_DWELL_TIME       100
152 #define WL_LONG_DWELL_TIME      1000
153 #define IFACE_MAX_CNT           2
154 #define WL_SCAN_CONNECT_DWELL_TIME_MS           200
155 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS          20
156 #define WL_SCAN_JOIN_ACTIVE_DWELL_TIME_MS       320
157 #define WL_SCAN_JOIN_PASSIVE_DWELL_TIME_MS      400
158 #define WL_AF_TX_MAX_RETRY      5
159
160 #define WL_AF_SEARCH_TIME_MAX           450
161 #define WL_AF_TX_EXTRA_TIME_MAX         200
162
163 #define WL_SCAN_TIMER_INTERVAL_MS       10000 /* Scan timeout */
164 #define WL_CHANNEL_SYNC_RETRY   5
165 #define WL_INVALID              -1
166
167 /* Bring down SCB Timeout to 20secs from 60secs default */
168 #ifndef WL_SCB_TIMEOUT
169 #define WL_SCB_TIMEOUT 20
170 #endif
171
172 /* SCAN_SUPPRESS timer values in ms */
173 #define WL_SCAN_SUPPRESS_TIMEOUT 31000 /* default Framwork DHCP timeout is 30 sec */
174 #define WL_SCAN_SUPPRESS_RETRY 3000
175
176 #define WL_PM_ENABLE_TIMEOUT 10000
177
178 /* driver status */
179 enum wl_status {
180         WL_STATUS_READY = 0,
181         WL_STATUS_SCANNING,
182         WL_STATUS_SCAN_ABORTING,
183         WL_STATUS_CONNECTING,
184         WL_STATUS_CONNECTED,
185         WL_STATUS_DISCONNECTING,
186         WL_STATUS_AP_CREATING,
187         WL_STATUS_AP_CREATED,
188         /* whole sending action frame procedure:
189          * includes a) 'finding common channel' for public action request frame
190          * and b) 'sending af via 'actframe' iovar'
191          */
192         WL_STATUS_SENDING_ACT_FRM,
193         /* find a peer to go to a common channel before sending public action req frame */
194         WL_STATUS_FINDING_COMMON_CHANNEL,
195         /* waiting for next af to sync time of supplicant.
196          * it includes SENDING_ACT_FRM and WAITING_NEXT_ACT_FRM_LISTEN
197          */
198         WL_STATUS_WAITING_NEXT_ACT_FRM,
199 #ifdef WL_CFG80211_SYNC_GON
200         /* go to listen state to wait for next af after SENDING_ACT_FRM */
201         WL_STATUS_WAITING_NEXT_ACT_FRM_LISTEN,
202 #endif /* WL_CFG80211_SYNC_GON */
203         /* it will be set when upper layer requests listen and succeed in setting listen mode.
204          * if set, other scan request can abort current listen state
205          */
206         WL_STATUS_REMAINING_ON_CHANNEL,
207 #ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
208         /* it's fake listen state to keep current scan state.
209          * it will be set when upper layer requests listen but scan is running. then just run
210          * a expire timer without actual listen state.
211          * if set, other scan request does not need to abort scan.
212          */
213         WL_STATUS_FAKE_REMAINING_ON_CHANNEL
214 #endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
215 };
216
217 /* wi-fi mode */
218 enum wl_mode {
219         WL_MODE_BSS,
220         WL_MODE_IBSS,
221         WL_MODE_AP
222 };
223
224 /* driver profile list */
225 enum wl_prof_list {
226         WL_PROF_MODE,
227         WL_PROF_SSID,
228         WL_PROF_SEC,
229         WL_PROF_IBSS,
230         WL_PROF_BAND,
231         WL_PROF_CHAN,
232         WL_PROF_BSSID,
233         WL_PROF_ACT,
234         WL_PROF_BEACONINT,
235         WL_PROF_DTIMPERIOD
236 };
237
238 /* driver iscan state */
239 enum wl_iscan_state {
240         WL_ISCAN_STATE_IDLE,
241         WL_ISCAN_STATE_SCANING
242 };
243
244 /* donlge escan state */
245 enum wl_escan_state {
246     WL_ESCAN_STATE_IDLE,
247     WL_ESCAN_STATE_SCANING
248 };
249 /* fw downloading status */
250 enum wl_fw_status {
251         WL_FW_LOADING_DONE,
252         WL_NVRAM_LOADING_DONE
253 };
254
255 enum wl_management_type {
256         WL_BEACON = 0x1,
257         WL_PROBE_RESP = 0x2,
258         WL_ASSOC_RESP = 0x4
259 };
260
261 enum wl_handler_del_type {
262         WL_HANDLER_NOTUSE,
263         WL_HANDLER_DEL,
264         WL_HANDLER_MAINTAIN,
265         WL_HANDLER_PEND
266 };
267
268 /* beacon / probe_response */
269 struct beacon_proberesp {
270         __le64 timestamp;
271         __le16 beacon_int;
272         __le16 capab_info;
273         u8 variable[0];
274 } __attribute__ ((packed));
275
276 /* driver configuration */
277 struct wl_conf {
278         u32 frag_threshold;
279         u32 rts_threshold;
280         u32 retry_short;
281         u32 retry_long;
282         s32 tx_power;
283         struct ieee80211_channel channel;
284 };
285
286 typedef s32(*EVENT_HANDLER) (struct wl_priv *wl, bcm_struct_cfgdev *cfgdev,
287                             const wl_event_msg_t *e, void *data);
288
289 /* bss inform structure for cfg80211 interface */
290 struct wl_cfg80211_bss_info {
291         u16 band;
292         u16 channel;
293         s16 rssi;
294         u16 frame_len;
295         u8 frame_buf[1];
296 };
297
298 /* basic structure of scan request */
299 struct wl_scan_req {
300         struct wlc_ssid ssid;
301 };
302
303 /* basic structure of information element */
304 struct wl_ie {
305         u16 offset;
306         u8 buf[WL_TLV_INFO_MAX];
307 };
308
309 /* event queue for cfg80211 main event */
310 struct wl_event_q {
311         struct list_head eq_list;
312         u32 etype;
313         wl_event_msg_t emsg;
314         s8 edata[1];
315 };
316
317 /* security information with currently associated ap */
318 struct wl_security {
319         u32 wpa_versions;
320         u32 auth_type;
321         u32 cipher_pairwise;
322         u32 cipher_group;
323         u32 wpa_auth;
324         u32 auth_assoc_res_status;
325 };
326
327 /* ibss information for currently joined ibss network */
328 struct wl_ibss {
329         u8 beacon_interval;     /* in millisecond */
330         u8 atim;                /* in millisecond */
331         s8 join_only;
332         u8 band;
333         u8 channel;
334 };
335
336 /* wl driver profile */
337 struct wl_profile {
338         u32 mode;
339         s32 band;
340         u32 channel;
341         struct wlc_ssid ssid;
342         struct wl_security sec;
343         struct wl_ibss ibss;
344         u8 bssid[ETHER_ADDR_LEN];
345         u16 beacon_interval;
346         u8 dtim_period;
347         bool active;
348 };
349
350 struct net_info {
351         struct net_device *ndev;
352         struct wireless_dev *wdev;
353         struct wl_profile profile;
354         s32 mode;
355         s32 roam_off;
356         unsigned long sme_state;
357         bool pm_restore;
358         bool pm_block;
359         s32 pm;
360         struct list_head list; /* list of all net_info structure */
361 };
362 typedef s32(*ISCAN_HANDLER) (struct wl_priv *wl);
363
364 /* iscan controller */
365 struct wl_iscan_ctrl {
366         struct net_device *dev;
367         struct timer_list timer;
368         u32 timer_ms;
369         u32 timer_on;
370         s32 state;
371         struct task_struct *tsk;
372         struct semaphore sync;
373         ISCAN_HANDLER iscan_handler[WL_SCAN_ERSULTS_LAST];
374         void *data;
375         s8 ioctl_buf[WLC_IOCTL_SMLEN];
376         s8 scan_buf[WL_ISCAN_BUF_MAX];
377 };
378
379 /* association inform */
380 #define MAX_REQ_LINE 1024
381 struct wl_connect_info {
382         u8 req_ie[MAX_REQ_LINE];
383         s32 req_ie_len;
384         u8 resp_ie[MAX_REQ_LINE];
385         s32 resp_ie_len;
386 };
387
388 /* firmware /nvram downloading controller */
389 struct wl_fw_ctrl {
390         const struct firmware *fw_entry;
391         unsigned long status;
392         u32 ptr;
393         s8 fw_name[WL_FILE_NAME_MAX];
394         s8 nvram_name[WL_FILE_NAME_MAX];
395 };
396
397 /* assoc ie length */
398 struct wl_assoc_ielen {
399         u32 req_len;
400         u32 resp_len;
401 };
402
403 /* wpa2 pmk list */
404 struct wl_pmk_list {
405         pmkid_list_t pmkids;
406         pmkid_t foo[MAXPMKID - 1];
407 };
408
409
410 #define ESCAN_BUF_SIZE (64 * 1024)
411
412 struct escan_info {
413         u32 escan_state;
414 #if defined(STATIC_WL_PRIV_STRUCT)
415 #ifndef CONFIG_DHD_USE_STATIC_BUF
416 #error STATIC_WL_PRIV_STRUCT should be used with CONFIG_DHD_USE_STATIC_BUF
417 #endif /* CONFIG_DHD_USE_STATIC_BUF */
418         u8 *escan_buf;
419 #else
420         u8 escan_buf[ESCAN_BUF_SIZE];
421 #endif /* STATIC_WL_PRIV_STRUCT */
422         struct wiphy *wiphy;
423         struct net_device *ndev;
424 };
425
426 struct ap_info {
427 /* Structure to hold WPS, WPA IEs for a AP */
428         u8   probe_res_ie[VNDR_IES_MAX_BUF_LEN];
429         u8   beacon_ie[VNDR_IES_MAX_BUF_LEN];
430         u32 probe_res_ie_len;
431         u32 beacon_ie_len;
432         u8 *wpa_ie;
433         u8 *rsn_ie;
434         u8 *wps_ie;
435         bool security_mode;
436 };
437 struct btcoex_info {
438         struct timer_list timer;
439         u32 timer_ms;
440         u32 timer_on;
441         u32 ts_dhcp_start;      /* ms ts ecord time stats */
442         u32 ts_dhcp_ok;         /* ms ts ecord time stats */
443         bool dhcp_done; /* flag, indicates that host done with
444                                          * dhcp before t1/t2 expiration
445                                          */
446         s32 bt_state;
447         struct work_struct work;
448         struct net_device *dev;
449 };
450
451 struct sta_info {
452         /* Structure to hold WPS IE for a STA */
453         u8  probe_req_ie[VNDR_IES_BUF_LEN];
454         u8  assoc_req_ie[VNDR_IES_BUF_LEN];
455         u32 probe_req_ie_len;
456         u32 assoc_req_ie_len;
457 };
458
459 struct afx_hdl {
460         wl_af_params_t *pending_tx_act_frm;
461         struct ether_addr       tx_dst_addr;
462         struct net_device *dev;
463         struct work_struct work;
464         u32 bssidx;
465         u32 retry;
466         s32 peer_chan;
467         s32 peer_listen_chan; /* search channel: configured by upper layer */
468         s32 my_listen_chan;     /* listen chanel: extract it from prb req or gon req */
469         bool is_listen;
470         bool ack_recv;
471         bool is_active;
472 };
473
474 struct parsed_ies {
475         wpa_ie_fixed_t *wps_ie;
476         u32 wps_ie_len;
477         wpa_ie_fixed_t *wpa_ie;
478         u32 wpa_ie_len;
479         bcm_tlv_t *wpa2_ie;
480         u32 wpa2_ie_len;
481 };
482
483
484 #define MAX_EVENT_BUF_NUM 16
485 typedef struct wl_eventmsg_buf {
486     u16 num;
487     struct {
488                 u16 type;
489                 bool set;
490         } event [MAX_EVENT_BUF_NUM];
491 } wl_eventmsg_buf_t;
492
493 /* private data of cfg80211 interface */
494 struct wl_priv {
495         struct wireless_dev *wdev;      /* representing wl cfg80211 device */
496
497         struct wireless_dev *p2p_wdev;  /* representing wl cfg80211 device for P2P */
498
499         struct net_device *p2p_net;    /* reference to p2p0 interface */
500
501         struct wl_conf *conf;
502         struct cfg80211_scan_request *scan_request;     /* scan request object */
503         EVENT_HANDLER evt_handler[WLC_E_LAST];
504         struct list_head eq_list;       /* used for event queue */
505         struct list_head net_list;     /* used for struct net_info */
506         struct list_head dealloc_list;     /* used for struct net_info which can be freed */
507         spinlock_t eq_lock;     /* for event queue synchronization */
508         spinlock_t cfgdrv_lock; /* to protect scan status (and others if needed) */
509         struct completion act_frm_scan;
510         struct completion iface_disable;
511         struct completion wait_next_af;
512         struct mutex usr_sync;  /* maily for up/down synchronization */
513         struct wl_scan_results *bss_list;
514         struct wl_scan_results *scan_results;
515
516         /* scan request object for internal purpose */
517         struct wl_scan_req *scan_req_int;
518         /* information element object for internal purpose */
519 #if defined(STATIC_WL_PRIV_STRUCT)
520         struct wl_ie *ie;
521 #else
522         struct wl_ie ie;
523 #endif
524         struct wl_iscan_ctrl *iscan;    /* iscan controller */
525
526         /* association information container */
527 #if defined(STATIC_WL_PRIV_STRUCT)
528         struct wl_connect_info *conn_info;
529 #else
530         struct wl_connect_info conn_info;
531 #endif
532 #ifdef DEBUGFS_CFG80211
533         struct dentry           *debugfs;
534 #endif /* DEBUGFS_CFG80211 */
535         struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
536         tsk_ctl_t event_tsk;            /* task of main event handler thread */
537         void *pub;
538         u32 iface_cnt;
539         u32 channel;            /* current channel */
540         u32 af_sent_channel;    /* channel action frame is sent */
541         /* next af subtype to cancel the remained dwell time in rx process */
542         u8 next_af_subtype;
543 #ifdef WL_CFG80211_SYNC_GON
544         ulong af_tx_sent_jiffies;
545 #endif /* WL_CFG80211_SYNC_GON */
546         bool iscan_on;          /* iscan on/off switch */
547         bool iscan_kickstart;   /* indicate iscan already started */
548         bool escan_on;      /* escan on/off switch */
549         struct escan_info escan_info;   /* escan information */
550         bool active_scan;       /* current scan mode */
551         bool ibss_starter;      /* indicates this sta is ibss starter */
552         bool link_up;           /* link/connection up flag */
553
554         /* indicate whether chip to support power save mode */
555         bool pwr_save;
556         bool roam_on;           /* on/off switch for self-roaming */
557         bool scan_tried;        /* indicates if first scan attempted */
558         bool wlfc_on;
559         bool vsdb_mode;
560         bool roamoff_on_concurrent;
561         u8 *ioctl_buf;          /* ioctl buffer */
562         struct mutex ioctl_buf_sync;
563         u8 *escan_ioctl_buf;
564         u8 *extra_buf;  /* maily to grab assoc information */
565         struct dentry *debugfsdir;
566         struct rfkill *rfkill;
567         bool rf_blocked;
568         struct ieee80211_channel remain_on_chan;
569         enum nl80211_channel_type remain_on_chan_type;
570         u64 send_action_id;
571         u64 last_roc_id;
572         wait_queue_head_t netif_change_event;
573         struct completion send_af_done;
574         struct afx_hdl *afx_hdl;
575         struct ap_info *ap_info;
576         struct sta_info *sta_info;
577         struct p2p_info *p2p;
578         bool p2p_supported;
579         struct btcoex_info *btcoex_info;
580         struct timer_list scan_timeout;   /* Timer for catch scan event timeout */
581         s32(*state_notifier) (struct wl_priv *wl,
582                 struct net_info *_net_info, enum wl_status state, bool set);
583         unsigned long interrested_state;
584         wlc_ssid_t hostapd_ssid;
585         bool sched_scan_running;        /* scheduled scan req status */
586 #ifdef WL_SCHED_SCAN
587         struct cfg80211_sched_scan_request *sched_scan_req;     /* scheduled scan req */
588 #endif /* WL_SCHED_SCAN */
589         bool scan_suppressed;
590         struct timer_list scan_supp_timer;
591         struct work_struct wlan_work;
592         struct work_struct dealloc_work;
593         struct mutex event_sync;        /* maily for up/down synchronization */
594         bool pm_enable_work_on;
595         struct delayed_work pm_enable_work;
596         vndr_ie_setbuf_t *ibss_vsie;    /* keep the VSIE for IBSS */
597         int ibss_vsie_len;
598
599 };
600
601
602 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
603 {
604         return bss = bss ?
605                 (struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
606 }
607 static inline s32
608 wl_alloc_netinfo(struct wl_priv *wl, struct net_device *ndev,
609         struct wireless_dev * wdev, s32 mode, bool pm_block)
610 {
611         struct net_info *_net_info;
612         s32 err = 0;
613         if (wl->iface_cnt == IFACE_MAX_CNT)
614                 return -ENOMEM;
615         _net_info = kzalloc(sizeof(struct net_info), GFP_KERNEL);
616         if (!_net_info)
617                 err = -ENOMEM;
618         else {
619                 _net_info->mode = mode;
620                 _net_info->ndev = ndev;
621                 _net_info->wdev = wdev;
622                 _net_info->pm_restore = 0;
623                 _net_info->pm = 0;
624                 _net_info->pm_block = pm_block;
625                 _net_info->roam_off = WL_INVALID;
626                 wl->iface_cnt++;
627                 list_add(&_net_info->list, &wl->net_list);
628         }
629         return err;
630 }
631 static inline void
632 wl_remove_netinfo(struct wl_priv *wl, struct net_device *ndev)
633 {
634         struct net_info *_net_info, *next;
635         bool dealloc_needed = false;
636
637         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
638                 if (ndev && (_net_info->ndev == ndev)) {
639                         list_del(&_net_info->list);
640                         wl->iface_cnt--;
641                         if (_net_info->wdev) {
642                                 ndev->ieee80211_ptr = NULL;
643                         }
644                         INIT_LIST_HEAD(&_net_info->list);
645                         list_add(&_net_info->list, &wl->dealloc_list);
646                         dealloc_needed = true;
647                 }
648         }
649         if (dealloc_needed)
650                 schedule_work(&wl->dealloc_work);
651 }
652
653 static inline void
654 wl_delete_all_netinfo(struct wl_priv *wl)
655 {
656         struct net_info *_net_info, *next;
657
658         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
659                 list_del(&_net_info->list);
660                         if (_net_info->wdev)
661                                 kfree(_net_info->wdev);
662                         kfree(_net_info);
663         }
664         wl->iface_cnt = 0;
665 }
666 static inline u32
667 wl_get_status_all(struct wl_priv *wl, s32 status)
668
669 {
670         struct net_info *_net_info, *next;
671         u32 cnt = 0;
672         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
673                 if (_net_info->ndev &&
674                         test_bit(status, &_net_info->sme_state))
675                         cnt++;
676         }
677         return cnt;
678 }
679 static inline void
680 wl_set_status_all(struct wl_priv *wl, s32 status, u32 op)
681 {
682         struct net_info *_net_info, *next;
683         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
684                 switch (op) {
685                         case 1:
686                                 return; /* set all status is not allowed */
687                         case 2:
688                                 clear_bit(status, &_net_info->sme_state);
689                                 if (wl->state_notifier &&
690                                         test_bit(status, &(wl->interrested_state)))
691                                         wl->state_notifier(wl, _net_info, status, false);
692                                 break;
693                         case 4:
694                                 return; /* change all status is not allowed */
695                         default:
696                                 return; /* unknown operation */
697                 }
698         }
699 }
700 static inline void
701 wl_set_status_by_netdev(struct wl_priv *wl, s32 status,
702         struct net_device *ndev, u32 op)
703 {
704
705         struct net_info *_net_info, *next;
706
707         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
708                 if (ndev && (_net_info->ndev == ndev)) {
709                         switch (op) {
710                                 case 1:
711                                         set_bit(status, &_net_info->sme_state);
712                                         if (wl->state_notifier &&
713                                                 test_bit(status, &(wl->interrested_state)))
714                                                 wl->state_notifier(wl, _net_info, status, true);
715                                         break;
716                                 case 2:
717                                         clear_bit(status, &_net_info->sme_state);
718                                         if (wl->state_notifier &&
719                                                 test_bit(status, &(wl->interrested_state)))
720                                                 wl->state_notifier(wl, _net_info, status, false);
721                                         break;
722                                 case 4:
723                                         change_bit(status, &_net_info->sme_state);
724                                         break;
725                         }
726                 }
727
728         }
729
730 }
731
732 static inline u32
733 wl_get_status_by_netdev(struct wl_priv *wl, s32 status,
734         struct net_device *ndev)
735 {
736         struct net_info *_net_info, *next;
737
738         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
739                                 if (ndev && (_net_info->ndev == ndev))
740                                         return test_bit(status, &_net_info->sme_state);
741         }
742         return 0;
743 }
744
745 static inline s32
746 wl_get_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev)
747 {
748         struct net_info *_net_info, *next;
749
750         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
751                                 if (ndev && (_net_info->ndev == ndev))
752                                         return _net_info->mode;
753         }
754         return -1;
755 }
756
757
758 static inline void
759 wl_set_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev,
760         s32 mode)
761 {
762         struct net_info *_net_info, *next;
763
764         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
765                                 if (ndev && (_net_info->ndev == ndev))
766                                         _net_info->mode = mode;
767         }
768 }
769 static inline struct wl_profile *
770 wl_get_profile_by_netdev(struct wl_priv *wl, struct net_device *ndev)
771 {
772         struct net_info *_net_info, *next;
773
774         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
775                                 if (ndev && (_net_info->ndev == ndev))
776                                         return &_net_info->profile;
777         }
778         return NULL;
779 }
780 static inline struct net_info *
781 wl_get_netinfo_by_netdev(struct wl_priv *wl, struct net_device *ndev)
782 {
783         struct net_info *_net_info, *next;
784
785         list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
786                                 if (ndev && (_net_info->ndev == ndev))
787                                         return _net_info;
788         }
789         return NULL;
790 }
791 #define wl_to_wiphy(w) (w->wdev->wiphy)
792 #define wl_to_prmry_ndev(w) (w->wdev->netdev)
793 #define wl_to_prmry_wdev(w) (w->wdev)
794 #define wl_to_p2p_wdev(w) (w->p2p_wdev)
795 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
796 #define ndev_to_wdev(ndev) (ndev->ieee80211_ptr)
797 #define wdev_to_ndev(wdev) (wdev->netdev)
798
799 #if defined(WL_ENABLE_P2P_IF)
800 #define ndev_to_wlc_ndev(ndev, wl)      ((ndev == wl->p2p_net) ? \
801         wl_to_prmry_ndev(wl) : ndev)
802 #else
803 #define ndev_to_wlc_ndev(ndev, wl)      (ndev)
804 #endif /* WL_ENABLE_P2P_IF */
805
806 #if defined(WL_CFG80211_P2P_DEV_IF)
807 #define wdev_to_wlc_ndev(wdev, wl)      \
808         ((wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) ? \
809         wl_to_prmry_ndev(wl) : wdev_to_ndev(wdev))
810 #define cfgdev_to_wlc_ndev(cfgdev, wl)  wdev_to_wlc_ndev(cfgdev, wl)
811 #elif defined(WL_ENABLE_P2P_IF)
812 #define cfgdev_to_wlc_ndev(cfgdev, wl)  ndev_to_wlc_ndev(cfgdev, wl)
813 #else
814 #define cfgdev_to_wlc_ndev(cfgdev, wl)  (cfgdev)
815 #endif /* WL_CFG80211_P2P_DEV_IF */
816
817 #if defined(WL_CFG80211_P2P_DEV_IF)
818 #define ndev_to_cfgdev(ndev)    ndev_to_wdev(ndev)
819 #else
820 #define ndev_to_cfgdev(ndev)    (ndev)
821 #endif /* WL_CFG80211_P2P_DEV_IF */
822
823 #if defined(WL_CFG80211_P2P_DEV_IF)
824 #define scan_req_match(wl)      (((wl) && (wl->scan_request) && \
825         (wl->scan_request->wdev == wl->p2p_wdev)) ? true : false)
826 #elif defined(WL_ENABLE_P2P_IF)
827 #define scan_req_match(wl)      (((wl) && (wl->scan_request) && \
828         (wl->scan_request->dev == wl->p2p_net)) ? true : false)
829 #else
830 #define scan_req_match(wl)      (((wl) && p2p_is_on(wl) && p2p_scan(wl)) ? \
831         true : false)
832 #endif /* WL_CFG80211_P2P_DEV_IF */
833
834 #define wl_to_sr(w) (w->scan_req_int)
835 #if defined(STATIC_WL_PRIV_STRUCT)
836 #define wl_to_ie(w) (w->ie)
837 #define wl_to_conn(w) (w->conn_info)
838 #else
839 #define wl_to_ie(w) (&w->ie)
840 #define wl_to_conn(w) (&w->conn_info)
841 #endif
842 #define iscan_to_wl(i) ((struct wl_priv *)(i->data))
843 #define wl_to_iscan(w) (w->iscan)
844 #define wiphy_from_scan(w) (w->escan_info.wiphy)
845 #define wl_get_drv_status_all(wl, stat) \
846         (wl_get_status_all(wl, WL_STATUS_ ## stat))
847 #define wl_get_drv_status(wl, stat, ndev)  \
848         (wl_get_status_by_netdev(wl, WL_STATUS_ ## stat, ndev))
849 #define wl_set_drv_status(wl, stat, ndev)  \
850         (wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 1))
851 #define wl_clr_drv_status(wl, stat, ndev)  \
852         (wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 2))
853 #define wl_clr_drv_status_all(wl, stat)  \
854         (wl_set_status_all(wl, WL_STATUS_ ## stat, 2))
855 #define wl_chg_drv_status(wl, stat, ndev)  \
856         (wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 4))
857
858 #define for_each_bss(list, bss, __i)    \
859         for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
860
861 #define for_each_ndev(wl, iter, next) \
862         list_for_each_entry_safe(iter, next, &wl->net_list, list)
863
864
865 /* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0.
866  * In addtion to that, wpa_version is WPA_VERSION_1
867  */
868 #define is_wps_conn(_sme) \
869         ((wl_cfgp2p_find_wpsie((u8 *)_sme->ie, _sme->ie_len) != NULL) && \
870          (!_sme->crypto.n_ciphers_pairwise) && \
871          (!_sme->crypto.cipher_group))
872 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
873 extern s32 wl_cfg80211_attach_post(struct net_device *ndev);
874 extern void wl_cfg80211_detach(void *para);
875
876 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
877             void *data);
878 void wl_cfg80211_set_parent_dev(void *dev);
879 struct device *wl_cfg80211_get_parent_dev(void);
880
881 extern s32 wl_cfg80211_up(void *para);
882 extern s32 wl_cfg80211_down(void *para);
883 extern s32 wl_cfg80211_notify_ifadd(struct net_device *ndev, s32 idx, s32 bssidx,
884         void* _net_attach);
885 extern s32 wl_cfg80211_ifdel_ops(struct net_device *net);
886 extern s32 wl_cfg80211_notify_ifdel(void);
887 extern s32 wl_cfg80211_is_progress_ifadd(void);
888 extern s32 wl_cfg80211_is_progress_ifchange(void);
889 extern s32 wl_cfg80211_is_progress_ifadd(void);
890 extern s32 wl_cfg80211_notify_ifchange(void);
891 extern void wl_cfg80211_dbg_level(u32 level);
892 extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
893 extern s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len);
894 extern s32 wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len);
895 extern s32 wl_cfg80211_set_wps_p2p_ie(struct net_device *net, char *buf, int len,
896         enum wl_management_type type);
897 extern s32 wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len);
898 #ifdef WL_SUPPORT_AUTO_CHANNEL
899 #define CHANSPEC_BUF_SIZE       1024
900 #define CHAN_SEL_IOCTL_DELAY    300
901 #define CHAN_SEL_RETRY_COUNT    15
902 #define CHANNEL_IS_RADAR(channel)       (((channel & WL_CHAN_RADAR) || \
903         (channel & WL_CHAN_PASSIVE)) ? true : false)
904 #define CHANNEL_IS_2G(channel)  (((channel >= 1) && (channel <= 14)) ? \
905         true : false)
906 #define CHANNEL_IS_5G(channel)  (((channel >= 36) && (channel <= 165)) ? \
907         true : false)
908 extern s32 wl_cfg80211_get_best_channels(struct net_device *dev, char* command,
909         int total_len);
910 #endif /* WL_SUPPORT_AUTO_CHANNEL */
911 extern int wl_cfg80211_hang(struct net_device *dev, u16 reason);
912 extern s32 wl_mode_to_nl80211_iftype(s32 mode);
913 int wl_cfg80211_do_driver_init(struct net_device *net);
914 void wl_cfg80211_enable_trace(bool set, u32 level);
915 extern s32 wl_update_wiphybands(struct wl_priv *wl, bool notify);
916 extern s32 wl_cfg80211_if_is_group_owner(void);
917 extern chanspec_t wl_ch_host_to_driver(u16 channel);
918 extern s32 wl_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add);
919 extern void wl_stop_wait_next_action_frame(struct wl_priv *wl);
920 extern int wl_cfg80211_update_power_mode(struct net_device *dev);
921 extern void wl_cfg80211_add_to_eventbuffer(wl_eventmsg_buf_t *ev, u16 event, bool set);
922 extern s32 wl_cfg80211_apply_eventbuffer(struct net_device *ndev,
923         struct wl_priv *wl, wl_eventmsg_buf_t *ev);
924 extern void get_primary_mac(struct wl_priv *wl, struct ether_addr *mac);
925 #define SCAN_BUF_CNT    2
926 #define SCAN_BUF_NEXT   1
927 #define wl_escan_set_sync_id(a, b) ((a) = htod16(0x1234))
928 #define wl_escan_get_buf(a, b) ((wl_scan_results_t *) (a)->escan_info.escan_buf)
929 #define wl_escan_check_sync_id(a, b, c) 0
930 #define wl_escan_print_sync_id(a, b, c)
931 #define wl_escan_increment_sync_id(a, b)
932 #define wl_escan_init_sync_id(a)
933 extern void wl_cfg80211_ibss_vsie_set_buffer(vndr_ie_setbuf_t *ibss_vsie, int ibss_vsie_len);
934 extern s32 wl_cfg80211_ibss_vsie_delete(struct net_device *dev);
935
936 /* Action frame specific functions */
937 extern u8 wl_get_action_category(void *frame, u32 frame_len);
938 extern int wl_get_public_action(void *frame, u32 frame_len, u8 *ret_action);
939 #endif                          /* _wl_cfg80211_h_ */