Blame view
drivers/staging/vt6655/wpa.c
7.77 KB
5449c685a
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * File: wpa.c * * Purpose: Handles the Basic Service Set & Node Database functions * * Functions: * WPA_ParseRSN - Parse RSN IE. * * Revision History: * * Author: Kyle Hsu * * Date: July 14, 2003 * */ |
5449c685a
|
34 |
#include "ttype.h" |
5449c685a
|
35 |
#include "tmacro.h" |
5449c685a
|
36 |
#include "tether.h" |
5449c685a
|
37 |
#include "device.h" |
5449c685a
|
38 |
#include "80211hdr.h" |
5449c685a
|
39 |
#include "bssdb.h" |
5449c685a
|
40 |
#include "wmgr.h" |
5449c685a
|
41 |
#include "wpa.h" |
5449c685a
|
42 |
#include "80211mgr.h" |
5449c685a
|
43 44 |
/*--------------------- Static Variables --------------------------*/ |
0aa82696f
|
45 46 47 48 49 50 |
static const unsigned char abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 }; static const unsigned char abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 }; static const unsigned char abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 }; static const unsigned char abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 }; static const unsigned char abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 }; static const unsigned char abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 }; |
5449c685a
|
51 |
|
5449c685a
|
52 53 54 55 56 57 58 59 60 61 62 63 64 |
/*+ * * Description: * Clear RSN information in BSSList. * * Parameters: * In: * pBSSList - BSS list. * Out: * none * * Return Value: none. * |
f0c35239a
|
65 |
-*/ |
5449c685a
|
66 |
|
6b35b7b37
|
67 |
void |
f0c35239a
|
68 69 70 |
WPA_ClearRSN( PKnownBSS pBSSList ) |
5449c685a
|
71 |
{ |
f0c35239a
|
72 |
int ii; |
6b7112719
|
73 |
|
f0c35239a
|
74 75 76 77 78 79 80 81 82 83 84 85 |
pBSSList->byGKType = WPA_TKIP; for (ii = 0; ii < 4; ii++) pBSSList->abyPKType[ii] = WPA_TKIP; pBSSList->wPKCount = 0; for (ii = 0; ii < 4; ii++) pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X; pBSSList->wAuthCount = 0; pBSSList->byDefaultK_as_PK = 0; pBSSList->byReplayIdx = 0; pBSSList->sRSNCapObj.bRSNCapExist = false; pBSSList->sRSNCapObj.wRSNCap = 0; pBSSList->bWPAValid = false; |
5449c685a
|
86 |
} |
5449c685a
|
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
/*+ * * Description: * Parse RSN IE. * * Parameters: * In: * pBSSList - BSS list. * pRSN - Pointer to the RSN IE. * Out: * none * * Return Value: none. * |
f0c35239a
|
101 |
-*/ |
6b35b7b37
|
102 |
void |
f0c35239a
|
103 104 105 106 |
WPA_ParseRSN( PKnownBSS pBSSList, PWLAN_IE_RSN_EXT pRSN ) |
5449c685a
|
107 |
{ |
f0c35239a
|
108 109 110 |
PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL; int i, j, m, n = 0; unsigned char *pbyCaps; |
5449c685a
|
111 |
|
f0c35239a
|
112 |
WPA_ClearRSN(pBSSList); |
5449c685a
|
113 |
|
48caf5a06
|
114 115 |
pr_debug("WPA_ParseRSN: [%d] ", pRSN->len); |
5449c685a
|
116 |
|
f0c35239a
|
117 118 119 120 |
// information element header makes sense if ((pRSN->len >= 6) // oui1(4)+ver(2) && (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) && (pRSN->wVersion == 1)) { |
48caf5a06
|
121 122 |
pr_debug("Legal RSN "); |
f0c35239a
|
123 |
// update each variable if pRSN is long enough to contain the variable |
049a8afba
|
124 125 |
if (pRSN->len >= 10) { //OUI1(4)+ver(2)+GKSuite(4) |
f0c35239a
|
126 127 128 129 130 131 132 133 134 135 136 137 138 |
if (!memcmp(pRSN->abyMulticast, abyOUI01, 4)) pBSSList->byGKType = WPA_WEP40; else if (!memcmp(pRSN->abyMulticast, abyOUI02, 4)) pBSSList->byGKType = WPA_TKIP; else if (!memcmp(pRSN->abyMulticast, abyOUI03, 4)) pBSSList->byGKType = WPA_AESWRAP; else if (!memcmp(pRSN->abyMulticast, abyOUI04, 4)) pBSSList->byGKType = WPA_AESCCMP; else if (!memcmp(pRSN->abyMulticast, abyOUI05, 4)) pBSSList->byGKType = WPA_WEP104; else // any vendor checks here pBSSList->byGKType = WPA_NONE; |
5449c685a
|
139 |
|
48caf5a06
|
140 141 |
pr_debug("byGKType: %x ", pBSSList->byGKType); |
f0c35239a
|
142 |
} |
5449c685a
|
143 |
|
049a8afba
|
144 145 |
if (pRSN->len >= 12) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2) |
f0c35239a
|
146 |
j = 0; |
48caf5a06
|
147 148 149 |
pr_debug("wPKCount: %d, sizeof(pBSSList->abyPKType): %zu ", pRSN->wPKCount, sizeof(pBSSList->abyPKType)); |
f0c35239a
|
150 151 152 153 154 155 156 157 158 159 160 161 162 |
for (i = 0; (i < pRSN->wPKCount) && (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) { if (pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i) if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4)) pBSSList->abyPKType[j++] = WPA_NONE; else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4)) pBSSList->abyPKType[j++] = WPA_TKIP; else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4)) pBSSList->abyPKType[j++] = WPA_AESWRAP; else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4)) pBSSList->abyPKType[j++] = WPA_AESCCMP; else // any vendor checks here ; |
5e0cc8a23
|
163 |
} else |
f0c35239a
|
164 |
break; |
4e8a7e5fc
|
165 |
} |
f0c35239a
|
166 |
pBSSList->wPKCount = (unsigned short)j; |
48caf5a06
|
167 168 |
pr_debug("wPKCount: %d ", pBSSList->wPKCount); |
f0c35239a
|
169 |
} |
5449c685a
|
170 |
|
f0c35239a
|
171 |
m = pRSN->wPKCount; |
48caf5a06
|
172 173 174 175 |
pr_debug("m: %d ", m); pr_debug("14+m*4: %d ", 14+m*4); |
5449c685a
|
176 |
|
f0c35239a
|
177 178 179 180 |
if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2) // overlay IE_RSN_Auth structure into correct place pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI; j = 0; |
48caf5a06
|
181 182 183 184 |
pr_debug("wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu ", pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType)); |
f0c35239a
|
185 186 187 188 189 190 191 192 193 |
for (i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) { if (pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i) if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4)) pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X; else if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4)) pBSSList->abyAuthType[j++] = WPA_AUTH_PSK; else // any vendor checks here ; |
5e0cc8a23
|
194 |
} else |
f0c35239a
|
195 |
break; |
4e8a7e5fc
|
196 |
|
f0c35239a
|
197 198 199 |
} if (j > 0) pBSSList->wAuthCount = (unsigned short)j; |
48caf5a06
|
200 201 |
pr_debug("wAuthCount: %d ", pBSSList->wAuthCount); |
f0c35239a
|
202 |
} |
5449c685a
|
203 |
|
f0c35239a
|
204 |
if (pIE_RSN_Auth != NULL) { |
f0c35239a
|
205 |
n = pIE_RSN_Auth->wAuthCount; |
5449c685a
|
206 |
|
48caf5a06
|
207 208 209 210 |
pr_debug("n: %d ", n); pr_debug("14+4+(m+n)*4: %d ", 14+4+(m+n)*4); |
5449c685a
|
211 |
|
f0c35239a
|
212 213 214 215 216 217 |
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) pbyCaps = (unsigned char *)pIE_RSN_Auth->AuthKSList[n].abyOUI; pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG; pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS); pBSSList->sRSNCapObj.bRSNCapExist = true; pBSSList->sRSNCapObj.wRSNCap = *(unsigned short *)pbyCaps; |
f0c35239a
|
218 219 220 221 |
} } pBSSList->bWPAValid = true; } |
5449c685a
|
222 223 224 225 226 227 228 229 230 231 |
} /*+ * * Description: * Search RSN information in BSSList. * * Parameters: * In: * byCmd - Search type |
789d1aef1
|
232 |
* byEncrypt- Encrypt Type |
5449c685a
|
233 234 235 236 237 238 |
* pBSSList - BSS list * Out: * none * * Return Value: none. * |
f0c35239a
|
239 |
-*/ |
7b6a00131
|
240 |
bool |
f0c35239a
|
241 242 243 244 245 |
WPA_SearchRSN( unsigned char byCmd, unsigned char byEncrypt, PKnownBSS pBSSList ) |
5449c685a
|
246 |
{ |
f0c35239a
|
247 248 |
int ii; unsigned char byPKType = WPA_NONE; |
5449c685a
|
249 |
|
1208f14a3
|
250 |
if (!pBSSList->bWPAValid) |
f0c35239a
|
251 |
return false; |
5449c685a
|
252 |
|
f0c35239a
|
253 254 |
switch (byCmd) { case 0: |
5449c685a
|
255 |
|
f0c35239a
|
256 257 |
if (byEncrypt != pBSSList->byGKType) return false; |
5449c685a
|
258 |
|
f0c35239a
|
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
if (pBSSList->wPKCount > 0) { for (ii = 0; ii < pBSSList->wPKCount; ii++) { if (pBSSList->abyPKType[ii] == WPA_AESCCMP) byPKType = WPA_AESCCMP; else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP)) byPKType = WPA_TKIP; else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP)) byPKType = WPA_WEP40; else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP)) byPKType = WPA_WEP104; } if (byEncrypt != byPKType) return false; } return true; |
5449c685a
|
274 |
|
f0c35239a
|
275 276 277 278 |
default: break; } return false; |
5449c685a
|
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
} /*+ * * Description: * Check if RSN IE makes sense. * * Parameters: * In: * pRSN - Pointer to the RSN IE. * Out: * none * * Return Value: none. * |
f0c35239a
|
294 |
-*/ |
7b6a00131
|
295 |
bool |
f0c35239a
|
296 297 298 |
WPAb_Is_RSN( PWLAN_IE_RSN_EXT pRSN ) |
5449c685a
|
299 |
{ |
f0c35239a
|
300 301 |
if (pRSN == NULL) return false; |
5449c685a
|
302 |
|
f0c35239a
|
303 304 305 306 |
if ((pRSN->len >= 6) && // oui1(4)+ver(2) (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) && (pRSN->wVersion == 1)) { return true; |
5e0cc8a23
|
307 |
} else |
f0c35239a
|
308 |
return false; |
5449c685a
|
309 |
} |