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 int msglevel
= MSG_LEVEL_INFO
;
49 * Set WPA algorithm & keys
60 int wpa_set_keys(struct vnt_private
*pDevice
, void *ctx
)
62 struct viawget_wpa_param
*param
= ctx
;
63 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
65 u8 abyKey
[MAX_KEY_LEN
];
66 u8 abySeq
[MAX_KEY_LEN
];
68 u8 byKeyDecMode
= KEY_CTL_WEP
;
73 if (param
->u
.wpa_key
.alg_name
> WPA_ALG_CCMP
)
76 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"param->u.wpa_key.alg_name = %d \n",
77 param
->u
.wpa_key
.alg_name
);
78 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
79 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
80 pDevice
->bEncryptionEnable
= false;
81 pDevice
->byKeyIndex
= 0;
82 pDevice
->bTransmitKey
= false;
83 for (uu
=0; uu
<MAX_KEY_TABLE
; uu
++) {
84 MACvDisableKeyEntry(pDevice
, uu
);
89 if (param
->u
.wpa_key
.key
&& param
->u
.wpa_key
.key_len
> sizeof(abyKey
))
92 memcpy(&abyKey
[0], param
->u
.wpa_key
.key
, param
->u
.wpa_key
.key_len
);
94 dwKeyIndex
= (u32
)(param
->u
.wpa_key
.key_index
);
96 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_WEP
) {
100 if (param
->u
.wpa_key
.set_tx
) {
101 pDevice
->byKeyIndex
= (u8
)dwKeyIndex
;
102 pDevice
->bTransmitKey
= true;
103 dwKeyIndex
|= (1 << 31);
105 KeybSetDefaultKey( pDevice
,
107 dwKeyIndex
& ~(BIT30
| USE_KEYRSC
),
108 param
->u
.wpa_key
.key_len
,
115 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
116 pDevice
->bEncryptionEnable
= true;
120 if (param
->u
.wpa_key
.seq
&& param
->u
.wpa_key
.seq_len
> sizeof(abySeq
))
123 memcpy(&abySeq
[0], param
->u
.wpa_key
.seq
, param
->u
.wpa_key
.seq_len
);
125 if (param
->u
.wpa_key
.seq_len
> 0) {
126 for (ii
= 0 ; ii
< param
->u
.wpa_key
.seq_len
; ii
++) {
128 KeyRSC
|= (abySeq
[ii
] << (ii
* 8));
130 KeyRSC
|= (abySeq
[ii
] << ((ii
-4) * 8));
132 dwKeyIndex
|= 1 << 29;
135 if (param
->u
.wpa_key
.key_index
>= MAX_GROUP_KEY
) {
136 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return dwKeyIndex > 3\n");
140 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_TKIP
) {
141 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
144 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_CCMP
) {
145 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
148 if (param
->u
.wpa_key
.set_tx
)
149 dwKeyIndex
|= (1 << 31);
151 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)
152 byKeyDecMode
= KEY_CTL_CCMP
;
153 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
)
154 byKeyDecMode
= KEY_CTL_TKIP
;
156 byKeyDecMode
= KEY_CTL_WEP
;
158 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
159 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
160 if (param
->u
.wpa_key
.key_len
== MAX_KEY_LEN
)
161 byKeyDecMode
= KEY_CTL_TKIP
;
162 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
163 byKeyDecMode
= KEY_CTL_WEP
;
164 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
165 byKeyDecMode
= KEY_CTL_WEP
;
166 } else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
167 if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
168 byKeyDecMode
= KEY_CTL_WEP
;
169 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
170 byKeyDecMode
= KEY_CTL_WEP
;
173 // Check TKIP key length
174 if ((byKeyDecMode
== KEY_CTL_TKIP
) &&
175 (param
->u
.wpa_key
.key_len
!= MAX_KEY_LEN
)) {
176 // TKIP Key must be 256 bits
177 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return - TKIP Key must be 256 bits!\n");
180 // Check AES key length
181 if ((byKeyDecMode
== KEY_CTL_CCMP
) &&
182 (param
->u
.wpa_key
.key_len
!= AES_KEY_LEN
)) {
183 // AES Key must be 128 bits
184 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return - AES Key must be 128 bits\n");
188 if (is_broadcast_ether_addr(¶m
->addr
[0]) || (param
->addr
== NULL
)) {
189 /* if broadcast, set the key as every key entry's group key */
190 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Groupe Key Assign.\n");
192 if ((KeybSetAllGroupKey(pDevice
, &(pDevice
->sKey
), dwKeyIndex
,
193 param
->u
.wpa_key
.key_len
,
198 (KeybSetDefaultKey(pDevice
,
201 param
->u
.wpa_key
.key_len
,
206 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP Key Assign.\n");
211 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Assign.\n");
212 // BSSID not 0xffffffffffff
213 // Pairwise Key can't be WEP
214 if (byKeyDecMode
== KEY_CTL_WEP
) {
215 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key can't be WEP\n");
218 dwKeyIndex
|= (1 << 30); // set pairwise key
219 if (pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) {
220 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
223 if (KeybSetKey(pDevice
, &(pDevice
->sKey
), ¶m
->addr
[0],
224 dwKeyIndex
, param
->u
.wpa_key
.key_len
,
225 &KeyRSC
, (u8
*)abyKey
, byKeyDecMode
227 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Set\n");
230 if (!compare_ether_addr(¶m
->addr
[0], pDevice
->abyBSSID
)) {
231 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
234 // Save Key and configure just before associate/reassociate to BSSID
235 // we do not implement now
239 } // BSSID not 0xffffffffffff
240 if ((ret
== 0) && ((param
->u
.wpa_key
.set_tx
) != 0)) {
241 pDevice
->byKeyIndex
= (u8
)param
->u
.wpa_key
.key_index
;
242 pDevice
->bTransmitKey
= true;
244 pDevice
->bEncryptionEnable
= true;