KVM: nVMX: Fix returned value of MSR_IA32_VMX_VMCS_ENUM
[linux/fpc-iii.git] / drivers / staging / vt6655 / wpa.c
blob9be59c23d7e628312d7f27c43f995114d0f1476d
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: wpa.c
22 * Purpose: Handles the Basic Service Set & Node Database functions
24 * Functions:
25 * WPA_ParseRSN - Parse RSN IE.
27 * Revision History:
29 * Author: Kyle Hsu
31 * Date: July 14, 2003
35 #include "ttype.h"
36 #include "tmacro.h"
37 #include "tether.h"
38 #include "device.h"
39 #include "80211hdr.h"
40 #include "bssdb.h"
41 #include "wmgr.h"
42 #include "wpa.h"
43 #include "80211mgr.h"
45 /*--------------------- Static Variables --------------------------*/
46 static int msglevel = MSG_LEVEL_INFO;
48 static const unsigned char abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
49 static const unsigned char abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
50 static const unsigned char abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
51 static const unsigned char abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
52 static const unsigned char abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
53 static const unsigned char abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
55 /*+
57 * Description:
58 * Clear RSN information in BSSList.
60 * Parameters:
61 * In:
62 * pBSSList - BSS list.
63 * Out:
64 * none
66 * Return Value: none.
68 -*/
70 void
71 WPA_ClearRSN(
72 PKnownBSS pBSSList
75 int ii;
76 pBSSList->byGKType = WPA_TKIP;
77 for (ii = 0; ii < 4; ii++)
78 pBSSList->abyPKType[ii] = WPA_TKIP;
79 pBSSList->wPKCount = 0;
80 for (ii = 0; ii < 4; ii++)
81 pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
82 pBSSList->wAuthCount = 0;
83 pBSSList->byDefaultK_as_PK = 0;
84 pBSSList->byReplayIdx = 0;
85 pBSSList->sRSNCapObj.bRSNCapExist = false;
86 pBSSList->sRSNCapObj.wRSNCap = 0;
87 pBSSList->bWPAValid = false;
90 /*+
92 * Description:
93 * Parse RSN IE.
95 * Parameters:
96 * In:
97 * pBSSList - BSS list.
98 * pRSN - Pointer to the RSN IE.
99 * Out:
100 * none
102 * Return Value: none.
105 void
106 WPA_ParseRSN(
107 PKnownBSS pBSSList,
108 PWLAN_IE_RSN_EXT pRSN
111 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
112 int i, j, m, n = 0;
113 unsigned char *pbyCaps;
115 WPA_ClearRSN(pBSSList);
117 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WPA_ParseRSN: [%d]\n", pRSN->len);
119 // information element header makes sense
120 if ((pRSN->len >= 6) // oui1(4)+ver(2)
121 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4)
122 && (pRSN->wVersion == 1)) {
123 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Legal RSN\n");
124 // update each variable if pRSN is long enough to contain the variable
125 if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
127 if (!memcmp(pRSN->abyMulticast, abyOUI01, 4))
128 pBSSList->byGKType = WPA_WEP40;
129 else if (!memcmp(pRSN->abyMulticast, abyOUI02, 4))
130 pBSSList->byGKType = WPA_TKIP;
131 else if (!memcmp(pRSN->abyMulticast, abyOUI03, 4))
132 pBSSList->byGKType = WPA_AESWRAP;
133 else if (!memcmp(pRSN->abyMulticast, abyOUI04, 4))
134 pBSSList->byGKType = WPA_AESCCMP;
135 else if (!memcmp(pRSN->abyMulticast, abyOUI05, 4))
136 pBSSList->byGKType = WPA_WEP104;
137 else
138 // any vendor checks here
139 pBSSList->byGKType = WPA_NONE;
141 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "byGKType: %x\n", pBSSList->byGKType);
144 if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
146 j = 0;
147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
148 for (i = 0; (i < pRSN->wPKCount) && (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
149 if (pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
150 if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
151 pBSSList->abyPKType[j++] = WPA_NONE;
152 else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
153 pBSSList->abyPKType[j++] = WPA_TKIP;
154 else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
155 pBSSList->abyPKType[j++] = WPA_AESWRAP;
156 else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
157 pBSSList->abyPKType[j++] = WPA_AESCCMP;
158 else
159 // any vendor checks here
161 } else
162 break;
164 pBSSList->wPKCount = (unsigned short)j;
165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wPKCount: %d\n", pBSSList->wPKCount);
168 m = pRSN->wPKCount;
169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "m: %d\n", m);
170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "14+m*4: %d\n", 14+m*4);
172 if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
173 // overlay IE_RSN_Auth structure into correct place
174 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
175 j = 0;
176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
177 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
178 for (i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
179 if (pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
180 if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
181 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
182 else if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
183 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
184 else
185 // any vendor checks here
187 } else
188 break;
191 if (j > 0)
192 pBSSList->wAuthCount = (unsigned short)j;
193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wAuthCount: %d\n", pBSSList->wAuthCount);
196 if (pIE_RSN_Auth != NULL) {
197 n = pIE_RSN_Auth->wAuthCount;
199 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "n: %d\n", n);
200 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
202 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)
203 pbyCaps = (unsigned char *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
204 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
205 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
206 pBSSList->sRSNCapObj.bRSNCapExist = true;
207 pBSSList->sRSNCapObj.wRSNCap = *(unsigned short *)pbyCaps;
210 pBSSList->bWPAValid = true;
216 * Description:
217 * Search RSN information in BSSList.
219 * Parameters:
220 * In:
221 * byCmd - Search type
222 * byEncrypt- Encrypt Type
223 * pBSSList - BSS list
224 * Out:
225 * none
227 * Return Value: none.
230 bool
231 WPA_SearchRSN(
232 unsigned char byCmd,
233 unsigned char byEncrypt,
234 PKnownBSS pBSSList
237 int ii;
238 unsigned char byPKType = WPA_NONE;
240 if (!pBSSList->bWPAValid)
241 return false;
243 switch (byCmd) {
244 case 0:
246 if (byEncrypt != pBSSList->byGKType)
247 return false;
249 if (pBSSList->wPKCount > 0) {
250 for (ii = 0; ii < pBSSList->wPKCount; ii++) {
251 if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
252 byPKType = WPA_AESCCMP;
253 else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
254 byPKType = WPA_TKIP;
255 else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
256 byPKType = WPA_WEP40;
257 else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
258 byPKType = WPA_WEP104;
260 if (byEncrypt != byPKType)
261 return false;
263 return true;
264 break;
266 default:
267 break;
269 return false;
274 * Description:
275 * Check if RSN IE makes sense.
277 * Parameters:
278 * In:
279 * pRSN - Pointer to the RSN IE.
280 * Out:
281 * none
283 * Return Value: none.
286 bool
287 WPAb_Is_RSN(
288 PWLAN_IE_RSN_EXT pRSN
291 if (pRSN == NULL)
292 return false;
294 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
295 (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
296 (pRSN->wVersion == 1)) {
297 return true;
298 } else
299 return false;