862b9fa64661b24daa7e5cc7af38cf3a2d913280
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931 / mgmt / sec_fsm.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/sec_fsm.c#1 $
3 */
4
5 /*! \file   "sec_fsm.c"
6     \brief  This is the file implement security check state machine.
7
8     In security module, do the port control check after success join to an AP,
9     and the path to NORMAL TR, the state machine handle these state transition.
10 */
11
12
13
14 /*
15 ** $Log: sec_fsm.c $
16  *
17  * 11 24 2011 wh.su
18  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
19  * Adjust code for DBG and CONFIG_XLOG.
20  *
21  * 11 11 2011 wh.su
22  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
23  * modify the xlog related code.
24  *
25  * 11 10 2011 wh.su
26  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
27  * change the debug module level.
28  *
29  * 11 02 2011 wh.su
30  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
31  * adding the code for XLOG.
32  *
33  * 03 29 2011 wh.su
34  * [WCXRP00000248] [MT6620 Wi-Fi][FW]Fixed the Klockwork error
35  * fixed the kclocwork error.
36  *
37  * 01 26 2011 yuche.tsai
38  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
39  * .
40  *
41  * 01 25 2011 yuche.tsai
42  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
43  * Fix Compile Error when DBG is disabled.
44  *
45  * 01 25 2011 yuche.tsai
46  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
47  * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
48  *
49  * 09 29 2010 wh.su
50  * [WCXRP00000072] [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue
51  * [MT6620 Wi-Fi][Driver] Fix TKIP Counter Measure EAPoL callback register issue.
52  *
53  * 09 24 2010 wh.su
54  * NULL
55  * [WCXRP00005002][MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning.
56  *
57  * 09 03 2010 kevin.huang
58  * NULL
59  * Refine #include sequence and solve recursive/nested #include issue
60  *
61  * 08 20 2010 wh.su
62  * NULL
63  * adding the eapol callback setting.
64  *
65  * 08 19 2010 wh.su
66  * NULL
67  * adding the tx pkt call back handle for countermeasure.
68  *
69  * 07 19 2010 wh.su
70  *
71  * fixed the compilng error at debug mode.
72  *
73  * 07 08 2010 cp.wu
74  *
75  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
76  *
77  * 06 21 2010 wh.su
78  * [WPD00003840][MT6620 5931] Security migration
79  * modify some code for concurrent network.
80  *
81  * 06 19 2010 wh.su
82  * [WPD00003840][MT6620 5931] Security migration
83  * consdier the concurrent network setting.
84  *
85  * 05 28 2010 wh.su
86  * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
87  * fixed the ad-hoc wpa-none send non-encrypted frame issue.
88  *
89  * 05 24 2010 kevin.huang
90  * [BORA00000794][WIFISYS][New Feature]Power Management Support
91  * Refine authSendAuthFrame() for NULL STA_RECORD_T case and minimum deauth interval.
92  *
93  * 04 24 2010 cm.chang
94  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
95  * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
96  *
97  * 04 13 2010 wh.su
98  * [BORA00000680][MT6620] Support the statistic for Microsoft os query
99  * fixed the Klocwork error and refine the class error message.
100  *
101  * 03 03 2010 wh.su
102  * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
103  * move the AIS specific variable for security to AIS specific structure.
104  *
105  * 03 03 2010 wh.su
106  * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
107  * Fixed the pre-authentication timer not correctly init issue, and modify the security related callback function prototype.
108  *
109  * 03 01 2010 wh.su
110  * [BORA00000605][WIFISYS] Phase3 Integration
111  * Refine the variable and parameter for security.
112  *
113  * 01 27 2010 wh.su
114  * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
115  * add and fixed some security function.
116  *
117  * 01 13 2010 wh.su
118  * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
119  * fixed the compiling warning
120  *
121  * 12 18 2009 cm.chang
122  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
123  * .
124  *
125  * Dec 7 2009 mtk01088
126  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
127  * refine some code
128  *
129  * Dec 4 2009 mtk01088
130  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
131  * refine the code
132  *
133  * Dec 1 2009 mtk01088
134  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
135  * code refine
136  *
137  * Nov 23 2009 mtk01088
138  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
139  * adjust the function name
140  *
141  * Nov 19 2009 mtk01088
142  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
143  * adjust the state machine, to meet the firmware security design v1.1
144  *
145  * Nov 18 2009 mtk01088
146  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
147  *
148 **
149 */
150
151 /*******************************************************************************
152 *                         C O M P I L E R   F L A G S
153 ********************************************************************************
154 */
155
156 /*******************************************************************************
157 *                    E X T E R N A L   R E F E R E N C E S
158 ********************************************************************************
159 */
160 #include "precomp.h"
161
162 #if CFG_RSN_MIGRATION
163
164 /*******************************************************************************
165 *                              C O N S T A N T S
166 ********************************************************************************
167 */
168
169 /*******************************************************************************
170 *                             D A T A   T Y P E S
171 ********************************************************************************
172 */
173
174 /*******************************************************************************
175 *                            P U B L I C   D A T A
176 ********************************************************************************
177 */
178
179 /*******************************************************************************
180 *                           P R I V A T E   D A T A
181 ********************************************************************************
182 */
183 #if DBG
184 /*lint -save -e64 Type mismatch */
185 static PUINT_8 apucDebugSecState[SEC_STATE_NUM] = {
186     (PUINT_8)DISP_STRING("SEC_STATE_INIT"),
187     (PUINT_8)DISP_STRING("SEC_STATE_INITIATOR_PORT_BLOCKED"),
188     (PUINT_8)DISP_STRING("SEC_STATE_RESPONDER_PORT_BLOCKED"),
189     (PUINT_8)DISP_STRING("SEC_STATE_CHECK_OK"),
190     (PUINT_8)DISP_STRING("SEC_STATE_SEND_EAPOL"),
191     (PUINT_8)DISP_STRING("SEC_STATE_SEND_DEAUTH"),
192     (PUINT_8)DISP_STRING("SEC_STATE_COUNTERMEASURE"),
193 };
194 /*lint -restore */
195 #endif /* DBG */
196
197 /*******************************************************************************
198 *                                 M A C R O S
199 ********************************************************************************
200 */
201
202 /*******************************************************************************
203 *                   F U N C T I O N   D E C L A R A T I O N S
204 ********************************************************************************
205 */
206
207 /*******************************************************************************
208 *                              F U N C T I O N S
209 ********************************************************************************
210 */
211
212 /*----------------------------------------------------------------------------*/
213 /*!
214 * \brief This function will do initialization of Security FSM and all variables in
215 *        SEC_INFO_T.
216 *
217 * \param[in] prSta            Pointer to the STA record
218 *
219 * \return none
220 */
221 /*----------------------------------------------------------------------------*/
222 VOID
223 secFsmInit (
224     IN P_ADAPTER_T          prAdapter,
225     IN P_STA_RECORD_T       prSta
226     )
227 {
228     P_SEC_INFO_T            prSecInfo;
229     P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
230
231     ASSERT(prSta);
232
233     prSecInfo = &prSta->rSecInfo;
234
235     #if 1 /* MT6620 */
236     //At MT5921, is ok, but at MT6620, firmware base ASIC, the firmware
237     //will lost these data, thus, driver have to keep the wep material and
238     //setting to firmware while awake from D3.
239     #endif
240
241     prSecInfo->eCurrentState = SEC_STATE_INIT;
242
243     prSecInfo->fg2nd1xSend = FALSE;
244     prSecInfo->fgKeyStored = FALSE;
245
246     if (IS_STA_IN_AIS(prSta)) {
247         prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
248
249         prAisSpecBssInfo->u4RsnaLastMICFailTime = 0;
250         prAisSpecBssInfo->fgCheckEAPoLTxDone = FALSE;
251
252         cnmTimerInitTimer(prAdapter,
253                        &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaEAPoLReportTimeoutTimer,
254                        (PFN_MGMT_TIMEOUT_FUNC)secFsmEventEapolTxTimeout,
255                        (UINT_32)prSta);
256
257         cnmTimerInitTimer(prAdapter,
258                        &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaBlockTrafficTimer,
259                        (PFN_MGMT_TIMEOUT_FUNC)secFsmEventEndOfCounterMeasure,
260                        (UINT_32)prSta);
261
262     }
263     return;
264 }
265
266
267 /*----------------------------------------------------------------------------*/
268 /*!
269 * \brief This function will do uninitialization of Security FSM and all variables in
270 *        SEC_INFO_T.
271 *
272 * \param[in] prSta            Pointer to the STA record
273 *
274 * \return none
275 */
276 /*----------------------------------------------------------------------------*/
277 VOID /* whsu:Todo: */
278 secFsmUnInit (
279     IN P_ADAPTER_T          prAdapter,
280     IN P_STA_RECORD_T       prSta
281     )
282 {
283     P_SEC_INFO_T prSecInfo;
284
285     ASSERT(prSta);
286
287     prSecInfo = &prSta->rSecInfo;
288
289     prSecInfo->fg2nd1xSend = FALSE;
290     prSecInfo->fgKeyStored = FALSE;
291
292     //nicPrivacyRemoveWlanTable(prSta->ucWTEntry);
293
294     if (IS_STA_IN_AIS(prSta)) {
295         cnmTimerStopTimer(prAdapter,
296                        &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaEAPoLReportTimeoutTimer);
297         cnmTimerStopTimer(prAdapter,
298                        &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaBlockTrafficTimer);
299     }
300
301 }
302
303
304 /*----------------------------------------------------------------------------*/
305 /*!
306 * \brief This function will do action part while in STATE transition of
307 *        STANDBY to CHECK_OK.
308 *
309 * \param[in] prSta            Pointer to the Sta record
310 *
311 * \return - none
312 */
313 /*----------------------------------------------------------------------------*/
314 __KAL_INLINE__ VOID
315 secFsmTrans_INIT_to_CHECK_OK (
316     IN P_ADAPTER_T          prAdapter,
317     IN P_STA_RECORD_T       prSta
318     )
319 {
320     secSetPortBlocked(prAdapter, prSta, FALSE);
321
322     return;
323 }
324
325
326 /*----------------------------------------------------------------------------*/
327 /*!
328 * \brief This function will do action part while in STATE transition of
329 *        INIT to INITIATOR_PORT_BLOCKED.
330 *
331 * \param[in] prSta            Pointer to the Sta record
332 *
333 * \return - none
334 */
335 /*----------------------------------------------------------------------------*/
336 __KAL_INLINE__ VOID
337 secFsmTrans_INIT_to_INITIATOR_PORT_BLOCKED (
338     IN P_ADAPTER_T          prAdapter,
339     IN P_STA_RECORD_T       prSta
340     )
341 {
342
343     return;
344 }
345
346
347 /*----------------------------------------------------------------------------*/
348 /*!
349 * \brief This function will do action part while in STATE transition of
350 *        INIT to RESPONDER_PORT_BLOCKED.
351 *
352 * \param[in] prSta            Pointer to the Sta record
353 *
354 * \return - none
355 */
356 /*----------------------------------------------------------------------------*/
357 __KAL_INLINE__ VOID
358 secFsmTrans_INIT_to_RESPONDER_PORT_BLOCKED (
359     IN P_ADAPTER_T          prAdapter,
360     IN P_STA_RECORD_T       prSta
361     )
362 {
363     return;
364 }
365
366
367 /*----------------------------------------------------------------------------*/
368 /*!
369 * \brief This function will do action part while in STATE transition of
370 *        INITIATOR_PORT_BLOCKED to CHECK_OK.
371 *
372 * \param[in] prSta            Pointer to the Sta record
373 *
374 * \return - none
375 */
376 /*----------------------------------------------------------------------------*/
377 __KAL_INLINE__ VOID
378 secFsmTrans_INITIATOR_PORT_BLOCKED_to_CHECK_OK (
379     IN P_ADAPTER_T          prAdapter,
380     IN P_STA_RECORD_T       prSta
381     )
382 {
383     secSetPortBlocked(prAdapter, prSta, FALSE);
384     return;
385 }
386
387
388 /*----------------------------------------------------------------------------*/
389 /*!
390 * \brief This function will do action part while in STATE transition of
391 *        RESPONDER_PORT_BLOCKED to CHECK_OK.
392 *
393 * \param[in] prSta            Pointer to the Sta record
394 *
395 * \return - none
396 */
397 /*----------------------------------------------------------------------------*/
398 __KAL_INLINE__ VOID
399 secFsmTrans_RESPONDER_PORT_BLOCKED_to_CHECK_OK (
400     IN P_ADAPTER_T          prAdapter,
401     IN P_STA_RECORD_T       prSta
402     )
403 {
404     secSetPortBlocked(prAdapter, prSta, FALSE);
405     return;
406 }
407
408
409 /*----------------------------------------------------------------------------*/
410 /*!
411 * \brief This function will do action part while in STATE transition of
412 *        CHECK_OK to SEND_EAPOL
413 *
414 * \param[in] prSta            Pointer to the Sta record
415 *
416 * \return -
417 */
418 /*----------------------------------------------------------------------------*/
419 __KAL_INLINE__ VOID
420 secFsmTrans_CHECK_OK_to_SEND_EAPOL (
421     IN P_ADAPTER_T          prAdapter,
422     IN P_STA_RECORD_T       prSta
423     )
424 {
425
426     P_AIS_SPECIFIC_BSS_INFO_T prAisBssInfo;
427
428     ASSERT(prAdapter);
429
430     ASSERT(prSta);
431
432     prAisBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
433
434     ASSERT(prAisBssInfo);
435
436     if (!IS_STA_IN_AIS(prSta)) {
437         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
438         //ASSERT(0);
439         return;
440     }
441
442     prAisBssInfo->fgCheckEAPoLTxDone = TRUE;
443
444     //cnmTimerStartTimer(prAdapter,
445     //              &prAisBssInfo->rRsnaEAPoLReportTimeoutTimer,
446     //              SEC_TO_MSEC(EAPOL_REPORT_SEND_TIMEOUT_INTERVAL_SEC));
447
448     return;
449 }
450
451
452 /*----------------------------------------------------------------------------*/
453 /*!
454 * \brief This function will do action part while in STATE transition of
455 *        SEND_EAPOL to SEND_DEAUTH.
456 *
457 * \param[in] prSta            Pointer to the Sta record
458 *
459 * \return - none
460 */
461 /*----------------------------------------------------------------------------*/
462 __KAL_INLINE__ VOID
463 secFsmTrans_SEND_EAPOL_to_SEND_DEAUTH (
464     IN P_ADAPTER_T          prAdapter,
465     IN P_STA_RECORD_T       prSta
466     )
467 {
468
469     if (!IS_STA_IN_AIS(prSta)) {
470         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
471         //ASSERT(0);
472         return;
473     }
474
475     /* Compose deauth frame to AP, a call back function for tx done */
476     if (authSendDeauthFrame(prAdapter,
477                             prSta,
478                             (P_SW_RFB_T)NULL,
479                             REASON_CODE_MIC_FAILURE,
480                             (PFN_TX_DONE_HANDLER)secFsmEventDeauthTxDone) != WLAN_STATUS_SUCCESS) {
481         ASSERT(FALSE);
482     }
483 }
484
485
486 /*----------------------------------------------------------------------------*/
487 /*!
488 * \brief This function will do action part while in STATE transition of
489 *        SEND_DEAUTH to COUNTERMEASURE.
490 *
491 * \param[in] prSta            Pointer to the Sta record
492 *
493 * \return -
494 */
495 /*----------------------------------------------------------------------------*/
496 __KAL_INLINE__ VOID
497 secFsmTrans_SEND_DEAUTH_to_COUNTERMEASURE (
498     IN P_ADAPTER_T          prAdapter,
499     IN P_STA_RECORD_T       prSta
500     )
501 {
502     ASSERT(prAdapter);
503     ASSERT(prSta);
504
505     if (!IS_STA_IN_AIS(prSta)) {
506         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
507         //ASSERT(0);
508         return;
509     }
510
511     //Start the 60 sec timer
512     cnmTimerStartTimer(prAdapter,
513                 &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaBlockTrafficTimer,
514                 SEC_TO_MSEC(COUNTER_MEASURE_TIMEOUT_INTERVAL_SEC));
515     return;
516 }
517
518
519 /*----------------------------------------------------------------------------*/
520 /*!
521 * \brief This function will do action part while in STATE transition of
522 *        SEND_DEAUTH to COUNTERMEASURE.
523 *
524 * \param[in] prSta            Pointer to the Sta record
525 *
526 * \return -
527 */
528 /*----------------------------------------------------------------------------*/
529 __KAL_INLINE__ VOID
530 secFsmTrans_COUNTERMEASURE_to_INIT (
531     IN P_ADAPTER_T          prAdapter,
532     IN P_STA_RECORD_T       prSta
533     )
534 {
535
536     //Clear the counter measure flag
537     return;
538 }
539
540 /*----------------------------------------------------------------------------*/
541 /*!
542 * \brief The Core FSM engine of security module.
543 *
544 * \param[in] prSta            Pointer to the Sta record
545 * \param[in] eNextState    Enum value of next sec STATE
546 *
547 * \return -
548 */
549 /*----------------------------------------------------------------------------*/
550 VOID
551 secFsmSteps (
552     IN P_ADAPTER_T          prAdapter,
553     IN P_STA_RECORD_T       prSta,
554     IN ENUM_SEC_STATE_T     eNextState
555     )
556 {
557     P_SEC_INFO_T            prSecInfo;
558     BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
559
560     ASSERT(prSta);
561
562     prSecInfo = &prSta->rSecInfo;
563     ASSERT(prSecInfo);
564
565     DEBUGFUNC("secFsmSteps");
566     do {
567         /* Do entering Next State */
568         prSecInfo->ePreviousState = prSecInfo->eCurrentState;
569
570         /* Do entering Next State */
571 #if DBG
572         DBGLOG(RSN, STATE, ("\n"MACSTR" TRANSITION: [%s] -> [%s]\n\n",
573                             MAC2STR(prSta->aucMacAddr),
574                             apucDebugSecState[prSecInfo->eCurrentState],
575                             apucDebugSecState[eNextState]));
576 #else
577         DBGLOG(RSN, STATE, ("\n"MACSTR" [%d] TRANSITION: [%d] -> [%d]\n\n",
578                             MAC2STR(prSta->aucMacAddr),
579                             DBG_RSN_IDX,
580                             prSecInfo->eCurrentState,
581                             eNextState));
582 #endif
583         prSecInfo->eCurrentState = eNextState;
584
585         fgIsTransition = (BOOLEAN)FALSE;
586 #if 0
587         /* Do tasks of the State that we just entered */
588         switch (prSecInfo->eCurrentState) {
589         case SEC_STATE_INIT:
590         break;
591         case SEC_STATE_INITIATOR_PORT_BLOCKED:
592         break;
593         case SEC_STATE_RESPONDER_PORT_BLOCKED:
594         break;
595         case SEC_STATE_CHECK_OK:
596         break;
597         case SEC_STATE_SEND_EAPOL:
598         break;
599         case SEC_STATE_SEND_DEAUTH:
600         break;
601         case SEC_STATE_COUNTERMEASURE:
602         break;
603         default:
604             ASSERT(0); /* Make sure we have handle all STATEs */
605         break;
606         }
607 #endif
608     }
609     while (fgIsTransition);
610
611     return;
612
613 }
614
615
616 /*----------------------------------------------------------------------------*/
617 /*!
618 * \brief This function will do initialization of Security FSM and all variables in
619 *        SEC_INFO_T.
620 *
621 * \param[in] prSta            Pointer to the Sta record
622 *
623 * \return none
624 */
625 /*----------------------------------------------------------------------------*/
626 VOID
627 secFsmEventStart (
628     IN P_ADAPTER_T          prAdapter,
629     IN P_STA_RECORD_T       prSta
630     )
631 {
632     P_SEC_INFO_T            prSecInfo;
633     BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
634     ENUM_SEC_STATE_T        eNextState;
635
636     DBGLOG(RSN, TRACE, ("secFsmRunEventStart\n"));
637
638     ASSERT(prSta);
639
640     if (!prSta)
641         return;
642
643     if (!IS_STA_IN_AIS(prSta))
644         return;
645
646     DBGLOG(RSN, TRACE, ("secFsmRunEventStart for sta "MACSTR" network %d\n",
647         MAC2STR(prSta->aucMacAddr), prSta->ucNetTypeIndex));
648
649     prSecInfo = (P_SEC_INFO_T)&prSta->rSecInfo;
650
651     eNextState = prSecInfo->eCurrentState;
652
653     secSetPortBlocked(prAdapter, prSta, TRUE);
654
655     //prSta->fgTransmitKeyExist = FALSE;
656     //whsu:: nicPrivacySetStaDefaultWTIdx(prSta);
657
658 #if 1 /* Since the 1x and key can set to firmware in order, always enter the check ok state */
659     SEC_STATE_TRANSITION(prAdapter, prSta, INIT, CHECK_OK);
660 #else
661     if (IS_STA_IN_AIS(prSta->eStaType)) {
662         if (secRsnKeyHandshakeEnabled(prAdapter) == TRUE
663 #if CFG_SUPPORT_WAPI
664             || (prAdapter->rWifiVar.rConnSettings.fgWapiMode)
665 #endif
666             ) {
667             prSta->fgTransmitKeyExist = FALSE;
668             //nicPrivacyInitialize(prSta->ucNetTypeIndex);
669             SEC_STATE_TRANSITION(prAdapter, prSta, INIT, INITIATOR_PORT_BLOCKED);
670         }
671         else {
672             SEC_STATE_TRANSITION(prAdapter, prSta, INIT, CHECK_OK);
673         }
674     }
675 #if CFG_ENABLE_WIFI_DIRECT || CFG_ENABLE_BT_OVER_WIFI
676     #if CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_BT_OVER_WIFI
677     else if ((prSta->eStaType == STA_TYPE_BOW_CLIENT) ||
678         (prSta->eStaType == STA_TYPE_P2P_GC))
679     #elif CFG_ENABLE_WIFI_DIRECT
680     else if (prSta->eStaType == STA_TYPE_P2P_GC)
681     #elif CFG_ENABLE_BT_OVER_WIFI
682     else if (prSta->eStaType == STA_TYPE_BOW_CLIENT)
683     #endif
684     {
685         SEC_STATE_TRANSITION(prAdapter, prSta, INIT, RESPONDER_PORT_BLOCKED);
686     }
687 #endif
688     else {
689         SEC_STATE_TRANSITION(prAdapter, prSta, INIT, INITIATOR_PORT_BLOCKED);
690     }
691 #endif
692     if (prSecInfo->eCurrentState != eNextState) {
693         secFsmSteps(prAdapter, prSta, eNextState);
694     }
695
696     return;
697 } /* secFsmRunEventStart */
698
699
700 /*----------------------------------------------------------------------------*/
701 /*!
702 * \brief This function called by reset procedure to force the sec fsm enter
703 *        idle state
704 *
705 * \param[in] ucNetTypeIdx  The Specific Network type index
706 * \param[in] prSta         Pointer to the Sta record
707 *
708 * \return none
709 */
710 /*----------------------------------------------------------------------------*/
711 VOID
712 secFsmEventAbort (
713     IN P_ADAPTER_T          prAdapter,
714     IN P_STA_RECORD_T       prSta
715     )
716 {
717     P_SEC_INFO_T            prSecInfo;
718
719     DBGLOG(RSN, TRACE, ("secFsmEventAbort for sta "MACSTR" network %d\n",
720         MAC2STR(prSta->aucMacAddr), prSta->ucNetTypeIndex));
721
722     ASSERT(prSta);
723
724     if (!prSta)
725         return;
726
727     if (!IS_STA_IN_AIS(prSta))
728         return;
729
730     prSecInfo = (P_SEC_INFO_T)&prSta->rSecInfo;
731
732     prSta->fgTransmitKeyExist = FALSE;
733
734     secSetPortBlocked(prAdapter, prSta, TRUE);
735
736     if (prSecInfo == NULL)
737         return;
738
739     if (IS_STA_IN_AIS(prSta)) {
740
741         prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist = FALSE;
742
743         if (prSecInfo->eCurrentState == SEC_STATE_SEND_EAPOL) {
744             if (prAdapter->rWifiVar.rAisSpecificBssInfo.fgCheckEAPoLTxDone == FALSE) {
745                 DBGLOG(RSN, TRACE, ("EAPOL STATE not match the flag\n"));
746                 //cnmTimerStopTimer(prAdapter, &prAdapter->rWifiVar.rAisSpecificBssInfo.rRsnaEAPoLReportTimeoutTimer);
747             }
748         }
749     }
750     prSecInfo->eCurrentState = SEC_STATE_INIT;
751 }
752
753
754 /*----------------------------------------------------------------------------*/
755 /*!
756 * \brief This function will indicate an Event of "2nd EAPoL Tx is sending" to Sec FSM.
757 *
758 * \param[in] prSta            Pointer to the Sta record
759 *
760 * \return -
761 */
762 /*----------------------------------------------------------------------------*/
763 VOID
764 secFsmEvent2ndEapolTx (
765     IN P_ADAPTER_T          prAdapter,
766     IN P_STA_RECORD_T       prSta
767     )
768 {
769     P_SEC_INFO_T            prSecInfo;
770     ENUM_SEC_STATE_T        eNextState;
771     //BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
772
773     DEBUGFUNC("secFsmRunEvent2ndEapolTx");
774
775     ASSERT(prSta);
776
777     prSecInfo = &prSta->rSecInfo;
778     eNextState = prSecInfo->eCurrentState;
779
780 #if DBG
781     DBGLOG(RSN, TRACE, (MACSTR" Sec state %s\n", MAC2STR(prSta->aucMacAddr),
782         apucDebugSecState[prSecInfo->eCurrentState]));
783 #else
784     DBGLOG(RSN, TRACE, (MACSTR" Sec state [%d]\n", MAC2STR(prSta->aucMacAddr), prSecInfo->eCurrentState));
785 #endif
786
787     switch(prSecInfo->eCurrentState) {
788     case SEC_STATE_INITIATOR_PORT_BLOCKED :
789     case SEC_STATE_CHECK_OK :
790         prSecInfo->fg2nd1xSend = TRUE;
791         break;
792     default:
793 #if DBG
794         DBGLOG(RSN, WARN, ("Rcv 2nd EAPoL at %s\n", apucDebugSecState[prSecInfo->eCurrentState]));
795 #else
796         DBGLOG(RSN, WARN, ("Rcv 2nd EAPoL at [%d]\n", prSecInfo->eCurrentState));
797 #endif
798         break;
799     }
800
801     if (prSecInfo->eCurrentState != eNextState) {
802         secFsmSteps(prAdapter, prSta, eNextState);
803     }
804
805     return;
806
807 }/* secFsmRunEvent2ndEapolTx */
808
809
810 /*----------------------------------------------------------------------------*/
811 /*!
812 * \brief This function will indicate an Event of "4th EAPoL Tx is Tx done" to Sec FSM.
813 *
814 * \param[in] prSta            Pointer to the Sta record
815 *
816 * \return -
817 */
818 /*----------------------------------------------------------------------------*/
819 VOID
820 secFsmEvent4ndEapolTxDone (
821     IN P_ADAPTER_T          prAdapter,
822     IN P_STA_RECORD_T       prSta
823     )
824 {
825     P_SEC_INFO_T            prSecInfo;
826     ENUM_SEC_STATE_T        eNextState;
827     BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
828     P_CMD_802_11_KEY        prStoredKey;
829
830     DEBUGFUNC("secFsmRunEvent4ndEapolTx");
831
832     ASSERT(prSta);
833
834     prSecInfo = &prSta->rSecInfo;
835     eNextState = prSecInfo->eCurrentState;
836
837 #if DBG
838     DBGLOG(RSN, TRACE, (MACSTR " Sec state %s\n", MAC2STR(prSta->aucMacAddr),
839         apucDebugSecState[prSecInfo->eCurrentState]));
840 #else
841     DBGLOG(RSN, TRACE, (MACSTR " Sec state [%d]\n", MAC2STR(prSta->aucMacAddr), prSecInfo->eCurrentState));
842 #endif
843
844     switch(prSecInfo->eCurrentState) {
845     case SEC_STATE_INITIATOR_PORT_BLOCKED :
846     case SEC_STATE_CHECK_OK :
847         prSecInfo->fg2nd1xSend = FALSE;
848         if (prSecInfo->fgKeyStored) {
849             prStoredKey = (P_CMD_802_11_KEY)prSecInfo->aucStoredKey;
850
851             //prSta = rxmLookupStaRecIndexFromTA(prStoredKey->aucPeerAddr);
852             //if (nicPrivacySetKeyEntry(prStoredKey, prSta->ucWTEntry) == FALSE)
853             //    DBGLOG(RSN, WARN, ("nicPrivacySetKeyEntry() fail,..\n"));
854
855             //key update
856             prSecInfo->fgKeyStored = FALSE;
857             prSta->fgTransmitKeyExist = TRUE;
858         }
859         if (prSecInfo->eCurrentState == SEC_STATE_INITIATOR_PORT_BLOCKED) {
860             SEC_STATE_TRANSITION(prAdapter, prSta, INITIATOR_PORT_BLOCKED, CHECK_OK);
861         }
862         break;
863     default:
864
865 #if DBG
866         DBGLOG(RSN, WARN, ("Rcv thh EAPoL Tx done at %s\n", apucDebugSecState[prSecInfo->eCurrentState]));
867 #else
868         DBGLOG(RSN, WARN, ("Rcv thh EAPoL Tx done at [%d]\n", prSecInfo->eCurrentState));
869 #endif
870         break;
871     }
872
873     if (prSecInfo->eCurrentState != eNextState) {
874         secFsmSteps(prAdapter, prSta, eNextState);
875     }
876
877     return;
878
879 }/* secFsmRunEvent4ndEapolTx */
880
881
882 /*----------------------------------------------------------------------------*/
883 /*!
884 * \brief This function will indicate an Event of "Pairwise key installed" to SEC FSM.
885 *
886 * \param[in] prSta            Pointer to the Sta record
887 *
888 * \retval TRUE The key can be installed to HW
889 * \retval FALSE The kay conflict with the current key, abort it
890 */
891 /*----------------------------------------------------------------------------*/
892 BOOLEAN
893 secFsmEventPTKInstalled (
894     IN P_ADAPTER_T          prAdapter,
895     IN P_STA_RECORD_T       prSta
896     )
897 {
898     P_SEC_INFO_T            prSecInfo;
899     ENUM_SEC_STATE_T        eNextState;
900     BOOLEAN                 fgStatus = TRUE;
901     BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
902
903     ASSERT(prSta);
904
905     prSecInfo = &prSta->rSecInfo;
906     if (prSecInfo == NULL)
907         return TRUE; /* Not PTK */
908
909 #if DBG
910     DBGLOG(RSN, TRACE, (MACSTR " Sec state %s\n", MAC2STR(prSta->aucMacAddr),
911         apucDebugSecState[prSecInfo->eCurrentState]));
912 #else
913     DBGLOG(RSN, TRACE, (MACSTR " Sec state [%d]\n", MAC2STR(prSta->aucMacAddr), prSecInfo->eCurrentState));
914 #endif
915
916     eNextState = prSecInfo->eCurrentState;
917
918     switch(prSecInfo->eCurrentState) {
919     case SEC_STATE_INIT:
920         /* Legacy wep, wpa-none */
921         break;
922
923     case SEC_STATE_INITIATOR_PORT_BLOCKED:
924         if (prSecInfo->fg2nd1xSend) {
925         }
926         else {
927             SEC_STATE_TRANSITION(prAdapter, prSta, INITIATOR_PORT_BLOCKED, CHECK_OK);
928         }
929         break;
930
931     case SEC_STATE_RESPONDER_PORT_BLOCKED:
932         SEC_STATE_TRANSITION(prAdapter, prSta, RESPONDER_PORT_BLOCKED, CHECK_OK);
933         break;
934
935
936     case SEC_STATE_CHECK_OK:
937         break;
938
939     default:
940         fgStatus = FALSE;
941         break;
942     }
943
944     if (prSecInfo->eCurrentState != eNextState) {
945         secFsmSteps(prAdapter, prSta, eNextState);
946     }
947
948     return fgStatus;
949
950 } /* end of secFsmRunEventPTKInstalled() */
951
952
953 /*----------------------------------------------------------------------------*/
954 /*!
955 * \brief This function will indicate an Event of "Counter Measure" to SEC FSM.
956 *
957 * \param[in] prSta            Pointer to the Sta record
958 *
959 * \return -
960 */
961 /*----------------------------------------------------------------------------*/
962 VOID
963 secFsmEventStartCounterMeasure (
964     IN P_ADAPTER_T          prAdapter,
965     IN P_STA_RECORD_T       prSta
966     )
967 {
968     P_SEC_INFO_T            prSecInfo;
969     ENUM_SEC_STATE_T        eNextState;
970     BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
971
972     DEBUGFUNC("secFsmRunEventStartCounterMeasure");
973
974     ASSERT(prSta);
975
976     if (!IS_STA_IN_AIS(prSta)) {
977         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
978         //ASSERT(0);
979         return;
980     }
981
982     prSecInfo = &prSta->rSecInfo;
983
984     eNextState = prSecInfo->eCurrentState;
985
986 #if DBG
987     DBGLOG(RSN, TRACE, (MACSTR " Sec state %s\n", MAC2STR(prSta->aucMacAddr),
988         apucDebugSecState[prSecInfo->eCurrentState]));
989 #else
990     DBGLOG(RSN, TRACE, (MACSTR " Sec state [%d]\n", MAC2STR(prSta->aucMacAddr), prSecInfo->eCurrentState));
991 #endif
992
993     prAdapter->rWifiVar.rAisSpecificBssInfo.u4RsnaLastMICFailTime = 0;
994
995     switch(prSecInfo->eCurrentState) {
996     case SEC_STATE_CHECK_OK:
997         {
998             prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure = TRUE;
999
1000             //<Todo> dls port control
1001             SEC_STATE_TRANSITION(prAdapter, prSta, CHECK_OK, SEND_EAPOL);
1002         }
1003         break;
1004
1005     default:
1006         break;
1007     }
1008
1009     /* Call arbFsmSteps() when we are going to change ARB STATE */
1010     if (prSecInfo->eCurrentState != eNextState) {
1011         secFsmSteps(prAdapter, prSta, eNextState);
1012     }
1013
1014     return;
1015
1016 } /* secFsmRunEventStartCounterMeasure */
1017
1018
1019 /*----------------------------------------------------------------------------*/
1020 /*!
1021 * \brief This function will indicate an Event of "802.1x EAPoL Tx Done" to Sec FSM.
1022 *
1023 * \param[in] prSta            Pointer to the Sta record
1024 *
1025 * \return -
1026 */
1027 /*----------------------------------------------------------------------------*/
1028 VOID
1029 secFsmEventEapolTxDone (
1030     IN P_ADAPTER_T            prAdapter,
1031     IN P_STA_RECORD_T         prStaRec,
1032     IN ENUM_TX_RESULT_CODE_T  rTxDoneStatus
1033     )
1034 {
1035     P_SEC_INFO_T              prSecInfo;
1036     ENUM_SEC_STATE_T          eNextState;
1037     BOOLEAN                   fgIsTransition = (BOOLEAN)FALSE;
1038     P_AIS_SPECIFIC_BSS_INFO_T prAisBssInfo;
1039
1040     DEBUGFUNC("secFsmRunEventEapolTxDone");
1041
1042     ASSERT(prStaRec);
1043
1044     if (rTxDoneStatus != TX_RESULT_SUCCESS) {
1045         DBGLOG(RSN, INFO, ("Error EAPoL fram fail to send!!\n"));
1046         //ASSERT(0);
1047         return;
1048     }
1049
1050     if (!IS_STA_IN_AIS(prStaRec)) {
1051         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
1052         //ASSERT(0);
1053         return;
1054     }
1055
1056     prAisBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
1057
1058     ASSERT(prAisBssInfo);
1059
1060     prSecInfo = &prStaRec->rSecInfo;
1061     eNextState = prSecInfo->eCurrentState;
1062
1063 #if DBG
1064     DBGLOG(RSN, TRACE, (MACSTR " Sec state %s\n", MAC2STR(prStaRec->aucMacAddr),
1065         apucDebugSecState[prSecInfo->eCurrentState]));
1066 #else
1067     DBGLOG(RSN, TRACE, (MACSTR " Sec state [%d]\n", MAC2STR(prStaRec->aucMacAddr), prSecInfo->eCurrentState));
1068 #endif
1069
1070     switch(prSecInfo->eCurrentState) {
1071     case SEC_STATE_SEND_EAPOL:
1072         if (prAisBssInfo->fgCheckEAPoLTxDone == FALSE) {
1073             ASSERT(0);
1074         }
1075
1076         prAisBssInfo->fgCheckEAPoLTxDone = FALSE;
1077         //cnmTimerStopTimer(prAdapter, &prAisBssInfo->rRsnaEAPoLReportTimeoutTimer);
1078
1079         SEC_STATE_TRANSITION(prAdapter, prStaRec, SEND_EAPOL, SEND_DEAUTH);
1080         break;
1081     default:
1082         break;
1083     }
1084
1085     if (prSecInfo->eCurrentState != eNextState) {
1086         secFsmSteps(prAdapter, prStaRec, eNextState);
1087     }
1088
1089     return;
1090
1091 }/* secFsmRunEventEapolTxDone */
1092
1093
1094 /*----------------------------------------------------------------------------*/
1095 /*!
1096 * \brief This function will indicate an Event of "Deauth frame Tx Done" to Sec FSM.
1097 *
1098 * \param[in] pMsduInfo            Pointer to the Msdu Info
1099 * \param[in] rStatus              The Tx done status
1100 *
1101 * \return -
1102 *
1103 * \note after receive deauth frame, callback function call this
1104 */
1105 /*----------------------------------------------------------------------------*/
1106 VOID
1107 secFsmEventDeauthTxDone (
1108     IN P_ADAPTER_T            prAdapter,
1109     IN P_MSDU_INFO_T          prMsduInfo,
1110     IN ENUM_TX_RESULT_CODE_T  rTxDoneStatus
1111     )
1112 {
1113     P_STA_RECORD_T            prStaRec;
1114     P_SEC_INFO_T              prSecInfo;
1115     ENUM_SEC_STATE_T          eNextState;
1116     BOOLEAN                   fgIsTransition = (BOOLEAN)FALSE;
1117
1118     DEBUGFUNC("secFsmRunEventDeauthTxDone");
1119
1120     ASSERT(prMsduInfo);
1121
1122     prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
1123
1124     ASSERT(prStaRec);
1125
1126     if (!prStaRec)
1127         return;
1128
1129     if (!IS_STA_IN_AIS(prStaRec)) {
1130         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
1131         //ASSERT(0);
1132         return;
1133     }
1134
1135     prSecInfo = (P_SEC_INFO_T)&prStaRec->rSecInfo;
1136
1137 #if DBG
1138     DBGLOG(RSN, TRACE, (MACSTR " Sec state %s\n", MAC2STR(prStaRec->aucMacAddr),
1139         apucDebugSecState[prSecInfo->eCurrentState]));
1140 #else
1141     DBGLOG(RSN, TRACE, (MACSTR " Sec state [%d]\n", MAC2STR(prStaRec->aucMacAddr), prSecInfo->eCurrentState));
1142 #endif
1143
1144     switch(prSecInfo->eCurrentState) {
1145     case SEC_STATE_SEND_DEAUTH:
1146
1147         DBGLOG(RSN, TRACE, ("Set timer %d\n", COUNTER_MEASURE_TIMEOUT_INTERVAL_SEC));
1148
1149         SEC_STATE_TRANSITION(prAdapter, prStaRec, SEND_DEAUTH, COUNTERMEASURE);
1150
1151         break;
1152
1153     default:
1154         ASSERT(0);
1155         break;
1156     }
1157
1158     return;
1159 }/* secFsmRunEventDeauthTxDone */
1160
1161
1162 /*----------------------------------------------------------------------------*/
1163 /*!
1164 * \brief This function will check the eapol error frame fail to send issue.
1165 *
1166 * \param[in] prSta            Pointer to the Sta record
1167 *
1168 * \return -
1169 */
1170 /*----------------------------------------------------------------------------*/
1171 VOID
1172 secFsmEventEapolTxTimeout (
1173     IN P_ADAPTER_T            prAdapter,
1174     IN UINT_32                u4Parm
1175     )
1176 {
1177     P_STA_RECORD_T            prStaRec;
1178
1179     DEBUGFUNC("secFsmRunEventEapolTxTimeout");
1180
1181     prStaRec = (P_STA_RECORD_T)u4Parm;
1182
1183     ASSERT(prStaRec);
1184
1185     /* Todo:: How to handle the Eapol Error fail to send case? */
1186     ASSERT(0);
1187
1188     return;
1189
1190 }/* secFsmEventEapolTxTimeout */
1191
1192
1193 /*----------------------------------------------------------------------------*/
1194 /*!
1195 * \brief This function will stop the counterMeasure duration.
1196 *
1197 * \param[in] prSta            Pointer to the Sta record
1198 *
1199 * \return -
1200 */
1201 /*----------------------------------------------------------------------------*/
1202 VOID
1203 secFsmEventEndOfCounterMeasure (
1204     IN P_ADAPTER_T          prAdapter,
1205     UINT_32                 u4Parm
1206     )
1207 {
1208     P_STA_RECORD_T          prSta;
1209     P_SEC_INFO_T            prSecInfo;
1210     ENUM_SEC_STATE_T        eNextState;
1211     BOOLEAN                 fgIsTransition = (BOOLEAN)FALSE;
1212
1213     DEBUGFUNC("secFsmRunEventEndOfCounterMeasure");
1214
1215     prSta = (P_STA_RECORD_T)u4Parm;
1216
1217     ASSERT(prSta);
1218
1219     if (!IS_STA_IN_AIS(prSta)) {
1220         DBGLOG(RSN, INFO, ("Counter Measure should occur at AIS network!!\n"));
1221         //ASSERT(0);
1222         return;
1223     }
1224
1225     prSecInfo = &prSta->rSecInfo;
1226     eNextState = prSecInfo->eCurrentState;
1227
1228 #if DBG
1229     DBGLOG(RSN, TRACE, (MACSTR " Sec state %s\n", MAC2STR(prSta->aucMacAddr),
1230         apucDebugSecState[prSecInfo->eCurrentState]));
1231 #else
1232     DBGLOG(RSN, TRACE, (MACSTR " Sec state [%d]\n", MAC2STR(prSta->aucMacAddr), prSecInfo->eCurrentState));
1233 #endif
1234
1235     switch(prSecInfo->eCurrentState) {
1236     case SEC_STATE_SEND_DEAUTH:
1237         {
1238             prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure = FALSE;
1239
1240             SEC_STATE_TRANSITION(prAdapter, prSta, COUNTERMEASURE, INIT);
1241         }
1242         break;
1243
1244     default:
1245         ASSERT(0);
1246     }
1247
1248     /* Call arbFsmSteps() when we are going to change ARB STATE */
1249     if (prSecInfo->eCurrentState != eNextState) {
1250         secFsmSteps(prAdapter, prSta, eNextState);
1251     }
1252
1253     return;
1254 }/* end of secFsmRunEventEndOfCounterMeasure */
1255 #endif