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
44 static int msglevel = MSG_LEVEL_INFO;
48 * Set WPA algorithm & keys
59 int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
61 struct viawget_wpa_param *param = ctx;
62 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
64 u8 abyKey[MAX_KEY_LEN];
65 u8 abySeq[MAX_KEY_LEN];
67 u8 byKeyDecMode = KEY_CTL_WEP;
72 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
75 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n",
76 param->u.wpa_key.alg_name);
77 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
78 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
79 pDevice->bEncryptionEnable = false;
80 pDevice->byKeyIndex = 0;
81 pDevice->bTransmitKey = false;
82 for (uu=0; uu<MAX_KEY_TABLE; uu++) {
83 MACvDisableKeyEntry(pDevice, uu);
88 if (param->u.wpa_key.key_len > sizeof(abyKey))
91 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
93 dwKeyIndex = (u32)(param->u.wpa_key.key_index);
95 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
99 if (param->u.wpa_key.set_tx) {
100 pDevice->byKeyIndex = (u8)dwKeyIndex;
101 pDevice->bTransmitKey = true;
102 dwKeyIndex |= (1 << 31);
104 KeybSetDefaultKey( pDevice,
106 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
107 param->u.wpa_key.key_len,
114 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
115 pDevice->bEncryptionEnable = true;
119 if (param->u.wpa_key.seq && param->u.wpa_key.seq_len > sizeof(abySeq))
122 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
124 if (param->u.wpa_key.seq_len > 0) {
125 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
127 KeyRSC |= (abySeq[ii] << (ii * 8));
129 KeyRSC |= (abySeq[ii] << ((ii-4) * 8));
131 dwKeyIndex |= 1 << 29;
134 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
139 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
140 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
143 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
144 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
147 if (param->u.wpa_key.set_tx)
148 dwKeyIndex |= (1 << 31);
150 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
151 byKeyDecMode = KEY_CTL_CCMP;
152 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
153 byKeyDecMode = KEY_CTL_TKIP;
155 byKeyDecMode = KEY_CTL_WEP;
157 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
158 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
159 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
160 byKeyDecMode = KEY_CTL_TKIP;
161 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
162 byKeyDecMode = KEY_CTL_WEP;
163 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
164 byKeyDecMode = KEY_CTL_WEP;
165 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
166 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
167 byKeyDecMode = KEY_CTL_WEP;
168 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
169 byKeyDecMode = KEY_CTL_WEP;
172 // Check TKIP key length
173 if ((byKeyDecMode == KEY_CTL_TKIP) &&
174 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
175 // TKIP Key must be 256 bits
176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - TKIP Key must be 256 bits!\n");
179 // Check AES key length
180 if ((byKeyDecMode == KEY_CTL_CCMP) &&
181 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
182 // AES Key must be 128 bits
183 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - AES Key must be 128 bits\n");
187 if (is_broadcast_ether_addr(¶m->addr[0]) || (param->addr == NULL)) {
188 /* if broadcast, set the key as every key entry's group key */
189 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
191 if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex,
192 param->u.wpa_key.key_len,
197 (KeybSetDefaultKey(pDevice,
200 param->u.wpa_key.key_len,
205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
211 // BSSID not 0xffffffffffff
212 // Pairwise Key can't be WEP
213 if (byKeyDecMode == KEY_CTL_WEP) {
214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
217 dwKeyIndex |= (1 << 30); // set pairwise key
218 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
219 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
222 if (KeybSetKey(pDevice, &(pDevice->sKey), ¶m->addr[0],
223 dwKeyIndex, param->u.wpa_key.key_len,
224 &KeyRSC, (u8 *)abyKey, byKeyDecMode
226 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
229 if (ether_addr_equal(param->addr, pDevice->abyBSSID)) {
230 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
233 // Save Key and configure just before associate/reassociate to BSSID
234 // we do not implement now
238 } // BSSID not 0xffffffffffff
239 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
240 pDevice->byKeyIndex = (u8)param->u.wpa_key.key_index;
241 pDevice->bTransmitKey = true;
243 pDevice->bEncryptionEnable = true;