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