b6c627f162152e8eb824f21873d98926c158e26b
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931 / 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 #endif
532
533 #if CFG_SUPPORT_ADHOC
534     { MID_SCN_AIS_FOUND_IBSS,       aisFsmRunEventFoundIBSSPeer             },
535 #endif /* CFG_SUPPORT_ADHOC */
536
537     { MID_SAA_AIS_FSM_ABORT,        aisFsmRunEventAbort                     }
538 };
539
540 /*******************************************************************************
541 *                                 M A C R O S
542 ********************************************************************************
543 */
544
545 #if DBG
546 #define MBOX_HNDL_MSG(prAdapter, prMsg) do { \
547         ASSERT(arMsgMapTable[prMsg->eMsgId].pfMsgHndl); \
548         if (arMsgMapTable[prMsg->eMsgId].pfMsgHndl) { \
549             DBGLOG(CNM, LOUD, ("DO MSG [%d: %s]\n", prMsg->eMsgId, apucDebugMsg[prMsg->eMsgId])); \
550             arMsgMapTable[prMsg->eMsgId].pfMsgHndl(prAdapter, prMsg); \
551         } \
552         else { \
553             DBGLOG(CNM, ERROR, ("NULL fptr for MSG [%d]\n", prMsg->eMsgId)); \
554             cnmMemFree(prAdapter, prMsg); \
555         } \
556 } while (0)
557 #else
558 #define MBOX_HNDL_MSG(prAdapter, prMsg) do { \
559         ASSERT(arMsgMapTable[prMsg->eMsgId].pfMsgHndl); \
560         if (arMsgMapTable[prMsg->eMsgId].pfMsgHndl) { \
561             DBGLOG(CNM, LOUD, ("DO MSG [%d]\n", prMsg->eMsgId)); \
562             arMsgMapTable[prMsg->eMsgId].pfMsgHndl(prAdapter, prMsg); \
563         } \
564         else { \
565             DBGLOG(CNM, ERROR, ("NULL fptr for MSG [%d]\n", prMsg->eMsgId)); \
566             cnmMemFree(prAdapter, prMsg); \
567         } \
568 } while (0)
569 #endif
570 /*******************************************************************************
571 *                   F U N C T I O N   D E C L A R A T I O N S
572 ********************************************************************************
573 */
574
575 /*******************************************************************************
576 *                              F U N C T I O N S
577 ********************************************************************************
578 */
579
580
581 /*----------------------------------------------------------------------------*/
582 /*!
583 * \brief
584 *
585 * \param[in]
586 *
587 * \return none
588 */
589 /*----------------------------------------------------------------------------*/
590 VOID
591 mboxInitMsgMap (
592     VOID
593     )
594 {
595     UINT_32             i, idx;
596     MSG_HNDL_ENTRY_T    rTempEntry;
597
598     ASSERT((sizeof(arMsgMapTable) / sizeof(MSG_HNDL_ENTRY_T)) == MID_TOTAL_NUM);
599
600     for (i = 0; i < MID_TOTAL_NUM; i++) {
601         if (arMsgMapTable[i].eMsgId == (ENUM_MSG_ID_T) i) {
602             continue;
603         }
604         for (idx = i + 1; idx < MID_TOTAL_NUM; idx++) {
605             if (arMsgMapTable[idx].eMsgId == (ENUM_MSG_ID_T) i) {
606                 break;
607             }
608         }
609         ASSERT(idx < MID_TOTAL_NUM);
610         if (idx >= MID_TOTAL_NUM) {
611             continue;
612         }
613
614         /* Swap target entry and current entry */
615         rTempEntry.eMsgId = arMsgMapTable[idx].eMsgId;
616         rTempEntry.pfMsgHndl= arMsgMapTable[idx].pfMsgHndl;
617
618         arMsgMapTable[idx].eMsgId = arMsgMapTable[i].eMsgId;
619         arMsgMapTable[idx].pfMsgHndl = arMsgMapTable[i].pfMsgHndl;
620
621         arMsgMapTable[i].eMsgId = rTempEntry.eMsgId;
622         arMsgMapTable[i].pfMsgHndl = rTempEntry.pfMsgHndl;
623     }
624
625     /* Verify the correctness of final message map */
626     for (i = 0; i < MID_TOTAL_NUM; i++) {
627         ASSERT(arMsgMapTable[i].eMsgId == (ENUM_MSG_ID_T) i);
628         while (arMsgMapTable[i].eMsgId != (ENUM_MSG_ID_T) i);
629     }
630
631 }
632
633 /*----------------------------------------------------------------------------*/
634 /*!
635 * \brief
636 *
637 * \param[in]
638 *
639 * \return none
640 */
641 /*----------------------------------------------------------------------------*/
642 VOID
643 mboxSetup (
644     IN P_ADAPTER_T prAdapter,
645     IN ENUM_MBOX_ID_T eMboxId
646     )
647 {
648     P_MBOX_T prMbox;
649     KAL_SPIN_LOCK_DECLARATION();
650
651     ASSERT(eMboxId < MBOX_ID_TOTAL_NUM);
652     ASSERT(prAdapter);
653
654     prMbox = &(prAdapter->arMbox[eMboxId]);
655
656     KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
657     LINK_INITIALIZE(&prMbox->rLinkHead);
658     KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
659 }
660
661 /*----------------------------------------------------------------------------*/
662 /*!
663 * \brief
664 *
665 * \param[in]
666 *
667 * \return none
668 */
669 /*----------------------------------------------------------------------------*/
670 VOID
671 mboxSendMsg (
672     IN P_ADAPTER_T prAdapter,
673     IN ENUM_MBOX_ID_T eMboxId,
674     IN P_MSG_HDR_T prMsg,
675     IN EUNM_MSG_SEND_METHOD_T eMethod
676     )
677 {
678     P_MBOX_T    prMbox;
679     KAL_SPIN_LOCK_DECLARATION();
680
681     ASSERT(eMboxId < MBOX_ID_TOTAL_NUM);
682     ASSERT(prMsg);
683     ASSERT(prAdapter);
684
685     prMbox = &(prAdapter->arMbox[eMboxId]);
686
687     switch (eMethod) {
688     case MSG_SEND_METHOD_BUF:
689         KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
690         LINK_INSERT_TAIL(&prMbox->rLinkHead, &prMsg->rLinkEntry);
691         KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
692
693         // to wake up main service thread
694         GLUE_SET_EVENT(prAdapter->prGlueInfo);
695
696         break;
697
698     case MSG_SEND_METHOD_UNBUF:
699         MBOX_HNDL_MSG(prAdapter, prMsg);
700         break;
701
702     default:
703         ASSERT(0);
704         break;
705     }
706 }
707
708 /*----------------------------------------------------------------------------*/
709 /*!
710 * \brief
711 *
712 * \param[in]
713 *
714 * \return none
715 */
716 /*----------------------------------------------------------------------------*/
717 VOID
718 mboxRcvAllMsg (
719     IN P_ADAPTER_T prAdapter,
720     ENUM_MBOX_ID_T eMboxId
721     )
722 {
723     P_MBOX_T        prMbox;
724     P_MSG_HDR_T     prMsg;
725     KAL_SPIN_LOCK_DECLARATION();
726
727     ASSERT(eMboxId < MBOX_ID_TOTAL_NUM);
728     ASSERT(prAdapter);
729
730     prMbox = &(prAdapter->arMbox[eMboxId]);
731
732     while (!LINK_IS_EMPTY(&prMbox->rLinkHead) ) {
733         KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
734         LINK_REMOVE_HEAD(&prMbox->rLinkHead, prMsg, P_MSG_HDR_T);
735         KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
736
737         ASSERT(prMsg);
738         MBOX_HNDL_MSG(prAdapter, prMsg);
739     }
740
741 }
742
743 /*----------------------------------------------------------------------------*/
744 /*!
745 * \brief
746 *
747 * \param[in]
748 *
749 * \return none
750 */
751 /*----------------------------------------------------------------------------*/
752 VOID
753 mboxInitialize (
754     IN P_ADAPTER_T prAdapter
755     )
756 {
757     UINT_32     i;
758
759     ASSERT(prAdapter);
760
761     /* Initialize Mailbox */
762     mboxInitMsgMap();
763
764     /* Setup/initialize each mailbox */
765     for (i = 0; i < MBOX_ID_TOTAL_NUM; i++) {
766         mboxSetup(prAdapter, i);
767     }
768
769 }
770
771 /*----------------------------------------------------------------------------*/
772 /*!
773 * \brief
774 *
775 * \param[in]
776 *
777 * \return none
778 */
779 /*----------------------------------------------------------------------------*/
780 VOID
781 mboxDestroy (
782     IN P_ADAPTER_T prAdapter
783     )
784 {
785     P_MBOX_T        prMbox;
786     P_MSG_HDR_T     prMsg;
787     UINT_8          i;
788     KAL_SPIN_LOCK_DECLARATION();
789
790     ASSERT(prAdapter);
791
792     for (i = 0; i < MBOX_ID_TOTAL_NUM; i++) {
793         prMbox = &(prAdapter->arMbox[i]);
794
795         while (!LINK_IS_EMPTY(&prMbox->rLinkHead) ) {
796             KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
797             LINK_REMOVE_HEAD(&prMbox->rLinkHead, prMsg, P_MSG_HDR_T);
798             KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_MAILBOX);
799
800             ASSERT(prMsg);
801             cnmMemFree(prAdapter, prMsg);
802         }
803     }
804 }
805
806 /*----------------------------------------------------------------------------*/
807 /*!
808 * \brief This is dummy function to prevent empty arMsgMapTable[] for compiling.
809 *
810 * \param[in]
811 *
812 * \return none
813 */
814 /*----------------------------------------------------------------------------*/
815 VOID
816 mboxDummy (
817     IN P_ADAPTER_T prAdapter,
818     IN P_MSG_HDR_T prMsgHdr
819     )
820 {
821     ASSERT(prAdapter);
822
823     cnmMemFree(prAdapter, prMsgHdr);
824
825     return;
826 }
827