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.
45 /*--------------------- Static Variables --------------------------*/
46 static int msglevel
=MSG_LEVEL_INFO
;
48 const BYTE abyOUI00
[4] = { 0x00, 0x50, 0xf2, 0x00 };
49 const BYTE abyOUI01
[4] = { 0x00, 0x50, 0xf2, 0x01 };
50 const BYTE abyOUI02
[4] = { 0x00, 0x50, 0xf2, 0x02 };
51 const BYTE abyOUI03
[4] = { 0x00, 0x50, 0xf2, 0x03 };
52 const BYTE abyOUI04
[4] = { 0x00, 0x50, 0xf2, 0x04 };
53 const BYTE abyOUI05
[4] = { 0x00, 0x50, 0xf2, 0x05 };
59 * Clear RSN information in BSSList.
63 * pBSSList - BSS list.
77 pBSSList
->byGKType
= WPA_TKIP
;
78 for (ii
=0; ii
< 4; ii
++)
79 pBSSList
->abyPKType
[ii
] = WPA_TKIP
;
80 pBSSList
->wPKCount
= 0;
81 for (ii
=0; ii
< 4; ii
++)
82 pBSSList
->abyAuthType
[ii
] = WPA_AUTH_IEEE802_1X
;
83 pBSSList
->wAuthCount
= 0;
84 pBSSList
->byDefaultK_as_PK
= 0;
85 pBSSList
->byReplayIdx
= 0;
86 pBSSList
->sRSNCapObj
.bRSNCapExist
= FALSE
;
87 pBSSList
->sRSNCapObj
.wRSNCap
= 0;
88 pBSSList
->bWPAValid
= FALSE
;
99 * pBSSList - BSS list.
100 * pRSN - Pointer to the RSN IE.
104 * Return Value: none.
110 PWLAN_IE_RSN_EXT pRSN
113 PWLAN_IE_RSN_AUTH pIE_RSN_Auth
= NULL
;
117 WPA_ClearRSN(pBSSList
);
119 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"WPA_ParseRSN: [%d]\n", pRSN
->len
);
121 // information element header makes sense
122 if ((pRSN
->len
>= 6) // oui1(4)+ver(2)
123 && (pRSN
->byElementID
== WLAN_EID_RSN_WPA
) && !memcmp(pRSN
->abyOUI
, abyOUI01
, 4)
124 && (pRSN
->wVersion
== 1)) {
126 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Legal RSN\n");
127 // update each variable if pRSN is long enough to contain the variable
128 if (pRSN
->len
>= 10) //oui1(4)+ver(2)+GKSuite(4)
130 if ( !memcmp(pRSN
->abyMulticast
, abyOUI01
, 4))
131 pBSSList
->byGKType
= WPA_WEP40
;
132 else if ( !memcmp(pRSN
->abyMulticast
, abyOUI02
, 4))
133 pBSSList
->byGKType
= WPA_TKIP
;
134 else if ( !memcmp(pRSN
->abyMulticast
, abyOUI03
, 4))
135 pBSSList
->byGKType
= WPA_AESWRAP
;
136 else if ( !memcmp(pRSN
->abyMulticast
, abyOUI04
, 4))
137 pBSSList
->byGKType
= WPA_AESCCMP
;
138 else if ( !memcmp(pRSN
->abyMulticast
, abyOUI05
, 4))
139 pBSSList
->byGKType
= WPA_WEP104
;
141 // any vendor checks here
142 pBSSList
->byGKType
= WPA_NONE
;
144 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"byGKType: %x\n", pBSSList
->byGKType
);
147 if (pRSN
->len
>= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
150 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN
->wPKCount
, sizeof(pBSSList
->abyPKType
));
151 for (i
= 0; (i
< pRSN
->wPKCount
) &&
152 (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 ( !memcmp(pRSN
->PKSList
[i
].abyOUI
, abyOUI00
, 4))
155 pBSSList
->abyPKType
[j
++] = WPA_NONE
;
156 else if ( !memcmp(pRSN
->PKSList
[i
].abyOUI
, abyOUI02
, 4))
157 pBSSList
->abyPKType
[j
++] = WPA_TKIP
;
158 else if ( !memcmp(pRSN
->PKSList
[i
].abyOUI
, abyOUI03
, 4))
159 pBSSList
->abyPKType
[j
++] = WPA_AESWRAP
;
160 else if ( !memcmp(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): %zu\n",
183 pIE_RSN_Auth
->wAuthCount
, sizeof(pBSSList
->abyAuthType
));
184 for (i
= 0; (i
< pIE_RSN_Auth
->wAuthCount
) &&
185 (j
< sizeof(pBSSList
->abyAuthType
)/sizeof(BYTE
)); i
++) {
186 if(pRSN
->len
>= 14+4+(m
+i
)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
187 if ( !memcmp(pIE_RSN_Auth
->AuthKSList
[i
].abyOUI
, abyOUI01
, 4))
188 pBSSList
->abyAuthType
[j
++] = WPA_AUTH_IEEE802_1X
;
189 else if ( !memcmp(pIE_RSN_Auth
->AuthKSList
[i
].abyOUI
, abyOUI02
, 4))
190 pBSSList
->abyAuthType
[j
++] = WPA_AUTH_PSK
;
192 // any vendor checks here
197 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
200 pBSSList
->wAuthCount
= (WORD
)j
;
201 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wAuthCount: %d\n", pBSSList
->wAuthCount
);
204 if (pIE_RSN_Auth
!= NULL
) {
206 n
= pIE_RSN_Auth
->wAuthCount
;
208 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"n: %d\n", n
);
209 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"14+4+(m+n)*4: %d\n", 14+4+(m
+n
)*4);
211 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)
212 pbyCaps
= (PBYTE
)pIE_RSN_Auth
->AuthKSList
[n
].abyOUI
;
213 pBSSList
->byDefaultK_as_PK
= (*pbyCaps
) & WPA_GROUPFLAG
;
214 pBSSList
->byReplayIdx
= 2 << ((*pbyCaps
>> WPA_REPLAYBITSSHIFT
) & WPA_REPLAYBITS
);
215 pBSSList
->sRSNCapObj
.bRSNCapExist
= TRUE
;
216 pBSSList
->sRSNCapObj
.wRSNCap
= *(PWORD
)pbyCaps
;
217 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
218 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
219 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
222 pBSSList
->bWPAValid
= TRUE
;
229 * Search RSN information in BSSList.
233 * byCmd - Search type
234 * byEncrypt- Encrcypt Type
235 * pBSSList - BSS list
239 * Return Value: none.
250 BYTE byPKType
= WPA_NONE
;
252 if (pBSSList
->bWPAValid
== FALSE
)
258 if (byEncrypt
!= pBSSList
->byGKType
)
261 if (pBSSList
->wPKCount
> 0) {
262 for (ii
= 0; ii
< pBSSList
->wPKCount
; ii
++) {
263 if (pBSSList
->abyPKType
[ii
] == WPA_AESCCMP
)
264 byPKType
= WPA_AESCCMP
;
265 else if ((pBSSList
->abyPKType
[ii
] == WPA_TKIP
) && (byPKType
!= WPA_AESCCMP
))
267 else if ((pBSSList
->abyPKType
[ii
] == WPA_WEP40
) && (byPKType
!= WPA_AESCCMP
) && (byPKType
!= WPA_TKIP
))
268 byPKType
= WPA_WEP40
;
269 else if ((pBSSList
->abyPKType
[ii
] == WPA_WEP104
) && (byPKType
!= WPA_AESCCMP
) && (byPKType
!= WPA_TKIP
))
270 byPKType
= WPA_WEP104
;
272 if (byEncrypt
!= byPKType
)
276 // if (pBSSList->wAuthCount > 0)
277 // for (ii=0; ii < pBSSList->wAuthCount; ii ++)
278 // if (byAuth == pBSSList->abyAuthType[ii])
291 * Check if RSN IE makes sense.
295 * pRSN - Pointer to the RSN IE.
299 * Return Value: none.
304 PWLAN_IE_RSN_EXT pRSN
310 if ((pRSN
->len
>= 6) && // oui1(4)+ver(2)
311 (pRSN
->byElementID
== WLAN_EID_RSN_WPA
) && !memcmp(pRSN
->abyOUI
, abyOUI01
, 4) &&
312 (pRSN
->wVersion
== 1)) {