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