add rk3288 pinctrl dts code
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / combo_mt66xx / mt6628 / wlan / mgmt / aaa_fsm.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/aaa_fsm.c#2 $
3 */
4
5 /*! \file   "aaa_fsm.c"
6     \brief  This file defines the FSM for AAA MODULE.
7
8     This file defines the FSM for AAA MODULE.
9 */
10
11
12
13 /*
14 ** $Log: aaa_fsm.c $
15  *
16  * 07 17 2012 yuche.tsai
17  * NULL
18  * Compile no error before trial run.
19  *
20  * 06 13 2012 yuche.tsai
21  * NULL
22  * Update maintrunk driver.
23  * Add support for driver compose assoc request frame.
24  *
25  * 03 02 2012 terry.wu
26  * NULL
27  * Sync CFG80211 modification from branch 2,2.
28  *
29  * 02 22 2012 yuche.tsai
30  * NULL
31  * Solve sigma test 5.1.3 issue, assoc response should have P2P IE.
32  *
33  * 12 02 2011 yuche.tsai
34  * NULL
35  * Resolve inorder issue under AP mode.
36  * 
37  * data frame may TX before assoc response frame.
38  *
39  * 11 18 2011 yuche.tsai
40  * NULL
41  * CONFIG P2P support RSSI query, default turned off.
42  *
43  * 06 17 2011 terry.wu
44  * NULL
45  * Add BoW 11N support.
46  *
47  * 06 02 2011 eddie.chen
48  * [WCXRP00000759] [MT6620 Wi-Fi][DRV] Update RCPI in AAA
49  * Update RCPI when receiving Assoc request.
50  *
51  * 04 21 2011 terry.wu
52  * [WCXRP00000674] [MT6620 Wi-Fi][Driver] Refine AAA authSendAuthFrame
53  * Add network type parameter to authSendAuthFrame.
54  *
55  * 04 15 2011 chinghwa.yu
56  * [WCXRP00000065] Update BoW design and settings
57  * Add BOW short range mode.
58  *
59  * 04 09 2011 chinghwa.yu
60  * [WCXRP00000065] Update BoW design and settings
61  * Change Link connection event procedure and change skb length check to 1512 bytes.
62  *
63  * 03 09 2011 wh.su
64  * [WCXRP00000530] [MT6620 Wi-Fi] [Driver] skip doing p2pRunEventAAAComplete after send assoc response Tx Done
65  * Skip to call p2pRunEventAAAComplete to avoid indicate STA connect twice.
66  *
67  * 03 04 2011 terry.wu
68  * [WCXRP00000515] [MT6620 Wi-Fi][Driver] Surpress compiler warning which is identified by GNU compiler collection
69  * Remove unused variable.
70  *
71  * 02 16 2011 yuche.tsai
72  * [WCXRP00000429] [Volunteer Patch][MT6620][Driver] Hot Spot Client Limit Issue
73  * Add more check after RX assoc frame under Hot-Spot mode.
74  *
75  * 02 09 2011 yuche.tsai
76  * [WCXRP00000429] [Volunteer Patch][MT6620][Driver] Hot Spot Client Limit Issue
77  * Fix Client Limit Issue.
78  *
79  * 01 25 2011 yuche.tsai
80  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
81  * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
82  *
83  * 01 15 2011 puff.wen
84  * NULL
85  * [On behalf of Frog] Add CFG_ENABLE_WIFI_DIRECT to p2pRunEventAAAComplete
86  *
87  * 01 14 2011 yuche.tsai
88  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
89  * Modify AAA flow according to CM's comment.
90  *
91  * 09 03 2010 kevin.huang
92  * NULL
93  * Refine #include sequence and solve recursive/nested #include issue
94  *
95  * 08 29 2010 yuche.tsai
96  * NULL
97  * Fix Compile warning, type cast from UINT_32 to UINT_16.
98  *
99  * 08 26 2010 yuche.tsai
100  * NULL
101  * In P2P AT GO test mode under WinXP, we would not indicate connected event to host.
102  *
103  * 08 24 2010 cm.chang
104  * NULL
105  * Support RLM initail channel of Ad-hoc, P2P and BOW
106  *
107  * 08 23 2010 chinghwa.yu
108  * NULL
109  * Update for BOW.
110  *
111  * 08 20 2010 kevin.huang
112  * NULL
113  * Modify AAA Module for changing STA STATE 3 at p2p/bowRunEventAAAComplete()
114  *
115  * 08 17 2010 yuche.tsai
116  * NULL
117  * Fix bug while enabling P2P GO.
118  *
119  * 08 16 2010 kevin.huang
120  * NULL
121  * Refine AAA functions
122  *
123  * 07 08 2010 cp.wu
124  *
125  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
126  *
127  * 06 21 2010 cp.wu
128  * [WPD00003833][MT6620 and MT5931] Driver migration
129  * refine TX-DONE callback.
130  *
131  * 06 21 2010 yuche.tsai
132  * [WPD00003839][MT6620 5931][P2P] Feature migration
133  * modify due to P2P functino call prototype change.
134  *
135  * 06 17 2010 yuche.tsai
136  * [WPD00003839][MT6620 5931][P2P] Feature migration
137  * First draft for migration P2P FSM from FW to Driver.
138  *
139  * 04 02 2010 kevin.huang
140  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
141  * Modify CFG flags
142  *
143  * 02 26 2010 kevin.huang
144  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
145  * add support of Driver STA_RECORD_T activation
146  *
147  * 02 04 2010 kevin.huang
148  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
149  * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
150 */
151
152 /*******************************************************************************
153 *                         C O M P I L E R   F L A G S
154 ********************************************************************************
155 */
156
157 /*******************************************************************************
158 *                    E X T E R N A L   R E F E R E N C E S
159 ********************************************************************************
160 */
161 #include "precomp.h"
162
163 /*******************************************************************************
164 *                              C O N S T A N T S
165 ********************************************************************************
166 */
167
168 /*******************************************************************************
169 *                             D A T A   T Y P E S
170 ********************************************************************************
171 */
172
173 /*******************************************************************************
174 *                            P U B L I C   D A T A
175 ********************************************************************************
176 */
177
178 /*******************************************************************************
179 *                           P R I V A T E   D A T A
180 ********************************************************************************
181 */
182
183 /*******************************************************************************
184 *                                 M A C R O S
185 ********************************************************************************
186 */
187
188 /*******************************************************************************
189 *                   F U N C T I O N   D E C L A R A T I O N S
190 ********************************************************************************
191 */
192
193 /*******************************************************************************
194 *                              F U N C T I O N S
195 ********************************************************************************
196 */
197 #if 0
198 /*----------------------------------------------------------------------------*/
199 /*!
200 * @brief This function will send Event to AIS/BOW/P2P
201 *
202 * @param[in] rJoinStatus        To indicate JOIN success or failure.
203 * @param[in] prStaRec           Pointer to the STA_RECORD_T
204 * @param[in] prSwRfb            Pointer to the SW_RFB_T
205
206 * @return none
207 */
208 /*----------------------------------------------------------------------------*/
209 WLAN_STATUS
210 aaaFsmSendEventJoinComplete (
211     WLAN_STATUS rJoinStatus,
212     P_STA_RECORD_T prStaRec,
213     P_SW_RFB_T prSwRfb
214     )
215 {
216     P_MSG_SAA_JOIN_COMP_T prJoinCompMsg;
217
218
219     ASSERT(prStaRec);
220
221     prJoinCompMsg = cnmMemAlloc(RAM_TYPE_TCM, sizeof(MSG_SAA_JOIN_COMP_T));
222     if (!prJoinCompMsg) {
223         return WLAN_STATUS_RESOURCES;
224     }
225
226     if (IS_STA_IN_AIS(prStaRec)) {
227         prJoinCompMsg->rMsgHdr.eMsgId = MID_SAA_AIS_JOIN_COMPLETE;
228     }
229     else if (IS_STA_IN_P2P(prStaRec)) {
230         prJoinCompMsg->rMsgHdr.eMsgId = MID_SAA_P2P_JOIN_COMPLETE;
231     }
232     else if (IS_STA_IN_BOW(prStaRec)) {
233         prJoinCompMsg->rMsgHdr.eMsgId = MID_SAA_BOW_JOIN_COMPLETE;
234     }
235     else {
236         ASSERT(0);
237     }
238
239     prJoinCompMsg->rJoinStatus = rJoinStatus;
240     prJoinCompMsg->prStaRec = prStaRec;
241     prJoinCompMsg->prSwRfb = prSwRfb;
242
243     mboxSendMsg(MBOX_ID_0,
244                 (P_MSG_HDR_T)prJoinCompMsg,
245                 MSG_SEND_METHOD_BUF);
246
247     return WLAN_STATUS_SUCCESS;
248
249 } /* end of saaFsmSendEventJoinComplete() */
250
251 /*----------------------------------------------------------------------------*/
252 /*!
253 * @brief This function will handle the Start Event to AAA FSM.
254 *
255 * @param[in] prMsgHdr   Message of Join Request for a particular STA.
256 *
257 * @return none
258 */
259 /*----------------------------------------------------------------------------*/
260 VOID
261 aaaFsmRunEventStart (
262     IN P_MSG_HDR_T prMsgHdr
263     )
264 {
265     P_MSG_SAA_JOIN_REQ_T prJoinReqMsg;
266     P_STA_RECORD_T prStaRec;
267     P_AIS_BSS_INFO_T prAisBssInfo;
268
269
270     ASSERT(prMsgHdr);
271
272     prJoinReqMsg = (P_MSG_SAA_JOIN_REQ_T)prMsgHdr;
273     prStaRec = prJoinReqMsg->prStaRec;
274
275     ASSERT(prStaRec);
276
277     DBGLOG(SAA, LOUD, ("EVENT-START: Trigger SAA FSM\n"));
278
279     cnmMemFree(prMsgHdr);
280
281     //4 <1> Validation of SAA Start Event
282     if (!IS_AP_STA(prStaRec->eStaType)) {
283
284         DBGLOG(SAA, ERROR, ("EVENT-START: STA Type - %d was not supported.\n", prStaRec->eStaType));
285
286         /* Ignore the return value because don't care the prSwRfb */
287         saaFsmSendEventJoinComplete(WLAN_STATUS_FAILURE, prStaRec, NULL);
288
289         return;
290     }
291
292     //4 <2> The previous JOIN process is not completed ?
293     if (prStaRec->eAuthAssocState != AA_STATE_IDLE) {
294         DBGLOG(SAA, ERROR, ("EVENT-START: Reentry of SAA Module.\n"));
295         prStaRec->eAuthAssocState = AA_STATE_IDLE;
296     }
297
298     //4 <3> Reset Status Code and Time
299     /* Update Station Record - Status/Reason Code */
300     prStaRec->u2StatusCode = STATUS_CODE_SUCCESSFUL;
301
302     /* Update the record join time. */
303     GET_CURRENT_SYSTIME(&prStaRec->rLastJoinTime);
304
305     prStaRec->ucTxAuthAssocRetryCount = 0;
306
307     if (prStaRec->prChallengeText) {
308         cnmMemFree(prStaRec->prChallengeText);
309         prStaRec->prChallengeText = (P_IE_CHALLENGE_TEXT_T)NULL;
310     }
311
312     cnmTimerStopTimer(&prStaRec->rTxReqDoneOrRxRespTimer);
313
314     prStaRec->ucStaState = STA_STATE_1;
315
316     /* Trigger SAA MODULE */
317     saaFsmSteps(prStaRec, SAA_STATE_SEND_AUTH1, (P_SW_RFB_T)NULL);
318
319     return;
320 } /* end of saaFsmRunEventStart() */
321 #endif
322
323
324 #if CFG_SUPPORT_AAA
325 /*----------------------------------------------------------------------------*/
326 /*!
327 * @brief This function will process the Rx Auth Request Frame and then
328 *        trigger AAA FSM.
329 *
330 * @param[in] prAdapter          Pointer to the Adapter structure.
331 * @param[in] prSwRfb            Pointer to the SW_RFB_T structure.
332 *
333 * @return (none)
334 */
335 /*----------------------------------------------------------------------------*/
336 VOID
337 aaaFsmRunEventRxAuth (
338     IN P_ADAPTER_T prAdapter,
339     IN P_SW_RFB_T prSwRfb
340     )
341 {
342     P_BSS_INFO_T prBssInfo;
343     P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
344     UINT_16 u2StatusCode;
345     BOOLEAN fgReplyAuth = FALSE;
346     ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex;
347
348
349     ASSERT(prAdapter);
350
351     do {
352
353
354         //4 <1> Check P2P network conditions
355 #if CFG_ENABLE_WIFI_DIRECT
356         if(prAdapter->fgIsP2PRegistered){
357             prBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
358
359             if (prBssInfo->fgIsNetActive) {
360
361                 //4 <1.1> Validate Auth Frame by Auth Algorithm/Transation Seq
362                 if (WLAN_STATUS_SUCCESS ==
363                     authProcessRxAuth1Frame(prAdapter,
364                                             prSwRfb,
365                                             prBssInfo->aucBSSID,
366                                             AUTH_ALGORITHM_NUM_OPEN_SYSTEM,
367                                             AUTH_TRANSACTION_SEQ_1,
368                                             &u2StatusCode)) {
369
370                     if (STATUS_CODE_SUCCESSFUL == u2StatusCode) {
371                         //4 <1.2> Validate Auth Frame for Network Specific Conditions
372                         fgReplyAuth = p2pFuncValidateAuth(
373                                             prAdapter,
374                                             prSwRfb,
375                                             &prStaRec,
376                                             &u2StatusCode);
377                     }
378                     else {
379                         fgReplyAuth = TRUE;
380                     }
381                     eNetTypeIndex = NETWORK_TYPE_P2P_INDEX;
382                     break;
383                 }
384             }
385         }
386 #endif /* CFG_ENABLE_WIFI_DIRECT */
387
388         //4 <2> Check BOW network conditions
389 #if CFG_ENABLE_BT_OVER_WIFI
390         {
391             prBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_BOW_INDEX]);
392
393             if ((prBssInfo->fgIsNetActive) &&
394             (OP_MODE_BOW == prBssInfo->eCurrentOPMode)) {
395
396                 //4 <2.1> Validate Auth Frame by Auth Algorithm/Transation Seq
397                 /* Check if for this BSSID */
398                 if (WLAN_STATUS_SUCCESS ==
399                     authProcessRxAuth1Frame(prAdapter,
400                                             prSwRfb,
401                                             prBssInfo->aucBSSID,
402                                             AUTH_ALGORITHM_NUM_OPEN_SYSTEM,
403                                             AUTH_TRANSACTION_SEQ_1,
404                                             &u2StatusCode)) {
405
406                     if (STATUS_CODE_SUCCESSFUL == u2StatusCode) {
407
408                         //4 <2.2> Validate Auth Frame for Network Specific Conditions
409                         fgReplyAuth = bowValidateAuth(prAdapter, prSwRfb, &prStaRec, &u2StatusCode);
410
411                     }
412                     else {
413
414                         fgReplyAuth = TRUE;
415                     }
416                     eNetTypeIndex = NETWORK_TYPE_BOW_INDEX;
417                     /* TODO(Kevin): Allocate a STA_RECORD_T for new client */
418                     break;
419                 }
420             }
421         }
422 #endif /* CFG_ENABLE_BT_OVER_WIFI */
423
424         return;
425     } while (FALSE);
426
427     if(prStaRec) {
428         /* update RCPI */
429         prStaRec->ucRCPI = prSwRfb->prHifRxHdr->ucRcpi;
430     }
431
432     //4 <3> Update STA_RECORD_T and reply Auth_2(Response to Auth_1) Frame
433     if (fgReplyAuth) {
434
435         if (prStaRec) {
436
437             if (u2StatusCode == STATUS_CODE_SUCCESSFUL) {
438                 if (prStaRec->eAuthAssocState != AA_STATE_IDLE) {
439                     DBGLOG(AAA, WARN, ("Previous AuthAssocState (%d) != IDLE.\n",
440                         prStaRec->eAuthAssocState));
441                 }
442
443                 prStaRec->eAuthAssocState = AAA_STATE_SEND_AUTH2;
444             }
445             else {
446                 prStaRec->eAuthAssocState = AA_STATE_IDLE;
447
448                 /* NOTE(Kevin): Change to STATE_1 */
449                 cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_1);
450             }
451
452             /* Update the record join time. */
453             GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
454
455             /* Update Station Record - Status/Reason Code */
456             prStaRec->u2StatusCode = u2StatusCode;
457
458             prStaRec->ucAuthAlgNum = AUTH_ALGORITHM_NUM_OPEN_SYSTEM;
459         }
460         else {
461             /* NOTE(Kevin): We should have STA_RECORD_T if the status code was successful */
462             ASSERT(!(u2StatusCode == STATUS_CODE_SUCCESSFUL));
463         }
464
465         /* NOTE: Ignore the return status for AAA */
466         //4 <4> Reply  Auth
467         authSendAuthFrame(prAdapter,
468                         prStaRec,
469                         eNetTypeIndex,
470                         prSwRfb,
471                         AUTH_TRANSACTION_SEQ_2,
472                         u2StatusCode);
473
474     }
475
476     return;
477 } /* end of aaaFsmRunEventRxAuth() */
478
479
480 /*----------------------------------------------------------------------------*/
481 /*!
482 * @brief This function will process the Rx (Re)Association Request Frame and then
483 *        trigger AAA FSM.
484 *
485 * @param[in] prAdapter          Pointer to the Adapter structure.
486 * @param[in] prSwRfb            Pointer to the SW_RFB_T structure.
487 *
488 * @retval WLAN_STATUS_SUCCESS           Always return success
489 */
490 /*----------------------------------------------------------------------------*/
491 WLAN_STATUS
492 aaaFsmRunEventRxAssoc (
493     IN P_ADAPTER_T prAdapter,
494     IN P_SW_RFB_T prSwRfb
495     )
496 {
497     P_BSS_INFO_T prBssInfo;
498     P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
499     UINT_16 u2StatusCode = STATUS_CODE_RESERVED;
500     BOOLEAN fgReplyAssocResp = FALSE;
501
502
503     ASSERT(prAdapter);
504
505     do {
506
507         //4 <1> Check if we have the STA_RECORD_T for incoming Assoc Req
508         prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
509
510         /* We should have the corresponding Sta Record. */
511         if ((!prStaRec) || (!prStaRec->fgIsInUse)) {
512             ASSERT(0); // Only for debug phase
513             break;
514         }
515
516         if (!IS_CLIENT_STA(prStaRec)) {
517             break;
518         }
519
520         if (prStaRec->ucStaState == STA_STATE_3) {
521             /* Do Reassocation */
522         }
523         else if ((prStaRec->ucStaState == STA_STATE_2) &&
524                  (prStaRec->eAuthAssocState == AAA_STATE_SEND_AUTH2)) {
525             /* Normal case */
526         }
527         else {
528             DBGLOG(AAA, WARN, ("Previous AuthAssocState (%d) != SEND_AUTH2.\n",
529                 prStaRec->eAuthAssocState));
530             break;
531         }
532
533         /* update RCPI */
534         prStaRec->ucRCPI = prSwRfb->prHifRxHdr->ucRcpi;
535
536         //4 <2> Check P2P network conditions
537 #if CFG_ENABLE_WIFI_DIRECT
538         if ((prAdapter->fgIsP2PRegistered) && (IS_STA_IN_P2P(prStaRec))) {
539
540             prBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
541
542             if (prBssInfo->fgIsNetActive) {
543
544                 //4 <2.1> Validate Assoc Req Frame and get Status Code
545                 /* Check if for this BSSID */
546                 if (WLAN_STATUS_SUCCESS ==
547                     assocProcessRxAssocReqFrame(prAdapter,
548                                                 prSwRfb,
549                                                 &u2StatusCode)) {
550
551                     if (STATUS_CODE_SUCCESSFUL == u2StatusCode) {
552                         //4 <2.2> Validate Assoc Req  Frame for Network Specific Conditions
553                         fgReplyAssocResp = p2pFuncValidateAssocReq(
554                                                 prAdapter,
555                                                 prSwRfb,
556                                                 (PUINT_16)&u2StatusCode);
557                     }
558                     else {
559                         fgReplyAssocResp = TRUE;
560                     }
561
562                     break;
563                 }
564             }
565         }
566 #endif /* CFG_ENABLE_WIFI_DIRECT */
567
568         //4 <3> Check BOW network conditions
569 #if CFG_ENABLE_BT_OVER_WIFI
570         if (IS_STA_IN_BOW(prStaRec)) {
571
572             prBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_BOW_INDEX]);
573
574             if ((prBssInfo->fgIsNetActive) &&
575                 (OP_MODE_BOW == prBssInfo->eCurrentOPMode)){
576
577                 //4 <3.1> Validate Auth Frame by Auth Algorithm/Transation Seq
578                 /* Check if for this BSSID */
579                 if (WLAN_STATUS_SUCCESS ==
580                     assocProcessRxAssocReqFrame(prAdapter,
581                                                 prSwRfb,
582                                                 &u2StatusCode)) {
583
584                     if (STATUS_CODE_SUCCESSFUL == u2StatusCode) {
585
586                         //4 <3.2> Validate Auth Frame for Network Specific Conditions
587                         fgReplyAssocResp = bowValidateAssocReq(prAdapter, prSwRfb, &u2StatusCode);
588
589                     }
590                     else {
591
592                         fgReplyAssocResp = TRUE;
593                     }
594
595                     /* TODO(Kevin): Allocate a STA_RECORD_T for new client */
596                     break;
597                 }
598             }
599         }
600 #endif /* CFG_ENABLE_BT_OVER_WIFI */
601
602         return WLAN_STATUS_SUCCESS; // To release the SW_RFB_T
603     } while (FALSE);
604
605
606     //4 <4> Update STA_RECORD_T and reply Assoc Resp Frame
607     if (fgReplyAssocResp) {
608         UINT_16     u2IELength;
609         PUINT_8     pucIE;
610
611         if ((((P_WLAN_ASSOC_REQ_FRAME_T)(prSwRfb->pvHeader))->u2FrameCtrl & MASK_FRAME_TYPE) ==
612             MAC_FRAME_REASSOC_REQ) {
613
614             u2IELength = prSwRfb->u2PacketLen -
615                 (UINT_16)OFFSET_OF(WLAN_REASSOC_REQ_FRAME_T, aucInfoElem[0]);
616
617             pucIE = ((P_WLAN_REASSOC_REQ_FRAME_T)(prSwRfb->pvHeader))->aucInfoElem;
618         }
619         else {
620             u2IELength = prSwRfb->u2PacketLen -
621                 (UINT_16)OFFSET_OF(WLAN_ASSOC_REQ_FRAME_T, aucInfoElem[0]);
622
623             pucIE = ((P_WLAN_ASSOC_REQ_FRAME_T)(prSwRfb->pvHeader))->aucInfoElem;
624         }
625
626         rlmProcessAssocReq(prAdapter, prSwRfb, pucIE, u2IELength);
627
628         //4 <4.1> Assign Association ID
629         if (u2StatusCode == STATUS_CODE_SUCCESSFUL) {
630
631 #if CFG_ENABLE_WIFI_DIRECT
632             if ((prAdapter->fgIsP2PRegistered) && (IS_STA_IN_P2P(prStaRec))) {
633                 if (p2pRunEventAAAComplete(prAdapter, prStaRec) == WLAN_STATUS_SUCCESS) {
634                     prStaRec->u2AssocId = bssAssignAssocID(prStaRec);
635                     //prStaRec->eAuthAssocState = AA_STATE_IDLE;
636                     prStaRec->eAuthAssocState = AAA_STATE_SEND_ASSOC2; // NOTE(Kevin): for TX done
637
638                     /* NOTE(Kevin): Method A: Change to STATE_3 before handle TX Done */
639                     //cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
640                 }
641                 else {
642                     /* Client List FULL. */
643                     u2StatusCode = STATUS_CODE_REQ_DECLINED;
644
645                     prStaRec->u2AssocId = 0; /* Invalid Assocation ID */
646
647                     /* If (Re)association fail, the peer can try Assocation w/o Auth immediately */
648                     prStaRec->eAuthAssocState = AAA_STATE_SEND_AUTH2;
649
650                     /* NOTE(Kevin): Better to change state here, not at TX Done */
651                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_2);
652                 }
653             }
654 #endif
655
656 #if CFG_ENABLE_BT_OVER_WIFI
657             if ((IS_STA_IN_BOW(prStaRec))) {
658
659 //                    if (bowRunEventAAAComplete(prAdapter, prStaRec) == WLAN_STATUS_SUCCESS) {
660                 prStaRec->u2AssocId = bssAssignAssocID(prStaRec);
661                 prStaRec->eAuthAssocState = AAA_STATE_SEND_ASSOC2; // NOTE(Kevin): for TX done
662
663                 /* NOTE(Kevin): Method A: Change to STATE_3 before handle TX Done */
664                 //cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
665             }
666 #if 0
667                 else {
668                     /* Client List FULL. */
669                     u2StatusCode = STATUS_CODE_REQ_DECLINED;
670
671                     prStaRec->u2AssocId = 0; /* Invalid Assocation ID */
672
673                     /* If (Re)association fail, the peer can try Assocation w/o Auth immediately */
674                     prStaRec->eAuthAssocState = AAA_STATE_SEND_AUTH2;
675
676                     /* NOTE(Kevin): Better to change state here, not at TX Done */
677                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_2);
678                 }
679             }
680 #endif
681 #endif
682         }
683         else {
684             prStaRec->u2AssocId = 0; /* Invalid Assocation ID */
685
686             /* If (Re)association fail, the peer can try Assocation w/o Auth immediately */
687             prStaRec->eAuthAssocState = AAA_STATE_SEND_AUTH2;
688
689             /* NOTE(Kevin): Better to change state here, not at TX Done */
690             cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_2);
691         }
692
693         /* Update the record join time. */
694         GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
695
696         /* Update Station Record - Status/Reason Code */
697         prStaRec->u2StatusCode = u2StatusCode;
698
699         /* NOTE: Ignore the return status for AAA */
700         //4 <4.2> Reply  Assoc Resp
701         assocSendReAssocRespFrame(prAdapter, prStaRec);
702
703     }
704
705     return WLAN_STATUS_SUCCESS;
706
707 } /* end of aaaFsmRunEventRxAssoc() */
708
709
710 /*----------------------------------------------------------------------------*/
711 /*!
712 * @brief This function will handle TxDone(Auth2/AssocReq) Event of AAA FSM.
713 *
714 * @param[in] prAdapter      Pointer to the Adapter structure.
715 * @param[in] prMsduInfo     Pointer to the MSDU_INFO_T.
716 * @param[in] rTxDoneStatus  Return TX status of the Auth1/Auth3/AssocReq frame.
717 *
718 * @retval WLAN_STATUS_SUCCESS
719 */
720 /*----------------------------------------------------------------------------*/
721 WLAN_STATUS
722 aaaFsmRunEventTxDone (
723     IN P_ADAPTER_T              prAdapter,
724     IN P_MSDU_INFO_T            prMsduInfo,
725     IN ENUM_TX_RESULT_CODE_T    rTxDoneStatus
726     )
727 {
728     P_STA_RECORD_T prStaRec;
729     P_BSS_INFO_T prBssInfo;
730
731
732     ASSERT(prAdapter);
733     ASSERT(prMsduInfo);
734
735     DBGLOG(AAA, LOUD, ("EVENT-TX DONE: Current Time = %ld\n", kalGetTimeTick()));
736
737     prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
738
739     if ((!prStaRec) || (!prStaRec->fgIsInUse)) {
740         return WLAN_STATUS_SUCCESS; /* For the case of replying ERROR STATUS CODE */
741     }
742
743     ASSERT(prStaRec->ucNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
744
745     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
746
747     switch (prStaRec->eAuthAssocState) {
748     case AAA_STATE_SEND_AUTH2:
749         {
750             /* Strictly check the outgoing frame is matched with current AA STATE */
751             if (authCheckTxAuthFrame(prAdapter,
752                                     prMsduInfo,
753                                     AUTH_TRANSACTION_SEQ_2) != WLAN_STATUS_SUCCESS) {
754                 break;
755             }
756
757             if (STATUS_CODE_SUCCESSFUL == prStaRec->u2StatusCode) {
758                 if (TX_RESULT_SUCCESS == rTxDoneStatus) {
759
760                     /* NOTE(Kevin): Change to STATE_2 at TX Done */
761                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_2);
762                 }
763                 else {
764
765                     prStaRec->eAuthAssocState = AA_STATE_IDLE;
766
767                     /* NOTE(Kevin): Change to STATE_1 */
768                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_1);
769
770 #if CFG_ENABLE_WIFI_DIRECT
771                     if ((prAdapter->fgIsP2PRegistered) &&
772                         (IS_STA_IN_P2P(prStaRec))) {
773                         p2pRunEventAAATxFail(prAdapter, prStaRec);
774                     }
775 #endif /* CFG_ENABLE_WIFI_DIRECT */
776
777 #if CFG_ENABLE_BT_OVER_WIFI
778                     if (IS_STA_IN_BOW(prStaRec)) {
779                         bowRunEventAAATxFail(prAdapter, prStaRec);
780                     }
781 #endif /* CFG_ENABLE_BT_OVER_WIFI */
782                 }
783
784             }
785             /* NOTE(Kevin): Ignore the TX Done Event of Auth Frame with Error Status Code */
786
787         }
788         break;
789
790     case AAA_STATE_SEND_ASSOC2:
791         {
792             /* Strictly check the outgoing frame is matched with current SAA STATE */
793             if (assocCheckTxReAssocRespFrame(prAdapter, prMsduInfo) != WLAN_STATUS_SUCCESS) {
794                 break;
795             }
796
797             if (STATUS_CODE_SUCCESSFUL == prStaRec->u2StatusCode) {
798                 if (TX_RESULT_SUCCESS == rTxDoneStatus) {
799
800                     prStaRec->eAuthAssocState = AA_STATE_IDLE;
801
802                     /* NOTE(Kevin): Change to STATE_3 at TX Done */
803 #if CFG_ENABLE_WIFI_DIRECT
804                     if ((prAdapter->fgIsP2PRegistered) &&
805                         (IS_STA_IN_P2P(prStaRec))) {
806                         p2pRunEventAAASuccess(prAdapter, prStaRec);
807                     }
808 #endif /* CFG_ENABLE_WIFI_DIRECT */
809
810 #if CFG_ENABLE_BT_OVER_WIFI
811
812                     if (IS_STA_IN_BOW(prStaRec))
813                         {
814                         bowRunEventAAAComplete(prAdapter, prStaRec);
815                     }
816 #endif /* CFG_ENABLE_BT_OVER_WIFI */
817
818                 }
819                 else {
820
821                     prStaRec->eAuthAssocState = AAA_STATE_SEND_AUTH2;
822
823                     /* NOTE(Kevin): Change to STATE_2 */
824                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_2);
825
826 #if CFG_ENABLE_WIFI_DIRECT
827                     if ((prAdapter->fgIsP2PRegistered) &&
828                         (IS_STA_IN_P2P(prStaRec))) {
829                         p2pRunEventAAATxFail(prAdapter, prStaRec);
830                     }
831 #endif /* CFG_ENABLE_WIFI_DIRECT */
832
833 #if CFG_ENABLE_BT_OVER_WIFI
834                     if (IS_STA_IN_BOW(prStaRec)) {
835                         bowRunEventAAATxFail(prAdapter, prStaRec);
836                     }
837 #endif /* CFG_ENABLE_BT_OVER_WIFI */
838
839                 }
840             }
841             /* NOTE(Kevin): Ignore the TX Done Event of Auth Frame with Error Status Code */
842         }
843         break;
844
845     default:
846         break; /* Ignore other cases */
847     }
848
849
850     return WLAN_STATUS_SUCCESS;
851
852 } /* end of aaaFsmRunEventTxDone() */
853 #endif /* CFG_SUPPORT_AAA */
854
855
856 #if 0 /* TODO(Kevin): for abort event, just reset the STA_RECORD_T. */
857 /*----------------------------------------------------------------------------*/
858 /*!
859 * \brief This function will send ABORT Event to JOIN FSM.
860 *
861 * \param[in] prAdapter  Pointer to the Adapter structure.
862 *
863 * \return none
864 */
865 /*----------------------------------------------------------------------------*/
866 VOID
867 saaFsmRunEventAbort (
868     IN P_MSG_HDR_T prMsgHdr
869     )
870 {
871     P_JOIN_INFO_T prJoinInfo;
872     P_STA_RECORD_T prStaRec;
873
874     DEBUGFUNC("joinFsmRunEventAbort");
875
876
877     ASSERT(prAdapter);
878     prJoinInfo = &prAdapter->rJoinInfo;
879
880     DBGLOG(JOIN, EVENT, ("JOIN EVENT: ABORT\n"));
881
882
883     /* NOTE(Kevin): when reach here, the ARB_STATE should be in ARB_STATE_JOIN. */
884     ASSERT(prJoinInfo->prBssDesc);
885
886     //4 <1> Update Flags and Elements of JOIN Module.
887     /* Reset Send Auth/(Re)Assoc Frame Count */
888     prJoinInfo->ucTxAuthAssocRetryCount = 0;
889
890     /* Cancel all JOIN relative Timer */
891     ARB_CANCEL_TIMER(prAdapter,
892                      prJoinInfo->rTxRequestTimer);
893
894     ARB_CANCEL_TIMER(prAdapter,
895                      prJoinInfo->rRxResponseTimer);
896
897     ARB_CANCEL_TIMER(prAdapter,
898                      prJoinInfo->rJoinTimer);
899
900     //4 <2> Update the associated STA_RECORD_T during JOIN.
901     /* Get a Station Record if possible, TA == BSSID for AP */
902     prStaRec = staRecGetStaRecordByAddr(prAdapter,
903                                         prJoinInfo->prBssDesc->aucBSSID);
904     if (prStaRec) {
905
906         /* Update Station Record - Class 1 Flag */
907         prStaRec->ucStaState = STA_STATE_1;
908     }
909 #if DBG
910     else {
911         ASSERT(0); /* Shouldn't happened, because we already add this STA_RECORD_T at JOIN_STATE_INIT */
912     }
913 #endif /* DBG */
914
915     //4 <3> Pull back to IDLE.
916     joinFsmSteps(prAdapter, JOIN_STATE_IDLE);
917
918     //4 <4> If we are in Roaming, recover the settings of previous BSS.
919     /* NOTE: JOIN FAIL -
920      * Restore original setting from current BSS_INFO_T.
921      */
922     if (prAdapter->eConnectionState == MEDIA_STATE_CONNECTED) {
923         joinAdoptParametersFromCurrentBss(prAdapter);
924     }
925
926     return;
927 } /* end of joinFsmRunEventAbort() */
928 #endif
929
930
931 /* TODO(Kevin): following code will be modified and move to AIS FSM */
932 #if 0
933 /*----------------------------------------------------------------------------*/
934 /*!
935 * \brief This function will send Join Timeout Event to JOIN FSM.
936 *
937 * \param[in] prAdapter      Pointer to the Adapter structure.
938 *
939 * \retval WLAN_STATUS_FAILURE   Fail because of Join Timeout
940 */
941 /*----------------------------------------------------------------------------*/
942 WLAN_STATUS
943 joinFsmRunEventJoinTimeOut (
944     IN P_ADAPTER_T  prAdapter
945     )
946 {
947     P_JOIN_INFO_T prJoinInfo;
948     P_STA_RECORD_T prStaRec;
949
950     DEBUGFUNC("joinFsmRunEventJoinTimeOut");
951
952
953     ASSERT(prAdapter);
954     prJoinInfo = &prAdapter->rJoinInfo;
955
956     DBGLOG(JOIN, EVENT, ("JOIN EVENT: JOIN TIMEOUT\n"));
957
958     /* Get a Station Record if possible, TA == BSSID for AP */
959     prStaRec = staRecGetStaRecordByAddr(prAdapter,
960                                         prJoinInfo->prBssDesc->aucBSSID);
961
962     /* We have renew this Sta Record when in JOIN_STATE_INIT */
963     ASSERT(prStaRec);
964
965     /* Record the Status Code of Authentication Request */
966     prStaRec->u2StatusCode = STATUS_CODE_JOIN_TIMEOUT;
967
968     /* Increase Failure Count */
969     prStaRec->ucJoinFailureCount++;
970
971     /* Reset Send Auth/(Re)Assoc Frame Count */
972     prJoinInfo->ucTxAuthAssocRetryCount = 0;
973
974     /* Cancel other JOIN relative Timer */
975     ARB_CANCEL_TIMER(prAdapter,
976                      prJoinInfo->rTxRequestTimer);
977
978     ARB_CANCEL_TIMER(prAdapter,
979                      prJoinInfo->rRxResponseTimer);
980
981     /* Restore original setting from current BSS_INFO_T */
982     if (prAdapter->eConnectionState == MEDIA_STATE_CONNECTED) {
983         joinAdoptParametersFromCurrentBss(prAdapter);
984     }
985
986     /* Pull back to IDLE */
987     joinFsmSteps(prAdapter, JOIN_STATE_IDLE);
988
989     return WLAN_STATUS_FAILURE;
990
991 } /* end of joinFsmRunEventJoinTimeOut() */
992
993 /*----------------------------------------------------------------------------*/
994 /*!
995 * \brief This function will adopt the parameters from Peer BSS.
996 *
997 * \param[in] prAdapter      Pointer to the Adapter structure.
998 *
999 * \return (none)
1000 */
1001 /*----------------------------------------------------------------------------*/
1002 VOID
1003 joinAdoptParametersFromPeerBss (
1004     IN P_ADAPTER_T prAdapter
1005     )
1006 {
1007     P_JOIN_INFO_T prJoinInfo;
1008     P_BSS_DESC_T prBssDesc;
1009
1010     DEBUGFUNC("joinAdoptParametersFromPeerBss");
1011
1012
1013     ASSERT(prAdapter);
1014     prJoinInfo = &prAdapter->rJoinInfo;
1015     prBssDesc = prJoinInfo->prBssDesc;
1016
1017     //4 <1> Adopt Peer BSS' PHY TYPE
1018     prAdapter->eCurrentPhyType = prBssDesc->ePhyType;
1019
1020     DBGLOG(JOIN, INFO, ("Target BSS[%s]'s PhyType = %s\n",
1021         prBssDesc->aucSSID, (prBssDesc->ePhyType == PHY_TYPE_ERP_INDEX) ? "ERP" : "HR_DSSS"));
1022
1023
1024     //4 <2> Adopt Peer BSS' Frequency(Band/Channel)
1025     DBGLOG(JOIN, INFO, ("Target BSS's Channel = %d, Band = %d\n",
1026         prBssDesc->ucChannelNum, prBssDesc->eBand));
1027
1028     nicSwitchChannel(prAdapter,
1029                      prBssDesc->eBand,
1030                      prBssDesc->ucChannelNum,
1031                      10);
1032
1033     prJoinInfo->fgIsParameterAdopted = TRUE;
1034
1035     return;
1036 } /* end of joinAdoptParametersFromPeerBss() */
1037
1038
1039 /*----------------------------------------------------------------------------*/
1040 /*!
1041 * \brief This function will adopt the parameters from current associated BSS.
1042 *
1043 * \param[in] prAdapter      Pointer to the Adapter structure.
1044 *
1045 * \return (none)
1046 */
1047 /*----------------------------------------------------------------------------*/
1048 VOID
1049 joinAdoptParametersFromCurrentBss (
1050     IN P_ADAPTER_T prAdapter
1051     )
1052 {
1053     //P_JOIN_INFO_T prJoinInfo = &prAdapter->rJoinInfo;
1054     P_BSS_INFO_T prBssInfo;
1055
1056
1057     ASSERT(prAdapter);
1058     prBssInfo = &prAdapter->rBssInfo;
1059
1060     //4 <1> Adopt current BSS' PHY TYPE
1061     prAdapter->eCurrentPhyType = prBssInfo->ePhyType;
1062
1063     //4 <2> Adopt current BSS' Frequency(Band/Channel)
1064     DBGLOG(JOIN, INFO, ("Current BSS's Channel = %d, Band = %d\n",
1065         prBssInfo->ucChnl, prBssInfo->eBand));
1066
1067     nicSwitchChannel(prAdapter,
1068                      prBssInfo->eBand,
1069                      prBssInfo->ucChnl,
1070                      10);
1071     return;
1072 } /* end of joinAdoptParametersFromCurrentBss() */
1073
1074
1075 /*----------------------------------------------------------------------------*/
1076 /*!
1077 * \brief This function will update all the SW variables and HW MCR registers after
1078 *        the association with target BSS.
1079 *
1080 * \param[in] prAdapter      Pointer to the Adapter structure.
1081 *
1082 * \return (none)
1083 */
1084 /*----------------------------------------------------------------------------*/
1085 VOID
1086 joinComplete (
1087     IN P_ADAPTER_T prAdapter
1088     )
1089 {
1090     P_JOIN_INFO_T prJoinInfo;
1091     P_BSS_DESC_T prBssDesc;
1092     P_PEER_BSS_INFO_T prPeerBssInfo;
1093     P_BSS_INFO_T prBssInfo;
1094     P_CONNECTION_SETTINGS_T prConnSettings;
1095     P_STA_RECORD_T prStaRec;
1096     P_TX_CTRL_T prTxCtrl;
1097 #if CFG_SUPPORT_802_11D
1098     P_IE_COUNTRY_T          prIECountry;
1099 #endif
1100
1101     DEBUGFUNC("joinComplete");
1102
1103
1104     ASSERT(prAdapter);
1105     prJoinInfo = &prAdapter->rJoinInfo;
1106     prBssDesc = prJoinInfo->prBssDesc;
1107     prPeerBssInfo = &prAdapter->rPeerBssInfo;
1108     prBssInfo = &prAdapter->rBssInfo;
1109     prConnSettings = &prAdapter->rConnSettings;
1110     prTxCtrl = &prAdapter->rTxCtrl;
1111
1112 //4 <1> Update Connecting & Connected Flag of BSS_DESC_T.
1113     /* Remove previous AP's Connection Flags if have */
1114     scanRemoveConnectionFlagOfBssDescByBssid(prAdapter, prBssInfo->aucBSSID);
1115
1116     prBssDesc->fgIsConnected = TRUE; /* Mask as Connected */
1117
1118     if (prBssDesc->fgIsHiddenSSID) {
1119         /* NOTE(Kevin): This is for the case of Passive Scan and the target BSS didn't
1120          * broadcast SSID on its Beacon Frame.
1121          */
1122         COPY_SSID(prBssDesc->aucSSID,
1123                   prBssDesc->ucSSIDLen,
1124                   prAdapter->rConnSettings.aucSSID,
1125                   prAdapter->rConnSettings.ucSSIDLen);
1126
1127         if (prBssDesc->ucSSIDLen) {
1128             prBssDesc->fgIsHiddenSSID = FALSE;
1129         }
1130 #if DBG
1131         else {
1132             ASSERT(0);
1133         }
1134 #endif /* DBG */
1135
1136         DBGLOG(JOIN, INFO, ("Hidden SSID! - Update SSID : %s\n", prBssDesc->aucSSID));
1137     }
1138
1139
1140 //4 <2> Update BSS_INFO_T from BSS_DESC_T
1141     //4 <2.A> PHY Type
1142     prBssInfo->ePhyType = prBssDesc->ePhyType;
1143
1144     //4 <2.B> BSS Type
1145     prBssInfo->eBSSType = BSS_TYPE_INFRASTRUCTURE;
1146
1147     //4 <2.C> BSSID
1148     COPY_MAC_ADDR(prBssInfo->aucBSSID, prBssDesc->aucBSSID);
1149
1150     DBGLOG(JOIN, INFO, ("JOIN to BSSID: ["MACSTR"]\n", MAC2STR(prBssDesc->aucBSSID)));
1151
1152
1153     //4 <2.D> SSID
1154     COPY_SSID(prBssInfo->aucSSID,
1155               prBssInfo->ucSSIDLen,
1156               prBssDesc->aucSSID,
1157               prBssDesc->ucSSIDLen);
1158
1159     //4 <2.E> Channel / Band information.
1160     prBssInfo->eBand = prBssDesc->eBand;
1161     prBssInfo->ucChnl = prBssDesc->ucChannelNum;
1162
1163     //4 <2.F> RSN/WPA information.
1164     secFsmRunEventStart(prAdapter);
1165     prBssInfo->u4RsnSelectedPairwiseCipher = prBssDesc->u4RsnSelectedPairwiseCipher;
1166     prBssInfo->u4RsnSelectedGroupCipher = prBssDesc->u4RsnSelectedGroupCipher;
1167     prBssInfo->u4RsnSelectedAKMSuite = prBssDesc->u4RsnSelectedAKMSuite;
1168
1169     if (secRsnKeyHandshakeEnabled()) {
1170         prBssInfo->fgIsWPAorWPA2Enabled = TRUE;
1171     }
1172     else {
1173         prBssInfo->fgIsWPAorWPA2Enabled = FALSE;
1174     }
1175
1176     //4 <2.G> Beacon interval.
1177     prBssInfo->u2BeaconInterval = prBssDesc->u2BeaconInterval;
1178
1179     //4 <2.H> DTIM period.
1180     prBssInfo->ucDtimPeriod = prBssDesc->ucDTIMPeriod;
1181
1182     //4 <2.I> ERP Information
1183     if ((prBssInfo->ePhyType == PHY_TYPE_ERP_INDEX) && // Our BSS's PHY_TYPE is ERP now.
1184         (prBssDesc->fgIsERPPresent)) {
1185
1186         prBssInfo->fgIsERPPresent = TRUE;
1187         prBssInfo->ucERP = prBssDesc->ucERP; /* Save the ERP for later check */
1188     }
1189     else { /* Some AP, may send ProbeResp without ERP IE. Thus prBssDesc->fgIsERPPresent is FALSE. */
1190         prBssInfo->fgIsERPPresent = FALSE;
1191         prBssInfo->ucERP = 0;
1192     }
1193
1194 #if CFG_SUPPORT_802_11D
1195     //4 <2.J> Country inforamtion of the associated AP
1196     if (prConnSettings->fgMultiDomainCapabilityEnabled) {
1197         DOMAIN_INFO_ENTRY   rDomainInfo;
1198         if (domainGetDomainInfoByScanResult(prAdapter, &rDomainInfo)) {
1199             if (prBssDesc->prIECountry) {
1200                 prIECountry = prBssDesc->prIECountry;
1201
1202                 domainParseCountryInfoElem(prIECountry, &prBssInfo->rDomainInfo);
1203
1204                 /* use the domain get from the BSS info */
1205                 prBssInfo->fgIsCountryInfoPresent = TRUE;
1206                 nicSetupOpChnlList(prAdapter, prBssInfo->rDomainInfo.u2CountryCode, FALSE);
1207             } else {
1208                 /* use the domain get from the scan result */
1209                 prBssInfo->fgIsCountryInfoPresent = TRUE;
1210                 nicSetupOpChnlList(prAdapter, rDomainInfo.u2CountryCode, FALSE);
1211             }
1212         }
1213     }
1214 #endif
1215
1216     //4 <2.K> Signal Power of the associated AP
1217     prBssInfo->rRcpi = prBssDesc->rRcpi;
1218     prBssInfo->rRssi = RCPI_TO_dBm(prBssInfo->rRcpi);
1219     GET_CURRENT_SYSTIME(&prBssInfo->rRssiLastUpdateTime);
1220
1221     //4 <2.L> Capability Field of the associated AP
1222     prBssInfo->u2CapInfo = prBssDesc->u2CapInfo;
1223
1224     DBGLOG(JOIN, INFO, ("prBssInfo-> fgIsERPPresent = %d, ucERP = %02x, rRcpi = %d, rRssi = %ld\n",
1225         prBssInfo->fgIsERPPresent, prBssInfo->ucERP, prBssInfo->rRcpi, prBssInfo->rRssi));
1226
1227
1228 //4 <3> Update BSS_INFO_T from PEER_BSS_INFO_T & NIC RATE FUNC
1229     //4 <3.A> Association ID
1230     prBssInfo->u2AssocId = prPeerBssInfo->u2AssocId;
1231
1232     //4 <3.B> WMM Infomation
1233     if (prAdapter->fgIsEnableWMM &&
1234         (prPeerBssInfo->rWmmInfo.ucWmmFlag & WMM_FLAG_SUPPORT_WMM)) {
1235
1236         prBssInfo->fgIsWmmAssoc = TRUE;
1237         prTxCtrl->rTxQForVoipAccess = TXQ_AC3;
1238
1239         qosWmmInfoInit(&prBssInfo->rWmmInfo, (prBssInfo->ePhyType == PHY_TYPE_HR_DSSS_INDEX) ? TRUE : FALSE);
1240
1241         if (prPeerBssInfo->rWmmInfo.ucWmmFlag & WMM_FLAG_AC_PARAM_PRESENT) {
1242             kalMemCopy(&prBssInfo->rWmmInfo,
1243                        &prPeerBssInfo->rWmmInfo,
1244                        sizeof(WMM_INFO_T));
1245         }
1246         else {
1247             kalMemCopy(&prBssInfo->rWmmInfo,
1248                        &prPeerBssInfo->rWmmInfo,
1249                        sizeof(WMM_INFO_T) - sizeof(prPeerBssInfo->rWmmInfo.arWmmAcParams));
1250         }
1251     }
1252     else {
1253         prBssInfo->fgIsWmmAssoc = FALSE;
1254         prTxCtrl->rTxQForVoipAccess = TXQ_AC1;
1255
1256         kalMemZero(&prBssInfo->rWmmInfo, sizeof(WMM_INFO_T));
1257     }
1258
1259
1260     //4 <3.C> Operational Rate Set & BSS Basic Rate Set
1261     prBssInfo->u2OperationalRateSet = prPeerBssInfo->u2OperationalRateSet;
1262     prBssInfo->u2BSSBasicRateSet = prPeerBssInfo->u2BSSBasicRateSet;
1263
1264
1265     //4 <3.D> Short Preamble
1266     if (prBssInfo->fgIsERPPresent) {
1267
1268         /* NOTE(Kevin 2007/12/24): Truth Table.
1269          * Short Preamble Bit in
1270          * <AssocReq>     <AssocResp w/i ERP>     <BARKER(Long)>  Final Driver Setting(Short)
1271          * TRUE            FALSE                  FALSE           FALSE(shouldn't have such case, use the AssocResp)
1272          * TRUE            FALSE                  TRUE            FALSE
1273          * FALSE           FALSE                  FALSE           FALSE(shouldn't have such case, use the AssocResp)
1274          * FALSE           FALSE                  TRUE            FALSE
1275          * TRUE            TRUE                   FALSE           TRUE(follow ERP)
1276          * TRUE            TRUE                   TRUE            FALSE(follow ERP)
1277          * FALSE           TRUE                   FALSE           FALSE(shouldn't have such case, and we should set to FALSE)
1278          * FALSE           TRUE                   TRUE            FALSE(we should set to FALSE)
1279          */
1280         if ((prPeerBssInfo->fgIsShortPreambleAllowed) &&
1281             ((prConnSettings->ePreambleType == PREAMBLE_TYPE_SHORT) || /* Short Preamble Option Enable is TRUE */
1282              ((prConnSettings->ePreambleType == PREAMBLE_TYPE_AUTO) &&
1283               (prBssDesc->u2CapInfo & CAP_INFO_SHORT_PREAMBLE)))) {
1284
1285             prBssInfo->fgIsShortPreambleAllowed = TRUE;
1286
1287             if (prBssInfo->ucERP & ERP_INFO_BARKER_PREAMBLE_MODE) {
1288                 prBssInfo->fgUseShortPreamble = FALSE;
1289             }
1290             else {
1291                 prBssInfo->fgUseShortPreamble = TRUE;
1292             }
1293         }
1294         else {
1295             prBssInfo->fgIsShortPreambleAllowed = FALSE;
1296             prBssInfo->fgUseShortPreamble = FALSE;
1297         }
1298     }
1299     else {
1300         /* NOTE(Kevin 2007/12/24): Truth Table.
1301          * Short Preamble Bit in
1302          * <AssocReq>     <AssocResp w/o ERP>     Final Driver Setting(Short)
1303          * TRUE            FALSE                  FALSE
1304          * FALSE           FALSE                  FALSE
1305          * TRUE            TRUE                   TRUE
1306          * FALSE           TRUE(status success)   TRUE
1307          * --> Honor the result of prPeerBssInfo.
1308          */
1309
1310         prBssInfo->fgIsShortPreambleAllowed = prBssInfo->fgUseShortPreamble =
1311             prPeerBssInfo->fgIsShortPreambleAllowed;
1312     }
1313
1314     DBGLOG(JOIN, INFO, ("prBssInfo->fgIsShortPreambleAllowed = %d, prBssInfo->fgUseShortPreamble = %d\n",
1315         prBssInfo->fgIsShortPreambleAllowed, prBssInfo->fgUseShortPreamble));
1316
1317
1318     //4 <3.E> Short Slot Time
1319     prBssInfo->fgUseShortSlotTime =
1320         prPeerBssInfo->fgUseShortSlotTime; /* AP support Short Slot Time */
1321
1322     DBGLOG(JOIN, INFO, ("prBssInfo->fgUseShortSlotTime = %d\n",
1323         prBssInfo->fgUseShortSlotTime));
1324
1325     nicSetSlotTime(prAdapter,
1326                    prBssInfo->ePhyType,
1327                    ((prConnSettings->fgIsShortSlotTimeOptionEnable &&
1328                      prBssInfo->fgUseShortSlotTime) ? TRUE : FALSE));
1329
1330
1331     //4 <3.F> Update Tx Rate for Control Frame
1332     bssUpdateTxRateForControlFrame(prAdapter);
1333
1334
1335     //4 <3.G> Save the available Auth Types during Roaming (Design for Fast BSS Transition).
1336     //if (prAdapter->fgIsEnableRoaming) /* NOTE(Kevin): Always prepare info for roaming */
1337     {
1338
1339         if (prJoinInfo->ucCurrAuthAlgNum == AUTH_ALGORITHM_NUM_OPEN_SYSTEM) {
1340             prJoinInfo->ucRoamingAuthTypes |= AUTH_TYPE_OPEN_SYSTEM;
1341         }
1342         else if (prJoinInfo->ucCurrAuthAlgNum == AUTH_ALGORITHM_NUM_SHARED_KEY) {
1343             prJoinInfo->ucRoamingAuthTypes |= AUTH_TYPE_SHARED_KEY;
1344         }
1345
1346         prBssInfo->ucRoamingAuthTypes = prJoinInfo->ucRoamingAuthTypes;
1347
1348
1349         /* Set the stable time of the associated BSS. We won't do roaming decision
1350          * during the stable time.
1351          */
1352         SET_EXPIRATION_TIME(prBssInfo->rRoamingStableExpirationTime,
1353             SEC_TO_SYSTIME(ROAMING_STABLE_TIMEOUT_SEC));
1354     }
1355
1356
1357     //4 <3.H> Update Parameter for TX Fragmentation Threshold
1358 #if CFG_TX_FRAGMENT
1359     txFragInfoUpdate(prAdapter);
1360 #endif /* CFG_TX_FRAGMENT */
1361
1362
1363 //4 <4> Update STA_RECORD_T
1364     /* Get a Station Record if possible */
1365     prStaRec = staRecGetStaRecordByAddr(prAdapter,
1366                                         prBssDesc->aucBSSID);
1367
1368     if (prStaRec) {
1369         UINT_16 u2OperationalRateSet, u2DesiredRateSet;
1370
1371         //4 <4.A> Desired Rate Set
1372         u2OperationalRateSet = (rPhyAttributes[prBssInfo->ePhyType].u2SupportedRateSet &
1373                                 prBssInfo->u2OperationalRateSet);
1374
1375         u2DesiredRateSet = (u2OperationalRateSet & prConnSettings->u2DesiredRateSet);
1376         if (u2DesiredRateSet) {
1377             prStaRec->u2DesiredRateSet = u2DesiredRateSet;
1378         }
1379         else {
1380             /* For Error Handling - The Desired Rate Set is not covered in Operational Rate Set. */
1381             prStaRec->u2DesiredRateSet = u2OperationalRateSet;
1382         }
1383
1384         /* Try to set the best initial rate for this entry */
1385         if (!rateGetBestInitialRateIndex(prStaRec->u2DesiredRateSet,
1386                                          prStaRec->rRcpi,
1387                                          &prStaRec->ucCurrRate1Index)) {
1388
1389             if (!rateGetLowestRateIndexFromRateSet(prStaRec->u2DesiredRateSet,
1390                                                    &prStaRec->ucCurrRate1Index)) {
1391                 ASSERT(0);
1392             }
1393         }
1394
1395         DBGLOG(JOIN, INFO, ("prStaRec->ucCurrRate1Index = %d\n",
1396             prStaRec->ucCurrRate1Index));
1397
1398         //4 <4.B> Preamble Mode
1399         prStaRec->fgIsShortPreambleOptionEnable =
1400             prBssInfo->fgUseShortPreamble;
1401
1402         //4 <4.C> QoS Flag
1403         prStaRec->fgIsQoS = prBssInfo->fgIsWmmAssoc;
1404     }
1405 #if DBG
1406     else {
1407         ASSERT(0);
1408     }
1409 #endif /* DBG */
1410
1411
1412 //4 <5> Update NIC
1413     //4 <5.A> Update BSSID & Operation Mode
1414     nicSetupBSS(prAdapter, prBssInfo);
1415
1416     //4 <5.B> Update WLAN Table.
1417     if (nicSetHwBySta(prAdapter, prStaRec) == FALSE) {
1418         ASSERT(FALSE);
1419     }
1420
1421     //4 <5.C> Update Desired Rate Set for BT.
1422 #if CFG_TX_FRAGMENT
1423     if (prConnSettings->fgIsEnableTxAutoFragmentForBT) {
1424         txRateSetInitForBT(prAdapter, prStaRec);
1425     }
1426 #endif /* CFG_TX_FRAGMENT */
1427
1428     //4 <5.D> TX AC Parameter and TX/RX Queue Control
1429     if (prBssInfo->fgIsWmmAssoc) {
1430
1431 #if CFG_TX_AGGREGATE_HW_FIFO
1432         nicTxAggregateTXQ(prAdapter, FALSE);
1433 #endif /* CFG_TX_AGGREGATE_HW_FIFO */
1434
1435         qosUpdateWMMParametersAndAssignAllowedACI(prAdapter, &prBssInfo->rWmmInfo);
1436     }
1437     else {
1438
1439 #if CFG_TX_AGGREGATE_HW_FIFO
1440         nicTxAggregateTXQ(prAdapter, TRUE);
1441 #endif /* CFG_TX_AGGREGATE_HW_FIFO */
1442
1443         nicTxNonQoSAssignDefaultAdmittedTXQ(prAdapter);
1444
1445         nicTxNonQoSUpdateTXQParameters(prAdapter,
1446                                        prBssInfo->ePhyType);
1447     }
1448
1449 #if CFG_TX_STOP_WRITE_TX_FIFO_UNTIL_JOIN
1450     {
1451         prTxCtrl->fgBlockTxDuringJoin = FALSE;
1452
1453     #if !CFG_TX_AGGREGATE_HW_FIFO /* TX FIFO AGGREGATE already do flush once */
1454         nicTxFlushStopQueues(prAdapter, (UINT_8)TXQ_DATA_MASK, (UINT_8)NULL);
1455     #endif /* CFG_TX_AGGREGATE_HW_FIFO */
1456
1457         nicTxRetransmitOfSendWaitQue(prAdapter);
1458
1459         if (prTxCtrl->fgIsPacketInOsSendQueue) {
1460             nicTxRetransmitOfOsSendQue(prAdapter);
1461         }
1462
1463     #if CFG_SDIO_TX_ENHANCE
1464         halTxLeftClusteredMpdu(prAdapter);
1465     #endif /* CFG_SDIO_TX_ENHANCE */
1466
1467     }
1468 #endif /* CFG_TX_STOP_WRITE_TX_FIFO_UNTIL_JOIN */
1469
1470
1471 //4 <6> Setup CONNECTION flag.
1472     prAdapter->eConnectionState = MEDIA_STATE_CONNECTED;
1473     prAdapter->eConnectionStateIndicated = MEDIA_STATE_CONNECTED;
1474
1475     if (prJoinInfo->fgIsReAssoc) {
1476         prAdapter->fgBypassPortCtrlForRoaming = TRUE;
1477     }
1478     else {
1479         prAdapter->fgBypassPortCtrlForRoaming = FALSE;
1480     }
1481
1482     kalIndicateStatusAndComplete(prAdapter->prGlueInfo,
1483         WLAN_STATUS_MEDIA_CONNECT,
1484         (PVOID)NULL,
1485         0);
1486
1487     return;
1488 } /* end of joinComplete() */
1489 #endif
1490