xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/mvl88w8977/mlinux/moal_main.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /** @file moal_main.h
2   *
3   * @brief This file contains wlan driver specific defines etc.
4   *
5   * Copyright (C) 2008-2017, Marvell International Ltd.
6   *
7   * This software file (the "File") is distributed by Marvell International
8   * Ltd. under the terms of the GNU General Public License Version 2, June 1991
9   * (the "License").  You may use, redistribute and/or modify this File in
10   * accordance with the terms and conditions of the License, a copy of which
11   * is available by writing to the Free Software Foundation, Inc.,
12   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
13   * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14   *
15   * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
16   * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
17   * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
18   * this warranty disclaimer.
19   *
20   */
21 
22 /********************************************************
23 Change log:
24     10/21/2008: initial version
25 ********************************************************/
26 
27 #ifndef _MOAL_MAIN_H
28 #define _MOAL_MAIN_H
29 
30 /* warnfix for FS redefination if any? */
31 #ifdef FS
32 #undef FS
33 #endif
34 
35 /* Linux header files */
36 #include        <linux/kernel.h>
37 #include        <linux/module.h>
38 #include        <linux/init.h>
39 #include        <linux/version.h>
40 #include        <linux/param.h>
41 #include        <linux/delay.h>
42 #include        <linux/slab.h>
43 #include        <linux/mm.h>
44 #include        <linux/types.h>
45 #include        <linux/sched.h>
46 #include        <linux/timer.h>
47 #include        <linux/ioport.h>
48 #include        <linux/pci.h>
49 #include        <linux/ctype.h>
50 #include        <linux/proc_fs.h>
51 #include        <linux/vmalloc.h>
52 #include        <linux/ptrace.h>
53 #include        <linux/string.h>
54 #include        <linux/irqreturn.h>
55 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
56 #include        <linux/namei.h>
57 #include        <linux/fs.h>
58 #endif
59 
60 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
61 #include       <linux/config.h>
62 #endif
63 
64 /* ASM files */
65 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
66 #include        <linux/semaphore.h>
67 #else
68 #include        <asm/semaphore.h>
69 #endif
70 #include        <asm/byteorder.h>
71 #include        <asm/irq.h>
72 #include        <linux/uaccess.h>
73 #include        <asm/io.h>
74 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
75 #include        <asm/switch_to.h>
76 #else
77 #include        <asm/system.h>
78 #endif
79 
80 #include        <linux/spinlock.h>
81 
82 /* Net header files */
83 #include        <linux/netdevice.h>
84 #include        <linux/net.h>
85 #include        <linux/inet.h>
86 #include        <linux/ip.h>
87 #include        <linux/skbuff.h>
88 #include        <linux/if_arp.h>
89 #include        <linux/if_ether.h>
90 #include        <linux/etherdevice.h>
91 #include        <net/sock.h>
92 #include        <net/arp.h>
93 #include        <linux/rtnetlink.h>
94 #include        <linux/inetdevice.h>
95 
96 #include	<linux/firmware.h>
97 
98 #ifdef ANDROID_KERNEL
99 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
100 #include <linux/pm_wakeup.h>
101 #include <linux/device.h>
102 #else
103 #include <linux/wakelock.h>
104 #endif
105 #endif
106 
107 #include <net/ieee80211_radiotap.h>
108 
109 #include        "mlan.h"
110 #include        "moal_shim.h"
111 /* Wireless header */
112 #if defined(STA_CFG80211) || defined(UAP_CFG80211)
113 #include        <net/lib80211.h>
114 #include        <net/cfg80211.h>
115 #include        <net/ieee80211_radiotap.h>
116 #endif
117 #if defined(STA_WEXT) || defined(UAP_WEXT)
118 #include        <linux/wireless.h>
119 #include        <net/iw_handler.h>
120 #include        "moal_wext.h"
121 #endif
122 #ifdef STA_WEXT
123 #include        "moal_priv.h"
124 #endif
125 
126 #ifndef MIN
127 /** Find minimum */
128 #define MIN(a, b)		((a) < (b) ? (a) : (b))
129 #endif
130 
131 /** Find maximum */
132 #ifndef MAX
133 #define MAX(a, b)                ((a) > (b) ? (a) : (b))
134 #endif
135 
136 #define COMPAT_VERSION_CODE KERNEL_VERSION( 0, 0, 0)
137 #define CFG80211_VERSION_CODE MAX(LINUX_VERSION_CODE, COMPAT_VERSION_CODE)
138 
139 /**
140  * Reason Code 3: STA is leaving (or has left) IBSS or ESS
141  */
142 #define DEF_DEAUTH_REASON_CODE (0x3)
143 
144 /**
145  * 802.1 Local Experimental 1.
146  */
147 
148 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 24)
149 #define REFDATA __refdata
150 #else
151 #define REFDATA
152 #endif
153 
154 /**
155  * Linux Kernels later 3.9 use CONFIG_PM_RUNTIME instead of
156  * CONFIG_USB_SUSPEND
157  * Linux Kernels later 3.19 use CONFIG_PM instead of
158  * CONFIG_PM_RUNTIME
159  */
160 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
161 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
162 #ifdef CONFIG_PM
163 #ifndef CONFIG_USB_SUSPEND
164 #define CONFIG_USB_SUSPEND
165 #endif
166 #ifndef CONFIG_PM_RUNTIME
167 #define CONFIG_PM_RUNTIME
168 #endif
169 #endif
170 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
171 #ifdef CONFIG_PM_RUNTIME
172 #ifndef CONFIG_USB_SUSPEND
173 #define CONFIG_USB_SUSPEND
174 #endif
175 #endif
176 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) */
177 #endif
178 
179 /**
180  * Linux kernel later 3.10 use strncasecmp instead of strnicmp
181  */
182 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
183 #define strnicmp strncasecmp
184 #endif
185 
186 /**
187  * Linux kernel later 4.7 use nl80211_band instead of ieee80211_band
188  * Linux kernel later 4.7 use new macro
189  */
190 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
191 #define ieee80211_band          nl80211_band
192 #define IEEE80211_BAND_2GHZ     NL80211_BAND_2GHZ
193 #define IEEE80211_BAND_5GHZ     NL80211_BAND_5GHZ
194 #define IEEE80211_NUM_BANDS     NUM_NL80211_BANDS
195 #endif
196 
197 /**
198 * interface name
199 */
200 #define default_mlan_name    "wlan%%d"
201 #define default_uap_name    "uap%%d"
202 #define default_wfd_name    "p2p%%d"
203 #define default_nan_name    "nan%%d"
204 #define default_mpl_name    "mpl%d"
205 #define default_11p_name    "ocb%d"
206 #define mwiphy_name          "mwiphy%d"
207 
208 #ifdef OPENWRT
209 #ifdef mwiphy_name
210 #undef mwiphy_name
211 #define mwiphy_name          "phy%d"
212 #endif
213 #ifdef default_mlan_name
214 #undef default_mlan_name
215 #define default_mlan_name "wlan%%d"
216 #endif
217 #endif
218 
219 /**
220  * define write_can_lock() to fix compile issue on ACTIA platform
221  */
222 #if !defined(write_can_lock) && defined(CONFIG_PREEMPT_RT_FULL)
223 #define write_can_lock(X) 1
224 #endif
225 
226 #define MLAN_ACTION_FRAME_CATEGORY_OFFSET (40)
227 #define MLAN_ACTION_FRAME_ACTION_OFFSET (41)
228 
229 /** Define BOOLEAN */
230 typedef t_u8 BOOLEAN;
231 
232 /** Driver version */
233 extern char driver_version[];
234 
235 /** Private structure for MOAL */
236 typedef struct _moal_private moal_private;
237 /** Handle data structure for MOAL  */
238 typedef struct _moal_handle moal_handle;
239 
240 /** Hardware status codes */
241 typedef enum _MOAL_HARDWARE_STATUS {
242 	HardwareStatusReady,
243 	HardwareStatusInitializing,
244 	HardwareStatusFwReady,
245 	HardwareStatusReset,
246 	HardwareStatusClosing,
247 	HardwareStatusNotReady
248 } MOAL_HARDWARE_STATUS;
249 
250 /** fw cap info 11p */
251 #define FW_CAPINFO_80211P          MBIT(24)
252 /** fw cap info BGA */
253 #define FW_CAPINFO_80211BGA        (MBIT(8)|MBIT(9)|MBIT(10))
254 
255 /** moal_wait_option */
256 enum {
257 	MOAL_NO_WAIT,
258 	MOAL_IOCTL_WAIT,
259 	MOAL_IOCTL_WAIT_TIMEOUT
260 };
261 
262 /** moal_main_state */
263 enum {
264 	MOAL_STATE_IDLE,
265 	MOAL_RECV_INT,
266 	MOAL_ENTER_WORK_QUEUE,
267 	MOAL_START_MAIN_PROCESS,
268 	MOAL_END_MAIN_PROCESS
269 };
270 
271 /** HostCmd_Header */
272 typedef struct _HostCmd_Header {
273     /** Command */
274 	t_u16 command;
275     /** Size */
276 	t_u16 size;
277 } HostCmd_Header;
278 
279 /*
280  * OS timer specific
281  */
282 
283 /** Timer structure */
284 typedef struct _moal_drv_timer {
285 	/** Timer list */
286 	struct timer_list tl;
287 	/** Timer function */
288 	void (*timer_function) (void *context);
289 	/** Timer function context */
290 	void *function_context;
291 	/** Time period */
292 	t_u32 time_period;
293 	/** Is timer periodic ? */
294 	t_u32 timer_is_periodic;
295 	/** Is timer cancelled ? */
296 	t_u32 timer_is_canceled;
297 } moal_drv_timer, *pmoal_drv_timer;
298 
299 typedef struct {
300 	t_u8 dialog_token;
301 	t_u8 follow_up_dialog_token;
302 	t_u32 t1;
303 	t_u32 t4;
304 	t_u8 t1_err;
305 	t_u8 t4_err;
306 } __attribute__ ((packed)) moal_wnm_tm_msmt;
307 
308 /** wlan_802_11_header */
309 typedef struct {
310     /** Frame Control */
311 	t_u16 frm_ctl;
312     /** Duration ID */
313 	t_u16 duration_id;
314     /** Address1 */
315 	mlan_802_11_mac_addr addr1;
316     /** Address2 */
317 	mlan_802_11_mac_addr addr2;
318     /** Address3 */
319 	mlan_802_11_mac_addr addr3;
320     /** Sequence Control */
321 	t_u16 seq_ctl;
322     /** Address4 */
323 	mlan_802_11_mac_addr addr4;
324 } __attribute__ ((packed)) moal_wlan_802_11_header;
325 
326 typedef struct {
327 	/** t2 time */
328 	t_u32 t2;
329 	/** t2 error */
330 	t_u8 t2_err;
331 	/** t3 time */
332 	t_u32 t3;
333 	/** t3 error */
334 	t_u8 t3_err;
335 	/** ingress time */
336 	t_u64 ingress_time;
337 } __attribute__ ((packed)) moal_timestamps;
338 
339 typedef struct {
340 	t_u8 vendor_specific;
341 	t_u8 length;
342 	t_u8 data[0];
343 } __attribute__ ((packed)) moal_ptp_context;
344 
345 /**
346  *  @brief Timer handler
347  *
348  *  @param fcontext	Timer context
349  *
350  *  @return		N/A
351  */
352 static inline void
woal_timer_handler(unsigned long fcontext)353 woal_timer_handler(unsigned long fcontext)
354 {
355 	pmoal_drv_timer timer = (pmoal_drv_timer)fcontext;
356 
357 	timer->timer_function(timer->function_context);
358 
359 	if (timer->timer_is_periodic == MTRUE) {
360 		mod_timer(&timer->tl,
361 			  jiffies + ((timer->time_period * HZ) / 1000));
362 	} else {
363 		timer->timer_is_canceled = MTRUE;
364 		timer->time_period = 0;
365 	}
366 }
367 
368 /**
369  *  @brief Initialize timer
370  *
371  *  @param timer		Timer structure
372  *  @param TimerFunction	Timer function
373  *  @param FunctionContext	Timer function context
374  *
375  *  @return			N/A
376  */
377 static inline void
woal_initialize_timer(pmoal_drv_timer timer,void (* TimerFunction)(void * context),void * FunctionContext)378 woal_initialize_timer(pmoal_drv_timer timer,
379 		      void (*TimerFunction) (void *context),
380 		      void *FunctionContext)
381 {
382 	/* First, setup the timer to trigger the wlan_timer_handler proxy */
383 	init_timer(&timer->tl);
384 	timer->tl.function = woal_timer_handler;
385 	timer->tl.data = (t_ptr)timer;
386 
387 	/* Then tell the proxy which function to call and what to pass it */
388 	timer->timer_function = TimerFunction;
389 	timer->function_context = FunctionContext;
390 	timer->timer_is_canceled = MTRUE;
391 	timer->time_period = 0;
392 	timer->timer_is_periodic = MFALSE;
393 }
394 
395 /**
396  *  @brief Modify timer
397  *
398  *  @param timer		Timer structure
399  *  @param millisecondperiod	Time period in millisecond
400  *
401  *  @return			N/A
402  */
403 static inline void
woal_mod_timer(pmoal_drv_timer timer,t_u32 millisecondperiod)404 woal_mod_timer(pmoal_drv_timer timer, t_u32 millisecondperiod)
405 {
406 	timer->time_period = millisecondperiod;
407 	mod_timer(&timer->tl, jiffies + (millisecondperiod * HZ) / 1000);
408 	timer->timer_is_canceled = MFALSE;
409 }
410 
411 /**
412  *  @brief Cancel timer
413  *
414  *  @param timer	Timer structure
415  *
416  *  @return		N/A
417  */
418 static inline void
woal_cancel_timer(moal_drv_timer * timer)419 woal_cancel_timer(moal_drv_timer *timer)
420 {
421 	if (timer->timer_is_periodic || in_atomic() || irqs_disabled())
422 		del_timer(&timer->tl);
423 	else
424 		del_timer_sync(&timer->tl);
425 	timer->timer_is_canceled = MTRUE;
426 	timer->time_period = 0;
427 }
428 
429 #ifdef REASSOCIATION
430 /*
431  * OS Thread Specific
432  */
433 
434 #include	<linux/kthread.h>
435 
436 /** Kernel thread structure */
437 typedef struct _moal_thread {
438     /** Task control structrue */
439 	struct task_struct *task;
440     /** Pointer to wait_queue_head */
441 	wait_queue_head_t wait_q;
442     /** PID */
443 	pid_t pid;
444     /** Pointer to moal_handle */
445 	void *handle;
446 } moal_thread;
447 
448 /**
449  *  @brief Activate thread
450  *
451  *  @param thr			Thread structure
452  *  @return			N/A
453  */
454 static inline void
woal_activate_thread(moal_thread * thr)455 woal_activate_thread(moal_thread *thr)
456 {
457     /** Initialize the wait queue */
458 	init_waitqueue_head(&thr->wait_q);
459 
460     /** Record the thread pid */
461 	thr->pid = current->pid;
462 }
463 
464 /**
465  *  @brief De-activate thread
466  *
467  *  @param thr			Thread structure
468  *  @return			N/A
469  */
470 static inline void
woal_deactivate_thread(moal_thread * thr)471 woal_deactivate_thread(moal_thread *thr)
472 {
473 	/* Reset the pid */
474 	thr->pid = 0;
475 }
476 
477 /**
478  *  @brief Create and run the thread
479  *
480  *  @param threadfunc		Thread function
481  *  @param thr			Thread structure
482  *  @param name			Thread name
483  *  @return			N/A
484  */
485 static inline void
woal_create_thread(int (* threadfunc)(void *),moal_thread * thr,char * name)486 woal_create_thread(int (*threadfunc) (void *), moal_thread *thr, char *name)
487 {
488 	/* Create and run the thread */
489 	thr->task = kthread_run(threadfunc, thr, "%s", name);
490 }
491 #endif /* REASSOCIATION */
492 
493 /* The following macros are neccessary to retain compatibility
494  * around the workqueue chenges happened in kernels >= 2.6.20:
495  * - INIT_WORK changed to take 2 arguments and let the work function
496  *   get its own data through the container_of macro
497  * - delayed works have been split from normal works to save some
498  *   memory usage in struct work_struct
499  */
500 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
501 /** Work_queue work initialization */
502 #define MLAN_INIT_WORK(_work, _fun)                 INIT_WORK(_work, ((void (*)(void *))_fun), _work)
503 /** Work_queue delayed work initialization */
504 #define MLAN_INIT_DELAYED_WORK(_work, _fun)         INIT_WORK(_work, ((void (*)(void *))_fun), _work)
505 /** Work_queue container parameter */
506 #define MLAN_DELAYED_CONTAINER_OF(_ptr, _type, _m)  container_of(_ptr, _type, _m)
507 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) */
508 /** Work_queue work initialization */
509 #define MLAN_INIT_WORK                              INIT_WORK
510 /** Work_queue delayed work initialization */
511 #define MLAN_INIT_DELAYED_WORK                      INIT_DELAYED_WORK
512 /** Work_queue container parameter */
513 #define MLAN_DELAYED_CONTAINER_OF(_ptr, _type, _m)  container_of(_ptr, _type, _m.work)
514 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) */
515 
516 /**
517  *  @brief Schedule timeout
518  *
519  *  @param millisec	Timeout duration in milli second
520  *
521  *  @return		N/A
522  */
523 static inline void
woal_sched_timeout(t_u32 millisec)524 woal_sched_timeout(t_u32 millisec)
525 {
526 	set_current_state(TASK_INTERRUPTIBLE);
527 
528 	schedule_timeout((millisec * HZ) / 1000);
529 }
530 
531 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
532 #define IN6PTON_XDIGIT		0x00010000
533 #define IN6PTON_DIGIT		0x00020000
534 #define IN6PTON_COLON_MASK	0x00700000
535 #define IN6PTON_COLON_1		0x00100000	/* single : requested */
536 #define IN6PTON_COLON_2		0x00200000	/* second : requested */
537 #define IN6PTON_COLON_1_2	0x00400000	/* :: requested */
538 #define IN6PTON_DOT		0x00800000	/* . */
539 #define IN6PTON_DELIM		0x10000000
540 #define IN6PTON_NULL		0x20000000	/* first/tail */
541 #define IN6PTON_UNKNOWN		0x40000000
542 
543 static inline int
xdigit2bin(char c,int delim)544 xdigit2bin(char c, int delim)
545 {
546 	if (c == delim || c == '\0')
547 		return IN6PTON_DELIM;
548 	if (c == ':')
549 		return IN6PTON_COLON_MASK;
550 	if (c == '.')
551 		return IN6PTON_DOT;
552 	if (c >= '0' && c <= '9')
553 		return IN6PTON_XDIGIT | IN6PTON_DIGIT | (c - '0');
554 	if (c >= 'a' && c <= 'f')
555 		return IN6PTON_XDIGIT | (c - 'a' + 10);
556 	if (c >= 'A' && c <= 'F')
557 		return IN6PTON_XDIGIT | (c - 'A' + 10);
558 	if (delim == -1)
559 		return IN6PTON_DELIM;
560 	return IN6PTON_UNKNOWN;
561 }
562 
563 static inline int
in4_pton(const char * src,int srclen,u8 * dst,int delim,const char ** end)564 in4_pton(const char *src, int srclen, u8 *dst, int delim, const char **end)
565 {
566 	const char *s;
567 	u8 *d;
568 	u8 dbuf[4];
569 	int ret = 0;
570 	int i;
571 	int w = 0;
572 
573 	if (srclen < 0)
574 		srclen = strlen(src);
575 	s = src;
576 	d = dbuf;
577 	i = 0;
578 	while (1) {
579 		int c;
580 		c = xdigit2bin(srclen > 0 ? *s : '\0', delim);
581 		if (!
582 		    (c &
583 		     (IN6PTON_DIGIT | IN6PTON_DOT | IN6PTON_DELIM |
584 		      IN6PTON_COLON_MASK))) {
585 			goto out;
586 		}
587 		if (c & (IN6PTON_DOT | IN6PTON_DELIM | IN6PTON_COLON_MASK)) {
588 			if (w == 0)
589 				goto out;
590 			*d++ = w & 0xff;
591 			w = 0;
592 			i++;
593 			if (c & (IN6PTON_DELIM | IN6PTON_COLON_MASK)) {
594 				if (i != 4)
595 					goto out;
596 				break;
597 			}
598 			goto cont;
599 		}
600 		w = (w * 10) + c;
601 		if ((w & 0xffff) > 255)
602 			goto out;
603 cont:
604 		if (i >= 4)
605 			goto out;
606 		s++;
607 		srclen--;
608 	}
609 	ret = 1;
610 	memcpy(dst, dbuf, sizeof(dbuf));
611 out:
612 	if (end)
613 		*end = s;
614 	return ret;
615 }
616 #endif /* < 2.6.19 */
617 
618 #ifndef __ATTRIB_ALIGN__
619 #define __ATTRIB_ALIGN__ __attribute__((aligned(4)))
620 #endif
621 
622 #ifndef __ATTRIB_PACK__
623 #define __ATTRIB_PACK__ __attribute__ ((packed))
624 #endif
625 
626 /** Get module */
627 #define MODULE_GET	try_module_get(THIS_MODULE)
628 /** Put module */
629 #define MODULE_PUT	module_put(THIS_MODULE)
630 
631 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
632 /** Initialize semaphore */
633 #define MOAL_INIT_SEMAPHORE(x)      init_MUTEX(x)
634 /** Initialize semaphore */
635 #define MOAL_INIT_SEMAPHORE_LOCKED(x)   init_MUTEX_LOCKED(x)
636 #else
637 /** Initialize semaphore */
638 #define MOAL_INIT_SEMAPHORE(x)      sema_init(x, 1)
639 /** Initialize semaphore */
640 #define MOAL_INIT_SEMAPHORE_LOCKED(x)   sema_init(x, 0)
641 #endif
642 
643 /** Acquire semaphore and with blocking */
644 #define MOAL_ACQ_SEMAPHORE_BLOCK(x)	down_interruptible(x)
645 /** Acquire semaphore without blocking */
646 #define MOAL_ACQ_SEMAPHORE_NOBLOCK(x)	down_trylock(x)
647 /** Release semaphore */
648 #define MOAL_REL_SEMAPHORE(x)       up(x)
649 
650 /** Request FW timeout in second */
651 #define REQUEST_FW_TIMEOUT		30
652 
653 #if defined(SYSKT)
654 /** Max loop count (* 100ms) for waiting device ready at init time */
655 #define MAX_WAIT_DEVICE_READY_COUNT	50
656 #endif
657 
658 /** Default watchdog timeout */
659 #define MRVDRV_DEFAULT_WATCHDOG_TIMEOUT (10 * HZ)
660 
661 #ifdef UAP_SUPPORT
662 /** Default watchdog timeout
663     Increase the value to avoid kernel Tx timeout message in case
664     station in PS mode or left.
665     The default value of PS station ageout timer is 40 seconds.
666     Hence, the watchdog timer is set to a value higher than it.
667 */
668 #define MRVDRV_DEFAULT_UAP_WATCHDOG_TIMEOUT (41 * HZ)
669 #endif
670 
671 /* IOCTL Timeout */
672 #define MOAL_IOCTL_TIMEOUT                    (20 * HZ)
673 
674 #ifdef ANDROID_KERNEL
675 /** Wake lock timeout in msec */
676 #define WAKE_LOCK_TIMEOUT 3000
677 /** Roaming Wake lock timeout in msec */
678 #define ROAMING_WAKE_LOCK_TIMEOUT 10000
679 #endif
680 
681 /** Threshold value of number of times the Tx timeout happened */
682 #define NUM_TX_TIMEOUT_THRESHOLD      5
683 
684 /** Custom event : DRIVER HANG */
685 #define CUS_EVT_DRIVER_HANG	            "EVENT=DRIVER_HANG"
686 
687 /** TDLS connected event */
688 #define CUS_EVT_TDLS_CONNECTED           "EVENT=TDLS_CONNECTED"
689 /** TDLS tear down event */
690 #define CUS_EVT_TDLS_TEARDOWN            "EVENT=TDLS_TEARDOWN"
691 /** wmm info */
692 #define WMM_TYPE_INFO                     0
693 /** wmm parameter */
694 #define WMM_TYPE_PARAMETER                1
695 
696 /** AP connected event */
697 #define CUS_EVT_AP_CONNECTED           "EVENT=AP_CONNECTED"
698 
699 /** Custom event : BW changed */
700 #define CUS_EVT_BW_CHANGED		"EVENT=BW_CHANGED"
701 /** Custom event : OBSS scan parameter */
702 #define CUS_EVT_OBSS_SCAN_PARAM		"EVENT=OBSS_SCAN_PARAM"
703 
704 /** Custom event : AdHoc link sensed */
705 #define CUS_EVT_ADHOC_LINK_SENSED	"EVENT=ADHOC_LINK_SENSED"
706 /** Custom event : AdHoc link lost */
707 #define CUS_EVT_ADHOC_LINK_LOST		"EVENT=ADHOC_LINK_LOST"
708 /** Custom event : MIC failure, unicast */
709 #define CUS_EVT_MLME_MIC_ERR_UNI	"MLME-MICHAELMICFAILURE.indication unicast"
710 /** Custom event : MIC failure, multicast */
711 #define CUS_EVT_MLME_MIC_ERR_MUL	"MLME-MICHAELMICFAILURE.indication multicast"
712 /** Custom event : Beacon RSSI low */
713 #define CUS_EVT_BEACON_RSSI_LOW		"EVENT=BEACON_RSSI_LOW"
714 /** Custom event : Beacon SNR low */
715 #define CUS_EVT_BEACON_SNR_LOW		"EVENT=BEACON_SNR_LOW"
716 /** Custom event : Beacon RSSI high */
717 #define CUS_EVT_BEACON_RSSI_HIGH	"EVENT=BEACON_RSSI_HIGH"
718 /** Custom event : Beacon SNR high */
719 #define CUS_EVT_BEACON_SNR_HIGH		"EVENT=BEACON_SNR_HIGH"
720 /** Custom event : Max fail */
721 #define CUS_EVT_MAX_FAIL		"EVENT=MAX_FAIL"
722 /** Custom event : Data RSSI low */
723 #define CUS_EVT_DATA_RSSI_LOW		"EVENT=DATA_RSSI_LOW"
724 /** Custom event : Data SNR low */
725 #define CUS_EVT_DATA_SNR_LOW		"EVENT=DATA_SNR_LOW"
726 /** Custom event : Data RSSI high */
727 #define CUS_EVT_DATA_RSSI_HIGH		"EVENT=DATA_RSSI_HIGH"
728 /** Custom event : Data SNR high */
729 #define CUS_EVT_DATA_SNR_HIGH		"EVENT=DATA_SNR_HIGH"
730 /** Custom event : Link Quality */
731 #define CUS_EVT_LINK_QUALITY		"EVENT=LINK_QUALITY"
732 /** Custom event : Port Release */
733 #define CUS_EVT_PORT_RELEASE		"EVENT=PORT_RELEASE"
734 /** Custom event : Pre-Beacon Lost */
735 #define CUS_EVT_PRE_BEACON_LOST		"EVENT=PRE_BEACON_LOST"
736 
737 /** Custom event : Deep Sleep awake */
738 #define CUS_EVT_DEEP_SLEEP_AWAKE	"EVENT=DS_AWAKE"
739 
740 #define CUS_EVT_GET_CORRELATED_TIME     "EVENT=CORRELATED-TIME"
741 #define CUS_EVT_TIMING_MSMT_CONFIRM     "EVENT=TIMING-MSMT-CONFIRM"
742 #define CUS_EVT_TM_FRAME_INDICATION     "EVENT=TIMING-MSMT-FRAME"
743 
744 /** Custom event : Host Sleep activated */
745 #define CUS_EVT_HS_ACTIVATED		"HS_ACTIVATED"
746 /** Custom event : Host Sleep deactivated */
747 #define CUS_EVT_HS_DEACTIVATED		"HS_DEACTIVATED"
748 /** Custom event : Host Sleep wakeup */
749 #define CUS_EVT_HS_WAKEUP		"HS_WAKEUP"
750 
751 /** Wakeup Reason */
752 typedef enum {
753 	NO_HSWAKEUP_REASON = 0,	//0.unknown
754 	BCAST_DATA_MATCHED,	// 1. Broadcast data matched
755 	MCAST_DATA_MATCHED,	// 2. Multicast data matched
756 	UCAST_DATA_MATCHED,	// 3. Unicast data matched
757 	MASKTABLE_EVENT_MATCHED,	// 4. Maskable event matched
758 	NON_MASKABLE_EVENT_MATCHED,	// 5. Non-maskable event matched
759 	NON_MASKABLE_CONDITION_MATCHED,	// 6. Non-maskable condition matched (EAPoL rekey)
760 	MAGIC_PATTERN_MATCHED,	// 7. Magic pattern matched
761 	CONTROL_FRAME_MATCHED,	// 8. Control frame matched
762 	MANAGEMENT_FRAME_MATCHED,	// 9. Management frame matched
763 	GTK_REKEY_FAILURE,	//10. GTK rekey failure
764 	RESERVED		// Others: reserved
765 } HSWakeupReason_t;
766 
767 /** Custom event : WEP ICV error */
768 #define CUS_EVT_WEP_ICV_ERR		"EVENT=WEP_ICV_ERR"
769 
770 /** Custom event : Channel Switch Announcment */
771 #define CUS_EVT_CHANNEL_SWITCH_ANN	"EVENT=CHANNEL_SWITCH_ANN"
772 
773 /** Custom indiciation message sent to the application layer for WMM changes */
774 #define WMM_CONFIG_CHANGE_INDICATION  "WMM_CONFIG_CHANGE.indication"
775 
776 #ifdef UAP_SUPPORT
777 /** Custom event : STA connected */
778 #define CUS_EVT_STA_CONNECTED           "EVENT=STA_CONNECTED"
779 /** Custom event : STA disconnected */
780 #define CUS_EVT_STA_DISCONNECTED        "EVENT=STA_DISCONNECTED"
781 #endif
782 
783 /** 10 seconds */
784 #define MOAL_TIMER_10S                10000
785 /** 5 seconds */
786 #define MOAL_TIMER_5S                 5000
787 /** 1 second */
788 #define MOAL_TIMER_1S                 1000
789 /** 1 milisecond */
790 #define MOAL_TIMER_1MS                1
791 
792 /** passive scan time */
793 #define PASSIVE_SCAN_CHAN_TIME       110
794 /** active scan time */
795 #define ACTIVE_SCAN_CHAN_TIME        110
796 /** specific scan time */
797 #define SPECIFIC_SCAN_CHAN_TIME      110
798 /** passive scan time */
799 #define INIT_PASSIVE_SCAN_CHAN_TIME  80
800 /** active scan time */
801 #define INIT_ACTIVE_SCAN_CHAN_TIME   80
802 /** specific scan time */
803 #define INIT_SPECIFIC_SCAN_CHAN_TIME 80
804 /** specific scan time after connected */
805 #define MIN_SPECIFIC_SCAN_CHAN_TIME   40
806 
807 /** Default value of re-assoc timer */
808 #define REASSOC_TIMER_DEFAULT         500
809 
810 /** Netlink protocol number */
811 #define NETLINK_MARVELL     (MAX_LINKS - 1)
812 /** Netlink maximum payload size */
813 #define NL_MAX_PAYLOAD      1024
814 /** Netlink multicast group number */
815 #define NL_MULTICAST_GROUP  1
816 
817 #define MAX_RX_PENDING_THRHLD	50
818 
819 /** high rx pending packets */
820 #define HIGH_RX_PENDING         100
821 /** low rx pending packets */
822 #define LOW_RX_PENDING          80
823 
824 /** MAX Tx Pending count */
825 #define MAX_TX_PENDING      100
826 
827 /** LOW Tx Pending count */
828 #define LOW_TX_PENDING      80
829 
830 /** Offset for subcommand */
831 #define SUBCMD_OFFSET       4
832 
833 /** default scan channel gap  */
834 #define DEF_SCAN_CHAN_GAP   50
835 /** default scan time per channel in miracast mode */
836 #define DEF_MIRACAST_SCAN_TIME   20
837 
838 /** Macro to extract the TOS field from a skb */
839 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
840 #define SKB_TOS(skb) (ip_hdr(skb)->tos)
841 #else
842 #define SKB_TOS(skb) (skb->nh.iph->tos)
843 #endif
844 #define SKB_TIDV6(skb)  (ipv6_get_dsfield(ipv6_hdr(skb)))
845 #define IS_SKB_MAGIC_VLAN(skb) (skb->priority >= 256 && skb->priority <= 263)
846 #define GET_VLAN_PRIO(skb) (skb->priority - 256)
847 
848 /** Offset for TOS field in the IP header */
849 #define IPTOS_OFFSET 5
850 
851 /** Offset for DSCP in the tos field */
852 #define DSCP_OFFSET 2
853 
854 /** max retry count for wait_event_interupptible_xx while loop */
855 #define MAX_RETRY_CNT 100
856 /** wait_queue structure */
857 typedef struct _wait_queue {
858 	/** wait_queue_head */
859 	wait_queue_head_t wait;
860 	/** Wait condition */
861 	BOOLEAN condition;
862 	/** Start time */
863 	long start_time;
864 	/** Status from MLAN */
865 	mlan_status status;
866     /** flag for wait_timeout */
867 	t_u8 wait_timeout;
868     /** retry count */
869 	t_u8 retry;
870 } wait_queue, *pwait_queue;
871 
872 /** Auto Rate */
873 #define AUTO_RATE 0xFF
874 
875 #define STA_WEXT_MASK        MBIT(0)
876 #define UAP_WEXT_MASK        MBIT(1)
877 #define STA_CFG80211_MASK    MBIT(2)
878 #define UAP_CFG80211_MASK    MBIT(3)
879 #ifdef STA_CFG80211
880 #ifdef STA_SUPPORT
881 /** Is STA CFG80211 enabled in module param */
882 #define IS_STA_CFG80211(x)          (x & STA_CFG80211_MASK)
883 #endif
884 #endif
885 #ifdef UAP_CFG80211
886 #ifdef UAP_SUPPORT
887 /** Is UAP CFG80211 enabled in module param */
888 #define IS_UAP_CFG80211(x)          (x & UAP_CFG80211_MASK)
889 #endif
890 #endif
891 #if defined(STA_CFG80211) || defined(UAP_CFG80211)
892 /** Is UAP or STA CFG80211 enabled in module param */
893 #define IS_STA_OR_UAP_CFG80211(x)   (x & (STA_CFG80211_MASK | UAP_CFG80211_MASK))
894 #endif
895 
896 #ifdef STA_WEXT
897 /** Is STA WEXT enabled in module param */
898 #define IS_STA_WEXT(x)              (x & STA_WEXT_MASK)
899 #endif /* STA_WEXT */
900 #ifdef UAP_WEXT
901 /** Is UAP WEXT enabled in module param */
902 #define IS_UAP_WEXT(x)              (x & UAP_WEXT_MASK)
903 #endif /* UAP_WEXT */
904 #if defined(STA_WEXT) || defined(UAP_WEXT)
905 /** Is UAP or STA WEXT enabled in module param */
906 #define IS_STA_OR_UAP_WEXT(x)       (x & (STA_WEXT_MASK | UAP_WEXT_MASK))
907 #endif
908 
909 #ifdef STA_SUPPORT
910 /** Driver mode STA bit */
911 #define DRV_MODE_STA       MBIT(0)
912 /** Maximum STA BSS */
913 #define MAX_STA_BSS        1
914 /** Default STA BSS */
915 #define DEF_STA_BSS        1
916 #endif
917 #ifdef UAP_SUPPORT
918 /** Driver mode uAP bit */
919 #define DRV_MODE_UAP       MBIT(1)
920 /** Maximum uAP BSS */
921 #define MAX_UAP_BSS        2
922 /** Default uAP BSS */
923 #define DEF_UAP_BSS        1
924 #endif
925 #if defined(WIFI_DIRECT_SUPPORT)
926 /** Driver mode WIFIDIRECT bit */
927 #define DRV_MODE_WIFIDIRECT       MBIT(2)
928 /** Maximum WIFIDIRECT BSS */
929 #define MAX_WIFIDIRECT_BSS        2
930 /** Default WIFIDIRECT BSS */
931 #define DEF_WIFIDIRECT_BSS        1
932 #if defined(STA_CFG80211) && defined(UAP_CFG80211)
933 #define DEF_VIRTUAL_BSS			  0
934 #endif
935 #endif /* WIFI_DIRECT_SUPPORT && V14_FEATURE */
936 /** Driver mode NAN bit */
937 #define DRV_MODE_NAN              MBIT(4)
938 /** Maximum NAN BSS */
939 #define MAX_NAN_BSS               1
940 /** Default NAN BSS */
941 #define DEF_NAN_BSS               1
942 
943 #define DRV_MODE_WLAN            (MBIT(0)|MBIT(1)|MBIT(2)|MBIT(3)|MBIT(4))
944 
945 /**
946  * the maximum number of adapter supported
947  **/
948 #define MAX_MLAN_ADAPTER    2
949 
950 typedef struct _moal_drv_mode {
951     /** driver mode */
952 	t_u16 drv_mode;
953     /** total number of interfaces */
954 	t_u16 intf_num;
955     /** attribute of bss */
956 	mlan_bss_attr *bss_attr;
957     /** name of firmware image */
958 	char *fw_name;
959 } moal_drv_mode;
960 
961 #ifdef PROC_DEBUG
962 /** Debug data */
963 struct debug_data {
964     /** Name */
965 	char name[32];
966     /** Size */
967 	t_u32 size;
968     /** Address */
969 	t_ptr addr;
970 };
971 
972 /** Private debug data */
973 struct debug_data_priv {
974     /** moal_private handle */
975 	moal_private *priv;
976     /** Debug items */
977 	struct debug_data *items;
978     /** numbre of item */
979 	int num_of_items;
980 };
981 #endif
982 
983 /** Maximum IP address buffer length */
984 #define IPADDR_MAX_BUF          20
985 /** IP address operation: Remove */
986 #define IPADDR_OP_REMOVE        0
987 
988 #define DROP_TCP_ACK        1
989 #define HOLD_TCP_ACK        2
990 struct tcp_sess {
991 	struct list_head link;
992     /** tcp session info */
993 	t_u32 src_ip_addr;
994 	t_u32 dst_ip_addr;
995 	t_u16 src_tcp_port;
996 	t_u16 dst_tcp_port;
997     /** tx ack packet info */
998 	t_u32 ack_seq;
999 	/** tcp ack buffer */
1000 	void *ack_skb;
1001 	/** priv structure */
1002 	void *priv;
1003 	/** pmbuf */
1004 	void *pmbuf;
1005     /** timer for ack */
1006 	moal_drv_timer ack_timer __ATTRIB_ALIGN__;
1007     /** timer is set */
1008 	BOOLEAN is_timer_set;
1009 };
1010 
1011 struct tx_status_info {
1012 	struct list_head link;
1013     /** cookie */
1014 	t_u64 tx_cookie;
1015     /** seq_num */
1016 	t_u8 tx_seq_num;
1017 	/**          skb */
1018 	void *tx_skb;
1019 };
1020 
1021 #define MAX_NUM_ETHER_TYPE 8
1022 typedef struct {
1023     /** number of protocols in protocol array*/
1024 	t_u8 protocol_num;
1025     /** protocols supported */
1026 	t_u16 protocols[MAX_NUM_ETHER_TYPE];
1027 } __ATTRIB_PACK__ dot11_protocol;
1028 typedef struct {
1029     /** Data rate in unit of 0.5Mbps */
1030 	t_u16 datarate;
1031     /** Channel number to transmit the frame */
1032 	t_u8 channel;
1033     /** Bandwidth to transmit the frame */
1034 	t_u8 bw;
1035     /** Power to be used for transmission */
1036 	t_u8 power;
1037     /** Priority of the packet to be transmitted */
1038 	t_u8 priority;
1039     /** retry time of tx transmission*/
1040 	t_u8 retry_limit;
1041     /** Reserved fields*/
1042 	t_u8 reserved[1];
1043 } __ATTRIB_PACK__ dot11_txcontrol;
1044 
1045 typedef struct {
1046    /** Data rate of received paccket*/
1047 	t_u16 datarate;
1048    /** Channel on which packet was received*/
1049 	t_u8 channel;
1050    /** Rx antenna*/
1051 	t_u8 antenna;
1052    /** RSSI */
1053 	t_u8 rssi;
1054    /** Reserved */
1055 	t_u8 reserved[3];
1056 } __ATTRIB_PACK__ dot11_rxcontrol;
1057 
1058 #define OKC_WAIT_TARGET_PMKSA_TIMEOUT (4 * HZ / 1000)
1059 #define PMKID_LEN 16
1060 struct pmksa_entry {
1061 	struct list_head link;
1062 	u8 bssid[ETH_ALEN];
1063 	u8 pmkid[PMKID_LEN];
1064 };
1065 
1066 /** default rssi low threshold */
1067 #define TDLS_RSSI_LOW_THRESHOLD 55
1068 /** default rssi high threshold */
1069 #define TDLS_RSSI_HIGH_THRESHOLD 50
1070 /** TDLS idle time */
1071 #define TDLS_IDLE_TIME			(10*HZ)
1072 /** TDLS max failure count */
1073 #define TDLS_MAX_FAILURE_COUNT	 4
1074 /** TDLS tear down reason */
1075 #define TDLS_TEARN_DOWN_REASON_UNSPECIFIC	26
1076 
1077 /** TDLS status */
1078 typedef enum _tdlsStatus_e {
1079 	TDLS_NOT_SETUP = 0,
1080 	TDLS_SETUP_INPROGRESS,
1081 	TDLS_SETUP_COMPLETE,
1082 	TDLS_SETUP_FAILURE,
1083 	TDLS_TEAR_DOWN,
1084 	TDLS_SWITCHING_CHANNEL,
1085 	TDLS_IN_BASE_CHANNEL,
1086 	TDLS_IN_OFF_CHANNEL,
1087 } tdlsStatus_e;
1088 
1089 /** tdls peer_info */
1090 struct tdls_peer {
1091 	struct list_head link;
1092 	/** MAC address information */
1093 	t_u8 peer_addr[ETH_ALEN];
1094 	/** rssi */
1095 	int rssi;
1096     /** jiffies with rssi */
1097 	long rssi_jiffies;
1098     /** link status */
1099 	tdlsStatus_e link_status;
1100     /** num of set up failure */
1101 	t_u8 num_failure;
1102 };
1103 
1104 /** Number of samples in histogram (/proc/mwlan/mlan0/histogram).*/
1105 #define HIST_MAX_SAMPLES   1048576
1106 #define RX_RATE_MAX			76
1107 
1108 /** SRN MAX  */
1109 #define SNR_MAX				256
1110 /** NOISE FLR MAX  */
1111 #define NOISE_FLR_MAX			256
1112 /** SIG STRENTGH MAX */
1113 #define SIG_STRENGTH_MAX		256
1114 /** historgram data */
1115 typedef struct _hgm_data {
1116     /** snr */
1117 	atomic_t snr[SNR_MAX];
1118     /** noise flr */
1119 	atomic_t noise_flr[NOISE_FLR_MAX];
1120     /** sig_str */
1121 	atomic_t sig_str[SIG_STRENGTH_MAX];
1122     /** num sample */
1123 	atomic_t num_samples;
1124     /** rx rate */
1125 	atomic_t rx_rate[0];
1126 } hgm_data;
1127 
1128 /** max antenna number */
1129 #define MAX_ANTENNA_NUM			1
1130 
1131 /* wlan_hist_proc_data */
1132 typedef struct _wlan_hist_proc_data {
1133     /** antenna */
1134 	u8 ant_idx;
1135 	/** Private structure */
1136 	struct _moal_private *priv;
1137 } wlan_hist_proc_data;
1138 
1139 /** Private structure for MOAL */
1140 struct _moal_private {
1141 	/** Handle structure */
1142 	moal_handle *phandle;
1143 	/** Tx timeout count */
1144 	t_u32 num_tx_timeout;
1145 	/** BSS index */
1146 	t_u8 bss_index;
1147 	/** BSS type */
1148 	t_u8 bss_type;
1149 	/** BSS role */
1150 	t_u8 bss_role;
1151 	/** bss virtual flag */
1152 	t_u8 bss_virtual;
1153 	/** MAC address information */
1154 	t_u8 current_addr[ETH_ALEN];
1155 	/** Media connection status */
1156 	BOOLEAN media_connected;
1157 	/** Statistics of tcp ack tx dropped */
1158 	t_u32 tcp_ack_drop_cnt;
1159 	/** Statistics of tcp ack tx in total from kernel */
1160 	t_u32 tcp_ack_cnt;
1161 #ifdef UAP_SUPPORT
1162 	/** uAP started or not */
1163 	BOOLEAN bss_started;
1164     /** host based uap flag */
1165 	BOOLEAN uap_host_based;
1166 	/** uAP skip CAC*/
1167 	BOOLEAN skip_cac;
1168 	/** tx block flag */
1169 	BOOLEAN uap_tx_blocked;
1170 #if defined(DFS_TESTING_SUPPORT)
1171     /** user cac period */
1172 	t_u32 user_cac_period_msec;
1173     /** channel under nop */
1174 	BOOLEAN chan_under_nop;
1175 #endif
1176 #ifdef UAP_CFG80211
1177 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
1178 	/** current working channel */
1179 	struct cfg80211_chan_def chan;
1180 #endif
1181 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)
1182 	/** switch channel */
1183 	struct cfg80211_chan_def csa_chan;
1184 	/** beacon after channel switch */
1185 	struct cfg80211_beacon_data beacon_after;
1186 	/** CSA work queue */
1187 	struct workqueue_struct *csa_workqueue;
1188 	/** csa work */
1189 	struct delayed_work csa_work;
1190 #endif
1191 #endif
1192 #endif
1193     /** IP addr type */
1194 	t_u32 ip_addr_type;
1195     /** IP addr */
1196 	t_u8 ip_addr[IPADDR_LEN];
1197 #ifdef STA_SUPPORT
1198 	/** scan type */
1199 	t_u8 scan_type;
1200 	/** extended capabilities */
1201 	ExtCap_t extended_capabilities;
1202 	/** bg_scan_start */
1203 	t_u8 bg_scan_start;
1204     /** bg_scan reported */
1205 	t_u8 bg_scan_reported;
1206     /** bg_scan config */
1207 	wlan_bgscan_cfg scan_cfg;
1208 	/** sched scaning flag */
1209 	t_u8 sched_scanning;
1210 #ifdef STA_CFG80211
1211     /** roaming enabled flag */
1212 	t_u8 roaming_enabled;
1213 	/** rssi low threshold */
1214 	int rssi_low;
1215     /** channel for connect */
1216 	struct ieee80211_channel conn_chan;
1217     /** bssid for connect */
1218 	t_u8 conn_bssid[ETH_ALEN];
1219     /** ssid for connect */
1220 	t_u8 conn_ssid[MLAN_MAX_SSID_LENGTH];
1221 	/** key data */
1222 	t_u8 conn_wep_key[MAX_WEP_KEY_SIZE];
1223     /** connection param */
1224 	struct cfg80211_connect_params sme_current;
1225     /** roaming required flag */
1226 	t_u8 roaming_required;
1227 #endif
1228 	t_u8 wait_target_ap_pmkid;
1229 	wait_queue_head_t okc_wait_q __ATTRIB_ALIGN__;
1230 	struct list_head pmksa_cache_list;
1231 	spinlock_t pmksa_list_lock;
1232 	struct pmksa_entry *target_ap_pmksa;
1233 	t_u8 okc_ie_len;
1234 	t_u8 *okc_roaming_ie;
1235 #endif
1236 	/** Net device pointer */
1237 	struct net_device *netdev;
1238 	/** Net device statistics structure */
1239 	struct net_device_stats stats;
1240 #if defined(STA_CFG80211) || defined(UAP_CFG80211)
1241 	/** Wireless device pointer */
1242 	struct wireless_dev *wdev;
1243 	/** Wireless device */
1244 	struct wireless_dev w_dev;
1245 	/** Net device pointer */
1246 	struct net_device *pa_netdev;
1247 	/** channel parameter for UAP/GO */
1248 	t_u16 channel;
1249 #ifdef UAP_SUPPORT
1250     /** wep key */
1251 	wep_key uap_wep_key[4];
1252 	/** cipher */
1253 	t_u32 cipher;
1254 #endif
1255 	/** pmk saved flag */
1256 	t_u8 pmk_saved;
1257 	/** pmk */
1258 	mlan_pmk_t pmk;
1259 	/** beacon ie index */
1260 	t_u16 beacon_index;
1261 	/** proberesp ie index */
1262 	t_u16 proberesp_index;
1263 	/** proberesp_p2p_index */
1264 	t_u16 proberesp_p2p_index;
1265 	/** assocresp ie index */
1266 	t_u16 assocresp_index;
1267 	/** assocresp qos map ie index */
1268 	t_u16 assocresp_qos_map_index;
1269 	/** probereq index for mgmt ie */
1270 	t_u16 probereq_index;
1271 	/** mgmt_subtype_mask */
1272 	t_u32 mgmt_subtype_mask;
1273 	/** beacon wps index for mgmt ie */
1274 	t_u16 beacon_wps_index;
1275 	/** beacon/proberesp vendor ie index */
1276 	t_u16 proberesp_vendor_index;
1277 #endif
1278 #ifdef STA_CFG80211
1279 #ifdef STA_SUPPORT
1280 	/** CFG80211 association description */
1281 	t_u8 cfg_bssid[ETH_ALEN];
1282 	/** Disconnect request from CFG80211 */
1283 	bool cfg_disconnect;
1284     /** connect request from CFG80211 */
1285 	bool cfg_connect;
1286     /** lock for cfg connect */
1287 	spinlock_t connect_lock;
1288 	/** assoc status */
1289 	t_u32 assoc_status;
1290 	/** rssi_threshold */
1291 	s32 cqm_rssi_thold;
1292 	/** rssi_high_threshold */
1293 	s32 cqm_rssi_high_thold;
1294 	/** rssi hysteresis */
1295 	u32 cqm_rssi_hyst;
1296 	/** last rssi_low */
1297 	u8 last_rssi_low;
1298 	/** last rssi_high */
1299 	u8 last_rssi_high;
1300 	/** mrvl rssi threshold */
1301 	u8 mrvl_rssi_low;
1302 	/** last event */
1303 	u32 last_event;
1304 	/** fake scan flag */
1305 	u8 fake_scan_complete;
1306 	/**ft ie*/
1307 	t_u8 ft_ie[MAX_IE_SIZE];
1308     /**ft ie len*/
1309 	t_u8 ft_ie_len;
1310     /**mobility domain value*/
1311 	t_u16 ft_md;
1312     /**ft capability*/
1313 	t_u8 ft_cap;
1314     /**set true during ft connection*/
1315 	t_bool ft_pre_connect;
1316     /**ft roaming triggered by driver or not*/
1317 	t_bool ft_roaming_triggered_by_driver;
1318     /**target ap mac address for Fast Transition*/
1319 	t_u8 target_ap_bssid[ETH_ALEN];
1320     /** IOCTL wait queue for FT*/
1321 	wait_queue_head_t ft_wait_q __ATTRIB_ALIGN__;
1322 	/** ft wait condition */
1323 	t_bool ft_wait_condition;
1324 #endif				/* STA_SUPPORT */
1325 #endif				/* STA_CFG80211 */
1326 #ifdef CONFIG_PROC_FS
1327 	/** Proc entry */
1328 	struct proc_dir_entry *proc_entry;
1329 	/** Proc entry name */
1330 	char proc_entry_name[IFNAMSIZ];
1331     /** proc entry for hist */
1332 	struct proc_dir_entry *hist_entry;
1333 	/** ant_hist_proc_data */
1334 	wlan_hist_proc_data hist_proc[MAX_ANTENNA_NUM];
1335 #endif				/* CONFIG_PROC_FS */
1336 #ifdef STA_SUPPORT
1337 	/** Nickname */
1338 	t_u8 nick_name[16];
1339 	/** AdHoc link sensed flag */
1340 	BOOLEAN is_adhoc_link_sensed;
1341 	/** Current WEP key index */
1342 	t_u16 current_key_index;
1343 #ifdef REASSOCIATION
1344 	mlan_ssid_bssid prev_ssid_bssid;
1345 	/** Re-association required */
1346 	BOOLEAN reassoc_required;
1347 	/** Flag of re-association on/off */
1348 	BOOLEAN reassoc_on;
1349 	/** Set asynced essid flag */
1350 	BOOLEAN set_asynced_essid_flag;
1351 #endif				/* REASSOCIATION */
1352 	/** Report scan result */
1353 	t_u8 report_scan_result;
1354 	/** wpa_version */
1355 	t_u8 wpa_version;
1356 	/** key mgmt */
1357 	t_u8 key_mgmt;
1358 	/** rx_filter */
1359 	t_u8 rx_filter;
1360 #endif				/* STA_SUPPORT */
1361 	/** Rate index */
1362 	t_u16 rate_index;
1363 #if defined(STA_WEXT) || defined(UAP_WEXT)
1364 	/** IW statistics */
1365 	struct iw_statistics w_stats;
1366 #endif
1367 #ifdef UAP_WEXT
1368     /** Pairwise Cipher used for WPA/WPA2 mode */
1369 	t_u16 pairwise_cipher;
1370     /** Group Cipher */
1371 	t_u16 group_cipher;
1372     /** Protocol stored during uap wext configuratoin */
1373 	t_u16 uap_protocol;
1374     /** Key Mgmt whether PSK or 1x */
1375 	t_u16 uap_key_mgmt;
1376     /** Beacon IE length from hostapd */
1377 	t_u16 bcn_ie_len;
1378     /** Beacon IE buffer from hostapd */
1379 	t_u8 bcn_ie_buf[MAX_IE_SIZE];
1380 #endif
1381 
1382     /** dscp mapping */
1383 	t_u8 dscp_map[64];
1384 #ifdef PROC_DEBUG
1385     /** MLAN debug info */
1386 	struct debug_data_priv items_priv;
1387 #endif
1388 
1389     /** tcp session queue */
1390 	struct list_head tcp_sess_queue;
1391     /** TCP Ack enhance flag */
1392 	t_u8 enable_tcp_ack_enh;
1393     /** TCP session spin lock */
1394 	spinlock_t tcp_sess_lock;
1395     /** tcp list */
1396 	struct list_head tdls_list;
1397 	/** tdls spin lock */
1398 	spinlock_t tdls_lock;
1399 	/** auto tdls  flag */
1400 	t_u8 enable_auto_tdls;
1401     /** check tx packet for tdls peer */
1402 	t_u8 tdls_check_tx;
1403 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
1404 	atomic_t wmm_tx_pending[4];
1405 #endif
1406     /** per interface extra headroom */
1407 	t_u16 extra_tx_head_len;
1408     /** TX status spin lock */
1409 	spinlock_t tx_stat_lock;
1410     /** tx_seq_num */
1411 	t_u8 tx_seq_num;
1412     /** tx status queue */
1413 	struct list_head tx_stat_queue;
1414 
1415     /** rx hgm data */
1416 	hgm_data *hist_data[3];
1417 	BOOLEAN assoc_with_mac;
1418 	t_u8 gtk_data_ready;
1419 	mlan_ds_misc_gtk_rekey_data gtk_rekey_data;
1420 	dot11_protocol tx_protocols;
1421 	dot11_protocol rx_protocols;
1422 };
1423 
1424 /** channel_field.flags */
1425 #define CHANNEL_FLAGS_TURBO 0x0010
1426 #define CHANNEL_FLAGS_CCK   0x0020
1427 #define CHANNEL_FLAGS_OFDM  0x0040
1428 #define CHANNEL_FLAGS_2GHZ  0x0080
1429 #define CHANNEL_FLAGS_5GHZ  0x0100
1430 #define CHANNEL_FLAGS_ONLY_PASSIVSCAN_ALLOW  0x0200
1431 #define CHANNEL_FLAGS_DYNAMIC_CCK_OFDM  0x0400
1432 #define CHANNEL_FLAGS_GFSK  0x0800
1433 struct channel_field {
1434 	t_u16 frequency;
1435 	t_u16 flags;
1436 } __packed;
1437 
1438 /** mcs_field.known */
1439 #define MCS_KNOWN_BANDWIDTH   0x01
1440 #define MCS_KNOWN_MCS_INDEX_KNOWN  0x02
1441 #define MCS_KNOWN_GUARD_INTERVAL   0x04
1442 #define MCS_KNOWN_HT_FORMAT   0x08
1443 #define MCS_KNOWN_FEC_TYPE    0x10
1444 #define MCS_KNOWN_STBC_KNOWN  0x20
1445 #define MCS_KNOWN_NESS_KNOWN  0x40
1446 #define MCS_KNOWN_NESS_DATA   0x80
1447 /** bandwidth */
1448 #define RX_BW_20   0
1449 #define RX_BW_40   1
1450 #define RX_BW_20L  2
1451 #define RX_BW_20U  3
1452 /** mcs_field.flags
1453 The flags field is any combination of the following:
1454 0x03    bandwidth - 0: 20, 1: 40, 2: 20L, 3: 20U
1455 0x04    guard interval - 0: long GI, 1: short GI
1456 0x08    HT format - 0: mixed, 1: greenfield
1457 0x10    FEC type - 0: BCC, 1: LDPC
1458 0x60    Number of STBC streams
1459 0x80    Ness - bit 0 (LSB) of Number of extension spatial streams */
1460 struct mcs_field {
1461 	t_u8 known;
1462 	t_u8 flags;
1463 	t_u8 mcs;
1464 } __packed;
1465 
1466 /** radiotap_body.flags */
1467 #define RADIOTAP_FLAGS_DURING_CFG  0x01
1468 #define RADIOTAP_FLAGS_SHORT_PREAMBLE  0x02
1469 #define RADIOTAP_FLAGS_WEP_ENCRYPTION  0x04
1470 #define RADIOTAP_FLAGS_WITH_FRAGMENT   0x08
1471 #define RADIOTAP_FLAGS_INCLUDE_FCS  0x10
1472 #define RADIOTAP_FLAGS_PAD_BTW_HEADER_PAYLOAD  0x20
1473 #define RADIOTAP_FLAGS_FAILED_FCS_CHECK  0x40
1474 #define RADIOTAP_FLAGS_USE_SGI_HT  0x80
1475 struct radiotap_body {
1476 	t_u64 timestamp;
1477 	t_u8 flags;
1478 	t_u8 rate;
1479 	struct channel_field channel;
1480 	t_s8 antenna_signal;
1481 	t_s8 antenna_noise;
1482 	t_u8 antenna;
1483 	struct mcs_field mcs;
1484 } __packed;
1485 
1486 struct radiotap_header {
1487 	struct ieee80211_radiotap_header hdr;
1488 	struct radiotap_body body;
1489 } __packed;
1490 
1491 /** Roam offload config parameters */
1492 typedef struct woal_priv_fw_roam_offload_cfg {
1493 	/* User set passphrase */
1494 	t_u8 userset_passphrase;
1495 	/* BSSID for fw roaming/auto_reconnect */
1496 	t_u8 bssid[MLAN_MAC_ADDR_LENGTH];
1497 	/* Retry_count for fw roaming/auto_reconnect */
1498 	t_u8 retry_count;
1499 	/* Condition to trigger roaming
1500 	 * Bit0 : RSSI low trigger
1501 	 * Bit1 : Pre-beacon lost trigger
1502 	 * Bit2 : Link Lost trigger
1503 	 * Bit3 : Deauth by ext-AP trigger
1504 	 * Bit4 ~ Bit15 : Reserved
1505 	 * value 0 : no trigger
1506 	 * value 0xff : invalid
1507 	 */
1508 	t_u16 trigger_condition;
1509 	/* SSID List(White list) */
1510 	mlan_ds_misc_ssid_list ssid_list;
1511 	/* Black list(BSSID list) */
1512 	mlan_ds_misc_roam_offload_aplist black_list;
1513 
1514 	/* RSSI paramters set flag */
1515 	t_u8 rssi_param_set_flag;
1516 	/* MAX_RSSI for fw roaming */
1517 	t_u8 max_rssi;
1518 	/*  MIN_RSSI for fw roaming */
1519 	t_u8 min_rssi;
1520 	/*  Step_RSSI for fw roaming */
1521 	t_u8 step_rssi;
1522 
1523 	/* BAND and RSSI_HYSTERESIS set flag */
1524 	t_u8 band_rssi_flag;
1525 	mlan_ds_misc_band_rssi band_rssi;
1526 
1527 	/* BGSCAN params set flag */
1528 	t_u8 bgscan_set_flag;
1529 	mlan_ds_misc_bgscan_cfg bgscan_cfg;
1530 
1531 	/* EES mode params set flag */
1532 	t_u8 ees_param_set_flag;
1533 	mlan_ds_misc_ees_cfg ees_cfg;
1534 
1535 	/* Beacon miss threshold */
1536 	t_u8 bcn_miss_threshold;
1537 
1538 	/* Beacon miss threshold */
1539 	t_u8 pre_bcn_miss_threshold;
1540 
1541 	/* scan repeat count */
1542 	t_u16 repeat_count;
1543 } woal_roam_offload_cfg;
1544 
1545 int woal_set_clear_pmk(moal_private *priv, t_u8 action);
1546 mlan_status woal_config_fw_roaming(moal_private *priv, t_u8 cfg_mode,
1547 				   woal_roam_offload_cfg * roam_offload_cfg);
1548 int woal_enable_fw_roaming(moal_private *priv, int data);
1549 
1550 #define GTK_REKEY_OFFLOAD_DISABLE                    0
1551 #define GTK_REKEY_OFFLOAD_ENABLE                     1
1552 #define GTK_REKEY_OFFLOAD_SUSPEND                    2
1553 
1554 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
1555 /** Monitor Band Channel Config */
1556 typedef struct _netmon_band_chan_cfg {
1557 	t_u32 band;
1558 	t_u32 channel;
1559 	t_u32 chan_bandwidth;
1560 } netmon_band_chan_cfg;
1561 #endif
1562 
1563 typedef struct _monitor_iface {
1564 	/* The priv data of interface on which the monitor iface is based */
1565 	moal_private *priv;
1566 	struct wireless_dev wdev;
1567 	/** 0 - Disabled
1568 	    * 1 - Channel Specified sniffer mode
1569 	    * 2 - In-Channel sniffer mode
1570 	*/
1571 	int sniffer_mode;
1572 	int radiotap_enabled;
1573 	/* The net_device on which the monitor iface is based. */
1574 	struct net_device *base_ndev;
1575 	struct net_device *mon_ndev;
1576 	char ifname[IFNAMSIZ];
1577 	int flag;
1578 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
1579 	struct cfg80211_chan_def chandef;
1580 	/** Netmon Band Channel Config */
1581 	netmon_band_chan_cfg band_chan_cfg;
1582 #endif
1583 	/** Monitor device statistics structure */
1584 	struct net_device_stats stats;
1585 } monitor_iface;
1586 
1587 /** Handle data structure for MOAL */
1588 struct _moal_handle {
1589 	/** MLAN adapter structure */
1590 	t_void *pmlan_adapter;
1591 	/** Private pointer */
1592 	moal_private *priv[MLAN_MAX_BSS_NUM];
1593 	/** Priv number */
1594 	t_u8 priv_num;
1595 	/** Bss attr */
1596 	moal_drv_mode drv_mode;
1597 
1598 	/** Monitor interface */
1599 	monitor_iface *mon_if;
1600 
1601 	/** set mac address flag */
1602 	t_u8 set_mac_addr;
1603 	/** MAC address */
1604 	t_u8 mac_addr[ETH_ALEN];
1605 #ifdef CONFIG_PROC_FS
1606 	/** Proc top level directory entry */
1607 	struct proc_dir_entry *proc_mwlan;
1608 #endif
1609 	/** Firmware */
1610 	const struct firmware *firmware;
1611 	/** Firmware request start time */
1612 	struct timeval req_fw_time;
1613 	/** Init config file */
1614 	const struct firmware *init_cfg_data;
1615 	/** Init config file */
1616 	const struct firmware *user_data;
1617 	/** Init user configure wait queue token */
1618 	t_u16 init_user_conf_wait_flag;
1619 	/** Init user configure file wait queue */
1620 	wait_queue_head_t init_user_conf_wait_q __ATTRIB_ALIGN__;
1621 	/** dpd config file */
1622 	const struct firmware *dpd_data;
1623 	/** txpwr data file */
1624 	const struct firmware *txpwr_data;
1625 	/** Hotplug device */
1626 	struct device *hotplug_device;
1627 	/** STATUS variables */
1628 	MOAL_HARDWARE_STATUS hardware_status;
1629 	BOOLEAN fw_reload;
1630 	/** POWER MANAGEMENT AND PnP SUPPORT */
1631 	BOOLEAN surprise_removed;
1632 	/** Firmware release number */
1633 	t_u32 fw_release_number;
1634 	/** ECSA support */
1635 	t_u8 fw_ecsa_enable;
1636 	/** FW ROAMING support */
1637 	t_u8 fw_roam_enable;
1638 	/** FW ROAMING capability in fw */
1639 	t_u8 fw_roaming_support;
1640 	/** Retry count for auto reconnect based on FW ROAMING*/
1641 	t_u16 auto_reconnect_retry_count;
1642 	/** The SSID for auto reconnect FW ROAMING*/
1643 	mlan_802_11_ssid auto_reconnect_ssid;
1644 	/** The BSSID for auto reconnect FW ROAMING*/
1645 	mlan_802_11_mac_addr auto_reconnect_bssid;
1646 	/** The parameters for FW  ROAMING*/
1647 	woal_roam_offload_cfg fw_roam_params;
1648 	/** The keys for FW  ROAMING*/
1649 	mlan_ds_passphrase ssid_passphrase[MAX_SEC_SSID_NUM];
1650 
1651 	/** Getlog support */
1652 	t_u8 fw_getlog_enable;
1653 	/** Init wait queue token */
1654 	t_u16 init_wait_q_woken;
1655 	/** Init wait queue */
1656 	wait_queue_head_t init_wait_q __ATTRIB_ALIGN__;
1657 #if defined(SDIO_SUSPEND_RESUME)
1658 	/** Device suspend flag */
1659 	BOOLEAN is_suspended;
1660 #ifdef SDIO_SUSPEND_RESUME
1661 	/** suspend notify flag */
1662 	BOOLEAN suspend_notify_req;
1663 #endif
1664 	/** Host Sleep activated flag */
1665 	t_u8 hs_activated;
1666 	/** Host Sleep activated event wait queue token */
1667 	t_u16 hs_activate_wait_q_woken;
1668 	/** Host Sleep activated event wait queue */
1669 	wait_queue_head_t hs_activate_wait_q __ATTRIB_ALIGN__;
1670     /** auto_arp and ipv6 offload enable/disable flag */
1671 	t_u8 hs_auto_arp;
1672 #endif
1673 	/** Card pointer */
1674 	t_void *card;
1675 	/** Rx pending in MLAN */
1676 	atomic_t rx_pending;
1677 	/** Tx packet pending count in mlan */
1678 	atomic_t tx_pending;
1679 	/** IOCTL pending count in mlan */
1680 	atomic_t ioctl_pending;
1681 	/** lock count */
1682 	atomic_t lock_count;
1683 	/** Malloc count */
1684 	atomic_t malloc_count;
1685 	/** vmalloc count */
1686 	atomic_t vmalloc_count;
1687 	/** mlan buffer alloc count */
1688 	atomic_t mbufalloc_count;
1689 #if defined(SDIO_SUSPEND_RESUME)
1690 	/** hs skip count */
1691 	t_u32 hs_skip_count;
1692 	/** hs force count */
1693 	t_u32 hs_force_count;
1694 	/** suspend_fail flag */
1695 	BOOLEAN suspend_fail;
1696 #endif
1697 #ifdef REASSOCIATION
1698 	/** Re-association thread */
1699 	moal_thread reassoc_thread;
1700 	/** Re-association timer set flag */
1701 	BOOLEAN is_reassoc_timer_set;
1702 	/** Re-association timer */
1703 	moal_drv_timer reassoc_timer __ATTRIB_ALIGN__;
1704 	/**  */
1705 	struct semaphore reassoc_sem;
1706 	/** Bitmap for re-association on/off */
1707 	t_u8 reassoc_on;
1708 #endif				/* REASSOCIATION */
1709 	/** Driver workqueue */
1710 	struct workqueue_struct *workqueue;
1711 	/** main work */
1712 	struct work_struct main_work;
1713     /** Driver workqueue */
1714 	struct workqueue_struct *rx_workqueue;
1715 	/** main work */
1716 	struct work_struct rx_work;
1717 #if defined(STA_CFG80211) || defined(UAP_CFG80211)
1718 	struct wiphy *wiphy;
1719 	/** Country code for regulatory domain */
1720 	t_u8 country_code[COUNTRY_CODE_LEN];
1721     /** band */
1722 	enum ieee80211_band band;
1723     /** first scan done flag */
1724 	t_u8 first_scan_done;
1725     /** scan channel gap */
1726 	t_u16 scan_chan_gap;
1727 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)
1728     /** remain on channel flag */
1729 	t_u8 remain_on_channel;
1730 	/** bss index for remain on channel */
1731 	t_u8 remain_bss_index;
1732 	/** remain_on_channel timer set flag */
1733 	BOOLEAN is_remain_timer_set;
1734 	/** remani_on_channel_timer */
1735 	moal_drv_timer remain_timer __ATTRIB_ALIGN__;
1736 	/** ieee802_11_channel */
1737 	struct ieee80211_channel chan;
1738 #if CFG80211_VERSION_CODE < KERNEL_VERSION(3, 8, 0)
1739 	/** channel type */
1740 	enum nl80211_channel_type channel_type;
1741 #endif
1742 	/** cookie */
1743 	t_u64 cookie;
1744 #endif
1745 #ifdef WIFI_DIRECT_SUPPORT
1746     /** NoA duration */
1747 	t_u32 noa_duration;
1748     /** NoA interval */
1749 	t_u32 noa_interval;
1750     /** miracast mode */
1751 	t_u8 miracast_mode;
1752 	/** scan time in miracast mode */
1753 	t_u16 miracast_scan_time;
1754 
1755 	/** GO timer set flag */
1756 	BOOLEAN is_go_timer_set;
1757 	/** GO timer */
1758 	moal_drv_timer go_timer __ATTRIB_ALIGN__;
1759 #endif
1760 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
1761 	/** cfg80211_suspend status */
1762 	t_u8 cfg80211_suspend;
1763 #endif
1764 #endif
1765 	/** Read SDIO registers for debugging */
1766 	t_u32 sdio_reg_dbg;
1767 	/** Netlink kernel socket */
1768 	struct sock *nl_sk;
1769 	/** Netlink kernel socket number */
1770 	t_u32 netlink_num;
1771     /** w_stats wait queue token */
1772 	BOOLEAN meas_wait_q_woken;
1773     /** w_stats wait queue */
1774 	wait_queue_head_t meas_wait_q __ATTRIB_ALIGN__;
1775     /** Measurement start jiffes */
1776 	long meas_start_jiffies;
1777     /** CAC checking period flag */
1778 	BOOLEAN cac_period;
1779     /** CAC timer jiffes */
1780 	long cac_timer_jiffies;
1781     /** BSS START command delay executing flag */
1782 	BOOLEAN delay_bss_start;
1783     /** SSID,BSSID parameter of delay executing */
1784 	mlan_ssid_bssid delay_ssid_bssid;
1785 #ifdef UAP_CFG80211
1786 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)
1787 	/* CAC channel info */
1788 	struct cfg80211_chan_def dfs_channel;
1789 	/* time set flag */
1790 	BOOLEAN is_cac_timer_set;
1791     /** cac_timer */
1792 	moal_drv_timer cac_timer __ATTRIB_ALIGN__;
1793 	/** cac bss index */
1794 	t_u8 cac_bss_index;
1795 #endif
1796 #endif
1797 #if defined(UAP_SUPPORT)
1798 /** channel switch wait queue token */
1799 	BOOLEAN chsw_wait_q_woken;
1800     /** channel switch wait queue */
1801 	wait_queue_head_t chsw_wait_q __ATTRIB_ALIGN__;
1802 #endif
1803 #ifdef DFS_TESTING_SUPPORT
1804     /** cac period length, valid only when dfs testing is enabled */
1805 	long cac_period_jiffies;
1806 #endif
1807     /** handle index - for multiple card supports */
1808 	t_u8 handle_idx;
1809 #ifdef SDIO_MMC_DEBUG
1810 	/** cmd53 write state */
1811 	u8 cmd53w;
1812 	/** cmd53 read state */
1813 	u8 cmd53r;
1814 #endif
1815 #ifdef STA_SUPPORT
1816 	/** Scan pending on blocked flag */
1817 	t_u8 scan_pending_on_block;
1818     /** Scan Private pointer */
1819 	moal_private *scan_priv;
1820 	/** Async scan semaphore */
1821 	struct semaphore async_sem;
1822 #ifdef STA_CFG80211
1823 	/** CFG80211 scan request description */
1824 	struct cfg80211_scan_request *scan_request;
1825 #endif
1826 #endif
1827 	/** main state */
1828 	t_u8 main_state;
1829     /** driver state */
1830 	t_u8 driver_state;
1831     /** ioctl timeout */
1832 	t_u8 ioctl_timeout;
1833     /** FW dump state */
1834 	t_u8 fw_dump;
1835 	/** cmd52 function */
1836 	t_u8 cmd52_func;
1837 	/** cmd52 register */
1838 	t_u8 cmd52_reg;
1839 	/** cmd52 value */
1840 	t_u8 cmd52_val;
1841 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
1842 	/** spinlock to stop_queue/wake_queue*/
1843 	spinlock_t queue_lock;
1844 #endif
1845 	/** Driver spin lock */
1846 	spinlock_t driver_lock;
1847 	/** Driver ioctl spin lock */
1848 	spinlock_t ioctl_lock;
1849 	/** lock for scan_request */
1850 	spinlock_t scan_req_lock;
1851 	/** Card specific driver version */
1852 	t_s8 driver_version[MLAN_MAX_VER_STR_LEN];
1853 	char *fwdump_fname;
1854 #ifdef ANDROID_KERNEL
1855 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
1856 	struct wakeup_source ws;
1857 #else
1858 	struct wake_lock wake_lock;
1859 #endif
1860 #endif
1861 	t_u16 dfs_repeater_mode;
1862 	t_u8 histogram_table_num;
1863 	struct notifier_block woal_notifier;
1864 #if defined(STA_CFG80211) || defined(UAP_CFG80211)
1865 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
1866 	struct ieee80211_regdomain *regd;
1867 #endif
1868 #endif
1869 	struct net_device napi_dev;
1870 	struct napi_struct napi_rx;
1871 };
1872 /**
1873  *  @brief set trans_start for each TX queue.
1874  *
1875  *  @param dev		A pointer to net_device structure
1876  *
1877  *  @return			N/A
1878  */
1879 static inline void
woal_set_trans_start(struct net_device * dev)1880 woal_set_trans_start(struct net_device *dev)
1881 {
1882 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
1883 	unsigned int i;
1884 	for (i = 0; i < dev->num_tx_queues; i++)
1885 		netdev_get_tx_queue(dev, i)->trans_start = jiffies;
1886 #endif
1887 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
1888 	dev->trans_start = jiffies;
1889 #else
1890 	netif_trans_update(dev);
1891 #endif
1892 }
1893 
1894 /**
1895  *  @brief Start queue
1896  *
1897  *  @param dev		A pointer to net_device structure
1898  *
1899  *  @return			N/A
1900  */
1901 static inline void
woal_start_queue(struct net_device * dev)1902 woal_start_queue(struct net_device *dev)
1903 {
1904 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 29)
1905 	netif_start_queue(dev);
1906 #else
1907 	if (dev->reg_state == NETREG_REGISTERED)
1908 		netif_tx_wake_all_queues(dev);
1909 	else
1910 		netif_tx_start_all_queues(dev);
1911 #endif
1912 }
1913 
1914 /**
1915  *  @brief Stop queue
1916  *
1917  *  @param dev		A pointer to net_device structure
1918  *
1919  *  @return			N/A
1920  */
1921 static inline void
woal_stop_queue(struct net_device * dev)1922 woal_stop_queue(struct net_device *dev)
1923 {
1924 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
1925 	unsigned long flags;
1926 	moal_private *priv = (moal_private *)netdev_priv(dev);
1927 	spin_lock_irqsave(&priv->phandle->queue_lock, flags);
1928 	woal_set_trans_start(dev);
1929 	if (!netif_queue_stopped(dev))
1930 		netif_tx_stop_all_queues(dev);
1931 	spin_unlock_irqrestore(&priv->phandle->queue_lock, flags);
1932 #else
1933 	woal_set_trans_start(dev);
1934 	if (!netif_queue_stopped(dev))
1935 		netif_stop_queue(dev);
1936 #endif
1937 }
1938 
1939 /**
1940  *  @brief wake queue
1941  *
1942  *  @param dev		A pointer to net_device structure
1943  *
1944  *  @return			N/A
1945  */
1946 static inline void
woal_wake_queue(struct net_device * dev)1947 woal_wake_queue(struct net_device *dev)
1948 {
1949 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
1950 	unsigned long flags;
1951 	moal_private *priv = (moal_private *)netdev_priv(dev);
1952 	spin_lock_irqsave(&priv->phandle->queue_lock, flags);
1953 	if (netif_queue_stopped(dev))
1954 		netif_tx_wake_all_queues(dev);
1955 	spin_unlock_irqrestore(&priv->phandle->queue_lock, flags);
1956 #else
1957 	if (netif_queue_stopped(dev))
1958 		netif_wake_queue(dev);
1959 #endif
1960 }
1961 
1962 /** Debug Macro definition*/
1963 #ifdef	DEBUG_LEVEL1
1964 extern t_u32 drvdbg;
1965 
1966 #define LOG_CTRL(level)     (0)
1967 
1968 #ifdef	DEBUG_LEVEL2
1969 #define	PRINTM_MINFO(level, msg...) do { \
1970 	woal_print(level, msg); \
1971 	if (drvdbg & MINFO) printk(KERN_DEBUG msg); \
1972 } while (0)
1973 #define	PRINTM_MWARN(level, msg...) do { \
1974 	woal_print(level, msg); \
1975 	if (drvdbg & MWARN) printk(KERN_DEBUG msg); \
1976 } while (0)
1977 #define	PRINTM_MENTRY(level, msg...) do { \
1978 	woal_print(level, msg); \
1979 	if (drvdbg & MENTRY) printk(KERN_DEBUG msg); \
1980 } while (0)
1981 #else
1982 #define	PRINTM_MINFO(level, msg...)  do {} while (0)
1983 #define	PRINTM_MWARN(level, msg...)  do {} while (0)
1984 #define	PRINTM_MENTRY(level, msg...) do {} while (0)
1985 #endif /* DEBUG_LEVEL2 */
1986 
1987 #define	PRINTM_MFW_D(level, msg...) do { \
1988 	woal_print(level, msg); \
1989 	if (drvdbg & MFW_D) printk(KERN_DEBUG msg); \
1990 } while (0)
1991 #define	PRINTM_MCMD_D(level, msg...) do { \
1992 	woal_print(level, msg); \
1993 	if (drvdbg & MCMD_D) printk(KERN_DEBUG msg); \
1994 } while (0)
1995 #define	PRINTM_MDAT_D(level, msg...) do { \
1996 	woal_print(level, msg); \
1997 	if (drvdbg & MDAT_D) printk(KERN_DEBUG msg); \
1998 } while (0)
1999 #define	PRINTM_MIF_D(level, msg...) do { \
2000 	woal_print(level, msg); \
2001 	if (drvdbg & MIF_D) printk(KERN_DEBUG msg); \
2002 } while (0)
2003 
2004 #define	PRINTM_MIOCTL(level, msg...) do { \
2005 	woal_print(level, msg); \
2006 	if (drvdbg & MIOCTL) printk(KERN_DEBUG msg); \
2007 } while (0)
2008 #define	PRINTM_MINTR(level, msg...) do { \
2009 	woal_print(level, msg); \
2010 	if (drvdbg & MINTR) printk(KERN_DEBUG msg); \
2011 } while (0)
2012 #define	PRINTM_MEVENT(level, msg...) do { \
2013 	woal_print(level, msg); \
2014 	if (drvdbg & MEVENT) printk(msg); \
2015 } while (0)
2016 #define	PRINTM_MCMND(level, msg...) do { \
2017 	woal_print(level, msg); \
2018 	if (drvdbg & MCMND) printk(KERN_DEBUG msg); \
2019 } while (0)
2020 #define	PRINTM_MDATA(level, msg...) do { \
2021 	woal_print(level, msg); \
2022 	if (drvdbg & MDATA) printk(KERN_DEBUG msg); \
2023 } while (0)
2024 #define	PRINTM_MERROR(level, msg...) do { \
2025 	woal_print(level, msg); \
2026 	if (drvdbg & MERROR) printk(KERN_ERR msg); \
2027 } while (0)
2028 #define	PRINTM_MFATAL(level, msg...) do { \
2029 	woal_print(level, msg); \
2030 	if (drvdbg & MFATAL) printk(KERN_ERR msg); \
2031 } while (0)
2032 #define	PRINTM_MMSG(level, msg...) do { \
2033 	woal_print(level, msg); \
2034 	if (drvdbg & MMSG) printk(KERN_ALERT msg); \
2035 } while (0)
2036 
2037 static inline void
woal_print(t_u32 level,char * fmt,...)2038 woal_print(t_u32 level, char *fmt, ...)
2039 {
2040 }
2041 
2042 #define	PRINTM(level, msg...) PRINTM_##level(level, msg)
2043 
2044 #else
2045 
2046 #define	PRINTM(level, msg...) do {} while (0)
2047 
2048 #endif /* DEBUG_LEVEL1 */
2049 
2050 /** Wait until a condition becomes true */
2051 #define MASSERT(cond)                   \
2052 do {                                    \
2053 	if (!(cond)) {                      \
2054 	    PRINTM(MFATAL, "ASSERT: %s: %i\n", __func__, __LINE__); \
2055 	    panic("Assert failed: Panic!"); \
2056 	}                                   \
2057 } while (0)
2058 
2059 /** Log entry point for debugging */
2060 #define	ENTER()			PRINTM(MENTRY, "Enter: %s\n", \
2061 									__func__)
2062 /** Log exit point for debugging */
2063 #define	LEAVE()			PRINTM(MENTRY, "Leave: %s\n", \
2064 									__func__)
2065 
2066 #ifdef DEBUG_LEVEL1
2067 #define DBG_DUMP_BUF_LEN	64
2068 #define MAX_DUMP_PER_LINE	16
2069 
2070 static inline void
hexdump(t_u32 level,char * prompt,t_u8 * buf,int len)2071 hexdump(t_u32 level, char *prompt, t_u8 *buf, int len)
2072 {
2073 	int i;
2074 	char dbgdumpbuf[DBG_DUMP_BUF_LEN];
2075 	char *ptr = dbgdumpbuf;
2076 
2077 	if (drvdbg & level)
2078 		printk(KERN_DEBUG "%s:\n", prompt);
2079 	for (i = 1; i <= len; i++) {
2080 		ptr += snprintf(ptr, 4, "%02x ", *buf);
2081 		buf++;
2082 		if (i % MAX_DUMP_PER_LINE == 0) {
2083 			*ptr = 0;
2084 			if (drvdbg & level)
2085 				printk(KERN_DEBUG "%s\n", dbgdumpbuf);
2086 			ptr = dbgdumpbuf;
2087 		}
2088 	}
2089 	if (len % MAX_DUMP_PER_LINE) {
2090 		*ptr = 0;
2091 		if (drvdbg & level)
2092 			printk(KERN_DEBUG "%s\n", dbgdumpbuf);
2093 	}
2094 }
2095 
2096 #define DBG_HEXDUMP_MERROR(x, y, z) do { \
2097 	if ((drvdbg & MERROR) || LOG_CTRL(MERROR)) \
2098 		hexdump(MERROR, x, y, z); \
2099 } while (0)
2100 #define DBG_HEXDUMP_MCMD_D(x, y, z) do { \
2101 	if ((drvdbg & MCMD_D) || LOG_CTRL(MCMD_D)) \
2102 		hexdump(MCMD_D, x, y, z); \
2103 } while (0)
2104 #define DBG_HEXDUMP_MDAT_D(x, y, z) do { \
2105 	if ((drvdbg & MDAT_D) || LOG_CTRL(MDAT_D)) \
2106 		hexdump(MDAT_D, x, y, z); \
2107 } while (0)
2108 #define DBG_HEXDUMP_MIF_D(x, y, z) do { \
2109 	if ((drvdbg & MIF_D)  || LOG_CTRL(MIF_D)) \
2110 		hexdump(MIF_D, x, y, z); \
2111 } while (0)
2112 #define DBG_HEXDUMP_MEVT_D(x, y, z) do { \
2113 	if ((drvdbg & MEVT_D) || LOG_CTRL(MEVT_D)) \
2114 		hexdump(MEVT_D, x, y, z); \
2115 } while (0)
2116 #define DBG_HEXDUMP_MFW_D(x, y, z) do { \
2117 	if ((drvdbg & MFW_D)  || LOG_CTRL(MFW_D)) \
2118 		hexdump(MFW_D, x, y, z); \
2119 } while (0)
2120 #define	DBG_HEXDUMP(level, x, y, z)    DBG_HEXDUMP_##level(x, y, z)
2121 
2122 #else
2123 /** Do nothing since debugging is not turned on */
2124 #define DBG_HEXDUMP(level, x, y, z)    do {} while (0)
2125 #endif
2126 
2127 #ifdef DEBUG_LEVEL2
2128 #define HEXDUMP(x, y, z) do { \
2129 	if ((drvdbg & MINFO) || LOG_CTRL(MINFO)) \
2130 		hexdump(MINFO, x, y, z); \
2131 } while (0)
2132 #else
2133 /** Do nothing since debugging is not turned on */
2134 #define HEXDUMP(x, y, z)            do {} while (0)
2135 #endif
2136 
2137 #ifdef BIG_ENDIAN_SUPPORT
2138 /** Convert from 16 bit little endian format to CPU format */
2139 #define woal_le16_to_cpu(x) le16_to_cpu(x)
2140 /** Convert from 32 bit little endian format to CPU format */
2141 #define woal_le32_to_cpu(x) le32_to_cpu(x)
2142 /** Convert from 64 bit little endian format to CPU format */
2143 #define woal_le64_to_cpu(x) le64_to_cpu(x)
2144 /** Convert to 16 bit little endian format from CPU format */
2145 #define woal_cpu_to_le16(x) cpu_to_le16(x)
2146 /** Convert to 32 bit little endian format from CPU format */
2147 #define woal_cpu_to_le32(x) cpu_to_le32(x)
2148 /** Convert to 64 bit little endian format from CPU format */
2149 #define woal_cpu_to_le64(x) cpu_to_le64(x)
2150 #else
2151 /** Do nothing */
2152 #define woal_le16_to_cpu(x) x
2153 /** Do nothing */
2154 #define woal_le32_to_cpu(x) x
2155 /** Do nothing */
2156 #define woal_le64_to_cpu(x) x
2157 /** Do nothing */
2158 #define woal_cpu_to_le16(x) x
2159 /** Do nothing */
2160 #define woal_cpu_to_le32(x) x
2161 /** Do nothing */
2162 #define woal_cpu_to_le64(x) x
2163 #endif
2164 
2165 /**
2166  *  @brief This function returns first available priv
2167  *  based on the BSS role
2168  *
2169  *  @param handle    A pointer to moal_handle
2170  *  @param bss_role  BSS role or MLAN_BSS_ROLE_ANY
2171  *
2172  *  @return          Pointer to moal_private
2173  */
2174 static inline moal_private *
woal_get_priv(moal_handle * handle,mlan_bss_role bss_role)2175 woal_get_priv(moal_handle *handle, mlan_bss_role bss_role)
2176 {
2177 	int i;
2178 
2179 	for (i = 0; i < MIN(handle->priv_num, MLAN_MAX_BSS_NUM); i++) {
2180 		if (handle->priv[i]) {
2181 			if (bss_role == MLAN_BSS_ROLE_ANY ||
2182 			    GET_BSS_ROLE(handle->priv[i]) == bss_role)
2183 				return handle->priv[i];
2184 		}
2185 	}
2186 	return NULL;
2187 }
2188 
2189 /**
2190  *  @brief This function returns first available priv
2191  *  based on the BSS type
2192  *
2193  *  @param handle    A pointer to moal_handle
2194  *  @param bss_type  BSS type or MLAN_BSS_TYPE_ANY
2195  *
2196  *  @return          Pointer to moal_private
2197  */
2198 static inline moal_private *
woal_get_priv_bss_type(moal_handle * handle,mlan_bss_type bss_type)2199 woal_get_priv_bss_type(moal_handle *handle, mlan_bss_type bss_type)
2200 {
2201 	int i;
2202 
2203 	for (i = 0; i < MIN(handle->priv_num, MLAN_MAX_BSS_NUM); i++) {
2204 		if (handle->priv[i]) {
2205 			if (bss_type == MLAN_BSS_TYPE_ANY ||
2206 			    handle->priv[i]->bss_type == bss_type)
2207 				return handle->priv[i];
2208 		}
2209 	}
2210 	return NULL;
2211 }
2212 
2213 /* CAC Measure report default time 60 seconds */
2214 #define MEAS_REPORT_TIME (60 * HZ)
2215 
2216 /** Max line length allowed in init config file */
2217 #define MAX_LINE_LEN        256
2218 /** Max MAC address string length allowed */
2219 #define MAX_MAC_ADDR_LEN    18
2220 /** Max register type/offset/value etc. parameter length allowed */
2221 #define MAX_PARAM_LEN       12
2222 
2223 /** HostCmd_CMD_CFG_DATA for CAL data */
2224 #define HostCmd_CMD_CFG_DATA 0x008f
2225 /** HostCmd action set */
2226 #define HostCmd_ACT_GEN_SET 0x0001
2227 /** HostCmd CAL data header length */
2228 #define CFG_DATA_HEADER_LEN	6
2229 
2230 typedef struct _HostCmd_DS_GEN {
2231 	t_u16 command;
2232 	t_u16 size;
2233 	t_u16 seq_num;
2234 	t_u16 result;
2235 } HostCmd_DS_GEN;
2236 
2237 typedef struct _HostCmd_DS_802_11_CFG_DATA {
2238     /** Action */
2239 	t_u16 action;
2240     /** Type */
2241 	t_u16 type;
2242     /** Data length */
2243 	t_u16 data_len;
2244     /** Data */
2245 	t_u8 data[1];
2246 } __ATTRIB_PACK__ HostCmd_DS_802_11_CFG_DATA;
2247 
2248 /** combo scan header */
2249 #define WEXT_CSCAN_HEADER		"CSCAN S\x01\x00\x00S\x00"
2250 /** combo scan header size */
2251 #define WEXT_CSCAN_HEADER_SIZE		12
2252 /** combo scan ssid section */
2253 #define WEXT_CSCAN_SSID_SECTION		'S'
2254 /** commbo scan channel section */
2255 #define WEXT_CSCAN_CHANNEL_SECTION	'C'
2256 /** commbo scan passive dwell section */
2257 #define WEXT_CSCAN_PASV_DWELL_SECTION	'P'
2258 /** commbo scan home dwell section */
2259 #define WEXT_CSCAN_HOME_DWELL_SECTION	'H'
2260 /** BGSCAN RSSI section */
2261 #define WEXT_BGSCAN_RSSI_SECTION	 'R'
2262 /** BGSCAN SCAN INTERVAL SECTION */
2263 #define WEXT_BGSCAN_INTERVAL_SECTION 'T'
2264 /** BGSCAN REPEAT SECTION */
2265 #define WEXT_BGSCAN_REPEAT_SECTION  'E'
2266 /** Min BGSCAN interval 30 second */
2267 #define MIN_BGSCAN_INTERVAL	 30000
2268 /** default repeat count */
2269 #define DEF_REPEAT_COUNT	 6
2270 
2271 /** default rssi low threshold */
2272 #define DEFAULT_RSSI_LOW_THRESHOLD 70
2273 /** RSSI HYSTERSIS */
2274 #define RSSI_HYSTERESIS		6
2275 /** lowest rssi threshold */
2276 #define LOWEST_RSSI_THRESHOLD	82
2277 /** delta rssi */
2278 #define DELTA_RSSI 10
2279 
2280 /** NL80211 scan configuration header */
2281 #define NL80211_SCANCFG_HEADER		"SCAN-CFG "
2282 /** NL80211 scan configuration header length */
2283 #define NL80211_SCANCFG_HEADER_SIZE		9
2284 /** NL80211 scan configuration active scan section */
2285 #define NL80211_SCANCFG_ACTV_DWELL_SECTION	'A'
2286 /** NL80211 scan configuration passive scan section */
2287 #define NL80211_SCANCFG_PASV_DWELL_SECTION	'P'
2288 /** NL80211 scan configuration specific scan section */
2289 #define NL80211_SCANCFG_SPCF_DWELL_SECTION	'S'
2290 
2291 /** band AUTO */
2292 #define	WIFI_FREQUENCY_BAND_AUTO		0
2293 /** band 5G */
2294 #define	WIFI_FREQUENCY_BAND_5GHZ        1
2295 /** band 2G */
2296 #define	WIFI_FREQUENCY_BAND_2GHZ		2
2297 /** All band */
2298 #define WIFI_FREQUENCY_ALL_BAND         3
2299 
2300 /** Rx filter: IPV4 multicast */
2301 #define RX_FILTER_IPV4_MULTICAST        1
2302 /** Rx filter: broadcast */
2303 #define RX_FILTER_BROADCAST             2
2304 /** Rx filter: unicast */
2305 #define RX_FILTER_UNICAST               4
2306 /** Rx filter: IPV6 multicast */
2307 #define RX_FILTER_IPV6_MULTICAST        8
2308 
2309 /**  Convert ASCII string to hex value */
2310 int woal_ascii2hex(t_u8 *d, char *s, t_u32 dlen);
2311 /** parse ie */
2312 const t_u8 *woal_parse_ie_tlv(const t_u8 *ie, int len, t_u8 id);
2313 /**  Convert mac address from string to t_u8 buffer */
2314 void woal_mac2u8(t_u8 *mac_addr, char *buf);
2315 /**  Extract token from string */
2316 char *woal_strsep(char **s, char delim, char esc);
2317 /** Return int value of a given ASCII string */
2318 mlan_status woal_atoi(int *data, char *a);
2319 /** Return hex value of a given ASCII string */
2320 int woal_atox(char *a);
2321 /** Allocate buffer */
2322 pmlan_buffer woal_alloc_mlan_buffer(moal_handle *handle, int size);
2323 /** Allocate IOCTL request buffer */
2324 pmlan_ioctl_req woal_alloc_mlan_ioctl_req(int size);
2325 /** Free buffer */
2326 void woal_free_mlan_buffer(moal_handle *handle, pmlan_buffer pmbuf);
2327 /** Get private structure of a BSS by index */
2328 moal_private *woal_bss_index_to_priv(moal_handle *handle, t_u8 bss_index);
2329 /* Functions in interface module */
2330 /** Add card */
2331 moal_handle *woal_add_card(void *card);
2332 /** Remove card */
2333 mlan_status woal_remove_card(void *card);
2334 /** broadcast event */
2335 mlan_status woal_broadcast_event(moal_private *priv, t_u8 *payload, t_u32 len);
2336 #ifdef CONFIG_PROC_FS
2337 /** switch driver mode */
2338 mlan_status woal_switch_drv_mode(moal_handle *handle, t_u32 mode);
2339 #endif
2340 
2341 /** Interrupt handler */
2342 mlan_status woal_interrupt(moal_handle *handle);
2343 
2344 /** check if any interface is up */
2345 t_u8 woal_is_any_interface_active(moal_handle *handle);
2346 /** Get version */
2347 void woal_get_version(moal_handle *handle, char *version, int maxlen);
2348 /** Get Driver Version */
2349 int woal_get_driver_version(moal_private *priv, struct ifreq *req);
2350 /** Get extended driver version */
2351 int woal_get_driver_verext(moal_private *priv, struct ifreq *ireq);
2352 /** check driver status */
2353 t_u8 woal_check_driver_status(moal_handle *handle);
2354 /** Mgmt frame forward registration */
2355 int woal_reg_rx_mgmt_ind(moal_private *priv, t_u16 action,
2356 			 t_u32 *pmgmt_subtype_mask, t_u8 wait_option);
2357 #ifdef DEBUG_LEVEL1
2358 /** Set driver debug bit masks */
2359 int woal_set_drvdbg(moal_private *priv, t_u32 drvdbg);
2360 #endif
2361 
2362 mlan_status woal_set_get_tx_bf_cap(moal_private *priv, t_u16 action,
2363 				   t_u32 *tx_bf_cap);
2364 /** Set/Get TX beamforming configurations */
2365 mlan_status woal_set_get_tx_bf_cfg(moal_private *priv, t_u16 action,
2366 				   mlan_ds_11n_tx_bf_cfg *bf_cfg);
2367 /** Request MAC address setting */
2368 mlan_status woal_request_set_mac_address(moal_private *priv);
2369 /** Request multicast list setting */
2370 void woal_request_set_multicast_list(moal_private *priv,
2371 				     struct net_device *dev);
2372 /** Request IOCTL action */
2373 mlan_status woal_request_ioctl(moal_private *priv, mlan_ioctl_req *req,
2374 			       t_u8 wait_option);
2375 #ifdef CONFIG_PROC_FS
2376 mlan_status woal_request_soft_reset(moal_handle *handle);
2377 #endif
2378 void woal_request_fw_reload(moal_handle *handle, t_u8 mode);
2379 /** driver initial the fw reset */
2380 #define FW_RELOAD_SDIO_INBAND_RESET   1
2381 /** out band reset trigger reset, no interface re-emulation */
2382 #define FW_RELOAD_NO_EMULATION  2
2383 /** out band reset with interface re-emulation */
2384 #define FW_RELOAD_WITH_EMULATION 3
2385 
2386 #ifdef PROC_DEBUG
2387 /** Get debug information */
2388 mlan_status woal_get_debug_info(moal_private *priv, t_u8 wait_option,
2389 				mlan_debug_info *debug_info);
2390 /** Set debug information */
2391 mlan_status woal_set_debug_info(moal_private *priv, t_u8 wait_option,
2392 				mlan_debug_info *debug_info);
2393 #endif
2394 /** Disconnect */
2395 mlan_status woal_disconnect(moal_private *priv, t_u8 wait_option, t_u8 *mac,
2396 			    t_u16 reason_code);
2397 /** associate */
2398 mlan_status woal_bss_start(moal_private *priv, t_u8 wait_option,
2399 			   mlan_ssid_bssid *ssid_bssid);
2400 /** Request firmware information */
2401 mlan_status woal_request_get_fw_info(moal_private *priv, t_u8 wait_option,
2402 				     mlan_fw_info *fw_info);
2403 #ifdef STA_SUPPORT
2404 /** Request Exented Capability information */
2405 int woal_request_extcap(moal_private *priv, t_u8 *buf, t_u8 len);
2406 #endif
2407 mlan_status woal_set_get_dtim_period(moal_private *priv,
2408 				     t_u32 action, t_u8 wait_option,
2409 				     t_u8 *value);
2410 /** Set/get Host Sleep parameters */
2411 mlan_status woal_set_get_hs_params(moal_private *priv, t_u16 action,
2412 				   t_u8 wait_option, mlan_ds_hs_cfg *hscfg);
2413 /** Cancel Host Sleep configuration */
2414 mlan_status woal_cancel_hs(moal_private *priv, t_u8 wait_option);
2415 #if defined(SDIO_SUSPEND_RESUME)
2416 /** Enable Host Sleep configuration */
2417 int woal_enable_hs(moal_private *priv);
2418 /** hs active timeout 2 second */
2419 #define HS_ACTIVE_TIMEOUT  (2 * HZ)
2420 #endif
2421 /** Get wakeup reason */
2422 mlan_status woal_get_wakeup_reason(moal_private *priv,
2423 				   mlan_ds_hs_wakeup_reason *wakeup_reason);
2424 
2425 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
2426 void woal_create_dump_dir(moal_handle *phandle, char *dir_buf, int buf_size);
2427 #endif
2428 mlan_status woal_save_dump_info_to_file(char *dir_name, char *file_name,
2429 					t_u8 *buf, t_u32 buf_len);
2430 void woal_dump_drv_info(moal_handle *phandle, t_u8 *dir_name);
2431 
2432 void woal_dump_firmware_info_v3(moal_handle *phandle);
2433 /* Store the FW dumps received from events in a file */
2434 void woal_store_firmware_dump(moal_handle *phandle, mlan_event *pmevent);
2435 
2436 /** get deep sleep */
2437 int woal_get_deep_sleep(moal_private *priv, t_u32 *data);
2438 /** set deep sleep */
2439 int woal_set_deep_sleep(moal_private *priv, t_u8 wait_option,
2440 			BOOLEAN bdeep_sleep, t_u16 idletime);
2441 /** process hang */
2442 void woal_process_hang(moal_handle *handle);
2443 /** Get BSS information */
2444 mlan_status woal_get_bss_info(moal_private *priv, t_u8 wait_option,
2445 			      mlan_bss_info *bss_info);
2446 void woal_process_ioctl_resp(moal_private *priv, mlan_ioctl_req *req);
2447 /** Set/Get generic element */
2448 mlan_status woal_set_get_gen_ie(moal_private *priv, t_u32 action, t_u8 *ie,
2449 				int *ie_len, t_u8 wait_option);
2450 char *region_code_2_string(t_u8 region_code);
2451 t_bool woal_is_etsi_country(t_u8 *country_code);
2452 t_u8 woal_is_valid_alpha2(char *alpha2);
2453 #ifdef STA_SUPPORT
2454 void woal_send_disconnect_to_system(moal_private *priv);
2455 void woal_send_mic_error_event(moal_private *priv, t_u32 event);
2456 void woal_ioctl_get_bss_resp(moal_private *priv, mlan_ds_bss *bss);
2457 void woal_ioctl_get_info_resp(moal_private *priv, mlan_ds_get_info *info);
2458 mlan_status woal_get_assoc_rsp(moal_private *priv,
2459 			       mlan_ds_misc_assoc_rsp *assoc_rsp,
2460 			       t_u8 wait_option);
2461 /** Get signal information */
2462 mlan_status woal_get_signal_info(moal_private *priv, t_u8 wait_option,
2463 				 mlan_ds_get_signal *signal);
2464 /** Get mode */
2465 t_u32 woal_get_mode(moal_private *priv, t_u8 wait_option);
2466 mlan_status woal_get_sta_channel(moal_private *priv, t_u8 wait_option,
2467 				 chan_band_info * channel);
2468 #ifdef STA_WEXT
2469 /** Get data rates */
2470 mlan_status woal_get_data_rates(moal_private *priv, t_u8 wait_option,
2471 				moal_802_11_rates *m_rates);
2472 void woal_send_iwevcustom_event(moal_private *priv, char *str);
2473 /** Get channel list */
2474 mlan_status woal_get_channel_list(moal_private *priv, t_u8 wait_option,
2475 				  mlan_chan_list *chanlist);
2476 mlan_status woal_11d_check_ap_channel(moal_private *priv, t_u8 wait_option,
2477 				      mlan_ssid_bssid *ssid_bssid);
2478 #endif
2479 /** Set/Get retry count */
2480 mlan_status woal_set_get_retry(moal_private *priv, t_u32 action,
2481 			       t_u8 wait_option, int *value);
2482 /** Set/Get RTS threshold */
2483 mlan_status woal_set_get_rts(moal_private *priv, t_u32 action, t_u8 wait_option,
2484 			     int *value);
2485 /** Set/Get fragment threshold */
2486 mlan_status woal_set_get_frag(moal_private *priv, t_u32 action,
2487 			      t_u8 wait_option, int *value);
2488 /** Set/Get TX power */
2489 mlan_status woal_set_get_tx_power(moal_private *priv, t_u32 action,
2490 				  mlan_power_cfg_t *pwr);
2491 /** Set/Get power IEEE management */
2492 mlan_status woal_set_get_power_mgmt(moal_private *priv, t_u32 action,
2493 				    int *disabled, int type, t_u8 wait_option);
2494 /** Get data rate */
2495 mlan_status woal_set_get_data_rate(moal_private *priv, t_u8 action,
2496 				   mlan_rate_cfg_t *datarate);
2497 /** Request a network scan */
2498 mlan_status woal_request_scan(moal_private *priv, t_u8 wait_option,
2499 			      mlan_802_11_ssid *req_ssid);
2500 /** Set radio on/off */
2501 int woal_set_radio(moal_private *priv, t_u8 option);
2502 /** Set region code */
2503 mlan_status woal_set_region_code(moal_private *priv, char *region);
2504 /** Set authentication mode */
2505 mlan_status woal_set_auth_mode(moal_private *priv, t_u8 wait_option,
2506 			       t_u32 auth_mode);
2507 /** Set encryption mode */
2508 mlan_status woal_set_encrypt_mode(moal_private *priv, t_u8 wait_option,
2509 				  t_u32 encrypt_mode);
2510 /** Enable wep key */
2511 mlan_status woal_enable_wep_key(moal_private *priv, t_u8 wait_option);
2512 /** Set WPA enable */
2513 mlan_status woal_set_wpa_enable(moal_private *priv, t_u8 wait_option,
2514 				t_u32 enable);
2515 
2516 /** cancel scan command */
2517 mlan_status woal_cancel_scan(moal_private *priv, t_u8 wait_option);
2518 /** Find best network to connect */
2519 mlan_status woal_find_best_network(moal_private *priv, t_u8 wait_option,
2520 				   mlan_ssid_bssid *ssid_bssid);
2521 /** Set Ad-Hoc channel */
2522 mlan_status woal_change_adhoc_chan(moal_private *priv, int channel,
2523 				   t_u8 wait_option);
2524 
2525 /** Get scan table */
2526 mlan_status woal_get_scan_table(moal_private *priv, t_u8 wait_option,
2527 				mlan_scan_resp *scanresp);
2528 /** Get authentication mode */
2529 mlan_status woal_get_auth_mode(moal_private *priv, t_u8 wait_option,
2530 			       t_u32 *auth_mode);
2531 /** Get encryption mode */
2532 mlan_status woal_get_encrypt_mode(moal_private *priv, t_u8 wait_option,
2533 				  t_u32 *encrypt_mode);
2534 /** Get WPA state */
2535 mlan_status woal_get_wpa_enable(moal_private *priv, t_u8 wait_option,
2536 				t_u32 *enable);
2537 #endif	/**STA_SUPPORT */
2538 mlan_status woal_set_11d(moal_private *priv, t_u8 wait_option, t_u8 enable);
2539 
2540 #if defined(STA_SUPPORT) || defined(UAP_SUPPORT)
2541 /** Get statistics information */
2542 mlan_status woal_get_stats_info(moal_private *priv, t_u8 wait_option,
2543 				mlan_ds_get_stats *stats);
2544 #endif	/**STA_SUPPORT||UAP_SUPPORT*/
2545 
2546 mlan_status woal_set_wapi_enable(moal_private *priv, t_u8 wait_option,
2547 				 t_u32 enable);
2548 
2549 /** Initialize priv */
2550 void woal_init_priv(moal_private *priv, t_u8 wait_option);
2551 /** Reset interface(s) */
2552 int woal_reset_intf(moal_private *priv, t_u8 wait_option, int all_intf);
2553 #define TLV_TYPE_MGMT_IE            (0x169)
2554 #define MGMT_MASK_ASSOC_REQ             0x01
2555 #define MGMT_MASK_REASSOC_REQ           0x04
2556 #define MGMT_MASK_ASSOC_RESP            0x02
2557 #define MGMT_MASK_REASSOC_RESP          0x08
2558 #define MGMT_MASK_PROBE_REQ             0x10
2559 #define MGMT_MASK_PROBE_RESP            0x20
2560 #define MGMT_MASK_BEACON                0x100
2561 #define MGMT_MASK_ASSOC_RESP_QOS_MAP        0x4000
2562 #define MGMT_MASK_BEACON_WPS_P2P        0x8000
2563 /** common ioctl for uap, station */
2564 int woal_custom_ie_ioctl(struct net_device *dev, struct ifreq *req);
2565 int woal_send_host_packet(struct net_device *dev, struct ifreq *req);
2566 /** Private command ID to pass mgmt frame */
2567 #define WOAL_MGMT_FRAME_TX_IOCTL          (SIOCDEVPRIVATE + 12)
2568 /** common ioctl for TDLS */
2569 int woal_tdls_config_ioctl(struct net_device *dev, struct ifreq *req);
2570 
2571 int woal_get_bss_type(struct net_device *dev, struct ifreq *req);
2572 #if defined(STA_WEXT) || defined(UAP_WEXT)
2573 int woal_host_command(moal_private *priv, struct iwreq *wrq);
2574 #endif
2575 #if defined(STA_SUPPORT) && defined(UAP_SUPPORT)
2576 mlan_status woal_bss_role_cfg(moal_private *priv, t_u8 action,
2577 			      t_u8 wait_option, t_u8 *bss_role);
2578 #if defined(STA_CFG80211) && defined(UAP_CFG80211)
2579 void woal_go_timer_func(void *context);
2580 #endif
2581 #if defined(STA_WEXT) || defined(UAP_WEXT)
2582 int woal_set_get_bss_role(moal_private *priv, struct iwreq *wrq);
2583 #endif
2584 #endif
2585 #if defined(WIFI_DIRECT_SUPPORT) || defined(UAP_SUPPORT)
2586 /** hostcmd ioctl for uap, wifidirect */
2587 int woal_hostcmd_ioctl(struct net_device *dev, struct ifreq *req);
2588 #endif
2589 
2590 mlan_status woal_set_remain_channel_ioctl(moal_private *priv, t_u8 wait_option,
2591 					  mlan_ds_remain_chan *pchan);
2592 void woal_remain_timer_func(void *context);
2593 
2594 #if defined(WIFI_DIRECT_SUPPORT)
2595 mlan_status woal_wifi_direct_mode_cfg(moal_private *priv, t_u16 action,
2596 				      t_u16 *mode);
2597 mlan_status woal_p2p_config(moal_private *priv, t_u32 action,
2598 			    mlan_ds_wifi_direct_config *p2p_config);
2599 #endif /* WIFI_DIRECT_SUPPORT */
2600 
2601 int woal_11h_cancel_chan_report_ioctl(moal_private *priv, t_u8 wait_option);
2602 
2603 #ifdef CONFIG_PROC_FS
2604 /** Initialize proc fs */
2605 void woal_proc_init(moal_handle *handle);
2606 /** Clean up proc fs */
2607 void woal_proc_exit(moal_handle *handle);
2608 /** Create proc entry */
2609 void woal_create_proc_entry(moal_private *priv);
2610 /** Remove proc entry */
2611 void woal_proc_remove(moal_private *priv);
2612 /** string to number */
2613 int woal_string_to_number(char *s);
2614 #endif
2615 
2616 #ifdef PROC_DEBUG
2617 /** Create debug proc fs */
2618 void woal_debug_entry(moal_private *priv);
2619 /** Remove debug proc fs */
2620 void woal_debug_remove(moal_private *priv);
2621 #endif /* PROC_DEBUG */
2622 
2623 /** check pm info */
2624 mlan_status woal_get_pm_info(moal_private *priv, mlan_ds_ps_info *pm_info);
2625 /** get mlan debug info */
2626 void woal_mlan_debug_info(moal_private *priv);
2627 
2628 #ifdef REASSOCIATION
2629 int woal_reassociation_thread(void *data);
2630 void woal_reassoc_timer_func(void *context);
2631 #endif /* REASSOCIATION */
2632 
2633 t_void woal_main_work_queue(struct work_struct *work);
2634 t_void woal_rx_work_queue(struct work_struct *work);
2635 
2636 int woal_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
2637 #ifdef STA_SUPPORT
2638 mlan_status woal_init_sta_dev(struct net_device *dev, moal_private *priv);
2639 #endif
2640 #ifdef UAP_SUPPORT
2641 mlan_status woal_init_uap_dev(struct net_device *dev, moal_private *priv);
2642 #endif
2643 mlan_status woal_update_drv_tbl(moal_handle *handle, int drv_mode_local);
2644 moal_private *woal_add_interface(moal_handle *handle, t_u8 bss_num,
2645 				 t_u8 bss_type);
2646 void woal_remove_interface(moal_handle *handle, t_u8 bss_index);
2647 void woal_set_multicast_list(struct net_device *dev);
2648 mlan_status woal_request_fw(moal_handle *handle);
2649 int woal_11h_channel_check_ioctl(moal_private *priv, t_u8 wait_option);
2650 void woal_cancel_cac_block(moal_private *priv);
2651 void woal_moal_debug_info(moal_private *priv, moal_handle *handle, u8 flag);
2652 
2653 #ifdef STA_SUPPORT
2654 mlan_status woal_get_powermode(moal_private *priv, int *powermode);
2655 mlan_status woal_set_scan_type(moal_private *priv, t_u32 scan_type);
2656 mlan_status woal_enable_ext_scan(moal_private *priv, t_u8 enable);
2657 mlan_status woal_set_powermode(moal_private *priv, char *powermode);
2658 int woal_find_essid(moal_private *priv, mlan_ssid_bssid *ssid_bssid,
2659 		    t_u8 wait_option);
2660 mlan_status woal_request_userscan(moal_private *priv, t_u8 wait_option,
2661 				  wlan_user_scan_cfg *scan_cfg);
2662 mlan_status woal_do_scan(moal_private *priv, wlan_user_scan_cfg *scan_cfg);
2663 int woal_set_combo_scan(moal_private *priv, char *buf, int length);
2664 mlan_status woal_set_scan_time(moal_private *priv, t_u16 active_scan_time,
2665 			       t_u16 passive_scan_time,
2666 			       t_u16 specific_scan_time);
2667 mlan_status woal_get_band(moal_private *priv, int *band);
2668 mlan_status woal_set_band(moal_private *priv, char *pband);
2669 mlan_status woal_add_rxfilter(moal_private *priv, char *rxfilter);
2670 mlan_status woal_remove_rxfilter(moal_private *priv, char *rxfilter);
2671 mlan_status woal_priv_qos_cfg(moal_private *priv, t_u32 action, char *qos_cfg);
2672 mlan_status woal_set_sleeppd(moal_private *priv, char *psleeppd);
2673 int woal_set_scan_cfg(moal_private *priv, char *buf, int length);
2674 void woal_update_dscp_mapping(moal_private *priv);
2675 
2676 /* EVENT: BCN_RSSI_LOW */
2677 #define EVENT_BCN_RSSI_LOW			0x0001
2678 /* EVENT: PRE_BCN_LOST */
2679 #define EVENT_PRE_BCN_LOST			0x0002
2680 mlan_status woal_set_rssi_low_threshold(moal_private *priv, char *rssi,
2681 					t_u8 wait_option);
2682 mlan_status woal_set_rssi_threshold(moal_private *priv, t_u32 event_id,
2683 				    t_u8 wait_option);
2684 /* EVENT: BG_SCAN_REPORT */
2685 #define EVENT_BG_SCAN_REPORT		0x0004
2686 mlan_status woal_set_bg_scan(moal_private *priv, char *buf, int length);
2687 mlan_status woal_stop_bg_scan(moal_private *priv, t_u8 wait_option);
2688 void woal_reconfig_bgscan(moal_handle *handle);
2689 #ifdef STA_CFG80211
2690 void woal_config_bgscan_and_rssi(moal_private *priv, t_u8 set_rssi);
2691 void woal_start_roaming(moal_private *priv);
2692 #endif
2693 #ifdef STA_CFG80211
2694 void woal_save_conn_params(moal_private *priv,
2695 			   struct cfg80211_connect_params *sme);
2696 void woal_clear_conn_params(moal_private *priv);
2697 #endif
2698 mlan_status woal_request_bgscan(moal_private *priv, t_u8 wait_option,
2699 				wlan_bgscan_cfg *scan_cfg);
2700 #endif
2701 
2702 void woal_flush_tcp_sess_queue(moal_private *priv);
2703 void woal_flush_tdls_list(moal_private *priv);
2704 void wlan_scan_create_brief_table_entry(t_u8 **ppbuffer,
2705 					BSSDescriptor_t *pbss_desc);
2706 int wlan_get_scan_table_ret_entry(BSSDescriptor_t *pbss_desc, t_u8 **ppbuffer,
2707 				  int *pspace_left);
2708 BOOLEAN woal_ssid_valid(mlan_802_11_ssid *pssid);
2709 int woal_is_connected(moal_private *priv, mlan_ssid_bssid *ssid_bssid);
2710 int woal_priv_hostcmd(moal_private *priv, t_u8 *respbuf, t_u32 respbuflen,
2711 		      t_u8 wait_option);
2712 void woal_flush_tx_stat_queue(moal_private *priv);
2713 struct tx_status_info *woal_get_tx_info(moal_private *priv, t_u8 tx_seq_num);
2714 void woal_remove_tx_info(moal_private *priv, t_u8 tx_seq_num);
2715 
2716 mlan_status woal_request_country_power_table(moal_private *priv, char *region);
2717 mlan_status woal_mc_policy_cfg(moal_private *priv, t_u16 *enable,
2718 			       t_u8 wait_option, t_u8 action);
2719 #ifdef RX_PACKET_COALESCE
2720 mlan_status woal_rx_pkt_coalesce_cfg(moal_private *priv, t_u16 *enable,
2721 				     t_u8 wait_option, t_u8 action);
2722 #endif
2723 int woal_hexval(char chr);
2724 mlan_status woal_pmic_configure(moal_handle *handle, t_u8 wait_option);
2725 void woal_hist_data_reset(moal_private *priv);
2726 void woal_hist_do_reset(moal_private *priv, void *data);
2727 void woal_hist_reset_table(moal_private *priv, t_u8 antenna);
2728 void woal_hist_data_add(moal_private *priv, t_u8 rx_rate, t_s8 snr, t_s8 nflr,
2729 			t_u8 antenna);
2730 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)
2731 mlan_status woal_set_net_monitor(moal_private *priv, t_u8 wait_option,
2732 				 t_u8 enable, t_u8 filter,
2733 				 netmon_band_chan_cfg * band_chan_cfg);
2734 #endif
2735 mlan_status woal_delba_all(moal_private *priv, t_u8 wait_option);
2736 
2737 monitor_iface *woal_prepare_mon_if(moal_private *priv,
2738 				   const char *name,
2739 				   unsigned char name_assign_type,
2740 				   int sniffer_mode);
2741 
2742 #if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
2743 mlan_status woal_set_rekey_data(moal_private *priv,
2744 				mlan_ds_misc_gtk_rekey_data * gtk_rekey,
2745 				t_u8 action);
2746 #endif
2747 void woal_ioctl_get_misc_conf(moal_private *priv, mlan_ds_misc_cfg *info);
2748 #endif /* _MOAL_MAIN_H */
2749