wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / mt5931_kk / drv_wlan / mgmt / hem_mbox.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT662X_593X_WIFI_DRIVER_V2_3/mgmt/hem_mbox.c#1 $
3 */
4
5 /*! \file   "hem_mbox.c"
6     \brief
7
8 */
9
10 /*******************************************************************************
11 * Copyright (c) 2009 MediaTek Inc.
12 *
13 * All rights reserved. Copying, compilation, modification, distribution
14 * or any other use whatsoever of this material is strictly prohibited
15 * except in accordance with a Software License Agreement with
16 * MediaTek Inc.
17 ********************************************************************************
18 */
19
20 /*******************************************************************************
21 * LEGAL DISCLAIMER
22 *
23 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
24 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
25 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
26 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
27 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
28 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
29 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
30 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
31 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
32 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
33 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
34 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
35 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
36 *
37 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
38 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
39 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
40 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
41 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
42 *
43 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
44 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
45 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
46 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
47 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
48 * (ICC).
49 ********************************************************************************
50 */
51
52 /*
53 ** $Log: hem_mbox.c $
54 ** 
55 ** 08 24 2012 cp.wu
56 ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
57 ** .
58 ** 
59 ** 08 24 2012 cp.wu
60 ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
61 ** cfg80211 support merge back from ALPS.JB to DaVinci - MT6620 Driver v2.3 branch.
62 ** 
63 ** 07 24 2012 yuche.tsai
64 ** NULL
65 ** Bug fix.
66 ** 
67 ** 07 24 2012 yuche.tsai
68 ** NULL
69 ** Bug fix for JB.
70 ** 
71 ** 07 19 2012 yuche.tsai
72 ** NULL
73 ** Code update for JB.
74  *
75  * 07 17 2012 yuche.tsai
76  * NULL
77  * Compile no error before trial run.
78  *
79  * 05 03 2012 cp.wu
80  * [WCXRP00001231] [MT6620 Wi-Fi][MT5931][Driver] Correct SCAN_V2 related debugging facilities within hem_mbox.c
81  * correct for debug message string table by adding missed scan_v2 related definitions.
82  *
83  * 03 02 2012 terry.wu
84  * NULL
85  * Sync CFG80211 modification from branch 2,2.
86  *
87  * 01 17 2012 yuche.tsai
88  * NULL
89  * Update mgmt frame filter setting.
90  * Please also update FW 2.1
91  *
92  * 01 13 2012 yuche.tsai
93  * NULL
94  * WiFi Hot Spot Tethering for ICS ALPHA testing version.
95  *
96  * 11 24 2011 wh.su
97  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
98  * Adjust code for DBG and CONFIG_XLOG.
99  *
100  * 11 15 2011 cm.chang
101  * NULL
102  * Add exception handle for NULL function pointer of mailbox message
103  *
104  * 11 11 2011 wh.su
105  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
106  * modify the xlog related code.
107  *
108  * 11 02 2011 wh.su
109  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
110  * adding the code for XLOG.
111  *
112  * 07 18 2011 cp.wu
113  * [WCXRP00000858] [MT5931][Driver][Firmware] Add support for scan to search for more than one SSID in a single scanning request
114  * add framework in driver domain for supporting new SCAN_REQ_V2 for more than 1 SSID support as well as uProbeDelay in NDIS 6.x driver model
115  *
116  * 06 07 2011 yuche.tsai
117  * [WCXRP00000696] [Volunteer Patch][MT6620][Driver] Infinite loop issue when RX invitation response.[WCXRP00000763] [Volunteer Patch][MT6620][Driver] RX Service Discovery Frame under AP mode Issue
118  * Add invitation support.
119  *
120  * 04 18 2011 terry.wu
121  * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
122  * Remove flag CFG_WIFI_DIRECT_MOVED.
123  *
124  * 03 29 2011 cm.chang
125  * [WCXRP00000606] [MT6620 Wi-Fi][Driver][FW] Fix klocwork warning
126  * As CR title
127  *
128  * 02 24 2011 cp.wu
129  * [WCXRP00000490] [MT6620 Wi-Fi][Driver][Win32] modify kalMsleep() implementation because NdisMSleep() won't sleep long enough for specified interval such as 500ms
130  * modify cnm_timer and hem_mbox APIs to be thread safe to ease invoking restrictions
131  *
132  * 02 15 2011 chinghwa.yu
133  * [WCXRP00000065] Update BoW design and settings
134  * Update bowString and channel grant.
135  *
136  * 01 26 2011 cm.chang
137  * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
138  * Allocate system RAM if fixed message or mgmt buffer is not available
139  *
140  * 01 26 2011 yuche.tsai
141  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
142  * .
143  *
144  * 01 25 2011 yuche.tsai
145  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
146  * Fix Compile Error when DBG is disabled.
147  *
148  * 01 24 2011 cp.wu
149  * [WCXRP00000382] [MT6620 Wi-Fi][Driver] Track forwarding packet number with notifying tx thread for serving
150  * 1. add an extra counter for tracking pending forward frames.
151  * 2. notify TX service thread as well when there is pending forward frame
152  * 3. correct build errors leaded by introduction of Wi-Fi direct separation module
153  *
154  * 12 08 2010 chinghwa.yu
155  * [WCXRP00000065] Update BoW design and settings
156  * Support concurrent networks.
157  *
158  * 11 08 2010 cm.chang
159  * [WCXRP00000169] [MT6620 Wi-Fi][Driver][FW] Remove unused CNM recover message ID
160  * Remove CNM channel reover message ID
161  *
162  * 11 01 2010 cp.wu
163  * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000150] [MT6620 Wi-Fi][Driver] Add implementation for querying current TX rate from firmware auto rate module
164  * 1) Query link speed (TX rate) from firmware directly with buffering mechanism to reduce overhead
165  * 2) Remove CNM CH-RECOVER event handling
166  * 3) cfg read/write API renamed with kal prefix for unified naming rules.
167  *
168  * 10 08 2010 wh.su
169  * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine
170  * update the frog's new p2p state machine.
171  *
172  * 09 28 2010 wh.su
173  * NULL
174  * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
175  *
176  * 09 16 2010 cm.chang
177  * NULL
178  * Remove unused message ID
179  *
180  * 08 30 2010 cp.wu
181  * NULL
182  * eliminate klockwork errors
183  *
184  * 08 26 2010 yuche.tsai
185  * NULL
186  * Add P2P Connection Abort Event Message handler.
187  *
188  * 08 25 2010 george.huang
189  * NULL
190  * update OID/ registry control path for PM related settings
191  *
192  * 08 24 2010 yarco.yang
193  * NULL
194  * Fixed Driver ASSERT at mboxInitMsgMap()
195  *
196  * 08 24 2010 chinghwa.yu
197  * NULL
198  * Update for MID_SCN_BOW_SCAN_DONE mboxDummy.
199  * Update saa_fsm for BOW.
200  *
201  * 08 23 2010 chinghwa.yu
202  * NULL
203  * Add CFG_ENABLE_BT_OVER_WIFI.
204  *
205  * 08 23 2010 chinghwa.yu
206  * NULL
207  * Update for BOW.
208  *
209  * 08 16 2010 cp.wu
210  * NULL
211  * add interface for RLM to trigger OBSS-SCAN.
212  *
213  * 08 16 2010 yuche.tsai
214  * NULL
215  * Add debug message for newly add P2P message.
216  *
217  * 08 11 2010 yuche.tsai
218  * NULL
219  * Add some function entry for P2P FSM under provisioning phase..
220  *
221  * 08 11 2010 yuche.tsai
222  * NULL
223  * Add some events to P2P Module.
224  *
225  * 08 05 2010 yuche.tsai
226  * NULL
227  * Add message box event for P2P device switch on & device discovery.
228  *
229  * 08 04 2010 cp.wu
230  * NULL
231  * remove unused mailbox message definitions.
232  *
233  * 08 02 2010 yuche.tsai
234  * NULL
235  * P2P Group Negotiation Code Check in.
236  *
237  * 07 19 2010 cp.wu
238  *
239  * [WPD00003833] [MT6620 and MT5931] Driver migration.
240  * message table should not be commented out by compilation option without modifying header file
241  *
242  * 07 19 2010 cp.wu
243  *
244  * [WPD00003833] [MT6620 and MT5931] Driver migration.
245  * Add Ad-Hoc support to AIS-FSM
246  *
247  * 07 19 2010 yuche.tsai
248  *
249  * Add wifi direct scan done callback.
250  *
251  * 07 09 2010 cp.wu
252  *
253  * change handler of MID_MNY_CNM_CONNECTION_ABORT from NULL to mboxDummy.
254  *
255  * 07 08 2010 cp.wu
256  *
257  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
258  *
259  * 07 08 2010 cm.chang
260  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
261  * Rename MID_MNY_CNM_CH_RELEASE to MID_MNY_CNM_CH_ABORT
262  *
263  * 07 01 2010 cp.wu
264  * [WPD00003833][MT6620 and MT5931] Driver migration
265  * AIS-FSM integration with CNM channel request messages
266  *
267  * 07 01 2010 cp.wu
268  * [WPD00003833][MT6620 and MT5931] Driver migration
269  * implementation of DRV-SCN and related mailbox message handling.
270  *
271  * 07 01 2010 cm.chang
272  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
273  * Modify CNM message handler for new flow
274  *
275  * 06 15 2010 cp.wu
276  * [WPD00003833][MT6620 and MT5931] Driver migration
277  * enable currently migrated message call-backs.
278  *
279  * 06 14 2010 cp.wu
280  * [WPD00003833][MT6620 and MT5931] Driver migration
281  * restore utility function invoking via hem_mbox to direct calls
282  *
283  * 06 10 2010 cp.wu
284  * [WPD00003833][MT6620 and MT5931] Driver migration
285  * add buildable & linkable ais_fsm.c
286  *
287  * related reference are still waiting to be resolved
288  *
289  * 06 08 2010 cp.wu
290  * [WPD00003833][MT6620 and MT5931] Driver migration
291  * hem_mbox is migrated.
292  *
293  * 06 08 2010 cp.wu
294  * [WPD00003833][MT6620 and MT5931] Driver migration
295  * add hem_mbox.c and cnm_mem.h (but disabled some feature) for further migration
296  *
297  * 05 12 2010 kevin.huang
298  * [BORA00000794][WIFISYS][New Feature]Power Management Support
299  * Fix file merge error
300  *
301  * 05 12 2010 kevin.huang
302  * [BORA00000794][WIFISYS][New Feature]Power Management Support
303  * Add Power Management - Legacy PS-POLL support.
304  *
305  * 04 29 2010 tehuang.liu
306  * [BORA00000605][WIFISYS] Phase3 Integration
307  * Removed MID_RXM_MQM_QOS_ACTION_FRAME
308  *
309  * 04 29 2010 tehuang.liu
310  * [BORA00000605][WIFISYS] Phase3 Integration
311  * Removed MID_RXM_MQM_BA_ACTION_FRAME
312  *
313  * 04 27 2010 tehuang.liu
314  * [BORA00000605][WIFISYS] Phase3 Integration
315  * MID_RXM_MQM_BA_ACTION_FRAME
316  *
317  * 03 30 2010 cm.chang
318  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
319  * Support 2.4G OBSS scan
320  *
321  * 03 16 2010 kevin.huang
322  * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
323  * Add AdHoc Mode
324  *
325  * 03 10 2010 kevin.huang
326  * [BORA00000654][WIFISYS][New Feature] CNM Module - Ch Manager Support
327  *
328  *  *  *  *  *  *  *  *  *  *  *  *  *  * Add Channel Manager for arbitration of JOIN and SCAN Req
329  *
330  * 03 05 2010 cm.chang
331  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
332  * Develop partial DPD code
333  *
334  * 02 11 2010 tehuang.liu
335  * [BORA00000569][WIFISYS] Phase 2 Integration Test
336  * Updated arMsgMapTable for MID_RXM_MQM_QOS_ACTION_FRAME
337  *
338  * 01 11 2010 kevin.huang
339  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
340  * Add Deauth and Disassoc Handler
341  *
342  * Dec 9 2009 mtk01461
343  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
344  * Add hemRunEventScanDone() to arMsgMapTable[]
345  *
346  * Dec 4 2009 mtk01461
347  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
348  * Fix mboxDummy() didn't free prMsgHdr
349  *
350  * Dec 3 2009 mtk01461
351  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
352  * Add saaAisJoinComplete event handler
353  *
354  * Dec 2 2009 MTK02468
355  * [BORA00000337] To check in codes for FPGA emulation
356  * Fixed the handler function name in arMsgMapTable for MID_RXM_MQM_BA_ACTION_FRAME
357  *
358  * Dec 2 2009 MTK02468
359  * [BORA00000337] To check in codes for FPGA emulation
360  * Added MID_RXM_MQM_BA_ACTION_FRAME to MsgMapTable
361  *
362  * Nov 23 2009 mtk01461
363  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
364  * Revise MSG Handler (remove dummy and add for SAA)
365  *
366  * Nov 16 2009 mtk01461
367  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
368  * Add aisFsmRunEventAbort() event handler
369  *
370  * Nov 11 2009 mtk01461
371  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
372  * Fix typo
373  *
374  * Nov 10 2009 mtk01461
375  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
376  * Add more MSG_HNDL_ENTRY_T to avoid ASSERT() in mboxInitMsgMap()
377  *
378  * Nov 5 2009 mtk01461
379  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
380  * Add SCN message and function entry to arMsgMapTable[]
381  *
382  * Nov 2 2009 mtk01104
383  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
384  * Fix sorting algorithm in mboxInitMsgMap()
385  *
386  * Oct 28 2009 mtk01104
387  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
388  *
389 **
390 */
391
392 /*******************************************************************************
393 *                         C O M P I L E R   F L A G S
394 ********************************************************************************
395 */
396
397 /*******************************************************************************
398 *                    E X T E R N A L   R E F E R E N C E S
399 ********************************************************************************
400 */
401 #include "precomp.h"
402
403 /*******************************************************************************
404 *                              C O N S T A N T S
405 ********************************************************************************
406 */
407
408 /*******************************************************************************
409 *                             D A T A   T Y P E S
410 ********************************************************************************
411 */
412
413 /*******************************************************************************
414 *                            P U B L I C   D A T A
415 ********************************************************************************
416 */
417
418 /*******************************************************************************
419 *                           P R I V A T E   D A T A
420 ********************************************************************************
421 */
422 #if DBG
423 /*lint -save -e64 Type mismatch */
424 static PUINT_8 apucDebugMsg[] = {
425     (PUINT_8)DISP_STRING("MID_MNY_CNM_CH_REQ"),
426     (PUINT_8)DISP_STRING("MID_MNY_CNM_CH_ABORT"),
427     (PUINT_8)DISP_STRING("MID_CNM_AIS_CH_GRANT"),
428     (PUINT_8)DISP_STRING("MID_CNM_P2P_CH_GRANT"),
429     (PUINT_8)DISP_STRING("MID_CNM_BOW_CH_GRANT"),
430
431     (PUINT_8)DISP_STRING("MID_AIS_SCN_SCAN_REQ"),
432     (PUINT_8)DISP_STRING("MID_AIS_SCN_SCAN_REQ_V2"),
433     (PUINT_8)DISP_STRING("MID_AIS_SCN_SCAN_CANCEL"),
434     (PUINT_8)DISP_STRING("MID_P2P_SCN_SCAN_REQ"),
435     (PUINT_8)DISP_STRING("MID_P2P_SCN_SCAN_REQ_V2"),
436     (PUINT_8)DISP_STRING("MID_P2P_SCN_SCAN_CANCEL"),
437     (PUINT_8)DISP_STRING("MID_BOW_SCN_SCAN_REQ"),
438     (PUINT_8)DISP_STRING("MID_BOW_SCN_SCAN_REQ_V2"),
439     (PUINT_8)DISP_STRING("MID_BOW_SCN_SCAN_CANCEL"),
440     (PUINT_8)DISP_STRING("MID_RLM_SCN_SCAN_REQ"),
441     (PUINT_8)DISP_STRING("MID_RLM_SCN_SCAN_REQ_V2"),
442     (PUINT_8)DISP_STRING("MID_RLM_SCN_SCAN_CANCEL"),
443     (PUINT_8)DISP_STRING("MID_SCN_AIS_SCAN_DONE"),
444     (PUINT_8)DISP_STRING("MID_SCN_P2P_SCAN_DONE"),
445     (PUINT_8)DISP_STRING("MID_SCN_BOW_SCAN_DONE"),
446     (PUINT_8)DISP_STRING("MID_SCN_RLM_SCAN_DONE"),
447
448     (PUINT_8)DISP_STRING("MID_OID_AIS_FSM_JOIN_REQ"),
449     (PUINT_8)DISP_STRING("MID_OID_AIS_FSM_ABORT"),
450     (PUINT_8)DISP_STRING("MID_AIS_SAA_FSM_START"),
451     (PUINT_8)DISP_STRING("MID_AIS_SAA_FSM_ABORT"),
452     (PUINT_8)DISP_STRING("MID_SAA_AIS_JOIN_COMPLETE"),
453
454 #if CFG_ENABLE_BT_OVER_WIFI
455     (PUINT_8)DISP_STRING("MID_BOW_SAA_FSM_START"),
456     (PUINT_8)DISP_STRING("MID_BOW_SAA_FSM_ABORT"),
457     (PUINT_8)DISP_STRING("MID_SAA_BOW_JOIN_COMPLETE"),
458 #endif
459
460 #if CFG_ENABLE_WIFI_DIRECT
461     (PUINT_8)DISP_STRING("MID_P2P_SAA_FSM_START"),
462     (PUINT_8)DISP_STRING("MID_P2P_SAA_FSM_ABORT"),
463     (PUINT_8)DISP_STRING("MID_SAA_P2P_JOIN_COMPLETE"),
464
465     (PUINT_8)DISP_STRING("MID_MNY_P2P_FUN_SWITCH"),
466     (PUINT_8)DISP_STRING("MID_MNY_P2P_DEVICE_DISCOVERY"),
467     (PUINT_8)DISP_STRING("MID_MNY_P2P_CONNECTION_REQ"),
468     (PUINT_8)DISP_STRING("MID_MNY_P2P_CONNECTION_ABORT"),
469     (PUINT_8)DISP_STRING("MID_MNY_P2P_BEACON_UPDATE"),
470     (PUINT_8)DISP_STRING("MID_MNY_P2P_STOP_AP"),
471     (PUINT_8)DISP_STRING("MID_MNY_P2P_CHNL_REQ"),
472     (PUINT_8)DISP_STRING("MID_MNY_P2P_CHNL_ABORT"),
473     (PUINT_8)DISP_STRING("MID_MNY_P2P_MGMT_TX"),
474     (PUINT_8)DISP_STRING("MID_MNY_P2P_GROUP_DISSOLVE"),
475     (PUINT_8)DISP_STRING("MID_MNY_P2P_MGMT_FRAME_REGISTER"),
476     (PUINT_8)DISP_STRING("MID_MNY_P2P_NET_DEV_REGISTER"),
477     (PUINT_8)DISP_STRING("MID_MNY_P2P_START_AP"),
478     (PUINT_8)DISP_STRING("MID_MNY_P2P_UPDATE_IE_BUF"),
479  #endif
480
481 #if CFG_SUPPORT_ADHOC
482     //(PUINT_8)DISP_STRING("MID_AIS_CNM_CREATE_IBSS_REQ"),
483     //(PUINT_8)DISP_STRING("MID_CNM_AIS_CREATE_IBSS_GRANT"),
484     //(PUINT_8)DISP_STRING("MID_AIS_CNM_MERGE_IBSS_REQ"),
485     //(PUINT_8)DISP_STRING("MID_CNM_AIS_MERGE_IBSS_GRANT"),
486     (PUINT_8)DISP_STRING("MID_SCN_AIS_FOUND_IBSS"),
487 #endif /* CFG_SUPPORT_ADHOC */
488
489     (PUINT_8)DISP_STRING("MID_SAA_AIS_FSM_ABORT")
490 };
491 /*lint -restore */
492 #endif /* DBG */
493
494 /* This message entry will be re-ordered based on the message ID order
495  * by invoking mboxInitMsgMap()
496  */
497 static MSG_HNDL_ENTRY_T arMsgMapTable[] = {
498     { MID_MNY_CNM_CH_REQ,           cnmChMngrRequestPrivilege               },
499     { MID_MNY_CNM_CH_ABORT,         cnmChMngrAbortPrivilege                 },
500     { MID_CNM_AIS_CH_GRANT,         aisFsmRunEventChGrant                   },
501 #if CFG_ENABLE_WIFI_DIRECT
502     { MID_CNM_P2P_CH_GRANT,         p2pFsmRunEventChGrant                   }, /*set in gl_p2p_init.c*/
503 #else
504     { MID_CNM_P2P_CH_GRANT,         mboxDummy                               },
505 #endif
506
507 #if CFG_ENABLE_BT_OVER_WIFI
508     { MID_CNM_BOW_CH_GRANT,         bowRunEventChGrant                             },
509 #else
510     { MID_CNM_BOW_CH_GRANT,         mboxDummy                               },
511 #endif
512
513     /*--------------------------------------------------*/
514     /* SCN Module Mailbox Messages                      */
515     /*--------------------------------------------------*/
516     { MID_AIS_SCN_SCAN_REQ,         scnFsmMsgStart                          },
517     { MID_AIS_SCN_SCAN_REQ_V2,      scnFsmMsgStart                          },
518     { MID_AIS_SCN_SCAN_CANCEL,      scnFsmMsgAbort                          },
519     { MID_P2P_SCN_SCAN_REQ,         scnFsmMsgStart                          },
520     { MID_P2P_SCN_SCAN_REQ_V2,      scnFsmMsgStart                          },
521     { MID_P2P_SCN_SCAN_CANCEL,      scnFsmMsgAbort                          },
522     { MID_BOW_SCN_SCAN_REQ,         scnFsmMsgStart                          },
523     { MID_BOW_SCN_SCAN_REQ_V2,      scnFsmMsgStart                          },
524     { MID_BOW_SCN_SCAN_CANCEL,      scnFsmMsgAbort                          },
525     { MID_RLM_SCN_SCAN_REQ,         scnFsmMsgStart                          },
526     { MID_RLM_SCN_SCAN_REQ_V2,      scnFsmMsgStart                          },
527     { MID_RLM_SCN_SCAN_CANCEL,      scnFsmMsgAbort                          },
528     { MID_SCN_AIS_SCAN_DONE,        aisFsmRunEventScanDone                  },
529 #if CFG_ENABLE_WIFI_DIRECT
530     { MID_SCN_P2P_SCAN_DONE,        p2pFsmRunEventScanDone                  }, /*set in gl_p2p_init.c*/
531 #else
532     { MID_SCN_P2P_SCAN_DONE,        mboxDummy                               },
533 #endif
534
535 #if CFG_ENABLE_BT_OVER_WIFI
536     { MID_SCN_BOW_SCAN_DONE,        bowResponderScanDone                               },
537 #else
538     { MID_SCN_BOW_SCAN_DONE,        mboxDummy                               },
539 #endif
540     { MID_SCN_RLM_SCAN_DONE,        rlmObssScanDone                         },
541
542     /*--------------------------------------------------*/
543     /* AIS Module Mailbox Messages                      */
544     /*--------------------------------------------------*/
545     { MID_OID_AIS_FSM_JOIN_REQ,     aisFsmRunEventAbort                     },
546     { MID_OID_AIS_FSM_ABORT,        aisFsmRunEventAbort                     },
547     { MID_AIS_SAA_FSM_START,        saaFsmRunEventStart                     },
548     { MID_AIS_SAA_FSM_ABORT,        saaFsmRunEventAbort                     },
549     { MID_SAA_AIS_JOIN_COMPLETE,    aisFsmRunEventJoinComplete              },
550
551 #if CFG_ENABLE_BT_OVER_WIFI
552     /*--------------------------------------------------*/
553     /* BOW Module Mailbox Messages                      */
554     /*--------------------------------------------------*/
555     { MID_BOW_SAA_FSM_START,        saaFsmRunEventStart                     },
556     { MID_BOW_SAA_FSM_ABORT,        saaFsmRunEventAbort                     },
557     { MID_SAA_BOW_JOIN_COMPLETE,    bowFsmRunEventJoinComplete              },
558 #endif
559
560 #if CFG_ENABLE_WIFI_DIRECT  /*set in gl_p2p_init.c*/
561     { MID_P2P_SAA_FSM_START,        saaFsmRunEventStart                     },
562     { MID_P2P_SAA_FSM_ABORT,        saaFsmRunEventAbort                     },
563     { MID_SAA_P2P_JOIN_COMPLETE,    p2pFsmRunEventJoinComplete              },// TODO: p2pFsmRunEventJoinComplete
564
565     { MID_MNY_P2P_FUN_SWITCH,       p2pFsmRunEventSwitchOPMode              },
566     { MID_MNY_P2P_DEVICE_DISCOVERY, p2pFsmRunEventScanRequest               },
567     { MID_MNY_P2P_CONNECTION_REQ,   p2pFsmRunEventConnectionRequest         },
568     { MID_MNY_P2P_CONNECTION_ABORT, p2pFsmRunEventConnectionAbort           },
569     { MID_MNY_P2P_BEACON_UPDATE,    p2pFsmRunEventBeaconUpdate              },
570     { MID_MNY_P2P_STOP_AP,          p2pFsmRunEventStopAP                    },
571     { MID_MNY_P2P_CHNL_REQ,         p2pFsmRunEventChannelRequest            },
572     { MID_MNY_P2P_CHNL_ABORT,       p2pFsmRunEventChannelAbort              },
573     { MID_MNY_P2P_MGMT_TX,          p2pFsmRunEventMgmtFrameTx               },
574     { MID_MNY_P2P_GROUP_DISSOLVE,   p2pFsmRunEventDissolve                  },
575     { MID_MNY_P2P_MGMT_FRAME_REGISTER, p2pFsmRunEventMgmtFrameRegister      },
576     { MID_MNY_P2P_NET_DEV_REGISTER, p2pFsmRunEventNetDeviceRegister         },
577     { MID_MNY_P2P_START_AP,         p2pFsmRunEventStartAP                   },
578     { MID_MNY_P2P_MGMT_FRAME_UPDATE,    p2pFsmRunEventUpdateMgmtFrame       },
579 #if CFG_SUPPORT_WFD
580     { MID_MNY_P2P_WFD_CFG_UPDATE, p2pFsmRunEventWfdSettingUpdate           },
581 #endif
582
583 #endif
584
585 #if CFG_SUPPORT_ADHOC
586     { MID_SCN_AIS_FOUND_IBSS,       aisFsmRunEventFoundIBSSPeer             },
587 #endif /* CFG_SUPPORT_ADHOC */
588
589     { MID_SAA_AIS_FSM_ABORT,        aisFsmRunEventAbort                     }
590 };
591
592 /*******************************************************************************
593 *                                 M A C R O S
594 ********************************************************************************
595 */
596
597 #if DBG
598 #define MBOX_HNDL_MSG(prAdapter, prMsg) do { \
599         ASSERT(arMsgMapTable[prMsg->eMsgId].pfMsgHndl); \
600         if (arMsgMapTable[prMsg->eMsgId].pfMsgHndl) { \
601             DBGLOG(CNM, LOUD, ("DO MSG [%d: %s]\n", prMsg->eMsgId, apucDebugMsg[prMsg->eMsgId])); \
602             arMsgMapTable[prMsg->eMsgId].pfMsgHndl(prAdapter, prMsg); \
603         } \
604         else { \
605             DBGLOG(CNM, ERROR, ("NULL fptr for MSG [%d]\n", prMsg->eMsgId)); \
606             cnmMemFree(prAdapter, prMsg); \
607         } \
608 } while (0)
609 #else
610 #define MBOX_HNDL_MSG(prAdapter, prMsg) do { \
611         ASSERT(arMsgMapTable[prMsg->eMsgId].pfMsgHndl); \
612         if (arMsgMapTable[prMsg->eMsgId].pfMsgHndl) { \
613             DBGLOG(CNM, LOUD, ("DO MSG [%d]\n", prMsg->eMsgId)); \
614             arMsgMapTable[prMsg->eMsgId].pfMsgHndl(prAdapter, prMsg); \
615         } \
616         else { \
617             DBGLOG(CNM, ERROR, ("NULL fptr for MSG [%d]\n", prMsg->eMsgId)); \
618             cnmMemFree(prAdapter, prMsg); \
619         } \
620 } while (0)
621 #endif
622 /*******************************************************************************
623 *                   F U N C T I O N   D E C L A R A T I O N S
624 ********************************************************************************
625 */
626
627 /*******************************************************************************
628 *                              F U N C T I O N S
629 ********************************************************************************
630 */
631
632
633 /*----------------------------------------------------------------------------*/
634 /*!
635 * \brief
636 *
637 * \param[in]
638 *
639 * \return none
640 */
641 /*----------------------------------------------------------------------------*/
642 VOID
643 mboxInitMsgMap (
644     VOID
645     )
646 {
647     UINT_32             i, idx;
648     MSG_HNDL_ENTRY_T    rTempEntry;
649
650     ASSERT((sizeof(arMsgMapTable) / sizeof(MSG_HNDL_ENTRY_T)) == MID_TOTAL_NUM);
651
652     for (i = 0; i < MID_TOTAL_NUM; i++) {
653         if (arMsgMapTable[i].eMsgId == (ENUM_MSG_ID_T) i) {
654             continue;
655         }
656         for (idx = i + 1; idx < MID_TOTAL_NUM; idx++) {
657             if (arMsgMapTable[idx].eMsgId == (ENUM_MSG_ID_T) i) {
658                 break;
659             }
660         }
661         ASSERT(idx < MID_TOTAL_NUM);
662         if (idx >= MID_TOTAL_NUM) {
663             continue;
664         }
665
666         /* Swap target entry and current entry */
667         rTempEntry.eMsgId = arMsgMapTable[idx].eMsgId;
668         rTempEntry.pfMsgHndl= arMsgMapTable[idx].pfMsgHndl;
669
670         arMsgMapTable[idx].eMsgId = arMsgMapTable[i].eMsgId;
671         arMsgMapTable[idx].pfMsgHndl = arMsgMapTable[i].pfMsgHndl;
672
673         arMsgMapTable[i].eMsgId = rTempEntry.eMsgId;
674         arMsgMapTable[i].pfMsgHndl = rTempEntry.pfMsgHndl;
675     }
676
677     /* Verify the correctness of final message map */
678     for (i = 0; i < MID_TOTAL_NUM; i++) {
679         ASSERT(arMsgMapTable[i].eMsgId == (ENUM_MSG_ID_T) i);
680         while (arMsgMapTable[i].eMsgId != (ENUM_MSG_ID_T) i);
681     }
682
683 }
684
685 /*----------------------------------------------------------------------------*/
686 /*!
687 * \brief
688 *
689 * \param[in]
690 *
691 * \return none
692 */
693 /*----------------------------------------------------------------------------*/
694 VOID
695 mboxSetup (
696     IN P_ADAPTER_T prAdapter,
697     IN ENUM_MBOX_ID_T eMboxId
698     )
699 {
700     P_MBOX_T prMbox;
701     KAL_SPIN_LOCK_DECLARATION();
702
703     ASSERT(eMboxId < MBOX_ID_TOTAL_NUM);
704     ASSERT(prAdapter);
705
706     prMbox = &(prAdapter->arMbox[eMboxId]);
707
708     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
709     LINK_INITIALIZE(&prMbox->rLinkHead);
710     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
711 }
712
713 /*----------------------------------------------------------------------------*/
714 /*!
715 * \brief
716 *
717 * \param[in]
718 *
719 * \return none
720 */
721 /*----------------------------------------------------------------------------*/
722 VOID
723 mboxSendMsg (
724     IN P_ADAPTER_T prAdapter,
725     IN ENUM_MBOX_ID_T eMboxId,
726     IN P_MSG_HDR_T prMsg,
727     IN EUNM_MSG_SEND_METHOD_T eMethod
728     )
729 {
730     P_MBOX_T    prMbox;
731     KAL_SPIN_LOCK_DECLARATION();
732
733     ASSERT(eMboxId < MBOX_ID_TOTAL_NUM);
734     ASSERT(prMsg);
735     ASSERT(prAdapter);
736
737     prMbox = &(prAdapter->arMbox[eMboxId]);
738
739     switch (eMethod) {
740     case MSG_SEND_METHOD_BUF:
741         KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
742         LINK_INSERT_TAIL(&prMbox->rLinkHead, &prMsg->rLinkEntry);
743         KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
744
745         // to wake up main service thread
746         GLUE_SET_EVENT(prAdapter->prGlueInfo);
747
748         break;
749
750     case MSG_SEND_METHOD_UNBUF:
751         MBOX_HNDL_MSG(prAdapter, prMsg);
752         break;
753
754     default:
755         ASSERT(0);
756         break;
757     }
758 }
759
760 /*----------------------------------------------------------------------------*/
761 /*!
762 * \brief
763 *
764 * \param[in]
765 *
766 * \return none
767 */
768 /*----------------------------------------------------------------------------*/
769 VOID
770 mboxRcvAllMsg (
771     IN P_ADAPTER_T prAdapter,
772     ENUM_MBOX_ID_T eMboxId
773     )
774 {
775     P_MBOX_T        prMbox;
776     P_MSG_HDR_T     prMsg;
777     KAL_SPIN_LOCK_DECLARATION();
778
779     ASSERT(eMboxId < MBOX_ID_TOTAL_NUM);
780     ASSERT(prAdapter);
781
782     prMbox = &(prAdapter->arMbox[eMboxId]);
783
784     while (!LINK_IS_EMPTY(&prMbox->rLinkHead) ) {
785         KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
786         LINK_REMOVE_HEAD(&prMbox->rLinkHead, prMsg, P_MSG_HDR_T);
787         KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
788
789         ASSERT(prMsg);
790         MBOX_HNDL_MSG(prAdapter, prMsg);
791     }
792
793 }
794
795 /*----------------------------------------------------------------------------*/
796 /*!
797 * \brief
798 *
799 * \param[in]
800 *
801 * \return none
802 */
803 /*----------------------------------------------------------------------------*/
804 VOID
805 mboxInitialize (
806     IN P_ADAPTER_T prAdapter
807     )
808 {
809     UINT_32     i;
810
811     ASSERT(prAdapter);
812
813     /* Initialize Mailbox */
814     mboxInitMsgMap();
815
816     /* Setup/initialize each mailbox */
817     for (i = 0; i < MBOX_ID_TOTAL_NUM; i++) {
818         mboxSetup(prAdapter, i);
819     }
820
821 }
822
823 /*----------------------------------------------------------------------------*/
824 /*!
825 * \brief
826 *
827 * \param[in]
828 *
829 * \return none
830 */
831 /*----------------------------------------------------------------------------*/
832 VOID
833 mboxDestroy (
834     IN P_ADAPTER_T prAdapter
835     )
836 {
837     P_MBOX_T        prMbox;
838     P_MSG_HDR_T     prMsg;
839     UINT_8          i;
840     KAL_SPIN_LOCK_DECLARATION();
841
842     ASSERT(prAdapter);
843
844     for (i = 0; i < MBOX_ID_TOTAL_NUM; i++) {
845         prMbox = &(prAdapter->arMbox[i]);
846
847         while (!LINK_IS_EMPTY(&prMbox->rLinkHead) ) {
848             KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
849             LINK_REMOVE_HEAD(&prMbox->rLinkHead, prMsg, P_MSG_HDR_T);
850             KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
851
852             ASSERT(prMsg);
853             cnmMemFree(prAdapter, prMsg);
854         }
855     }
856 }
857
858 /*----------------------------------------------------------------------------*/
859 /*!
860 * \brief This is dummy function to prevent empty arMsgMapTable[] for compiling.
861 *
862 * \param[in]
863 *
864 * \return none
865 */
866 /*----------------------------------------------------------------------------*/
867 VOID
868 mboxDummy (
869     IN P_ADAPTER_T prAdapter,
870     IN P_MSG_HDR_T prMsgHdr
871     )
872 {
873     ASSERT(prAdapter);
874
875     cnmMemFree(prAdapter, prMsgHdr);
876
877     return;
878 }
879