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).
This commit is contained in:
Jouni Malinen 2009-04-22 15:27:51 +03:00 committed by Jouni Malinen
parent ad6494515e
commit f55802e8bf
5 changed files with 36 additions and 33 deletions

View File

@ -14,7 +14,7 @@
#include "includes.h" #include "includes.h"
#include "hostapd.h" #include "common.h"
#include "ieee802_1x.h" #include "ieee802_1x.h"
#include "eapol_sm.h" #include "eapol_sm.h"
#include "eloop.h" #include "eloop.h"
@ -804,7 +804,7 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
sm->portControl = Auto; sm->portControl = Auto;
if (!eapol->conf.wpa && 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; sm->keyTxEnabled = TRUE;
else else
sm->keyTxEnabled = FALSE; sm->keyTxEnabled = FALSE;
@ -1318,6 +1318,11 @@ struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
return NULL; 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.eapol_send = cb->eapol_send;
eapol->cb.aaa_send = cb->aaa_send; eapol->cb.aaa_send = cb->aaa_send;
eapol->cb.finished = cb->finished; eapol->cb.finished = cb->finished;
@ -1338,5 +1343,6 @@ void eapol_auth_deinit(struct eapol_authenticator *eapol)
return; return;
eapol_auth_conf_free(&eapol->conf); eapol_auth_conf_free(&eapol->conf);
os_free(eapol->default_wep_key);
os_free(eapol); os_free(eapol);
} }

View File

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

View File

@ -392,8 +392,6 @@ static void hostapd_cleanup(struct hostapd_data *hapd)
{ {
hostapd_ctrl_iface_deinit(hapd); hostapd_ctrl_iface_deinit(hapd);
os_free(hapd->default_wep_key);
hapd->default_wep_key = NULL;
iapp_deinit(hapd->iapp); iapp_deinit(hapd->iapp);
hapd->iapp = NULL; hapd->iapp = NULL;
accounting_deinit(hapd); accounting_deinit(hapd);
@ -1522,11 +1520,6 @@ hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
hapd->conf = bss; hapd->conf = bss;
hapd->iface = hapd_iface; 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 #ifdef EAP_TLS_FUNCS
if (hapd->conf->eap_server && if (hapd->conf->eap_server &&
(hapd->conf->ca_cert || hapd->conf->server_cert || (hapd->conf->ca_cert || hapd->conf->server_cert ||

View File

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

View File

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