2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
22 * Purpose: Handles the Basic Service Set & Node Database functions
25 * WPA_ParseRSN - Parse RSN IE.
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 };
60 * Clear RSN information in BSSList.
64 * pBSSList - BSS list.
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
;
100 * pBSSList - BSS list.
101 * pRSN - Pointer to the RSN IE.
105 * Return Value: none.
110 IN PKnownBSS pBSSList
,
111 IN PWLAN_IE_RSN_EXT pRSN
114 PWLAN_IE_RSN_AUTH pIE_RSN_Auth
= NULL
;
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
;
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)
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
;
163 // any vendor checks here
168 //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
170 pBSSList
->wPKCount
= (WORD
)j
;
171 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wPKCount: %d\n", pBSSList
->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
;
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
;
191 // any vendor checks here
196 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
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
;
228 * Search RSN information in BSSList.
232 * byCmd - Search type
233 * byEncrypt- Encrcypt Type
234 * pBSSList - BSS list
238 * Return Value: none.
245 IN PKnownBSS pBSSList
249 BYTE byPKType
= WPA_NONE
;
251 if (pBSSList
->bWPAValid
== FALSE
)
257 if (byEncrypt
!= pBSSList
->byGKType
)
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
))
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
)
275 // if (pBSSList->wAuthCount > 0)
276 // for (ii=0; ii < pBSSList->wAuthCount; ii ++)
277 // if (byAuth == pBSSList->abyAuthType[ii])
290 * Check if RSN IE makes sense.
294 * pRSN - Pointer to the RSN IE.
298 * Return Value: none.
303 IN PWLAN_IE_RSN_EXT pRSN
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)) {