2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: Handles the Basic Service Set & Node Database functions
25 * WPA_ParseRSN - Parse RSN IE.
36 #if !defined(__TTYPE_H__)
39 #if !defined(__UMEM_H__)
42 #if !defined(__TMACRO_H__)
45 #if !defined(__TETHER_H__)
48 #if !defined(__DEVICE_H__)
51 #if !defined(__80211HDR_H__)
54 #if !defined(__BSSDB_H__)
57 #if !defined(__WMGR_H__)
60 #if !defined(__WPA_H__)
63 #if !defined(__80211MGR_H__)
68 /*--------------------- Static Variables --------------------------*/
69 static int msglevel =MSG_LEVEL_INFO;
71 const BYTE abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
72 const BYTE abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
73 const BYTE abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
74 const BYTE abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
75 const BYTE abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
76 const BYTE abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
82 * Clear RSN information in BSSList.
86 * pBSSList - BSS list.
100 pBSSList->byGKType = WPA_TKIP;
101 for (ii=0; ii < 4; ii ++)
102 pBSSList->abyPKType[ii] = WPA_TKIP;
103 pBSSList->wPKCount = 0;
104 for (ii=0; ii < 4; ii ++)
105 pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
106 pBSSList->wAuthCount = 0;
107 pBSSList->byDefaultK_as_PK = 0;
108 pBSSList->byReplayIdx = 0;
109 pBSSList->sRSNCapObj.bRSNCapExist = FALSE;
110 pBSSList->sRSNCapObj.wRSNCap = 0;
111 pBSSList->bWPAValid = FALSE;
122 * pBSSList - BSS list.
123 * pRSN - Pointer to the RSN IE.
127 * Return Value: none.
132 IN PKnownBSS pBSSList,
133 IN PWLAN_IE_RSN_EXT pRSN
136 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
140 WPA_ClearRSN(pBSSList);
142 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
144 // information element header makes sense
145 if ((pRSN->len >= 6) // oui1(4)+ver(2)
146 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && MEMEqualMemory(pRSN->abyOUI, abyOUI01, 4)
147 && (pRSN->wVersion == 1)) {
149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
150 // update each variable if pRSN is long enough to contain the variable
151 if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
153 if (MEMEqualMemory(pRSN->abyMulticast, abyOUI01, 4))
154 pBSSList->byGKType = WPA_WEP40;
155 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI02, 4))
156 pBSSList->byGKType = WPA_TKIP;
157 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI03, 4))
158 pBSSList->byGKType = WPA_AESWRAP;
159 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI04, 4))
160 pBSSList->byGKType = WPA_AESCCMP;
161 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI05, 4))
162 pBSSList->byGKType = WPA_WEP104;
164 // any vendor checks here
165 pBSSList->byGKType = WPA_NONE;
167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byGKType: %x\n", pBSSList->byGKType);
170 if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
173 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %ld\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
174 for(i = 0; (i < pRSN->wPKCount) && (j < sizeof(pBSSList->abyPKType)/sizeof(BYTE)); i++) {
175 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
176 if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
177 pBSSList->abyPKType[j++] = WPA_NONE;
178 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
179 pBSSList->abyPKType[j++] = WPA_TKIP;
180 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
181 pBSSList->abyPKType[j++] = WPA_AESWRAP;
182 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
183 pBSSList->abyPKType[j++] = WPA_AESCCMP;
185 // any vendor checks here
190 //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
192 pBSSList->wPKCount = (WORD)j;
193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"m: %d\n", m);
198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+m*4: %d\n", 14+m*4);
200 if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
201 // overlay IE_RSN_Auth structure into correct place
202 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %ld\n",
205 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
206 for(i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < sizeof(pBSSList->abyAuthType)/sizeof(BYTE)); i++) {
207 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
208 if (MEMEqualMemory(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
209 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
210 else if (MEMEqualMemory(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
211 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
213 // any vendor checks here
218 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
221 pBSSList->wAuthCount = (WORD)j;
222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
225 if (pIE_RSN_Auth != NULL) {
227 n = pIE_RSN_Auth->wAuthCount;
229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"n: %d\n", n);
230 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
232 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)
233 pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI;
234 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
235 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
236 pBSSList->sRSNCapObj.bRSNCapExist = TRUE;
237 pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps;
238 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
239 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
240 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
243 pBSSList->bWPAValid = TRUE;
250 * Search RSN information in BSSList.
254 * byCmd - Search type
255 * byEncrypt- Encrcypt Type
256 * pBSSList - BSS list
260 * Return Value: none.
267 IN PKnownBSS pBSSList
271 BYTE byPKType = WPA_NONE;
273 if (pBSSList->bWPAValid == FALSE)
279 if (byEncrypt != pBSSList->byGKType)
282 if (pBSSList->wPKCount > 0) {
283 for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
284 if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
285 byPKType = WPA_AESCCMP;
286 else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
288 else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
289 byPKType = WPA_WEP40;
290 else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
291 byPKType = WPA_WEP104;
293 if (byEncrypt != byPKType)
297 // if (pBSSList->wAuthCount > 0)
298 // for (ii=0; ii < pBSSList->wAuthCount; ii ++)
299 // if (byAuth == pBSSList->abyAuthType[ii])
312 * Check if RSN IE makes sense.
316 * pRSN - Pointer to the RSN IE.
320 * Return Value: none.
325 IN PWLAN_IE_RSN_EXT pRSN
331 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
332 (pRSN->byElementID == WLAN_EID_RSN_WPA) && MEMEqualMemory(pRSN->abyOUI, abyOUI01, 4) &&
333 (pRSN->wVersion == 1)) {