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
28 * Author: Yiching Chen
39 /*--------------------- Static Definitions -------------------------*/
40 static int msglevel =MSG_LEVEL_INFO;
41 //static int msglevel =MSG_LEVEL_DEBUG;
42 /*--------------------- Static Classes ----------------------------*/
44 /*--------------------- Static Variables --------------------------*/
46 const BYTE abyOUIGK[4] = { 0x00, 0x0F, 0xAC, 0x00 };
47 const BYTE abyOUIWEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 };
48 const BYTE abyOUIWEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 };
49 const BYTE abyOUITKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 };
50 const BYTE abyOUICCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 };
52 const BYTE abyOUI8021X[4] = { 0x00, 0x0F, 0xAC, 0x01 };
53 const BYTE abyOUIPSK[4] = { 0x00, 0x0F, 0xAC, 0x02 };
56 /*--------------------- Static Functions --------------------------*/
58 /*--------------------- Export Variables --------------------------*/
60 /*--------------------- Export Functions --------------------------*/
65 * Clear RSN information in BSSList.
69 * pBSSNode - BSS list.
83 pBSSNode->bWPA2Valid = FALSE;
85 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
86 for (ii=0; ii < 4; ii ++)
87 pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
88 pBSSNode->wCSSPKCount = 1;
89 for (ii=0; ii < 4; ii ++)
90 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
91 pBSSNode->wAKMSSAuthCount = 1;
92 pBSSNode->sRSNCapObj.bRSNCapExist = FALSE;
93 pBSSNode->sRSNCapObj.wRSNCap = 0;
103 * pBSSNode - BSS list.
104 * pRSN - Pointer to the RSN IE.
108 * Return Value: none.
113 IN PKnownBSS pBSSNode,
122 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
124 WPA2_ClearRSN(pBSSNode);
126 if (pRSN->len == 2) { // ver(2)
127 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
128 pBSSNode->bWPA2Valid = TRUE;
133 if (pRSN->len < 6) { // ver(2) + GK(4)
134 // invalid CSS, P802.11i/D10.0, p31
138 // information element header makes sense
139 if ((pRSN->byElementID == WLAN_EID_RSN) &&
140 (pRSN->wVersion == 1)) {
142 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal 802.11i RSN\n");
144 pbyOUI = &(pRSN->abyRSN[0]);
145 if (MEMEqualMemory(pbyOUI, abyOUIWEP40, 4))
146 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
147 else if (MEMEqualMemory(pbyOUI, abyOUITKIP, 4))
148 pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
149 else if (MEMEqualMemory(pbyOUI, abyOUICCMP, 4))
150 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
151 else if (MEMEqualMemory(pbyOUI, abyOUIWEP104, 4))
152 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
153 else if (MEMEqualMemory(pbyOUI, abyOUIGK, 4)) {
154 // invalid CSS, P802.11i/D10.0, p32
157 // any vendor checks here
158 pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK);
162 if (pRSN->len == 6) {
163 pBSSNode->bWPA2Valid = TRUE;
167 if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
168 pBSSNode->wCSSPKCount = *((PWORD) &(pRSN->abyRSN[4]));
170 pbyOUI = &(pRSN->abyRSN[6]);
172 for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(BYTE)); i++) {
174 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
175 if (MEMEqualMemory(pbyOUI, abyOUIGK, 4)) {
176 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
178 } else if (MEMEqualMemory(pbyOUI, abyOUIWEP40, 4)) {
179 // Invialid CSS, continue to parsing
180 } else if (MEMEqualMemory(pbyOUI, abyOUITKIP, 4)) {
181 if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
182 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
184 ; // Invialid CSS, continue to parsing
185 } else if (MEMEqualMemory(pbyOUI, abyOUICCMP, 4)) {
186 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
187 } else if (MEMEqualMemory(pbyOUI, abyOUIWEP104, 4)) {
188 // Invialid CSS, continue to parsing
190 // any vendor checks here
191 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyCSSPK[%d]: %X\n", j-1, pBSSNode->abyCSSPK[j-1]);
199 if (bUseGK == TRUE) {
201 // invalid CSS, This should be only PK CSS.
204 if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
205 // invalid CSS, If CCMP is enable , PK can't be CSSGK.
209 if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
210 // invalid CSS, No valid PK.
213 pBSSNode->wCSSPKCount = (WORD)j;
214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
217 m = *((PWORD) &(pRSN->abyRSN[4]));
219 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
220 pBSSNode->wAKMSSAuthCount = *((PWORD) &(pRSN->abyRSN[6+4*m]));;
222 pbyOUI = &(pRSN->abyRSN[8+4*m]);
223 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(BYTE)); i++) {
224 if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
225 if (MEMEqualMemory(pbyOUI, abyOUI8021X, 4))
226 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
227 else if (MEMEqualMemory(pbyOUI, abyOUIPSK, 4))
228 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
230 // any vendor checks here
231 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyAKMSSAuthType[%d]: %X\n", j-1, pBSSNode->abyAKMSSAuthType[j-1]);
236 pBSSNode->wAKMSSAuthCount = (WORD)j;
237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
239 n = *((PWORD) &(pRSN->abyRSN[6+4*m]));;
240 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
241 pBSSNode->sRSNCapObj.bRSNCapExist = TRUE;
242 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n]));
245 //ignore PMKID lists bcs only (Re)Assocrequest has this field
246 pBSSNode->bWPA2Valid = TRUE;
258 * pMgmtHandle - Pointer to management object
260 * pRSNIEs - Pointer to the RSN IE to set.
262 * Return Value: length of IEs.
267 IN PVOID pMgmtHandle,
268 OUT PWLAN_IE_RSN pRSNIEs
271 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
272 PBYTE pbyBuffer = NULL;
274 PWORD pwPMKID = NULL;
276 if (pRSNIEs == NULL) {
279 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
280 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
281 (pMgmt->pCurrBSS != NULL)) {
283 pbyBuffer = (PBYTE) pRSNIEs;
284 pRSNIEs->byElementID = WLAN_EID_RSN;
285 pRSNIEs->len = 6; //Version(2)+GK(4)
286 pRSNIEs->wVersion = 1;
287 //Group Key Cipher Suite
288 pRSNIEs->abyRSN[0] = 0x00;
289 pRSNIEs->abyRSN[1] = 0x0F;
290 pRSNIEs->abyRSN[2] = 0xAC;
291 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
292 pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
293 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
294 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
295 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
296 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
298 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
301 // Pairwise Key Cipher Suite
302 pRSNIEs->abyRSN[4] = 1;
303 pRSNIEs->abyRSN[5] = 0;
304 pRSNIEs->abyRSN[6] = 0x00;
305 pRSNIEs->abyRSN[7] = 0x0F;
306 pRSNIEs->abyRSN[8] = 0xAC;
307 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
308 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
309 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
310 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
311 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
312 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
314 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
318 // Auth Key Management Suite
319 pRSNIEs->abyRSN[10] = 1;
320 pRSNIEs->abyRSN[11] = 0;
321 pRSNIEs->abyRSN[12] = 0x00;
322 pRSNIEs->abyRSN[13] = 0x0F;
323 pRSNIEs->abyRSN[14] = 0xAC;
324 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
325 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
326 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
327 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
329 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
334 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) {
335 MEMvCopy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
337 pRSNIEs->abyRSN[16] = 0;
338 pRSNIEs->abyRSN[17] = 0;
342 if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
343 (pMgmt->bRoaming == TRUE) &&
344 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
346 pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]); // Point to PMKID count
347 *pwPMKID = 0; // Initialize PMKID count
348 pbyBuffer = &pRSNIEs->abyRSN[20]; // Point to PMKID list
349 for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
350 if (MEMEqualMemory(&pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0], pMgmt->abyCurrBSSID, U_ETHER_ADDR_LEN)) {
352 MEMvCopy(pbyBuffer, pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID, 16);
357 pRSNIEs->len += (2 + (*pwPMKID)*16);
359 pbyBuffer = &pRSNIEs->abyRSN[18];
362 return(pRSNIEs->len + WLAN_IEHDR_LEN);