wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / mt5931 / nic / nic_cmd_event.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/nic/nic_cmd_event.c#1 $
3 */
4
5 /*! \file   nic_cmd_event.c
6     \brief  Callback functions for Command packets.
7
8         Various Event packet handlers which will be setup in the callback function of
9     a command packet.
10 */
11
12
13
14 /*
15 ** $Log: nic_cmd_event.c $
16  *
17  * 04 10 2012 yuche.tsai
18  * NULL
19  * Update address for wifi direct connection issue.
20  *
21  * 06 15 2011 cm.chang
22  * [WCXRP00000785] [MT6620 Wi-Fi][Driver][FW] P2P/BOW MAC address is XOR with AIS MAC address
23  * P2P/BOW mac address XOR with local bit instead of OR
24  *
25  * 03 05 2011 wh.su
26  * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
27  * add the code to get the check rsponse and indicate to app.
28  *
29  * 03 02 2011 wh.su
30  * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
31  * Add security check code.
32  *
33  * 02 24 2011 cp.wu
34  * [WCXRP00000493] [MT6620 Wi-Fi][Driver] Do not indicate redundant disconnection to host when entering into RF test mode
35  * only indicate DISCONNECTION to host when entering RF test if necessary (connected -> disconnected cases)
36  *
37  * 01 20 2011 eddie.chen
38  * [WCXRP00000374] [MT6620 Wi-Fi][DRV] SW debug control
39  * Add Oid for sw control debug command
40  *
41  * 12 31 2010 cp.wu
42  * [WCXRP00000335] [MT6620 Wi-Fi][Driver] change to use milliseconds sleep instead of delay to avoid blocking to system scheduling
43  * change to use msleep() and shorten waiting interval to reduce blocking to other task while Wi-Fi driver is being loaded
44  *
45  * 12 01 2010 cp.wu
46  * [WCXRP00000223] MT6620 Wi-Fi][Driver][FW] Adopt NVRAM parameters when enter/exit RF test mode
47  * reload NVRAM settings before entering RF test mode and leaving from RF test mode.
48  *
49  * 11 01 2010 cp.wu
50  * [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
51  * 1) Query link speed (TX rate) from firmware directly with buffering mechanism to reduce overhead
52  * 2) Remove CNM CH-RECOVER event handling
53  * 3) cfg read/write API renamed with kal prefix for unified naming rules.
54  *
55  * 10 20 2010 cp.wu
56  * [WCXRP00000117] [MT6620 Wi-Fi][Driver] Add logic for suspending driver when MT6620 is not responding anymore
57  * use OID_CUSTOM_TEST_MODE as indication for driver reset
58  * by dropping pending TX packets
59  *
60  * 10 18 2010 cp.wu
61  * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000086] [MT6620 Wi-Fi][Driver] The mac address is all zero at android
62  * complete implementation of Android NVRAM access
63  *
64  * 09 21 2010 cp.wu
65  * [WCXRP00000053] [MT6620 Wi-Fi][Driver] Reset incomplete and might leads to BSOD when entering RF test with AIS associated
66  * Do a complete reset with STA-REC null checking for RF test re-entry
67  *
68  * 09 15 2010 yuche.tsai
69  * NULL
70  * Start to test AT GO only when P2P state is not IDLE.
71  *
72  * 09 09 2010 yuche.tsai
73  * NULL
74  * Add AT GO Test mode after MAC address available.
75  *
76  * 09 03 2010 kevin.huang
77  * NULL
78  * Refine #include sequence and solve recursive/nested #include issue
79  *
80  * 08 30 2010 cp.wu
81  * NULL
82  * eliminate klockwork errors
83  *
84  * 08 16 2010 cp.wu
85  * NULL
86  * Replace CFG_SUPPORT_BOW by CFG_ENABLE_BT_OVER_WIFI.
87  * There is no CFG_SUPPORT_BOW in driver domain source.
88  *
89  * 08 12 2010 cp.wu
90  * NULL
91  * [AIS-FSM] honor registry setting for adhoc running mode. (A/B/G)
92  *
93  * 08 11 2010 yuche.tsai
94  * NULL
95  * Add support for P2P Device Address query from FW.
96  *
97  * 08 03 2010 cp.wu
98  * NULL
99  * Centralize mgmt/system service procedures into independent calls.
100  *
101  * 08 02 2010 cp.wu
102  * NULL
103  * reset FSMs before entering RF test mode.
104  *
105  * 07 22 2010 cp.wu
106  *
107  * 1) refine AIS-FSM indent.
108  * 2) when entering RF Test mode, flush 802.1X frames as well
109  * 3) when entering D3 state, flush 802.1X frames as well
110  *
111  * 07 08 2010 cp.wu
112  *
113  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
114  *
115  * 07 05 2010 cp.wu
116  * [WPD00003833][MT6620 and MT5931] Driver migration
117  * 1) change fake BSS_DESC from channel 6 to channel 1 due to channel switching is not done yet.
118  * 2) after MAC address is queried from firmware, all related variables in driver domain should be updated as well
119  *
120  * 06 21 2010 wh.su
121  * [WPD00003840][MT6620 5931] Security migration
122  * remove duplicate variable for migration.
123  *
124  * 06 06 2010 kevin.huang
125  * [WPD00003832][MT6620 5931] Create driver base
126  * [MT6620 5931] Create driver base
127  *
128  * 05 29 2010 cp.wu
129  * [WPD00001943]Create WiFi test driver framework on WinXP
130  * change upon request: indicate as disconnected in driver domain when leaving from RF test mode
131  *
132  * 05 24 2010 cp.wu
133  * [WPD00001943]Create WiFi test driver framework on WinXP
134  * do not clear scanning list array after disassociation
135  *
136  * 05 22 2010 cp.wu
137  * [WPD00001943]Create WiFi test driver framework on WinXP
138  * 1) disable NETWORK_LAYER_ADDRESSES handling temporally.
139  * 2) finish statistics OIDs
140  *
141  * 05 22 2010 cp.wu
142  * [WPD00001943]Create WiFi test driver framework on WinXP
143  * change OID behavior to meet WHQL requirement.
144  *
145  * 05 20 2010 cp.wu
146  * [WPD00001943]Create WiFi test driver framework on WinXP
147  * 1) integrate OID_GEN_NETWORK_LAYER_ADDRESSES with CMD_ID_SET_IP_ADDRESS
148  * 2) buffer statistics data for 2 seconds
149  * 3) use default value for adhoc parameters instead of 0
150  *
151  * 05 19 2010 cp.wu
152  * [WPD00001943]Create WiFi test driver framework on WinXP
153  * 1) do not take timeout mechanism for power mode oids
154  * 2) retrieve network type from connection status
155  * 3) after disassciation, set radio state to off
156  * 4) TCP option over IPv6 is supported
157  *
158  * 05 17 2010 cp.wu
159  * [WPD00001943]Create WiFi test driver framework on WinXP
160  * correct OID_802_11_DISASSOCIATE handling.
161  *
162  * 05 17 2010 cp.wu
163  * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
164  * 1) add timeout handler mechanism for pending command packets
165  * 2) add p2p add/removal key
166  *
167  * 04 16 2010 cp.wu
168  * [WPD00001943]Create WiFi test driver framework on WinXP
169  * treat BUS access failure as kind of card removal.
170  *
171  * 04 14 2010 cp.wu
172  * [WPD00001943]Create WiFi test driver framework on WinXP
173  * information buffer for query oid/ioctl is now buffered in prCmdInfo
174  *  *  *  *  *  * instead of glue-layer variable to improve multiple oid/ioctl capability
175  *
176  * 04 13 2010 cp.wu
177  * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
178  * add framework for BT-over-Wi-Fi support.
179  *  *  *  *  *  *  *  *  *  *  *  *  *  * 1) prPendingCmdInfo is replaced by queue for multiple handler capability
180  *  *  *  *  *  *  *  *  *  *  *  *  *  * 2) command sequence number is now increased atomically
181  *  *  *  *  *  *  *  *  *  *  *  *  *  * 3) private data could be hold and taken use for other purpose
182  *
183  * 04 07 2010 cp.wu
184  * [WPD00001943]Create WiFi test driver framework on WinXP
185  * accessing to firmware load/start address, and access to OID handling information
186  * are now handled in glue layer
187  *
188  * 04 07 2010 cp.wu
189  * [WPD00001943]Create WiFi test driver framework on WinXP
190  * rWlanInfo should be placed at adapter rather than glue due to most operations
191  *  *  *  * are done in adapter layer.
192  *
193  * 04 06 2010 cp.wu
194  * [WPD00001943]Create WiFi test driver framework on WinXP
195  * add KAL API: kalFlushPendingTxPackets(), and take use of the API
196  *
197  * 04 06 2010 cp.wu
198  * [WPD00001943]Create WiFi test driver framework on WinXP
199  * eliminate direct access to prGlueInfo->rWlanInfo.eLinkAttr.ucMediaStreamMode from non-glue layer.
200  *
201  * 04 06 2010 jeffrey.chang
202  * [WPD00003826]Initial import for Linux port
203  * improve none-glude code portability
204  *
205  * 04 06 2010 cp.wu
206  * [WPD00001943]Create WiFi test driver framework on WinXP
207  * sync statistics data structure definition with firmware implementation
208  *
209  * 04 06 2010 cp.wu
210  * [WPD00001943]Create WiFi test driver framework on WinXP
211  * code refine: fgTestMode should be at adapter rather than glue due to the device/fw is also involved
212  *
213  * 04 06 2010 cp.wu
214  * [WPD00001943]Create WiFi test driver framework on WinXP
215  * eliminate direct access for prGlueInfo->fgIsCardRemoved in non-glue layer
216  *
217  * 03 30 2010 cp.wu
218  * [WPD00001943]Create WiFi test driver framework on WinXP
219  * statistics information OIDs are now handled by querying from firmware domain
220  *
221  * 03 26 2010 cp.wu
222  * [WPD00001943]Create WiFi test driver framework on WinXP
223  * indicate media stream mode after set is done
224  *
225  * 03 24 2010 jeffrey.chang
226  * [WPD00003826]Initial import for Linux port
227  * initial import for Linux port
228  *
229  * 03 03 2010 cp.wu
230  * [WPD00001943]Create WiFi test driver framework on WinXP
231  * implement custom OID: EEPROM read/write access
232  *
233  * 03 03 2010 cp.wu
234  * [WPD00001943]Create WiFi test driver framework on WinXP
235  * implement OID_802_3_MULTICAST_LIST oid handling
236  *
237  * 02 25 2010 cp.wu
238  * [WPD00001943]Create WiFi test driver framework on WinXP
239  * limit RSSI return value to microsoft defined range.
240  *
241  * 02 09 2010 cp.wu
242  * [WPD00001943]Create WiFi test driver framework on WinXP
243  * 1. Permanent and current MAC address are now retrieved by CMD/EVENT packets instead of hard-coded address
244  *  *  *  *  *  *  * 2. follow MSDN defined behavior when associates to another AP
245  *  *  *  *  *  *  * 3. for firmware download, packet size could be up to 2048 bytes
246  *
247  * 01 29 2010 cp.wu
248  * [WPD00001943]Create WiFi test driver framework on WinXP
249  * block until firmware finished RF test enter/leave then indicate completion to upper layer
250  *
251  * 01 29 2010 cp.wu
252  * [WPD00001943]Create WiFi test driver framework on WinXP
253  * when entering RF test mode and leaving from RF test mode, wait for W_FUNC_RDY bit to be asserted forever until it is set or card is removed.
254  *
255  * 01 27 2010 cp.wu
256  * [WPD00001943]Create WiFi test driver framework on WinXP
257  * 1. eliminate improper variable in rHifInfo
258  *  *  *  *  *  *  *  * 2. block TX/ordinary OID when RF test mode is engaged
259  *  *  *  *  *  *  *  * 3. wait until firmware finish operation when entering into and leaving from RF test mode
260  *  *  *  *  *  *  *  * 4. correct some HAL implementation
261  *
262  * 01 26 2010 cp.wu
263  * [WPD00001943]Create WiFi test driver framework on WinXP
264  * Under WinXP with SDIO, use prGlueInfo->rHifInfo.pvInformationBuffer instead of prGlueInfo->pvInformationBuffer
265  *
266  * 01 22 2010 cp.wu
267  * [WPD00001943]Create WiFi test driver framework on WinXP
268  * implement following 802.11 OIDs:
269  *  *  *  *  * OID_802_11_RSSI,
270  *  *  *  *  * OID_802_11_RSSI_TRIGGER,
271  *  *  *  *  * OID_802_11_STATISTICS,
272  *  *  *  *  * OID_802_11_DISASSOCIATE,
273  *  *  *  *  * OID_802_11_POWER_MODE
274  *
275  * 01 21 2010 cp.wu
276  * [WPD00001943]Create WiFi test driver framework on WinXP
277  * implement OID_802_11_MEDIA_STREAM_MODE
278  *
279  * 12 30 2009 cp.wu
280  * [WPD00001943]Create WiFi test driver framework on WinXP
281  * 1) According to CMD/EVENT documentation v0.8,
282  *  *  *  *  *  *  *  * OID_CUSTOM_TEST_RX_STATUS & OID_CUSTOM_TEST_TX_STATUS is no longer used,
283  *  *  *  *  *  *  *  * and result is retrieved by get ATInfo instead
284  *  *  *  *  *  *  *  * 2) add 4 counter for recording aggregation statistics
285 **  \main\maintrunk.MT6620WiFiDriver_Prj\10 2009-12-10 16:47:47 GMT mtk02752
286 **  only handle MCR read when accessing FW domain register
287 **  \main\maintrunk.MT6620WiFiDriver_Prj\9 2009-12-08 17:37:28 GMT mtk02752
288 **  * refine nicCmdEventQueryMcrRead
289 **  + add TxStatus/RxStatus for RF test QueryInformation OIDs
290 **  \main\maintrunk.MT6620WiFiDriver_Prj\8 2009-12-02 22:05:45 GMT mtk02752
291 **  kalOidComplete() will decrease i4OidPendingCount
292 **  \main\maintrunk.MT6620WiFiDriver_Prj\7 2009-12-01 23:02:57 GMT mtk02752
293 **  remove unnecessary spin locks
294 **  \main\maintrunk.MT6620WiFiDriver_Prj\6 2009-12-01 22:51:18 GMT mtk02752
295 **  maintein i4OidPendingCount
296 **  \main\maintrunk.MT6620WiFiDriver_Prj\5 2009-11-30 10:55:03 GMT mtk02752
297 **  modify for compatibility
298 **  \main\maintrunk.MT6620WiFiDriver_Prj\4 2009-11-23 14:46:32 GMT mtk02752
299 **  add another version of command-done handler upon new event structure
300 **  \main\maintrunk.MT6620WiFiDriver_Prj\3 2009-04-29 15:42:33 GMT mtk01461
301 **  Add comment
302 **  \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-04-21 19:32:42 GMT mtk01461
303 **  Add nicCmdEventSetCommon() for general set OID
304 **  \main\maintrunk.MT6620WiFiDriver_Prj\1 2009-04-21 01:40:35 GMT mtk01461
305 **  Command Done Handler
306 */
307
308 /*******************************************************************************
309 *                         C O M P I L E R   F L A G S
310 ********************************************************************************
311 */
312
313 /*******************************************************************************
314 *                    E X T E R N A L   R E F E R E N C E S
315 ********************************************************************************
316 */
317 #include "precomp.h"
318
319
320 /*******************************************************************************
321 *                              C O N S T A N T S
322 ********************************************************************************
323 */
324
325 /*******************************************************************************
326 *                             D A T A   T Y P E S
327 ********************************************************************************
328 */
329
330 /*******************************************************************************
331 *                            P U B L I C   D A T A
332 ********************************************************************************
333 */
334
335 VOID
336 nicCmdEventQueryMcrRead (
337     IN P_ADAPTER_T  prAdapter,
338     IN P_CMD_INFO_T prCmdInfo,
339     IN PUINT_8      pucEventBuf
340     )
341 {
342     UINT_32 u4QueryInfoLen;
343     P_PARAM_CUSTOM_MCR_RW_STRUC_T prMcrRdInfo;
344     P_GLUE_INFO_T prGlueInfo;
345     P_CMD_ACCESS_REG prCmdAccessReg;
346
347
348     ASSERT(prAdapter);
349     ASSERT(prCmdInfo);
350     ASSERT(pucEventBuf);
351
352     //4 <2> Update information of OID
353     if (prCmdInfo->fgIsOid) {
354         prGlueInfo = prAdapter->prGlueInfo;
355         prCmdAccessReg = (P_CMD_ACCESS_REG)(pucEventBuf);
356
357         u4QueryInfoLen = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T);
358
359         prMcrRdInfo = (P_PARAM_CUSTOM_MCR_RW_STRUC_T) prCmdInfo->pvInformationBuffer;
360         prMcrRdInfo->u4McrOffset = prCmdAccessReg->u4Address;
361         prMcrRdInfo->u4McrData = prCmdAccessReg->u4Data;
362
363         kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_SUCCESS);
364     }
365
366     return;
367
368 }
369
370
371 VOID
372 nicCmdEventQuerySwCtrlRead (
373     IN P_ADAPTER_T  prAdapter,
374     IN P_CMD_INFO_T prCmdInfo,
375     IN PUINT_8      pucEventBuf
376     )
377 {
378     UINT_32 u4QueryInfoLen;
379     P_PARAM_CUSTOM_SW_CTRL_STRUC_T prSwCtrlInfo;
380     P_GLUE_INFO_T prGlueInfo;
381     P_CMD_SW_DBG_CTRL_T prCmdSwCtrl;
382
383     ASSERT(prAdapter);
384     ASSERT(prCmdInfo);
385     ASSERT(pucEventBuf);
386
387     //4 <2> Update information of OID
388     if (prCmdInfo->fgIsOid) {
389         prGlueInfo = prAdapter->prGlueInfo;
390         prCmdSwCtrl = (P_CMD_SW_DBG_CTRL_T)(pucEventBuf);
391
392         u4QueryInfoLen = sizeof(PARAM_CUSTOM_SW_CTRL_STRUC_T);
393
394         prSwCtrlInfo = (P_PARAM_CUSTOM_SW_CTRL_STRUC_T) prCmdInfo->pvInformationBuffer;
395         prSwCtrlInfo->u4Id = prCmdSwCtrl->u4Id;
396         prSwCtrlInfo->u4Data = prCmdSwCtrl->u4Data;
397
398         kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_SUCCESS);
399     }
400
401     return;
402
403 }
404
405
406
407 VOID
408 nicCmdEventSetCommon (
409     IN P_ADAPTER_T  prAdapter,
410     IN P_CMD_INFO_T prCmdInfo,
411     IN PUINT_8      pucEventBuf
412     )
413 {
414     ASSERT(prAdapter);
415     ASSERT(prCmdInfo);
416
417     if (prCmdInfo->fgIsOid) {
418         /* Update Set Infomation Length */
419         kalOidComplete(prAdapter->prGlueInfo,
420                        prCmdInfo->fgSetQuery,
421                        prCmdInfo->u4InformationBufferLength,
422                        WLAN_STATUS_SUCCESS);
423     }
424
425     return;
426 }
427
428 VOID
429 nicCmdEventSetDisassociate (
430     IN P_ADAPTER_T  prAdapter,
431     IN P_CMD_INFO_T prCmdInfo,
432     IN PUINT_8      pucEventBuf
433     )
434 {
435     ASSERT(prAdapter);
436     ASSERT(prCmdInfo);
437
438     if (prCmdInfo->fgIsOid) {
439         /* Update Set Infomation Length */
440         kalOidComplete(prAdapter->prGlueInfo,
441                        prCmdInfo->fgSetQuery,
442                        0,
443                        WLAN_STATUS_SUCCESS);
444     }
445
446     kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
447                     WLAN_STATUS_MEDIA_DISCONNECT,
448                     NULL,
449                     0);
450
451 #if !defined(LINUX)
452     prAdapter->fgIsRadioOff = TRUE;
453 #endif
454
455     return;
456 }
457
458 VOID
459 nicCmdEventSetIpAddress (
460     IN P_ADAPTER_T  prAdapter,
461     IN P_CMD_INFO_T prCmdInfo,
462     IN PUINT_8      pucEventBuf
463     )
464 {
465     UINT_32 u4Count;
466
467     ASSERT(prAdapter);
468     ASSERT(prCmdInfo);
469
470     u4Count = (prCmdInfo->u4SetInfoLen - OFFSET_OF(CMD_SET_NETWORK_ADDRESS_LIST, arNetAddress))
471         / sizeof(IPV4_NETWORK_ADDRESS) ;
472
473     if (prCmdInfo->fgIsOid) {
474         /* Update Set Infomation Length */
475         kalOidComplete(prAdapter->prGlueInfo,
476                        prCmdInfo->fgSetQuery,
477                        OFFSET_OF(PARAM_NETWORK_ADDRESS_LIST, arAddress) + u4Count *
478                                 (OFFSET_OF(PARAM_NETWORK_ADDRESS, aucAddress) + sizeof(PARAM_NETWORK_ADDRESS_IP)),
479                        WLAN_STATUS_SUCCESS);
480     }
481
482     return;
483 }
484
485 VOID
486 nicCmdEventQueryRfTestATInfo(
487     IN P_ADAPTER_T  prAdapter,
488     IN P_CMD_INFO_T prCmdInfo,
489     IN PUINT_8      pucEventBuf
490     )
491 {
492     P_EVENT_TEST_STATUS prTestStatus, prQueryBuffer;
493     P_GLUE_INFO_T prGlueInfo;
494     UINT_32 u4QueryInfoLen;
495
496     ASSERT(prAdapter);
497     ASSERT(prCmdInfo);
498
499     prTestStatus = (P_EVENT_TEST_STATUS)pucEventBuf;
500
501     if (prCmdInfo->fgIsOid) {
502         prGlueInfo = prAdapter->prGlueInfo;
503         prQueryBuffer = (P_EVENT_TEST_STATUS) prCmdInfo->pvInformationBuffer;
504
505         kalMemCopy(prQueryBuffer, prTestStatus, sizeof(EVENT_TEST_STATUS));
506
507         u4QueryInfoLen = sizeof(EVENT_TEST_STATUS);
508
509         /* Update Query Infomation Length */
510         kalOidComplete(prGlueInfo,
511                        prCmdInfo->fgSetQuery,
512                        u4QueryInfoLen,
513                        WLAN_STATUS_SUCCESS);
514     }
515
516     return;
517 }
518
519 VOID
520 nicCmdEventQueryLinkQuality(
521     IN P_ADAPTER_T  prAdapter,
522     IN P_CMD_INFO_T prCmdInfo,
523     IN PUINT_8      pucEventBuf
524     )
525 {
526     PARAM_RSSI rRssi, *prRssi;
527     P_EVENT_LINK_QUALITY prLinkQuality;
528     P_GLUE_INFO_T prGlueInfo;
529     UINT_32 u4QueryInfoLen;
530
531     ASSERT(prAdapter);
532     ASSERT(prCmdInfo);
533
534     prLinkQuality = (P_EVENT_LINK_QUALITY)pucEventBuf;
535
536     rRssi = (PARAM_RSSI)prLinkQuality->cRssi; // ranged from (-128 ~ 30) in unit of dBm
537
538     if(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX].eConnectionState == PARAM_MEDIA_STATE_CONNECTED) {
539         if(rRssi > PARAM_WHQL_RSSI_MAX_DBM)
540             rRssi = PARAM_WHQL_RSSI_MAX_DBM;
541         else if(rRssi < PARAM_WHQL_RSSI_MIN_DBM)
542             rRssi = PARAM_WHQL_RSSI_MIN_DBM;
543     }
544     else {
545         rRssi = PARAM_WHQL_RSSI_MIN_DBM;
546     }
547
548     if (prCmdInfo->fgIsOid) {
549         prGlueInfo = prAdapter->prGlueInfo;
550         prRssi = (PARAM_RSSI *) prCmdInfo->pvInformationBuffer;
551
552         kalMemCopy(prRssi, &rRssi, sizeof(PARAM_RSSI));
553         u4QueryInfoLen = sizeof(PARAM_RSSI);
554
555         kalOidComplete(prGlueInfo,
556                        prCmdInfo->fgSetQuery,
557                        u4QueryInfoLen,
558                        WLAN_STATUS_SUCCESS);
559     }
560 }
561
562
563 /*----------------------------------------------------------------------------*/
564 /*!
565 * @brief This routine is in response of OID_GEN_LINK_SPEED query request
566 *
567 * @param prAdapter      Pointer to the Adapter structure.
568 * @param prCmdInfo      Pointer to the pending command info
569 * @param pucEventBuf
570 *
571 * @retval none
572 */
573 /*----------------------------------------------------------------------------*/
574 VOID
575 nicCmdEventQueryLinkSpeed(
576     IN P_ADAPTER_T  prAdapter,
577     IN P_CMD_INFO_T prCmdInfo,
578     IN PUINT_8      pucEventBuf
579     )
580 {
581     P_EVENT_LINK_QUALITY prLinkQuality;
582     P_GLUE_INFO_T prGlueInfo;
583     UINT_32 u4QueryInfoLen;
584     PUINT_32 pu4LinkSpeed;
585
586     ASSERT(prAdapter);
587     ASSERT(prCmdInfo);
588
589     prLinkQuality = (P_EVENT_LINK_QUALITY)pucEventBuf;
590
591     if (prCmdInfo->fgIsOid) {
592         prGlueInfo = prAdapter->prGlueInfo;
593         pu4LinkSpeed = (PUINT_32)(prCmdInfo->pvInformationBuffer);
594
595         if(prLinkQuality->u2LinkSpeed == 0) {
596             *pu4LinkSpeed = 10000; /* 10K * 100bps = 1Mbps */
597         }
598         else {
599             *pu4LinkSpeed = prLinkQuality->u2LinkSpeed * 5000;
600         }
601
602         u4QueryInfoLen = sizeof(UINT_32);
603
604         kalOidComplete(prGlueInfo,
605                        prCmdInfo->fgSetQuery,
606                        u4QueryInfoLen,
607                        WLAN_STATUS_SUCCESS);
608     }
609 }
610
611
612 VOID
613 nicCmdEventQueryStatistics(
614     IN P_ADAPTER_T  prAdapter,
615     IN P_CMD_INFO_T prCmdInfo,
616     IN PUINT_8      pucEventBuf
617     )
618 {
619     P_PARAM_802_11_STATISTICS_STRUCT_T prStatistics;
620     P_EVENT_STATISTICS prEventStatistics;
621     P_GLUE_INFO_T prGlueInfo;
622     UINT_32 u4QueryInfoLen;
623
624     ASSERT(prAdapter);
625     ASSERT(prCmdInfo);
626
627     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
628
629     if (prCmdInfo->fgIsOid) {
630         prGlueInfo = prAdapter->prGlueInfo;
631
632         u4QueryInfoLen = sizeof(PARAM_802_11_STATISTICS_STRUCT_T);
633         prStatistics = (P_PARAM_802_11_STATISTICS_STRUCT_T) prCmdInfo->pvInformationBuffer;
634
635         prStatistics->u4Length = sizeof(PARAM_802_11_STATISTICS_STRUCT_T);
636         prStatistics->rTransmittedFragmentCount
637             = prEventStatistics->rTransmittedFragmentCount;
638         prStatistics->rMulticastTransmittedFrameCount
639             = prEventStatistics->rMulticastTransmittedFrameCount;
640         prStatistics->rFailedCount
641             = prEventStatistics->rFailedCount;
642         prStatistics->rRetryCount
643             = prEventStatistics->rRetryCount;
644         prStatistics->rMultipleRetryCount
645             = prEventStatistics->rMultipleRetryCount;
646         prStatistics->rRTSSuccessCount
647             = prEventStatistics->rRTSSuccessCount;
648         prStatistics->rRTSFailureCount
649             = prEventStatistics->rRTSFailureCount;
650         prStatistics->rACKFailureCount
651             = prEventStatistics->rACKFailureCount;
652         prStatistics->rFrameDuplicateCount
653             = prEventStatistics->rFrameDuplicateCount;
654         prStatistics->rReceivedFragmentCount
655             = prEventStatistics->rReceivedFragmentCount;
656         prStatistics->rMulticastReceivedFrameCount
657             = prEventStatistics->rMulticastReceivedFrameCount;
658         prStatistics->rFCSErrorCount
659             = prEventStatistics->rFCSErrorCount;
660         prStatistics->rTKIPLocalMICFailures.QuadPart
661             = 0;
662         prStatistics->rTKIPICVErrors.QuadPart
663             = 0;
664         prStatistics->rTKIPCounterMeasuresInvoked.QuadPart
665             = 0;
666         prStatistics->rTKIPReplays.QuadPart
667             = 0;
668         prStatistics->rCCMPFormatErrors.QuadPart
669             = 0;
670         prStatistics->rCCMPReplays.QuadPart
671             = 0;
672         prStatistics->rCCMPDecryptErrors.QuadPart
673             = 0;
674         prStatistics->rFourWayHandshakeFailures.QuadPart
675             = 0;
676         prStatistics->rWEPUndecryptableCount.QuadPart
677             = 0;
678         prStatistics->rWEPICVErrorCount.QuadPart
679             = 0;
680         prStatistics->rDecryptSuccessCount.QuadPart
681             = 0;
682         prStatistics->rDecryptFailureCount.QuadPart
683             = 0;
684
685         kalOidComplete(prGlueInfo,
686                        prCmdInfo->fgSetQuery,
687                        u4QueryInfoLen,
688                        WLAN_STATUS_SUCCESS);
689     }
690 }
691
692 VOID
693 nicCmdEventEnterRfTest(
694     IN P_ADAPTER_T  prAdapter,
695     IN P_CMD_INFO_T prCmdInfo,
696     IN PUINT_8      pucEventBuf
697     )
698 {
699     UINT_32 u4WHISR = 0, u4Value = 0;
700     UINT_8 aucTxCount[8];
701
702     ASSERT(prAdapter);
703     ASSERT(prCmdInfo);
704
705     // [driver-land]
706     prAdapter->fgTestMode = TRUE;
707
708     // 0. always indicate disconnection
709     if(kalGetMediaStateIndicated(prAdapter->prGlueInfo) != PARAM_MEDIA_STATE_DISCONNECTED) {
710         kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
711                 WLAN_STATUS_MEDIA_DISCONNECT,
712                 NULL,
713                 0);
714     }
715
716     // 1. Remove pending TX
717     nicTxRelease(prAdapter);
718
719     // 1.1 clear pending Security / Management Frames
720     kalClearSecurityFrames(prAdapter->prGlueInfo);
721     kalClearMgmtFrames(prAdapter->prGlueInfo);
722
723     // 1.2 clear pending TX packet queued in glue layer
724     kalFlushPendingTxPackets(prAdapter->prGlueInfo);
725
726     // 2. Reset driver-domain FSMs
727     nicUninitMGMT(prAdapter);
728
729     nicResetSystemService(prAdapter);
730     nicInitMGMT(prAdapter, NULL);
731
732     // 3. Disable Interrupt
733     HAL_INTR_DISABLE(prAdapter);
734
735     // 4. Block til firmware completed entering into RF test mode
736     kalMsleep(500);
737     while(1) {
738         HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
739
740         if (u4Value & WCIR_WLAN_READY) {
741             break;
742         }
743         else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
744                 || fgIsBusAccessFailed == TRUE) {
745             if (prCmdInfo->fgIsOid) {
746                 /* Update Set Infomation Length */
747                 kalOidComplete(prAdapter->prGlueInfo,
748                         prCmdInfo->fgSetQuery,
749                         prCmdInfo->u4SetInfoLen,
750                         WLAN_STATUS_NOT_SUPPORTED);
751
752             }
753             return;
754         }
755         else
756             kalMsleep(10);
757     }
758
759     // 5. Clear Interrupt Status
760     HAL_READ_INTR_STATUS(prAdapter, 4, (PUINT_8)&u4WHISR);
761     if(HAL_IS_TX_DONE_INTR(u4WHISR)) {
762         HAL_READ_TX_RELEASED_COUNT(prAdapter, aucTxCount);
763     }
764
765     // 6. Reset TX Counter
766     nicTxResetResource(prAdapter);
767
768     // 7. Re-enable Interrupt
769     HAL_INTR_ENABLE(prAdapter);
770
771     // 8. completion indication
772     if (prCmdInfo->fgIsOid) {
773         /* Update Set Infomation Length */
774         kalOidComplete(prAdapter->prGlueInfo,
775                        prCmdInfo->fgSetQuery,
776                        prCmdInfo->u4SetInfoLen,
777                        WLAN_STATUS_SUCCESS);
778     }
779
780 #if CFG_SUPPORT_NVRAM
781     // 9. load manufacture data
782     wlanLoadManufactureData(prAdapter, kalGetConfiguration(prAdapter->prGlueInfo));
783 #endif
784
785     return;
786 }
787
788 VOID
789 nicCmdEventLeaveRfTest(
790     IN P_ADAPTER_T  prAdapter,
791     IN P_CMD_INFO_T prCmdInfo,
792     IN PUINT_8      pucEventBuf
793     )
794 {
795     UINT_32 u4WHISR = 0, u4Value = 0;
796     UINT_8 aucTxCount[8];
797
798     ASSERT(prAdapter);
799     ASSERT(prCmdInfo);
800
801     // 1. Disable Interrupt
802     HAL_INTR_DISABLE(prAdapter);
803
804     // 2. Block til firmware completed leaving from RF test mode
805     kalMsleep(500);
806     while(1) {
807         HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
808
809         if (u4Value & WCIR_WLAN_READY) {
810             break;
811         }
812         else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
813                 || fgIsBusAccessFailed == TRUE) {
814             if (prCmdInfo->fgIsOid) {
815                 /* Update Set Infomation Length */
816                 kalOidComplete(prAdapter->prGlueInfo,
817                         prCmdInfo->fgSetQuery,
818                         prCmdInfo->u4SetInfoLen,
819                         WLAN_STATUS_NOT_SUPPORTED);
820
821             }
822             return;
823         }
824         else {
825             kalMsleep(10);
826         }
827     }
828
829     // 3. Clear Interrupt Status
830     HAL_READ_INTR_STATUS(prAdapter, 4, (PUINT_8)&u4WHISR);
831     if(HAL_IS_TX_DONE_INTR(u4WHISR)) {
832         HAL_READ_TX_RELEASED_COUNT(prAdapter, aucTxCount);
833     }
834
835     // 4. Reset TX Counter
836     nicTxResetResource(prAdapter);
837
838     // 5. Re-enable Interrupt
839     HAL_INTR_ENABLE(prAdapter);
840
841     // 6. set driver-land variable
842     prAdapter->fgTestMode = FALSE;
843
844     // 7. completion indication
845     if (prCmdInfo->fgIsOid) {
846         /* Update Set Infomation Length */
847         kalOidComplete(prAdapter->prGlueInfo,
848                        prCmdInfo->fgSetQuery,
849                        prCmdInfo->u4SetInfoLen,
850                        WLAN_STATUS_SUCCESS);
851     }
852
853     /* 8. Indicate as disconnected */
854     if(kalGetMediaStateIndicated(prAdapter->prGlueInfo) != PARAM_MEDIA_STATE_DISCONNECTED) {
855
856         kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
857                 WLAN_STATUS_MEDIA_DISCONNECT,
858                 NULL,
859                 0);
860
861         prAdapter->rWlanInfo.u4SysTime = kalGetTimeTick();
862     }
863
864 #if CFG_SUPPORT_NVRAM
865     /* 9. load manufacture data */
866     wlanLoadManufactureData(prAdapter, kalGetConfiguration(prAdapter->prGlueInfo));
867 #endif
868
869     /* 10. Override network address */
870     wlanUpdateNetworkAddress(prAdapter);
871
872     return;
873 }
874
875 VOID
876 nicCmdEventQueryAddress(
877     IN P_ADAPTER_T  prAdapter,
878     IN P_CMD_INFO_T prCmdInfo,
879     IN PUINT_8      pucEventBuf
880     )
881 {
882     UINT_32 u4QueryInfoLen;
883     P_GLUE_INFO_T prGlueInfo;
884     P_EVENT_BASIC_CONFIG prEventBasicConfig;
885
886     ASSERT(prAdapter);
887     ASSERT(prCmdInfo);
888     ASSERT(pucEventBuf);
889
890     prEventBasicConfig = (P_EVENT_BASIC_CONFIG)(pucEventBuf);
891
892     // copy to adapter
893     kalMemCopy(&(prAdapter->rMyMacAddr), &(prEventBasicConfig->rMyMacAddr), MAC_ADDR_LEN);
894
895     //4 <2> Update information of OID
896     if (prCmdInfo->fgIsOid) {
897         prGlueInfo = prAdapter->prGlueInfo;
898
899         kalMemCopy(prCmdInfo->pvInformationBuffer, &(prEventBasicConfig->rMyMacAddr), MAC_ADDR_LEN);
900         u4QueryInfoLen = MAC_ADDR_LEN;
901
902         kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_SUCCESS);
903     }
904
905     //4 <3> Update new MAC address and all 3 networks
906     COPY_MAC_ADDR(prAdapter->rWifiVar.aucMacAddress, prAdapter->rMyMacAddr);
907     COPY_MAC_ADDR(prAdapter->rWifiVar.aucDeviceAddress, prAdapter->rMyMacAddr);
908     prAdapter->rWifiVar.aucDeviceAddress[0] ^= MAC_ADDR_LOCAL_ADMIN;
909
910     COPY_MAC_ADDR(prAdapter->rWifiVar.aucInterfaceAddress, prAdapter->rMyMacAddr);
911     prAdapter->rWifiVar.aucInterfaceAddress[0] ^= MAC_ADDR_LOCAL_ADMIN;
912
913     COPY_MAC_ADDR(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX].aucOwnMacAddr,
914             prAdapter->rMyMacAddr);
915
916 #if CFG_ENABLE_WIFI_DIRECT
917     if(prAdapter->fgIsP2PRegistered) {
918         COPY_MAC_ADDR(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX].aucOwnMacAddr,
919                 prAdapter->rWifiVar.aucDeviceAddress);
920     }
921 #endif
922
923 #if CFG_ENABLE_BT_OVER_WIFI
924     COPY_MAC_ADDR(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_BOW_INDEX].aucOwnMacAddr,
925             prAdapter->rWifiVar.aucDeviceAddress);
926 #endif
927
928 #if CFG_TEST_WIFI_DIRECT_GO
929     if (prAdapter->rWifiVar.prP2pFsmInfo->eCurrentState == P2P_STATE_IDLE) {
930         wlanEnableP2pFunction(prAdapter);
931
932         wlanEnableATGO(prAdapter);
933     }
934 #endif
935
936     kalUpdateMACAddress(prAdapter->prGlueInfo, prAdapter->rWifiVar.aucMacAddress);
937
938     return;
939 }
940
941 VOID
942 nicCmdEventQueryMcastAddr(
943     IN P_ADAPTER_T  prAdapter,
944     IN P_CMD_INFO_T prCmdInfo,
945     IN PUINT_8      pucEventBuf
946     )
947 {
948     UINT_32 u4QueryInfoLen;
949     P_GLUE_INFO_T prGlueInfo;
950     P_EVENT_MAC_MCAST_ADDR prEventMacMcastAddr;
951
952     ASSERT(prAdapter);
953     ASSERT(prCmdInfo);
954     ASSERT(pucEventBuf);
955
956     //4 <2> Update information of OID
957     if (prCmdInfo->fgIsOid) {
958         prGlueInfo = prAdapter->prGlueInfo;
959         prEventMacMcastAddr = (P_EVENT_MAC_MCAST_ADDR)(pucEventBuf);
960
961         u4QueryInfoLen = prEventMacMcastAddr->u4NumOfGroupAddr * MAC_ADDR_LEN;
962
963         // buffer length check
964         if (prCmdInfo->u4InformationBufferLength < u4QueryInfoLen) {
965             kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_BUFFER_TOO_SHORT);
966         }
967         else {
968             kalMemCopy(prCmdInfo->pvInformationBuffer,
969                     prEventMacMcastAddr->arAddress,
970                     prEventMacMcastAddr->u4NumOfGroupAddr * MAC_ADDR_LEN);
971
972             kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_SUCCESS);
973         }
974     }
975 }
976
977 VOID
978 nicCmdEventQueryEepromRead(
979     IN P_ADAPTER_T  prAdapter,
980     IN P_CMD_INFO_T prCmdInfo,
981     IN PUINT_8      pucEventBuf
982     )
983 {
984     UINT_32 u4QueryInfoLen;
985     P_PARAM_CUSTOM_EEPROM_RW_STRUC_T prEepromRdInfo;
986     P_GLUE_INFO_T prGlueInfo;
987     P_EVENT_ACCESS_EEPROM prEventAccessEeprom;
988
989     ASSERT(prAdapter);
990     ASSERT(prCmdInfo);
991     ASSERT(pucEventBuf);
992
993     //4 <2> Update information of OID
994     if (prCmdInfo->fgIsOid) {
995         prGlueInfo = prAdapter->prGlueInfo;
996         prEventAccessEeprom = (P_EVENT_ACCESS_EEPROM)(pucEventBuf);
997
998         u4QueryInfoLen = sizeof(PARAM_CUSTOM_EEPROM_RW_STRUC_T);
999
1000         prEepromRdInfo = (P_PARAM_CUSTOM_EEPROM_RW_STRUC_T) prCmdInfo->pvInformationBuffer;
1001         prEepromRdInfo->ucEepromIndex = (UINT_8)(prEventAccessEeprom->u2Offset);
1002         prEepromRdInfo->u2EepromData = prEventAccessEeprom->u2Data;
1003
1004         kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_SUCCESS);
1005     }
1006
1007     return;
1008
1009 }
1010
1011
1012 VOID
1013 nicCmdEventSetMediaStreamMode(
1014     IN P_ADAPTER_T  prAdapter,
1015     IN P_CMD_INFO_T prCmdInfo,
1016     IN PUINT_8      pucEventBuf
1017     )
1018 {
1019     PARAM_MEDIA_STREAMING_INDICATION rParamMediaStreamIndication;
1020
1021     ASSERT(prAdapter);
1022     ASSERT(prCmdInfo);
1023
1024     if (prCmdInfo->fgIsOid) {
1025         /* Update Set Infomation Length */
1026         kalOidComplete(prAdapter->prGlueInfo,
1027                        prCmdInfo->fgSetQuery,
1028                        prCmdInfo->u4SetInfoLen,
1029                        WLAN_STATUS_SUCCESS);
1030     }
1031
1032     rParamMediaStreamIndication.rStatus.eStatusType =
1033         ENUM_STATUS_TYPE_MEDIA_STREAM_MODE;
1034     rParamMediaStreamIndication.eMediaStreamMode =
1035         prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode == 0 ?
1036             ENUM_MEDIA_STREAM_OFF : ENUM_MEDIA_STREAM_ON;
1037
1038     kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
1039                 WLAN_STATUS_MEDIA_SPECIFIC_INDICATION,
1040                 (PVOID)&rParamMediaStreamIndication,
1041                 sizeof(PARAM_MEDIA_STREAMING_INDICATION));
1042 }
1043
1044
1045 /* Statistics responder */
1046 VOID
1047 nicCmdEventQueryXmitOk(
1048     IN P_ADAPTER_T  prAdapter,
1049     IN P_CMD_INFO_T prCmdInfo,
1050     IN PUINT_8      pucEventBuf
1051     )
1052 {
1053     P_EVENT_STATISTICS prEventStatistics;
1054     P_GLUE_INFO_T prGlueInfo;
1055     UINT_32 u4QueryInfoLen;
1056     PUINT_32 pu4Data;
1057     PUINT_64 pu8Data;
1058
1059     ASSERT(prAdapter);
1060     ASSERT(prCmdInfo);
1061
1062     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1063
1064     if (prCmdInfo->fgIsOid) {
1065         prGlueInfo = prAdapter->prGlueInfo;
1066
1067         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1068             u4QueryInfoLen = sizeof(UINT_32);
1069
1070             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1071             *pu4Data = (UINT_32) prEventStatistics->rTransmittedFragmentCount.QuadPart;
1072         }
1073         else {
1074             u4QueryInfoLen = sizeof(UINT_64);
1075
1076             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1077             *pu8Data = prEventStatistics->rTransmittedFragmentCount.QuadPart;
1078         }
1079
1080         kalOidComplete(prGlueInfo,
1081                        prCmdInfo->fgSetQuery,
1082                        u4QueryInfoLen,
1083                        WLAN_STATUS_SUCCESS);
1084     }
1085 }
1086
1087
1088 VOID
1089 nicCmdEventQueryRecvOk(
1090     IN P_ADAPTER_T  prAdapter,
1091     IN P_CMD_INFO_T prCmdInfo,
1092     IN PUINT_8      pucEventBuf
1093     )
1094 {
1095     P_EVENT_STATISTICS prEventStatistics;
1096     P_GLUE_INFO_T prGlueInfo;
1097     UINT_32 u4QueryInfoLen;
1098     PUINT_32 pu4Data;
1099     PUINT_64 pu8Data;
1100
1101     ASSERT(prAdapter);
1102     ASSERT(prCmdInfo);
1103
1104     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1105
1106     if (prCmdInfo->fgIsOid) {
1107         prGlueInfo = prAdapter->prGlueInfo;
1108
1109         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1110             u4QueryInfoLen = sizeof(UINT_32);
1111
1112             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1113             *pu4Data = (UINT_32) prEventStatistics->rReceivedFragmentCount.QuadPart;
1114         }
1115         else {
1116             u4QueryInfoLen = sizeof(UINT_64);
1117
1118             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1119             *pu8Data = prEventStatistics->rReceivedFragmentCount.QuadPart;
1120         }
1121
1122         kalOidComplete(prGlueInfo,
1123                        prCmdInfo->fgSetQuery,
1124                        u4QueryInfoLen,
1125                        WLAN_STATUS_SUCCESS);
1126     }
1127 }
1128
1129 VOID
1130 nicCmdEventQueryXmitError(
1131     IN P_ADAPTER_T  prAdapter,
1132     IN P_CMD_INFO_T prCmdInfo,
1133     IN PUINT_8      pucEventBuf
1134     )
1135 {
1136     P_EVENT_STATISTICS prEventStatistics;
1137     P_GLUE_INFO_T prGlueInfo;
1138     UINT_32 u4QueryInfoLen;
1139     PUINT_32 pu4Data;
1140     PUINT_64 pu8Data;
1141
1142     ASSERT(prAdapter);
1143     ASSERT(prCmdInfo);
1144
1145     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1146
1147     if (prCmdInfo->fgIsOid) {
1148         prGlueInfo = prAdapter->prGlueInfo;
1149
1150         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1151             u4QueryInfoLen = sizeof(UINT_32);
1152
1153             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1154             *pu4Data = (UINT_32) prEventStatistics->rFailedCount.QuadPart;
1155         }
1156         else {
1157             u4QueryInfoLen = sizeof(UINT_64);
1158
1159             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1160             *pu8Data = (UINT_64) prEventStatistics->rFailedCount.QuadPart;
1161         }
1162
1163         kalOidComplete(prGlueInfo,
1164                        prCmdInfo->fgSetQuery,
1165                        u4QueryInfoLen,
1166                        WLAN_STATUS_SUCCESS);
1167     }
1168 }
1169
1170
1171 VOID
1172 nicCmdEventQueryRecvError(
1173     IN P_ADAPTER_T  prAdapter,
1174     IN P_CMD_INFO_T prCmdInfo,
1175     IN PUINT_8      pucEventBuf
1176     )
1177 {
1178     P_EVENT_STATISTICS prEventStatistics;
1179     P_GLUE_INFO_T prGlueInfo;
1180     UINT_32 u4QueryInfoLen;
1181     PUINT_32 pu4Data;
1182     PUINT_64 pu8Data;
1183
1184     ASSERT(prAdapter);
1185     ASSERT(prCmdInfo);
1186
1187     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1188
1189     if (prCmdInfo->fgIsOid) {
1190         prGlueInfo = prAdapter->prGlueInfo;
1191
1192         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1193             u4QueryInfoLen = sizeof(UINT_32);
1194
1195             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1196             *pu4Data = (UINT_32) prEventStatistics->rFCSErrorCount.QuadPart;
1197             // @FIXME, RX_ERROR_DROP_COUNT/RX_FIFO_FULL_DROP_COUNT is not calculated
1198         }
1199         else {
1200             u4QueryInfoLen = sizeof(UINT_64);
1201
1202             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1203             *pu8Data = prEventStatistics->rFCSErrorCount.QuadPart;
1204             // @FIXME, RX_ERROR_DROP_COUNT/RX_FIFO_FULL_DROP_COUNT is not calculated
1205         }
1206
1207         kalOidComplete(prGlueInfo,
1208                        prCmdInfo->fgSetQuery,
1209                        u4QueryInfoLen,
1210                        WLAN_STATUS_SUCCESS);
1211     }
1212 }
1213
1214
1215 VOID
1216 nicCmdEventQueryRecvNoBuffer(
1217     IN P_ADAPTER_T  prAdapter,
1218     IN P_CMD_INFO_T prCmdInfo,
1219     IN PUINT_8      pucEventBuf
1220     )
1221 {
1222     P_EVENT_STATISTICS prEventStatistics;
1223     P_GLUE_INFO_T prGlueInfo;
1224     UINT_32 u4QueryInfoLen;
1225     PUINT_32 pu4Data;
1226     PUINT_64 pu8Data;
1227
1228     ASSERT(prAdapter);
1229     ASSERT(prCmdInfo);
1230
1231     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1232
1233     if (prCmdInfo->fgIsOid) {
1234         prGlueInfo = prAdapter->prGlueInfo;
1235
1236         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1237             u4QueryInfoLen = sizeof(UINT_32);
1238
1239             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1240             *pu4Data = 0; // @FIXME?
1241         }
1242         else {
1243             u4QueryInfoLen = sizeof(UINT_64);
1244
1245             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1246             *pu8Data = 0; //@FIXME?
1247         }
1248
1249         kalOidComplete(prGlueInfo,
1250                        prCmdInfo->fgSetQuery,
1251                        u4QueryInfoLen,
1252                        WLAN_STATUS_SUCCESS);
1253     }
1254 }
1255
1256
1257 VOID
1258 nicCmdEventQueryRecvCrcError(
1259     IN P_ADAPTER_T  prAdapter,
1260     IN P_CMD_INFO_T prCmdInfo,
1261     IN PUINT_8      pucEventBuf
1262     )
1263 {
1264     P_EVENT_STATISTICS prEventStatistics;
1265     P_GLUE_INFO_T prGlueInfo;
1266     UINT_32 u4QueryInfoLen;
1267     PUINT_32 pu4Data;
1268     PUINT_64 pu8Data;
1269
1270     ASSERT(prAdapter);
1271     ASSERT(prCmdInfo);
1272
1273     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1274
1275     if (prCmdInfo->fgIsOid) {
1276         prGlueInfo = prAdapter->prGlueInfo;
1277
1278         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1279             u4QueryInfoLen = sizeof(UINT_32);
1280
1281             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1282             *pu4Data = (UINT_32) prEventStatistics->rFCSErrorCount.QuadPart;
1283         }
1284         else {
1285             u4QueryInfoLen = sizeof(UINT_64);
1286
1287             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1288             *pu8Data = prEventStatistics->rFCSErrorCount.QuadPart;
1289         }
1290
1291         kalOidComplete(prGlueInfo,
1292                        prCmdInfo->fgSetQuery,
1293                        u4QueryInfoLen,
1294                        WLAN_STATUS_SUCCESS);
1295     }
1296 }
1297
1298
1299 VOID
1300 nicCmdEventQueryRecvErrorAlignment(
1301     IN P_ADAPTER_T  prAdapter,
1302     IN P_CMD_INFO_T prCmdInfo,
1303     IN PUINT_8      pucEventBuf
1304     )
1305 {
1306     P_EVENT_STATISTICS prEventStatistics;
1307     P_GLUE_INFO_T prGlueInfo;
1308     UINT_32 u4QueryInfoLen;
1309     PUINT_32 pu4Data;
1310     PUINT_64 pu8Data;
1311
1312     ASSERT(prAdapter);
1313     ASSERT(prCmdInfo);
1314
1315     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1316
1317     if (prCmdInfo->fgIsOid) {
1318         prGlueInfo = prAdapter->prGlueInfo;
1319
1320         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1321             u4QueryInfoLen = sizeof(UINT_32);
1322
1323             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1324             *pu4Data = (UINT_32) 0; //@FIXME
1325         }
1326         else {
1327             u4QueryInfoLen = sizeof(UINT_64);
1328
1329             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1330             *pu8Data = 0; //@FIXME
1331         }
1332
1333         kalOidComplete(prGlueInfo,
1334                        prCmdInfo->fgSetQuery,
1335                        u4QueryInfoLen,
1336                        WLAN_STATUS_SUCCESS);
1337     }
1338 }
1339
1340
1341 VOID
1342 nicCmdEventQueryXmitOneCollision(
1343     IN P_ADAPTER_T  prAdapter,
1344     IN P_CMD_INFO_T prCmdInfo,
1345     IN PUINT_8      pucEventBuf
1346     )
1347 {
1348     P_EVENT_STATISTICS prEventStatistics;
1349     P_GLUE_INFO_T prGlueInfo;
1350     UINT_32 u4QueryInfoLen;
1351     PUINT_32 pu4Data;
1352     PUINT_64 pu8Data;
1353
1354     ASSERT(prAdapter);
1355     ASSERT(prCmdInfo);
1356
1357     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1358
1359     if (prCmdInfo->fgIsOid) {
1360         prGlueInfo = prAdapter->prGlueInfo;
1361
1362         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1363             u4QueryInfoLen = sizeof(UINT_32);
1364
1365             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1366             *pu4Data = (UINT_32) (prEventStatistics->rMultipleRetryCount.QuadPart - prEventStatistics->rRetryCount.QuadPart);
1367         }
1368         else {
1369             u4QueryInfoLen = sizeof(UINT_64);
1370
1371             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1372             *pu8Data = (UINT_64) (prEventStatistics->rMultipleRetryCount.QuadPart - prEventStatistics->rRetryCount.QuadPart);
1373         }
1374
1375         kalOidComplete(prGlueInfo,
1376                        prCmdInfo->fgSetQuery,
1377                        u4QueryInfoLen,
1378                        WLAN_STATUS_SUCCESS);
1379     }
1380 }
1381
1382
1383 VOID
1384 nicCmdEventQueryXmitMoreCollisions(
1385     IN P_ADAPTER_T  prAdapter,
1386     IN P_CMD_INFO_T prCmdInfo,
1387     IN PUINT_8      pucEventBuf
1388     )
1389 {
1390     P_EVENT_STATISTICS prEventStatistics;
1391     P_GLUE_INFO_T prGlueInfo;
1392     UINT_32 u4QueryInfoLen;
1393     PUINT_32 pu4Data;
1394     PUINT_64 pu8Data;
1395
1396     ASSERT(prAdapter);
1397     ASSERT(prCmdInfo);
1398
1399     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1400
1401     if (prCmdInfo->fgIsOid) {
1402         prGlueInfo = prAdapter->prGlueInfo;
1403
1404         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1405             u4QueryInfoLen = sizeof(UINT_32);
1406
1407             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1408             *pu4Data = (UINT_32) prEventStatistics->rMultipleRetryCount.QuadPart;
1409         }
1410         else {
1411             u4QueryInfoLen = sizeof(UINT_64);
1412
1413             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1414             *pu8Data = (UINT_64) prEventStatistics->rMultipleRetryCount.QuadPart;
1415         }
1416
1417         kalOidComplete(prGlueInfo,
1418                        prCmdInfo->fgSetQuery,
1419                        u4QueryInfoLen,
1420                        WLAN_STATUS_SUCCESS);
1421     }
1422 }
1423
1424
1425 VOID
1426 nicCmdEventQueryXmitMaxCollisions(
1427     IN P_ADAPTER_T  prAdapter,
1428     IN P_CMD_INFO_T prCmdInfo,
1429     IN PUINT_8      pucEventBuf
1430     )
1431 {
1432     P_EVENT_STATISTICS prEventStatistics;
1433     P_GLUE_INFO_T prGlueInfo;
1434     UINT_32 u4QueryInfoLen;
1435     PUINT_32 pu4Data;
1436     PUINT_64 pu8Data;
1437
1438     ASSERT(prAdapter);
1439     ASSERT(prCmdInfo);
1440
1441     prEventStatistics = (P_EVENT_STATISTICS)pucEventBuf;
1442
1443     if (prCmdInfo->fgIsOid) {
1444         prGlueInfo = prAdapter->prGlueInfo;
1445
1446         if(prCmdInfo->u4InformationBufferLength == sizeof(UINT_32)) {
1447             u4QueryInfoLen = sizeof(UINT_32);
1448
1449             pu4Data = (PUINT_32) prCmdInfo->pvInformationBuffer;
1450             *pu4Data = (UINT_32) prEventStatistics->rFailedCount.QuadPart;
1451         }
1452         else {
1453             u4QueryInfoLen = sizeof(UINT_64);
1454
1455             pu8Data = (PUINT_64) prCmdInfo->pvInformationBuffer;
1456             *pu8Data = (UINT_64) prEventStatistics->rFailedCount.QuadPart;
1457         }
1458
1459         kalOidComplete(prGlueInfo,
1460                        prCmdInfo->fgSetQuery,
1461                        u4QueryInfoLen,
1462                        WLAN_STATUS_SUCCESS);
1463     }
1464 }
1465
1466
1467 /*----------------------------------------------------------------------------*/
1468 /*!
1469 * @brief This function is called when command by OID/ioctl has been timeout
1470 *
1471 * @param prAdapter          Pointer to the Adapter structure.
1472 * @param prCmdInfo          Pointer to the command information
1473 *
1474 * @return TRUE
1475 *         FALSE
1476 */
1477 /*----------------------------------------------------------------------------*/
1478 VOID
1479 nicOidCmdTimeoutCommon (
1480     IN P_ADAPTER_T  prAdapter,
1481     IN P_CMD_INFO_T prCmdInfo
1482     )
1483 {
1484     ASSERT(prAdapter);
1485
1486     kalOidComplete(prAdapter->prGlueInfo,
1487             prCmdInfo->fgSetQuery,
1488             0,
1489             WLAN_STATUS_FAILURE);
1490 }
1491
1492
1493 /*----------------------------------------------------------------------------*/
1494 /*!
1495 * @brief This function is a generic command timeout handler
1496 *
1497 * @param pfnOidHandler      Pointer to the OID handler
1498 *
1499 * @return none
1500 */
1501 /*----------------------------------------------------------------------------*/
1502 VOID
1503 nicCmdTimeoutCommon (
1504     IN P_ADAPTER_T  prAdapter,
1505     IN P_CMD_INFO_T prCmdInfo
1506     )
1507 {
1508     ASSERT(prAdapter);
1509 }
1510
1511
1512 /*----------------------------------------------------------------------------*/
1513 /*!
1514 * @brief This function is called when command for entering RF test has
1515 *        failed sending due to timeout (highly possibly by firmware crash)
1516 *
1517 * @param prAdapter          Pointer to the Adapter structure.
1518 * @param prCmdInfo          Pointer to the command information
1519 *
1520 * @return none
1521 *
1522 */
1523 /*----------------------------------------------------------------------------*/
1524 VOID
1525 nicOidCmdEnterRFTestTimeout (
1526     IN P_ADAPTER_T  prAdapter,
1527     IN P_CMD_INFO_T prCmdInfo
1528     )
1529 {
1530     ASSERT(prAdapter);
1531
1532     // 1. Remove pending TX frames
1533     nicTxRelease(prAdapter);
1534
1535     // 1.1 clear pending Security / Management Frames
1536     kalClearSecurityFrames(prAdapter->prGlueInfo);
1537     kalClearMgmtFrames(prAdapter->prGlueInfo);
1538
1539     // 1.2 clear pending TX packet queued in glue layer
1540     kalFlushPendingTxPackets(prAdapter->prGlueInfo);
1541
1542     // 2. indiate for OID failure
1543     kalOidComplete(prAdapter->prGlueInfo,
1544             prCmdInfo->fgSetQuery,
1545             0,
1546             WLAN_STATUS_FAILURE);
1547 }
1548
1549
1550 /*----------------------------------------------------------------------------*/
1551 /*!
1552 * @brief This function is called when command for memory dump has
1553 *        replied a event.
1554 *
1555 * @param prAdapter          Pointer to the Adapter structure.
1556 * @param prCmdInfo         Pointer to the command information
1557 * @param pucEventBuf       Pointer to event buffer
1558 *
1559 * @return none
1560 *
1561 */
1562 /*----------------------------------------------------------------------------*/
1563 VOID
1564 nicCmdEventQueryMemDump (
1565     IN P_ADAPTER_T  prAdapter,
1566     IN P_CMD_INFO_T prCmdInfo,
1567     IN PUINT_8      pucEventBuf
1568     )
1569 {
1570     UINT_32 u4QueryInfoLen;
1571     P_PARAM_CUSTOM_MEM_DUMP_STRUC_T prMemDumpInfo;
1572     P_GLUE_INFO_T prGlueInfo;
1573     P_EVENT_DUMP_MEM_T prEventDumpMem;
1574     static UINT_8 aucPath[256];
1575     static UINT_32 u4CurTimeTick;
1576
1577     ASSERT(prAdapter);
1578     ASSERT(prCmdInfo);
1579     ASSERT(pucEventBuf);
1580
1581     //4 <2> Update information of OID
1582     if (prCmdInfo->fgIsOid) {
1583         prGlueInfo = prAdapter->prGlueInfo;
1584         prEventDumpMem = (P_EVENT_DUMP_MEM_T)(pucEventBuf);
1585
1586         u4QueryInfoLen = sizeof(P_PARAM_CUSTOM_MEM_DUMP_STRUC_T);
1587
1588         prMemDumpInfo = (P_PARAM_CUSTOM_MEM_DUMP_STRUC_T) prCmdInfo->pvInformationBuffer;
1589         prMemDumpInfo->u4Address = prEventDumpMem->u4Address;
1590         prMemDumpInfo->u4Length = prEventDumpMem->u4Length;
1591         prMemDumpInfo->u4RemainLength = prEventDumpMem->u4RemainLength;
1592         prMemDumpInfo->ucFragNum = prEventDumpMem->ucFragNum;
1593
1594 #if 0
1595         do{
1596             UINT_32 i = 0;
1597             printk("Rx dump address 0x%X, Length %d, FragNum %d, remain %d\n",
1598                 prEventDumpMem->u4Address,
1599                 prEventDumpMem->u4Length,
1600                 prEventDumpMem->ucFragNum,
1601                 prEventDumpMem->u4RemainLength);
1602 #if 0
1603             for(i = 0; i < prEventDumpMem->u4Length; i++) {
1604                 printk("%02X ", prEventDumpMem->aucBuffer[i]);
1605                 if(i % 32 == 31) {
1606                     printk("\n");
1607                 }
1608             }
1609 #endif
1610         }while(FALSE);
1611 #endif
1612
1613         if(prEventDumpMem->ucFragNum == 1) {
1614         /* Store memory dump into sdcard,
1615                 * path /sdcard/dump_<current  system tick>_<memory address>_<memory length>.hex
1616                 */
1617             u4CurTimeTick = kalGetTimeTick();
1618             sprintf(aucPath, "/sdcard/dump_%ld_0x%08lX_%ld.hex",
1619                 u4CurTimeTick,
1620                 prEventDumpMem->u4Address,
1621                 prEventDumpMem->u4Length + prEventDumpMem->u4RemainLength);
1622             kalWriteToFile(aucPath, FALSE, &prEventDumpMem->aucBuffer[0], prEventDumpMem->u4Length);
1623         }
1624         else {
1625             /* Append current memory dump to the hex file */
1626             kalWriteToFile(aucPath, TRUE, &prEventDumpMem->aucBuffer[0], prEventDumpMem->u4Length);
1627         }
1628
1629         if(prEventDumpMem->u4RemainLength == 0 ||
1630            prEventDumpMem->u4Address == 0xFFFFFFFF) {
1631            /* The request is finished or firmware response a error */
1632            /* Reply time tick to iwpriv */
1633             *((PUINT_32)prCmdInfo->pvInformationBuffer) = u4CurTimeTick;
1634             kalOidComplete(prGlueInfo, prCmdInfo->fgSetQuery, u4QueryInfoLen, WLAN_STATUS_SUCCESS);
1635         }
1636         else {
1637             /* The memory dump request is not finished, Send next command*/
1638             wlanSendMemDumpCmd(
1639                 prAdapter,
1640                 prCmdInfo->pvInformationBuffer,
1641                 prCmdInfo->u4InformationBufferLength);
1642         }
1643     }
1644
1645     return;
1646
1647 }
1648
1649
1650
1651