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: handle wpa supplicant ioctl input/out functions
45 /*--------------------- Static Definitions -------------------------*/
47 /*--------------------- Static Classes ----------------------------*/
49 /*--------------------- Static Variables --------------------------*/
50 static int msglevel
= MSG_LEVEL_INFO
;
52 /*--------------------- Static Functions --------------------------*/
54 /*--------------------- Export Variables --------------------------*/
59 * Set WPA algorithm & keys
70 int wpa_set_keys(struct vnt_private
*pDevice
, void *ctx
)
72 struct viawget_wpa_param
*param
= ctx
;
73 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
75 BYTE abyKey
[MAX_KEY_LEN
];
76 BYTE abySeq
[MAX_KEY_LEN
];
78 BYTE byKeyDecMode
= KEY_CTL_WEP
;
83 if (param
->u
.wpa_key
.alg_name
> WPA_ALG_CCMP
)
86 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"param->u.wpa_key.alg_name = %d \n",
87 param
->u
.wpa_key
.alg_name
);
88 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
89 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
90 pDevice
->bEncryptionEnable
= false;
91 pDevice
->byKeyIndex
= 0;
92 pDevice
->bTransmitKey
= false;
93 for (uu
=0; uu
<MAX_KEY_TABLE
; uu
++) {
94 MACvDisableKeyEntry(pDevice
, uu
);
99 if (param
->u
.wpa_key
.key
&& param
->u
.wpa_key
.key_len
> sizeof(abyKey
))
102 memcpy(&abyKey
[0], param
->u
.wpa_key
.key
, param
->u
.wpa_key
.key_len
);
104 dwKeyIndex
= (DWORD
)(param
->u
.wpa_key
.key_index
);
106 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_WEP
) {
107 if (dwKeyIndex
> 3) {
110 if (param
->u
.wpa_key
.set_tx
) {
111 pDevice
->byKeyIndex
= (BYTE
)dwKeyIndex
;
112 pDevice
->bTransmitKey
= true;
113 dwKeyIndex
|= (1 << 31);
115 KeybSetDefaultKey( pDevice
,
117 dwKeyIndex
& ~(BIT30
| USE_KEYRSC
),
118 param
->u
.wpa_key
.key_len
,
125 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
126 pDevice
->bEncryptionEnable
= true;
131 if (param
->u
.wpa_key
.seq
&& param
->u
.wpa_key
.seq_len
> sizeof(abySeq
))
134 memcpy(&abySeq
[0], param
->u
.wpa_key
.seq
, param
->u
.wpa_key
.seq_len
);
136 if (param
->u
.wpa_key
.seq_len
> 0) {
137 for (ii
= 0 ; ii
< param
->u
.wpa_key
.seq_len
; ii
++) {
139 KeyRSC
|= (abySeq
[ii
] << (ii
* 8));
141 KeyRSC
|= (abySeq
[ii
] << ((ii
-4) * 8));
143 dwKeyIndex
|= 1 << 29;
146 if (param
->u
.wpa_key
.key_index
>= MAX_GROUP_KEY
) {
147 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return dwKeyIndex > 3\n");
151 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_TKIP
) {
152 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
155 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_CCMP
) {
156 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
159 if (param
->u
.wpa_key
.set_tx
)
160 dwKeyIndex
|= (1 << 31);
163 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)
164 byKeyDecMode
= KEY_CTL_CCMP
;
165 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
)
166 byKeyDecMode
= KEY_CTL_TKIP
;
168 byKeyDecMode
= KEY_CTL_WEP
;
170 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
171 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
172 if (param
->u
.wpa_key
.key_len
== MAX_KEY_LEN
)
173 byKeyDecMode
= KEY_CTL_TKIP
;
174 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
175 byKeyDecMode
= KEY_CTL_WEP
;
176 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
177 byKeyDecMode
= KEY_CTL_WEP
;
178 } else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
179 if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
180 byKeyDecMode
= KEY_CTL_WEP
;
181 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
182 byKeyDecMode
= KEY_CTL_WEP
;
185 // Check TKIP key length
186 if ((byKeyDecMode
== KEY_CTL_TKIP
) &&
187 (param
->u
.wpa_key
.key_len
!= MAX_KEY_LEN
)) {
188 // TKIP Key must be 256 bits
189 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return - TKIP Key must be 256 bits!\n");
192 // Check AES key length
193 if ((byKeyDecMode
== KEY_CTL_CCMP
) &&
194 (param
->u
.wpa_key
.key_len
!= AES_KEY_LEN
)) {
195 // AES Key must be 128 bits
196 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return - AES Key must be 128 bits\n");
200 if (is_broadcast_ether_addr(¶m
->addr
[0]) || (param
->addr
== NULL
)) {
201 /* if broadcast, set the key as every key entry's group key */
202 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Groupe Key Assign.\n");
204 if ((KeybSetAllGroupKey(pDevice
, &(pDevice
->sKey
), dwKeyIndex
,
205 param
->u
.wpa_key
.key_len
,
210 (KeybSetDefaultKey(pDevice
,
213 param
->u
.wpa_key
.key_len
,
218 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP Key Assign.\n");
223 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Assign.\n");
224 // BSSID not 0xffffffffffff
225 // Pairwise Key can't be WEP
226 if (byKeyDecMode
== KEY_CTL_WEP
) {
227 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key can't be WEP\n");
230 dwKeyIndex
|= (1 << 30); // set pairwise key
231 if (pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) {
232 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
235 if (KeybSetKey(pDevice
, &(pDevice
->sKey
), ¶m
->addr
[0],
236 dwKeyIndex
, param
->u
.wpa_key
.key_len
,
237 &KeyRSC
, (PBYTE
)abyKey
, byKeyDecMode
239 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Set\n");
242 if (!compare_ether_addr(¶m
->addr
[0], pDevice
->abyBSSID
)) {
243 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
246 // Save Key and configure just before associate/reassociate to BSSID
247 // we do not implement now
251 } // BSSID not 0xffffffffffff
252 if ((ret
== 0) && ((param
->u
.wpa_key
.set_tx
) != 0)) {
253 pDevice
->byKeyIndex
= (BYTE
)param
->u
.wpa_key
.key_index
;
254 pDevice
->bTransmitKey
= true;
256 pDevice
->bEncryptionEnable
= true;