Full support for Ginger Console
[linux-ginger.git] / drivers / staging / vt6655 / wpa2.c
blob931b6bd360e62036969cc8c66a20d28b83138652
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
20 * File: wpa2.c
22 * Purpose: Handles the Basic Service Set & Node Database functions
24 * Functions:
26 * Revision History:
28 * Author: Yiching Chen
30 * Date: Oct. 4, 2004
34 #include "wpa2.h"
35 #include "device.h"
36 #include "wmgr.h"
38 /*--------------------- Static Definitions -------------------------*/
39 static int msglevel =MSG_LEVEL_INFO;
40 //static int msglevel =MSG_LEVEL_DEBUG;
41 /*--------------------- Static Classes ----------------------------*/
43 /*--------------------- Static Variables --------------------------*/
45 const BYTE abyOUIGK[4] = { 0x00, 0x0F, 0xAC, 0x00 };
46 const BYTE abyOUIWEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 };
47 const BYTE abyOUIWEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 };
48 const BYTE abyOUITKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 };
49 const BYTE abyOUICCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 };
51 const BYTE abyOUI8021X[4] = { 0x00, 0x0F, 0xAC, 0x01 };
52 const BYTE abyOUIPSK[4] = { 0x00, 0x0F, 0xAC, 0x02 };
55 /*--------------------- Static Functions --------------------------*/
57 /*--------------------- Export Variables --------------------------*/
59 /*--------------------- Export Functions --------------------------*/
61 /*+
63 * Description:
64 * Clear RSN information in BSSList.
66 * Parameters:
67 * In:
68 * pBSSNode - BSS list.
69 * Out:
70 * none
72 * Return Value: none.
74 -*/
75 VOID
76 WPA2_ClearRSN (
77 IN PKnownBSS pBSSNode
80 int ii;
82 pBSSNode->bWPA2Valid = FALSE;
84 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
85 for (ii=0; ii < 4; ii ++)
86 pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
87 pBSSNode->wCSSPKCount = 1;
88 for (ii=0; ii < 4; ii ++)
89 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
90 pBSSNode->wAKMSSAuthCount = 1;
91 pBSSNode->sRSNCapObj.bRSNCapExist = FALSE;
92 pBSSNode->sRSNCapObj.wRSNCap = 0;
95 /*+
97 * Description:
98 * Parse RSN IE.
100 * Parameters:
101 * In:
102 * pBSSNode - BSS list.
103 * pRSN - Pointer to the RSN IE.
104 * Out:
105 * none
107 * Return Value: none.
110 VOID
111 WPA2vParseRSN (
112 IN PKnownBSS pBSSNode,
113 IN PWLAN_IE_RSN pRSN
116 int i, j;
117 WORD m = 0, n = 0;
118 PBYTE pbyOUI;
119 BOOL bUseGK = FALSE;
121 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
123 WPA2_ClearRSN(pBSSNode);
125 if (pRSN->len == 2) { // ver(2)
126 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
127 pBSSNode->bWPA2Valid = TRUE;
129 return;
132 if (pRSN->len < 6) { // ver(2) + GK(4)
133 // invalid CSS, P802.11i/D10.0, p31
134 return;
137 // information element header makes sense
138 if ((pRSN->byElementID == WLAN_EID_RSN) &&
139 (pRSN->wVersion == 1)) {
141 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal 802.11i RSN\n");
143 pbyOUI = &(pRSN->abyRSN[0]);
144 if ( !memcmp(pbyOUI, abyOUIWEP40, 4))
145 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
146 else if ( !memcmp(pbyOUI, abyOUITKIP, 4))
147 pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
148 else if ( !memcmp(pbyOUI, abyOUICCMP, 4))
149 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
150 else if ( !memcmp(pbyOUI, abyOUIWEP104, 4))
151 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
152 else if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
153 // invalid CSS, P802.11i/D10.0, p32
154 return;
155 } else
156 // any vendor checks here
157 pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK);
161 if (pRSN->len == 6) {
162 pBSSNode->bWPA2Valid = TRUE;
163 return;
166 if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
167 pBSSNode->wCSSPKCount = *((PWORD) &(pRSN->abyRSN[4]));
168 j = 0;
169 pbyOUI = &(pRSN->abyRSN[6]);
171 for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(BYTE)); i++) {
173 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
174 if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
175 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
176 bUseGK = TRUE;
177 } else if ( !memcmp(pbyOUI, abyOUIWEP40, 4)) {
178 // Invialid CSS, continue to parsing
179 } else if ( !memcmp(pbyOUI, abyOUITKIP, 4)) {
180 if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
181 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
182 else
183 ; // Invialid CSS, continue to parsing
184 } else if ( !memcmp(pbyOUI, abyOUICCMP, 4)) {
185 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
186 } else if ( !memcmp(pbyOUI, abyOUIWEP104, 4)) {
187 // Invialid CSS, continue to parsing
188 } else {
189 // any vendor checks here
190 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
192 pbyOUI += 4;
193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyCSSPK[%d]: %X\n", j-1, pBSSNode->abyCSSPK[j-1]);
194 } else
195 break;
196 } //for
198 if (bUseGK == TRUE) {
199 if (j != 1) {
200 // invalid CSS, This should be only PK CSS.
201 return;
203 if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
204 // invalid CSS, If CCMP is enable , PK can't be CSSGK.
205 return;
208 if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
209 // invalid CSS, No valid PK.
210 return;
212 pBSSNode->wCSSPKCount = (WORD)j;
213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
216 m = *((PWORD) &(pRSN->abyRSN[4]));
218 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
219 pBSSNode->wAKMSSAuthCount = *((PWORD) &(pRSN->abyRSN[6+4*m]));;
220 j = 0;
221 pbyOUI = &(pRSN->abyRSN[8+4*m]);
222 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(BYTE)); i++) {
223 if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
224 if ( !memcmp(pbyOUI, abyOUI8021X, 4))
225 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
226 else if ( !memcmp(pbyOUI, abyOUIPSK, 4))
227 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
228 else
229 // any vendor checks here
230 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyAKMSSAuthType[%d]: %X\n", j-1, pBSSNode->abyAKMSSAuthType[j-1]);
232 } else
233 break;
235 pBSSNode->wAKMSSAuthCount = (WORD)j;
236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
238 n = *((PWORD) &(pRSN->abyRSN[6+4*m]));;
239 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
240 pBSSNode->sRSNCapObj.bRSNCapExist = TRUE;
241 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n]));
244 //ignore PMKID lists bcs only (Re)Assocrequest has this field
245 pBSSNode->bWPA2Valid = TRUE;
252 * Description:
253 * Set WPA IEs
255 * Parameters:
256 * In:
257 * pMgmtHandle - Pointer to management object
258 * Out:
259 * pRSNIEs - Pointer to the RSN IE to set.
261 * Return Value: length of IEs.
264 UINT
265 WPA2uSetIEs(
266 IN PVOID pMgmtHandle,
267 OUT PWLAN_IE_RSN pRSNIEs
270 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
271 PBYTE pbyBuffer = NULL;
272 UINT ii = 0;
273 PWORD pwPMKID = NULL;
275 if (pRSNIEs == NULL) {
276 return(0);
278 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
279 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
280 (pMgmt->pCurrBSS != NULL)) {
281 /* WPA2 IE */
282 pbyBuffer = (PBYTE) pRSNIEs;
283 pRSNIEs->byElementID = WLAN_EID_RSN;
284 pRSNIEs->len = 6; //Version(2)+GK(4)
285 pRSNIEs->wVersion = 1;
286 //Group Key Cipher Suite
287 pRSNIEs->abyRSN[0] = 0x00;
288 pRSNIEs->abyRSN[1] = 0x0F;
289 pRSNIEs->abyRSN[2] = 0xAC;
290 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
291 pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
292 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
293 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
294 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
295 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
296 } else {
297 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
300 // Pairwise Key Cipher Suite
301 pRSNIEs->abyRSN[4] = 1;
302 pRSNIEs->abyRSN[5] = 0;
303 pRSNIEs->abyRSN[6] = 0x00;
304 pRSNIEs->abyRSN[7] = 0x0F;
305 pRSNIEs->abyRSN[8] = 0xAC;
306 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
307 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
308 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
309 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
310 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
311 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
312 } else {
313 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
315 pRSNIEs->len += 6;
317 // Auth Key Management Suite
318 pRSNIEs->abyRSN[10] = 1;
319 pRSNIEs->abyRSN[11] = 0;
320 pRSNIEs->abyRSN[12] = 0x00;
321 pRSNIEs->abyRSN[13] = 0x0F;
322 pRSNIEs->abyRSN[14] = 0xAC;
323 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
324 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
325 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
326 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
327 } else {
328 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
330 pRSNIEs->len +=6;
332 // RSN Capabilites
333 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) {
334 memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
335 } else {
336 pRSNIEs->abyRSN[16] = 0;
337 pRSNIEs->abyRSN[17] = 0;
339 pRSNIEs->len +=2;
341 if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
342 (pMgmt->bRoaming == TRUE) &&
343 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
344 // RSN PMKID
345 pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]); // Point to PMKID count
346 *pwPMKID = 0; // Initialize PMKID count
347 pbyBuffer = &pRSNIEs->abyRSN[20]; // Point to PMKID list
348 for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
349 if ( !memcmp(&pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0], pMgmt->abyCurrBSSID, U_ETHER_ADDR_LEN)) {
350 (*pwPMKID) ++;
351 memcpy(pbyBuffer, pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID, 16);
352 pbyBuffer += 16;
355 if (*pwPMKID != 0) {
356 pRSNIEs->len += (2 + (*pwPMKID)*16);
357 } else {
358 pbyBuffer = &pRSNIEs->abyRSN[18];
361 return(pRSNIEs->len + WLAN_IEHDR_LEN);
363 return(0);