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
34
35#include "tmacro.h"
36#include "tether.h"
37#include "device.h"
38#include "80211hdr.h"
39#include "bssdb.h"
40#include "wmgr.h"
41#include "wpa.h"
42#include "80211mgr.h"
43
44static int msglevel =MSG_LEVEL_INFO;
45
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 };
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68void
69WPA_ClearRSN(
70 PKnownBSS pBSSList
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;
83 pBSSList->sRSNCapObj.bRSNCapExist = false;
84 pBSSList->sRSNCapObj.wRSNCap = 0;
85 pBSSList->bWPAValid = false;
86}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103void
104WPA_ParseRSN(
105 PKnownBSS pBSSList,
106 PWLAN_IE_RSN_EXT pRSN
107 )
108{
109 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
110 int i, j, m, n = 0;
111 u8 * pbyCaps;
112
113 WPA_ClearRSN(pBSSList);
114
115 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
116
117
118 if ((pRSN->len >= 6)
119 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4)
120 && (pRSN->wVersion == 1)) {
121
122 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
123
124 if (pRSN->len >= 10)
125 {
126 if ( !memcmp(pRSN->abyMulticast, abyOUI01, 4))
127 pBSSList->byGKType = WPA_WEP40;
128 else if ( !memcmp(pRSN->abyMulticast, abyOUI02, 4))
129 pBSSList->byGKType = WPA_TKIP;
130 else if ( !memcmp(pRSN->abyMulticast, abyOUI03, 4))
131 pBSSList->byGKType = WPA_AESWRAP;
132 else if ( !memcmp(pRSN->abyMulticast, abyOUI04, 4))
133 pBSSList->byGKType = WPA_AESCCMP;
134 else if ( !memcmp(pRSN->abyMulticast, abyOUI05, 4))
135 pBSSList->byGKType = WPA_WEP104;
136 else
137
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)
144 {
145 j = 0;
146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
147 for (i = 0; (i < pRSN->wPKCount) &&
148 (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
149 if(pRSN->len >= 12+i*4+4) {
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
160 ;
161 }
162 else
163 break;
164
165 }
166 pBSSList->wPKCount = (u16)j;
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) {
175
176 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
177 j = 0;
178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
179 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
180 for (i = 0; (i < pIE_RSN_Auth->wAuthCount) &&
181 (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
182 if(pRSN->len >= 14+4+(m+i)*4) {
183 if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
184 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
185 else if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
186 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
187 else
188
189 ;
190 }
191 else
192 break;
193
194 }
195 if(j > 0)
196 pBSSList->wAuthCount = (u16)j;
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) {
208 pbyCaps = (u8 *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
209 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
210 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
211 pBSSList->sRSNCapObj.bRSNCapExist = true;
212 pBSSList->sRSNCapObj.wRSNCap = *(u16 *)pbyCaps;
213
214
215
216 }
217 }
218 pBSSList->bWPAValid = true;
219 }
220}
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238bool
239WPA_SearchRSN(
240 u8 byCmd,
241 u8 byEncrypt,
242 PKnownBSS pBSSList
243 )
244{
245 int ii;
246 u8 byPKType = WPA_NONE;
247
248 if (pBSSList->bWPAValid == false)
249 return false;
250
251 switch(byCmd) {
252 case 0:
253
254 if (byEncrypt != pBSSList->byGKType)
255 return false;
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)
269 return false;
270 }
271 return true;
272
273
274
275
276 break;
277
278 default:
279 break;
280 }
281 return false;
282}
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298bool
299WPAb_Is_RSN(
300 PWLAN_IE_RSN_EXT pRSN
301 )
302{
303 if (pRSN == NULL)
304 return false;
305
306 if ((pRSN->len >= 6) &&
307 (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
308 (pRSN->wVersion == 1)) {
309 return true;
310 }
311 else
312 return false;
313}
314
315