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