Move default_wep_key variable into EAPOL authenticator data

With this change, eapol_sm.c does not need to dereference main hostapd
structures anymore (i.e., hostapd.h is not needed to be included).
master
Jouni Malinen 15 years ago committed by Jouni Malinen
parent ad6494515e
commit f55802e8bf

@ -14,7 +14,7 @@
#include "includes.h"
#include "hostapd.h"
#include "common.h"
#include "ieee802_1x.h"
#include "eapol_sm.h"
#include "eloop.h"
@ -804,7 +804,7 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
sm->portControl = Auto;
if (!eapol->conf.wpa &&
(hapd->default_wep_key || eapol->conf.individual_wep_key_len > 0))
(eapol->default_wep_key || eapol->conf.individual_wep_key_len > 0))
sm->keyTxEnabled = TRUE;
else
sm->keyTxEnabled = FALSE;
@ -1318,6 +1318,11 @@ struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
return NULL;
}
if (conf->individual_wep_key_len > 0) {
/* use key0 in individual key and key1 in broadcast key */
eapol->default_wep_key_idx = 1;
}
eapol->cb.eapol_send = cb->eapol_send;
eapol->cb.aaa_send = cb->aaa_send;
eapol->cb.finished = cb->finished;
@ -1338,5 +1343,6 @@ void eapol_auth_deinit(struct eapol_authenticator *eapol)
return;
eapol_auth_conf_free(&eapol->conf);
os_free(eapol->default_wep_key);
os_free(eapol);
}

@ -85,6 +85,9 @@ struct eapol_auth_cb {
struct eapol_authenticator {
struct eapol_auth_config conf;
struct eapol_auth_cb cb;
u8 *default_wep_key;
u8 default_wep_key_idx;
};

@ -392,8 +392,6 @@ static void hostapd_cleanup(struct hostapd_data *hapd)
{
hostapd_ctrl_iface_deinit(hapd);
os_free(hapd->default_wep_key);
hapd->default_wep_key = NULL;
iapp_deinit(hapd->iapp);
hapd->iapp = NULL;
accounting_deinit(hapd);
@ -1522,11 +1520,6 @@ hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
hapd->conf = bss;
hapd->iface = hapd_iface;
if (hapd->conf->individual_wep_key_len > 0) {
/* use key0 in individual key and key1 in broadcast key */
hapd->default_wep_key_idx = 1;
}
#ifdef EAP_TLS_FUNCS
if (hapd->conf->eap_server &&
(hapd->conf->ca_cert || hapd->conf->server_cert ||

@ -57,9 +57,6 @@ struct hostapd_data {
const struct wpa_driver_ops *driver;
void *drv_priv;
u8 *default_wep_key;
u8 default_wep_key_idx;
struct radius_client_data *radius;
int radius_client_reconfigured;
u32 acct_session_id_hi, acct_session_id_lo;

@ -285,6 +285,7 @@ ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
{
struct eapol_authenticator *eapol = hapd->eapol_auth;
struct eapol_state_machine *sm = sta->eapol_sm;
#ifndef CONFIG_NO_VLAN
struct hostapd_wep_keys *key = NULL;
@ -310,9 +311,9 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
key->len[key->idx]);
} else
#endif /* CONFIG_NO_VLAN */
if (hapd->default_wep_key) {
ieee802_1x_tx_key_one(hapd, sta, hapd->default_wep_key_idx, 1,
hapd->default_wep_key,
if (eapol->default_wep_key) {
ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
eapol->default_wep_key,
hapd->conf->default_wep_key_len);
}
@ -1425,22 +1426,24 @@ void ieee802_1x_dump_state(FILE *f, const char *prefix, struct sta_info *sta)
static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
{
struct eapol_authenticator *eapol = hapd->eapol_auth;
if (hapd->conf->default_wep_key_len < 1)
return 0;
os_free(hapd->default_wep_key);
hapd->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
if (hapd->default_wep_key == NULL ||
os_get_random(hapd->default_wep_key,
os_free(eapol->default_wep_key);
eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
if (eapol->default_wep_key == NULL ||
os_get_random(eapol->default_wep_key,
hapd->conf->default_wep_key_len)) {
printf("Could not generate random WEP key.\n");
os_free(hapd->default_wep_key);
hapd->default_wep_key = NULL;
os_free(eapol->default_wep_key);
eapol->default_wep_key = NULL;
return -1;
}
wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
hapd->default_wep_key,
eapol->default_wep_key,
hapd->conf->default_wep_key_len);
return 0;
@ -1461,36 +1464,37 @@ static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
{
struct hostapd_data *hapd = eloop_ctx;
struct eapol_authenticator *eapol = hapd->eapol_auth;
if (hapd->default_wep_key_idx >= 3)
hapd->default_wep_key_idx =
if (eapol->default_wep_key_idx >= 3)
eapol->default_wep_key_idx =
hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
else
hapd->default_wep_key_idx++;
eapol->default_wep_key_idx++;
wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
hapd->default_wep_key_idx);
eapol->default_wep_key_idx);
if (ieee802_1x_rekey_broadcast(hapd)) {
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_WARNING, "failed to generate a "
"new broadcast key");
os_free(hapd->default_wep_key);
hapd->default_wep_key = NULL;
os_free(eapol->default_wep_key);
eapol->default_wep_key = NULL;
return;
}
/* TODO: Could setup key for RX here, but change default TX keyid only
* after new broadcast key has been sent to all stations. */
if (hostapd_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP, NULL,
hapd->default_wep_key_idx, 1, NULL, 0,
hapd->default_wep_key,
eapol->default_wep_key_idx, 1, NULL, 0,
eapol->default_wep_key,
hapd->conf->default_wep_key_len)) {
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
HOSTAPD_LEVEL_WARNING, "failed to configure a "
"new broadcast key");
os_free(hapd->default_wep_key);
hapd->default_wep_key = NULL;
os_free(eapol->default_wep_key);
eapol->default_wep_key = NULL;
return;
}
@ -1695,7 +1699,7 @@ int ieee802_1x_init(struct hostapd_data *hapd)
ieee802_1x_rekey(hapd, NULL);
if (hapd->default_wep_key == NULL)
if (hapd->eapol_auth->default_wep_key == NULL)
return -1;
}

Loading…
Cancel
Save