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