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