x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / staging / vt6656 / wpa2.c
blobaa2216184345192dabe1e524c2779d809f6038d6
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 "device.h"
35 #include "wpa2.h"
37 static int msglevel =MSG_LEVEL_INFO;
38 //static int msglevel =MSG_LEVEL_DEBUG;
40 const u8 abyOUIGK[4] = { 0x00, 0x0F, 0xAC, 0x00 };
41 const u8 abyOUIWEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 };
42 const u8 abyOUIWEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 };
43 const u8 abyOUITKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 };
44 const u8 abyOUICCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 };
46 const u8 abyOUI8021X[4] = { 0x00, 0x0F, 0xAC, 0x01 };
47 const u8 abyOUIPSK[4] = { 0x00, 0x0F, 0xAC, 0x02 };
49 /*+
51 * Description:
52 * Clear RSN information in BSSList.
54 * Parameters:
55 * In:
56 * pBSSNode - BSS list.
57 * Out:
58 * none
60 * Return Value: none.
62 -*/
63 void
64 WPA2_ClearRSN (
65 PKnownBSS pBSSNode
68 int ii;
70 pBSSNode->bWPA2Valid = false;
72 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
73 for (ii=0; ii < 4; ii ++)
74 pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
75 pBSSNode->wCSSPKCount = 1;
76 for (ii=0; ii < 4; ii ++)
77 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
78 pBSSNode->wAKMSSAuthCount = 1;
79 pBSSNode->sRSNCapObj.bRSNCapExist = false;
80 pBSSNode->sRSNCapObj.wRSNCap = 0;
83 /*+
85 * Description:
86 * Parse RSN IE.
88 * Parameters:
89 * In:
90 * pBSSNode - BSS list.
91 * pRSN - Pointer to the RSN IE.
92 * Out:
93 * none
95 * Return Value: none.
97 -*/
98 void
99 WPA2vParseRSN (
100 PKnownBSS pBSSNode,
101 PWLAN_IE_RSN pRSN
104 int i, j;
105 u16 m = 0, n = 0;
106 u8 * pbyOUI;
107 bool bUseGK = false;
109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
111 WPA2_ClearRSN(pBSSNode);
113 if (pRSN->len == 2) { // ver(2)
114 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
115 pBSSNode->bWPA2Valid = true;
117 return;
120 if (pRSN->len < 6) { // ver(2) + GK(4)
121 // invalid CSS, P802.11i/D10.0, p31
122 return;
125 // information element header makes sense
126 if ((pRSN->byElementID == WLAN_EID_RSN) &&
127 (pRSN->wVersion == 1)) {
129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal 802.11i RSN\n");
131 pbyOUI = &(pRSN->abyRSN[0]);
132 if ( !memcmp(pbyOUI, abyOUIWEP40, 4))
133 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
134 else if ( !memcmp(pbyOUI, abyOUITKIP, 4))
135 pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
136 else if ( !memcmp(pbyOUI, abyOUICCMP, 4))
137 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
138 else if ( !memcmp(pbyOUI, abyOUIWEP104, 4))
139 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
140 else if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
141 // invalid CSS, P802.11i/D10.0, p32
142 return;
143 } else
144 // any vendor checks here
145 pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK);
149 if (pRSN->len == 6) {
150 pBSSNode->bWPA2Valid = true;
151 return;
154 if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
155 pBSSNode->wCSSPKCount = *((u16 *) &(pRSN->abyRSN[4]));
156 j = 0;
157 pbyOUI = &(pRSN->abyRSN[6]);
159 for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(u8)); i++) {
161 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
162 if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
163 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
164 bUseGK = true;
165 } else if ( !memcmp(pbyOUI, abyOUIWEP40, 4)) {
166 // Invalid CSS, continue parsing
167 } else if ( !memcmp(pbyOUI, abyOUITKIP, 4)) {
168 if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
169 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
170 else
171 ; // Invalid CSS, continue parsing
172 } else if ( !memcmp(pbyOUI, abyOUICCMP, 4)) {
173 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
174 } else if ( !memcmp(pbyOUI, abyOUIWEP104, 4)) {
175 // Invalid CSS, continue parsing
176 } else {
177 // any vendor checks here
178 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
180 pbyOUI += 4;
181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyCSSPK[%d]: %X\n", j-1, pBSSNode->abyCSSPK[j-1]);
182 } else
183 break;
184 } //for
186 if (bUseGK == true) {
187 if (j != 1) {
188 // invalid CSS, This should be only PK CSS.
189 return;
191 if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
192 // invalid CSS, If CCMP is enable , PK can't be CSSGK.
193 return;
196 if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
197 // invalid CSS, No valid PK.
198 return;
200 pBSSNode->wCSSPKCount = (u16)j;
201 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
204 m = *((u16 *) &(pRSN->abyRSN[4]));
206 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
207 pBSSNode->wAKMSSAuthCount = *((u16 *) &(pRSN->abyRSN[6+4*m]));
208 j = 0;
209 pbyOUI = &(pRSN->abyRSN[8+4*m]);
210 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(u8)); i++) {
211 if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
212 if ( !memcmp(pbyOUI, abyOUI8021X, 4))
213 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
214 else if ( !memcmp(pbyOUI, abyOUIPSK, 4))
215 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
216 else
217 // any vendor checks here
218 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyAKMSSAuthType[%d]: %X\n", j-1, pBSSNode->abyAKMSSAuthType[j-1]);
220 } else
221 break;
223 pBSSNode->wAKMSSAuthCount = (u16)j;
224 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
226 n = *((u16 *) &(pRSN->abyRSN[6+4*m]));
227 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
228 pBSSNode->sRSNCapObj.bRSNCapExist = true;
229 pBSSNode->sRSNCapObj.wRSNCap = *((u16 *) &(pRSN->abyRSN[8+4*m+4*n]));
232 //ignore PMKID lists bcs only (Re)Assocrequest has this field
233 pBSSNode->bWPA2Valid = true;