Merge tag 'lsk-v4.4-16.06-android'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / bcmdhd / wl_cfg80211.h
1 /*
2  * Linux cfg80211 driver
3  *
4  * Copyright (C) 1999-2016, 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  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id: wl_cfg80211.h 608788 2015-12-29 10:59:33Z $
28  */
29
30 /**
31  * Older Linux versions support the 'iw' interface, more recent ones the 'cfg80211' interface.
32  */
33
34 #ifndef _wl_cfg80211_h_
35 #define _wl_cfg80211_h_
36
37 #include <linux/wireless.h>
38 #include <typedefs.h>
39 #include <proto/ethernet.h>
40 #include <wlioctl.h>
41 #include <linux/wireless.h>
42 #include <net/cfg80211.h>
43 #include <linux/rfkill.h>
44
45 #include <dngl_stats.h>
46 #include <dhd.h>
47 #include <wl_cfgp2p.h>
48 #include <linux/time.h>
49
50 struct wl_conf;
51 struct wl_iface;
52 struct bcm_cfg80211;
53 struct wl_security;
54 struct wl_ibss;
55
56
57 #define htod32(i) (i)
58 #define htod16(i) (i)
59 #define dtoh64(i) (i)
60 #define dtoh32(i) (i)
61 #define dtoh16(i) (i)
62 #define htodchanspec(i) (i)
63 #define dtohchanspec(i) (i)
64
65 #define WL_DBG_NONE     0
66 #define WL_DBG_P2P_ACTION (1 << 5)
67 #define WL_DBG_TRACE    (1 << 4)
68 #define WL_DBG_SCAN     (1 << 3)
69 #define WL_DBG_DBG      (1 << 2)
70 #define WL_DBG_INFO     (1 << 1)
71 #define WL_DBG_ERR      (1 << 0)
72
73 #ifdef DHD_LOG_DUMP
74 extern void dhd_log_dump_print(const char *fmt, ...);
75 extern char *dhd_log_dump_get_timestamp(void);
76 struct bcm_cfg80211 *wl_get_bcm_cfg80211_ptr(void);
77 #endif /* DHD_LOG_DUMP */
78
79 /* 0 invalidates all debug messages.  default is 1 */
80 #define WL_DBG_LEVEL 0xFF
81
82 #ifdef CUSTOMER_HW4_DEBUG
83 #define CFG80211_ERROR_TEXT             "CFG80211-INFO2) "
84 #else
85 #define CFG80211_ERROR_TEXT             "CFG80211-ERROR) "
86 #endif /* CUSTOMER_HW4_DEBUG */
87
88 #if defined(DHD_DEBUG)
89 #ifdef DHD_LOG_DUMP
90 #define WL_ERR(args)    \
91 do {    \
92         if (wl_dbg_level & WL_DBG_ERR) {        \
93                 printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);        \
94                 printk args;    \
95                 dhd_log_dump_print("[%s] %s: ", dhd_log_dump_get_timestamp(), __func__);        \
96                 dhd_log_dump_print args;        \
97         }       \
98 } while (0)
99 #else
100 #define WL_ERR(args)                                                                    \
101 do {                                                                            \
102         if (wl_dbg_level & WL_DBG_ERR) {                                \
103                         printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);        \
104                         printk args;                                            \
105                 }                                                               \
106 } while (0)
107 #endif /* DHD_LOG_DUMP */
108 #else /* defined(DHD_DEBUG) */
109 #define WL_ERR(args)                                                                    \
110 do {                                                                            \
111         if ((wl_dbg_level & WL_DBG_ERR) && net_ratelimit()) {                           \
112                         printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);        \
113                         printk args;                                            \
114                 }                                                               \
115 } while (0)
116 #endif /* defined(DHD_DEBUG) */
117
118 #ifdef WL_INFORM
119 #undef WL_INFORM
120 #endif
121
122 #define WL_INFORM(args)                                                                 \
123 do {                                                                            \
124         if (wl_dbg_level & WL_DBG_INFO) {                               \
125                         printk(KERN_INFO "CFG80211-INFO) %s : ", __func__);     \
126                         printk args;                                            \
127                 }                                                               \
128 } while (0)
129
130
131 #ifdef WL_SCAN
132 #undef WL_SCAN
133 #endif
134 #define WL_SCAN(args)                                                           \
135 do {                                                                    \
136         if (wl_dbg_level & WL_DBG_SCAN) {                       \
137                 printk(KERN_INFO "CFG80211-SCAN) %s :", __func__);      \
138                 printk args;                                                    \
139         }                                                                       \
140 } while (0)
141 #ifdef WL_TRACE
142 #undef WL_TRACE
143 #endif
144 #define WL_TRACE(args)                                                          \
145 do {                                                                    \
146         if (wl_dbg_level & WL_DBG_TRACE) {                      \
147                 printk(KERN_INFO "CFG80211-TRACE) %s :", __func__);     \
148                 printk args;                                                    \
149         }                                                                       \
150 } while (0)
151 #ifdef WL_TRACE_HW4
152 #undef WL_TRACE_HW4
153 #endif
154 #ifdef CUSTOMER_HW4_DEBUG
155 #define WL_TRACE_HW4(args)                                      \
156 do {                                                                            \
157         if (wl_dbg_level & WL_DBG_ERR) {                                \
158                         printk(KERN_INFO "CFG80211-TRACE) %s : ", __func__);    \
159                         printk args;                                            \
160                 }                                                               \
161 } while (0)
162 #else
163 #define WL_TRACE_HW4                    WL_TRACE
164 #endif /* CUSTOMER_HW4_DEBUG */
165 #if (WL_DBG_LEVEL > 0)
166 #define WL_DBG(args)                                                            \
167 do {                                                                    \
168         if (wl_dbg_level & WL_DBG_DBG) {                        \
169                 printk(KERN_INFO "CFG80211-DEBUG) %s :", __func__);     \
170                 printk args;                                                    \
171         }                                                                       \
172 } while (0)
173 #else                           /* !(WL_DBG_LEVEL > 0) */
174 #define WL_DBG(args)
175 #endif                          /* (WL_DBG_LEVEL > 0) */
176 #define WL_PNO(x)
177 #define WL_SD(x)
178
179
180 #define WL_SCAN_RETRY_MAX       3
181 #define WL_NUM_PMKIDS_MAX       MAXPMKID
182 #define WL_SCAN_BUF_MAX         (1024 * 8)
183 #define WL_TLV_INFO_MAX         1500
184 #define WL_SCAN_IE_LEN_MAX      2048
185 #define WL_BSS_INFO_MAX         2048
186 #define WL_ASSOC_INFO_MAX       512
187 #define WL_IOCTL_LEN_MAX        2048
188 #define WL_EXTRA_BUF_MAX        2048
189 #define WL_SCAN_ERSULTS_LAST    (WL_SCAN_RESULTS_NO_MEM+1)
190 #define WL_AP_MAX                       256
191 #define WL_FILE_NAME_MAX        256
192 #define WL_DWELL_TIME           200
193 #define WL_MED_DWELL_TIME       400
194 #define WL_MIN_DWELL_TIME       100
195 #define WL_LONG_DWELL_TIME      1000
196 #define IFACE_MAX_CNT   4
197 #define WL_SCAN_CONNECT_DWELL_TIME_MS           200
198 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS          20
199 #define WL_SCAN_JOIN_ACTIVE_DWELL_TIME_MS       320
200 #define WL_SCAN_JOIN_PASSIVE_DWELL_TIME_MS      400
201 #define WL_AF_TX_MAX_RETRY      5
202
203 #define WL_AF_SEARCH_TIME_MAX           450
204 #define WL_AF_TX_EXTRA_TIME_MAX         200
205
206 #define WL_SCAN_TIMER_INTERVAL_MS       10000 /* Scan timeout */
207 #define WL_CHANNEL_SYNC_RETRY   5
208 #define WL_INVALID              -1
209
210 #ifdef DHD_LOSSLESS_ROAMING
211 #define WL_ROAM_TIMEOUT_MS      1000 /* Roam timeout */
212 #endif
213 /* Bring down SCB Timeout to 20secs from 60secs default */
214 #ifndef WL_SCB_TIMEOUT
215 #define WL_SCB_TIMEOUT  20
216 #endif
217
218 #ifndef WL_SCB_ACTIVITY_TIME
219 #define WL_SCB_ACTIVITY_TIME    5
220 #endif
221
222 #ifndef WL_SCB_MAX_PROBE
223 #define WL_SCB_MAX_PROBE        3
224 #endif
225
226 #ifndef WL_MIN_PSPRETEND_THRESHOLD
227 #define WL_MIN_PSPRETEND_THRESHOLD      2
228 #endif
229
230 /* SCAN_SUPPRESS timer values in ms */
231 #define WL_SCAN_SUPPRESS_TIMEOUT 31000 /* default Framwork DHCP timeout is 30 sec */
232 #define WL_SCAN_SUPPRESS_RETRY 3000
233
234 #define WL_PM_ENABLE_TIMEOUT 10000
235
236 /* cfg80211 wowlan definitions */
237 #define WL_WOWLAN_MAX_PATTERNS                  8
238 #define WL_WOWLAN_MIN_PATTERN_LEN               1
239 #define WL_WOWLAN_MAX_PATTERN_LEN               255
240 #define WL_WOWLAN_PKT_FILTER_ID_FIRST   201
241 #define WL_WOWLAN_PKT_FILTER_ID_LAST    (WL_WOWLAN_PKT_FILTER_ID_FIRST + \
242                                                                         WL_WOWLAN_MAX_PATTERNS - 1)
243
244 #ifdef WLTDLS
245 #define TDLS_TUNNELED_PRB_REQ   "\x7f\x50\x6f\x9a\04"
246 #define TDLS_TUNNELED_PRB_RESP  "\x7f\x50\x6f\x9a\05"
247 #endif /* WLTDLS */
248
249
250 /* driver status */
251 enum wl_status {
252         WL_STATUS_READY = 0,
253         WL_STATUS_SCANNING,
254         WL_STATUS_SCAN_ABORTING,
255         WL_STATUS_CONNECTING,
256         WL_STATUS_CONNECTED,
257         WL_STATUS_DISCONNECTING,
258         WL_STATUS_AP_CREATING,
259         WL_STATUS_AP_CREATED,
260         /* whole sending action frame procedure:
261          * includes a) 'finding common channel' for public action request frame
262          * and b) 'sending af via 'actframe' iovar'
263          */
264         WL_STATUS_SENDING_ACT_FRM,
265         /* find a peer to go to a common channel before sending public action req frame */
266         WL_STATUS_FINDING_COMMON_CHANNEL,
267         /* waiting for next af to sync time of supplicant.
268          * it includes SENDING_ACT_FRM and WAITING_NEXT_ACT_FRM_LISTEN
269          */
270         WL_STATUS_WAITING_NEXT_ACT_FRM,
271 #ifdef WL_CFG80211_SYNC_GON
272         /* go to listen state to wait for next af after SENDING_ACT_FRM */
273         WL_STATUS_WAITING_NEXT_ACT_FRM_LISTEN,
274 #endif /* WL_CFG80211_SYNC_GON */
275         /* it will be set when upper layer requests listen and succeed in setting listen mode.
276          * if set, other scan request can abort current listen state
277          */
278         WL_STATUS_REMAINING_ON_CHANNEL,
279 #ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
280         /* it's fake listen state to keep current scan state.
281          * it will be set when upper layer requests listen but scan is running. then just run
282          * a expire timer without actual listen state.
283          * if set, other scan request does not need to abort scan.
284          */
285         WL_STATUS_FAKE_REMAINING_ON_CHANNEL
286 #endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
287 };
288
289 /* wi-fi mode */
290 enum wl_mode {
291         WL_MODE_BSS,
292         WL_MODE_IBSS,
293         WL_MODE_AP
294 };
295
296 /* driver profile list */
297 enum wl_prof_list {
298         WL_PROF_MODE,
299         WL_PROF_SSID,
300         WL_PROF_SEC,
301         WL_PROF_IBSS,
302         WL_PROF_BAND,
303         WL_PROF_CHAN,
304         WL_PROF_BSSID,
305         WL_PROF_ACT,
306         WL_PROF_BEACONINT,
307         WL_PROF_DTIMPERIOD
308 };
309
310 /* donlge escan state */
311 enum wl_escan_state {
312         WL_ESCAN_STATE_IDLE,
313         WL_ESCAN_STATE_SCANING
314 };
315 /* fw downloading status */
316 enum wl_fw_status {
317         WL_FW_LOADING_DONE,
318         WL_NVRAM_LOADING_DONE
319 };
320
321 enum wl_management_type {
322         WL_BEACON = 0x1,
323         WL_PROBE_RESP = 0x2,
324         WL_ASSOC_RESP = 0x4
325 };
326
327 enum wl_pm_workq_act_type {
328         WL_PM_WORKQ_SHORT,
329         WL_PM_WORKQ_LONG,
330         WL_PM_WORKQ_DEL
331 };
332
333 /* beacon / probe_response */
334 struct beacon_proberesp {
335         __le64 timestamp;
336         __le16 beacon_int;
337         __le16 capab_info;
338         u8 variable[0];
339 } __attribute__ ((packed));
340
341 /* driver configuration */
342 struct wl_conf {
343         u32 frag_threshold;
344         u32 rts_threshold;
345         u32 retry_short;
346         u32 retry_long;
347         s32 tx_power;
348         struct ieee80211_channel channel;
349 };
350
351 typedef s32(*EVENT_HANDLER) (struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
352                             const wl_event_msg_t *e, void *data);
353
354 /* bss inform structure for cfg80211 interface */
355 struct wl_cfg80211_bss_info {
356         u16 band;
357         u16 channel;
358         s16 rssi;
359         u16 frame_len;
360         u8 frame_buf[1];
361 };
362
363 /* basic structure of scan request */
364 struct wl_scan_req {
365         struct wlc_ssid ssid;
366 };
367
368 /* basic structure of information element */
369 struct wl_ie {
370         u16 offset;
371         u8 buf[WL_TLV_INFO_MAX];
372 };
373
374 /* event queue for cfg80211 main event */
375 struct wl_event_q {
376         struct list_head eq_list;
377         u32 etype;
378         wl_event_msg_t emsg;
379         s8 edata[1];
380 };
381
382 /* security information with currently associated ap */
383 struct wl_security {
384         u32 wpa_versions;
385         u32 auth_type;
386         u32 cipher_pairwise;
387         u32 cipher_group;
388         u32 wpa_auth;
389         u32 auth_assoc_res_status;
390 };
391
392 /* ibss information for currently joined ibss network */
393 struct wl_ibss {
394         u8 beacon_interval;     /* in millisecond */
395         u8 atim;                /* in millisecond */
396         s8 join_only;
397         u8 band;
398         u8 channel;
399 };
400
401 typedef struct wl_bss_vndr_ies {
402         u8  probe_req_ie[VNDR_IES_BUF_LEN];
403         u8  probe_res_ie[VNDR_IES_MAX_BUF_LEN];
404         u8  assoc_req_ie[VNDR_IES_BUF_LEN];
405         u8  assoc_res_ie[VNDR_IES_BUF_LEN];
406         u8  beacon_ie[VNDR_IES_MAX_BUF_LEN];
407         u32 probe_req_ie_len;
408         u32 probe_res_ie_len;
409         u32 assoc_req_ie_len;
410         u32 assoc_res_ie_len;
411         u32 beacon_ie_len;
412 } wl_bss_vndr_ies_t;
413
414 typedef struct wl_cfgbss {
415         u8 *wpa_ie;
416         u8 *rsn_ie;
417         u8 *wps_ie;
418         bool security_mode;
419         struct wl_bss_vndr_ies ies;     /* Common for STA, P2P GC, GO, AP, P2P Disc Interface */
420 } wl_cfgbss_t;
421
422 /* cfg driver profile */
423 struct wl_profile {
424         u32 mode;
425         s32 band;
426         u32 channel;
427         struct wlc_ssid ssid;
428         struct wl_security sec;
429         struct wl_ibss ibss;
430         u8 bssid[ETHER_ADDR_LEN];
431         u16 beacon_interval;
432         u8 dtim_period;
433         bool active;
434 };
435
436 struct net_info {
437         struct net_device *ndev;
438         struct wireless_dev *wdev;
439         struct wl_profile profile;
440         s32 mode;
441         s32 roam_off;
442         unsigned long sme_state;
443         bool pm_restore;
444         bool pm_block;
445         s32 pm;
446         s32 bssidx;
447         wl_cfgbss_t bss;
448         u32 ulb_bw;
449         struct list_head list; /* list of all net_info structure */
450 };
451
452 /* association inform */
453 #define MAX_REQ_LINE 1024
454 struct wl_connect_info {
455         u8 req_ie[MAX_REQ_LINE];
456         s32 req_ie_len;
457         u8 resp_ie[MAX_REQ_LINE];
458         s32 resp_ie_len;
459 };
460
461 /* firmware /nvram downloading controller */
462 struct wl_fw_ctrl {
463         const struct firmware *fw_entry;
464         unsigned long status;
465         u32 ptr;
466         s8 fw_name[WL_FILE_NAME_MAX];
467         s8 nvram_name[WL_FILE_NAME_MAX];
468 };
469
470 /* assoc ie length */
471 struct wl_assoc_ielen {
472         u32 req_len;
473         u32 resp_len;
474 };
475
476 /* wpa2 pmk list */
477 struct wl_pmk_list {
478         pmkid_list_t pmkids;
479         pmkid_t foo[MAXPMKID - 1];
480 };
481
482 #ifdef DHD_MAX_IFS
483 #define WL_MAX_IFS DHD_MAX_IFS
484 #else
485 #define WL_MAX_IFS 16
486 #endif
487
488 #define ESCAN_BUF_SIZE (64 * 1024)
489
490 struct escan_info {
491         u32 escan_state;
492 #if defined(STATIC_WL_PRIV_STRUCT)
493 #ifndef CONFIG_DHD_USE_STATIC_BUF
494 #error STATIC_WL_PRIV_STRUCT should be used with CONFIG_DHD_USE_STATIC_BUF
495 #endif /* CONFIG_DHD_USE_STATIC_BUF */
496         u8 *escan_buf;
497 #else
498         u8 escan_buf[ESCAN_BUF_SIZE];
499 #endif /* STATIC_WL_PRIV_STRUCT */
500         struct wiphy *wiphy;
501         struct net_device *ndev;
502 };
503
504 #ifdef ESCAN_BUF_OVERFLOW_MGMT
505 #define BUF_OVERFLOW_MGMT_COUNT 3
506 typedef struct {
507         int RSSI;
508         int length;
509         struct ether_addr BSSID;
510 } removal_element_t;
511 #endif /* ESCAN_BUF_OVERFLOW_MGMT */
512
513 struct afx_hdl {
514         wl_af_params_t *pending_tx_act_frm;
515         struct ether_addr       tx_dst_addr;
516         struct net_device *dev;
517         struct work_struct work;
518         s32 bssidx;
519         u32 retry;
520         s32 peer_chan;
521         s32 peer_listen_chan; /* search channel: configured by upper layer */
522         s32 my_listen_chan;     /* listen chanel: extract it from prb req or gon req */
523         bool is_listen;
524         bool ack_recv;
525         bool is_active;
526 };
527
528 struct parsed_ies {
529         wpa_ie_fixed_t *wps_ie;
530         u32 wps_ie_len;
531         wpa_ie_fixed_t *wpa_ie;
532         u32 wpa_ie_len;
533         bcm_tlv_t *wpa2_ie;
534         u32 wpa2_ie_len;
535 };
536
537
538 #ifdef P2P_LISTEN_OFFLOADING
539 typedef struct {
540         uint16  period;                 /* listen offload period */
541         uint16  interval;               /* listen offload interval */
542         uint16  count;                  /* listen offload count */
543         uint16  pad;                    /* pad for 32bit align */
544 } wl_p2plo_listen_t;
545 #endif /* P2P_LISTEN_OFFLOADING */
546
547 #ifdef WL11U
548 /* Max length of Interworking element */
549 #define IW_IES_MAX_BUF_LEN              9
550 #endif
551 #define MAX_EVENT_BUF_NUM 16
552 typedef struct wl_eventmsg_buf {
553         u16 num;
554         struct {
555                 u16 type;
556                 bool set;
557         } event [MAX_EVENT_BUF_NUM];
558 } wl_eventmsg_buf_t;
559
560 typedef struct wl_if_event_info {
561         bool valid;
562         int ifidx;
563         int bssidx;
564         uint8 mac[ETHER_ADDR_LEN];
565         char name[IFNAMSIZ+1];
566 } wl_if_event_info;
567
568 #if defined(DHD_ENABLE_BIGDATA_LOGGING)
569 #define GET_BSS_INFO_LEN 90
570 #endif /* DHD_ENABLE_BIGDATA_LOGGING */
571
572 /* private data of cfg80211 interface */
573 struct bcm_cfg80211 {
574         struct wireless_dev *wdev;      /* representing cfg cfg80211 device */
575
576         struct wireless_dev *p2p_wdev;  /* representing cfg cfg80211 device for P2P */
577         struct net_device *p2p_net;    /* reference to p2p0 interface */
578
579         struct wl_conf *conf;
580         struct cfg80211_scan_request *scan_request;     /* scan request object */
581         EVENT_HANDLER evt_handler[WLC_E_LAST];
582         struct list_head eq_list;       /* used for event queue */
583         struct list_head net_list;     /* used for struct net_info */
584         spinlock_t net_list_sync;       /* to protect scan status (and others if needed) */
585         spinlock_t eq_lock;     /* for event queue synchronization */
586         spinlock_t cfgdrv_lock; /* to protect scan status (and others if needed) */
587         struct completion act_frm_scan;
588         struct completion iface_disable;
589         struct completion wait_next_af;
590         struct mutex usr_sync;  /* maily for up/down synchronization */
591         struct mutex scan_complete;     /* serialize scan_complete call */
592         struct wl_scan_results *bss_list;
593         struct wl_scan_results *scan_results;
594
595         /* scan request object for internal purpose */
596         struct wl_scan_req *scan_req_int;
597         /* information element object for internal purpose */
598 #if defined(STATIC_WL_PRIV_STRUCT)
599         struct wl_ie *ie;
600 #else
601         struct wl_ie ie;
602 #endif
603
604         /* association information container */
605 #if defined(STATIC_WL_PRIV_STRUCT)
606         struct wl_connect_info *conn_info;
607 #else
608         struct wl_connect_info conn_info;
609 #endif
610 #ifdef DEBUGFS_CFG80211
611         struct dentry           *debugfs;
612 #endif /* DEBUGFS_CFG80211 */
613         struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
614         tsk_ctl_t event_tsk;            /* task of main event handler thread */
615         dhd_pub_t *pub;
616         u32 iface_cnt;
617         u32 channel;            /* current channel */
618         u32 af_sent_channel;    /* channel action frame is sent */
619         /* next af subtype to cancel the remained dwell time in rx process */
620         u8 next_af_subtype;
621 #ifdef WL_CFG80211_SYNC_GON
622         ulong af_tx_sent_jiffies;
623 #endif /* WL_CFG80211_SYNC_GON */
624         struct escan_info escan_info;   /* escan information */
625         bool active_scan;       /* current scan mode */
626         bool ibss_starter;      /* indicates this sta is ibss starter */
627         bool link_up;           /* link/connection up flag */
628
629         /* indicate whether chip to support power save mode */
630         bool pwr_save;
631         bool roam_on;           /* on/off switch for self-roaming */
632         bool scan_tried;        /* indicates if first scan attempted */
633 #if defined(BCMSDIO) || defined(BCMPCIE)
634         bool wlfc_on;
635 #endif 
636         bool vsdb_mode;
637         bool roamoff_on_concurrent;
638         u8 *ioctl_buf;          /* ioctl buffer */
639         struct mutex ioctl_buf_sync;
640         u8 *escan_ioctl_buf;
641         u8 *extra_buf;  /* maily to grab assoc information */
642         struct dentry *debugfsdir;
643         struct rfkill *rfkill;
644         bool rf_blocked;
645         struct ieee80211_channel remain_on_chan;
646         enum nl80211_channel_type remain_on_chan_type;
647         u64 send_action_id;
648         u64 last_roc_id;
649         wait_queue_head_t netif_change_event;
650         wl_if_event_info if_event_info;
651         struct completion send_af_done;
652         struct afx_hdl *afx_hdl;
653         struct p2p_info *p2p;
654         bool p2p_supported;
655         void *btcoex_info;
656         struct timer_list scan_timeout;   /* Timer for catch scan event timeout */
657 #if defined(P2P_IE_MISSING_FIX)
658         bool p2p_prb_noti;
659 #endif
660         s32(*state_notifier) (struct bcm_cfg80211 *cfg,
661                 struct net_info *_net_info, enum wl_status state, bool set);
662         unsigned long interrested_state;
663         wlc_ssid_t hostapd_ssid;
664 #ifdef WL11U
665         bool wl11u;
666         u8 iw_ie[IW_IES_MAX_BUF_LEN];
667         u32 iw_ie_len;
668 #endif /* WL11U */
669         bool sched_scan_running;        /* scheduled scan req status */
670 #ifdef WL_SCHED_SCAN
671         struct cfg80211_sched_scan_request *sched_scan_req;     /* scheduled scan req */
672 #endif /* WL_SCHED_SCAN */
673         bool scan_suppressed;
674         struct timer_list scan_supp_timer;
675         struct work_struct wlan_work;
676         struct mutex event_sync;        /* maily for up/down synchronization */
677         bool disable_roam_event;
678         struct delayed_work pm_enable_work;
679         struct mutex pm_sync;   /* mainly for pm work synchronization */
680
681         vndr_ie_setbuf_t *ibss_vsie;    /* keep the VSIE for IBSS */
682         int ibss_vsie_len;
683         u32 rmc_event_pid;
684         u32 rmc_event_seq;
685 #ifdef WLAIBSS_MCHAN
686         struct ether_addr ibss_if_addr;
687         bcm_struct_cfgdev *ibss_cfgdev; /* For AIBSS */
688 #endif /* WLAIBSS_MCHAN */
689         bcm_struct_cfgdev *bss_cfgdev;  /* For DUAL STA/STA+AP */
690         s32 cfgdev_bssidx;
691         bool bss_pending_op;            /* indicate where there is a pending IF operation */
692         int roam_offload;
693 #ifdef WL_NAN
694         bool nan_enable;
695         bool nan_running;
696 #endif /* WL_NAN */
697 #ifdef WL_CFG80211_P2P_DEV_IF
698         bool down_disc_if;
699 #endif /* WL_CFG80211_P2P_DEV_IF */
700 #ifdef P2PLISTEN_AP_SAMECHN
701         bool p2p_resp_apchn_status;
702 #endif /* P2PLISTEN_AP_SAMECHN */
703         struct wl_wsec_key wep_key;
704 #ifdef WLTDLS
705         u8 *tdls_mgmt_frame;
706         u32 tdls_mgmt_frame_len;
707         s32 tdls_mgmt_freq;
708 #endif /* WLTDLS */
709         bool need_wait_afrx;
710 #ifdef QOS_MAP_SET
711         uint8    *up_table;     /* user priority table, size is UP_TABLE_MAX */
712 #endif /* QOS_MAP_SET */
713         struct ether_addr last_roamed_addr;
714 #ifdef DHD_LOSSLESS_ROAMING
715         struct timer_list roam_timeout;   /* Timer for catch roam timeout */
716 #endif
717         bool rcc_enabled;       /* flag for Roam channel cache feature */
718 #if defined(DHD_ENABLE_BIGDATA_LOGGING)
719         char bss_info[GET_BSS_INFO_LEN];
720         wl_event_msg_t event_auth_assoc;
721         u32 assoc_reject_status;
722         u32 roam_count;
723 #endif /* DHD_ENABLE_BIGDATA_LOGGING */
724         u16 ap_oper_channel;
725         bool revert_ndo_disable;
726 #if defined(SUPPORT_RANDOM_MAC_SCAN)
727         bool random_mac_enabled;
728 #endif /* SUPPORT_RANDOM_MAC_SCAN */
729         int p2p_disconnected; // terence 20130703: Fix for wrong group_capab (timing issue)
730         struct ether_addr disconnected_bssid;
731 };
732
733 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
734         4 && __GNUC_MINOR__ >= 6))
735
736 #define BCM_LIST_FOR_EACH_ENTRY_SAFE(pos, next, head, member) \
737 _Pragma("GCC diagnostic push") \
738 _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
739 list_for_each_entry_safe((pos), (next), (head), member) \
740 _Pragma("GCC diagnostic pop") \
741
742 #else
743 #define BCM_LIST_FOR_EACH_ENTRY_SAFE(pos, next, head, member) \
744 list_for_each_entry_safe((pos), (next), (head), member) \
745
746 #endif /* STRICT_GCC_WARNINGS */
747
748 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
749 {
750         return bss = bss ?
751                 (struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
752 }
753
754 static inline void
755 wl_probe_wdev_all(struct bcm_cfg80211 *cfg)
756 {
757         struct net_info *_net_info, *next;
758         unsigned long int flags;
759         int idx = 0;
760         spin_lock_irqsave(&cfg->net_list_sync, flags);
761         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next,
762                 &cfg->net_list, list) {
763                 WL_ERR(("%s: net_list[%d] bssidx: %d, "
764                         "ndev: %p, wdev: %p \n", __FUNCTION__,
765                         idx++, _net_info->bssidx,
766                         _net_info->ndev, _net_info->wdev));
767         }
768         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
769         return;
770 }
771
772 static inline struct net_info *
773 wl_get_netinfo_by_bssidx(struct bcm_cfg80211 *cfg, s32 bssidx)
774 {
775         struct net_info *_net_info, *next, *info = NULL;
776         unsigned long int flags;
777
778         spin_lock_irqsave(&cfg->net_list_sync, flags);
779         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
780                 if ((bssidx >= 0) && (_net_info->bssidx == bssidx)) {
781                         info = _net_info;
782                         break;
783                 }
784         }
785         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
786         return info;
787 }
788
789 static inline void
790 wl_dealloc_netinfo_by_wdev(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev)
791 {
792         struct net_info *_net_info, *next;
793         unsigned long int flags;
794
795 #ifdef DHD_IFDEBUG
796         WL_ERR(("dealloc_netinfo enter wdev=%p \n", wdev));
797 #endif
798         spin_lock_irqsave(&cfg->net_list_sync, flags);
799         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
800                 if (wdev && (_net_info->wdev == wdev)) {
801                         wl_cfgbss_t *bss = &_net_info->bss;
802
803                         kfree(bss->wpa_ie);
804                         bss->wpa_ie = NULL;
805                         kfree(bss->rsn_ie);
806                         bss->rsn_ie = NULL;
807                         kfree(bss->wps_ie);
808                         bss->wps_ie = NULL;
809                         list_del(&_net_info->list);
810                         cfg->iface_cnt--;
811                         kfree(_net_info);
812                 }
813         }
814         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
815 #ifdef DHD_IFDEBUG
816         WL_ERR(("dealloc_netinfo exit iface_cnt=%d \n", cfg->iface_cnt));
817 #endif
818 }
819
820 static inline s32
821 wl_alloc_netinfo(struct bcm_cfg80211 *cfg, struct net_device *ndev,
822         struct wireless_dev * wdev, s32 mode, bool pm_block, u8 bssidx)
823 {
824         struct net_info *_net_info;
825         s32 err = 0;
826         unsigned long int flags;
827 #ifdef DHD_IFDEBUG
828         WL_ERR(("alloc_netinfo enter bssidx=%d wdev=%p ndev=%p\n", bssidx, wdev, ndev));
829 #endif
830         /* Check whether there is any duplicate entry for the
831          *  same bssidx *
832          */
833         if ((_net_info = wl_get_netinfo_by_bssidx(cfg, bssidx))) {
834                 /* We have a duplicate entry for the same bssidx
835                  * already present which shouldn't have been the case.
836                  * Attempt recovery.
837                  */
838                 WL_ERR(("Duplicate entry for bssidx=%d present\n", bssidx));
839                 wl_probe_wdev_all(cfg);
840 #ifdef DHD_DEBUG
841                 ASSERT(0);
842 #endif /* DHD_DEBUG */
843                 WL_ERR(("Removing the Dup entry for bssidx=%d \n", bssidx));
844                 wl_dealloc_netinfo_by_wdev(cfg, _net_info->wdev);
845         }
846         if (cfg->iface_cnt == IFACE_MAX_CNT)
847                 return -ENOMEM;
848         _net_info = kzalloc(sizeof(struct net_info), GFP_KERNEL);
849         if (!_net_info)
850                 err = -ENOMEM;
851         else {
852                 _net_info->mode = mode;
853                 _net_info->ndev = ndev;
854                 _net_info->wdev = wdev;
855                 _net_info->pm_restore = 0;
856                 _net_info->pm = 0;
857                 _net_info->pm_block = pm_block;
858                 _net_info->roam_off = WL_INVALID;
859                 _net_info->bssidx = bssidx;
860                 spin_lock_irqsave(&cfg->net_list_sync, flags);
861                 cfg->iface_cnt++;
862                 list_add(&_net_info->list, &cfg->net_list);
863                 spin_unlock_irqrestore(&cfg->net_list_sync, flags);
864         }
865 #ifdef DHD_IFDEBUG
866         WL_ERR(("alloc_netinfo exit iface_cnt=%d \n", cfg->iface_cnt));
867 #endif
868         return err;
869 }
870
871 static inline void
872 wl_delete_all_netinfo(struct bcm_cfg80211 *cfg)
873 {
874         struct net_info *_net_info, *next;
875         unsigned long int flags;
876
877         spin_lock_irqsave(&cfg->net_list_sync, flags);
878         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
879                 wl_cfgbss_t *bss = &_net_info->bss;
880
881                 kfree(bss->wpa_ie);
882                 bss->wpa_ie = NULL;
883                 kfree(bss->rsn_ie);
884                 bss->rsn_ie = NULL;
885                 kfree(bss->wps_ie);
886                 bss->wps_ie = NULL;
887                 list_del(&_net_info->list);
888                 if (_net_info->wdev)
889                         kfree(_net_info->wdev);
890                 kfree(_net_info);
891         }
892         cfg->iface_cnt = 0;
893         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
894 }
895 static inline u32
896 wl_get_status_all(struct bcm_cfg80211 *cfg, s32 status)
897
898 {
899         struct net_info *_net_info, *next;
900         u32 cnt = 0;
901         unsigned long int flags;
902
903         spin_lock_irqsave(&cfg->net_list_sync, flags);
904         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
905                 if (_net_info->ndev &&
906                         test_bit(status, &_net_info->sme_state))
907                         cnt++;
908         }
909         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
910         return cnt;
911 }
912 static inline void
913 wl_set_status_all(struct bcm_cfg80211 *cfg, s32 status, u32 op)
914 {
915         struct net_info *_net_info, *next;
916         unsigned long int flags;
917
918         spin_lock_irqsave(&cfg->net_list_sync, flags);
919         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
920                 switch (op) {
921                         case 1:
922                                 break; /* set all status is not allowed */
923                         case 2:
924                                 /*
925                                  * Release the spinlock before calling notifier. Else there
926                                  * will be nested calls
927                                  */
928                                 spin_unlock_irqrestore(&cfg->net_list_sync, flags);
929                                 clear_bit(status, &_net_info->sme_state);
930                                 if (cfg->state_notifier &&
931                                         test_bit(status, &(cfg->interrested_state)))
932                                         cfg->state_notifier(cfg, _net_info, status, false);
933                                 return;
934                         case 4:
935                                 break; /* change all status is not allowed */
936                         default:
937                                 break; /* unknown operation */
938                 }
939         }
940         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
941 }
942 static inline void
943 wl_set_status_by_netdev(struct bcm_cfg80211 *cfg, s32 status,
944         struct net_device *ndev, u32 op)
945 {
946
947         struct net_info *_net_info, *next;
948         unsigned long int flags;
949
950         spin_lock_irqsave(&cfg->net_list_sync, flags);
951         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
952                 if (ndev && (_net_info->ndev == ndev)) {
953                         switch (op) {
954                                 case 1:
955                                         /*
956                                          * Release the spinlock before calling notifier. Else there
957                                          * will be nested calls
958                                          */
959                                         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
960                                         set_bit(status, &_net_info->sme_state);
961                                         if (cfg->state_notifier &&
962                                                 test_bit(status, &(cfg->interrested_state)))
963                                                 cfg->state_notifier(cfg, _net_info, status, true);
964                                         return;
965                                 case 2:
966                                         /*
967                                          * Release the spinlock before calling notifier. Else there
968                                          * will be nested calls
969                                          */
970                                         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
971                                         clear_bit(status, &_net_info->sme_state);
972                                         if (cfg->state_notifier &&
973                                                 test_bit(status, &(cfg->interrested_state)))
974                                                 cfg->state_notifier(cfg, _net_info, status, false);
975                                         return;
976                                 case 4:
977                                         change_bit(status, &_net_info->sme_state);
978                                         break;
979                         }
980                 }
981
982         }
983         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
984
985 }
986
987 static inline wl_cfgbss_t *
988 wl_get_cfgbss_by_wdev(struct bcm_cfg80211 *cfg,
989         struct wireless_dev *wdev)
990 {
991         struct net_info *_net_info, *next;
992         wl_cfgbss_t *bss = NULL;
993         unsigned long int flags;
994
995         spin_lock_irqsave(&cfg->net_list_sync, flags);
996         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
997                 if (wdev && (_net_info->wdev == wdev)) {
998                         bss = &_net_info->bss;
999                         break;
1000                 }
1001         }
1002
1003         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1004         return bss;
1005 }
1006
1007 static inline u32
1008 wl_get_status_by_netdev(struct bcm_cfg80211 *cfg, s32 status,
1009         struct net_device *ndev)
1010 {
1011         struct net_info *_net_info, *next;
1012         u32 stat = 0;
1013         unsigned long int flags;
1014
1015         spin_lock_irqsave(&cfg->net_list_sync, flags);
1016         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1017                 if (ndev && (_net_info->ndev == ndev)) {
1018                         stat = test_bit(status, &_net_info->sme_state);
1019                         break;
1020                 }
1021         }
1022         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1023         return stat;
1024 }
1025
1026 static inline s32
1027 wl_get_mode_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev)
1028 {
1029         struct net_info *_net_info, *next;
1030         s32 mode = -1;
1031         unsigned long int flags;
1032
1033         spin_lock_irqsave(&cfg->net_list_sync, flags);
1034         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1035                 if (ndev && (_net_info->ndev == ndev)) {
1036                         mode = _net_info->mode;
1037                         break;
1038                 }
1039         }
1040         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1041         return mode;
1042 }
1043
1044 static inline void
1045 wl_set_mode_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev,
1046         s32 mode)
1047 {
1048         struct net_info *_net_info, *next;
1049         unsigned long int flags;
1050
1051         spin_lock_irqsave(&cfg->net_list_sync, flags);
1052         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1053                 if (ndev && (_net_info->ndev == ndev))
1054                         _net_info->mode = mode;
1055         }
1056         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1057 }
1058
1059 static inline s32
1060 wl_get_bssidx_by_wdev(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev)
1061 {
1062         struct net_info *_net_info, *next;
1063         s32 bssidx = -1;
1064         unsigned long int flags;
1065
1066         spin_lock_irqsave(&cfg->net_list_sync, flags);
1067         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1068                 if (_net_info->wdev && (_net_info->wdev == wdev)) {
1069                         bssidx = _net_info->bssidx;
1070                         break;
1071                 }
1072         }
1073         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1074         return bssidx;
1075 }
1076
1077 static inline struct wireless_dev *
1078 wl_get_wdev_by_bssidx(struct bcm_cfg80211 *cfg, s32 bssidx)
1079 {
1080         struct net_info *_net_info, *next;
1081         struct wireless_dev *wdev = NULL;
1082         unsigned long int flags;
1083
1084         if (bssidx < 0)
1085                 return NULL;
1086         spin_lock_irqsave(&cfg->net_list_sync, flags);
1087         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1088                 if (_net_info->bssidx == bssidx) {
1089                                 wdev = _net_info->wdev;
1090                                 break;
1091                 }
1092         }
1093         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1094         return wdev;
1095 }
1096
1097 static inline struct wl_profile *
1098 wl_get_profile_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev)
1099 {
1100         struct net_info *_net_info, *next;
1101         struct wl_profile *prof = NULL;
1102         unsigned long int flags;
1103
1104         spin_lock_irqsave(&cfg->net_list_sync, flags);
1105         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1106                 if (ndev && (_net_info->ndev == ndev)) {
1107                         prof = &_net_info->profile;
1108                         break;
1109                 }
1110         }
1111         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1112         return prof;
1113 }
1114 static inline struct net_info *
1115 wl_get_netinfo_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev)
1116 {
1117         struct net_info *_net_info, *next, *info = NULL;
1118         unsigned long int flags;
1119
1120         spin_lock_irqsave(&cfg->net_list_sync, flags);
1121         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1122                 if (ndev && (_net_info->ndev == ndev)) {
1123                         info = _net_info;
1124                         break;
1125                 }
1126         }
1127         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1128         return info;
1129 }
1130
1131 static inline struct net_info *
1132 wl_get_netinfo_by_wdev(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev)
1133 {
1134         struct net_info *_net_info, *next, *info = NULL;
1135         unsigned long int flags;
1136
1137         spin_lock_irqsave(&cfg->net_list_sync, flags);
1138         BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
1139                 if (wdev && (_net_info->wdev == wdev)) {
1140                         info = _net_info;
1141                         break;
1142                 }
1143         }
1144         spin_unlock_irqrestore(&cfg->net_list_sync, flags);
1145         return info;
1146 }
1147
1148 #define is_p2p_group_iface(wdev) (((wdev->iftype == NL80211_IFTYPE_P2P_GO) || \
1149                 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) ? 1 : 0)
1150 #define bcmcfg_to_wiphy(cfg) (cfg->wdev->wiphy)
1151 #define bcmcfg_to_prmry_ndev(cfg) (cfg->wdev->netdev)
1152 #define bcmcfg_to_prmry_wdev(cfg) (cfg->wdev)
1153 #define bcmcfg_to_p2p_wdev(cfg) (cfg->p2p_wdev)
1154 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
1155 #define ndev_to_wdev(ndev) (ndev->ieee80211_ptr)
1156 #define wdev_to_ndev(wdev) (wdev->netdev)
1157
1158 #if defined(WL_ENABLE_P2P_IF)
1159 #define ndev_to_wlc_ndev(ndev, cfg)     ((ndev == cfg->p2p_net) ? \
1160         bcmcfg_to_prmry_ndev(cfg) : ndev)
1161 #else
1162 #define ndev_to_wlc_ndev(ndev, cfg)     (ndev)
1163 #endif /* WL_ENABLE_P2P_IF */
1164
1165 #define wdev_to_wlc_ndev(wdev, cfg)     \
1166         (wdev_to_ndev(wdev) ? \
1167         wdev_to_ndev(wdev) : bcmcfg_to_prmry_ndev(cfg))
1168 #if defined(WL_CFG80211_P2P_DEV_IF)
1169 #define cfgdev_to_wlc_ndev(cfgdev, cfg) wdev_to_wlc_ndev(cfgdev, cfg)
1170 #define bcmcfg_to_prmry_cfgdev(cfgdev, cfg) bcmcfg_to_prmry_wdev(cfg)
1171 #elif defined(WL_ENABLE_P2P_IF)
1172 #define cfgdev_to_wlc_ndev(cfgdev, cfg) ndev_to_wlc_ndev(cfgdev, cfg)
1173 #define bcmcfg_to_prmry_cfgdev(cfgdev, cfg) bcmcfg_to_prmry_ndev(cfg)
1174 #else
1175 #define cfgdev_to_wlc_ndev(cfgdev, cfg) (cfgdev)
1176 #define bcmcfg_to_prmry_cfgdev(cfgdev, cfg) (cfgdev)
1177 #endif /* WL_CFG80211_P2P_DEV_IF */
1178
1179 #if defined(WL_CFG80211_P2P_DEV_IF)
1180 #define cfgdev_to_wdev(cfgdev)  (cfgdev)
1181 #define ndev_to_cfgdev(ndev)    ndev_to_wdev(ndev)
1182 #define cfgdev_to_ndev(cfgdev)  (cfgdev ? (cfgdev->netdev) : NULL)
1183 #define wdev_to_cfgdev(cfgdev)  (cfgdev)
1184 #define discover_cfgdev(cfgdev, cfg) (cfgdev->iftype == NL80211_IFTYPE_P2P_DEVICE)
1185 #else
1186 #define cfgdev_to_wdev(cfgdev)  (cfgdev->ieee80211_ptr)
1187 #define wdev_to_cfgdev(cfgdev)  cfgdev ? (cfgdev->netdev) : NULL
1188 #define ndev_to_cfgdev(ndev)    (ndev)
1189 #define cfgdev_to_ndev(cfgdev)  (cfgdev)
1190 #define discover_cfgdev(cfgdev, cfg) (cfgdev == cfg->p2p_net)
1191 #endif /* WL_CFG80211_P2P_DEV_IF */
1192
1193 #if defined(WL_CFG80211_P2P_DEV_IF)
1194 #define scan_req_match(cfg)     (((cfg) && (cfg->scan_request) && \
1195         (cfg->scan_request->wdev == cfg->p2p_wdev)) ? true : false)
1196 #elif defined(WL_ENABLE_P2P_IF)
1197 #define scan_req_match(cfg)     (((cfg) && (cfg->scan_request) && \
1198         (cfg->scan_request->dev == cfg->p2p_net)) ? true : false)
1199 #else
1200 #define scan_req_match(cfg)     (((cfg) && p2p_is_on(cfg) && p2p_scan(cfg)) ? \
1201         true : false)
1202 #endif /* WL_CFG80211_P2P_DEV_IF */
1203
1204 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
1205 #define scan_req_iftype(req) (req->dev->ieee80211_ptr->iftype)
1206 #else
1207 #define scan_req_iftype(req) (req->wdev->iftype)
1208 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0) */
1209
1210 #define wl_to_sr(w) (w->scan_req_int)
1211 #if defined(STATIC_WL_PRIV_STRUCT)
1212 #define wl_to_ie(w) (w->ie)
1213 #define wl_to_conn(w) (w->conn_info)
1214 #else
1215 #define wl_to_ie(w) (&w->ie)
1216 #define wl_to_conn(w) (&w->conn_info)
1217 #endif
1218 #define wiphy_from_scan(w) (w->escan_info.wiphy)
1219 #define wl_get_drv_status_all(cfg, stat) \
1220         (wl_get_status_all(cfg, WL_STATUS_ ## stat))
1221 #define wl_get_drv_status(cfg, stat, ndev)  \
1222         (wl_get_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev))
1223 #define wl_set_drv_status(cfg, stat, ndev)  \
1224         (wl_set_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev, 1))
1225 #define wl_clr_drv_status(cfg, stat, ndev)  \
1226         (wl_set_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev, 2))
1227 #define wl_clr_drv_status_all(cfg, stat)  \
1228         (wl_set_status_all(cfg, WL_STATUS_ ## stat, 2))
1229 #define wl_chg_drv_status(cfg, stat, ndev)  \
1230         (wl_set_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev, 4))
1231
1232 #define for_each_bss(list, bss, __i)    \
1233         for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
1234
1235 #define for_each_ndev(cfg, iter, next) \
1236         list_for_each_entry_safe(iter, next, &cfg->net_list, list)
1237
1238 /* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0.
1239  * In addtion to that, wpa_version is WPA_VERSION_1
1240  */
1241 #define is_wps_conn(_sme) \
1242         ((wl_cfgp2p_find_wpsie((u8 *)_sme->ie, _sme->ie_len) != NULL) && \
1243          (!_sme->crypto.n_ciphers_pairwise) && \
1244          (!_sme->crypto.cipher_group))
1245
1246 #define IS_AKM_SUITE_FT(sec) false
1247
1248 #define IS_AKM_SUITE_CCKM(sec) false
1249
1250 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
1251 #define STA_INFO_BIT(info) (1ul << NL80211_STA_ ## info)
1252 #define strnicmp(str1, str2, len) strncasecmp((str1), (str2), (len))
1253 #else
1254 #define STA_INFO_BIT(info) (STATION_ ## info)
1255 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) */
1256
1257 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *context);
1258 extern s32 wl_cfg80211_attach_post(struct net_device *ndev);
1259 extern void wl_cfg80211_detach(void *para);
1260
1261 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
1262             void *data);
1263 void wl_cfg80211_set_parent_dev(void *dev);
1264 struct device *wl_cfg80211_get_parent_dev(void);
1265
1266 /* clear IEs */
1267 extern s32 wl_cfg80211_clear_mgmt_vndr_ies(struct bcm_cfg80211 *cfg);
1268 extern s32 wl_cfg80211_clear_per_bss_ies(struct bcm_cfg80211 *cfg, s32 bssidx);
1269
1270 extern s32 wl_cfg80211_up(void *para);
1271 extern s32 wl_cfg80211_down(void *para);
1272 extern s32 wl_cfg80211_notify_ifadd(int ifidx, char *name, uint8 *mac, uint8 bssidx);
1273 extern s32 wl_cfg80211_notify_ifdel(int ifidx, char *name, uint8 *mac, uint8 bssidx);
1274 extern s32 wl_cfg80211_notify_ifchange(int ifidx, char *name, uint8 *mac, uint8 bssidx);
1275 extern struct net_device* wl_cfg80211_allocate_if(struct bcm_cfg80211 *cfg, int ifidx, char *name,
1276         uint8 *mac, uint8 bssidx, char *dngl_name);
1277 extern int wl_cfg80211_register_if(struct bcm_cfg80211 *cfg, int ifidx, struct net_device* ndev);
1278 extern int wl_cfg80211_remove_if(struct bcm_cfg80211 *cfg, int ifidx, struct net_device* ndev);
1279 extern int wl_cfg80211_scan_stop(bcm_struct_cfgdev *cfgdev);
1280 extern bool wl_cfg80211_is_concurrent_mode(void);
1281 extern void* wl_cfg80211_get_dhdp(void);
1282 extern bool wl_cfg80211_is_p2p_active(void);
1283 extern bool wl_cfg80211_is_roam_offload(void);
1284 extern bool wl_cfg80211_is_event_from_connected_bssid(const wl_event_msg_t *e, int ifidx);
1285 extern void wl_cfg80211_dbg_level(u32 level);
1286 extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
1287 extern s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len);
1288 extern s32 wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len);
1289 extern s32 wl_cfg80211_set_wps_p2p_ie(struct net_device *net, char *buf, int len,
1290         enum wl_management_type type);
1291 extern s32 wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len);
1292 extern s32 wl_cfg80211_set_p2p_ecsa(struct net_device *net, char* buf, int len);
1293 #ifdef WL11ULB
1294 extern s32 wl_cfg80211_set_ulb_mode(struct net_device *dev, int mode);
1295 extern s32 wl_cfg80211_set_ulb_bw(struct net_device *dev,
1296         u32 ulb_bw,  char *ifname);
1297 #endif /* WL11ULB */
1298 #ifdef P2PLISTEN_AP_SAMECHN
1299 extern s32 wl_cfg80211_set_p2p_resp_ap_chn(struct net_device *net, s32 enable);
1300 #endif /* P2PLISTEN_AP_SAMECHN */
1301
1302 /* btcoex functions */
1303 void* wl_cfg80211_btcoex_init(struct net_device *ndev);
1304 void wl_cfg80211_btcoex_deinit(void);
1305
1306 #ifdef WL_SUPPORT_AUTO_CHANNEL
1307 #define CHANSPEC_BUF_SIZE       1024
1308 #define CHAN_SEL_IOCTL_DELAY    300
1309 #define CHAN_SEL_RETRY_COUNT    15
1310 #define CHANNEL_IS_RADAR(channel)       (((channel & WL_CHAN_RADAR) || \
1311         (channel & WL_CHAN_PASSIVE)) ? true : false)
1312 #define CHANNEL_IS_2G(channel)  (((channel >= 1) && (channel <= 14)) ? \
1313         true : false)
1314 #define CHANNEL_IS_5G(channel)  (((channel >= 36) && (channel <= 165)) ? \
1315         true : false)
1316 extern s32 wl_cfg80211_get_best_channels(struct net_device *dev, char* command,
1317         int total_len);
1318 #endif /* WL_SUPPORT_AUTO_CHANNEL */
1319 extern int wl_cfg80211_ether_atoe(const char *a, struct ether_addr *n);
1320 extern int wl_cfg80211_hang(struct net_device *dev, u16 reason);
1321 extern s32 wl_mode_to_nl80211_iftype(s32 mode);
1322 int wl_cfg80211_do_driver_init(struct net_device *net);
1323 void wl_cfg80211_enable_trace(u32 level);
1324 extern s32 wl_update_wiphybands(struct bcm_cfg80211 *cfg, bool notify);
1325 extern s32 wl_cfg80211_if_is_group_owner(void);
1326 extern chanspec_t wl_chspec_host_to_driver(chanspec_t chanspec);
1327 extern chanspec_t wl_ch_host_to_driver(s32 bssidx, u16 channel);
1328 extern s32 wl_set_tx_power(struct net_device *dev,
1329         enum nl80211_tx_power_setting type, s32 dbm);
1330 extern s32 wl_get_tx_power(struct net_device *dev, s32 *dbm);
1331 extern s32 wl_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add);
1332 extern void wl_stop_wait_next_action_frame(struct bcm_cfg80211 *cfg, struct net_device *ndev);
1333 extern void wl_cfg80211_add_to_eventbuffer(wl_eventmsg_buf_t *ev, u16 event, bool set);
1334 extern s32 wl_cfg80211_apply_eventbuffer(struct net_device *ndev,
1335         struct bcm_cfg80211 *cfg, wl_eventmsg_buf_t *ev);
1336 extern void get_primary_mac(struct bcm_cfg80211 *cfg, struct ether_addr *mac);
1337 extern void wl_cfg80211_update_power_mode(struct net_device *dev);
1338 extern void wl_cfg80211_set_passive_scan(struct net_device *dev, char *command);
1339 extern void wl_terminate_event_handler(void);
1340 #if defined(DHD_ENABLE_BIGDATA_LOGGING)
1341 extern s32 wl_cfg80211_get_bss_info(struct net_device *dev, char* cmd, int total_len);
1342 extern s32 wl_cfg80211_get_connect_failed_status(struct net_device *dev, char* cmd, int total_len);
1343 #endif /* DHD_ENABLE_BIGDATA_LOGGING */
1344
1345 #define SCAN_BUF_CNT    2
1346 #define SCAN_BUF_NEXT   1
1347 #define WL_SCANTYPE_LEGACY      0x1
1348 #define WL_SCANTYPE_P2P         0x2
1349 #define wl_escan_set_sync_id(a, b) ((a) = htod16(0x1234))
1350 #define wl_escan_set_type(a, b)
1351 #define wl_escan_get_buf(a, b) ((wl_scan_results_t *) (a)->escan_info.escan_buf)
1352 #define wl_escan_check_sync_id(a, b, c) 0
1353 #define wl_escan_print_sync_id(a, b, c)
1354 #define wl_escan_increment_sync_id(a, b)
1355 #define wl_escan_init_sync_id(a)
1356 extern void wl_cfg80211_ibss_vsie_set_buffer(vndr_ie_setbuf_t *ibss_vsie, int ibss_vsie_len);
1357 extern s32 wl_cfg80211_ibss_vsie_delete(struct net_device *dev);
1358 extern void wl_cfg80211_set_rmc_pid(int pid);
1359 extern int wl_cfg80211_set_mgmt_vndr_ies(struct bcm_cfg80211 *cfg,
1360         bcm_struct_cfgdev *cfgdev, s32 bssidx, s32 pktflag,
1361         const u8 *vndr_ie, u32 vndr_ie_len);
1362
1363
1364 /* Action frame specific functions */
1365 extern u8 wl_get_action_category(void *frame, u32 frame_len);
1366 extern int wl_get_public_action(void *frame, u32 frame_len, u8 *ret_action);
1367
1368 #ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
1369 struct net_device *wl_cfg80211_get_remain_on_channel_ndev(struct bcm_cfg80211 *cfg);
1370 #endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
1371
1372 #ifdef WL_SUPPORT_ACS
1373 #define ACS_MSRMNT_DELAY 1000 /* dump_obss delay in ms */
1374 #define IOCTL_RETRY_COUNT 5
1375 #define CHAN_NOISE_DUMMY -80
1376 #define OBSS_TOKEN_IDX 15
1377 #define IBSS_TOKEN_IDX 15
1378 #define TX_TOKEN_IDX 14
1379 #define CTG_TOKEN_IDX 13
1380 #define PKT_TOKEN_IDX 15
1381 #define IDLE_TOKEN_IDX 12
1382 #endif /* WL_SUPPORT_ACS */
1383
1384 extern int wl_cfg80211_get_ioctl_version(void);
1385 extern int wl_cfg80211_enable_roam_offload(struct net_device *dev, int enable);
1386 extern s32 wl_cfg80211_dfs_ap_move(struct net_device *ndev, char *data,
1387                 char *command, int total_len);
1388 extern s32 wl_cfg80211_wbtext_config(struct net_device *ndev, char *data,
1389                 char *command, int total_len);
1390 extern int wl_cfg80211_wbtext_weight_config(struct net_device *ndev, char *data,
1391                 char *command, int total_len);
1392 extern int wl_cfg80211_wbtext_table_config(struct net_device *ndev, char *data,
1393                 char *command, int total_len);
1394 extern s32 wl_cfg80211_wbtext_delta_config(struct net_device *ndev, char *data,
1395                 char *command, int total_len);
1396 extern s32 wl_cfg80211_get_chanspecs_2g(struct net_device *ndev,
1397                 void *buf, s32 buflen);
1398 extern s32 wl_cfg80211_get_chanspecs_5g(struct net_device *ndev,
1399                 void *buf, s32 buflen);
1400 #if defined(WL_VIRTUAL_APSTA)
1401 extern int wl_cfg80211_interface_create(struct net_device *dev, char *name);
1402 extern int wl_cfg80211_interface_delete(struct net_device *dev, char *name);
1403 #endif /* defined (WL_VIRTUAL_APSTA) */
1404
1405 #ifdef WL_NAN
1406 extern int wl_cfg80211_nan_cmd_handler(struct net_device *ndev, char *cmd,
1407         int cmd_len);
1408 #endif /* WL_NAN */
1409
1410 #ifdef WL_CFG80211_P2P_DEV_IF
1411 extern void wl_cfg80211_del_p2p_wdev(void);
1412 #endif /* WL_CFG80211_P2P_DEV_IF */
1413
1414 #if defined(WL_SUPPORT_AUTO_CHANNEL)
1415 extern int wl_cfg80211_set_spect(struct net_device *dev, int spect);
1416 extern int wl_cfg80211_get_sta_channel(void);
1417 #endif /* WL_SUPPORT_AUTO_CHANNEL */
1418
1419 #ifdef P2P_LISTEN_OFFLOADING
1420 extern s32 wl_cfg80211_p2plo_listen_start(struct net_device *dev, u8 *buf, int len);
1421 extern s32 wl_cfg80211_p2plo_listen_stop(struct net_device *dev);
1422 #endif /* P2P_LISTEN_OFFLOADING */
1423
1424 #define RETURN_EIO_IF_NOT_UP(wlpriv)                        \
1425 do {                                    \
1426         struct net_device *checkSysUpNDev = bcmcfg_to_prmry_ndev(wlpriv);           \
1427         if (unlikely(!wl_get_drv_status(wlpriv, READY, checkSysUpNDev))) {  \
1428                 WL_INFORM(("device is not ready\n"));           \
1429                 return -EIO;                        \
1430         }                               \
1431 } while (0)
1432
1433 #ifdef QOS_MAP_SET
1434 extern uint8 *wl_get_up_table(void);
1435 #endif /* QOS_MAP_SET */
1436
1437 #define P2PO_COOKIE     65535
1438 u64 wl_cfg80211_get_new_roc_id(struct bcm_cfg80211 *cfg);
1439 #if defined(SUPPORT_RANDOM_MAC_SCAN)
1440 int wl_cfg80211_set_random_mac(struct net_device *dev, bool enable);
1441 int wl_cfg80211_random_mac_enable(struct net_device *dev);
1442 int wl_cfg80211_random_mac_disable(struct net_device *dev);
1443 #endif /* SUPPORT_RANDOM_MAC_SCAN */
1444 int wl_cfg80211_iface_count(void);
1445 int wl_check_dongle_idle(struct wiphy *wiphy);
1446 #endif /* _wl_cfg80211_h_ */