Staging: vt665x: Clean up include files, Part 2
[linux-2.6/mini2440.git] / drivers / staging / vt6655 / wpa.c
blob2e508973c42cb906a763d367c9bb115634b5177e
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 "umem.h"
37 #include "tmacro.h"
38 #include "tether.h"
39 #include "device.h"
40 #include "80211hdr.h"
41 #include "bssdb.h"
42 #include "wmgr.h"
43 #include "wpa.h"
44 #include "80211mgr.h"
46 /*--------------------- Static Variables --------------------------*/
47 static int msglevel =MSG_LEVEL_INFO;
49 const BYTE abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
50 const BYTE abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
51 const BYTE abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
52 const BYTE abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
53 const BYTE abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
54 const BYTE abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
57 /*+
59 * Description:
60 * Clear RSN information in BSSList.
62 * Parameters:
63 * In:
64 * pBSSList - BSS list.
65 * Out:
66 * none
68 * Return Value: none.
70 -*/
72 VOID
73 WPA_ClearRSN (
74 IN PKnownBSS pBSSList
77 int ii;
78 pBSSList->byGKType = WPA_TKIP;
79 for (ii=0; ii < 4; ii ++)
80 pBSSList->abyPKType[ii] = WPA_TKIP;
81 pBSSList->wPKCount = 0;
82 for (ii=0; ii < 4; ii ++)
83 pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
84 pBSSList->wAuthCount = 0;
85 pBSSList->byDefaultK_as_PK = 0;
86 pBSSList->byReplayIdx = 0;
87 pBSSList->sRSNCapObj.bRSNCapExist = FALSE;
88 pBSSList->sRSNCapObj.wRSNCap = 0;
89 pBSSList->bWPAValid = FALSE;
93 /*+
95 * Description:
96 * Parse RSN IE.
98 * Parameters:
99 * In:
100 * pBSSList - BSS list.
101 * pRSN - Pointer to the RSN IE.
102 * Out:
103 * none
105 * Return Value: none.
108 VOID
109 WPA_ParseRSN (
110 IN PKnownBSS pBSSList,
111 IN PWLAN_IE_RSN_EXT pRSN
114 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
115 int i, j, m, n = 0;
116 PBYTE pbyCaps;
118 WPA_ClearRSN(pBSSList);
120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
122 // information element header makes sense
123 if ((pRSN->len >= 6) // oui1(4)+ver(2)
124 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && MEMEqualMemory(pRSN->abyOUI, abyOUI01, 4)
125 && (pRSN->wVersion == 1)) {
127 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
128 // update each variable if pRSN is long enough to contain the variable
129 if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
131 if (MEMEqualMemory(pRSN->abyMulticast, abyOUI01, 4))
132 pBSSList->byGKType = WPA_WEP40;
133 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI02, 4))
134 pBSSList->byGKType = WPA_TKIP;
135 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI03, 4))
136 pBSSList->byGKType = WPA_AESWRAP;
137 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI04, 4))
138 pBSSList->byGKType = WPA_AESCCMP;
139 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI05, 4))
140 pBSSList->byGKType = WPA_WEP104;
141 else
142 // any vendor checks here
143 pBSSList->byGKType = WPA_NONE;
145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byGKType: %x\n", pBSSList->byGKType);
148 if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
150 j = 0;
151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %ld\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
152 for(i = 0; (i < pRSN->wPKCount) && (j < sizeof(pBSSList->abyPKType)/sizeof(BYTE)); i++) {
153 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
154 if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
155 pBSSList->abyPKType[j++] = WPA_NONE;
156 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
157 pBSSList->abyPKType[j++] = WPA_TKIP;
158 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
159 pBSSList->abyPKType[j++] = WPA_AESWRAP;
160 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
161 pBSSList->abyPKType[j++] = WPA_AESCCMP;
162 else
163 // any vendor checks here
166 else
167 break;
168 //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
169 } //for
170 pBSSList->wPKCount = (WORD)j;
171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
174 m = pRSN->wPKCount;
175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"m: %d\n", m);
176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+m*4: %d\n", 14+m*4);
178 if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
179 // overlay IE_RSN_Auth structure into correct place
180 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
181 j = 0;
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %ld\n",
183 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
184 for(i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < sizeof(pBSSList->abyAuthType)/sizeof(BYTE)); i++) {
185 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
186 if (MEMEqualMemory(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
187 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
188 else if (MEMEqualMemory(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
189 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
190 else
191 // any vendor checks here
194 else
195 break;
196 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
198 if(j > 0)
199 pBSSList->wAuthCount = (WORD)j;
200 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
203 if (pIE_RSN_Auth != NULL) {
205 n = pIE_RSN_Auth->wAuthCount;
207 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"n: %d\n", n);
208 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
210 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)
211 pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI;
212 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
213 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
214 pBSSList->sRSNCapObj.bRSNCapExist = TRUE;
215 pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps;
216 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
217 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
218 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
221 pBSSList->bWPAValid = TRUE;
227 * Description:
228 * Search RSN information in BSSList.
230 * Parameters:
231 * In:
232 * byCmd - Search type
233 * byEncrypt- Encrcypt Type
234 * pBSSList - BSS list
235 * Out:
236 * none
238 * Return Value: none.
241 BOOL
242 WPA_SearchRSN (
243 BYTE byCmd,
244 BYTE byEncrypt,
245 IN PKnownBSS pBSSList
248 int ii;
249 BYTE byPKType = WPA_NONE;
251 if (pBSSList->bWPAValid == FALSE)
252 return FALSE;
254 switch(byCmd) {
255 case 0:
257 if (byEncrypt != pBSSList->byGKType)
258 return FALSE;
260 if (pBSSList->wPKCount > 0) {
261 for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
262 if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
263 byPKType = WPA_AESCCMP;
264 else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
265 byPKType = WPA_TKIP;
266 else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
267 byPKType = WPA_WEP40;
268 else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
269 byPKType = WPA_WEP104;
271 if (byEncrypt != byPKType)
272 return FALSE;
274 return TRUE;
275 // if (pBSSList->wAuthCount > 0)
276 // for (ii=0; ii < pBSSList->wAuthCount; ii ++)
277 // if (byAuth == pBSSList->abyAuthType[ii])
278 // break;
279 break;
281 default:
282 break;
284 return FALSE;
289 * Description:
290 * Check if RSN IE makes sense.
292 * Parameters:
293 * In:
294 * pRSN - Pointer to the RSN IE.
295 * Out:
296 * none
298 * Return Value: none.
301 BOOL
302 WPAb_Is_RSN (
303 IN PWLAN_IE_RSN_EXT pRSN
306 if (pRSN == NULL)
307 return FALSE;
309 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
310 (pRSN->byElementID == WLAN_EID_RSN_WPA) && MEMEqualMemory(pRSN->abyOUI, abyOUI01, 4) &&
311 (pRSN->wVersion == 1)) {
312 return TRUE;
314 else
315 return FALSE;