192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*
292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * All rights reserved.
492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * This program is free software; you can redistribute it and/or modify
692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * it under the terms of the GNU General Public License as published by
792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * the Free Software Foundation; either version 2 of the License, or
892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * (at your option) any later version.
992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
1092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * This program is distributed in the hope that it will be useful,
1192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * but WITHOUT ANY WARRANTY; without even the implied warranty of
1292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * GNU General Public License for more details.
1492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
1592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * You should have received a copy of the GNU General Public License along
1692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * with this program; if not, write to the Free Software Foundation, Inc.,
1792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
1992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * File: wpa.c
2192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Purpose: Handles the Basic Service Set & Node Database functions
2392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Functions:
2592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      WPA_ParseRSN - Parse RSN IE.
2692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Revision History:
2892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Author: Kyle Hsu
3092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
3192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Date: July 14, 2003
3292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
3392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond */
3492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
3592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "ttype.h"
3692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "tmacro.h"
3792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "tether.h"
3892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "device.h"
3992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "80211hdr.h"
4092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "bssdb.h"
4192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "wmgr.h"
4292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "wpa.h"
4392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "80211mgr.h"
4492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
4592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*---------------------  Static Variables  --------------------------*/
4692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondstatic int          msglevel                =MSG_LEVEL_INFO;
4792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
4892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondconst BYTE abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
4992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondconst BYTE abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
5092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondconst BYTE abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
5192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondconst BYTE abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
5292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondconst BYTE abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
5392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bondconst BYTE abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
5492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
5592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
5692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*+
5792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
5892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Description:
5992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *    Clear RSN information in BSSList.
6092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
6192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Parameters:
6292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  In:
6392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      pBSSList - BSS list.
6492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  Out:
6592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      none
6692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
6792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Return Value: none.
6892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
6992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond-*/
7092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
718611a29ab967bc197494db19d31994d1b5a26fdcAndres Morevoid
7262e7e9614849c1a05ab8d18c07cb086304568629Victor RosalesWPA_ClearRSN(
73592ccfebb3d7ae6d2fa367b97f080790befa3c6cAndres More     PKnownBSS        pBSSList
7492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    )
7592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond{
7692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    int ii;
7792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->byGKType = WPA_TKIP;
7892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    for (ii=0; ii < 4; ii ++)
7992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        pBSSList->abyPKType[ii] = WPA_TKIP;
8092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->wPKCount = 0;
8192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    for (ii=0; ii < 4; ii ++)
8292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
8392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->wAuthCount = 0;
8492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->byDefaultK_as_PK = 0;
8592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->byReplayIdx = 0;
8692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->sRSNCapObj.bRSNCapExist = FALSE;
8792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->sRSNCapObj.wRSNCap = 0;
8892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    pBSSList->bWPAValid = FALSE;
8992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond}
9092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
9192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
9292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*+
9392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
9492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Description:
9592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *    Parse RSN IE.
9692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
9792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Parameters:
9892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  In:
9992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      pBSSList - BSS list.
10092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      pRSN - Pointer to the RSN IE.
10192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  Out:
10292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      none
10392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
10492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Return Value: none.
10592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
10692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond-*/
1078611a29ab967bc197494db19d31994d1b5a26fdcAndres Morevoid
10862e7e9614849c1a05ab8d18c07cb086304568629Victor RosalesWPA_ParseRSN(
109592ccfebb3d7ae6d2fa367b97f080790befa3c6cAndres More     PKnownBSS        pBSSList,
110592ccfebb3d7ae6d2fa367b97f080790befa3c6cAndres More     PWLAN_IE_RSN_EXT pRSN
11192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    )
11292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond{
11392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    PWLAN_IE_RSN_AUTH  pIE_RSN_Auth = NULL;
11492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    int                i, j, m, n = 0;
11592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    PBYTE              pbyCaps;
11692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
11792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    WPA_ClearRSN(pBSSList);
11892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
11992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
12092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
12192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    // information element header makes sense
12292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    if ((pRSN->len >= 6) // oui1(4)+ver(2)
1233e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb         && (pRSN->byElementID == WLAN_EID_RSN_WPA) &&  !memcmp(pRSN->abyOUI, abyOUI01, 4)
12492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond         && (pRSN->wVersion == 1)) {
12592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
12692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
12792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        // update each variable if pRSN is long enough to contain the variable
12892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
12992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        {
1303e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb            if ( !memcmp(pRSN->abyMulticast, abyOUI01, 4))
13192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byGKType = WPA_WEP40;
1323e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb            else if ( !memcmp(pRSN->abyMulticast, abyOUI02, 4))
13392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byGKType = WPA_TKIP;
1343e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb            else if ( !memcmp(pRSN->abyMulticast, abyOUI03, 4))
13592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byGKType = WPA_AESWRAP;
1363e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb            else if ( !memcmp(pRSN->abyMulticast, abyOUI04, 4))
13792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byGKType = WPA_AESCCMP;
1383e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb            else if ( !memcmp(pRSN->abyMulticast, abyOUI05, 4))
13992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byGKType = WPA_WEP104;
14092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            else
14192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                // any vendor checks here
14292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byGKType = WPA_NONE;
14392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
14492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byGKType: %x\n", pBSSList->byGKType);
14592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        }
14692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
14792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
14892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        {
14992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            j = 0;
150988536981327c9b8d28a6e956de285791e137cd3Randy Dunlap            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
15133d33e42b647095b01b1223c7b88718584129d2eAndres More	    for (i = 0; (i < pRSN->wPKCount) &&
15233d33e42b647095b01b1223c7b88718584129d2eAndres More		   (j < sizeof(pBSSList->abyPKType)/sizeof(BYTE)); i++) {
15392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
1543e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb                    if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
15592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        pBSSList->abyPKType[j++] = WPA_NONE;
1563e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb                    else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
15792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        pBSSList->abyPKType[j++] = WPA_TKIP;
1583e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb                    else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
15992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        pBSSList->abyPKType[j++] = WPA_AESWRAP;
1603e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb                    else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
16192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        pBSSList->abyPKType[j++] = WPA_AESCCMP;
16292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    else
16392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        // any vendor checks here
16492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        ;
16592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                }
16692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                else
16792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    break;
16892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
16992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            } //for
17092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            pBSSList->wPKCount = (WORD)j;
17192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
17292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        }
17392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
17492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        m = pRSN->wPKCount;
17592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"m: %d\n", m);
17692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+m*4: %d\n", 14+m*4);
17792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
17892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
17992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            // overlay IE_RSN_Auth structure into correct place
18092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
18192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            j = 0;
182988536981327c9b8d28a6e956de285791e137cd3Randy Dunlap            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
18392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                          pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
18433d33e42b647095b01b1223c7b88718584129d2eAndres More	    for (i = 0; (i < pIE_RSN_Auth->wAuthCount) &&
18533d33e42b647095b01b1223c7b88718584129d2eAndres More		   (j < sizeof(pBSSList->abyAuthType)/sizeof(BYTE)); i++) {
18692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
1873e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb                    if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
18892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
1893e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb                    else if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
19092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                        pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
19192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    else
19292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    // any vendor checks here
19392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    ;
19492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                }
19592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                else
19692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    break;
19792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
19892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            }
19992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            if(j > 0)
20092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->wAuthCount = (WORD)j;
20192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
20292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        }
20392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
20492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        if (pIE_RSN_Auth != NULL) {
20592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
20692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            n = pIE_RSN_Auth->wAuthCount;
20792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
20892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"n: %d\n", n);
20992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
21092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
21192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            if(pRSN->len+2 >= 14+4+(m+n)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*n)+Cap(2)
21292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI;
21392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
21492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
21592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->sRSNCapObj.bRSNCapExist = TRUE;
21692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps;
21792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
21892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
21992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
22092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            }
22192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        }
22292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        pBSSList->bWPAValid = TRUE;
22392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    }
22492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond}
22592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
22692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*+
22792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
22892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Description:
22992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *    Search RSN information in BSSList.
23092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
23192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Parameters:
23292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  In:
23392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      byCmd    - Search type
23492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      byEncrypt- Encrcypt Type
23592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      pBSSList - BSS list
23692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  Out:
23792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      none
23892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
23992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Return Value: none.
24092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
24192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond-*/
24292b96797118e5836294a6d42a5a8e10b86f50e3fForest BondBOOL
24362e7e9614849c1a05ab8d18c07cb086304568629Victor RosalesWPA_SearchRSN(
24492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    BYTE                byCmd,
24592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    BYTE                byEncrypt,
246592ccfebb3d7ae6d2fa367b97f080790befa3c6cAndres More     PKnownBSS        pBSSList
24792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    )
24892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond{
24992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    int ii;
25092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    BYTE byPKType = WPA_NONE;
25192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
25292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    if (pBSSList->bWPAValid == FALSE)
25392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        return FALSE;
25492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
25592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    switch(byCmd) {
25692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    case 0:
25792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
25892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        if (byEncrypt != pBSSList->byGKType)
25992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            return FALSE;
26092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
26192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        if (pBSSList->wPKCount > 0) {
26292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
26392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
26492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                    byPKType = WPA_AESCCMP;
26592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
26692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                     byPKType = WPA_TKIP;
26792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
26892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                     byPKType = WPA_WEP40;
26992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
27092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                     byPKType = WPA_WEP104;
27192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            }
27292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond            if (byEncrypt != byPKType)
27392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond                return FALSE;
27492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        }
27592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        return TRUE;
27692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond//        if (pBSSList->wAuthCount > 0)
27792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond//            for (ii=0; ii < pBSSList->wAuthCount; ii ++)
27892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond//                if (byAuth == pBSSList->abyAuthType[ii])
27992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond//                    break;
28092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        break;
28192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
28292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    default:
28392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        break;
28492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    }
28592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    return FALSE;
28692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond}
28792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
28892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*+
28992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
29092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Description:
29192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *    Check if RSN IE makes sense.
29292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
29392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Parameters:
29492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  In:
29592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      pRSN - Pointer to the RSN IE.
29692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *  Out:
29792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *      none
29892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
29992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Return Value: none.
30092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
30192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond-*/
30292b96797118e5836294a6d42a5a8e10b86f50e3fForest BondBOOL
30362e7e9614849c1a05ab8d18c07cb086304568629Victor RosalesWPAb_Is_RSN(
304592ccfebb3d7ae6d2fa367b97f080790befa3c6cAndres More     PWLAN_IE_RSN_EXT pRSN
30592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    )
30692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond{
30792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    if (pRSN == NULL)
30892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        return FALSE;
30992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
31092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    if ((pRSN->len >= 6) && // oui1(4)+ver(2)
3113e362598fd3c7b8729afd0383a4cdf08849b020eJim Lieb        (pRSN->byElementID == WLAN_EID_RSN_WPA) &&  !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
31292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        (pRSN->wVersion == 1)) {
31392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        return TRUE;
31492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    }
31592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond    else
31692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond        return FALSE;
31792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond}
31892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
319