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