aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2005-06-25 17:36:57 (GMT)
committerJouni Malinen <j@w1.fi>2005-06-25 17:36:57 (GMT)
commitabbbc3573fd748862aea8d3d83b36d66e96a3820 (patch)
treed0e24c18023522ecb45cd8202452aae47bb763ac
parent8bd9cfb4a3e76000c9db2d9abb8aa36642827ed3 (diff)
downloadhostap-history-abbbc3573fd748862aea8d3d83b36d66e96a3820.zip
hostap-history-abbbc3573fd748862aea8d3d83b36d66e96a3820.tar.gz
hostap-history-abbbc3573fd748862aea8d3d83b36d66e96a3820.tar.bz2
More WPA state machine separation work:
- rename wpa_supplicant_key_request() to wpa_sm_key_request() and use struct wpa_sm pointer as parameter - replace wpa_eapol_send() with wpa_ether_send() and rename original wpa_eapol_send() to wpa_supplicant_eapol_send() which is a static function - move number of functions in wpa.c to use struct wpa_sm instead of struct wpa_supplicant
-rw-r--r--wpa_supplicant/events.c2
-rw-r--r--wpa_supplicant/preauth_test.c2
-rw-r--r--wpa_supplicant/wpa.c159
-rw-r--r--wpa_supplicant/wpa.h10
-rw-r--r--wpa_supplicant/wpa_supplicant.c37
-rw-r--r--wpa_supplicant/wpa_supplicant_i.h14
6 files changed, 110 insertions, 114 deletions
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 1d44d53..b191384 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -561,7 +561,7 @@ wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
pairwise = (data && data->michael_mic_failure.unicast);
- wpa_supplicant_key_request(wpa_s, 1, pairwise);
+ wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
time(&now);
if (wpa_s->last_michael_mic_error &&
now - wpa_s->last_michael_mic_error <= 60) {
diff --git a/wpa_supplicant/preauth_test.c b/wpa_supplicant/preauth_test.c
index cc86f62..bbfa18e 100644
--- a/wpa_supplicant/preauth_test.c
+++ b/wpa_supplicant/preauth_test.c
@@ -166,7 +166,7 @@ wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
}
-int wpa_eapol_send(void *ctx, int type, u8 *buf, size_t len)
+int wpa_ether_send(struct wpa_supplicant *wpa_s, u8 *buf, size_t len)
{
printf("%s - not implemented\n", __func__);
return -1;
diff --git a/wpa_supplicant/wpa.c b/wpa_supplicant/wpa.c
index 23e37e3..97026ef 100644
--- a/wpa_supplicant/wpa.c
+++ b/wpa_supplicant/wpa.c
@@ -733,30 +733,24 @@ static void wpa_eapol_key_mic(const u8 *key, int ver,
}
-static void wpa_eapol_key_send(struct wpa_supplicant *wpa_s, const u8 *kck,
+static void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
int ver, u8 *msg, size_t msg_len, u8 *key_mic)
{
- struct wpa_sm *sm = wpa_s->wpa;
-
if (key_mic) {
wpa_eapol_key_mic(kck, ver, msg + sizeof(struct l2_ethhdr),
msg_len - sizeof(struct l2_ethhdr),
key_mic);
}
wpa_hexdump(MSG_MSGDUMP, "WPA: TX EAPOL-Key", msg, msg_len);
- if (wpa_s->l2)
- l2_packet_send(wpa_s->l2, msg, msg_len);
- else {
- wpa_drv_send_eapol(wpa_s, msg, msg_len);
- }
+ wpa_ether_send(sm->ctx, msg, msg_len);
eapol_sm_notify_tx_eapol_key(sm->eapol);
free(msg);
}
/**
- * wpa_supplicant_key_request - Send EAPOL-Key Request
- * @wpa_s: Pointer to wpa_supplicant data
+ * wpa_sm_key_request - Send EAPOL-Key Request
+ * @sm: Pointer to WPA state machine data from wpa_sm_init()
* @error: Indicate whether this is an Michael MIC error report
* @pairwise: 1 = error report for pairwise packet, 0 = for group packet
* Returns: Pointer to the current network structure or %NULL on failure
@@ -765,10 +759,8 @@ static void wpa_eapol_key_send(struct wpa_supplicant *wpa_s, const u8 *kck,
* used to request rekeying and it is usually called when a local Michael MIC
* failure is detected.
*/
-void wpa_supplicant_key_request(struct wpa_supplicant *wpa_s,
- int error, int pairwise)
+void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise)
{
- struct wpa_sm *sm = wpa_s->wpa;
size_t rlen;
struct wpa_eapol_key *reply;
int key_info, ver;
@@ -779,13 +771,13 @@ void wpa_supplicant_key_request(struct wpa_supplicant *wpa_s,
else
ver = WPA_KEY_INFO_TYPE_HMAC_MD5_RC4;
- if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
+ if (wpa_drv_get_bssid(sm->ctx, bssid) < 0) {
wpa_printf(MSG_WARNING, "Failed to read BSSID for EAPOL-Key "
"request");
return;
}
- rbuf = wpa_alloc_eapol(wpa_s, bssid, ETH_P_EAPOL,
+ rbuf = wpa_alloc_eapol(sm->ctx, bssid, ETH_P_EAPOL,
IEEE802_1X_TYPE_EAPOL_KEY, NULL, sizeof(*reply),
&rlen, (void *) &reply);
if (rbuf == NULL)
@@ -811,7 +803,7 @@ void wpa_supplicant_key_request(struct wpa_supplicant *wpa_s,
wpa_printf(MSG_INFO, "WPA: Sending EAPOL-Key Request (error=%d "
"pairwise=%d ptk_set=%d len=%lu)",
error, pairwise, sm->ptk_set, (unsigned long) rlen);
- wpa_eapol_key_send(wpa_s, sm->ptk.kck, ver, rbuf, rlen,
+ wpa_eapol_key_send(sm, sm->ptk.kck, ver, rbuf, rlen,
key_info & WPA_KEY_INFO_MIC ?
reply->key_mic : NULL);
}
@@ -912,11 +904,10 @@ static int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
}
-static int wpa_supplicant_get_pmk(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
const unsigned char *src_addr,
const u8 *pmkid)
{
- struct wpa_sm *sm = wpa_s->wpa;
int abort_cached = 0;
if (pmkid && !sm->cur_pmksa) {
@@ -964,10 +955,10 @@ static int wpa_supplicant_get_pmk(struct wpa_supplicant *wpa_s,
abort_cached = 0;
}
} else {
- wpa_msg(wpa_s, MSG_WARNING,
+ wpa_msg(sm->ctx, MSG_WARNING,
"WPA: Failed to get master session key from "
"EAPOL state machines");
- wpa_msg(wpa_s, MSG_WARNING,
+ wpa_msg(sm->ctx, MSG_WARNING,
"WPA: Key handshake aborted");
if (sm->cur_pmksa) {
wpa_printf(MSG_DEBUG, "RSN: Cancelled PMKSA "
@@ -982,10 +973,19 @@ static int wpa_supplicant_get_pmk(struct wpa_supplicant *wpa_s,
if (abort_cached && sm->key_mgmt == WPA_KEY_MGMT_IEEE8021X) {
/* Send EAPOL-Start to trigger full EAP authentication. */
+ u8 *buf;
+ size_t buflen;
+
wpa_printf(MSG_DEBUG, "RSN: no PMKSA entry found - trigger "
"full EAP authentication");
- wpa_eapol_send(wpa_s, IEEE802_1X_TYPE_EAPOL_START,
- (u8 *) "", 0);
+ buf = wpa_alloc_eapol(sm->ctx, sm->bssid, ETH_P_EAPOL,
+ IEEE802_1X_TYPE_EAPOL_START, NULL, 0,
+ &buflen, NULL);
+ if (buf) {
+ wpa_ether_send(sm->ctx, buf, buflen);
+ free(buf);
+ }
+
return -1;
}
@@ -993,12 +993,12 @@ static int wpa_supplicant_get_pmk(struct wpa_supplicant *wpa_s,
}
-static int wpa_supplicant_send_2_of_4(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_send_2_of_4(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
int ver)
{
- struct wpa_sm *sm = wpa_s->wpa;
+ struct wpa_supplicant *wpa_s = sm->ctx;
size_t rlen;
struct wpa_eapol_key *reply;
struct wpa_ptk *ptk;
@@ -1024,7 +1024,7 @@ static int wpa_supplicant_send_2_of_4(struct wpa_supplicant *wpa_s,
wpa_ie, wpa_ie_len);
}
- rbuf = wpa_alloc_eapol(wpa_s, src_addr, ETH_P_EAPOL,
+ rbuf = wpa_alloc_eapol(sm->ctx, src_addr, ETH_P_EAPOL,
IEEE802_1X_TYPE_EAPOL_KEY, NULL,
sizeof(*reply) + wpa_ie_len,
&rlen, (void *) &reply);
@@ -1047,7 +1047,7 @@ static int wpa_supplicant_send_2_of_4(struct wpa_supplicant *wpa_s,
if (sm->renew_snonce) {
if (hostapd_get_rand(sm->snonce, WPA_NONCE_LEN)) {
- wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to get "
+ wpa_msg(sm->ctx, MSG_WARNING, "WPA: Failed to get "
"random data for SNonce");
free(rbuf);
return -1;
@@ -1071,27 +1071,26 @@ static int wpa_supplicant_send_2_of_4(struct wpa_supplicant *wpa_s,
sm->tptk_set = 1;
wpa_printf(MSG_DEBUG, "WPA: Sending EAPOL-Key 2/4");
- wpa_eapol_key_send(wpa_s, ptk->kck, ver, rbuf, rlen, reply->key_mic);
+ wpa_eapol_key_send(sm, ptk->kck, ver, rbuf, rlen, reply->key_mic);
return 0;
}
-static void wpa_supplicant_process_1_of_4(struct wpa_supplicant *wpa_s,
+static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
u16 ver)
{
- struct wpa_sm *sm = wpa_s->wpa;
struct wpa_eapol_ie_parse ie;
- if (wpa_supplicant_get_ssid(wpa_s) == NULL) {
+ if (wpa_supplicant_get_ssid(sm->ctx) == NULL) {
wpa_printf(MSG_WARNING, "WPA: No SSID info found (msg 1 of "
"4).");
return;
}
- wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
+ wpa_supplicant_set_state(sm->ctx, WPA_4WAY_HANDSHAKE);
wpa_printf(MSG_DEBUG, "WPA: RX message 1 of 4-Way Handshake from "
MACSTR " (ver=%d)", MAC2STR(src_addr), ver);
@@ -1109,10 +1108,10 @@ static void wpa_supplicant_process_1_of_4(struct wpa_supplicant *wpa_s,
}
}
- if (wpa_supplicant_get_pmk(wpa_s, src_addr, ie.pmkid))
+ if (wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid))
return;
- if (wpa_supplicant_send_2_of_4(wpa_s, src_addr, key, ver))
+ if (wpa_supplicant_send_2_of_4(sm, src_addr, key, ver))
return;
memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN);
@@ -1126,18 +1125,16 @@ static void wpa_sm_start_preauth(void *eloop_ctx, void *timeout_ctx)
}
-static void wpa_supplicant_key_neg_complete(struct wpa_supplicant *wpa_s,
+static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
const u8 *addr, int secure)
{
- struct wpa_sm *sm = wpa_s->wpa;
-
- wpa_msg(wpa_s, MSG_INFO, "WPA: Key negotiation completed with "
+ wpa_msg(sm->ctx, MSG_INFO, "WPA: Key negotiation completed with "
MACSTR " [PTK=%s GTK=%s]", MAC2STR(addr),
wpa_cipher_txt(sm->pairwise_cipher),
wpa_cipher_txt(sm->group_cipher));
- eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
- wpa_supplicant_cancel_auth_timeout(wpa_s);
- wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
+ eloop_cancel_timeout(wpa_supplicant_scan, sm->ctx, NULL);
+ wpa_supplicant_cancel_auth_timeout(sm->ctx);
+ wpa_supplicant_set_state(sm->ctx, WPA_COMPLETED);
if (secure) {
/* MLME.SETPROTECTION.request(TA, Tx_Rx) */
@@ -1162,11 +1159,10 @@ static void wpa_supplicant_key_neg_complete(struct wpa_supplicant *wpa_s,
}
-static int wpa_supplicant_install_ptk(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key)
{
- struct wpa_sm *sm = wpa_s->wpa;
int alg, keylen, rsclen;
const u8 *key_rsc;
u8 null_rsc[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -1201,7 +1197,7 @@ static int wpa_supplicant_install_ptk(struct wpa_supplicant *wpa_s,
wpa_hexdump(MSG_DEBUG, "WPA: RSC", key_rsc, rsclen);
}
- if (wpa_drv_set_key(wpa_s, alg, src_addr, 0, 1, key_rsc, rsclen,
+ if (wpa_drv_set_key(sm->ctx, alg, src_addr, 0, 1, key_rsc, rsclen,
(u8 *) &sm->ptk.tk1, keylen) < 0) {
wpa_printf(MSG_WARNING, "WPA: Failed to set PTK to the "
"driver.");
@@ -1273,13 +1269,12 @@ struct wpa_gtk_data {
};
-static int wpa_supplicant_install_gtk(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
const struct wpa_gtk_data *gd,
const u8 *key_rsc)
{
const u8 *_gtk = gd->gtk;
u8 gtk_buf[32];
- struct wpa_sm *sm = wpa_s->wpa;
wpa_hexdump_key(MSG_DEBUG, "WPA: Group Key", gd->gtk, gd->gtk_len);
wpa_printf(MSG_DEBUG, "WPA: Installing GTK to the driver "
@@ -1293,7 +1288,7 @@ static int wpa_supplicant_install_gtk(struct wpa_supplicant *wpa_s,
_gtk = gtk_buf;
}
if (sm->pairwise_cipher == WPA_CIPHER_NONE) {
- if (wpa_drv_set_key(wpa_s, gd->alg,
+ if (wpa_drv_set_key(sm->ctx, gd->alg,
(u8 *) "\xff\xff\xff\xff\xff\xff",
gd->keyidx, 1, key_rsc, gd->key_rsc_len,
_gtk, gd->gtk_len) < 0) {
@@ -1301,7 +1296,7 @@ static int wpa_supplicant_install_gtk(struct wpa_supplicant *wpa_s,
"GTK to the driver (Group only).");
return -1;
}
- } else if (wpa_drv_set_key(wpa_s, gd->alg,
+ } else if (wpa_drv_set_key(sm->ctx, gd->alg,
(u8 *) "\xff\xff\xff\xff\xff\xff",
gd->keyidx, gd->tx, key_rsc,
gd->key_rsc_len, _gtk, gd->gtk_len) < 0) {
@@ -1331,14 +1326,13 @@ static int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm *sm,
}
-static int wpa_supplicant_pairwise_gtk(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
const u8 *gtk, int gtk_len,
int key_info)
{
struct wpa_gtk_data gd;
- struct wpa_sm *sm = wpa_s->wpa;
/*
* IEEE Std 802.11i-2004 - 8.5.2 EAPOL-Key frames - Figure 43x
@@ -1367,12 +1361,12 @@ static int wpa_supplicant_pairwise_gtk(struct wpa_supplicant *wpa_s,
if (wpa_supplicant_check_group_cipher(sm->group_cipher,
gtk_len, gtk_len,
&gd.key_rsc_len, &gd.alg) ||
- wpa_supplicant_install_gtk(wpa_s, &gd, key->key_rsc)) {
+ wpa_supplicant_install_gtk(sm, &gd, key->key_rsc)) {
wpa_printf(MSG_DEBUG, "RSN: Failed to install GTK");
return -1;
}
- wpa_supplicant_key_neg_complete(wpa_s, src_addr,
+ wpa_supplicant_key_neg_complete(sm, src_addr,
key_info & WPA_KEY_INFO_SECURE);
return 0;
}
@@ -1465,17 +1459,16 @@ static int wpa_supplicant_validate_ie(struct wpa_supplicant *wpa_s,
}
-static int wpa_supplicant_send_4_of_4(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_send_4_of_4(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
u16 ver, u16 key_info)
{
- struct wpa_sm *sm = wpa_s->wpa;
size_t rlen;
struct wpa_eapol_key *reply;
u8 *rbuf;
- rbuf = wpa_alloc_eapol(wpa_s, src_addr, ETH_P_EAPOL,
+ rbuf = wpa_alloc_eapol(sm->ctx, src_addr, ETH_P_EAPOL,
IEEE802_1X_TYPE_EAPOL_KEY, NULL,
sizeof(*reply), &rlen, (void *) &reply);
if (rbuf == NULL)
@@ -1496,24 +1489,23 @@ static int wpa_supplicant_send_4_of_4(struct wpa_supplicant *wpa_s,
WPA_PUT_BE16(reply->key_data_length, 0);
wpa_printf(MSG_DEBUG, "WPA: Sending EAPOL-Key 4/4");
- wpa_eapol_key_send(wpa_s, sm->ptk.kck, ver, rbuf, rlen,
+ wpa_eapol_key_send(sm, sm->ptk.kck, ver, rbuf, rlen,
reply->key_mic);
return 0;
}
-static void wpa_supplicant_process_3_of_4(struct wpa_supplicant *wpa_s,
+static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
int extra_len, u16 ver)
{
- struct wpa_sm *sm = wpa_s->wpa;
u16 key_info, keylen, len;
const u8 *pos;
struct wpa_eapol_ie_parse ie;
- wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
+ wpa_supplicant_set_state(sm->ctx, WPA_4WAY_HANDSHAKE);
wpa_printf(MSG_DEBUG, "WPA: RX message 3 of 4-Way Handshake from "
MACSTR " (ver=%d)", MAC2STR(src_addr), ver);
@@ -1528,7 +1520,7 @@ static void wpa_supplicant_process_3_of_4(struct wpa_supplicant *wpa_s,
return;
}
- if (wpa_supplicant_validate_ie(wpa_s, src_addr, &ie) < 0)
+ if (wpa_supplicant_validate_ie(sm->ctx, src_addr, &ie) < 0)
return;
if (memcmp(sm->anonce, key->key_nonce, WPA_NONCE_LEN) != 0) {
@@ -1558,7 +1550,7 @@ static void wpa_supplicant_process_3_of_4(struct wpa_supplicant *wpa_s,
break;
}
- if (wpa_supplicant_send_4_of_4(wpa_s, src_addr, key, ver, key_info))
+ if (wpa_supplicant_send_4_of_4(sm, src_addr, key, ver, key_info))
return;
/* SNonce was successfully used in msg 3/4, so mark it to be renewed
@@ -1567,17 +1559,17 @@ static void wpa_supplicant_process_3_of_4(struct wpa_supplicant *wpa_s,
sm->renew_snonce = 1;
if (key_info & WPA_KEY_INFO_INSTALL) {
- wpa_supplicant_install_ptk(wpa_s, src_addr, key);
+ wpa_supplicant_install_ptk(sm, src_addr, key);
}
if (key_info & WPA_KEY_INFO_SECURE) {
/* MLME.SETPROTECTION.request(TA, Tx_Rx) */
eapol_sm_notify_portValid(sm->eapol, TRUE);
}
- wpa_supplicant_set_state(wpa_s, WPA_GROUP_HANDSHAKE);
+ wpa_supplicant_set_state(sm->ctx, WPA_GROUP_HANDSHAKE);
if (ie.gtk &&
- wpa_supplicant_pairwise_gtk(wpa_s, src_addr, key,
+ wpa_supplicant_pairwise_gtk(sm, src_addr, key,
ie.gtk, ie.gtk_len, key_info) < 0) {
wpa_printf(MSG_INFO, "RSN: Failed to configure GTK");
}
@@ -1683,17 +1675,16 @@ static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm,
}
-static int wpa_supplicant_send_2_of_2(struct wpa_supplicant *wpa_s,
+static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
int ver, u16 key_info)
{
- struct wpa_sm *sm = wpa_s->wpa;
size_t rlen;
struct wpa_eapol_key *reply;
u8 *rbuf;
- rbuf = wpa_alloc_eapol(wpa_s, src_addr, ETH_P_EAPOL,
+ rbuf = wpa_alloc_eapol(sm->ctx, src_addr, ETH_P_EAPOL,
IEEE802_1X_TYPE_EAPOL_KEY, NULL,
sizeof(*reply), &rlen, (void *) &reply);
if (rbuf == NULL)
@@ -1714,14 +1705,14 @@ static int wpa_supplicant_send_2_of_2(struct wpa_supplicant *wpa_s,
WPA_PUT_BE16(reply->key_data_length, 0);
wpa_printf(MSG_DEBUG, "WPA: Sending EAPOL-Key 2/2");
- wpa_eapol_key_send(wpa_s, sm->ptk.kck, ver, rbuf, rlen,
+ wpa_eapol_key_send(sm, sm->ptk.kck, ver, rbuf, rlen,
reply->key_mic);
return 0;
}
-static void wpa_supplicant_process_1_of_2(struct wpa_supplicant *wpa_s,
+static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
const unsigned char *src_addr,
const struct wpa_eapol_key *key,
int extra_len, u16 ver)
@@ -1729,12 +1720,11 @@ static void wpa_supplicant_process_1_of_2(struct wpa_supplicant *wpa_s,
u16 key_info, keydatalen;
int rekey;
struct wpa_gtk_data gd;
- struct wpa_sm *sm = wpa_s->wpa;
memset(&gd, 0, sizeof(gd));
- rekey = wpa_supplicant_get_state(wpa_s) == WPA_COMPLETED;
- wpa_supplicant_set_state(wpa_s, WPA_GROUP_HANDSHAKE);
+ rekey = wpa_supplicant_get_state(sm->ctx) == WPA_COMPLETED;
+ wpa_supplicant_set_state(sm->ctx, WPA_GROUP_HANDSHAKE);
wpa_printf(MSG_DEBUG, "WPA: RX message 1 of Group Key Handshake from "
MACSTR " (ver=%d)", MAC2STR(src_addr), ver);
@@ -1754,17 +1744,17 @@ static void wpa_supplicant_process_1_of_2(struct wpa_supplicant *wpa_s,
return;
}
- if (wpa_supplicant_install_gtk(wpa_s, &gd, key->key_rsc) ||
- wpa_supplicant_send_2_of_2(wpa_s, src_addr, key, ver, key_info))
+ if (wpa_supplicant_install_gtk(sm, &gd, key->key_rsc) ||
+ wpa_supplicant_send_2_of_2(sm, src_addr, key, ver, key_info))
return;
if (rekey) {
- wpa_msg(wpa_s, MSG_INFO, "WPA: Group rekeying completed with "
- MACSTR " [GTK=%s]", MAC2STR(src_addr),
+ wpa_msg(sm->ctx, MSG_INFO, "WPA: Group rekeying completed "
+ "with " MACSTR " [GTK=%s]", MAC2STR(src_addr),
wpa_cipher_txt(sm->group_cipher));
- wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
+ wpa_supplicant_set_state(sm->ctx, WPA_COMPLETED);
} else {
- wpa_supplicant_key_neg_complete(wpa_s, src_addr,
+ wpa_supplicant_key_neg_complete(sm, src_addr,
key_info &
WPA_KEY_INFO_SECURE);
}
@@ -1874,7 +1864,7 @@ static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm,
/**
* wpa_sm_rx_eapol - Process received WPA EAPOL frames
- * @wpa_s: Pointer to wpa_supplicant data
+ * @sm: Pointer to WPA state machine data from wpa_sm_init()
* @src_addr: Source MAC address of the EAPOL packet
* @buf: Pointer to the beginning of the EAPOL data (EAPOL header)
* @len: Length of the EAPOL frame
@@ -1888,10 +1878,9 @@ static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm,
* to. In addition, key material (PTK, GTK) is configured at the end of a
* successful key handshake.
*/
-int wpa_sm_rx_eapol(struct wpa_supplicant *wpa_s, unsigned char *src_addr,
+int wpa_sm_rx_eapol(struct wpa_sm *sm, const unsigned char *src_addr,
unsigned char *buf, size_t len)
{
- struct wpa_sm *sm = wpa_s->wpa;
size_t plen, data_len, extra_len;
struct ieee802_1x_hdr *hdr;
struct wpa_eapol_key *key;
@@ -1911,7 +1900,7 @@ int wpa_sm_rx_eapol(struct wpa_supplicant *wpa_s, unsigned char *src_addr,
wpa_printf(MSG_DEBUG, "IEEE 802.1X RX: version=%d type=%d length=%lu",
hdr->version, hdr->type, (unsigned long) plen);
- wpa_drv_poll(wpa_s);
+ wpa_drv_poll(sm->ctx);
if (hdr->version < EAPOL_VERSION) {
/* TODO: backwards compatibility */
@@ -1999,7 +1988,7 @@ int wpa_sm_rx_eapol(struct wpa_supplicant *wpa_s, unsigned char *src_addr,
extra_len = data_len - sizeof(*hdr) - sizeof(*key);
if (WPA_GET_BE16(key->key_data_length) > extra_len) {
- wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid EAPOL-Key frame - "
+ wpa_msg(sm->ctx, MSG_INFO, "WPA: Invalid EAPOL-Key frame - "
"key_data overflow (%d > %lu)",
WPA_GET_BE16(key->key_data_length),
(unsigned long) extra_len);
@@ -2019,17 +2008,17 @@ int wpa_sm_rx_eapol(struct wpa_supplicant *wpa_s, unsigned char *src_addr,
}
if (key_info & WPA_KEY_INFO_MIC) {
/* 3/4 4-Way Handshake */
- wpa_supplicant_process_3_of_4(wpa_s, src_addr, key,
+ wpa_supplicant_process_3_of_4(sm, src_addr, key,
extra_len, ver);
} else {
/* 1/4 4-Way Handshake */
- wpa_supplicant_process_1_of_4(wpa_s, src_addr, key,
+ wpa_supplicant_process_1_of_4(sm, src_addr, key,
ver);
}
} else {
if (key_info & WPA_KEY_INFO_MIC) {
/* 1/2 Group Key Handshake */
- wpa_supplicant_process_1_of_2(wpa_s, src_addr, key,
+ wpa_supplicant_process_1_of_2(sm, src_addr, key,
extra_len, ver);
} else {
wpa_printf(MSG_WARNING, "WPA: EAPOL-Key (Group) "
diff --git a/wpa_supplicant/wpa.h b/wpa_supplicant/wpa.h
index aad972f..740664c 100644
--- a/wpa_supplicant/wpa.h
+++ b/wpa_supplicant/wpa.h
@@ -164,11 +164,7 @@ unsigned int wpa_sm_get_param(struct wpa_sm *sm,
int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
int verbose);
-
-struct wpa_supplicant;
-
-void wpa_supplicant_key_request(struct wpa_supplicant *wpa_s,
- int error, int pairwise);
+void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise);
struct wpa_ie_data {
@@ -184,10 +180,12 @@ struct wpa_ie_data {
int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
struct wpa_ie_data *data);
+struct wpa_supplicant;
+
int wpa_gen_wpa_ie(struct wpa_supplicant *wpa_s, u8 *wpa_ie,
size_t wpa_ie_len);
-int wpa_sm_rx_eapol(struct wpa_supplicant *wpa_s, unsigned char *src_addr,
+int wpa_sm_rx_eapol(struct wpa_sm *sm, const unsigned char *src_addr,
unsigned char *buf, size_t len);
#endif /* WPA_H */
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 7054d0b..5bb17e3 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -162,7 +162,32 @@ u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, const u8 *dest,
}
-int wpa_eapol_send(void *ctx, int type, u8 *buf, size_t len)
+/**
+ * wpa_ether_send - Send Ethernet frame
+ * @wpa_s: pointer to wpa_supplicant data
+ * @buf: Ethernet frame (including header and payload)
+ * @len: Ethernet frame length (including header and payload)
+ */
+int wpa_ether_send(struct wpa_supplicant *wpa_s, u8 *buf, size_t len)
+{
+ if (wpa_s->l2)
+ return l2_packet_send(wpa_s->l2, buf, len);
+
+ return wpa_drv_send_eapol(wpa_s, buf, len);
+}
+
+
+/**
+ * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator
+ * @ctx: pointer to wpa_supplicant data
+ * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
+ * @buf: EAPOL payload (after IEEE 802.1X header)
+ * @len: EAPOL payload length
+ *
+ * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
+ * to the current Authenticator.
+ */
+static int wpa_supplicant_eapol_send(void *ctx, int type, u8 *buf, size_t len)
{
struct wpa_supplicant *wpa_s = ctx;
u8 *msg, *dst, bssid[ETH_ALEN];
@@ -220,11 +245,7 @@ int wpa_eapol_send(void *ctx, int type, u8 *buf, size_t len)
return -1;
wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
- if (wpa_s->l2)
- res = l2_packet_send(wpa_s->l2, msg, msglen);
- else {
- res = wpa_drv_send_eapol(wpa_s, msg, msglen);
- }
+ res = wpa_ether_send(wpa_s, msg, msglen);
free(msg);
return res;
}
@@ -1516,7 +1537,7 @@ void wpa_supplicant_rx_eapol(void *ctx, unsigned char *src_addr,
if (wpa_s->key_mgmt != WPA_KEY_MGMT_PSK &&
eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0)
return;
- wpa_sm_rx_eapol(wpa_s, src_addr, buf, len);
+ wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len);
}
@@ -1706,7 +1727,7 @@ static int wpa_supplicant_init2(struct wpa_supplicant *wpa_s,
ctx->eapol_send_ctx = wpa_s;
ctx->preauth = 0;
ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
- ctx->eapol_send = wpa_eapol_send;
+ ctx->eapol_send = wpa_supplicant_eapol_send;
ctx->set_wep_key = wpa_eapol_set_wep_key;
ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 227d4bb..2b02a25 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -157,19 +157,7 @@ void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, const u8 *dest,
u16 proto, u8 type, const void *data, u16 data_len,
size_t *msg_len, void **data_pos);
-
-/**
- * wpa_eapol_send - send IEEE 802.1X EAPOL packet to the Authenticator
- * @ctx: pointer to wpa_supplicant data
- * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
- * @buf: EAPOL payload (after IEEE 802.1X header)
- * @len: EAPOL payload length
- *
- * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
- * to the current Authenticator or in case of pre-authentication, to the peer
- * of the authentication.
- */
-int wpa_eapol_send(void *ctx, int type, u8 *buf, size_t len);
+int wpa_ether_send(struct wpa_supplicant *wpa_s, u8 *buf, size_t len);
/* driver_ops */