2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/mgmt/wapi.c#1 $
6 \brief This file including the WAPI related function.
8 This file provided the macros and functions library support the wapi ie parsing,
9 cipher and AKM check to help the AP seleced deciding.
12 /*******************************************************************************
13 * Copyright (c) 2009 MediaTek Inc.
15 * All rights reserved. Copying, compilation, modification, distribution
16 * or any other use whatsoever of this material is strictly prohibited
17 * except in accordance with a Software License Agreement with
19 ********************************************************************************
22 /*******************************************************************************
25 * Copyright (c) 2008 MediaTek Inc. ALL RIGHTS RESERVED.
27 * BY OPENING OR USING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES
28 * AND AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS (¡§MEDIATEK
29 * SOFTWARE¡¨)RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
30 * PROVIDED TO BUYER ON AN ¡§AS IS¡¨ BASIS ONLY. MEDIATEK EXPRESSLY
31 * DISCLAIMS ANY AND ALL WARRANTIES, WHETHER EXPRESS OR IMPLIED, INCLUDING
32 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
33 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. NOR DOES MEDIATEK PROVIDE
34 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTIES
35 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE.
36 * BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTIES FOR ANY AND ALL
37 * WARRANTY CLAIMS RELATING THERETO. MEDIATEK SHALL NOT BE RESPONSIBLE FOR
38 * ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER¡¦S SPECIFICATION OR CONFORMING
39 * TO A PARTICULAR STANDARD OR OPEN FORUM.
41 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
42 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER SHALL BE,
43 * AT MEDIATEK'S SOLE OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE
44 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGES PAID BY BUYER TO
45 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE.
47 * THE MEDIATEK SOFTWARE IS PROVIDED FOR AND ONLY FOR USE WITH MEDIATEK CHIPS
48 * OR PRODUCTS. EXCEPT AS EXPRESSLY PROVIDED, NO LICENSE IS GRANTED BY
49 * IMPLICATION OR OTHERWISE UNDER ANY INTELLECTUAL PROPERTY RIGHTS, INCLUDING
50 * PATENT OR COPYRIGHTS, OF MEDIATEK. UNAUTHORIZED USE, REPRODUCTION, OR
51 * DISCLOSURE OF THE MEDIATEK SOFTWARE IN WHOLE OR IN PART IS STRICTLY PROHIBITED.
53 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE WITH
54 * THE LAWS OF THE REPUBLIC OF SINGAPORE, EXCLUDING ITS CONFLICT OF LAWS
55 * PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS RELATING HERETO OR ARISING
56 * HEREFROM SHALL BE EXCLUSIVELY SETTLED VIA ARBITRATION IN SINGAPORE UNDER THE
57 * THEN CURRENT ARBITRAL RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE.
58 * THE LANGUAGE OF ARBITRATION SHALL BE ENGLISH. THE AWARDS OF THE ARBITRATION
59 * SHALL BE FINAL AND BINDING UPON BOTH PARTIES AND SHALL BE ENTERED AND
60 * ENFORCEABLE IN ANY COURT OF COMPETENT JURISDICTION.
61 ********************************************************************************
68 * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
69 * change the debug module level.
72 * [WCXRP00000577] [MT6620 Wi-Fi][Driver][FW] Create V2.0 branch for firmware and driver
73 * create V2.0 driver release based on label "MT6620_WIFI_DRIVER_V2_0_110318_1600" from main trunk
76 * [WCXRP00000067] [MT6620 Wi-Fi][Driver] Support the android+ WAPI function
77 * fixed the network type
81 * adding the wapi support for integration test.
88 * [BORA00000680][MT6620] Support the statistic for Microsoft os query
89 * fixed the firmware return the broadcast frame at wrong tc.
92 * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
93 * move the AIS specific variable for security to AIS specific structure.
96 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
100 * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
101 * adding the function to check and update the default wapi tx
103 * Dec 7 2009 mtk01088
104 * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
105 * adding the generate wapi ie function, and replace the tabe by space
107 * Nov 23 2009 mtk01088
108 * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
112 /*******************************************************************************
113 * C O M P I L E R F L A G S
114 ********************************************************************************
117 /*******************************************************************************
118 * E X T E R N A L R E F E R E N C E S
119 ********************************************************************************
125 /*******************************************************************************
127 ********************************************************************************
130 /*******************************************************************************
132 ********************************************************************************
135 /*******************************************************************************
136 * P U B L I C D A T A
137 ********************************************************************************
140 /*******************************************************************************
141 * P R I V A T E D A T A
142 ********************************************************************************
145 /*******************************************************************************
147 ********************************************************************************
150 /*******************************************************************************
151 * F U N C T I O N D E C L A R A T I O N S
152 ********************************************************************************
155 /*******************************************************************************
157 ********************************************************************************
160 /*----------------------------------------------------------------------------*/
163 * \brief This routine is called to generate WPA IE for
164 * associate request frame.
166 * \param[in] prCurrentBss The Selected BSS description
168 * \retval The append WPA IE length
171 * Called by: AIS module, Associate request
173 /*----------------------------------------------------------------------------*/
176 IN P_ADAPTER_T prAdapter,
177 IN P_MSDU_INFO_T prMsduInfo
185 if (prMsduInfo->ucNetworkType != NETWORK_TYPE_AIS_INDEX)
188 pucBuffer = (PUINT_8)((UINT_32)prMsduInfo->prPacket +
189 (UINT_32)prMsduInfo->u2FrameLength);
191 /* ASSOC INFO IE ID: 68 :0x44 */
192 if (/* prWlanInfo->fgWapiMode && */ prAdapter->prGlueInfo->u2WapiAssocInfoIESz) {
193 kalMemCopy(pucBuffer, &prAdapter->prGlueInfo->aucWapiAssocInfoIEs, prAdapter->prGlueInfo->u2WapiAssocInfoIESz);
194 prMsduInfo->u2FrameLength += prAdapter->prGlueInfo->u2WapiAssocInfoIESz;
200 /*----------------------------------------------------------------------------*/
202 * \brief This routine is called to parse WAPI IE.
204 * \param[in] prInfoElem Pointer to the RSN IE
205 * \param[out] prRsnInfo Pointer to the BSSDescription structure to store the
206 ** WAPI information from the given WAPI IE
208 * \retval TRUE - Succeeded
209 * \retval FALSE - Failed
211 /*----------------------------------------------------------------------------*/
214 IN P_WAPI_INFO_ELEM_T prInfoElem,
215 OUT P_WAPI_INFO_T prWapiInfo
219 INT_32 u4RemainWapiIeLen;
222 UINT_32 u4GroupSuite = WAPI_CIPHER_SUITE_WPI;
223 UINT_16 u2PairSuiteCount = 0;
224 UINT_16 u2AuthSuiteCount = 0;
225 PUCHAR pucPairSuite = NULL;
226 PUCHAR pucAuthSuite = NULL;
229 DEBUGFUNC("wapiParseWapiIE");
234 /* Verify the length of the WAPI IE. */
235 if (prInfoElem->ucLength < 6) {
236 DBGLOG(SEC, TRACE, ("WAPI IE length too short (length=%d)\n", prInfoElem->ucLength));
240 /* Check WAPI version: currently, we only support version 1. */
241 WLAN_GET_FIELD_16(&prInfoElem->u2Version, &u2Version);
242 if (u2Version != 1) {
243 DBGLOG(SEC, TRACE, ("Unsupported WAPI IE version: %d\n", u2Version));
247 cp = (PUCHAR) &prInfoElem->u2AuthKeyMgtSuiteCount;
248 u4RemainWapiIeLen = (INT_32) prInfoElem->ucLength - 2;
251 if (u4RemainWapiIeLen == 0) {
257 AuthSuite : 4 * authSuiteCount
259 PairwiseSuite: 4 * pairSuiteCount
263 /* Parse the Authentication and Key Management Cipher Suite Count
265 if (u4RemainWapiIeLen < 2) {
266 DBGLOG(SEC, TRACE, ("Fail to parse WAPI IE in auth & key mgt suite count (IE len: %d)\n",
267 prInfoElem->ucLength));
271 WLAN_GET_FIELD_16(cp, &u2AuthSuiteCount);
273 u4RemainWapiIeLen -= 2;
275 /* Parse the Authentication and Key Management Cipher Suite List
277 i = (UINT_32) u2AuthSuiteCount * 4;
278 if (u4RemainWapiIeLen < (INT_32) i) {
279 DBGLOG(SEC, TRACE, ("Fail to parse WAPI IE in auth & key mgt suite list (IE len: %d)\n",
280 prInfoElem->ucLength));
287 u4RemainWapiIeLen -= (INT_32) i;
289 if (u4RemainWapiIeLen == 0) {
293 /* Parse the Pairwise Key Cipher Suite Count field. */
294 if (u4RemainWapiIeLen < 2) {
295 DBGLOG(SEC, TRACE, ("Fail to parse WAPI IE in pairwise cipher suite count (IE len: %d)\n",
296 prInfoElem->ucLength));
300 WLAN_GET_FIELD_16(cp, &u2PairSuiteCount);
302 u4RemainWapiIeLen -= 2;
304 /* Parse the Pairwise Key Cipher Suite List field. */
305 i = (UINT_32) u2PairSuiteCount * 4;
306 if (u4RemainWapiIeLen < (INT_32) i) {
307 DBGLOG(SEC, TRACE, ("Fail to parse WAPI IE in pairwise cipher suite list (IE len: %d)\n",
308 prInfoElem->ucLength));
315 u4RemainWapiIeLen -= (INT_32) i;
317 /* Parse the Group Key Cipher Suite field. */
318 if (u4RemainWapiIeLen < 4) {
319 DBGLOG(SEC, TRACE, ("Fail to parse WAPI IE in group cipher suite (IE len: %d)\n",
320 prInfoElem->ucLength));
324 WLAN_GET_FIELD_32(cp, &u4GroupSuite);
326 u4RemainWapiIeLen -= 4;
328 /* Parse the WAPI u2Capabilities field. */
329 if (u4RemainWapiIeLen < 2) {
330 DBGLOG(SEC, TRACE, ("Fail to parse WAPI IE in WAPI capabilities (IE len: %d)\n",
331 prInfoElem->ucLength));
335 WLAN_GET_FIELD_16(cp, &u2Cap);
336 u4RemainWapiIeLen -= 2;
338 /* Todo:: BKID support */
341 /* Save the WAPI information for the BSS. */
343 prWapiInfo->ucElemId = ELEM_ID_WAPI;
345 prWapiInfo->u2Version = u2Version;
347 prWapiInfo->u4GroupKeyCipherSuite = u4GroupSuite;
349 DBGLOG(SEC, LOUD, ("WAPI: version %d, group key cipher suite %02x-%02x-%02x-%02x\n",
350 u2Version, (UCHAR) (u4GroupSuite & 0x000000FF),
351 (UCHAR) ((u4GroupSuite >> 8) & 0x000000FF),
352 (UCHAR) ((u4GroupSuite >> 16) & 0x000000FF),
353 (UCHAR) ((u4GroupSuite >> 24) & 0x000000FF)));
356 /* The information about the pairwise key cipher suites is present. */
357 if (u2PairSuiteCount > MAX_NUM_SUPPORTED_CIPHER_SUITES) {
358 u2PairSuiteCount = MAX_NUM_SUPPORTED_CIPHER_SUITES;
361 prWapiInfo->u4PairwiseKeyCipherSuiteCount = (UINT_32) u2PairSuiteCount;
363 for (i = 0; i < (UINT_32) u2PairSuiteCount; i++) {
364 WLAN_GET_FIELD_32(pucPairSuite,
365 &prWapiInfo->au4PairwiseKeyCipherSuite[i]);
368 DBGLOG(SEC, LOUD,("WAPI: pairwise key cipher suite [%d]: %02x-%02x-%02x-%02x\n",
369 (UINT_8)i, (UCHAR) (prWapiInfo->au4PairwiseKeyCipherSuite[i] & 0x000000FF),
370 (UCHAR) ((prWapiInfo->au4PairwiseKeyCipherSuite[i] >> 8) & 0x000000FF),
371 (UCHAR) ((prWapiInfo->au4PairwiseKeyCipherSuite[i] >> 16) & 0x000000FF),
372 (UCHAR) ((prWapiInfo->au4PairwiseKeyCipherSuite[i] >> 24) & 0x000000FF)));
376 /* The information about the pairwise key cipher suites is not present.
377 Use the default chipher suite for WAPI: WPI. */
378 prWapiInfo->u4PairwiseKeyCipherSuiteCount = 1;
379 prWapiInfo->au4PairwiseKeyCipherSuite[0] = WAPI_CIPHER_SUITE_WPI;
381 DBGLOG(SEC, LOUD, ("WAPI: pairwise key cipher suite: %02x-%02x-%02x-%02x (default)\n",
382 (UCHAR) (prWapiInfo->au4PairwiseKeyCipherSuite[0] & 0x000000FF),
383 (UCHAR) ((prWapiInfo->au4PairwiseKeyCipherSuite[0] >> 8) & 0x000000FF),
384 (UCHAR) ((prWapiInfo->au4PairwiseKeyCipherSuite[0] >> 16) & 0x000000FF),
385 (UCHAR) ((prWapiInfo->au4PairwiseKeyCipherSuite[0] >> 24) & 0x000000FF)));
389 /* The information about the authentication and key management suites
391 if (u2AuthSuiteCount > MAX_NUM_SUPPORTED_AKM_SUITES) {
392 u2AuthSuiteCount = MAX_NUM_SUPPORTED_AKM_SUITES;
395 prWapiInfo->u4AuthKeyMgtSuiteCount = (UINT_32) u2AuthSuiteCount;
397 for (i = 0; i < (UINT_32) u2AuthSuiteCount; i++) {
398 WLAN_GET_FIELD_32(pucAuthSuite, &prWapiInfo->au4AuthKeyMgtSuite[i]);
401 DBGLOG(SEC, LOUD, ("WAPI: AKM suite [%d]: %02x-%02x-%02x-%02x\n",
402 (UINT_8)i, (UCHAR) (prWapiInfo->au4AuthKeyMgtSuite[i] & 0x000000FF),
403 (UCHAR) ((prWapiInfo->au4AuthKeyMgtSuite[i] >> 8) & 0x000000FF),
404 (UCHAR) ((prWapiInfo->au4AuthKeyMgtSuite[i] >> 16) & 0x000000FF),
405 (UCHAR) ((prWapiInfo->au4AuthKeyMgtSuite[i] >> 24) & 0x000000FF)));
409 /* The information about the authentication and key management suites
410 is not present. Use the default AKM suite for WAPI. */
411 prWapiInfo->u4AuthKeyMgtSuiteCount = 1;
412 prWapiInfo->au4AuthKeyMgtSuite[0] = WAPI_AKM_SUITE_802_1X;
414 DBGLOG(SEC, LOUD, ("WAPI: AKM suite: %02x-%02x-%02x-%02x (default)\n",
415 (UCHAR) (prWapiInfo->au4AuthKeyMgtSuite[0] & 0x000000FF),
416 (UCHAR) ((prWapiInfo->au4AuthKeyMgtSuite[0] >> 8) & 0x000000FF),
417 (UCHAR) ((prWapiInfo->au4AuthKeyMgtSuite[0] >> 16) & 0x000000FF),
418 (UCHAR) ((prWapiInfo->au4AuthKeyMgtSuite[0] >> 24) & 0x000000FF)));
421 prWapiInfo->u2WapiCap = u2Cap;
422 DBGLOG(SEC, LOUD, ("WAPI: cap: 0x%04x\n", prWapiInfo->u2WapiCap));
425 } /* wapiParseWapiIE */
428 /*----------------------------------------------------------------------------*/
430 * \brief This routine is called to perform WAPI policy selection for a given BSS.
432 * \param[in] prAdapter Pointer to the adapter object data area.
433 * \param[in] prBss Pointer to the BSS description
435 * \retval TRUE - The WAPI policy selection for the given BSS is
436 * successful. The selected pairwise and group cipher suites
437 * are returned in the BSS description.
438 * \retval FALSE - The WAPI policy selection for the given BSS is failed.
439 * The driver shall not attempt to join the given BSS.
441 * \note The Encrypt status matched score will save to bss for final ap select.
443 /*----------------------------------------------------------------------------*/
445 wapiPerformPolicySelection (
446 IN P_ADAPTER_T prAdapter,
447 IN P_BSS_DESC_T prBss
451 UINT_32 u4PairwiseCipher = 0;
452 UINT_32 u4GroupCipher = 0;
453 UINT_32 u4AkmSuite = 0;
454 P_WAPI_INFO_T prBssWapiInfo;
455 P_WLAN_INFO_T prWlanInfo;
457 DEBUGFUNC("wapiPerformPolicySelection");
461 /* Notice!!!! WAPI AP not set the privacy bit for WAI and WAI-PSK at WZC configuration mode */
462 prWlanInfo = &prAdapter->rWlanInfo;
464 if (prBss->fgIEWAPI) {
465 prBssWapiInfo = &prBss->rIEWAPI;
468 if (prAdapter->rWifiVar.rConnSettings.fgWapiMode == FALSE) {
469 DBGLOG(SEC, TRACE,("-- No Protected BSS\n"));
473 DBGLOG(SEC, TRACE, ("WAPI Information Element does not exist.\n"));
478 /* Select pairwise/group ciphers */
479 for (i = 0; i < prBssWapiInfo->u4PairwiseKeyCipherSuiteCount; i++) {
480 if (prBssWapiInfo->au4PairwiseKeyCipherSuite[i] ==
481 prAdapter->rWifiVar.rConnSettings.u4WapiSelectedPairwiseCipher) {
482 u4PairwiseCipher = prBssWapiInfo->au4PairwiseKeyCipherSuite[i];
485 if (prBssWapiInfo->u4GroupKeyCipherSuite ==
486 prAdapter->rWifiVar.rConnSettings.u4WapiSelectedGroupCipher)
487 u4GroupCipher = prBssWapiInfo->u4GroupKeyCipherSuite;
489 /* Exception handler */
490 /* If we cannot find proper pairwise and group cipher suites to join the
491 BSS, do not check the supported AKM suites. */
492 if (u4PairwiseCipher == 0 || u4GroupCipher == 0) {
493 DBGLOG(SEC, TRACE, ("Failed to select pairwise/group cipher (0x%08lx/0x%08lx)\n",
494 u4PairwiseCipher, u4GroupCipher));
499 /* If the driver cannot support any authentication suites advertised in
500 the given BSS, we fail to perform RSNA policy selection. */
501 /* Attempt to find any overlapping supported AKM suite. */
502 for (i = 0; i < prBssWapiInfo->u4AuthKeyMgtSuiteCount; i++) {
503 if (prBssWapiInfo->au4AuthKeyMgtSuite[i] == prAdapter->rWifiVar.rConnSettings.u4WapiSelectedAKMSuite) {
504 u4AkmSuite = prBssWapiInfo->au4AuthKeyMgtSuite[i];
509 if (u4AkmSuite == 0) {
510 DBGLOG(SEC, TRACE, ("Cannot support any AKM suites\n"));
514 DBGLOG(SEC, TRACE, ("Selected pairwise/group cipher: %02x-%02x-%02x-%02x/%02x-%02x-%02x-%02x\n",
515 (UINT_8) (u4PairwiseCipher & 0x000000FF),
516 (UINT_8) ((u4PairwiseCipher >> 8) & 0x000000FF),
517 (UINT_8) ((u4PairwiseCipher >> 16) & 0x000000FF),
518 (UINT_8) ((u4PairwiseCipher >> 24) & 0x000000FF),
519 (UINT_8) (u4GroupCipher & 0x000000FF),
520 (UINT_8) ((u4GroupCipher >> 8) & 0x000000FF),
521 (UINT_8) ((u4GroupCipher >> 16) & 0x000000FF),
522 (UINT_8) ((u4GroupCipher >> 24) & 0x000000FF)));
524 DBGLOG(SEC, TRACE, ("Selected AKM suite: %02x-%02x-%02x-%02x\n",
525 (UINT_8) (u4AkmSuite & 0x000000FF),
526 (UINT_8) ((u4AkmSuite >> 8) & 0x000000FF),
527 (UINT_8) ((u4AkmSuite >> 16) & 0x000000FF),
528 (UINT_8) ((u4AkmSuite >> 24) & 0x000000FF)));
531 } /* wapiPerformPolicySelection */
534 /*----------------------------------------------------------------------------*/
536 * \brief This routine is use for wapi mode, to update the current wpi tx idx ? 0 :1 .
538 * \param[in] prStaRec Pointer to the Sta record
539 * \param[out] ucWlanIdx The Rx status->wlanidx field
541 * \retval TRUE - Succeeded
542 * \retval FALSE - Failed
544 /*----------------------------------------------------------------------------*/
547 IN P_STA_RECORD_T prStaRec,
553 if ((ucWlanIdx & BITS(0, 3)) == CIPHER_SUITE_WPI) {
555 ucKeyId = ((ucWlanIdx & BITS(4, 5)) >> 4);
557 if (ucKeyId != g_prWifiVar->rAisSpecificBssInfo.ucWpiActivedPWKey) {
558 DBGLOG(RSN, STATE, ("Change wapi key index from %d->%d\n", g_prWifiVar->rAisSpecificBssInfo.ucWpiActivedPWKey, ucKeyId));
559 g_prWifiVar->rAisSpecificBssInfo.ucWpiActivedPWKey = ucKeyId;
561 prStaRec->ucWTEntry =
562 (ucKeyId == WTBL_AIS_BSSID_WAPI_IDX_0) ? WTBL_AIS_BSSID_WAPI_IDX_0 : WTBL_AIS_BSSID_WAPI_IDX_1;