• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Linux cfg80211 driver
3  *
4  * Copyright (C) 1999-2013, Broadcom Corporation
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id: wl_cfg80211.h 418267 2013-08-14 12:49:52Z $
25  */
26 
27 #ifndef _wl_cfg80211_h_
28 #define _wl_cfg80211_h_
29 
30 #include <linux/wireless.h>
31 #include <typedefs.h>
32 #include <proto/ethernet.h>
33 #include <wlioctl.h>
34 #include <linux/wireless.h>
35 #include <net/cfg80211.h>
36 #include <linux/rfkill.h>
37 
38 #include <wl_cfgp2p.h>
39 
40 struct wl_conf;
41 struct wl_iface;
42 struct wl_priv;
43 struct wl_security;
44 struct wl_ibss;
45 
46 
47 #define htod32(i) (i)
48 #define htod16(i) (i)
49 #define dtoh32(i) (i)
50 #define dtoh16(i) (i)
51 #define htodchanspec(i) (i)
52 #define dtohchanspec(i) (i)
53 
54 #define WL_DBG_NONE	0
55 #define WL_DBG_P2P_ACTION (1 << 5)
56 #define WL_DBG_TRACE	(1 << 4)
57 #define WL_DBG_SCAN 	(1 << 3)
58 #define WL_DBG_DBG 	(1 << 2)
59 #define WL_DBG_INFO	(1 << 1)
60 #define WL_DBG_ERR	(1 << 0)
61 
62 /* 0 invalidates all debug messages.  default is 1 */
63 #define WL_DBG_LEVEL 0xFF
64 
65 #define CFG80211_ERROR_TEXT		"CFG80211-ERROR) "
66 
67 #if defined(DHD_DEBUG)
68 #define	WL_ERR(args)									\
69 do {										\
70 	if (wl_dbg_level & WL_DBG_ERR) {				\
71 			printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);	\
72 			printk args;						\
73 		}								\
74 } while (0)
75 #else /* defined(DHD_DEBUG) */
76 #define	WL_ERR(args)									\
77 do {										\
78 	if ((wl_dbg_level & WL_DBG_ERR) && net_ratelimit()) {				\
79 			printk(KERN_INFO CFG80211_ERROR_TEXT "%s : ", __func__);	\
80 			printk args;						\
81 		}								\
82 } while (0)
83 #endif /* defined(DHD_DEBUG) */
84 
85 #ifdef WL_INFO
86 #undef WL_INFO
87 #endif
88 #define	WL_INFO(args)									\
89 do {										\
90 	if (wl_dbg_level & WL_DBG_INFO) {				\
91 			printk(KERN_INFO "CFG80211-INFO) %s : ", __func__);	\
92 			printk args;						\
93 		}								\
94 } while (0)
95 #ifdef WL_SCAN
96 #undef WL_SCAN
97 #endif
98 #define	WL_SCAN(args)								\
99 do {									\
100 	if (wl_dbg_level & WL_DBG_SCAN) {			\
101 		printk(KERN_INFO "CFG80211-SCAN) %s :", __func__);	\
102 		printk args;							\
103 	}									\
104 } while (0)
105 #ifdef WL_TRACE
106 #undef WL_TRACE
107 #endif
108 #define	WL_TRACE(args)								\
109 do {									\
110 	if (wl_dbg_level & WL_DBG_TRACE) {			\
111 		printk(KERN_INFO "CFG80211-TRACE) %s :", __func__);	\
112 		printk args;							\
113 	}									\
114 } while (0)
115 #ifdef WL_TRACE_HW4
116 #undef WL_TRACE_HW4
117 #endif
118 #define	WL_TRACE_HW4			WL_TRACE
119 #if (WL_DBG_LEVEL > 0)
120 #define	WL_DBG(args)								\
121 do {									\
122 	if (wl_dbg_level & WL_DBG_DBG) {			\
123 		printk(KERN_DEBUG "CFG80211-DEBUG) %s :", __func__);	\
124 		printk args;							\
125 	}									\
126 } while (0)
127 #else				/* !(WL_DBG_LEVEL > 0) */
128 #define	WL_DBG(args)
129 #endif				/* (WL_DBG_LEVEL > 0) */
130 #define WL_PNO(x)
131 #define WL_SD(x)
132 
133 
134 #define WL_SCAN_RETRY_MAX	3
135 #define WL_NUM_PMKIDS_MAX	MAXPMKID
136 #define WL_SCAN_BUF_MAX 	(1024 * 8)
137 #define WL_TLV_INFO_MAX 	1500
138 #define WL_SCAN_IE_LEN_MAX      2048
139 #define WL_BSS_INFO_MAX		2048
140 #define WL_ASSOC_INFO_MAX	512
141 #define WL_IOCTL_LEN_MAX	2048
142 #define WL_EXTRA_BUF_MAX	2048
143 #define WL_ISCAN_BUF_MAX	2048
144 #define WL_ISCAN_TIMER_INTERVAL_MS	3000
145 #define WL_SCAN_ERSULTS_LAST 	(WL_SCAN_RESULTS_NO_MEM+1)
146 #define WL_AP_MAX		256
147 #define WL_FILE_NAME_MAX	256
148 #define WL_DWELL_TIME 		200
149 #define WL_MED_DWELL_TIME       400
150 #define WL_MIN_DWELL_TIME	100
151 #define WL_LONG_DWELL_TIME 	1000
152 #define IFACE_MAX_CNT 		2
153 #define WL_SCAN_CONNECT_DWELL_TIME_MS 		200
154 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 		20
155 #define WL_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 	320
156 #define WL_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 	400
157 #define WL_AF_TX_MAX_RETRY 	5
158 
159 #define WL_AF_SEARCH_TIME_MAX           450
160 #define WL_AF_TX_EXTRA_TIME_MAX         200
161 
162 #define WL_SCAN_TIMER_INTERVAL_MS	8000 /* Scan timeout */
163 #define WL_CHANNEL_SYNC_RETRY 	5
164 #define WL_INVALID 		-1
165 
166 /* Bring down SCB Timeout to 20secs from 60secs default */
167 #ifndef WL_SCB_TIMEOUT
168 #define WL_SCB_TIMEOUT 20
169 #endif
170 
171 /* SCAN_SUPPRESS timer values in ms */
172 #define WL_SCAN_SUPPRESS_TIMEOUT 31000 /* default Framwork DHCP timeout is 30 sec */
173 #define WL_SCAN_SUPPRESS_RETRY 3000
174 
175 #define WL_PM_ENABLE_TIMEOUT 3000
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 /* driver iscan state */
238 enum wl_iscan_state {
239 	WL_ISCAN_STATE_IDLE,
240 	WL_ISCAN_STATE_SCANING
241 };
242 
243 /* donlge escan state */
244 enum wl_escan_state {
245     WL_ESCAN_STATE_IDLE,
246     WL_ESCAN_STATE_SCANING
247 };
248 /* fw downloading status */
249 enum wl_fw_status {
250 	WL_FW_LOADING_DONE,
251 	WL_NVRAM_LOADING_DONE
252 };
253 
254 enum wl_management_type {
255 	WL_BEACON = 0x1,
256 	WL_PROBE_RESP = 0x2,
257 	WL_ASSOC_RESP = 0x4
258 };
259 /* beacon / probe_response */
260 struct beacon_proberesp {
261 	__le64 timestamp;
262 	__le16 beacon_int;
263 	__le16 capab_info;
264 	u8 variable[0];
265 } __attribute__ ((packed));
266 
267 /* driver configuration */
268 struct wl_conf {
269 	u32 frag_threshold;
270 	u32 rts_threshold;
271 	u32 retry_short;
272 	u32 retry_long;
273 	s32 tx_power;
274 	struct ieee80211_channel channel;
275 };
276 
277 typedef s32(*EVENT_HANDLER) (struct wl_priv *wl, bcm_struct_cfgdev *cfgdev,
278                             const wl_event_msg_t *e, void *data);
279 
280 /* bss inform structure for cfg80211 interface */
281 struct wl_cfg80211_bss_info {
282 	u16 band;
283 	u16 channel;
284 	s16 rssi;
285 	u16 frame_len;
286 	u8 frame_buf[1];
287 };
288 
289 /* basic structure of scan request */
290 struct wl_scan_req {
291 	struct wlc_ssid ssid;
292 };
293 
294 /* basic structure of information element */
295 struct wl_ie {
296 	u16 offset;
297 	u8 buf[WL_TLV_INFO_MAX];
298 };
299 
300 /* event queue for cfg80211 main event */
301 struct wl_event_q {
302 	struct list_head eq_list;
303 	u32 etype;
304 	wl_event_msg_t emsg;
305 	s8 edata[1];
306 };
307 
308 /* security information with currently associated ap */
309 struct wl_security {
310 	u32 wpa_versions;
311 	u32 auth_type;
312 	u32 cipher_pairwise;
313 	u32 cipher_group;
314 	u32 wpa_auth;
315 	u32 auth_assoc_res_status;
316 };
317 
318 /* ibss information for currently joined ibss network */
319 struct wl_ibss {
320 	u8 beacon_interval;	/* in millisecond */
321 	u8 atim;		/* in millisecond */
322 	s8 join_only;
323 	u8 band;
324 	u8 channel;
325 };
326 
327 /* wl driver profile */
328 struct wl_profile {
329 	u32 mode;
330 	s32 band;
331 	u32 channel;
332 	struct wlc_ssid ssid;
333 	struct wl_security sec;
334 	struct wl_ibss ibss;
335 	u8 bssid[ETHER_ADDR_LEN];
336 	u16 beacon_interval;
337 	u8 dtim_period;
338 	bool active;
339 };
340 
341 struct net_info {
342 	struct net_device *ndev;
343 	struct wireless_dev *wdev;
344 	struct wl_profile profile;
345 	s32 mode;
346 	s32 roam_off;
347 	unsigned long sme_state;
348 	bool pm_restore;
349 	bool pm_block;
350 	s32 pm;
351 	struct list_head list; /* list of all net_info structure */
352 };
353 typedef s32(*ISCAN_HANDLER) (struct wl_priv *wl);
354 
355 /* iscan controller */
356 struct wl_iscan_ctrl {
357 	struct net_device *dev;
358 	struct timer_list timer;
359 	u32 timer_ms;
360 	u32 timer_on;
361 	s32 state;
362 	struct task_struct *tsk;
363 	struct semaphore sync;
364 	ISCAN_HANDLER iscan_handler[WL_SCAN_ERSULTS_LAST];
365 	void *data;
366 	s8 ioctl_buf[WLC_IOCTL_SMLEN];
367 	s8 scan_buf[WL_ISCAN_BUF_MAX];
368 };
369 
370 /* association inform */
371 #define MAX_REQ_LINE 1024
372 struct wl_connect_info {
373 	u8 req_ie[MAX_REQ_LINE];
374 	s32 req_ie_len;
375 	u8 resp_ie[MAX_REQ_LINE];
376 	s32 resp_ie_len;
377 };
378 
379 /* firmware /nvram downloading controller */
380 struct wl_fw_ctrl {
381 	const struct firmware *fw_entry;
382 	unsigned long status;
383 	u32 ptr;
384 	s8 fw_name[WL_FILE_NAME_MAX];
385 	s8 nvram_name[WL_FILE_NAME_MAX];
386 };
387 
388 /* assoc ie length */
389 struct wl_assoc_ielen {
390 	u32 req_len;
391 	u32 resp_len;
392 };
393 
394 /* wpa2 pmk list */
395 struct wl_pmk_list {
396 	pmkid_list_t pmkids;
397 	pmkid_t foo[MAXPMKID - 1];
398 };
399 
400 
401 #define ESCAN_BUF_SIZE (64 * 1024)
402 
403 struct escan_info {
404 	u32 escan_state;
405 #if defined(STATIC_WL_PRIV_STRUCT)
406 #ifndef CONFIG_DHD_USE_STATIC_BUF
407 #error STATIC_WL_PRIV_STRUCT should be used with CONFIG_DHD_USE_STATIC_BUF
408 #endif /* CONFIG_DHD_USE_STATIC_BUF */
409 	u8 *escan_buf;
410 #else
411 	u8 escan_buf[ESCAN_BUF_SIZE];
412 #endif /* STATIC_WL_PRIV_STRUCT */
413 	struct wiphy *wiphy;
414 	struct net_device *ndev;
415 };
416 
417 struct ap_info {
418 /* Structure to hold WPS, WPA IEs for a AP */
419 	u8   probe_res_ie[VNDR_IES_MAX_BUF_LEN];
420 	u8   beacon_ie[VNDR_IES_MAX_BUF_LEN];
421 	u32 probe_res_ie_len;
422 	u32 beacon_ie_len;
423 	u8 *wpa_ie;
424 	u8 *rsn_ie;
425 	u8 *wps_ie;
426 	bool security_mode;
427 };
428 struct btcoex_info {
429 	struct timer_list timer;
430 	u32 timer_ms;
431 	u32 timer_on;
432 	u32 ts_dhcp_start;	/* ms ts ecord time stats */
433 	u32 ts_dhcp_ok;		/* ms ts ecord time stats */
434 	bool dhcp_done;	/* flag, indicates that host done with
435 					 * dhcp before t1/t2 expiration
436 					 */
437 	s32 bt_state;
438 	struct work_struct work;
439 	struct net_device *dev;
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 
476 #ifdef WL11U
477 /* Max length of Interworking element */
478 #define IW_IES_MAX_BUF_LEN 		9
479 #endif
480 #ifdef WLFBT
481 #define FBT_KEYLEN		32
482 #endif
483 #define MAX_EVENT_BUF_NUM 16
484 typedef struct wl_eventmsg_buf {
485     u16 num;
486     struct {
487 		u16 type;
488 		bool set;
489 	} event [MAX_EVENT_BUF_NUM];
490 } wl_eventmsg_buf_t;
491 
492 /* private data of cfg80211 interface */
493 struct wl_priv {
494 	struct wireless_dev *wdev;	/* representing wl cfg80211 device */
495 
496 	struct wireless_dev *p2p_wdev;	/* representing wl cfg80211 device for P2P */
497 
498 	struct net_device *p2p_net;    /* reference to p2p0 interface */
499 
500 	struct wl_conf *conf;
501 	struct cfg80211_scan_request *scan_request;	/* scan request object */
502 	EVENT_HANDLER evt_handler[WLC_E_LAST];
503 	struct list_head eq_list;	/* used for event queue */
504 	struct list_head net_list;     /* used for struct net_info */
505 	spinlock_t eq_lock;	/* for event queue synchronization */
506 	spinlock_t cfgdrv_lock;	/* to protect scan status (and others if needed) */
507 	struct completion act_frm_scan;
508 	struct completion iface_disable;
509 	struct completion wait_next_af;
510 	struct mutex usr_sync;	/* maily for up/down synchronization */
511 	struct wl_scan_results *bss_list;
512 	struct wl_scan_results *scan_results;
513 
514 	/* scan request object for internal purpose */
515 	struct wl_scan_req *scan_req_int;
516 	/* information element object for internal purpose */
517 #if defined(STATIC_WL_PRIV_STRUCT)
518 	struct wl_ie *ie;
519 #else
520 	struct wl_ie ie;
521 #endif
522 	struct wl_iscan_ctrl *iscan;	/* iscan controller */
523 
524 	/* association information container */
525 #if defined(STATIC_WL_PRIV_STRUCT)
526 	struct wl_connect_info *conn_info;
527 #else
528 	struct wl_connect_info conn_info;
529 #endif
530 #ifdef DEBUGFS_CFG80211
531 	struct dentry		*debugfs;
532 #endif /* DEBUGFS_CFG80211 */
533 	struct wl_pmk_list *pmk_list;	/* wpa2 pmk list */
534 	tsk_ctl_t event_tsk;  		/* task of main event handler thread */
535 	void *pub;
536 	u32 iface_cnt;
537 	u32 channel;		/* current channel */
538 	u32 af_sent_channel;	/* channel action frame is sent */
539 	/* next af subtype to cancel the remained dwell time in rx process */
540 	u8 next_af_subtype;
541 #ifdef WL_CFG80211_SYNC_GON
542 	ulong af_tx_sent_jiffies;
543 #endif /* WL_CFG80211_SYNC_GON */
544 	bool iscan_on;		/* iscan on/off switch */
545 	bool iscan_kickstart;	/* indicate iscan already started */
546 	bool escan_on;      /* escan on/off switch */
547 	struct escan_info escan_info;   /* escan information */
548 	bool active_scan;	/* current scan mode */
549 	bool ibss_starter;	/* indicates this sta is ibss starter */
550 	bool link_up;		/* link/connection up flag */
551 
552 	/* indicate whether chip to support power save mode */
553 	bool pwr_save;
554 	bool roam_on;		/* on/off switch for self-roaming */
555 	bool scan_tried;	/* indicates if first scan attempted */
556 	bool wlfc_on;
557 	bool vsdb_mode;
558 	bool roamoff_on_concurrent;
559 	u8 *ioctl_buf;		/* ioctl buffer */
560 	struct mutex ioctl_buf_sync;
561 	u8 *escan_ioctl_buf;
562 	u8 *extra_buf;	/* maily to grab assoc information */
563 	struct dentry *debugfsdir;
564 	struct rfkill *rfkill;
565 	bool rf_blocked;
566 	struct ieee80211_channel remain_on_chan;
567 	enum nl80211_channel_type remain_on_chan_type;
568 	u64 send_action_id;
569 	u64 last_roc_id;
570 	wait_queue_head_t netif_change_event;
571 	struct completion send_af_done;
572 	struct afx_hdl *afx_hdl;
573 	struct ap_info *ap_info;
574 	struct sta_info *sta_info;
575 	struct p2p_info *p2p;
576 	bool p2p_supported;
577 	struct btcoex_info *btcoex_info;
578 	struct timer_list scan_timeout;   /* Timer for catch scan event timeout */
579 	s32(*state_notifier) (struct wl_priv *wl,
580 		struct net_info *_net_info, enum wl_status state, bool set);
581 	unsigned long interrested_state;
582 	wlc_ssid_t hostapd_ssid;
583 #ifdef WL11U
584 	bool wl11u;
585 	u8 iw_ie[IW_IES_MAX_BUF_LEN];
586 	u32 iw_ie_len;
587 #endif /* WL11U */
588 	bool sched_scan_running;	/* scheduled scan req status */
589 #ifdef WL_SCHED_SCAN
590 	struct cfg80211_sched_scan_request *sched_scan_req;	/* scheduled scan req */
591 #endif /* WL_SCHED_SCAN */
592 	bool scan_suppressed;
593 	struct timer_list scan_supp_timer;
594 	struct work_struct wlan_work;
595 	struct mutex event_sync;	/* maily for up/down synchronization */
596 	bool pm_enable_work_on;
597 	struct delayed_work pm_enable_work;
598 	vndr_ie_setbuf_t *ibss_vsie;	/* keep the VSIE for IBSS */
599 	int ibss_vsie_len;
600 };
601 
602 
next_bss(struct wl_scan_results * list,struct wl_bss_info * bss)603 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
604 {
605 	return bss = bss ?
606 		(struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
607 }
608 static inline s32
wl_alloc_netinfo(struct wl_priv * wl,struct net_device * ndev,struct wireless_dev * wdev,s32 mode,bool pm_block)609 wl_alloc_netinfo(struct wl_priv *wl, struct net_device *ndev,
610 	struct wireless_dev * wdev, s32 mode, bool pm_block)
611 {
612 	struct net_info *_net_info;
613 	s32 err = 0;
614 	if (wl->iface_cnt == IFACE_MAX_CNT)
615 		return -ENOMEM;
616 	_net_info = kzalloc(sizeof(struct net_info), GFP_KERNEL);
617 	if (!_net_info)
618 		err = -ENOMEM;
619 	else {
620 		_net_info->mode = mode;
621 		_net_info->ndev = ndev;
622 		_net_info->wdev = wdev;
623 		_net_info->pm_restore = 0;
624 		_net_info->pm = 0;
625 		_net_info->pm_block = pm_block;
626 		_net_info->roam_off = WL_INVALID;
627 		wl->iface_cnt++;
628 		list_add(&_net_info->list, &wl->net_list);
629 	}
630 	return err;
631 }
632 static inline void
wl_dealloc_netinfo(struct wl_priv * wl,struct net_device * ndev)633 wl_dealloc_netinfo(struct wl_priv *wl, struct net_device *ndev)
634 {
635 	struct net_info *_net_info, *next;
636 
637 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
638 		if (ndev && (_net_info->ndev == ndev)) {
639 			list_del(&_net_info->list);
640 			wl->iface_cnt--;
641 			if (_net_info->wdev) {
642 				kfree(_net_info->wdev);
643 				ndev->ieee80211_ptr = NULL;
644 			}
645 			kfree(_net_info);
646 		}
647 	}
648 
649 }
650 static inline void
wl_delete_all_netinfo(struct wl_priv * wl)651 wl_delete_all_netinfo(struct wl_priv *wl)
652 {
653 	struct net_info *_net_info, *next;
654 
655 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
656 		list_del(&_net_info->list);
657 			if (_net_info->wdev)
658 				kfree(_net_info->wdev);
659 			kfree(_net_info);
660 	}
661 	wl->iface_cnt = 0;
662 }
663 static inline u32
wl_get_status_all(struct wl_priv * wl,s32 status)664 wl_get_status_all(struct wl_priv *wl, s32 status)
665 
666 {
667 	struct net_info *_net_info, *next;
668 	u32 cnt = 0;
669 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
670 		if (_net_info->ndev &&
671 			test_bit(status, &_net_info->sme_state))
672 			cnt++;
673 	}
674 	return cnt;
675 }
676 static inline void
wl_set_status_all(struct wl_priv * wl,s32 status,u32 op)677 wl_set_status_all(struct wl_priv *wl, s32 status, u32 op)
678 {
679 	struct net_info *_net_info, *next;
680 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
681 		switch (op) {
682 			case 1:
683 				return; /* set all status is not allowed */
684 			case 2:
685 				clear_bit(status, &_net_info->sme_state);
686 				if (wl->state_notifier &&
687 					test_bit(status, &(wl->interrested_state)))
688 					wl->state_notifier(wl, _net_info, status, false);
689 				break;
690 			case 4:
691 				return; /* change all status is not allowed */
692 			default:
693 				return; /* unknown operation */
694 		}
695 	}
696 }
697 static inline void
wl_set_status_by_netdev(struct wl_priv * wl,s32 status,struct net_device * ndev,u32 op)698 wl_set_status_by_netdev(struct wl_priv *wl, s32 status,
699 	struct net_device *ndev, u32 op)
700 {
701 
702 	struct net_info *_net_info, *next;
703 
704 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
705 		if (ndev && (_net_info->ndev == ndev)) {
706 			switch (op) {
707 				case 1:
708 					set_bit(status, &_net_info->sme_state);
709 					if (wl->state_notifier &&
710 						test_bit(status, &(wl->interrested_state)))
711 						wl->state_notifier(wl, _net_info, status, true);
712 					break;
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 					change_bit(status, &_net_info->sme_state);
721 					break;
722 			}
723 		}
724 
725 	}
726 
727 }
728 
729 static inline u32
wl_get_status_by_netdev(struct wl_priv * wl,s32 status,struct net_device * ndev)730 wl_get_status_by_netdev(struct wl_priv *wl, s32 status,
731 	struct net_device *ndev)
732 {
733 	struct net_info *_net_info, *next;
734 
735 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
736 				if (ndev && (_net_info->ndev == ndev))
737 					return test_bit(status, &_net_info->sme_state);
738 	}
739 	return 0;
740 }
741 
742 static inline s32
wl_get_mode_by_netdev(struct wl_priv * wl,struct net_device * ndev)743 wl_get_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev)
744 {
745 	struct net_info *_net_info, *next;
746 
747 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
748 				if (ndev && (_net_info->ndev == ndev))
749 					return _net_info->mode;
750 	}
751 	return -1;
752 }
753 
754 
755 static inline void
wl_set_mode_by_netdev(struct wl_priv * wl,struct net_device * ndev,s32 mode)756 wl_set_mode_by_netdev(struct wl_priv *wl, struct net_device *ndev,
757 	s32 mode)
758 {
759 	struct net_info *_net_info, *next;
760 
761 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
762 				if (ndev && (_net_info->ndev == ndev))
763 					_net_info->mode = mode;
764 	}
765 }
766 static inline struct wl_profile *
wl_get_profile_by_netdev(struct wl_priv * wl,struct net_device * ndev)767 wl_get_profile_by_netdev(struct wl_priv *wl, struct net_device *ndev)
768 {
769 	struct net_info *_net_info, *next;
770 
771 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
772 				if (ndev && (_net_info->ndev == ndev))
773 					return &_net_info->profile;
774 	}
775 	return NULL;
776 }
777 static inline struct net_info *
wl_get_netinfo_by_netdev(struct wl_priv * wl,struct net_device * ndev)778 wl_get_netinfo_by_netdev(struct wl_priv *wl, struct net_device *ndev)
779 {
780 	struct net_info *_net_info, *next;
781 
782 	list_for_each_entry_safe(_net_info, next, &wl->net_list, list) {
783 				if (ndev && (_net_info->ndev == ndev))
784 					return _net_info;
785 	}
786 	return NULL;
787 }
788 #define wl_to_wiphy(w) (w->wdev->wiphy)
789 #define wl_to_prmry_ndev(w) (w->wdev->netdev)
790 #define wl_to_prmry_wdev(w) (w->wdev)
791 #define wl_to_p2p_wdev(w) (w->p2p_wdev)
792 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
793 #define ndev_to_wdev(ndev) (ndev->ieee80211_ptr)
794 #define wdev_to_ndev(wdev) (wdev->netdev)
795 
796 #if defined(WL_ENABLE_P2P_IF)
797 #define ndev_to_wlc_ndev(ndev, wl)	((ndev == wl->p2p_net) ? \
798 	wl_to_prmry_ndev(wl) : ndev)
799 #else
800 #define ndev_to_wlc_ndev(ndev, wl)	(ndev)
801 #endif /* WL_ENABLE_P2P_IF */
802 
803 #if defined(WL_CFG80211_P2P_DEV_IF)
804 #define wdev_to_wlc_ndev(wdev, wl)	\
805 	((wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) ? \
806 	wl_to_prmry_ndev(wl) : wdev_to_ndev(wdev))
807 #define cfgdev_to_wlc_ndev(cfgdev, wl)	wdev_to_wlc_ndev(cfgdev, wl)
808 #elif defined(WL_ENABLE_P2P_IF)
809 #define cfgdev_to_wlc_ndev(cfgdev, wl)	ndev_to_wlc_ndev(cfgdev, wl)
810 #else
811 #define cfgdev_to_wlc_ndev(cfgdev, wl)	(cfgdev)
812 #endif /* WL_CFG80211_P2P_DEV_IF */
813 
814 #if defined(WL_CFG80211_P2P_DEV_IF)
815 #define ndev_to_cfgdev(ndev)	ndev_to_wdev(ndev)
816 #else
817 #define ndev_to_cfgdev(ndev)	(ndev)
818 #endif /* WL_CFG80211_P2P_DEV_IF */
819 
820 #if defined(WL_CFG80211_P2P_DEV_IF)
821 #define scan_req_match(wl)	(((wl) && (wl->scan_request) && \
822 	(wl->scan_request->wdev == wl->p2p_wdev)) ? true : false)
823 #elif defined(WL_ENABLE_P2P_IF)
824 #define scan_req_match(wl)	(((wl) && (wl->scan_request) && \
825 	(wl->scan_request->dev == wl->p2p_net)) ? true : false)
826 #else
827 #define scan_req_match(wl)	(((wl) && p2p_is_on(wl) && p2p_scan(wl)) ? \
828 	true : false)
829 #endif /* WL_CFG80211_P2P_DEV_IF */
830 
831 #define wl_to_sr(w) (w->scan_req_int)
832 #if defined(STATIC_WL_PRIV_STRUCT)
833 #define wl_to_ie(w) (w->ie)
834 #define wl_to_conn(w) (w->conn_info)
835 #else
836 #define wl_to_ie(w) (&w->ie)
837 #define wl_to_conn(w) (&w->conn_info)
838 #endif
839 #define iscan_to_wl(i) ((struct wl_priv *)(i->data))
840 #define wl_to_iscan(w) (w->iscan)
841 #define wiphy_from_scan(w) (w->escan_info.wiphy)
842 #define wl_get_drv_status_all(wl, stat) \
843 	(wl_get_status_all(wl, WL_STATUS_ ## stat))
844 #define wl_get_drv_status(wl, stat, ndev)  \
845 	(wl_get_status_by_netdev(wl, WL_STATUS_ ## stat, ndev))
846 #define wl_set_drv_status(wl, stat, ndev)  \
847 	(wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 1))
848 #define wl_clr_drv_status(wl, stat, ndev)  \
849 	(wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 2))
850 #define wl_clr_drv_status_all(wl, stat)  \
851 	(wl_set_status_all(wl, WL_STATUS_ ## stat, 2))
852 #define wl_chg_drv_status(wl, stat, ndev)  \
853 	(wl_set_status_by_netdev(wl, WL_STATUS_ ## stat, ndev, 4))
854 
855 #define for_each_bss(list, bss, __i)	\
856 	for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
857 
858 #define for_each_ndev(wl, iter, next) \
859 	list_for_each_entry_safe(iter, next, &wl->net_list, list)
860 
861 
862 /* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0.
863  * In addtion to that, wpa_version is WPA_VERSION_1
864  */
865 #define is_wps_conn(_sme) \
866 	((wl_cfgp2p_find_wpsie((u8 *)_sme->ie, _sme->ie_len) != NULL) && \
867 	 (!_sme->crypto.n_ciphers_pairwise) && \
868 	 (!_sme->crypto.cipher_group))
869 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
870 extern s32 wl_cfg80211_attach_post(struct net_device *ndev);
871 extern void wl_cfg80211_detach(void *para);
872 
873 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
874             void *data);
875 void wl_cfg80211_set_parent_dev(void *dev);
876 struct device *wl_cfg80211_get_parent_dev(void);
877 
878 extern s32 wl_cfg80211_up(void *para);
879 extern s32 wl_cfg80211_down(void *para);
880 extern s32 wl_cfg80211_notify_ifadd(struct net_device *ndev, s32 idx, s32 bssidx,
881 	void* _net_attach);
882 extern s32 wl_cfg80211_ifdel_ops(struct net_device *net);
883 extern s32 wl_cfg80211_notify_ifdel(void);
884 extern s32 wl_cfg80211_is_progress_ifadd(void);
885 extern s32 wl_cfg80211_is_progress_ifchange(void);
886 extern s32 wl_cfg80211_is_progress_ifadd(void);
887 extern s32 wl_cfg80211_notify_ifchange(void);
888 extern void wl_cfg80211_dbg_level(u32 level);
889 extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
890 extern s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len);
891 extern s32 wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len);
892 extern s32 wl_cfg80211_set_wps_p2p_ie(struct net_device *net, char *buf, int len,
893 	enum wl_management_type type);
894 extern s32 wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len);
895 extern int wl_cfg80211_hang(struct net_device *dev, u16 reason);
896 extern s32 wl_mode_to_nl80211_iftype(s32 mode);
897 int wl_cfg80211_do_driver_init(struct net_device *net);
898 void wl_cfg80211_enable_trace(bool set, u32 level);
899 extern s32 wl_update_wiphybands(struct wl_priv *wl, bool notify);
900 extern s32 wl_cfg80211_if_is_group_owner(void);
901 extern chanspec_t wl_ch_host_to_driver(u16 channel);
902 extern s32 wl_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add);
903 extern void wl_stop_wait_next_action_frame(struct wl_priv *wl);
904 extern int wl_cfg80211_update_power_mode(struct net_device *dev);
905 extern void wl_cfg80211_add_to_eventbuffer(wl_eventmsg_buf_t *ev, u16 event, bool set);
906 extern s32 wl_cfg80211_apply_eventbuffer(struct net_device *ndev,
907 	struct wl_priv *wl, wl_eventmsg_buf_t *ev);
908 extern void get_primary_mac(struct wl_priv *wl, struct ether_addr *mac);
909 #define SCAN_BUF_CNT	2
910 #define SCAN_BUF_NEXT	1
911 #define wl_escan_set_sync_id(a, b) ((a) = htod16(0x1234))
912 #define wl_escan_get_buf(a, b) ((wl_scan_results_t *) (a)->escan_info.escan_buf)
913 #define wl_escan_check_sync_id(a, b, c) 0
914 #define wl_escan_print_sync_id(a, b, c)
915 #define wl_escan_increment_sync_id(a, b)
916 #define wl_escan_init_sync_id(a)
917 extern void wl_cfg80211_ibss_vsie_set_buffer(vndr_ie_setbuf_t *ibss_vsie, int ibss_vsie_len);
918 extern s32 wl_cfg80211_ibss_vsie_delete(struct net_device *dev);
919 
920 /* Action frame specific functions */
921 extern u8 wl_get_action_category(void *frame, u32 frame_len);
922 extern int wl_get_public_action(void *frame, u32 frame_len, u8 *ret_action);
923 
924 #endif				/* _wl_cfg80211_h_ */
925