Merge branch 'perf/core' into perf/urgent, to pick up the latest fixes
[deliverable/linux.git] / drivers / staging / vt6656 / wpa.c
CommitLineData
92b96797
FB
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 *
20 * File: wpa.c
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Functions:
25 * WPA_ParseRSN - Parse RSN IE.
26 *
27 * Revision History:
28 *
29 * Author: Kyle Hsu
30 *
31 * Date: July 14, 2003
32 *
33 */
34
92b96797 35#include "tmacro.h"
92b96797 36#include "tether.h"
92b96797 37#include "device.h"
92b96797 38#include "80211hdr.h"
92b96797 39#include "bssdb.h"
92b96797 40#include "wmgr.h"
92b96797 41#include "wpa.h"
92b96797 42#include "80211mgr.h"
92b96797 43
92b96797
FB
44static int msglevel =MSG_LEVEL_INFO;
45
3b138851
VM
46static const u8 abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
47static const u8 abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
48static const u8 abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
49static const u8 abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
50static const u8 abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
51static const u8 abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
92b96797 52
92b96797
FB
53/*+
54 *
55 * Description:
56 * Clear RSN information in BSSList.
57 *
58 * Parameters:
59 * In:
60 * pBSSList - BSS list.
61 * Out:
62 * none
63 *
64 * Return Value: none.
65 *
66-*/
67
8611a29a 68void
62e7e961 69WPA_ClearRSN(
592ccfeb 70 PKnownBSS pBSSList
92b96797
FB
71 )
72{
73 int ii;
74 pBSSList->byGKType = WPA_TKIP;
75 for (ii=0; ii < 4; ii ++)
76 pBSSList->abyPKType[ii] = WPA_TKIP;
77 pBSSList->wPKCount = 0;
78 for (ii=0; ii < 4; ii ++)
79 pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
80 pBSSList->wAuthCount = 0;
81 pBSSList->byDefaultK_as_PK = 0;
82 pBSSList->byReplayIdx = 0;
e269fc2d 83 pBSSList->sRSNCapObj.bRSNCapExist = false;
92b96797 84 pBSSList->sRSNCapObj.wRSNCap = 0;
e269fc2d 85 pBSSList->bWPAValid = false;
92b96797
FB
86}
87
92b96797
FB
88/*+
89 *
90 * Description:
91 * Parse RSN IE.
92 *
93 * Parameters:
94 * In:
95 * pBSSList - BSS list.
96 * pRSN - Pointer to the RSN IE.
97 * Out:
98 * none
99 *
100 * Return Value: none.
101 *
102-*/
8611a29a 103void
62e7e961 104WPA_ParseRSN(
592ccfeb
AM
105 PKnownBSS pBSSList,
106 PWLAN_IE_RSN_EXT pRSN
92b96797
FB
107 )
108{
109 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
110 int i, j, m, n = 0;
b902fbfe 111 u8 * pbyCaps;
92b96797
FB
112
113 WPA_ClearRSN(pBSSList);
114
115 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
116
117 // information element header makes sense
118 if ((pRSN->len >= 6) // oui1(4)+ver(2)
3e362598 119 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4)
92b96797
FB
120 && (pRSN->wVersion == 1)) {
121
122 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
123 // update each variable if pRSN is long enough to contain the variable
124 if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
125 {
3e362598 126 if ( !memcmp(pRSN->abyMulticast, abyOUI01, 4))
92b96797 127 pBSSList->byGKType = WPA_WEP40;
3e362598 128 else if ( !memcmp(pRSN->abyMulticast, abyOUI02, 4))
92b96797 129 pBSSList->byGKType = WPA_TKIP;
3e362598 130 else if ( !memcmp(pRSN->abyMulticast, abyOUI03, 4))
92b96797 131 pBSSList->byGKType = WPA_AESWRAP;
3e362598 132 else if ( !memcmp(pRSN->abyMulticast, abyOUI04, 4))
92b96797 133 pBSSList->byGKType = WPA_AESCCMP;
3e362598 134 else if ( !memcmp(pRSN->abyMulticast, abyOUI05, 4))
92b96797
FB
135 pBSSList->byGKType = WPA_WEP104;
136 else
137 // any vendor checks here
138 pBSSList->byGKType = WPA_NONE;
139
140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byGKType: %x\n", pBSSList->byGKType);
141 }
142
143 if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
144 {
145 j = 0;
98853698 146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
33d33e42 147 for (i = 0; (i < pRSN->wPKCount) &&
b330f606 148 (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
92b96797 149 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
3e362598 150 if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
92b96797 151 pBSSList->abyPKType[j++] = WPA_NONE;
3e362598 152 else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
92b96797 153 pBSSList->abyPKType[j++] = WPA_TKIP;
3e362598 154 else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
92b96797 155 pBSSList->abyPKType[j++] = WPA_AESWRAP;
3e362598 156 else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
92b96797
FB
157 pBSSList->abyPKType[j++] = WPA_AESCCMP;
158 else
159 // any vendor checks here
160 ;
161 }
162 else
163 break;
164 //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
165 } //for
3eaca0d2 166 pBSSList->wPKCount = (u16)j;
92b96797
FB
167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
168 }
169
170 m = pRSN->wPKCount;
171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"m: %d\n", m);
172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+m*4: %d\n", 14+m*4);
173
174 if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
175 // overlay IE_RSN_Auth structure into correct place
176 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
177 j = 0;
98853698 178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
92b96797 179 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
33d33e42 180 for (i = 0; (i < pIE_RSN_Auth->wAuthCount) &&
b330f606 181 (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
92b96797 182 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
3e362598 183 if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
92b96797 184 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
3e362598 185 else if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
92b96797
FB
186 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
187 else
188 // any vendor checks here
189 ;
190 }
191 else
192 break;
193 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
194 }
195 if(j > 0)
3eaca0d2 196 pBSSList->wAuthCount = (u16)j;
92b96797
FB
197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
198 }
199
200 if (pIE_RSN_Auth != NULL) {
201
202 n = pIE_RSN_Auth->wAuthCount;
203
204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"n: %d\n", n);
205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
206
207 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)
b902fbfe 208 pbyCaps = (u8 *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
92b96797
FB
209 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
210 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
4e9b5e2b 211 pBSSList->sRSNCapObj.bRSNCapExist = true;
3eaca0d2 212 pBSSList->sRSNCapObj.wRSNCap = *(u16 *)pbyCaps;
92b96797
FB
213 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
214 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
215 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
216 }
217 }
4e9b5e2b 218 pBSSList->bWPAValid = true;
92b96797
FB
219 }
220}
221
222/*+
223 *
224 * Description:
225 * Search RSN information in BSSList.
226 *
227 * Parameters:
228 * In:
229 * byCmd - Search type
a0a1f61a 230 * byEncrypt- Encrypt Type
92b96797
FB
231 * pBSSList - BSS list
232 * Out:
233 * none
234 *
235 * Return Value: none.
236 *
237-*/
dfdcc425 238bool
62e7e961 239WPA_SearchRSN(
b902fbfe
AM
240 u8 byCmd,
241 u8 byEncrypt,
592ccfeb 242 PKnownBSS pBSSList
92b96797
FB
243 )
244{
245 int ii;
b902fbfe 246 u8 byPKType = WPA_NONE;
92b96797 247
e269fc2d
AM
248 if (pBSSList->bWPAValid == false)
249 return false;
92b96797
FB
250
251 switch(byCmd) {
252 case 0:
253
254 if (byEncrypt != pBSSList->byGKType)
e269fc2d 255 return false;
92b96797
FB
256
257 if (pBSSList->wPKCount > 0) {
258 for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
259 if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
260 byPKType = WPA_AESCCMP;
261 else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
262 byPKType = WPA_TKIP;
263 else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
264 byPKType = WPA_WEP40;
265 else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
266 byPKType = WPA_WEP104;
267 }
268 if (byEncrypt != byPKType)
e269fc2d 269 return false;
92b96797 270 }
4e9b5e2b 271 return true;
92b96797
FB
272// if (pBSSList->wAuthCount > 0)
273// for (ii=0; ii < pBSSList->wAuthCount; ii ++)
274// if (byAuth == pBSSList->abyAuthType[ii])
275// break;
276 break;
277
278 default:
279 break;
280 }
e269fc2d 281 return false;
92b96797
FB
282}
283
284/*+
285 *
286 * Description:
287 * Check if RSN IE makes sense.
288 *
289 * Parameters:
290 * In:
291 * pRSN - Pointer to the RSN IE.
292 * Out:
293 * none
294 *
295 * Return Value: none.
296 *
297-*/
dfdcc425 298bool
62e7e961 299WPAb_Is_RSN(
592ccfeb 300 PWLAN_IE_RSN_EXT pRSN
92b96797
FB
301 )
302{
303 if (pRSN == NULL)
e269fc2d 304 return false;
92b96797
FB
305
306 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
3e362598 307 (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
92b96797 308 (pRSN->wVersion == 1)) {
4e9b5e2b 309 return true;
92b96797
FB
310 }
311 else
e269fc2d 312 return false;
92b96797
FB
313}
314
This page took 0.438207 seconds and 5 git commands to generate.