add rk3288 pinctrl dts code
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / combo_mt66xx / mt6620 / wlan / mgmt / privacy.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/privacy.c#1 $
3 */
4
5 /*! \file   "privacy.c"
6     \brief  This file including the protocol layer privacy function.
7
8     This file provided the macros and functions library support for the
9     protocol layer security setting from rsn.c and nic_privacy.c
10
11 */
12
13
14
15 /*
16 ** $Log: privacy.c $
17  *
18  * 11 10 2011 wh.su
19  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
20  * change the debug module level.
21  *
22  * 10 20 2011 terry.wu
23  * NULL
24  * Fix Hotspot deauth send failed.
25  *
26  * 10 12 2011 wh.su
27  * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
28  * adding the 802.11w related function and define .
29  *
30  * 06 28 2011 tsaiyuan.hsu
31  * [WCXRP00000819] [MT6620 Wi-Fi][Driver] check if staRec is NULL or not in secCheckClassError
32  * check if staRec is NULL or not in secCheckClassError.
33  *
34  * 06 09 2011 tsaiyuan.hsu
35  * [WCXRP00000760] [MT5931 Wi-Fi][FW] Refine rxmHandleMacRxDone to reduce code size
36  * move send_auth at rxmHandleMacRxDone in firmware to driver to reduce code size.
37  *
38  * 01 25 2011 yuche.tsai
39  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
40  * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
41  *
42  * 11 04 2010 wh.su
43  * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
44  * adding the p2p random ssid support.
45  *
46  * 10 04 2010 cp.wu
47  * [WCXRP00000077] [MT6620 Wi-Fi][Driver][FW] Eliminate use of ENUM_NETWORK_TYPE_T and replaced by ENUM_NETWORK_TYPE_INDEX_T only
48  * remove ENUM_NETWORK_TYPE_T definitions
49  *
50  * 09 03 2010 kevin.huang
51  * NULL
52  * Refine #include sequence and solve recursive/nested #include issue
53  *
54  * 09 01 2010 wh.su
55  * NULL
56  * adding the wapi support for integration test.
57  *
58  * 07 24 2010 wh.su
59  *
60  * .support the Wi-Fi RSN
61  *
62  * 07 20 2010 wh.su
63  *
64  * adding the wapi code.
65  *
66  * 07 08 2010 cp.wu
67  *
68  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
69  *
70  * 06 21 2010 wh.su
71  * [WPD00003840][MT6620 5931] Security migration
72  * modify some code for concurrent network.
73  *
74  * 06 21 2010 cp.wu
75  * [WPD00003833][MT6620 and MT5931] Driver migration
76  * [WPD00003833][MT6620 and MT5931] Driver migration
77  * enable RX management frame handling.
78  *
79  * 06 19 2010 wh.su
80  * [WPD00003840][MT6620 5931] Security migration
81  * adding the compiling flag for migration.
82  *
83  * 06 19 2010 wh.su
84  * [WPD00003840][MT6620 5931] Security migration
85  * consdier the concurrent network setting.
86  *
87  * 06 18 2010 wh.su
88  * [WPD00003840][MT6620 5931] Security migration
89  * migration the security related function from firmware.
90  *
91  * 05 28 2010 wh.su
92  * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
93  * fixed the ad-hoc wpa-none send non-encrypted frame issue.
94  *
95  * 05 24 2010 kevin.huang
96  * [BORA00000794][WIFISYS][New Feature]Power Management Support
97  * Refine authSendAuthFrame() for NULL STA_RECORD_T case and minimum deauth interval.
98  *
99  * 04 29 2010 wh.su
100  * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
101  * adjsut the pre-authentication code.
102  *
103  * 04 22 2010 wh.su
104  * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
105  * fixed the wpi same key id rx issue and fixed the remove wep key issue.
106  *
107  * 04 19 2010 kevin.huang
108  * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
109  * Add Send Deauth for Class 3 Error and Leave Network Support
110  *
111  * 04 15 2010 wh.su
112  * [BORA00000680][MT6620] Support the statistic for Microsoft os query
113  * remove the assert code for allow ad-hoc pkt.
114  *
115  * 04 13 2010 wh.su
116  * [BORA00000680][MT6620] Support the statistic for Microsoft os query
117  * fixed the Klocwork error and refine the class error message.
118  *
119  * 03 04 2010 wh.su
120  * [BORA00000605][WIFISYS] Phase3 Integration
121  * Code refine, and remove non-used code.
122  *
123  * 03 03 2010 wh.su
124  * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
125  * move the AIS specific variable for security to AIS specific structure.
126  *
127  * 03 03 2010 wh.su
128  * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
129  * Fixed the pre-authentication timer not correctly init issue, and modify the security related callback function prototype.
130  *
131  * 03 01 2010 wh.su
132  * [BORA00000605][WIFISYS] Phase3 Integration
133  * Refine the variable and parameter for security.
134  *
135  * 02 26 2010 wh.su
136  * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
137  * change the waning message shown level, and clear the global transmit flag for CMD INFRASTRUCTURE.
138  *
139  * 02 25 2010 wh.su
140  * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
141  * For support the WHQL test, do the remove key code refine.
142  *
143  * 01 27 2010 wh.su
144  * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
145  * add and fixed some security function.
146  *
147  * 12 25 2009 tehuang.liu
148  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
149  * Integrated modifications for 1st connection (mainly on FW modules MQM, TXM, and RXM)
150  *  *  *  *  *  *  *  *  * MQM: BA handling
151  *  *  *  *  *  *  *  *  * TXM: Macros updates
152  *  *  *  *  *  *  *  *  * RXM: Macros/Duplicate Removal updates
153  *
154  * 12 18 2009 cm.chang
155  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
156  * .
157  *
158  * Dec 11 2009 mtk01088
159  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
160  * modify the cmd with result return
161  *
162  * Dec 11 2009 mtk01088
163  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
164  * fixed the value not initialize issue
165  *
166  * Dec 10 2009 mtk01088
167  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
168  * change the cmd return type
169  *
170  * Dec 8 2009 mtk01088
171  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
172  * adding the function to update the auth mode and encryption status for cmd build connection
173  *
174  * Dec 7 2009 mtk01088
175  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
176  * adding some code for wapi mode
177  *
178  * Dec 7 2009 mtk01088
179  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
180  * adding the call to check the 4th and eapol error report frame
181  *
182  * Dec 7 2009 mtk01088
183  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
184  * rename the function name
185  *
186  * Dec 4 2009 mtk01088
187  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
188  * adding the code for parsing the EAPoL frame, and do some code refine
189  *
190  * Dec 3 2009 mtk01088
191  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
192  * adding the class error check
193  *
194  * Dec 3 2009 mtk01088
195  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
196  * adding the cmd_802_11_pmkid code
197  *
198  * Dec 1 2009 mtk01088
199  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
200  * doing some function rename, and adding the code for cmd CMD_ADD_REMOVE_KEY
201  *
202  * Nov 23 2009 mtk01088
203  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
204  * adding the clear pmkid function
205  *
206  * Nov 23 2009 mtk01461
207  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
208  * Fix eStaType check for AIS
209  *
210  * Nov 19 2009 mtk01088
211  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
212  * adding the ap selection related code
213  *
214  * Nov 18 2009 mtk01088
215  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
216  *
217 */
218
219 /*******************************************************************************
220 *                         C O M P I L E R   F L A G S
221 ********************************************************************************
222 */
223
224 /*******************************************************************************
225 *                    E X T E R N A L   R E F E R E N C E S
226 ********************************************************************************
227 */
228 #include "precomp.h"
229
230 #if CFG_PRIVACY_MIGRATION
231
232 /*******************************************************************************
233 *                              C O N S T A N T S
234 ********************************************************************************
235 */
236
237 /*******************************************************************************
238 *                             D A T A   T Y P E S
239 ********************************************************************************
240 */
241
242 /*******************************************************************************
243 *                            P U B L I C   D A T A
244 ********************************************************************************
245 */
246
247 /*******************************************************************************
248 *                           P R I V A T E   D A T A
249 ********************************************************************************
250 */
251
252 /*******************************************************************************
253 *                                 M A C R O S
254 ********************************************************************************
255 */
256
257 /*******************************************************************************
258 *                   F U N C T I O N   D E C L A R A T I O N S
259 ********************************************************************************
260 */
261
262 /*******************************************************************************
263 *                              F U N C T I O N S
264 ********************************************************************************
265 */
266
267
268 /*----------------------------------------------------------------------------*/
269 /*!
270 * \brief This routine is called to initialize the privacy-related
271 *        parameters.
272 *
273 * \param[in] prAdapter Pointer to the Adapter structure
274 * \param[in] ucNetTypeIdx  Pointer to netowrk type index
275 *
276 * \retval NONE
277 */
278 /*----------------------------------------------------------------------------*/
279 VOID
280 secInit (
281     IN P_ADAPTER_T          prAdapter,
282     IN UINT_8               ucNetTypeIdx
283     )
284 {
285     UINT_8                  i;
286     P_CONNECTION_SETTINGS_T prConnSettings;
287     P_BSS_INFO_T            prBssInfo;
288     P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
289
290     DEBUGFUNC("secInit");
291
292     ASSERT(prAdapter);
293
294     prConnSettings = &prAdapter->rWifiVar.rConnSettings;
295     prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_AIS_INDEX];
296     prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
297
298     prBssInfo->u4RsnSelectedGroupCipher = 0;
299     prBssInfo->u4RsnSelectedPairwiseCipher = 0;
300     prBssInfo->u4RsnSelectedAKMSuite = 0;
301
302 #if CFG_ENABLE_WIFI_DIRECT
303     prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
304
305     prBssInfo->u4RsnSelectedGroupCipher = RSN_CIPHER_SUITE_CCMP;
306     prBssInfo->u4RsnSelectedPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
307     prBssInfo->u4RsnSelectedAKMSuite = RSN_AKM_SUITE_PSK;
308 #endif
309
310 #if CFG_ENABLE_BT_OVER_WIFI
311     prBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_BOW_INDEX];
312
313     prBssInfo->u4RsnSelectedGroupCipher = RSN_CIPHER_SUITE_CCMP;
314     prBssInfo->u4RsnSelectedPairwiseCipher = RSN_CIPHER_SUITE_CCMP;
315     prBssInfo->u4RsnSelectedAKMSuite = RSN_AKM_SUITE_PSK;
316 #endif
317
318     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[0].dot11RSNAConfigPairwiseCipher =
319             WPA_CIPHER_SUITE_WEP40;
320     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[1].dot11RSNAConfigPairwiseCipher =
321             WPA_CIPHER_SUITE_TKIP;
322     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[2].dot11RSNAConfigPairwiseCipher =
323             WPA_CIPHER_SUITE_CCMP;
324     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[3].dot11RSNAConfigPairwiseCipher =
325             WPA_CIPHER_SUITE_WEP104;
326
327     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[4].dot11RSNAConfigPairwiseCipher =
328             RSN_CIPHER_SUITE_WEP40;
329     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[5].dot11RSNAConfigPairwiseCipher =
330             RSN_CIPHER_SUITE_TKIP;
331     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[6].dot11RSNAConfigPairwiseCipher =
332             RSN_CIPHER_SUITE_CCMP;
333     prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[7].dot11RSNAConfigPairwiseCipher =
334             RSN_CIPHER_SUITE_WEP104;
335
336     for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i ++) {
337         prAdapter->rMib.dot11RSNAConfigPairwiseCiphersTable[i].dot11RSNAConfigPairwiseCipherEnabled =
338             FALSE;
339     }
340
341     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[0].dot11RSNAConfigAuthenticationSuite =
342             WPA_AKM_SUITE_NONE;
343     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[1].dot11RSNAConfigAuthenticationSuite =
344             WPA_AKM_SUITE_802_1X;
345     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[2].dot11RSNAConfigAuthenticationSuite =
346             WPA_AKM_SUITE_PSK;
347     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[3].dot11RSNAConfigAuthenticationSuite =
348             RSN_AKM_SUITE_NONE;
349     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[4].dot11RSNAConfigAuthenticationSuite =
350             RSN_AKM_SUITE_802_1X;
351     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[5].dot11RSNAConfigAuthenticationSuite =
352             RSN_AKM_SUITE_PSK;
353
354 #if CFG_SUPPORT_802_11W
355     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[6].dot11RSNAConfigAuthenticationSuite =
356                 RSN_AKM_SUITE_802_1X_SHA256;
357     prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[7].dot11RSNAConfigAuthenticationSuite =
358                 RSN_AKM_SUITE_PSK_SHA256;
359 #endif
360
361     for (i = 0; i < MAX_NUM_SUPPORTED_AKM_SUITES; i ++) {
362         prAdapter->rMib.dot11RSNAConfigAuthenticationSuitesTable[i].dot11RSNAConfigAuthenticationSuiteEnabled =
363             FALSE;
364     }
365
366     secClearPmkid(prAdapter);
367
368     cnmTimerInitTimer(prAdapter,
369                    &prAisSpecBssInfo->rPreauthenticationTimer,
370                    (PFN_MGMT_TIMEOUT_FUNC)rsnIndicatePmkidCand,
371                    (UINT_32)NULL);
372
373 #if CFG_SUPPORT_802_11W
374     cnmTimerInitTimer(prAdapter,
375                    &prAisSpecBssInfo->rSaQueryTimer,
376                    (PFN_MGMT_TIMEOUT_FUNC)rsnStartSaQueryTimer,
377                    (UINT_32)NULL);
378 #endif
379
380     prAisSpecBssInfo->fgCounterMeasure = FALSE;
381     prAisSpecBssInfo->ucWEPDefaultKeyID = 0;
382
383
384     #if 0
385     for (i=0;i<WTBL_SIZE;i++) {
386         g_prWifiVar->arWtbl[i].fgUsed = FALSE;
387         g_prWifiVar->arWtbl[i].prSta = NULL;
388         g_prWifiVar->arWtbl[i].ucNetTypeIdx =  NETWORK_TYPE_INDEX_NUM;
389
390     }
391     nicPrivacyInitialize((UINT_8)NETWORK_TYPE_INDEX_NUM);
392     #endif
393 }   /* secInit */
394
395
396 /*----------------------------------------------------------------------------*/
397 /*!
398 * \brief This function will indicate an Event of "Rx Class Error" to SEC_FSM for
399 *        JOIN Module.
400 *
401 * \param[in] prAdapter     Pointer to the Adapter structure
402 * \param[in] prSwRfb       Pointer to the SW RFB.
403 *
404 * \return FALSE                Class Error
405 */
406 /*----------------------------------------------------------------------------*/
407 BOOL
408 secCheckClassError (
409     IN P_ADAPTER_T          prAdapter,
410     IN P_SW_RFB_T           prSwRfb,
411     IN P_STA_RECORD_T       prStaRec
412     )
413 {
414     ASSERT(prAdapter);
415     ASSERT(prSwRfb);
416     //ASSERT(prStaRec);
417
418     //prStaRec = &(g_arStaRec[prSwRfb->ucStaRecIdx]);
419
420     if ((prStaRec) && 1 /* RXM_IS_DATA_FRAME(prSwRfb) */) {
421         ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex = prStaRec->ucNetTypeIndex;
422
423         if (IS_NET_ACTIVE(prAdapter, eNetTypeIndex)) {
424                   P_BSS_INFO_T prBssInfo;
425                   prBssInfo = &prAdapter->rWifiVar.arBssInfo[eNetTypeIndex];            
426
427             if ((STA_STATE_3 != prStaRec->ucStaState) &&
428                    IS_BSS_ACTIVE(prBssInfo) && 
429                    prBssInfo->fgIsNetAbsent == FALSE) {
430                 /*(IS_AP_STA(prStaRec) || IS_CLIENT_STA(prStaRec))) {*/                
431
432                 if (WLAN_STATUS_SUCCESS == authSendDeauthFrame(prAdapter,
433                                                                prStaRec,
434                                                                NULL,
435                                                                REASON_CODE_CLASS_3_ERR,
436                                                                (PFN_TX_DONE_HANDLER)NULL)) {
437
438                     DBGLOG(RSN, INFO, ("Send Deauth to MAC:["MACSTR"] for Rx Class 3 Error.\n",
439                                       MAC2STR(prStaRec->aucMacAddr)));
440                 }
441
442                 return FALSE;
443             }
444
445             return secRxPortControlCheck(prAdapter, prSwRfb);
446         }
447     }
448
449     return FALSE;
450 } /* end of secCheckClassError() */
451
452
453 /*----------------------------------------------------------------------------*/
454 /*!
455 * \brief This routine is used to setting the sta port status.
456 *
457 * \param[in]  prAdapter Pointer to the Adapter structure
458 * \param[in]  prSta Pointer to the sta
459 * \param[in]  fgPortBlock The port status
460 *
461 * \retval none
462 *
463 */
464 /*----------------------------------------------------------------------------*/
465 VOID
466 secSetPortBlocked (
467     IN P_ADAPTER_T          prAdapter,
468     IN P_STA_RECORD_T       prSta,
469     IN BOOLEAN              fgPortBlock
470    )
471 {
472     if (prSta == NULL)
473         return ;
474
475     prSta->fgPortBlock = fgPortBlock;
476
477     DBGLOG(RSN, TRACE, ("The STA "MACSTR" port %s\n", MAC2STR(prSta->aucMacAddr), fgPortBlock == TRUE ? "BLOCK" :" OPEN"));
478 }
479
480
481 /*----------------------------------------------------------------------------*/
482 /*!
483 * \brief This routine is used to report the sta port status.
484 *
485 * \param[in]  prAdapter Pointer to the Adapter structure
486 * \param[in]  prSta Pointer to the sta
487 * \param[out]  fgPortBlock The port status
488 *
489 * \return TRUE sta exist, FALSE sta not exist
490 *
491 */
492 /*----------------------------------------------------------------------------*/
493 BOOLEAN
494 secGetPortStatus (
495     IN P_ADAPTER_T          prAdapter,
496     IN P_STA_RECORD_T       prSta,
497     OUT PBOOLEAN            pfgPortStatus
498    )
499 {
500     if (prSta == NULL)
501         return FALSE;
502
503     *pfgPortStatus = prSta->fgPortBlock;
504
505     return TRUE;
506 }
507
508
509 /*----------------------------------------------------------------------------*/
510 /*!
511 * \brief This routine is called to handle Peer device Tx Security process MSDU.
512 *
513 * \param[in] prMsduInfo pointer to the packet info pointer
514 *
515 * \retval TRUE Accept the packet
516 * \retval FALSE Refuse the MSDU packet due port blocked
517 *
518 */
519 /*----------------------------------------------------------------------------*/
520 BOOL /* ENUM_PORT_CONTROL_RESULT */
521 secTxPortControlCheck(
522     IN P_ADAPTER_T          prAdapter,
523     IN P_MSDU_INFO_T        prMsduInfo,
524     IN P_STA_RECORD_T       prStaRec
525     )
526 {
527     ASSERT(prAdapter);
528     ASSERT(prMsduInfo);
529     ASSERT(prStaRec);
530
531     if (prStaRec) {
532
533         /* Todo:: */
534         if (prMsduInfo->fgIs802_1x)
535             return TRUE;
536
537         if (prStaRec->fgPortBlock == TRUE) {
538             DBGLOG(INIT, TRACE, ("Drop Tx packet due Port Control!\n"));
539             return FALSE;
540         }
541
542 #if CFG_SUPPORT_WAPI
543         if (prAdapter->rWifiVar.rConnSettings.fgWapiMode) {
544             return TRUE;
545         }
546 #endif
547         if (IS_STA_IN_AIS(prStaRec)) {
548             if (!prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist &&
549                 (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION1_ENABLED)){
550                 DBGLOG(INIT, TRACE, ("Drop Tx packet due the key is removed!!!\n"));
551                 return FALSE;
552             }
553         }
554     }
555
556     return TRUE;
557 }
558
559
560 /*----------------------------------------------------------------------------*/
561 /*!
562 * \brief This routine is called to handle The Rx Security process MSDU.
563 *
564 * \param[in] prAdapter Pointer to the Adapter structure
565 * \param[in] prSWRfb SW rfb pinter
566 *
567 * \retval TRUE Accept the packet
568 * \retval FALSE Refuse the MSDU packet due port control
569 */
570 /*----------------------------------------------------------------------------*/
571 BOOLEAN
572 secRxPortControlCheck (
573     IN P_ADAPTER_T          prAdapter,
574     IN P_SW_RFB_T           prSWRfb
575     )
576 {
577     ASSERT(prSWRfb);
578
579 #if 0
580     /* whsu:Todo: Process MGMT and DATA */
581     if (prSWRfb->prStaRec) {
582         if (prSWRfb->prStaRec->fgPortBlock == TRUE) {
583             if (1 /* prSWRfb->fgIsDataFrame and not 1x*/ &&
584                 (g_prWifiVar->rConnSettings.eAuthMode >= AUTH_MODE_WPA)){
585                 //DBGLOG(SEC, WARN, ("Drop Rx data due port control !\r\n"));
586                 return TRUE; /* Todo: whsu FALSE; */
587             }
588             //if (!RX_STATUS_IS_PROTECT(prSWRfb->prRxStatus)) {
589             //  DBGLOG(RSN, WARN, ("Drop rcv non-encrypted data frame!\n"));
590             //  return FALSE;
591             //}
592         }
593     }
594     else {
595     }
596 #endif
597     return TRUE;
598 }
599
600 /*----------------------------------------------------------------------------*/
601 /*!
602 * \brief This routine will enable/disable the cipher suite
603 *
604 * \param[in] prAdapter Pointer to the adapter object data area.
605 * \param[in] u4CipherSuitesFlags flag for cipher suite
606 *
607 * \retval none
608 */
609 /*----------------------------------------------------------------------------*/
610 VOID
611 secSetCipherSuite (
612     IN P_ADAPTER_T prAdapter,
613     IN UINT_32     u4CipherSuitesFlags
614     )
615 {
616     UINT_32 i;
617     P_DOT11_RSNA_CONFIG_PAIRWISE_CIPHERS_ENTRY prEntry;
618     P_IEEE_802_11_MIB_T prMib;
619
620     ASSERT(prAdapter);
621
622     prMib = &prAdapter->rMib;
623
624     ASSERT(prMib);
625
626     if (u4CipherSuitesFlags == CIPHER_FLAG_NONE) {
627         /* Disable all the pairwise cipher suites. */
628         for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++) {
629             prMib->dot11RSNAConfigPairwiseCiphersTable[i].dot11RSNAConfigPairwiseCipherEnabled =
630                 FALSE;
631         }
632
633         /* Update the group cipher suite. */
634         prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_NONE;
635
636         return;
637     }
638
639     for (i = 0; i < MAX_NUM_SUPPORTED_CIPHER_SUITES; i++) {
640         prEntry = &prMib->dot11RSNAConfigPairwiseCiphersTable[i];
641
642         switch (prEntry->dot11RSNAConfigPairwiseCipher) {
643             case WPA_CIPHER_SUITE_WEP40:
644             case RSN_CIPHER_SUITE_WEP40:
645                  if (u4CipherSuitesFlags & CIPHER_FLAG_WEP40) {
646                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
647                  }
648                  else {
649                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
650                  }
651                  break;
652
653             case WPA_CIPHER_SUITE_TKIP:
654             case RSN_CIPHER_SUITE_TKIP:
655                  if (u4CipherSuitesFlags & CIPHER_FLAG_TKIP) {
656                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
657                  }
658                  else {
659                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
660                  }
661                  break;
662
663             case WPA_CIPHER_SUITE_CCMP:
664             case RSN_CIPHER_SUITE_CCMP:
665                  if (u4CipherSuitesFlags & CIPHER_FLAG_CCMP) {
666                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
667                  }
668                  else {
669                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
670                  }
671                  break;
672
673             case WPA_CIPHER_SUITE_WEP104:
674             case RSN_CIPHER_SUITE_WEP104:
675                  if (u4CipherSuitesFlags & CIPHER_FLAG_WEP104) {
676                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = TRUE;
677                  }
678                  else {
679                      prEntry->dot11RSNAConfigPairwiseCipherEnabled = FALSE;
680                  }
681                  break;
682             default:
683                  break;
684         }
685     }
686
687     /* Update the group cipher suite. */
688     if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_CCMP, &i)) {
689         prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_CCMP;
690     }
691     else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_TKIP, &i)) {
692         prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_TKIP;
693     }
694     else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP104, &i)) {
695         prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_WEP104;
696     }
697     else if (rsnSearchSupportedCipher(prAdapter, WPA_CIPHER_SUITE_WEP40, &i)) {
698         prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_WEP40;
699     }
700     else {
701         prMib->dot11RSNAConfigGroupCipher = WPA_CIPHER_SUITE_NONE;
702     }
703
704 }   /* secSetCipherSuite */
705
706
707 /*----------------------------------------------------------------------------*/
708 /*!
709 * \brief This routine is called to handle The 2nd Tx EAPoL Frame.
710 *
711 * \param[in] prAdapter Pointer to the Adapter structure
712 * \param[in] prMsduInfo pointer to the packet info pointer
713 * \param[in] pucPayload pointer to the 1x hdr
714 * \param[in] u2PayloadLen the 1x payload length
715 *
716 * \retval TRUE Accept the packet
717 * \retval FALSE Refuse the MSDU packet due port control
718 *
719 */
720 /*----------------------------------------------------------------------------*/
721 BOOL
722 secProcessEAPOL (
723     IN P_ADAPTER_T          prAdapter,
724     IN P_MSDU_INFO_T        prMsduInfo,
725     IN P_STA_RECORD_T       prStaRec,
726     IN PUINT_8              pucPayload,
727     IN UINT_16              u2PayloadLen
728 )
729 {
730     P_EAPOL_KEY             prEapol = (P_EAPOL_KEY)NULL;
731     P_IEEE_802_1X_HDR       pr1xHdr;
732     UINT_16                 u2KeyInfo;
733
734     ASSERT(prMsduInfo);
735     ASSERT(prStaRec);
736
737     //prStaRec = &(g_arStaRec[prMsduInfo->ucStaRecIndex]);
738     ASSERT(prStaRec);
739
740     if (prStaRec && IS_AP_STA(prStaRec)) {
741         pr1xHdr = (P_IEEE_802_1X_HDR)pucPayload;
742         if ((pr1xHdr->ucType == 3) /* EAPoL key */ && ((u2PayloadLen - 4) > sizeof(EAPOL_KEY))) {
743             prEapol = (P_EAPOL_KEY)((PUINT_32)(pucPayload + 4));
744             WLAN_GET_FIELD_BE16(prEapol->aucKeyInfo, &u2KeyInfo);
745             if ((prEapol->ucType == 254) && (u2KeyInfo & MASK_2ND_EAPOL)) {
746                 if (u2KeyInfo & WPA_KEY_INFO_SECURE) {
747                     /* 4th EAPoL check at secHandleTxDoneCallback() */
748                     //DBGLOG(RSN, TRACE, ("Tx 4th EAPoL frame\r\n"));
749                 }
750                 else if (u2PayloadLen == 123 /* Not include LLC */) {
751                     DBGLOG(RSN, INFO, ("Tx 2nd EAPoL frame\r\n"));
752                     secFsmEvent2ndEapolTx(prAdapter, prStaRec);
753                 }
754             }
755         }
756     }
757
758     return TRUE;
759 }
760
761
762 /*----------------------------------------------------------------------------*/
763 /*!
764 * \brief This function will handle the 4th EAPoL Tx done and mic Error Report frame.
765 *
766 * \param[in] prAdapter            Pointer to the Adapter structure
767 * \param[in] pMsduInfo            Pointer to the Msdu Info
768 * \param[in] rStatus                The Tx done status
769 *
770 * \return -
771 */
772 /*----------------------------------------------------------------------------*/
773 VOID
774 secHandleTxDoneCallback(
775     IN P_ADAPTER_T          prAdapter,
776     IN P_MSDU_INFO_T        prMsduInfo,
777     IN P_STA_RECORD_T       prStaRec,
778     IN WLAN_STATUS          rStatus
779     )
780 {
781     PUINT_8                 pucPayload;
782     P_IEEE_802_1X_HDR       pr1xHdr = (P_IEEE_802_1X_HDR)NULL;
783     P_EAPOL_KEY             prEapol = (P_EAPOL_KEY)NULL;
784     UINT_16                 u2KeyInfo;
785     UINT_16                 u2PayloadLen;
786
787     DEBUGFUNC("secHandleTxDoneCallback");
788
789     ASSERT(prMsduInfo);
790     //Todo:: Notice if using the TX free immediate after send to firmware, the payload may not correcttly!!!!
791
792     ASSERT(prStaRec);
793
794     //Todo:: This call back may not need because the order of set key and send 4th 1x can be make sure
795     //Todo:: Notice the LLC offset
796     #if 1
797     pucPayload = (PUINT_8)prMsduInfo->prPacket;
798     ASSERT(pucPayload);
799
800     u2PayloadLen = prMsduInfo->u2FrameLength;
801
802     if (0 /* prMsduInfo->fgIs1xFrame */) {
803
804         if (prStaRec && IS_AP_STA(prStaRec)) {
805             pr1xHdr = (P_IEEE_802_1X_HDR)(PUINT_32)(pucPayload + 8);
806             if ((pr1xHdr->ucType == 3) /* EAPoL key */ && ((u2PayloadLen - 4) > sizeof(EAPOL_KEY))) {
807                 prEapol = (P_EAPOL_KEY)(PUINT_32)(pucPayload + 12);
808                 WLAN_GET_FIELD_BE16(prEapol->aucKeyInfo, &u2KeyInfo);
809                 if ((prEapol->ucType == 254) && (u2KeyInfo & MASK_2ND_EAPOL)) {
810                     if (prStaRec->rSecInfo.fg2nd1xSend == TRUE && u2PayloadLen == 107 /* include LLC *//* u2KeyInfo & WPA_KEY_INFO_SECURE */) {
811                         DBGLOG(RSN, INFO, ("Tx 4th EAPoL frame\r\n"));
812                         secFsmEvent4ndEapolTxDone(prAdapter, prStaRec);
813                     }
814                     else if (prAdapter->rWifiVar.rAisSpecificBssInfo.fgCheckEAPoLTxDone){
815                         DBGLOG(RSN, INFO, ("Tx EAPoL Error report frame\r\n"));
816                         //secFsmEventEapolTxDone(prAdapter, (UINT_32)prMsduInfo->prStaRec);
817                     }
818                 }
819             }
820         }
821
822     }
823     #endif
824 }
825
826 /*----------------------------------------------------------------------------*/
827 /*!
828 * \brief This routine is called to initialize the pmkid parameters.
829 *
830 * \param[in] prAdapter Pointer to the Adapter structure
831 *
832 * \retval NONE
833 */
834 /*----------------------------------------------------------------------------*/
835 VOID
836 secClearPmkid (
837     IN P_ADAPTER_T          prAdapter
838     )
839 {
840     P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
841
842     DEBUGFUNC("secClearPmkid");
843
844     prAisSpecBssInfo = &prAdapter->rWifiVar.rAisSpecificBssInfo;
845     DBGLOG(RSN, TRACE, ("secClearPmkid\n"));
846     prAisSpecBssInfo->u4PmkidCandicateCount = 0;
847     prAisSpecBssInfo->u4PmkidCacheCount = 0;
848     kalMemZero((PVOID)prAisSpecBssInfo->arPmkidCandicate, sizeof(PMKID_CANDICATE_T) * CFG_MAX_PMKID_CACHE);
849     kalMemZero((PVOID)prAisSpecBssInfo->arPmkidCache, sizeof(PMKID_ENTRY_T) * CFG_MAX_PMKID_CACHE);
850 }
851
852
853 /*----------------------------------------------------------------------------*/
854 /*!
855 * \brief Whether WPA, or WPA2 but not WPA-None is enabled.
856 *
857 * \param[in] prAdapter Pointer to the Adapter structure
858 *
859 * \retval BOOLEAN
860 */
861 /*----------------------------------------------------------------------------*/
862 BOOLEAN
863 secRsnKeyHandshakeEnabled (
864     IN P_ADAPTER_T          prAdapter
865     )
866 {
867     P_CONNECTION_SETTINGS_T prConnSettings;
868
869     ASSERT(prAdapter);
870
871     prConnSettings = &prAdapter->rWifiVar.rConnSettings;
872
873     ASSERT(prConnSettings);
874
875     ASSERT(prConnSettings->eEncStatus < ENUM_ENCRYPTION3_KEY_ABSENT);
876
877     if (prConnSettings->eEncStatus == ENUM_ENCRYPTION_DISABLED) {
878         return FALSE;
879     }
880
881     ASSERT(prConnSettings->eAuthMode < AUTH_MODE_NUM);
882     if ((prConnSettings->eAuthMode >= AUTH_MODE_WPA) &&
883         (prConnSettings->eAuthMode != AUTH_MODE_WPA_NONE)) {
884         return TRUE;
885     }
886
887     return FALSE;
888 } /* secRsnKeyHandshakeEnabled */
889
890
891 /*----------------------------------------------------------------------------*/
892 /*!
893 * \brief Return whether the transmit key alread installed.
894 *
895 * \param[in] prAdapter Pointer to the Adapter structure
896 * \param[in] prSta Pointer the sta record
897 *
898 * \retval TRUE Default key or Transmit key installed
899 *         FALSE Default key or Transmit key not installed
900 *
901 * \note:
902 */
903 /*----------------------------------------------------------------------------*/
904 BOOLEAN
905 secTransmitKeyExist (
906     IN P_ADAPTER_T          prAdapter,
907     IN P_STA_RECORD_T       prSta
908     )
909 {
910     ASSERT(prSta);
911
912     if (prSta->fgTransmitKeyExist){
913         return TRUE;
914     }
915     else {
916         return FALSE;
917     }
918 } /* secTransmitKeyExist */
919
920
921 /*----------------------------------------------------------------------------*/
922 /*!
923 * \brief Whether 802.11 privacy is enabled.
924 *
925 * \param[in] prAdapter Pointer to the Adapter structure
926 *
927 * \retval BOOLEAN
928 */
929 /*----------------------------------------------------------------------------*/
930 BOOLEAN
931 secEnabledInAis (
932     IN P_ADAPTER_T          prAdapter
933     )
934 {
935     DEBUGFUNC("secEnabled");
936
937     ASSERT(prAdapter->rWifiVar.rConnSettings.eEncStatus < ENUM_ENCRYPTION3_KEY_ABSENT);
938
939     switch (prAdapter->rWifiVar.rConnSettings.eEncStatus) {
940         case ENUM_ENCRYPTION_DISABLED:
941             return FALSE;
942         case ENUM_ENCRYPTION1_ENABLED:
943         case ENUM_ENCRYPTION2_ENABLED:
944         case ENUM_ENCRYPTION3_ENABLED:
945             return TRUE;
946         default:
947             DBGLOG(RSN, TRACE, ("Unknown encryption setting %d\n",
948                 prAdapter->rWifiVar.rConnSettings.eEncStatus));
949             break;
950     }
951     return FALSE;
952 } /* secEnabled */
953
954
955 /*----------------------------------------------------------------------------*/
956 /*!
957 * \brief This routine is called to set the privacy bit at mac header for TxM
958 *
959 * \param[in] prAdapter Pointer to the Adapter structure
960 * \param[in] prMsdu the msdu for known the sta record
961 *
962 * \return TRUE the privacy need to set
963 *            FALSE the privacy no need to set
964 */
965 /*----------------------------------------------------------------------------*/
966 BOOLEAN
967 secIsProtectedFrame (
968     IN P_ADAPTER_T          prAdapter,
969     IN P_MSDU_INFO_T        prMsdu,
970     IN P_STA_RECORD_T       prStaRec
971     )
972 {
973     ASSERT(prAdapter);
974
975     ASSERT(prMsdu);
976
977     ASSERT(prStaRec);
978     //prStaRec = &(g_arStaRec[prMsdu->ucStaRecIndex]);
979
980     if (prStaRec == NULL) {
981         if (prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist)
982             return TRUE;
983         return FALSE; /* No privacy bit */
984     }
985
986     /* Todo:: */
987     if (0 /* prMsdu->fgIs1xFrame */){
988         if (IS_STA_IN_AIS(prStaRec) &&
989             prAdapter->rWifiVar.rConnSettings.eAuthMode < AUTH_MODE_WPA) {
990             DBGLOG(RSN, LOUD, ("For AIS Legacy 1x, always not encryped\n"));
991             return FALSE;
992         }
993         else if (!prStaRec->fgTransmitKeyExist) {
994             DBGLOG(RSN, LOUD, ("1x Not Protected.\n"));
995             return FALSE;
996         }
997         else if (prStaRec->rSecInfo.fgKeyStored) {
998             DBGLOG(RSN, LOUD, ("1x not Protected due key stored!\n"));
999             return FALSE;
1000         }
1001         else {
1002             DBGLOG(RSN, LOUD, ("1x Protected.\n"));
1003             return TRUE;
1004         }
1005     }
1006     else {
1007         if (!prStaRec->fgTransmitKeyExist) {
1008             /* whsu , check for AIS only */
1009             if (prAdapter->rWifiVar.rConnSettings.eAuthMode < AUTH_MODE_WPA &&
1010                 prAdapter->rWifiVar.rAisSpecificBssInfo.fgTransmitKeyExist){
1011                 DBGLOG(RSN, LOUD, ("Protected\n"));
1012                 return TRUE;
1013             }
1014         }
1015         else {
1016             DBGLOG(RSN, LOUD, ("Protected.\n"));
1017             return TRUE;
1018         }
1019     }
1020
1021     /* No sec or key is removed!!! */
1022     return FALSE;
1023 }
1024 #endif